Esempio n. 1
0
        void DoLogOn()
        {
            using (ForAssortingKanbanService proxy = new ForAssortingKanbanService())
            {
                proxy.Url = string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}/ForAssortingKanbanService/", this.textBoxServerIP.Text, this.textBoxServicePort.Text);

                CFG_ChannelDto[] cfgChannels = proxy.QueryChannels();
                if (cfgChannels.All(c => c.Code != this.comboBoxCfgChannelCode.Text))
                {
                    this.comboBoxCfgChannelCode.Items.Clear();
                    foreach (CFG_ChannelDto cfgChannel in cfgChannels)
                    {
                        this.comboBoxCfgChannelCode.Items.Add(cfgChannel.Code);
                    }

                    throw new Exception("无效的巷道编码。");
                }
            }

            XmlSerializerWrapper <LocalSettings> localSettingsXmlSerializer = new XmlSerializerWrapper <LocalSettings>();
            LocalSettings localSettings = localSettingsXmlSerializer.Entity;

            localSettings.ServerIP       = this.textBoxServerIP.Text;
            localSettings.ServicePort    = int.Parse(this.textBoxServicePort.Text, CultureInfo.InvariantCulture);
            localSettings.CfgChannelCode = this.comboBoxCfgChannelCode.Text;

            localSettingsXmlSerializer.Save();
        }
Esempio n. 2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //七个分拣口
            for (int i = 1; i <= 7; i++)
            {
                this.comboBoxCfgChannelCode.Items.Add(i.ToString(CultureInfo.InvariantCulture));
            }

            LocalSettings localSettings = new XmlSerializerWrapper <LocalSettings>().Entity;

            this.textBoxServerIP.Text        = localSettings.ServerIP;
            this.textBoxServicePort.Text     = localSettings.ServicePort.ToString(CultureInfo.InvariantCulture);
            this.comboBoxCfgChannelCode.Text = localSettings.CfgChannelCode;

            if (!string.IsNullOrEmpty(localSettings.CfgChannelCode))
            {
                try
                {
                    this.DoLogOn();

                    this.DialogResult = true;
                    this.Close();
                }
                catch { }

                this.autoLogOnTimer          = new DispatcherTimer();
                this.autoLogOnTimer.Interval = TimeSpan.FromMinutes(1);
                this.autoLogOnTimer.Tick    += this.timer_Tick;
                this.autoLogOnTimer.Start();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 初始化主界面的视图模型。
        /// </summary>
        public MainWindowViewModel()
        {
            LocalSettings localSettings = new XmlSerializerWrapper <LocalSettings>().Entity;

            this.serviceUrl = string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}/ForAssortingKanbanService/", localSettings.ServerIP, localSettings.ServicePort);

            this.SetupDesignTimeDatas();
        }
Esempio n. 4
0
        /// <summary>
        /// 启动所有服务。
        /// </summary>
        public void StartServices()
        {
            LocalSettings localSettings = new XmlSerializerWrapper <LocalSettings>().Entity;

            //使用 LocalSettings 里的数据库连接信息覆盖 App.config 里的
            Configuration            configuration            = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ConnectionStringSettings connectionStringSettings = configuration.ConnectionStrings.ConnectionStrings["GeelyPtlEntities"];

            connectionStringSettings.ProviderName     = localSettings.ConnectionStringProviderName;
            connectionStringSettings.ConnectionString = string.Format(CultureInfo.InvariantCulture, localSettings.ConnectionStringFormat, localSettings.ConnectionStringPassword);
            configuration.Save();
            ConfigurationManager.RefreshSection("connectionStrings");

            //确保基础数据已存在于数据库
            BaseDatasInitializer.EnsureInitialized();

            //启动通讯之前重值所有设备的在线状态
            this.DeviceOnLineStatusReset();

            //承载所有接口服务
            ServiceHosts.Open(localSettings.ServiceIP, localSettings.ServicePort);

            //启动设备通讯
            CartPtlHost.Instance.Start();
            ChannelPtlHost.Instance.Start();

            //启动PickZone通讯
            PickZoneHost.Instance.Start();
            //启动FeedZone通讯(分装工位)
            FeedZoneHost.Instance.Start();
            CacheRegionHost.Instance.Start();
            AssemblySectionHost.Instance.Start();

            //启动MarketZone通讯
            MarketZoneHost.Instance.Start();

            //启动任务加载业务
            AssortingExecutorLoader.Instance.Start();
            CartFindingExecutor.Instance.Start();
            IndicatingExecutorLoader.Instance.Start();

            //启动结果回写业务
            AssortResultWriteBack.Instance.Start(localSettings.PtlToLesServiceUrl);
            CartFindingDeliveryResultWriteBack.Instance.Start(localSettings.PtlToLesServiceUrl);
            AssembleResultWriteBack.Instance.Start(localSettings.PtlToMesServiceUrl);

            //启动历史记录清除器
            Ptl.Device.Log.Logger.HoldingPeriodInDays = localSettings.HistoryHoldingDays;
            HistoryRecordsRemover.Instance.Start(localSettings.HistoryHoldingDays);

            //启动AGV配送任务发送业务
            PickAreaService.Instance.Start(localSettings.PtlToAgvServiceUrl);
            ProductAreaService.Instance.Start(localSettings.PtlToAgvServiceUrl);
            InitService.Instance.Start(localSettings.PtlToAgvServiceUrl);

            //启动状态监控
            this.StartRunningStatusRefreshThread();
        }
Esempio n. 5
0
        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                XmlSerializerWrapper <LocalSettings> xmlSerializer = new XmlSerializerWrapper <LocalSettings>();
                LocalSettings localSettings = xmlSerializer.Entity;

                bool connectionStringChanged = false;
                if (localSettings.ConnectionStringProviderName != this.viewModel.ConnectionStringProviderName ||
                    localSettings.ConnectionStringFormat != this.viewModel.ConnectionStringFormat ||
                    localSettings.ConnectionStringPassword != this.viewModel.ConnectionStringPassword)
                {
                    if (MessageBox.Show(@"注意:

修改数据库连接信息需要重新启动应用程序,确定修改并重启?

请先确保没有正在进行的作业。
", "服务设置", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) == MessageBoxResult.Yes)
                    {
                        connectionStringChanged = true;
                    }
                }

                localSettings.ServiceIP                    = this.viewModel.ServiceIP;
                localSettings.ServicePort                  = this.viewModel.ServicePort;
                localSettings.PtlToLesServiceUrl           = string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}/Service/PtlToLesService", this.viewModel.LesServiceIP, this.viewModel.LesServicePort);
                localSettings.PtlToMesServiceUrl           = string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}/mes-interface/remote/toMes", this.viewModel.MesServiceIP, this.viewModel.MesServicePort);
                localSettings.PtlToAgvServiceUrl           = string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}/rcs/services/rest/hikRpcService", this.viewModel.AgvServiceIP, this.viewModel.AgvServicePort);
                localSettings.ConnectionStringProviderName = this.viewModel.ConnectionStringProviderName;
                localSettings.ConnectionStringFormat       = this.viewModel.ConnectionStringFormat;
                localSettings.ConnectionStringPassword     = this.viewModel.ConnectionStringPassword;
                localSettings.HistoryHoldingDays           = this.viewModel.HistoryHoldingDays;

                xmlSerializer.Save();

                if (connectionStringChanged)
                {
                    Process.Start(Application.ResourceAssembly.Location);
                    Application.Current.Shutdown();

                    return;
                }
                else
                {
                    this.viewModel.RestartSafelyServices();

                    MessageBox.Show("保存成功并重新启动各业务服务。", "服务设置", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "服务设置", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 开启AGV服务
        /// </summary>
        public void OpenAgvServices()
        {
            LocalSettings localSettings = new XmlSerializerWrapper <LocalSettings>().Entity;

            PickAreaService.Instance.Stop();
            ProductAreaService.Instance.Stop();
            InitService.Instance.Stop();

            PickAreaService.Instance.Start(localSettings.PtlToAgvServiceUrl);
            ProductAreaService.Instance.Start(localSettings.PtlToAgvServiceUrl);
            InitService.Instance.Start(localSettings.PtlToAgvServiceUrl);
        }
Esempio n. 7
0
        /// <summary>
        /// 重新启动所有可临时中断的服务。
        /// </summary>
        public void RestartSafelyServices()
        {
            LocalSettings localSettings = new XmlSerializerWrapper <LocalSettings>().Entity;

            //停止所有可临时中断的服务
            this.StopRunningStatusRefreshThread();

            PickAreaService.Instance.Stop();
            ProductAreaService.Instance.Stop();
            InitService.Instance.Stop();

            HistoryRecordsRemover.Instance.Stop();

            AssortResultWriteBack.Instance.Stop();
            CartFindingDeliveryResultWriteBack.Instance.Stop();
            AssembleResultWriteBack.Instance.Stop();

            AssortingExecutorLoader.Instance.Stop();
            CartFindingExecutor.Instance.Stop();
            IndicatingExecutorLoader.Instance.Stop();

            ServiceHosts.Close();

            //启动所有可临时中断的服务
            ServiceHosts.Open(localSettings.ServiceIP, localSettings.ServicePort);

            AssortingExecutorLoader.Instance.Start();
            CartFindingExecutor.Instance.Start();
            IndicatingExecutorLoader.Instance.Start();

            AssortResultWriteBack.Instance.Start(localSettings.PtlToLesServiceUrl);
            CartFindingDeliveryResultWriteBack.Instance.Start(localSettings.PtlToLesServiceUrl);
            AssembleResultWriteBack.Instance.Start(localSettings.PtlToMesServiceUrl);

            HistoryRecordsRemover.Instance.Start(localSettings.HistoryHoldingDays);

            //启动AGV配送任务发送业务
            PickAreaService.Instance.Start(localSettings.PtlToAgvServiceUrl);
            ProductAreaService.Instance.Start(localSettings.PtlToAgvServiceUrl);
            InitService.Instance.Start(localSettings.PtlToAgvServiceUrl);

            this.StartRunningStatusRefreshThread();
        }
Esempio n. 8
0
        void InitializeSettings()
        {
            LocalSettings localSettings      = new XmlSerializerWrapper <LocalSettings>().Entity;
            Uri           ptlToLesServiceUrl = new Uri(localSettings.PtlToLesServiceUrl);
            Uri           ptlToMesServiceUrl = new Uri(localSettings.PtlToMesServiceUrl);
            Uri           ptlToAgvServiceUrl = new Uri(localSettings.PtlToAgvServiceUrl);

            this.ServiceIP      = localSettings.ServiceIP;
            this.ServicePort    = localSettings.ServicePort;
            this.LesServiceIP   = ptlToLesServiceUrl.Host;
            this.LesServicePort = ptlToLesServiceUrl.Port;
            this.MesServiceIP   = ptlToMesServiceUrl.Host;
            this.MesServicePort = ptlToMesServiceUrl.Port;
            this.AgvServiceIP   = ptlToAgvServiceUrl.Host;
            this.AgvServicePort = ptlToAgvServiceUrl.Port;
            this.ConnectionStringProviderName = localSettings.ConnectionStringProviderName;
            this.ConnectionStringFormat       = localSettings.ConnectionStringFormat;
            this.ConnectionStringPassword     = localSettings.ConnectionStringPassword;
            this.HistoryHoldingDays           = localSettings.HistoryHoldingDays;
        }
        /// <summary>
        /// Client执行接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="request"></param>
        /// <returns></returns>
        public static T Excute <T>(BasicRequest <T> request) where T : BasicResponse
        {
            //设置request对象的随机字符串
            request.NonceStr = RandomStringBulider.Generate(32);

            //1.首先执行参数验证,如果参数提供有误,会抛出异常
            request.Validate();

            //2.得到请求的所有参数字典,调用request.GetParameterDict()可以获得Request的应用参数,同时要将SYS_PARAMETER_DICT系统参数也加入
            Dictionary <string, string> paramterDict = request.GetParameterDict()
                                                       .Concat(WechatPaymentConfig.SYS_PARAMETER_DICT).ToDictionary(k => k.Key, v => v.Value);

            //3.将参数字典的key值按字母顺序排序(按ASCII排序,例如a在b前面)
            SortedDictionary <string, string> sortedParameterDict = SortDictionaryConverter.Convert(paramterDict);

            //4.拼接计算Sign参数
            string sign = SignBulider.Generate(sortedParameterDict, WechatPaymentConfig.SECRET);

            //5.将sign参数加入到参数字典中
            paramterDict.Add("sign", sign);

            //6.将paramterDict字典转化为XML格式
            string requestXml = XmlStringBulider.Generate(paramterDict);

            //7.提交请求到微信服务器,获取响应的字符串
            //HACK(Teroy):退款API在POST的时候要带证书,其他API请求不用
            string responseXml = request.IsPostRequireCertificate ?
                                 HttpRequestWrapper.PostXmlWithCertificate(request.ApiUrl, requestXml) : HttpRequestWrapper.PostXml(request.ApiUrl, requestXml);

            //8.将响应的XML数据实例化为T类型
            T result = XmlSerializerWrapper.Deserialize <T>(responseXml);

            //9.将响应的XML数据预存到Body中
            result.Body = responseXml;

            return(result);
        }
 public string Parse <XmlDto>(XmlDto from)
 {
     try
     {
         using (var ms = new MemoryStream())
         {
             using (XmlWriter xw = new XmlTextWriter(ms, Encoding.UTF8))
             {
                 var ser = new XmlSerializerWrapper(from.GetType());
                 ser.WriteObject(xw, from);
                 xw.Flush();
                 ms.Seek(0, SeekOrigin.Begin);
                 using (var reader = new StreamReader(ms))
                 {
                     return(reader.ReadToEnd());
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw new SerializationException(string.Format("Error serializing object of type {0}", from.GetType().FullName), ex);
     }
 }
Esempio n. 11
0
        public void Deserialize_输入UnifiedOrderResponse对象的xml字符串_解析正确()
        {
            //arrange
            string xmlStr = @"
                            <xml>
                                <return_code><![CDATA[SUCCESS]]></return_code>
                                <return_msg><![CDATA[OK]]></return_msg>
                                <appid><![CDATA[wx2421b1c4370ec43b]]></appid>
                                <mch_id><![CDATA[10000100]]></mch_id>
                                <nonce_str><![CDATA[IITRi8Iabbblz1Jc]]></nonce_str>
                                <sign><![CDATA[7921E432F65EB8ED0CE9755F0E86D72F]]></sign>
                                <result_code><![CDATA[SUCCESS]]></result_code>
                                <prepay_id><![CDATA[wx201411101639507cbf6ffd8b0779950874]]></prepay_id>
                                <trade_type><![CDATA[JSAPI]]></trade_type>
                            </xml>";

            //act
            UnifiedOrderResponse target = XmlSerializerWrapper.Deserialize <UnifiedOrderResponse>(xmlStr);

            //assert
            Assert.IsTrue(target.Code == "SUCCESS");
            Assert.IsTrue(target.Message == "OK");
            Assert.IsTrue(target.IsSuccess);
        }
Esempio n. 12
0
        void ThreadStart()
        {
            while (true)
            {
                try
                {
                    //第一次需要额外获取分拣口名称
                    if (this.channelId == null)
                    {
                        LocalSettings localSettings = new XmlSerializerWrapper <LocalSettings>().Entity;

                        using (ForAssortingKanbanService proxy = new ForAssortingKanbanService())
                        {
                            proxy.Url = this.serviceUrl;

                            CFG_ChannelDto[] cfgChannels = proxy.QueryChannels();
                            CFG_ChannelDto   cfgChannel  = cfgChannels
                                                           .First(c => c.Code == localSettings.CfgChannelCode);

                            this.channelId   = cfgChannel.Id;
                            this.ChannelName = cfgChannel.Name;
                            this.TaskInfo    = proxy.QueryCurrentTaskInfo(this.channelId.Value);

                            if (this.TaskInfo.CurrentBatchInfo.PickType == "P") //PTL料架拣料
                            {
                                this.TodayStatistics = proxy.QueryTodayStatistics(this.channelId.Value);
                            }
                            else
                            {
                                this.TodayStatistics = proxy.QueryPDATodayStatistics(this.channelId.Value);
                            }
                        }
                    }

                    using (ForAssortingKanbanService proxy = new ForAssortingKanbanService())
                    {
                        proxy.Url = this.serviceUrl;

                        this.TaskInfo = proxy.QueryCurrentTaskInfo(this.channelId.Value);

                        //每 10 秒一次汇总
                        if (DateTime.Now.Second % 10 == 0)
                        {
                            if (this.TaskInfo.CurrentBatchInfo.PickType == "P") //PTL料架拣料
                            {
                                this.TodayStatistics = proxy.QueryTodayStatistics(this.channelId.Value);
                            }
                            else
                            {
                                this.TodayStatistics = proxy.QueryPDATodayStatistics(this.channelId.Value);
                            }
                        }
                    }

                    this.ServiceError = false;
                }
                catch
                {
                    this.ServiceError = true;
                }
                finally
                {
                    Thread.Sleep(this.pollingPeriod);
                }
            }
        }
        /// <summary>
        /// 将微信支付自动通知的xml字符串数据转化为PaymentResultNotifyResponse对象
        /// </summary>
        /// <param name="notifyXmlStr">xml字符串数据</param>
        /// <returns></returns>
        public static PaymentResultNotify ToPaymentResultNotify(string notifyXmlStr)
        {
            PaymentResultNotify result = XmlSerializerWrapper.Deserialize <PaymentResultNotify>(notifyXmlStr);

            return(result);
        }
Esempio n. 14
0
        private void ProcessRequest(HttpListenerContext context)
        {
            HttpListenerResponse response = context.Response;
            HttpListenerRequest  request  = context.Request;

            try
            {
                if (request.HttpMethod.ToLower().Equals("get"))
                {
                    string rawUrl = System.Web.HttpUtility.UrlDecode(request.RawUrl);

                    #region 获取版本信息
                    if (rawUrl.StartsWith(search_version))
                    {
                        string groupid = context.Request.QueryString["groupid"];

                        XmlSerializerWrapper <RFEntity.XmlUpdateFiles> xmlSerializer_UpdateFiles = new XmlSerializerWrapper <RFEntity.XmlUpdateFiles>();
                        List <RFEntity.UpdateFile> lstUpdateFile = xmlSerializer_UpdateFiles.Entity.lstupdatefiles;
                        if (lstUpdateFile != null && lstUpdateFile.Count > 0)
                        {
                            RFEntity.UpdateFile file = lstUpdateFile.Find(item => { return(item.groupid.ToString() == groupid); });
                            if (file != null)
                            {
                                string files = JsonHelper.GetJson(file);
                                Response(context, files);
                            }
                        }
                    }
                    #endregion

                    #region  载文件
                    if (rawUrl.StartsWith(download_files))
                    {
                        string groupid     = context.Request.QueryString["groupid"];
                        string versioninfo = context.Request.QueryString["versioninfo"];

                        XmlSerializerWrapper <RFEntity.XmlUpdateFiles> xmlSerializer_UpdateFiles = new XmlSerializerWrapper <RFEntity.XmlUpdateFiles>();
                        List <RFEntity.UpdateFile> lstUpdateFile = xmlSerializer_UpdateFiles.Entity.lstupdatefiles;
                        if (lstUpdateFile != null && lstUpdateFile.Count > 0)
                        {
                            RFEntity.UpdateFile file = lstUpdateFile.Find(item => { return(item.groupid.ToString() == groupid && item.versioninfo == versioninfo); });
                            if (file != null && !string.IsNullOrEmpty(file.filepath) && File.Exists(file.filepath))
                            {
                                response.StatusCode = 200;

                                FileStream fileStream = new System.IO.FileStream(file.filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
                                int        l          = 0;
                                byte[]     fileBytes  = new byte[1024];
                                while ((l = fileStream.Read(fileBytes, 0, fileBytes.Length)) > 0)
                                {
                                    response.OutputStream.Write(fileBytes, 0, l);
                                }
                                fileStream.Close();
                                fileStream.Dispose();
                                response.OutputStream.Close();
                            }
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                myLogFile.WriteErrLogFile("客户端获取文件信息异常" + request.RemoteEndPoint.Address + ";" + ex);
            }

            try
            {
                if (response != null)
                {
                    response.Close();
                }
            }
            catch
            {
            }
        }