Пример #1
0
        protected void Application_Start()
        {
            ServiceStackHelper.Help();
            LicenseUtils.ActivatedLicenseFeatures();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Пример #2
0
            // CoinBaseSharp.ExchangeRates.Test();
            public static void Test()
            {
                // https://docs.google.com/document/d/13rwJuIzL22bUILemGlZ6zf64Ej0CayPnKBcz1-zKjO0
                string sql = @"
SELECT 
	-- api_uid 
	--,api_name 
	--,api_app_id 
	--,api_href, 
	REPLACE(api_href, '{@api_app_id}', api_app_id) AS api_url 
	--,api_comment 
FROM t_api_configurations 
";

                string url = SQL.ExecuteScalar <string>(sql);

                System.Console.WriteLine(url);

                string fileName = MapProjectPath(@"~CoinBaseSharp\ExchangeRates\OpenExchangeRates_Data.txt");

                //string fileName = MapProjectPath(@"~CoinBaseSharp\ExchangeRates\OpenExchangeRates_Error.txt");
                System.Console.WriteLine(fileName);


                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                OpenExchangeRatesData oed = EasyJSON.JsonHelper.DeserializeFromFile <OpenExchangeRatesData>(fileName);

                sw.Stop();
                System.Console.WriteLine(sw.Elapsed);
                System.Console.WriteLine(oed);


#if BENCHMARK || false
                // OpenExchangeRatesData oed = JilHelper.DeserializeUrl<OpenExchangeRatesData>(url);
                System.Diagnostics.Stopwatch swJil1 = new System.Diagnostics.Stopwatch();
                swJil1.Start();
                OpenExchangeRatesData oedJil = JilHelper.DeserializeFromFile <OpenExchangeRatesData>(fileName);
                swJil1.Stop();
                System.Console.WriteLine(swJil1.Elapsed);
                System.Console.WriteLine(oedJil);


                System.Diagnostics.Stopwatch swJil = new System.Diagnostics.Stopwatch();
                swJil.Start();
                OpenExchangeRatesData oedJil2 = JilHelper.DeserializeFromFile <OpenExchangeRatesData>(fileName);
                swJil.Stop();
                System.Console.WriteLine(swJil.Elapsed);
                System.Console.WriteLine(oedJil2);


                System.Diagnostics.Stopwatch sw2 = new System.Diagnostics.Stopwatch();
                sw2.Start();
                OpenExchangeRatesData oed2 = ServiceStackHelper.DeserializeFromFile <OpenExchangeRatesData>(fileName);
                sw2.Stop();
                System.Console.WriteLine(sw2.Elapsed);
                System.Console.WriteLine(oed2);

                System.Diagnostics.Stopwatch sw3 = new System.Diagnostics.Stopwatch();
                sw3.Start();
                OpenExchangeRatesData oed3 = EasyJSON.JsonHelper.DeserializeFromFile <OpenExchangeRatesData>(fileName);
                sw3.Stop();
                System.Console.WriteLine(sw3.Elapsed);
                System.Console.WriteLine(oed3);



                System.Diagnostics.Stopwatch sw4 = new System.Diagnostics.Stopwatch();
                sw4.Start();
                OpenExchangeRatesData oed4 = ServiceStackHelper.DeserializeFromFile <OpenExchangeRatesData>(fileName);
                sw4.Stop();
                System.Console.WriteLine(sw4.Elapsed);
                System.Console.WriteLine(oed4);
#endif


                if (oed.error)
                {
                    System.Console.WriteLine("Error {0}: {1}", oed.status, oed.message);
                    System.Console.WriteLine(oed.description);
                    return;
                } // End if (oed.error)


                sql = @"
INSERT INTO t_map_currency_rate(cur_uid,cur_rate,cur_name,cur_time)
VALUES
(
	 @cur_uid -- uniqueidentifier
	,@cur_rate -- decimal(35,15)
	,@cur_name -- char(3)
	,@cur_time -- datetime
);
";

                System.DateTime localShapshotTime = oed.SnapshotTime.ToLocalTime();
                System.Console.WriteLine(localShapshotTime);


                foreach (System.Collections.Generic.KeyValuePair <string, decimal> kvp in oed.RatesList)
                {
                    System.Console.WriteLine(kvp.Key);
                    System.Console.WriteLine(kvp.Value);

                    using (System.Data.IDbCommand cmd = SQL.CreateCommand(sql))
                    {
                        SQL.AddParameter(cmd, "cur_uid", System.Guid.NewGuid());
                        SQL.AddParameter(cmd, "cur_time", oed.SnapshotTime);
                        SQL.AddParameter(cmd, "cur_name", kvp.Key);
                        SQL.AddParameter(cmd, "cur_rate", kvp.Value);

                        SQL.ExecuteNonQuery(cmd);
                    } // End Using cmd
                }     // Next kvp
            }         // End Sub Test
Пример #3
0
        public static void ConnectServer()
        {
            //初始化
            Tools.WriteStartLog();
            ClientInfo.RequestTime = DateTime.Now;
            ClientInfo.LinkId      = -1;

            ClientInfo.cache = MemoryCache.Default;

            var policy = new CacheItemPolicy
            {
                AbsoluteExpiration = DateTime.Now.AddMinutes(10)
            };


            ClientInfo.cache.Set("one", "", policy);
            ClientInfo.cache.Set("many", "", policy);

            ServiceStackHelper.Patch();
            #region Hsl注册
            if (!HslCommunication.Authorization.SetAuthorizationCode("92db0877-b41e-4445-a594-7be68e32a5ee"))
            {
                Console.WriteLine("Authorization failed! The current program can only be used for 8 hours!");
                return;
            }
            #endregion
            //Console.CancelKeyPress += Console_CancelKeyPress;

            //一个大坑,没有这个前面的appSettings出不来
            var assembliesWithServices = new Assembly[1];
            assembliesWithServices[0] = typeof(AppHost).Assembly;
            var appHost = new AppHost("AppHost", assembliesWithServices);

            IAppSettings appSettings = new AppSettings();

            var localIp     = appSettings.Get <string>("Modbus.LocalIP");
            var tcpPortMany = appSettings.Get <int>("Modbus.TcpPort.Many");
            var tcpPortOne  = appSettings.Get <int>("Modbus.TcpPort.One");

            var modbusTimeout      = appSettings.Get <int>("Modbus.Timeout", 3000);
            var groupName          = appSettings.Get <string>("Modbus.GroupName");
            var jobListRedisConfig = appSettings.Get <RedisEndpoint>("Redis.ModbusJobList");
            var jobListTimeOut     = appSettings.Get <int>("JobList.Timeout");
            useLinkId = appSettings.Get <bool>("Modbus.UserLinkId");
            var isDebug = appSettings.Get <bool>("Modbus.IsDebug");
            var app     = appSettings.Get <string>("AppCMD");
            var isUseStrictCheckMode = appSettings.Get <string>("Modbus.IsUseStrictCheckMode");
            var appRunTime           = appSettings.Get <string>("AppRunTime");


            jobListRedisConfig = Tools.GetRedisEndpoint(jobListRedisConfig);

            JsConfig.DateHandler       = DateHandler.ISO8601DateTime;
            JsConfig.IncludeNullValues = true;

            Console.WriteLine("GroupName          : " + groupName);
            Console.WriteLine("Modbus.LocalIP     : " + localIp);
            Console.WriteLine("Modbus.TcpPort     : " + $"{tcpPortOne}<->{tcpPortMany}");
            Console.WriteLine("Modbus.Timeout     : " + modbusTimeout + " 毫秒");
            Console.WriteLine("Redis.Host         : " + jobListRedisConfig.Host);
            Console.WriteLine("JobList.Timeout    : " + jobListTimeOut + " 秒");
            Console.WriteLine("Modbus.UserLinkId  : " + useLinkId);
            Console.WriteLine("Modbus.IsDebug     : " + isDebug);
            Console.WriteLine("Modbus.IsUseStrictCheckMode: " + isUseStrictCheckMode);

            "程序开始执行".Info();
            redisClient = new RedisClient(jobListRedisConfig);
            var bridge = new Bridge.TcpBridge(localIp, tcpPortOne, tcpPortMany);
            var time   = appRunTime.Split(',');
            var hour   = int.Parse(time[0]);
            var minute = int.Parse(time[1]);
            var second = int.Parse(time[2]);

            long endTime = DateTime.Now.Add(new TimeSpan(hour, minute, second)).Ticks;

            try
            {
                client = new ModbusRtuOverTcp(localIp, tcpPortOne)
                {
                    ReceiveTimeOut = modbusTimeout
                };
                //断开长连接,转为短连接
                client.ConnectClose();
                //client.ConnectServer();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Task.Run[0-0]:" + ex.Message);
                Console.WriteLine("Task.Run[0-0]:" + ex.StackTrace);
            }
        }