コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: radtek/ifDataHouse
        /// <summary>
        /// Process File
        /// </summary>
        /// <param name="fullPath"></param>
        private void Process(string fullPath)
        {
            bool canRemoveErrorFile = true;

            string nextDir = System.IO.Path.Combine(TskBaseConfig.ErrorFilePath, DateTime.Today.ToString("yyyy-MM-dd"));

            try
            {
                if (IsFileClosed(fullPath))
                {
                    using (FileStream fs = File.Open(fullPath, FileMode.Open, FileAccess.Read))
                    {
                        using (StreamReader reader = new StreamReader(fs))
                        {
                            string s = reader.ReadLine();
                            InspectServiceClient client = new InspectServiceClient("BasicHttpBinding_IInspectService",
                                                                                   TskBaseConfig.InspectServiceAddress);
                            ProcessMessage msg    = client.CreateInspect(s);
                            string         msgStr = msg.GetMessageContent();
                            if (msg.Result)
                            {
                                setWatchContent(msgStr, false);
                                nextDir = System.IO.Path.Combine(TskBaseConfig.MovedFilePath, DateTime.Today.ToString("yyyy-MM-dd"));
                            }
                            else
                            {
                                setWatchContent(msgStr);
                                LogUtil.Logger.Error(msgStr);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogUtil.Logger.Error(e.GetType());
                //if (e is System.ServiceModel.EndpointNotFoundException) {
                canRemoveErrorFile = false;
                //}
                setWatchContent(e.Message);
                LogUtil.Logger.Error(e.Message);
            }
            // 是否可以访问服务 不可以访问时保持文件不处理
            if (canRemoveErrorFile)
            {
                // 是否删除文件
                if (TskBaseConfig.DeleteFileAfterRead)
                {
                    // 删除文件
                    if (IsFileClosed(fullPath))
                    {
                        File.Delete(fullPath);
                        LogUtil.Logger.Warn("【删除读完的数据文件】" + fullPath);
                    }
                }
                else
                {
                    // 移动文件
                    CheckDirectory(nextDir);
                    MoveFile(fullPath, System.IO.Path.Combine(nextDir, System.IO.Path.GetFileName(fullPath)));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Process File
        /// </summary>
        /// <param name="fullPath"></param>
        private void Process(string fullPath)
        {
            bool canRemoveErrorFile = true;

            string nextDir = System.IO.Path.Combine(TskBaseConfig.ErrorFilePath, DateTime.Today.ToString("yyyy-MM-dd"));
            try
            {
                if (IsFileClosed(fullPath))
                {
                    using (FileStream fs = File.Open(fullPath, FileMode.Open, FileAccess.Read))
                    {
                        using (StreamReader reader = new StreamReader(fs))
                        {
                            string s = reader.ReadLine();
                            InspectServiceClient client = new InspectServiceClient("BasicHttpBinding_IInspectService",
                                TskBaseConfig.InspectServiceAddress);
                            ProcessMessage msg = client.CreateInspect(s);
                            string msgStr=msg.GetMessageContent();
                            if (msg.Result)
                            {
                                setWatchContent(msgStr, false);
                                nextDir = System.IO.Path.Combine(TskBaseConfig.MovedFilePath, DateTime.Today.ToString("yyyy-MM-dd"));
                            }
                            else
                            {
                                setWatchContent(msgStr);
                                LogUtil.Logger.Error(msgStr);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogUtil.Logger.Error(e.GetType());
               //if (e is System.ServiceModel.EndpointNotFoundException) {
                    canRemoveErrorFile = false;
                //}
                    setWatchContent(e.Message);
                LogUtil.Logger.Error(e.Message);
            }
            // 是否可以访问服务 不可以访问时保持文件不处理
            if (canRemoveErrorFile)
            {
                // 是否删除文件
                if (TskBaseConfig.DeleteFileAfterRead)
                {
                    // 删除文件
                    if (IsFileClosed(fullPath))
                    {
                        File.Delete(fullPath);
                        LogUtil.Logger.Warn("【删除读完的数据文件】" + fullPath);
                    }
                }
                else
                {
                    // 移动文件
                    CheckDirectory(nextDir);
                    MoveFile(fullPath, System.IO.Path.Combine(nextDir, System.IO.Path.GetFileName(fullPath)));
                }
            }
        }