Beispiel #1
0
        //#ResolveConstants
        public static string ResolveConstants(string text)
        {
            try
            {
                if (!text.Contains("%"))
                {
                    return(text);
                }
                var toBeRplStr = "";
                toBeRplStr = "%Now%".ToLower();
                if (text.ToLower().Contains(toBeRplStr))
                {
                    var rplStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    text = Regex.Replace(text, toBeRplStr, rplStr, RegexOptions.IgnoreCase);
                }
                toBeRplStr = "%UtcNow%".ToLower();
                if (text.ToLower().Contains(toBeRplStr))
                {
                    var rplStr = SystemTimeHelper.UtcNow().ToString("yyyy-MM-dd HH:mm:ss");
                    text = Regex.Replace(text, toBeRplStr, rplStr, RegexOptions.IgnoreCase);
                }

                return(ResolveSpecialFolder(text));
            }
            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + TypeName + ".ResolveDefaultVariables Error: " + ex.Message);
            }
        }
Beispiel #2
0
 private void RunningErrorViewer_Load(object sender, EventArgs e)
 {
     labelError.Text         = WinformRes.ErrorMsg + ":";
     richTextBoxError.Text   = ErrorText + ExceptionMsg;
     richTextBoxError.Height = Height - panelTop.Height - panelBottom.Height - 28;
     OccurringTime           = SystemTimeHelper.UtcNow().ToString("yy-MM-dd HH:mm");
 }
Beispiel #3
0
 private void textBoxMsg_MouseUp(object sender, MouseEventArgs e)
 {
     _mouseButtons = e.Button;
     if (e.Button == MouseButtons.Right)
     {
         _lastRightClickTime = SystemTimeHelper.UtcNow();
     }
 }
Beispiel #4
0
 private void RaiseWork(BackgroundWorker worker, ThreadTask task)
 {
     task.Status    = TaskStatus.Processing;
     task.StartTime = SystemTimeHelper.Now();
     worker.RunWorkerAsync(task);
     if (OnTaskStart != null)
     {
         OnTaskStart(this, new TaskEventArgs(task.Id, task.DisplayName, task.TransactionParamsObj));
     }
 }
 //#proc
 private void RaiseDoWork(BackgroundWorker worker, Task task)
 {
     task.Status    = TaskStatus.Processing;
     task.StartTime = SystemTimeHelper.Now();
     worker.RunWorkerAsync(task);
     if (OnTaskStart != null)
     {
         OnTaskStart(this, new TaskIdParamObjEventArgs(task.Id, task.ParamObj));
     }
 }
Beispiel #6
0
        private async void UpdateSystemTime_OnClick(object sender, RoutedEventArgs e)
        {
            IsSearching = true;
            string result = string.Empty;
            await Task.Run(() => { SystemTimeHelper.UpdateSystemTime(out result); });

            Application.Current.Dispatcher?.Invoke(() =>
            {
                MessageBox.Show(Window.GetWindow(this), result, "提示");
            });

            IsSearching = false;
        }
Beispiel #7
0
        ////////////////////////////////////////
        //##following is no use



        private void textBoxMsg_MouseDown(object sender, MouseEventArgs e)
        {
            var now = SystemTimeHelper.UtcNow();
            var ts1 = new TimeSpan(_lastRightClickTime.Ticks);
            var ts2 = new TimeSpan(now.Ticks);
            var ts  = ts2.Subtract(ts1).Duration();

            if (_mouseButtons == MouseButtons.Right && e.Button == MouseButtons.Right && (ts.Milliseconds < 300))
            {
                if ((FormWidth - 200 > 100))
                {
                    FormWidth = FormWidth - 200;
                    ResizeComponent();
                }
            }
        }
Beispiel #8
0
 private void FixSystemTime(DateTime time)
 {
     try
     {
         SystemTimeHelper.SetLocalTime(time);
         LogHelper.Log($@"{true}|{string.Empty}");
     }
     catch (Exception e)
     {
         LogHelper.Log($@"{false}{DataSepartor}{e.Message}");
     }
     finally
     {
         Environment.Exit(0);
     }
 }
        //*resolve
        public static string ResolveConstants(string text)
        {
            if (!text.Contains("%"))
            {
                return(text);
            }
            var toBeRplStr = "";

            toBeRplStr = "%Now%".ToLower();
            if (text.ToLower().Contains(toBeRplStr))
            {
                var rplStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                text = Regex.Replace(text, toBeRplStr, rplStr, RegexOptions.IgnoreCase);
            }
            toBeRplStr = "%UtcNow%".ToLower();
            if (text.ToLower().Contains(toBeRplStr))
            {
                var rplStr = SystemTimeHelper.UtcNow().ToString("yyyy-MM-dd HH:mm:ss");
                text = Regex.Replace(text, toBeRplStr, rplStr, RegexOptions.IgnoreCase);
            }

            toBeRplStr = "%r%".ToLower();
            if (text.ToLower().Contains(toBeRplStr))
            {
                var rplStr = "\r";
                text = Regex.Replace(text, toBeRplStr, rplStr, RegexOptions.IgnoreCase);
            }

            toBeRplStr = "%n%".ToLower();
            if (text.ToLower().Contains(toBeRplStr))
            {
                var rplStr = "\n";
                text = Regex.Replace(text, toBeRplStr, rplStr, RegexOptions.IgnoreCase);
            }

            toBeRplStr = "%t%".ToLower();
            if (text.ToLower().Contains(toBeRplStr))
            {
                var rplStr = "\t";
                text = Regex.Replace(text, toBeRplStr, rplStr, RegexOptions.IgnoreCase);
            }

            return(ResolveSpecialFolder(text));
        }
        private void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            lock (_threadLock)
            {
                var result        = (TaskResult)(e.Result);
                var completedTask = _tasks.Find(x => x.Id == result.TaskId);
                completedTask.Status       = TaskStatus.Completed;
                completedTask.CompleteTime = SystemTimeHelper.Now();
                if (OnTaskComplete != null)
                {
                    OnTaskComplete(this, new TaskIdParamObjResultObjEventArgs(result.TaskId, completedTask.ParamObj, result.ResultObj));
                }

                var processingTasks = _tasks.Where(x => x.Status == TaskStatus.Processing);
                var processingTaskIdentityFlagList = processingTasks.Where(x => !x.IdentityFlag.IsNullOrEmpty()).Select(x => x.IdentityFlag).Distinct().ToList();
                var toBeProcessedTasks             = _tasks.FindAll(x => (x.Status == TaskStatus.Waiting) & (x.IdentityFlag.IsNullOrEmpty() | !processingTaskIdentityFlagList.Contains(x.IdentityFlag)));
                if (toBeProcessedTasks.Count > 0)
                {
                    var worker = (BackgroundWorker)(sender);
                    if (worker.IsBusy == false)
                    {
                        var toBeProcessedTask = toBeProcessedTasks.FirstOrDefault();
                        if (toBeProcessedTask != null)
                        {
                            toBeProcessedTask.WorkerId = result.WorkerId;
                            RaiseDoWork(worker, toBeProcessedTask);
                        }
                    }
                }

                var waitingOrProcessingTasks = _tasks.FindAll(x => x.Status == TaskStatus.Waiting | x.Status == TaskStatus.Processing);
                if (waitingOrProcessingTasks.Count == 0)
                {
                    if (OnAllTasksComplete != null)
                    {
                        OnAllTasksComplete(this, new EventArgs());
                    }
                }
            }
        }
Beispiel #11
0
        private void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            lock (_threadLock)
            {
                var result        = (TaskCompletedResult)(e.Result);
                var completedTask = _tasks.Find(x => x.Id == result.TaskId);
                completedTask.Status       = TaskStatus.Completed;
                completedTask.CompleteTime = SystemTimeHelper.Now();
                if (OnTaskComplete != null)
                {
                    OnTaskComplete(this, new TaskResultEventArgs(result.TaskId, completedTask.DisplayName, completedTask.TransactionParamsObj, result.ResultObj));
                }

                var toBeProcessedTasks = _tasks.FindAll(x => x.Status == TaskStatus.Waiting);
                if (toBeProcessedTasks.Count > 0)
                {
                    var worker = (BackgroundWorker)(sender);
                    if (worker.IsBusy == false)
                    {
                        var toBeProcessedTask = toBeProcessedTasks.FirstOrDefault();
                        if (toBeProcessedTask != null)
                        {
                            toBeProcessedTask.WorkerId = result.WorkerId;
                            RaiseWork(worker, toBeProcessedTask);
                        }
                    }
                }

                var waitingOrProcessingTasks = _tasks.FindAll(x => x.Status == TaskStatus.Waiting | x.Status == TaskStatus.Processing);
                if (waitingOrProcessingTasks.Count == 0)
                {
                    if (OnAllTasksComplete != null)
                    {
                        OnAllTasksComplete(this, new EventArgs());
                    }
                }
            }
        }
        //#method
        public int Join(WorkDelegate workDelegate, Object paramObj)
        {
            lock (_threadLock)
            {
                _id++;
                var task = new Task(_id, paramObj, workDelegate);
                task.JoinTime = SystemTimeHelper.Now();
                task.Status   = TaskStatus.Waiting;
                _tasks.Add(task);

                if (OnTaskJoin != null)
                {
                    var args = new TaskIdParamObjEventArgs(_id, paramObj);
                    OnTaskJoin(this, args);
                }

                var processingTasks = _tasks.Where(x => x.Status == TaskStatus.Processing);
                var processingTaskIdentityFlagList = processingTasks.Where(x => !x.IdentityFlag.IsNullOrEmpty()).Select(x => x.IdentityFlag).Distinct().ToList();
                if (!task.IdentityFlag.IsNullOrEmpty() & processingTaskIdentityFlagList.Contains(task.IdentityFlag))
                {
                    return(_id);
                }

                int i;
                for (i = 0; i < _workerCount; i++)
                {
                    if (!_workers[i].IsBusy)
                    {
                        task.WorkerId = i;
                        task.Status   = TaskStatus.Processing;
                        RaiseDoWork(_workers[i], task);
                        break;
                    }
                }
                return(_id);
            }
        }
Beispiel #13
0
        public string Join(WorkDelegate workDelegate, string displayName, Object transactionParams)
        {
            lock (_threadLock)
            {
                var id   = "".ToUniqueStringByShortGuid(null);
                var task = new ThreadTask(workDelegate, id, displayName, transactionParams);
                task.JoinTime = SystemTimeHelper.Now();
                task.Status   = TaskStatus.Waiting;
                _tasks.Add(task);

                if (OnTaskJoin != null)
                {
                    var args = new TaskEventArgs(id, displayName, transactionParams);
                    OnTaskJoin(this, args);
                }

                int  i;
                bool isWorkerPoolBusy = true;
                for (i = 0; i < _workerNum; i++)
                {
                    if (!_workers[i].IsBusy)
                    {
                        task.WorkerId = i;
                        task.Status   = TaskStatus.Processing;
                        RaiseWork(_workers[i], task);
                        isWorkerPoolBusy = false;
                        break;
                    }
                }
                if (isWorkerPoolBusy)
                {
                    task.Status = TaskStatus.Waiting;
                }
                return(id);
            }
        }
 public static bool IsFutureTime(this DateTime target)
 {
     return(target > SystemTimeHelper.UtcNow());
 }
 public static bool IsPastTime(this DateTime target)
 {
     return(target < SystemTimeHelper.UtcNow());
 }
Beispiel #16
0
        public static string GetText(string funcName, string[] funcParamArray)
        {
            //*common
            if (funcName.ToLower() == "empty" | funcName.ToLower() == "null")
            {
                return(string.Empty);
            }
            else if (funcName.ToLower() == "DateTime".ToLower())
            {
                var customFormat = "yyyy-MM-dd HH:mm:ss";
                if (funcParamArray[0].ToLower() == "UtcNow".ToLower())
                {
                    var time = SystemTimeHelper.UtcNow(); //
                    return(time.ToString(customFormat, DateTimeFormatInfo.InvariantInfo));
                }
                else if (funcParamArray[0].ToLower() == "Now".ToLower())
                {
                    var time = SystemTimeHelper.Now(); //
                    return(time.ToString(customFormat, DateTimeFormatInfo.InvariantInfo));
                }
                else
                {
                    throw new ArgumentException("funcName: " + funcName + " has no param " + funcParamArray[0] + "! ");
                }
            }
            else if (funcName.ToLower() == "UniqueCode".ToLower())
            {
                if (funcParamArray[0] == "ByNow")
                {
                    var baseStr   = funcParamArray.Length > 1 ? funcParamArray[1] : "";
                    var separator = funcParamArray.Length > 2 ? funcParamArray[2] : "";
                    return(baseStr.ToUniqueStringByNow(separator));
                }
                else if (funcName.ToLower() == "ShortGuid".ToLower())
                {
                    var baseStr   = funcParamArray.Length > 1 ? funcParamArray[1] : "";
                    var separator = funcParamArray.Length > 2 ? funcParamArray[2] : "";
                    return(baseStr.ToUniqueStringByShortGuid(separator));
                }
                else
                {
                    throw new ArgumentException("funcName: " + funcName + " has no param '" + funcParamArray[0] + "'! ");
                }
            }

            else if (funcName.ToLower() == "Format".ToLower())
            {
                if (funcParamArray[0].ToLower() == "upper")
                {
                    return(funcParamArray[1].ToUpper());
                }
                else if (funcParamArray[0].ToLower() == "lower")
                {
                    return(funcParamArray[1].ToLower());
                }
                else if (funcParamArray[0].ToLower() == "timespan")
                {
                    return(SystemTimeHelper.GetTimeSpanString(Convert.ToDouble(funcParamArray[1]), funcParamArray[2],
                                                              false));
                }
                else if (funcParamArray[0].ToLower() == "real")
                {
                    return(string.Format(funcParamArray[2], Convert.ToDouble(funcParamArray[1])));
                }

                else if (funcParamArray[0].ToLower() == "FormatString")
                {
                    return(string.Format(funcParamArray[1], funcParamArray[2]));
                }
                else
                {
                    throw new ArgumentException(funcName + " has no param '" + funcParamArray[0] + "'! ");
                }
            }
            else if (funcName.ToLower() == "Replace".ToLower())
            {
                return(funcParamArray[1].Length == 0 ? funcParamArray[0]
                    : funcParamArray[0].Replace(funcParamArray[1], funcParamArray[2]));
            }
            else if (funcName.ToLower() == "Split".ToLower())
            {
                var separator   = funcParamArray[1][0];
                var tmpStrArray = funcParamArray[0].Split(separator);
                var index       = Convert.ToInt16(funcParamArray[2]);
                if (index > tmpStrArray.Length || index == tmpStrArray.Length)
                {
                    return("");
                }
                else
                {
                    return(tmpStrArray[index]);
                }
            }
            else if (funcName.ToLower() == "Combine".ToLower())
            {
                var tmpStrArray = funcParamArray[0].GetSubParamArray(false, false);
                var rtStr       = "";
                if (funcParamArray.Length > 1)
                {
                    var joinSeparator = funcParamArray[1].Length == 1 ? Convert.ToChar(funcParamArray[1]) : ' ';
                    rtStr = Ligg.Infrastructure.Base.Helpers.StringHelper.UnwrapStringArrayBySeparator(tmpStrArray, joinSeparator);
                }
                else
                {
                    foreach (var tmpStr in tmpStrArray)
                    {
                        rtStr = rtStr + tmpStr;
                    }
                }
                return(rtStr);
            }
            else if (funcName.ToLower() == "SubString".ToLower())
            {
                var   tmStr    = funcParamArray[0];
                Int16 sttIndex = Convert.ToInt16(funcParamArray[1]);
                Int16 len      = Convert.ToInt16(funcParamArray[2]);
                return(tmStr.Substring(sttIndex, len));
            }
            else if (funcName.ToLower() == "AddOrRemoveSubParam".ToLower())
            {
                var separator = ',';
                if (funcParamArray[0].ContainsSubParamSeparator())
                {
                    separator = funcParamArray[0].GetSubParamSeparator();
                }

                var add = funcParamArray[2].ToLower() == "true" ? true : false;
                return(funcParamArray[0].AddOrDelToSeparatedStrings(funcParamArray[1], add, separator));
            }

            //*get
            else if (funcName.ToLower() == "GetLineQty".ToLower())
            {
                int qty = funcParamArray[0].Split('\n').Length;
                return(Convert.ToString(qty));
            }
            else if (funcName.ToLower() == "GetLinesBySearch".ToLower())
            {
                var strArry    = funcParamArray[0].Split('\n');
                var schStrArry = funcParamArray[1].Split(',');
                var strList    = new List <string>();
                foreach (var v in strArry)
                {
                    foreach (var s in schStrArry)
                    {
                        if (v.ToLower().Contains(s.ToLower()))
                        {
                            strList.Add(v);
                        }
                    }
                }

                var strList1 = strList.Distinct();
                var strBlder = new StringBuilder();
                foreach (var v in strList1)
                {
                    if (!string.IsNullOrEmpty(v))
                    {
                        strBlder.AppendLine(v);
                    }
                }

                return(strBlder.ToString());
            }

            //*convert
            else if (funcName.ToLower() == "ConvertJsonToRichText".ToLower())
            {
                var  jsonStr = funcParamArray[0];
                var  dt      = JsonHelper.ConvertToDataTable(jsonStr);
                bool hasHead = false;
                if (funcParamArray.Length > 1)
                {
                    if (funcParamArray[1].ToLower() == "true")
                    {
                        hasHead = true;
                    }
                }

                String[] strArray = null;
                if (funcParamArray.Length > 2)
                {
                    if (!funcParamArray[2].IsNullOrEmpty())
                    {
                        strArray = funcParamArray[2].GetSubParamArray(true, true);
                    }
                }
                var rtStr = DataTableHelper.ConvertToRichText(dt, hasHead, strArray);

                return(rtStr);
            }

            //*file
            else if (funcName.ToLower() == "FileDetail".ToLower())
            {
                if (funcParamArray[1].IsNullOrEmpty())
                {
                    throw new ArgumentException("file path can't be empty! ");
                }
                if (funcParamArray[0].ToLower() == "Directory".ToLower())
                {
                    return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.Directory));
                }
                else if (funcParamArray[0].ToLower() == "FileName".ToLower())
                {
                    return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.FileName));
                }
                else if (funcParamArray[0].ToLower() == "FileTitle".ToLower())
                {
                    return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.FileTitle));
                }
                else if (funcParamArray[0].ToLower() == "Suffix".ToLower())
                {
                    return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.Suffix));
                }
                else if (funcParamArray[0].ToLower() == "Postfix".ToLower())
                {
                    return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.Postfix));
                }
                else
                {
                    throw new ArgumentException("funcName: " + funcName + " has no param '" + funcParamArray[0] + "'! ");
                }
            }
            //*no use yet
            else if (funcName.ToLower() == "CompareFile".ToLower())
            {
                //var result = FileHelper.Compare2Files(funcParamArray[1], funcParamArray[2]).ToString();
                return(string.Empty);
            }


            else if (funcName.ToLower() == "GetContentFromTextFile".ToLower() | funcName.ToLower() == "GetCttFrTextFile".ToLower())
            {
                return(FileHelper.GetContentFromTextFile(funcParamArray[0]));
            }

            else if (funcName.ToLower() == "GetIniFileSetting".ToLower())
            {
                var filePath = funcParamArray[0];
                FileHelper.CheckFilePathExistence(filePath);
                var key    = funcParamArray[1];
                var defVal = funcParamArray.Length > 2 ? funcParamArray[2] : "";
                return(IniFileHelper.ReadIniString(filePath, "setting", key, defVal));
            }

            //*Json

            //*calc
            else if (funcName.ToLower() == "Calc".ToLower())
            {
                if (funcParamArray[0].ToLower() == "add".ToLower())
                {
                    return((Convert.ToDouble(funcParamArray[1]) + Convert.ToDouble(funcParamArray[2])).ToString());
                }
                else if (funcParamArray[0].ToLower() == "sub".ToLower())
                {
                    return((Convert.ToDouble(funcParamArray[1]) - Convert.ToDouble(funcParamArray[2])).ToString());
                }
                else if (funcParamArray[0].ToLower() == "mtp".ToLower())
                {
                    return((Convert.ToDouble(funcParamArray[1]) * Convert.ToDouble(funcParamArray[2])).ToString());
                }
                else if (funcParamArray[0].ToLower() == "div".ToLower())
                {
                    return((Convert.ToDouble(funcParamArray[1]) / Convert.ToDouble(funcParamArray[2])).ToString());
                }
                else if (funcParamArray[0].ToLower() == "rnd".ToLower())
                {
                    return((Math.Round(Convert.ToDouble(funcParamArray[1]))).ToString());
                }
                else if (funcParamArray[0].ToLower() == "spls".ToLower())
                {
                    return((Convert.ToDouble(funcParamArray[1]) % (Convert.ToDouble(funcParamArray[2]))).ToString());
                }
                else
                {
                    throw new ArgumentException("funcName: " + funcName + " has no param: " + funcParamArray[0] + "! ");
                }
            }

            //*Status
            else if (funcName.ToLower() == "GetFinalStatus".ToLower())
            {
                if (funcParamArray.All(v => v.ToLower() == "true"))
                {
                    return("true");
                }
                if (funcParamArray.Any(v => v.ToLower() == "unknown"))
                {
                    return("unknown");
                }
                return("false");
            }

            //*bool
            else if (funcName.ToLower() == "GetBool".ToLower())
            {
                if (funcParamArray[0].ToLower() == "TotalStatus".ToLower())
                {
                    var returnStr         = "true";
                    var subfuncParamArray = funcParamArray[1].Split(',');
                    if (subfuncParamArray.Any(v => v.ToLower() != "1"))
                    {
                        returnStr = "false";
                    }
                    return(returnStr);
                }
                else if (funcParamArray[0].ToLower() == "And".ToLower())
                {
                    var returnStr         = "true";
                    var subfuncParamArray = funcParamArray[1].Split(',');
                    if (subfuncParamArray.Any(v => v.ToLower() != "true"))
                    {
                        returnStr = "false";
                    }
                    return(returnStr);
                }
                else if (funcParamArray[0].ToLower() == "Or".ToLower())
                {
                    var returnStr         = "false";
                    var subfuncParamArray = funcParamArray[1].Split(',');
                    if (subfuncParamArray.Any(v => v.ToLower() == "true"))
                    {
                        returnStr = "true";
                    }
                    return(returnStr);
                }
                else if (funcParamArray[0].ToLower() == "Not".ToLower())
                {
                    var returnStr = "true";
                    if (funcParamArray[1].ToLower() == "true")
                    {
                        returnStr = "false";
                    }
                    return(returnStr);
                }

                else if (funcParamArray[0].ToLower() == "IsDirectoryExisting".ToLower())
                {
                    var returnStr = "false";
                    if (Directory.Exists(funcParamArray[1]))
                    {
                        returnStr = "true";
                    }
                    return(returnStr);
                }
                else if (funcParamArray[0].ToLower() == "IsDirectoryHidden".ToLower())
                {
                    if (!Directory.Exists(funcParamArray[1]))
                    {
                        return("false");
                    }
                    var returnStr = "false";
                    var di        = new DirectoryInfo(funcParamArray[1]);
                    if ((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                    {
                        returnStr = "true";
                    }
                    return(returnStr);
                }
                else if (funcParamArray[0].ToLower() == "IsFileExisting".ToLower())
                {
                    var returnStr = "false";
                    if (File.Exists(funcParamArray[1]))
                    {
                        returnStr = "true";
                    }
                    return(returnStr);
                }

                else if (funcParamArray[0].ToLower() == "IfElse".ToLower())
                {
                    var con        = funcParamArray[1];
                    var conArry    = con.GetSubParamArray(true, false);
                    var judgedText = conArry[0];
                    var judgeFlag  = conArry[1];
                    var val        = "";
                    if (conArry.Length > 2)
                    {
                        val = conArry[2];
                    }
                    if (GetHelper.Judge(judgeFlag, judgedText, val))
                    {
                        return("true");
                    }
                    return("false");
                }

                else
                {
                    throw new ArgumentException("funcName: " + funcName + " has no param: " + funcParamArray[0] + "! ");
                }
            }

            //*if
            else if (funcName.ToLower() == "IfElse".ToLower())
            {
                var con        = funcParamArray[0];
                var returnVal  = funcParamArray[1];
                var returnVal1 = funcParamArray[2];
                var conArry    = con.GetSubParamArray(true, false);
                var judgedText = conArry[0];
                var judgeFlag  = conArry[1];
                var val        = "";
                if (conArry.Length > 2)
                {
                    val = conArry[2];
                }
                if (GetHelper.Judge(judgeFlag, judgedText, val))
                {
                    return(returnVal);
                }
                return(returnVal1);
            }
            //*encrypt
            else if (funcName.ToLower() == "EncryptText".ToLower())
            {
                if (funcParamArray[0].ToLower() == "Md5".ToLower())
                {
                    return(EncryptionHelper.Md5Encrypt(funcParamArray[1]));
                }

                else
                {
                    throw new ArgumentException("funcName: " + funcName + " has no param: " + funcParamArray[0] + "! ");
                }
            }


            else if (funcName.ToLower() == "Validate".ToLower())
            {
                var retStr = Validator.Validate(funcParamArray[0], funcParamArray[1]);
                if (retStr == "OutOfScopeOfValidator")
                {
                    return("OutOfScope");
                }
                else
                {
                    return(retStr);
                }
            }

            else
            {
                return("OutOfScope");
            }
        }
Beispiel #17
0
        //#GetText
        public static string GetText(string funcName, string[] funcParamArray)
        {
            try
            {
                //common
                if (funcName.ToLower() == "empty" | funcName.ToLower() == "null")
                {
                    return(string.Empty);
                }


                else if (funcName.ToLower() == "GetInputText".ToLower())
                {
                    var dlg          = new TextInputDialog();
                    var verifyRule   = funcParamArray.Length > 0 ? funcParamArray[0] : "";
                    var verifyParams = funcParamArray.Length > 1 ? funcParamArray[1] : "";
                    dlg.VerificationRule   = verifyRule;
                    dlg.VerificationParams = verifyParams;
                    dlg.ShowDialog();
                    return(dlg.InputText);
                }

                else if (funcName.ToLower() == "GetInputDateTime".ToLower())
                {
                    var dlg          = new DateTimeInputDialog();
                    var customFormat = funcParamArray.Length > 0 ? funcParamArray[0] : "";
                    var verifyRule   = funcParamArray.Length > 1 ? funcParamArray[1] : "";
                    var verifyParams = funcParamArray.Length > 2 ? funcParamArray[2] : "";

                    dlg.VerificationRule   = verifyRule;
                    dlg.VerificationParams = verifyParams;
                    dlg.CustomFormat       = customFormat;
                    dlg.ShowDialog();
                    return(dlg.InputText);
                }

                else if (funcName.ToLower() == "LineQty".ToLower())
                {
                    int qty = funcParamArray[0].Split('\n').Length;
                    return(Convert.ToString(qty));
                }
                else if (funcName.ToLower() == "LinesBySearch".ToLower())
                {
                    var strArry    = funcParamArray[0].Split('\n');
                    var schStrArry = funcParamArray[1].Split(',');
                    var strList    = new List <string>();
                    foreach (var v in strArry)
                    {
                        foreach (var s in schStrArry)
                        {
                            if (v.ToLower().Contains(s.ToLower()))
                            {
                                strList.Add(v);
                            }
                        }
                    }

                    var strList1 = strList.Distinct();
                    var strBlder = new StringBuilder();
                    foreach (var v in strList1)
                    {
                        if (!string.IsNullOrEmpty(v))
                        {
                            strBlder.AppendLine(v);
                        }
                    }

                    return(strBlder.ToString());
                }

                else if (funcName.ToLower() == "DateTime".ToLower())
                {
                    var customFormat = "yyyy-MM-dd HH:mm:ss";
                    if (funcParamArray[0].ToLower() == "UtcNow".ToLower())
                    {
                        var time = SystemTimeHelper.UtcNow(); //
                        return(time.ToString(customFormat, DateTimeFormatInfo.InvariantInfo));
                    }
                    else if (funcParamArray[0].ToLower() == "Now".ToLower())
                    {
                        var time = SystemTimeHelper.Now(); //
                        return(time.ToString(customFormat, DateTimeFormatInfo.InvariantInfo));
                    }
                    else
                    {
                        throw new ArgumentException("funcName: " + funcName + " has no param " + funcParamArray[0] + "! ");
                    }
                }
                else if (funcName.ToLower() == "UniqueString".ToLower())
                {
                    if (funcParamArray[0] == "ByNow")
                    {
                        var seperator = funcParamArray[1];
                        return(funcParamArray[2].ToUniqueStringByNow(seperator));
                    }
                    else
                    {
                        throw new ArgumentException("funcName: " + funcName + " has no param '" + funcParamArray[0] + "'! ");
                    }
                }

                else if (funcName.ToLower() == "Format".ToLower())
                {
                    if (funcParamArray[0].ToLower() == "upper")
                    {
                        return(funcParamArray[1].ToUpper());
                    }
                    else if (funcParamArray[0].ToLower() == "lower")
                    {
                        return(funcParamArray[1].ToLower());
                    }
                    else if (funcParamArray[0].ToLower() == "timespan")
                    {
                        return(SystemTimeHelper.GetTimeSpanString(Convert.ToDouble(funcParamArray[1]), funcParamArray[2],
                                                                  false));
                    }
                    else if (funcParamArray[0].ToLower() == "real")
                    {
                        return(string.Format(funcParamArray[2], Convert.ToDouble(funcParamArray[1])));
                    }

                    else if (funcParamArray[0].ToLower() == "FormatString")
                    {
                        return(string.Format(funcParamArray[1], funcParamArray[2]));
                    }
                    else
                    {
                        throw new ArgumentException(funcName + " has no param '" + funcParamArray[0] + "'! ");
                    }
                }
                else if (funcName.ToLower() == "Replace".ToLower())
                {
                    return(funcParamArray[1].Length == 0 ? funcParamArray[0]
                        : funcParamArray[0].Replace(funcParamArray[1], funcParamArray[2]));
                }

                else if (funcName.ToLower() == "Split".ToLower())
                {
                    var seperator   = funcParamArray[1][0];
                    var tmpStrArray = funcParamArray[0].Split(seperator);
                    var index       = Convert.ToInt16(funcParamArray[2]);
                    if (index > tmpStrArray.Length || index == tmpStrArray.Length)
                    {
                        return("");
                    }
                    else
                    {
                        return(tmpStrArray[index]);
                    }
                }
                else if (funcName.ToLower() == "Combine".ToLower())
                {
                    var separator   = funcParamArray[0].GetSubParamSeparator();
                    var tmpStrArray = funcParamArray[0].Split(separator);
                    var rtStr       = "";
                    var i           = 0;
                    foreach (var tmpStr in tmpStrArray)
                    {
                        rtStr = rtStr + tmpStr;
                    }
                    return(rtStr);
                }
                else if (funcName.ToLower() == "SubString".ToLower())
                {
                    var   tmStr    = funcParamArray[0];
                    Int16 sttIndex = Convert.ToInt16(funcParamArray[1]);
                    Int16 len      = Convert.ToInt16(funcParamArray[2]);
                    return(tmStr.Substring(sttIndex, len));
                }

                //file
                else if (funcName.ToLower() == "FileDetail".ToLower())
                {
                    if (funcParamArray[1].IsNullOrEmpty())
                    {
                        throw new ArgumentException("file path can't be empty! ");
                    }
                    if (funcParamArray[0].ToLower() == "Directory".ToLower())
                    {
                        return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.Directory));
                    }
                    else if (funcParamArray[0].ToLower() == "FileName".ToLower())
                    {
                        return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.FileName));
                    }
                    else if (funcParamArray[0].ToLower() == "FileTitle".ToLower())
                    {
                        return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.FileTitle));
                    }
                    else if (funcParamArray[0].ToLower() == "Suffix".ToLower())
                    {
                        return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.Suffix));
                    }
                    else if (funcParamArray[0].ToLower() == "Postfix".ToLower())
                    {
                        return(FileHelper.GetFileDetailByOption(funcParamArray[1], FilePathComposition.Postfix));
                    }
                    else
                    {
                        throw new ArgumentException("funcName: " + funcName + " has no param '" + funcParamArray[0] + "'! ");
                    }
                }
                else if (funcName.ToLower() == "ChooseFile".ToLower())
                {
                    var dlg = new OpenFileDialog();
                    dlg.Title = "Choose File";
                    if (!string.IsNullOrEmpty(funcParamArray[0]))
                    {
                        dlg.InitialDirectory = funcParamArray[0];
                    }
                    if (!string.IsNullOrEmpty(funcParamArray[1]))
                    {
                        dlg.Filter = funcParamArray[1];
                    }

                    dlg.Multiselect      = false;
                    dlg.RestoreDirectory = true;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        if (dlg.FileNames.Count() > 0)
                        {
                            var firstFilePath = dlg.FileNames[0];
                            return(firstFilePath);
                        }
                    }
                    return(string.Empty);
                }

                //no use yet
                else if (funcName.ToLower() == "CompareFile".ToLower())
                {
                    //var result = FileHelper.Compare2Files(funcParamArray[1], funcParamArray[2]).ToString();
                    return(string.Empty);
                }

                //dir
                else if (funcName.ToLower() == "ChooseDirectory".ToLower())
                {
                    var dlg = new FolderBrowserDialog();
                    dlg.Description  = @"Choose Directory";
                    dlg.SelectedPath = funcParamArray[0];
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        return(dlg.SelectedPath);
                    }
                    return(string.Empty);
                }

                //calc
                else if (funcName.ToLower() == "Calc".ToLower())
                {
                    if (funcParamArray[0].ToLower() == "add".ToLower())
                    {
                        return((Convert.ToDouble(funcParamArray[1]) + Convert.ToDouble(funcParamArray[2])).ToString());
                    }
                    else if (funcParamArray[0].ToLower() == "sub".ToLower())
                    {
                        return((Convert.ToDouble(funcParamArray[1]) - Convert.ToDouble(funcParamArray[2])).ToString());
                    }
                    else if (funcParamArray[0].ToLower() == "mtp".ToLower())
                    {
                        return((Convert.ToDouble(funcParamArray[1]) * Convert.ToDouble(funcParamArray[2])).ToString());
                    }
                    else if (funcParamArray[0].ToLower() == "div".ToLower())
                    {
                        return((Convert.ToDouble(funcParamArray[1]) / Convert.ToDouble(funcParamArray[2])).ToString());
                    }
                    else if (funcParamArray[0].ToLower() == "rnd".ToLower())
                    {
                        return((Math.Round(Convert.ToDouble(funcParamArray[1]))).ToString());
                    }
                    else if (funcParamArray[0].ToLower() == "spls".ToLower())
                    {
                        return((Convert.ToDouble(funcParamArray[1]) % (Convert.ToDouble(funcParamArray[2]))).ToString());
                    }
                    else
                    {
                        throw new ArgumentException("funcName: " + funcName + " has no param: " + funcParamArray[0] + "! ");
                    }
                }
                //ifelse
                else if (funcName.ToLower() == "IfElse".ToLower())
                {
                    var con         = funcParamArray[0];
                    var returnVal   = funcParamArray[1];
                    var returnVal1  = funcParamArray[2];
                    var conArry     = con.Split(con.GetSubParamSeparator());
                    var compareVar  = conArry[0];
                    var compareFlag = conArry[1];
                    var compareVal  = "";
                    if (conArry.Length > 2)
                    {
                        compareVal = conArry[2];
                    }
                    if (compareFlag.ToLower().Trim() == "Contain".ToLower().Trim())
                    {
                        if (compareVar.Contains(compareVal))
                        {
                            if (!string.IsNullOrEmpty(compareVal))
                            {
                                return(returnVal);
                            }
                        }
                    }
                    else if (compareFlag.ToLower().Trim() == "Equal".ToLower().Trim())
                    {
                        if (compareVar == compareVal)
                        {
                            return(returnVal);
                        }
                    }
                    else if (compareFlag.ToLower() == "VEqual".ToLower())
                    {
                        if (Convert.ToDouble(compareVar) == Convert.ToDouble(compareVal))
                        {
                            return(returnVal);
                        }
                    }
                    else if (compareFlag.ToLower() == "VGreater".ToLower())
                    {
                        if (Convert.ToDouble(compareVar) > Convert.ToDouble(compareVal))
                        {
                            return(returnVal);
                        }
                    }
                    else if (compareFlag.ToLower() == "VGreaterEqual".ToLower())
                    {
                        if (Convert.ToDouble(compareVar) >= Convert.ToDouble(compareVal))
                        {
                            return(returnVal);
                        }
                    }
                    else if (compareFlag.ToLower() == "VLess".ToLower())
                    {
                        if (Convert.ToDouble(compareVar) < Convert.ToDouble(compareVal))
                        {
                            return(returnVal);
                        }
                    }
                    else if (compareFlag.ToLower() == "VLessEqual".ToLower())
                    {
                        if (Convert.ToDouble(compareVar) <= Convert.ToDouble(compareVal))
                        {
                            return(returnVal);
                        }
                    }
                    else if (compareFlag.ToLower() == "NotEqual".ToLower())
                    {
                        if (compareVar.Trim() != compareVal.Trim())
                        {
                            return(returnVal);
                        }
                    }
                    else if (compareFlag.ToLower() == "IsNull".ToLower())
                    {
                        if (compareVar.IsNullOrEmpty())
                        {
                            return(returnVal);
                        }
                    }
                    else if (compareFlag.ToLower() == "IsNotNull".ToLower())
                    {
                        if (!compareVar.IsNullOrEmpty())
                        {
                            return(returnVal);
                        }
                    }
                    else
                    {
                        throw new ArgumentException("funcName: " + funcName + " has no compare Flag: '" + compareFlag + "'! ");
                    }

                    return(returnVal1);
                } //IfElse ends

                //Status
                else if (funcName.ToLower() == "GetFinalStatus".ToLower())
                {
                    if (funcParamArray.All(v => v.ToLower() == "true"))
                    {
                        return("true");
                    }
                    if (funcParamArray.Any(v => v.ToLower() == "unknown"))
                    {
                        return("unknown");
                    }
                    return("false");
                }

                //getbool
                else if (funcName.ToLower() == "GetBool".ToLower())
                {
                    if (funcParamArray[0].ToLower() == "TotalStatus".ToLower())
                    {
                        var returnStr         = "true";
                        var subfuncParamArray = funcParamArray[1].Split(',');
                        if (subfuncParamArray.Any(v => v.ToLower() != "1"))
                        {
                            returnStr = "false";
                        }
                        return(returnStr);
                    }
                    else if (funcParamArray[0].ToLower() == "And".ToLower())
                    {
                        var returnStr         = "true";
                        var subfuncParamArray = funcParamArray[1].Split(',');
                        if (subfuncParamArray.Any(v => v.ToLower() != "true"))
                        {
                            returnStr = "false";
                        }
                        return(returnStr);
                    }
                    else if (funcParamArray[0].ToLower() == "Or".ToLower())
                    {
                        var returnStr         = "false";
                        var subfuncParamArray = funcParamArray[1].Split(',');
                        if (subfuncParamArray.Any(v => v.ToLower() == "true"))
                        {
                            returnStr = "true";
                        }
                        return(returnStr);
                    }
                    else if (funcParamArray[0].ToLower() == "Not".ToLower())
                    {
                        var returnStr = "true";
                        if (funcParamArray[1].ToLower() == "true")
                        {
                            returnStr = "false";
                        }
                        return(returnStr);
                    }

                    else if (funcParamArray[0].ToLower() == "JudgeStringIsNull".ToLower())
                    {
                        var returnStr = "false";
                        if (string.IsNullOrEmpty(funcParamArray[1]))
                        {
                            returnStr = "true";
                        }
                        return(returnStr);
                    }
                    else if (funcParamArray[0].ToLower() == "JudgeStringIsNotNull".ToLower())
                    {
                        var returnStr = "false";
                        if (!string.IsNullOrEmpty(funcParamArray[1]))
                        {
                            returnStr = "true";
                        }
                        return(returnStr);
                    }
                    else if (funcParamArray[0].ToLower() == "JudgeIfDirectoryExists".ToLower())
                    {
                        var returnStr = "false";
                        if (Directory.Exists(funcParamArray[1]))
                        {
                            returnStr = "true";
                        }
                        return(returnStr);
                    }
                    else if (funcParamArray[0].ToLower() == "JudgeIsDirectoryHidden".ToLower())
                    {
                        if (!Directory.Exists(funcParamArray[1]))
                        {
                            return("false");
                        }
                        var returnStr = "false";
                        var di        = new DirectoryInfo(funcParamArray[1]);
                        if ((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                        {
                            returnStr = "true";
                        }
                        return(returnStr);
                    }

                    else if (funcParamArray[0].ToLower() == "VerifyInput".ToLower())
                    {
                        var returnStr    = "false";
                        var dlg          = new TextInputDialog();
                        var verifyRule   = funcParamArray[1];
                        var verifyParams = funcParamArray.Length > 2 ? funcParamArray[2] : "";
                        dlg.VerificationRule   = verifyRule;
                        dlg.VerificationParams = verifyParams;
                        dlg.ShowDialog();
                        returnStr = dlg.IsOk.ToString().ToLower();
                        return(returnStr);
                    }
                    else
                    {
                        throw new ArgumentException("funcName: " + funcName + " has no param: " + funcParamArray[0] + "! ");
                    }
                }

                else if (funcName.ToLower() == "GetEncryptedText".ToLower())
                {
                    if (funcParamArray[0].ToLower() == "Md5".ToLower())
                    {
                        //return EncryptionHelper.Md5Encrypt(funcParamArray[1]);
                        return(string.Empty);
                    }
                    else if (funcParamArray[0].ToLower() == "Rsa".ToLower())
                    {
                        //return EncryptionHelper.RsaEncrypt(funcParamArray[1]);
                        return(string.Empty);
                    }
                    else if (funcParamArray[0].ToLower() == "Bitwise".ToLower())
                    {
                        //return EncryptionHelper.BitwiseEncrypt(funcParamArray[1]);
                        return(string.Empty);
                    }
                    else if (funcParamArray[0].ToLower() == "Symmetric".ToLower())
                    {
                        return(EncryptionHelper.SmEncrypt(funcParamArray[1]));
                    }
                    else if (funcParamArray[0].ToLower() == "TimeDynamic".ToLower())
                    {
                        return(string.Empty);
                    }
                    else
                    {
                        throw new ArgumentException("funcName: " + funcName + " has no param: " + funcParamArray[0] + "! ");
                    }
                }

                else if (funcName.ToLower() == "GetDecryptedText".ToLower())
                {
                    if (funcParamArray[0].ToLower() == "Rsa".ToLower())
                    {
                        //return EncryptionHelper.RsaDecrypt(funcParamArray[1]);
                        return(string.Empty);
                    }
                    if (funcParamArray[0].ToLower() == "Symmetric".ToLower())
                    {
                        //return EncryptionHelper.SmDecrypt(funcParamArray[1]);
                        return(string.Empty);
                    }
                    else
                    {
                        throw new ArgumentException("funcName: " + funcName + " has no param: " + funcParamArray[0] + "! ");
                    }
                }

                //xml
                else if (funcName.ToLower() == "GetTableXmlNodeVal".ToLower())
                {
                    var path   = funcParamArray[0];
                    var xmlMgr = new XmlHandler(path);
                    return(xmlMgr.GetNodeInnerTextByTagName(funcParamArray[1], 0));
                }

                //following can be extended to impl in AdapterGetHelper
                else if (funcName.ToLower() == "GetValidationResult".ToLower())
                {
                    var retStr = TextValidationHelper.Validate(funcParamArray[0], funcParamArray[1]);
                    if (retStr == "OutOfScopeOfTextValidationHelper")
                    {
                        return("OutOfScope");
                    }
                    else
                    {
                        return(retStr);
                    }
                }

                else if (funcName.ToLower() == "GetJson".ToLower())
                {
                    return("OutOfScope");
                }

                else
                {
                    return("OutOfScope");
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + TypeName + ".GetText error: " + ex.Message);
            }
        }