BourneCao 3 лет назад
Родитель
Сommit
07d2f63a85

+ 4 - 3
CarMeterSystem/App.config

@@ -5,17 +5,18 @@
 	</startup>
 	<appSettings>
 		<!--<add key="ServiceUrl" value="http://127.0.0.1:9004/v1" />-->
-    <add key="ServiceUrl" value="http://10.104.4.105:9004/v1" />
+    <!--<add key="ServiceUrl" value="http://10.104.4.105:9004/v1" />-->
     <!--<add key="ServiceUrl" value="http://192.168.216.143:9004/v1" />-->
     <!--<add key="ServiceUrl" value="http://192.168.137.136:9004/v1" />-->
     <!--<add key="ServiceUrl" value="http://10.104.0.1:9004/v1" />-->
     <!--<add key="ServiceUrl" value="http://192.168.107.60:8888/icore.icp.winform/pass/jlcar"/>-->
     <!--<add key="ServiceUrl" value="http://192.168.185.29/icore.icp.winform/pass/jlcar"/>-->
-    <!--<add key="ServiceUrl" value="http://10.99.81.20/icore.icp.web/pass/systemBase/v1"/>-->
+    <add key="ServiceUrl" value="http://10.99.81.20/icore.icp.web/pass/systemBase/v1"/>
     <!--<add key="ServiceUrl" value="http://jgwzjl.jiugang.com/icore.icp.web/pass/systemBase/v1"/>-->
     <!--<add key="ServiceUrl" value="http://10.130.1.2/icore.icp.web/pass/systemBase/v1"/>-->
     <!--实时库地址-->
-    <add key="icoredbTcp" value="tarantool://guest@10.99.200.86:2101" />
+    <add key="icoredbTcp" value="tarantool://guest@10.99.200.86:21019" />
+    <add key="icoredbTcp2" value="tarantool://guest@10.99.200.86:2101" />
     <!--<add key="icoredbTcp" value="tarantool://guest@10.130.1.3:2101" />-->
     <!--SFTP或者vsftp服务端连接及地址-->
 		<add key="fip" value="192.168.185.238" />

+ 2 - 0
Common/cacheCls/AppConfigCache.cs

@@ -19,6 +19,8 @@ namespace Common
         /// 最新实时数据库连接地址
         /// </summary>
         public static readonly string icoredbTcp= ConfigurationManager.AppSettings["icoredbTcp"].ToString().Trim();
+
+        public static readonly string icoredbTcp2 = ConfigurationManager.AppSettings["icoredbTcp2"].ToString().Trim();
         #endregion
 
         #region ftp信息

+ 5 - 0
Common/cacheCls/PbCache.cs

@@ -393,6 +393,11 @@ namespace Common
         /// </summary>
         public static JArray jArray { get; set; }
 
+        /// <summary>
+        /// 数采实时库返回结果
+        /// </summary>
+        public static string icoredbType { get; set; }
+
 
         #region 扫码器相关
         /// <summary>

+ 37 - 17
Common/database/MemoryTableDataSocket.cs

@@ -20,7 +20,7 @@ namespace Common
             }
             catch (Exception ex)
             {
-                WriteLog("MemoryTableData:" + cln);
+                ChangeCln();
             }
         }
 
@@ -32,7 +32,7 @@ namespace Common
             }
             catch (Exception ex)
             {
-                WriteLog("MemoryTableData:" + cln);
+                ChangeCln();
             }
         }
 
@@ -66,6 +66,7 @@ namespace Common
             }
             catch (Exception ex)
             {
+                ChangeCln();
                 WriteLog("读采集数据异常错误:" + ex.Message);
                 return null;
             }
@@ -90,6 +91,7 @@ namespace Common
             }
             catch (Exception ex)
             {
+                ChangeCln();
                 WriteLog("写入信息到内存表异常!" + ex.Message);
                 errorInfo = "写入信息到内存表异常!" + ex.Message;
                 return false;
@@ -121,6 +123,7 @@ namespace Common
             }
             catch (Exception exp)
             {
+                ChangeCln();
                 WriteLog("LiveTable:" + exp.Message + exp.StackTrace);
                 return null;
             }
@@ -224,11 +227,7 @@ namespace Common
             }
             catch (Exception exp)
             {
-                try
-                {
-                    cln = new CoredbClient(AppConfigCache.icoredbTcp);
-                }
-                catch { }
+                ChangeCln();
 
                 WriteLog(PointIdKey + "_TrackTable:" + exp.Message + exp.StackTrace + "空值");
                 return null;
@@ -295,11 +294,8 @@ namespace Common
             }
             catch (Exception exp)
             {
-                try
-                {
-                    cln = new CoredbClient(AppConfigCache.icoredbTcp);
-                }
-                catch { }
+                ChangeCln();
+
                 WriteLog("調用TrackTable异常:" + exp.Message + exp.StackTrace + "空值");
                 return null;
             }
@@ -379,11 +375,8 @@ namespace Common
             }
             catch (Exception exp)
             {
-                try
-                {
-                    cln = new CoredbClient(AppConfigCache.icoredbTcp);
-                }
-                catch { }
+                ChangeCln();
+
                 WriteLog("調用TrackTable异常:" + exp.Message + exp.StackTrace + "空值");
                 return null;
             }
@@ -447,5 +440,32 @@ namespace Common
             }
             catch { }
         }
+
+        private void ChangeCln()
+        {
+            // 自动切换主备数采平台
+            if(PbCache.icoredbType == "icoredb2")
+            {
+                PbCache.icoredbType = "icoredb1";
+
+                try
+                {
+                    cln = new CoredbClient(AppConfigCache.icoredbTcp);
+                }
+                catch { }
+            }
+            else
+            {
+                PbCache.icoredbType = "icoredb2";
+
+                try
+                {
+                    cln = new CoredbClient(AppConfigCache.icoredbTcp2);
+                }
+                catch { }
+            }
+
+            WriteLog("MemoryTableData:" + cln);
+        }
     }
 }