Пример #1
0
        public void Do(string name,  Dictionary<string, string> options, ref Pacient p)
        {
            MethodInfo method;

            if (!_methods.ContainsKey(name))
            {
                method = GetType().GetMethod("_" + name);
                if (method != null)
                    _methods.Add(name, method);
                else
                    return;
            }
            else 
            {
                method = _methods[name];
            }

            var parametrs = new object[2];

            try
            {
                method.Invoke(this, new object[] { p, options });
            }
            catch (Exception exc)
            {
                if (OnException != null)
                {
                    OnException(exc.InnerException.InnerException != null
                        ? new DoctorExceptionArgs(string.Format("Name: {0}\r\n; Exception: {1}\r\n", name,
                            exc.InnerException.InnerException.Message))
                        : new DoctorExceptionArgs(string.Format("Name: {0}\r\n; Exception: {1}\r\n", name, exc.Message)));
                }
            }
        }
Пример #2
0
        public bool Save(Pacient pacient)
        {
            if(_methodSave == null)
                _methodSave = InstanceType.GetMethod("Save");

            return (bool)_methodSave.Invoke(Instance, new object[] { pacient });
        }
Пример #3
0
        private bool _template(ref Pacient pacient, ref StringBuilder tpl, Regex ex, Boolean isFirstMatch)
        {
            if ((ex == null) && (tpl == null)) return false;

            Boolean isContains = false;
            MatchCollection matches = ex.Matches(pacient.Body);
            Int32 mcount = (isFirstMatch && matches.Count > 1) ? 1 : matches.Count;

            // matches
            for (int ctr = 0; ctr < mcount; ctr++)
            {
                //groups
                GroupCollection group = matches[ctr].Groups;
                for (var i = 1; i <= group.Count; i++)
                {
                    if (tpl.ToString().IndexOf("$" + i, StringComparison.Ordinal) >= 0)
                    {
                        isContains = true;
                        tpl.Replace("$" + i, group[i].Value);
                    }
                }

                tpl.Replace("$index", matches[ctr].Index.ToString(CultureInfo.InvariantCulture));
                tpl.Replace("$length", matches[ctr].Length.ToString(CultureInfo.InvariantCulture));
            }

            tpl.Replace("$name", pacient.Name);

            return isContains;
        }
Пример #4
0
        public void _append(ref Pacient pacient, Dictionary<string, string> parameters)
        {
            Boolean isFirstMatch = false;

            var options = RegexOptions.None;
            if (parameters.ContainsKey("options") && !string.IsNullOrEmpty(parameters["options"]))
                RegExUtility.RegexOptionsParse(parameters["options"], ref options,ref isFirstMatch);

            Regex ex = null;
            if (parameters.ContainsKey("regex") && !string.IsNullOrEmpty(parameters["regex"]))
                ex = new Regex(parameters["regex"], options);

            StringBuilder tpl = null;
            if (parameters.ContainsKey("template") && !string.IsNullOrEmpty(parameters["template"]))
                tpl = new StringBuilder(parameters["template"]);

            if (_template(ref pacient, ref tpl, ex, isFirstMatch) &&
                (parameters.ContainsKey("file") && !string.IsNullOrEmpty(parameters["file"])))
            {
                var finfo = new FileInfo(parameters["file"].Replace("%CurrentDirectory%", Directory.GetCurrentDirectory() + @"\"));
                if (OnFile != null)
                    OnFile(new DoctorFileArgs(finfo, tpl.ToString()));
            }
        }
Пример #5
0
        public void _replace(ref Pacient pacient, Dictionary<string, string> parameters)
        {
            var options = RegexOptions.None;
            if (parameters.ContainsKey("options") && !string.IsNullOrEmpty(parameters["options"]))
                RegExUtility.RegexOptionsParse(parameters["options"], ref options);

            if ((parameters.ContainsKey("regex") && parameters.ContainsKey("value")) && 
                (!string.IsNullOrEmpty(parameters["regex"]) && !string.IsNullOrEmpty(parameters["value"]))
                )
            {
                var ex = new Regex(parameters["regex"], options);
                pacient.Body = ex.Replace(pacient.Body, parameters["value"]);
            }

            if ((parameters.ContainsKey("pattern") && parameters.ContainsKey("value")) &&
                (!string.IsNullOrEmpty(parameters["pattern"]) && !string.IsNullOrEmpty(parameters["value"]))
                )
            {
                pacient.Body = pacient.Body.Replace(parameters["pattern"], parameters["value"]);
            }
        }
Пример #6
0
        public void _sql(ref Pacient pacient, Dictionary<string, string> parameters)
        {
            Boolean isFirstMatch = false;

            var options = RegexOptions.None;
            if (parameters.ContainsKey("options") && !string.IsNullOrEmpty(parameters["options"]))
                RegExUtility.RegexOptionsParse(parameters["options"], ref options, ref isFirstMatch);

            Regex ex = null;
            if (parameters.ContainsKey("regex") && !string.IsNullOrEmpty(parameters["regex"]))
                ex = new Regex(parameters["regex"], options);

            StringBuilder tpl = null;
            if (parameters.ContainsKey("query") && !string.IsNullOrEmpty(parameters["query"]))
                tpl = new StringBuilder(parameters["query"]);

            if (_template(ref pacient, ref tpl, ex, isFirstMatch))
            {
                if(OnExecute != null)
                    OnExecute(new DoctorExecuteQueryArgs(tpl.ToString()));
            }
        }
Пример #7
0
 public bool Save(Pacient pacient)
 {
     WritePacient(ref pacient); 
     return false;
 }
Пример #8
0
        private void WritePacient(ref Pacient pacient)
        {
            StreamWriter writer = null;

            try
            {
                writer = new StreamWriter(_mDesDirectory.FullName + pacient.Name);
                writer.Write(pacient.Body);
            }
            catch (Exception ex)
            {
                var e = ex;
            }
            finally
            {
                if (writer != null) writer.Close();
            }
        }
Пример #9
0
/*
        private void FilesCounter(FileInfo file)
        {
            mFilesCount++;
        }

        public delegate void OnFileEventHandler(OnFileEventArgs e);

        public event OnFileEventHandler OnFile;

        private void Recursion(FileSystemInfo[] FSInfo, FileProcess fp)
        {
            foreach (FileSystemInfo f in FSInfo)
            {
                if (f is DirectoryInfo)
                {
                    mDirectoriesCount++;

                    DirectoryInfo dInfo = (DirectoryInfo)f;
                    Recursion(dInfo.GetFileSystemInfos(), fp);
                }
                else if (f is FileInfo)
                {
                    if ((Settings.Extension != string.Empty) && (((FileInfo)f).Extension.ToUpper() == Settings.Extension))
                    {
                        if (this.OnFile != null)
                            this.OnFile(new OnFileEventArgs((FileInfo)f));

                        if (fp != null)
                            fp((FileInfo)f);
                    }
                }
            }
        }

        public void Process(FileProcess fp)
        {
            Recursion(mSrcDirectory.GetFileSystemInfos(), fp);
        }
*/

        private void ReadPacient(ref Pacient pacient)
        {
            StreamReader reader = null;

            try
            {
                reader = new StreamReader( _mSrcDirectory.FullName + pacient.Name);
                pacient.Body = reader.ReadToEnd();
            }
            catch (Exception ex)
            {
                var e = ex;
            }
            finally
            {
                if (reader != null) reader.Close();
            }
        }