コード例 #1
0
ファイル: EnityImporter.cs プロジェクト: radtek/phamacy2016
 public bool Import()
 {
     if (!FileExists)
     {
         LoggerHelper.Instance.Warning(string.Format("导入的文件({0})不存在,无法导入!", FileFullPath));
         return(false);
     }
     LoggerHelper.Instance.Information(string.Format("开始导入的实体({0}-{1})...", FileFullPath, typeof(T).FullName));
     try
     {
         List <T> entities = JsonSerializeHelper.DeSerializeJson <List <T> >(FileFullPath);
         if (entities == null)
         {
             return(false);
         }
         foreach (var entity in entities)
         {
             if (entity.Id == default(Guid))
             {
                 entity.Id = Guid.NewGuid();
             }
             _Repository.Add(entity);
         }
         _Repository.UnitOfWork.Commit();
         LoggerHelper.Instance.Information(string.Format("成功导入的实体({0}-{1}).", FileFullPath, typeof(T).FullName));
         Backup();
     }
     catch (Exception ex)
     {
         ex = new Exception(string.Format("导入的实体({0}-{1})失败.", FileFullPath, typeof(T).FullName));
         LoggerHelper.Instance.Error(ex);
     }
     return(true);
 }
コード例 #2
0
        private bool RemoteVerifyPrdKey(string productKey)
        {
            HttpHelper http        = new HttpHelper();
            var        postdata    = string.Format("CPUSerialNumber={0}&ProductKey={1}", MachineInfo.Instance.GetCPUSerialNumber(), productKey);
            string     responseStr = "";

            if (PingHelper.Ping())
            {
                // 验证有效性
                responseStr = http.PostPage(remoteservice + "/api/device/VerifyProductKey", postdata);
            }

            var verifyKeyReponse = JsonHelper.FromJson <VerifyKeyReponse>(responseStr);

            if (verifyKeyReponse != null && verifyKeyReponse.ExpirationDate.HasValue)
            {
                //验证通过
                var filename = Constants.PRODUCT_KEY;

                var launchInfo = JsonSerializeHelper.DeSerializeJson <LaunchInfo>(filename);

                launchInfo.ExpirationDate = verifyKeyReponse.ExpirationDate.Value.Date;
                launchInfo.EncryptedText  = EncryptionService.EncryptText(launchInfo.ExpirationDate.ToShortDateString());
                launchInfo.ProductKey     = productKey;
                File.Delete(filename);
                launchInfo.SerializeJson(filename);

                WindowsRegistry.SetRegistryValue(Constants.EXPIRATION_DATE, launchInfo.ExpirationDate.ToShortDateString());
                WindowsRegistry.SetRegistryValue(Constants.ENCRYPTED_TEXT, launchInfo.EncryptedText);
                WindowsRegistry.SetRegistryValue(Constants.PRODUCT_KEY, productKey);

                var datediff = launchInfo.ExpirationDate.Subtract(DateTime.Now).Days;
                return(datediff >= 0);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        public void Launch()
        {
            new Thread(() =>
            {
                var filename = Constants.PRODUCT_KEY;

                var launchInfo = JsonSerializeHelper.DeSerializeJson <LaunchInfo>(filename);


                if (launchInfo == null)
                {
                    //使用试用账号
                    launchInfo = new LaunchInfo
                    {
                        ComputerName    = MachineInfo.Instance.GetComputerName(),
                        CPUSerialNumber = MachineInfo.Instance.GetCPUSerialNumber(),
                        MACAddress      = MachineInfo.Instance.GetMacAddress(),
                        Name            = PharmacyServiceConfig.Config.CurrentStore.Name,
                        ProductKey      = Constants.DEFAULT_SECURITY_KEY,
                        ExpirationDate  = DateTime.Now.AddDays(30).Date,
                        SystemType      = MachineInfo.Instance.GetSystemType()
                    };
                    launchInfo.EncryptedText = EncryptionService.EncryptText(launchInfo.ExpirationDate.ToShortDateString());


                    WindowsRegistry.CreateRegistry();

                    if (WindowsRegistry.IsRegeditKeyExist(Constants.EXPIRATION_DATE))
                    {
                        CallBack(Constants.PRODUCT_KEY_NOT_AVAILABLE);
                    }

                    CreateRegistry(launchInfo);
                }
                launchInfo.Name = PharmacyServiceConfig.Config.CurrentStore.Name;


                HttpHelper http = new HttpHelper();
                var postdata    = string.Format("ComputerName={0}&CPUSerialNumber={1}&MACAddress={2}&Name={3}&ProductKey={4}&SystemType={5}&ExpirationDate={6}", launchInfo.ComputerName, launchInfo.CPUSerialNumber, launchInfo.MACAddress, launchInfo.Name, launchInfo.ProductKey, launchInfo.SystemType, launchInfo.ExpirationDate);
                try
                {
                    if (PingHelper.Ping())
                    {
                        Log.Error("外部网络正常");
                        // 发送客户端设备信息
                        var strPHtml = http.PostPage(remoteservice + "/api/device/launch", postdata);
                    }
                    else
                    {
                        Log.Error("外部网络不通");
                    }
                }
                catch (Exception)
                {
                }
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
                launchInfo.SerializeJson(filename);

                while (true)
                {
                    launchInfo = JsonSerializeHelper.DeSerializeJson <LaunchInfo>(filename);

                    if (launchInfo == null)
                    {
                        CallBack(Constants.PRODUCT_KEY_NOT_AVAILABLE);
                    }
                    else
                    {
                        var networkIsNotAvailable = PingHelper.Ping();

                        if (networkIsNotAvailable)
                        {
                            try
                            {
                                if (RemoteVerifyPrdKey(launchInfo.ProductKey))
                                {
                                    CallBack(Constants.PRODUCT_KEY_AVAILABLE);
                                }
                                else
                                {
                                    CallBack(Constants.PRODUCT_KEY_NOT_AVAILABLE);
                                }
                            }
                            catch (WebException)
                            {
                                networkIsNotAvailable = false;
                            }
                        }

                        if (!networkIsNotAvailable)
                        {
                            if (OfflineVerify(launchInfo))
                            {
                                CallBack(Constants.PRODUCT_KEY_AVAILABLE);
                            }
                            else
                            {
                                CallBack(Constants.PRODUCT_KEY_NOT_AVAILABLE);
                            }
                        }
                    }

                    Thread.Sleep(new TimeSpan(0, int.Parse(verifyInterval), 0));
                }
            }).Start();
        }