private void PrcessExistingFiles() { List<FileInfo> fsList; try { fsList = CommUtil.GetProcessFiles(this.InputUNC); if (fsList.Count >= 0) { foreach (var f in fsList) { if (!_processingFileList.Contains(f.FullName)) { _processingFileList.Add(f.FullName); CreateProcessThread(f.FullName); } } } } catch (Exception ex) { Loghelper.Write(LogLevel.Error, ex.Message); } finally { fsList = null; } }
public void StartMonitorFolder() { if (_processingFileList == null) { _processingFileList = new ThreadSafeList<string>(); } if (_fSWatcher == null) { PrcessExistingFiles(); try { _fSWatcher = new FileSystemWatcher(); _fSWatcher.Path = this.InputUNC; _fSWatcher.Created += new FileSystemEventHandler(FSWatcher_Created); _fSWatcher.EnableRaisingEvents = true; // re-config NotifyFilter & IncludeSubdirectories to saving resource _fSWatcher.IncludeSubdirectories = false; _fSWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName; this.FMSObjStatus = "Start"; } catch (Exception ex) { Loghelper.Write(LogLevel.Error, ex.Message); _fSWatcher = null; } finally { } } }
private void FSWatcher_Created(object sender, FileSystemEventArgs e) { if (!_processingFileList.Contains(e.FullPath)) { //Add2ProcessFileList(e.FullPath); //CreateProcessThread(e.FullPath); } else { Loghelper.Write(LogLevel.Warning, e.FullPath + ": File exist in ProcessList!!"); } CreateProcessThread(e.FullPath); }
private XmlDocument LoadConfigDocument() { XmlDocument doc = null; try { doc = new XmlDocument(); doc.Load((string)GetConfigFilePath()); } catch (Exception e) { Loghelper.Write(LogLevel.Error, "No configuration file found." + e.Message); } return(doc); }
private ThreadedBindingList <FMSbaseObj> LoadSettingtoList() { ThreadedBindingList <FMSbaseObj> result = new ThreadedBindingList <FMSbaseObj>(); XmlDocument doc; XmlNode node; try {// load config document for current assembly doc = LoadConfigDocument(); // retrieve TMOConfigurations node = doc.SelectSingleNode("//TMOConfigurations"); if (node != null) { foreach (XmlElement selectNode in node.SelectNodes("//TMOConfiguration")) { try { var _maxt = 1; if (!int.TryParse(selectNode.GetAttribute("MaxProcessThreads"), out _maxt)) { _maxt = 1; } FMSbaseObj o = FMSbaseObj.CreateFMSObj(selectNode.GetAttribute("Id"), selectNode.GetAttribute("InputUNC"), selectNode.GetAttribute("OutputUNC"), selectNode.GetAttribute("StoreProcedure"), _maxt, selectNode.GetAttribute("Classname")); result.Add(o); } catch (Exception ex) { Loghelper.Write(LogLevel.Error, ex.Message); } } } } catch (Exception e) { Loghelper.Write(LogLevel.Error, e.Message); } finally { node = null; doc = null; } return(result); }
private void DoProcessFile(string processFN) { Add2ProcessFileList(processFN); int _tickstart = Environment.TickCount; int _processTimeofReadfile = -1; int _processTimeofProcedure = -1; int _processTimeofOutput = -1; int _processTime = -1; int _tryTimes = 1; string _errormsg = ""; if (processFN != "") { try { _tryTimes = CommUtil.InputFileTryTimes; // check file lock CommUtil.CheckFileLock(processFN, ref _tryTimes); // read file content var textLines = ReadFilelines(processFN); // remove file right after read content if (File.Exists(processFN)) { File.Delete(processFN); } else { throw new Exception("File does not exist before try to delete"); } _processTimeofReadfile = Environment.TickCount - _tickstart; _tickstart = Environment.TickCount; // get SN# var _snnumber = GetSNNumber(processFN); //process file content and get output values string[] outputValues = GetOutputValues(_snnumber, textLines); _processTimeofProcedure = Environment.TickCount - _tickstart; _tickstart = Environment.TickCount; // get output file name from output parameter "COMMAND1" 1st segment var outputFN = outputValues[0].Split(';')[0]; // remove filename from returned parameters outputValues[0] = outputValues[0].Substring(outputValues[0].IndexOf(';') + 1); // connect outputvalues into one string var _outputvalues_s = String.Join("", outputValues); outputValues = new string[] { _outputvalues_s }; // output to file if (outputFN != "") { if (CommUtil.WritetoFile(Path.Combine(this.OutputUNC, outputFN + ".sf"), outputValues)) { // remove file //File.Delete(processFN); } } else { textLines = null; outputValues = null; throw new Exception("Output FileName is Empty!!"); } textLines = null; outputValues = null; _processTimeofOutput = Environment.TickCount - _tickstart; } catch (Exception ex) { _errormsg = ":Error:" + ex.Message; } } _processTime = _processTimeofReadfile + _processTimeofProcedure + _processTimeofOutput; #region write log if (Loghelper.IfneedTestLog) { Loghelper.SetThreadContext(this.Id, processFN, _tryTimes, _processTimeofOutput, _processTimeofProcedure, _processTimeofOutput); } string _log = String.Format("{0}{1}:{2}|{3}|{4}|{5}|{6}", processFN, _errormsg, _tryTimes, _processTimeofReadfile, _processTimeofProcedure, _processTimeofOutput, _processTime); var _loglevel = (_errormsg != "") ? LogLevel.Error : ((_tryTimes > 1) ? LogLevel.Warning : LogLevel.Info); Loghelper.Write(_loglevel, _log); #endregion // ** remove file from ProcessingFileList RemoveFromProcessFileList(processFN); //return null; }