Ejemplo n.º 1
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();
        }