Browse Source

2020/01/03 Jessica

Actions:
1.OnlineJob 修改OnlineRecord保存在資料庫 OnlineLogDBContext
2.不顯示 Quartz Log 在Console
Jessica.Tseng 5 years ago
parent
commit
780d3020da

+ 22 - 6
EVCB_OCPP.TaskScheduler/App.config

@@ -1,11 +1,27 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <configuration>
-    <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
-    </startup>
+   <configSections>
+    <sectionGroup name="common">
+      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
+    </sectionGroup>
+    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
+  </configSections>
+  <startup>
+    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
+  </startup>
   <connectionStrings>
-    <add name="ConnectionLogDBContext" connectionString="data source=172.1.0.142\SQLEXPRESS;initial catalog=OCPP_ConnectionLogDBContext;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
-    <add name="MainDBContext" connectionString="data source=172.1.0.142\SQLEXPRESS;initial catalog=OCPP_MainDBContext;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
-    <add name="MeterValueDBContext" connectionString="data source=172.1.0.142\SQLEXPRESS;initial catalog=OCPP_MeterValueDBContext;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
+    <add name="OnlineLogDBContext" connectionString="data source=.\SQLEXPRESS2017;initial catalog=StandardOCPP_OnlineRecord;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
+    <add name="MainDBContext" connectionString="data source=.\SQLEXPRESS2017;initial catalog=StandardOCPP_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
   </connectionStrings>
+
+<!--<common>
+    <logging>
+      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog4000">
+        <arg key="level" value="INFO" />
+        <arg key="configType" value="FILE" />
+        <arg key="configFile" value="~/Config/NLog.config" />
+      </factoryAdapter>
+    </logging>
+  </common>-->
+  
 </configuration>

+ 0 - 86
EVCB_OCPP.TaskScheduler/DBTool/SQLHepler.cs

@@ -1,86 +0,0 @@
-using EVCB_OCPP.TaskScheduler.Models;
-using System;
-using System.Collections.Generic;
-using System.Data.SqlClient;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Transactions;
-
-namespace EVCB_OCPP.TaskScheduler.DBTool
-{
-    internal class SQLHepler
-    {
-        private NLog.ILogger logger = NLog.LogManager.GetCurrentClassLogger();
-        private string ConnectString = "data source=172.1.0.142;initial catalog=OCPP_MainDBContext;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework";
-
-
-        internal SQLHepler()
-        {
-           // ConnectString = connectString;
-
-        }
-
-
-        public void Run()
-        {
-            try
-            {
-                using (SqlConnection conn = new SqlConnection(ConnectString))
-                {
-
-                    string queryString = "update [OCPP_MainDBContext].[dbo].[Machine] set  OfflineOn=HeartbeatUpdatedOn  where ChargeBoxId=@ChargeBoxId";
-                    conn.Open();
-                    using (SqlCommand cmd = new SqlCommand(queryString, conn))
-                    {
-                       // cmd.Parameters.Add(new SqlParameter("OfflineOn"));
-                        cmd.Parameters.Add(new SqlParameter("ChargeBoxId", "RDTEST103"));
-                        cmd.ExecuteNonQuery();
-
-
-                    }
-                }
-            }
-            catch (Exception ex)
-            {
-
-            }
-        }
-
-
-
-
-        private List<EVSECurrentStatus> GetEVSECurrentStatuses()
-        {
-            List<EVSECurrentStatus> result = new List<EVSECurrentStatus>();
-            try
-            {
-                //using (var tranScope = new TransactionScope())
-                //{
-                //    SqlParameter ss = new SqlParameter() {  v} ;
-
-                //    using (SqlConnection conn = new SqlConnection(ConnectString))
-                //    {
-                //        string strSql = " UPDATE Users SET col1=@c1 WHERE col2=@c2";
-                //        dynamic datas = new[]{ new { c1 = "A", c2 = "A2" }
-                //    , new { c1 = "B", c2 = "B2" }
-                //    , new { c1 = "C", c2 = "C2" }};
-                //        conn.(strSql, datas);
-                //    }
-                //    tranScope.Complete();
-                //}
-
-
-
-            }
-            catch (Exception ex)
-            {
-                logger.Error(string.Format("GetEVSECurrentStatuses Exception: {0}", ex.ToString()));
-            }
-
-            return result;
-
-        }
-
-    }
-}

+ 1 - 2
EVCB_OCPP.TaskScheduler/EVCB_OCPP.TaskScheduler.csproj

@@ -58,13 +58,11 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="DBTool\SQLHepler.cs" />
     <Compile Include="DefaultSetting.cs" />
     <Compile Include="Models\EVSECurrentStatus.cs" />
     <Compile Include="Models\EVSEOnlineRecord.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="TaskScheduler.cs" />
     <Compile Include="Jobs\CheckEVSEOnlineJob.cs" />
   </ItemGroup>
   <ItemGroup>
@@ -73,6 +71,7 @@
     </None>
     <Content Include="NLog.config">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      <SubType>Designer</SubType>
     </Content>
     <None Include="NLog.xsd">
       <SubType>Designer</SubType>

+ 1 - 1
EVCB_OCPP.TaskScheduler/Jobs/CheckEVSEOnlineJob.cs

@@ -22,7 +22,7 @@ namespace EVCB_OCPP.TaskScheduler.Jobs
         private List<EVSEOnlineRecord> updateData = new List<EVSEOnlineRecord>();
         private List<EVSEOnlineRecord> insertData = new List<EVSEOnlineRecord>();
         private string mainDBConnectString = ConfigurationManager.ConnectionStrings["MainDBContext"].ToString();
-        private string onlineDBConnectString = ConfigurationManager.ConnectionStrings["ConnectionLogDBContext"].ToString();
+        private string onlineDBConnectString = ConfigurationManager.ConnectionStrings["OnlineLogDBContext"].ToString();
 
         public CheckEVSEOnlineJob()
         {

+ 5 - 2
EVCB_OCPP.TaskScheduler/NLog.config

@@ -31,6 +31,7 @@
     <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
          layout="${longdate} ${uppercase:${level}} ${message}" />
     <target xsi:type="Console" name="Console"  layout="${longdate} ${uppercase:${level}} ${message}" />
+   
   </targets>
 
   <rules>
@@ -40,7 +41,9 @@
     Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace)  to "f"
     <logger name="*" minlevel="Debug" writeTo="f" />
     -->
-    <logger name="*" minlevel="Debug" writeTo="f" />
-    <logger name="*" minlevel="Debug" writeTo="Console" />
+    <logger name="Quartz.*" minlevel="Warn" writeTo="f" />
+    <logger name="EVCB_OCPP.TaskScheduler.*" minlevel="Debug" writeTo="f" />
+    <logger name="EVCB_OCPP.TaskScheduler.*" minlevel="Debug" writeTo="Console" />
+  
   </rules>
 </nlog>

+ 3 - 2
EVCB_OCPP.TaskScheduler/Program.cs

@@ -1,4 +1,4 @@
-using EVCB_OCPP.TaskScheduler.DBTool;
+
 using EVCB_OCPP.TaskScheduler.Jobs;
 using Quartz;
 using Quartz.Impl;
@@ -20,6 +20,7 @@ namespace EVCB_OCPP.TaskScheduler
             {
                //TaskScheduler.Start();
                 logger.Info("running....");
+
                 RunProgramRunExample().GetAwaiter().GetResult();
             }
             catch (Exception ex)
@@ -39,7 +40,7 @@ namespace EVCB_OCPP.TaskScheduler
                
                
                 IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();
-
+                
                 // and start it off
                 await scheduler.Start();
 

+ 0 - 13
EVCB_OCPP.TaskScheduler/TaskScheduler.cs

@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EVCB_OCPP.TaskScheduler
-{
-    public class TaskScheduler
-    {
-
-    }
-}