private void ChangeComparisonType()
        {
            DataResult <Settings> dataResult = Config.RetrieveSettings();

            if (dataResult.MainResult.Success)
            {
                ComparisonType type = dataResult.Data.ComparisonType;
                WriteLine($"Current Setting For Comparison Type: {type.ToString()}");
                string name = Enum.GetNames(typeof(ComparisonType))
                              .Where(x => !x.Equals(type.ToString(), StringComparison.InvariantCultureIgnoreCase))
                              .First();
                ComparisonType nextType = (ComparisonType)Enum.Parse(typeof(ComparisonType), name);
                Write($"Do you want to change comparison type to `{name}` ? [Y|N]> ");

                string confirm = ReadLine();
                while ((!confirm.Equals("y", StringComparison.InvariantCultureIgnoreCase) &&
                        !confirm.Equals("n", StringComparison.InvariantCultureIgnoreCase)))
                {
                    Write($"Do you want to change comparison type to `{name}` ? [Y|N]> ");
                    confirm = ReadLine();
                }
                switch (confirm.ToLower())
                {
                case "y":
                    Settings settings = dataResult.Data;
                    settings.ComparisonType = nextType;
                    WriteLine("Updating settings...");
                    MainResult result = Config.StoreSettings(settings);
                    if (result.Success)
                    {
                        WriteLine("Comparison type has been changed");
                        //refresing service.....
                        WriteLine($"Refreshing service...");
                        MainResult refreshResult = _serviceController.RefreshService();
                        if (refreshResult.Success)
                        {
                            WriteLine("Service refreshed");
                        }
                        else
                        {
                            WriteLine(refreshResult.ErrorMessage);
                        }
                        //......................
                    }
                    else
                    {
                        WriteLine($"Error: `{result.ErrorMessage}`");
                    }
                    break;

                default:
                    WriteLine("Operation cancelled");
                    break;
                }
            }
            else
            {
                WriteLine($"Error: `{dataResult.MainResult.ErrorMessage}`");
            }
        }
        public void Run()
        {
            MainResult serviceStarterResult = _serviceController.StartService();

            if (serviceStarterResult.Success)
            {
                Flags();
                WriteLine("\n  Press <enter> to continue...");
                ReadLine();
                Clear();
                if (!File.Exists(Global.MasterKeyLocation))
                {
                    SetUpMasterKey(new Action(HandleCommand));
                }
                else
                {
                    Login(new Action(HandleCommand));
                }
            }
            else
            {
                WriteLine($"Error: `{serviceStarterResult.ErrorMessage}`");
                WriteLine("Press <enter> to continue...");
                ReadLine();
            }
        }
        private void ChangeInterval()
        {
            DataResult <Settings> dataResult = Config.RetrieveSettings();

            if (dataResult.MainResult.Success)
            {
                WriteLine($"Current Setting For Interval: {dataResult.Data.Interval} ms");
                Write("Input new interval [min: 500, cancel: -1]> ");
                string input    = ReadLine();
                int    number   = 0;
                bool   isNumber = int.TryParse(input, out number);
                while (!isNumber || number < 500)
                {
                    if (number == -1)
                    {
                        break;
                    }
                    Write("Input new interval [min:500, cancel :-1]> ");
                    input    = ReadLine();
                    number   = 0;
                    isNumber = int.TryParse(input, out number);
                }
                if (number != -1)
                {
                    Settings settings = dataResult.Data;
                    settings.Interval = number;
                    WriteLine("Updating settings...");
                    MainResult result = Config.StoreSettings(settings);
                    if (result.Success)
                    {
                        WriteLine($"Timer interval has been changed to {number} ms");
                        //refresing service.....
                        WriteLine($"Refreshing service...");
                        MainResult refreshResult = _serviceController.RefreshService();
                        if (refreshResult.Success)
                        {
                            WriteLine("Service refreshed");
                        }
                        else
                        {
                            WriteLine(refreshResult.ErrorMessage);
                        }
                        //......................
                    }
                    else
                    {
                        WriteLine($"Error: `{result.ErrorMessage}`");
                    }
                }
                else
                {
                    WriteLine("Operation cancelled");
                }
            }
            else
            {
                WriteLine($"Error: `{dataResult.MainResult.ErrorMessage}`");
            }
        }
Exemple #4
0
        public MainResult RefreshService()
        {
            MainResult pauseResult = PauseService();

            if (pauseResult.Success)
            {
                return(ContinueService());
            }
            return(pauseResult);
        }
        public ActionResult Index(int?fid, int?orderBy)
        {
            MainResult model = new MainResult();

            ViewBag.NewUserList      = base.GetNewUserList;
            ViewBag.ForList          = base.GetForumsList;
            ViewBag.ForumsStatistics = base.GetForumsStatistics();
            _service.Command <MainOutsourcing, ResultModel <MainResult> >((db, o, api) =>
            {
                model            = api.Get(Url.Action("GetMainResult"), new { fid = fid, orderBy = orderBy }).ResultInfo;
                model.ForumsList = ViewBag.ForList;
                model.OrderBy    = orderBy.TryToInt();
                model.Fid        = (short)fid.TryToInt();
            });
            return(View(model));
        }
        private void Command4()
        {
            ViewList();
            Write("Are you sure want to clear black list? [Y/N]> ");
            string confirm = ReadLine();

            while ((!confirm.Equals("y", StringComparison.InvariantCultureIgnoreCase) &&
                    !confirm.Equals("n", StringComparison.InvariantCultureIgnoreCase)))
            {
                Write("Are you sure want to clear black list? [Y/N]> ");
                confirm = ReadLine();
            }
            switch (confirm.ToLower())
            {
            case "y":
                WriteLine("Clearing the list...");
                var clearResult = _iOSecurity.StoreData(new List <ProcessModel>());
                if (clearResult.Success)
                {
                    WriteLine("black list has been cleared");
                    //refresing service.....
                    WriteLine($"Refreshing service...");
                    MainResult refreshResult = _serviceController.RefreshService();
                    if (refreshResult.Success)
                    {
                        WriteLine("Service refreshed");
                    }
                    else
                    {
                        WriteLine(refreshResult.ErrorMessage);
                    }
                    //......................
                }
                else
                {
                    WriteLine("Failed to clear the list due to unexcepted error. Please try again");
                }
                break;

            default:
                WriteLine("Operation cancelled");
                break;
            }
            WriteLine("\nPress <enter> to continue...");
            ReadLine();
            Clear();
        }
        public void BindResult(string filePath, IntPtr windowPtr)
        {
            _filePath = filePath;
            //开启一个线程来读取xml文件,因为数据是在图形绘制完之后才出来
            Thread thread = new Thread(new ThreadStart(delegate {
                while (true)
                {
                    if (File.Exists(filePath))
                    {
                        this.Invoke(new Action(() =>
                        {
                            MainResult cv = XmlHelper.Deserialize <MainResult>(filePath);
                            //初始化参数
                            if (cv != null)
                            {
                                StringBuilder builder = new StringBuilder();
                                builder.AppendLine("计算结果:");
                                builder.AppendLine("洪峰流量Qm = " + cv.Qm);
                                builder.AppendLine("洪峰历时系数p1_0 = " + cv.p1);
                                builder.AppendLine("造峰历时tQ = " + cv.tQ);
                                builder.AppendLine("洪峰上涨历时t = " + cv.t);
                                builder.AppendLine("产流期净雨强a1tc = " + cv.a1tc);
                                builder.AppendLine("迭代次数:" + cv.d1 + "-" + cv.d2);
                                FormOutput.AppendLog(builder.ToString());
                                txtQm.Text   = cv.Qm.ToString();
                                txtP1.Text   = cv.p1.ToString();
                                txttQ.Text   = cv.tQ.ToString();
                                txtt.Text    = cv.t.ToString();
                                txta1tc.Text = cv.a1tc.ToString();
                                txtd1.Text   = cv.d1.ToString();
                                txtd2.Text   = cv.d2.ToString();
                            }
                        }));
                        break;
                    }
                }
            }));

            thread.IsBackground = true;
            thread.Start();

            //初始化曲线
            this.DockFigure(windowPtr);
        }
        public ActionResult Index(int?fid, int?orderBy, int?pageIndex)
        {
            MainResult model = new MainResult();

            ViewBag.NewUserList      = base.GetNewUserList;
            ViewBag.ForList          = base.GetForumsList;
            ViewBag.ForumsStatistics = base.GetForumsStatistics();
            ViewBag.IsLogin          = base.IsLogin;
            ViewBag.BBS_Right        = base.GetBBS_Right;
            _service.Command <MainOutsourcing, ResultModel <MainResult> >((db, o, api) =>
            {
                model            = api.Get(Url.Action("GetMainResult"), new { fid = fid, orderBy = orderBy, pageIndex = pageIndex }).ResultInfo;
                model.ForumsList = ViewBag.ForList;
                model.OrderBy    = orderBy.TryToInt();
                model.Fid        = (short)fid.TryToInt();
                var ps           = new SyntacticSugar.PageString();
                model.PageString = ps.ToPageString(model.PageCount, model.PageSize, model.PageIndex, Url.Content("/Ask?"));
            });
            return(View(model));
        }
        private void Login(Action action)
        {
            int            _loginCounter = 0;
            PasswordMasker masker        = new PasswordMasker();
            MainResult     result        = new MainResult();
            string         passCode      = "";

            do
            {
                passCode = masker.Mask($"Login (attempt: {_loginCounter}/5): ");
                if (String.IsNullOrEmpty(passCode) || passCode.Length <= 5)
                {
                    Write("Password length must be greater than 5 chars!");
                    ReadLine();
                    Clear();
                }
                else
                {
                    result = _iOSecurity.Login(passCode);
                    if (result.Success)
                    {
                        break;
                    }
                    else
                    {
                        Write($"Error: `{result.ErrorMessage}`");
                        ReadLine();
                        Clear();
                    }
                }
                _loginCounter++;
            } while (_loginCounter <= 5);
            if (result.Success)
            {
                action();
            }
            else if (_loginCounter == 5)
            {
                Environment.Exit(0);
            }
        }
Exemple #10
0
        private async void UpdatePassword()
        {
            IOSecurity iOSecurity = new IOSecurity();
            //because we use non-UI thread to update password,
            //we must copy both passwords in variables.
            string oldPwd  = passwordBoxCurrentPassword.Password;
            string newPwd  = passwordBoxNewPassword.Password;
            string message = "";
            string title   = "";

            progressBarLoading.IsIndeterminate = true;
            await Task.Run(() =>
            {
                MainResult loginResult = iOSecurity.Login(oldPwd);
                if (loginResult.Success)
                {
                    MainResult changePasswordResult = iOSecurity.ChangeMasterKey(newPwd);
                    if (changePasswordResult.Success)
                    {
                        title   = LanguageChanger.Instance["SettingsView_CodeBehind_Success"];
                        message = LanguageChanger.Instance["SettingsView_CodeBehind_Code7"];
                    }
                    else
                    {
                        title   = LanguageChanger.Instance["SettingsView_CodeBehind_Error"];
                        message = changePasswordResult.ErrorMessage;
                    }
                }
                else
                {
                    title   = LanguageChanger.Instance["SettingsView_CodeBehind_Error"];
                    message = LanguageChanger.Instance["SettingsView_CodeBehind_Code8"];
                }
            });

            progressBarLoading.IsIndeterminate = false;
            await this.ShowMessageAsync(title, message);

            passwordBoxCurrentPassword.Password = passwordBoxNewPassword.Password = string.Empty;
        }
        private void ChangePassword(Action action)
        {
            PasswordMasker masker = new PasswordMasker();
            string         key    = "";

            do
            {
                key = masker.Mask("Set password (length>5): ");
                if (String.IsNullOrEmpty(key) || key.Length <= 5)
                {
                    Write("Password length must be greater than 5 chars!");
                    ReadLine();
                    Clear();
                }
                else if (File.Exists(Global.MasterKeyLocation) && _iOSecurity.Login(key).Success)
                {
                    Write("You cannot input the same password!");
                    ReadLine();
                    Clear();
                }
                else
                {
                    break;
                }
            } while (true);
            WriteLine("Loading...");
            MainResult result = _iOSecurity.ChangeMasterKey(key);

            if (result.Success)
            {
                WriteLine("Password changed successfully");
            }
            else
            {
                WriteLine($"Error: `{result.ErrorMessage}`");
            }
            action();
        }
Exemple #12
0
        public async Task <IActionResult> GetNoiseLevels(double[] w, string[] selectedSpeakers)
        {
            var speakerList = new List <SpeakerViewModel>();

            foreach (var speakerName in selectedSpeakers)
            {
                var speaker = _context.Files.FirstOrDefault(x => x.Name == speakerName);
                speakerList.Add(speaker.ToViewModel());
            }

            // худший диктор
            var worstSpeaker = Core.GetWorstSpeaker(speakerList);

            var levels = Core.GetNoiseLevels(speakerList, -30, 30, w[0]);

            var result = new MainResult
            {
                Levels      = levels,
                SpeakerName = worstSpeaker.Name
            };

            return(View("Index", result));
        }
        private void Command3()
        {
            List <ProcessModel> list = ViewList();

            if (list != null)
            {
                if (list.Count > 0)
                {
                    Write($"Choose [1-{list.Count}]> ");
                    string input    = ReadLine();
                    int    number   = 0;
                    bool   isNumber = int.TryParse(input, out number);
                    while (!isNumber || (isNumber && (number < 1 || number > list.Count)))
                    {
                        Write($"Choose [1-{list.Count}]> ");
                        input    = ReadLine();
                        number   = 0;
                        isNumber = int.TryParse(input, out number);
                    }
                    bool success = true;
                    try
                    {
                        list.RemoveAt(number - 1);
                    }
                    catch { success = false; }
                    if (success)
                    {
                        WriteLine("Removing item...");
                        MainResult deleteResult = _iOSecurity.StoreData(list);
                        if (deleteResult.Success)
                        {
                            WriteLine("Item removed");
                            WriteLine("Viewing current list...");
                            ViewList();
                            //refresing service.....
                            WriteLine($"Refreshing service...");
                            MainResult refreshResult = _serviceController.RefreshService();
                            if (refreshResult.Success)
                            {
                                WriteLine("Service refreshed");
                            }
                            else
                            {
                                WriteLine(refreshResult.ErrorMessage);
                            }
                            //......................
                        }
                        else
                        {
                            WriteLine($"Error: `{deleteResult.ErrorMessage}`");
                        }
                    }
                    else
                    {
                        WriteLine("Failed to remove selected item");
                    }
                }
                else
                {
                    WriteLine("Nothing to remove");
                }
            }
            WriteLine("\nPress <enter> to continue...");
            ReadLine();
            Clear();
        }
        private MainResult StoreMasterKey(string clearTextPassword)
        {
            if (String.IsNullOrEmpty(clearTextPassword))
            {
                return(new MainResult
                {
                    ErrorMessage = "Password cannot be null",
                    Success = false
                });
            }
            bool   success = true;
            string error   = "";

            try
            {
                byte[] hashedKey = new SHA256Crypto().GetHashBytes(clearTextPassword);
                if (hashedKey == null)
                {
                    success = false;
                    error   = "Failed to hash master key";
                }
                else
                {
                    byte[] encryptedKey = null;
                    try
                    {
                        //this entropy is not a secret
                        byte[] optionalEntropy = BitHelpers.CreateSecurePassword("#EF$RCVDFQER!#@#~~!WE@R@?>?KU$%#THT%#$HK%TH%YU%**($%DADGDFHWEJdfsffwgt34t#%@#r4t3T3r43", 128);
                        encryptedKey = ProtectedData.Protect(hashedKey, optionalEntropy, DataProtectionScope.LocalMachine);
                    }
                    catch
                    {
                        encryptedKey = null;
                    }
                    if (encryptedKey == null)
                    {
                        success = false;
                        error   = "Failed during master key encryption";
                    }
                    else
                    {
                        bool       exists           = File.Exists(Global.MasterKeyLocation) ? true : false;
                        MainResult unlockFileResult = null;

                        unlockFileResult = exists ? UnlockFile(Global.MasterKeyLocation) : new MainResult();

                        if (exists && !unlockFileResult.Success)
                        {
                            success = false;
                            error   = unlockFileResult.ErrorMessage;
                        }
                        else
                        {
                            bool save = true;
                            try
                            {
                                File.WriteAllBytes(Global.MasterKeyLocation, encryptedKey);
                            }
                            catch { save = false; }
                            if (!save)
                            {
                                success = false;
                                error   = "Failed to write master key to desired location";
                            }
                            else
                            {
                                var result = LockFile(Global.MasterKeyLocation);
                                if (!result.Success)
                                {
                                    success = false;
                                    error   = result.ErrorMessage;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                error   = ex.Message;
            }
            return(new MainResult
            {
                Success = success,
                ErrorMessage = error
            });
        }
        private void Command2()
        {
            WriteLine("Note: Duplicate items won't be added to black list");
            WriteLine("Press <enter> to add item");
            ReadLine();
            WriteLine("Retrieving list....");
            DataResult <List <ProcessModel> > dataResult = _iOSecurity.RetrieveData();

            if (dataResult.MainResult.Success)
            {
                List <ProcessModel> list       = dataResult.Data;
                OpenFileDialog      fileDialog = new OpenFileDialog()
                {
                    Filter          = "Executable File (*.exe)|*.exe",
                    FileName        = "",
                    CheckFileExists = true,
                    CheckPathExists = true,
                    Multiselect     = true
                };
                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    int added = 0;
                    foreach (string name in fileDialog.FileNames)
                    {
                        if (!name.ToLower().Contains("mgr21"))
                        {
                            if (!list.Any(x => x.FileLocation.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                DataResult <ProcessModel> addResult = _iOSecurity.CreateProcessModel(name);
                                if (addResult.MainResult.Success)
                                {
                                    list.Add(addResult.Data);
                                    added++;
                                }
                                else
                                {
                                    WriteLine($"Error: `{addResult.MainResult.ErrorMessage}`");
                                }
                            }
                        }
                    }
                    if (added > 0)
                    {
                        WriteLine("Adding data....");
                        MainResult storeResult = _iOSecurity.StoreData(list);
                        if (storeResult.Success)
                        {
                            WriteLine($"\n{added} item(s) added to black list");
                            ViewList();

                            //refresing service.....
                            WriteLine($"Refreshing service...");
                            MainResult refreshResult = _serviceController.RefreshService();
                            if (refreshResult.Success)
                            {
                                WriteLine("Service refreshed");
                            }
                            else
                            {
                                WriteLine(refreshResult.ErrorMessage);
                            }
                            //......................
                        }
                        else
                        {
                            WriteLine($"Error: `{storeResult.ErrorMessage}`");
                        }
                    }
                    else
                    {
                        WriteLine("No item(s) being added");
                    }
                }
                else
                {
                    WriteLine("Operation cancelled");
                }
            }
            else
            {
                WriteLine($"Error: `{dataResult.MainResult.ErrorMessage}`");
            }
            WriteLine("\nPress <enter> to continue...");
            ReadLine();
            Clear();
        }
Exemple #16
0
        public async Task <MainResult> RunAsync()
        {
            var stopwatch = Stopwatch.StartNew();
            var result    = new MainResult();

            if (!string.IsNullOrEmpty(_options.Config) &&
                !string.IsNullOrWhiteSpace(_options.Config))
            {
                if (!await ParseConfigFileAsync())
                {
                    return(result);
                }
            }

            if (!_options.SyncConfigs.Any())
            {
                if (string.IsNullOrEmpty(_options.SourceDir) ||
                    string.IsNullOrWhiteSpace(_options.SourceDir))
                {
                    Logger.Error("Missing source directory, please see --help.");
                    return(result);
                }

                if (!Directory.Exists(_options.SourceDir))
                {
                    Logger.Error($"Source directory doesn't exist: {_options.SourceDir}.");
                    return(result);
                }

                if (string.IsNullOrEmpty(_options.TargetDir) ||
                    string.IsNullOrWhiteSpace(_options.TargetDir))
                {
                    Logger.Error("Missing target directory, please see --help.");
                    return(result);
                }

                _options.SyncConfigs.Add(new SyncConfig {
                    Source = _options.SourceDir, Target = _options.TargetDir
                });
            }

            var syncIngestTasks    = new List <Task <SyncIngestResult> >();
            var cleanupIngestTasks = new List <Task <CleanupIngestResult> >();

            var syncService          = new SyncService(_options, Logger, ProgressBarType, _cancellationToken);
            var cleanupService       = new CleanupService(Logger, _options, _cancellationToken);
            var syncIngestResults    = new List <SyncIngestResult>();
            var cleanupIngestResults = new List <CleanupIngestResult>();


            foreach (var item in _options.SyncConfigs)
            {
                syncIngestTasks.Add(syncService.IngestAsync(item));
                if (_options.Cleanup)
                {
                    cleanupIngestTasks.Add(cleanupService.IngestAsync(item));
                }
            }

            var syncIngestCompletedTask = Task.WhenAll(syncIngestTasks)
                                          .ContinueWith(t => syncService.MarkAsCompleted(), _cancellationToken);
            var cleanupIngestCompletedTask = Task.WhenAll(cleanupIngestTasks)
                                             .ContinueWith(t => cleanupService.MarkAsCompleted(), _cancellationToken);
            var syncRunTask    = syncService.RunAsync();
            var cleanupRunTask = cleanupService.RunAsync();
            await Task.WhenAll(syncIngestCompletedTask, cleanupIngestCompletedTask, syncRunTask, cleanupRunTask);

            foreach (var syncIngestTask in syncIngestTasks)
            {
                syncIngestResults.Add(await syncIngestTask);
            }

            foreach (var cleanupIngestTask in cleanupIngestTasks)
            {
                cleanupIngestResults.Add(await cleanupIngestTask);
            }

            var syncRunResults    = await syncRunTask;
            var cleanupRunResults = await cleanupRunTask;

            result.Configs = _options.SyncConfigs;
            result.AggregateSyncIngestResults(syncIngestResults);
            result.AggregateCleanupIngestResults(cleanupIngestResults);
            result.AggregateRunResults(syncRunResults, cleanupRunResults);

            result.Succeed = true;
            stopwatch.Stop();
            Logger.Info($"All done. Elapsed: {stopwatch.Elapsed:hh\\:mm\\:ss}.");
            return(result);
        }
Exemple #17
0
        static void Main(string[] args)
        {
            if (args != null && args.Length > 0)
            {
                string methodName = args[0];//方法名称
                Class1 C          = null;

                #region 水文曲线
                if (methodName == MethodName.SWCure)
                {
                    try
                    {
                        C = new Class1();
                        //删除文件
                        string filePath = Path.Combine(Application.StartupPath, ConfigNames.SvCure);
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                        double[,] CC = (double[, ])C.miaodian().ToArray();
                        Console.WriteLine("Cv:" + CC[0, 0]);
                        Console.WriteLine("Cs:" + CC[0, 1]);
                        Console.WriteLine("X:" + CC[0, 2]);
                        Console.WriteLine("Nihe:" + CC[0, 3]);
                        XmlHelper.Serialize <CvCure>(new CvCure()
                        {
                            Cv   = CC[0, 0],
                            Cs   = CC[0, 1],
                            X    = CC[0, 2],
                            Nihe = CC[0, 3].ToString()
                        }, filePath);
                        Console.ReadKey();  //不直接关闭
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (C != null)
                        {
                            C.Dispose();
                        }
                    }
                }
                #endregion

                #region 拟合曲线

                else if (methodName == MethodName.NiHeCure)
                {
                    try
                    {
                        double         X   = Convert.ToDouble(args[1]);
                        MWNumericArray XX  = new MWNumericArray(X);
                        double         Cv  = Convert.ToDouble(args[2]);
                        MWNumericArray Cvv = new MWNumericArray(Cv);
                        double         Cs  = Convert.ToDouble(args[3]);
                        MWNumericArray Css = new MWNumericArray(Cs);
                        C = new Class1();
                        double[,] Nihe = (double[, ])C.peixian(Cvv, Css, XX).ToArray();
                        Console.WriteLine("Nihe:" + Nihe[0, 0]);
                        XmlHelper.Serialize <string>(Nihe[0, 0].ToString(), Path.Combine(Application.StartupPath, ConfigNames.TempName));
                        C.Dispose();
                        Console.ReadKey();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (C != null)
                        {
                            C.Dispose();
                        }
                    }
                }

                #endregion

                #region 曲线反查

                else if (methodName == MethodName.ResearchCure)
                {
                    double         X   = Convert.ToDouble(args[1]);
                    MWNumericArray XX  = new MWNumericArray(X);
                    double         Cv  = Convert.ToDouble(args[2]);
                    MWNumericArray Cvv = new MWNumericArray(Cv);
                    double         Cs  = Convert.ToDouble(args[3]);
                    MWNumericArray Css = new MWNumericArray(Cs);
                    //反查类型 c1-根据概率查值,c2-根据值查询概率,c3-查询时间段内所有内定概率
                    string type = args[4].Split('-')[0];
                    if (type == "c1")
                    {
                        double         k   = Convert.ToDouble(args[4].Split('-')[1]);
                        MWNumericArray kik = new MWNumericArray(k);
                        C = new Class1();
                        double[,] Xcha = (double[, ])C.chaxun1(Cvv, Css, XX, kik).ToArray();
                        Console.WriteLine(Xcha[0, 0]);
                    }
                    else if (type == "c2")
                    {
                        double         k   = Convert.ToDouble(args[4].Split('-')[1]);
                        MWNumericArray kik = new MWNumericArray(k);
                        C = new Class1();
                        double[,] Xcha = (double[, ])C.chaxun2(Cvv, Css, XX, kik).ToArray();
                        Console.WriteLine(Xcha[0, 0]);
                    }
                    // c3-站号-时间段
                    else if (type == "c3")
                    {
                        string state = args[4].Split('-')[1];
                        string time  = args[4].Split('-')[2];
                        //将时间段转换为小时
                        double during  = 0;
                        bool   success = CollectionCons.DicStrToHour.TryGetValue(time, out during);
                        if (success == false)
                        {
                            Console.WriteLine("参数错误");
                            return;
                        }
                        double value       = 0;
                        string commandText = string.Empty;
                        C = new Class1();
                        foreach (double item in CollectionCons.StaticsPercents)
                        {
                            try
                            {
                                MWNumericArray kik = new MWNumericArray(item);
                                double[,] Xcha = (double[, ])C.chaxun1(Cvv, Css, XX, kik).ToArray();
                                value          = Xcha[0, 0];
                                //先查询数据是否存在,存在更新,不存在新增
                                commandText = string.Format("SELECT * FROM [DB_RainMonitor].[dbo].[RAINFALL_PERCENT] where [PERCENT]={0} and During={1} and MONITORNUM='{2}'", item, during, state);
                                object obj = SqlHelper.ExecuteScalar(SqlHelper.GetConnSting(), System.Data.CommandType.Text, commandText);
                                if (obj == null)
                                {
                                    commandText = string.Format("insert into RAINFALL_PERCENT values(NEWID(),'{0}',{1},{2},{3},{4},{5},{6},{7},'{8}',{9})", state, "null", "null", "null", X, Cv, Cs, item, during, value);
                                }
                                else
                                {
                                    commandText = string.Format("update RAINFALL_PERCENT set [VALUE] = {0} where [PERCENT]={1} and During={2} and MONITORNUM='{3}'", value, item, during, state);
                                }
                                SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), System.Data.CommandType.Text, commandText);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("入库失败-" + ex.Message);
                                return;
                            }
                        }
                        Console.WriteLine("入库成功!");
                    }
                }

                #endregion

                #region 暴雨衰减

                else if (methodName == MethodName.RainStormSub)
                {
                    //参数值 1-小于一小时的时间段,2-小于一小时的值,3-大于一小时的时间段,4-大于一小时的值

                    List <double> list1   = new List <double>();
                    string[]      minHour = args[2].Split(',');
                    Array.ForEach(minHour, t =>
                    {
                        list1.Add(Convert.ToDouble(t));
                    });
                    MWNumericArray MatY1 = new MWNumericArray(list1.ToArray());
                    List <double>  list2 = new List <double>();
                    minHour = args[1].Split(',');
                    Array.ForEach(minHour, t =>
                    {
                        list2.Add(Convert.ToDouble(t));
                    });
                    MWNumericArray MatX1 = new MWNumericArray(list2.ToArray());
                    List <double>  list3 = new List <double>();
                    minHour = args[4].Split(',');
                    Array.ForEach(minHour, t =>
                    {
                        list3.Add(Convert.ToDouble(t));
                    });
                    MWNumericArray MatY2 = new MWNumericArray(list3.ToArray());
                    List <double>  list4 = new List <double>();
                    minHour = args[3].Split(',');
                    Array.ForEach(minHour, t =>
                    {
                        list4.Add(Convert.ToDouble(t));
                    });
                    MWNumericArray MatX2 = new MWNumericArray(list4.ToArray());
                    try
                    {
                        C = new Class1();
                        SubCure sub = new SubCure();
                        //删除文件
                        string filePath = Path.Combine(Application.StartupPath, ConfigNames.SubCure);
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                        MWArray polyData3 = C.polyfit_line(MatX1, MatY1);
                        MWArray polyData1 = C.polyfit_line(MatX1, MatY1);
                        MWArray polyData2 = C.polyfit_line(MatX2, MatY2);
                        double[,] DataBox1 = (double[, ])polyData1.ToArray();
                        double[,] DataBox2 = (double[, ])polyData2.ToArray();
                        double d = (Math.Abs(DataBox2[0, 0]) / Math.Abs(DataBox1[0, 0]) - 1) * 0.3;
                        sub.d = d;
                        double k1 = Math.Log10(10 + d);
                        double k2 = Math.Log10(0.1 + d);
                        double nd = Math.Abs((DataBox1[0, 0] + DataBox2[0, 0]) / (k1 - k2));
                        double Sd = (Math.Pow((10 + d), nd) / Math.Pow(10, Math.Abs(DataBox2[0, 0]))) * Math.Pow(10, DataBox2[0, 1]);
                        sub.nd = nd;
                        sub.Sd = Sd;
                        sub.n1 = DataBox1[0, 0];
                        sub.j1 = DataBox1[0, 1];
                        sub.n2 = DataBox2[0, 0];
                        sub.j2 = DataBox2[0, 1];
                        XmlHelper.Serialize <SubCure>(sub, filePath);
                        Console.ReadKey();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (C != null)
                        {
                            C.Dispose();
                        }
                    }
                }

                #endregion

                #region d=0

                else if (methodName == MethodName.RainStormSub0)
                {
                    //参数值 1-小于一小时的时间段,2-小于一小时的值,3-大于一小时的时间段,4-大于一小时的值

                    List <double> list1   = new List <double>();
                    string[]      minHour = args[2].Split(',');
                    Array.ForEach(minHour, t =>
                    {
                        list1.Add(Convert.ToDouble(t));
                    });
                    MWNumericArray MatY1 = new MWNumericArray(list1.ToArray());
                    List <double>  list2 = new List <double>();
                    minHour = args[1].Split(',');
                    Array.ForEach(minHour, t =>
                    {
                        list2.Add(Convert.ToDouble(t));
                    });
                    MWNumericArray MatX1 = new MWNumericArray(list2.ToArray());
                    try
                    {
                        C = new Class1();
                        //删除文件
                        string filePath = Path.Combine(Application.StartupPath, ConfigNames.SubCure0);
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                        MWArray polyData3 = C.polyfit_line(MatX1, MatY1);
                        MWArray polyData1 = C.polyfit_line(MatX1, MatY1);
                        double[,] DataBox1 = (double[, ])polyData1.ToArray();
                        SubCure sub = new SubCure();
                        double  nd  = Math.Abs(2 * (DataBox1[0, 0]) / (Math.Log(10) - Math.Log(0.1)));
                        double  Sd  = (Math.Pow(10, nd) / Math.Pow(10, Math.Abs(DataBox1[0, 0]))) * Math.Pow(10, DataBox1[0, 1]);
                        sub.nd = nd;
                        sub.Sd = Sd;
                        sub.n1 = DataBox1[0, 0];
                        sub.j1 = DataBox1[0, 1];
                        XmlHelper.Serialize <SubCure>(sub, filePath);
                        Console.ReadKey();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (C != null)
                        {
                            C.Dispose();
                        }
                    }
                }

                #endregion

                #region 洪峰流量

                else if (methodName == MethodName.FloodPeak)
                {
                    //p1,Qm,eps1,sd,R,d,nd,r1,F,L1,L2,I1,I2,A1,A2,tc,eps2,项目路径

                    MWNumericArray p1_0 = new MWNumericArray(Convert.ToDouble(args[1]));
                    //MWArray p1_0 = MWArray(p);
                    MWNumericArray Qm_0 = new MWNumericArray(Convert.ToDouble(args[2]));
                    //MWArray Qm_0 = MWArray(Q);
                    MWNumericArray eps = new MWNumericArray(Convert.ToDouble(args[3]));
                    //MWArray eps = MWArray(ee);
                    MWNumericArray sd = new MWNumericArray(Convert.ToDouble(args[4]));
                    //MWArray sd = MWArray(s);
                    MWNumericArray R = new MWNumericArray(Convert.ToDouble(args[5]));
                    //MWArray R = MWArray(RR);
                    MWNumericArray d = new MWNumericArray(Convert.ToDouble(args[6]));
                    //MWArray d = MWArray(dd);
                    MWNumericArray nd = new MWNumericArray(Convert.ToDouble(args[7]));
                    //MWArray nd = MWArray(ndd);
                    MWNumericArray r1 = new MWNumericArray(Convert.ToDouble(args[8]));
                    //MWArray r1 = MWArray(rr1);
                    MWNumericArray F = new MWNumericArray(Convert.ToDouble(args[9]));
                    //MWArray F = MWArray(FF);
                    MWNumericArray L1 = new MWNumericArray(Convert.ToDouble(args[10]));
                    //MWArray L1 = MWArray(LL1);
                    MWNumericArray L2 = new MWNumericArray(Convert.ToDouble(args[11]));
                    //MWArray L2 = MWArray(LL2);
                    MWNumericArray I1 = new MWNumericArray(Convert.ToDouble(args[12]));
                    //MWArray I1 = MWArray(II1);
                    MWNumericArray I2 = new MWNumericArray(Convert.ToDouble(args[13]));
                    //MWArray I2 = MWArray(II2);
                    MWNumericArray A1 = new MWNumericArray(Convert.ToDouble(args[14]));
                    //MWArray A1 = MWArray(AA1);
                    MWNumericArray A2 = new MWNumericArray(Convert.ToDouble(args[15]));
                    //MWArray A2 = MWArray(AA2);
                    MWNumericArray tc   = new MWNumericArray(Convert.ToDouble(args[16]));
                    MWNumericArray eps1 = new MWNumericArray(Convert.ToDouble(args[17]));
                    try
                    {
                        C = new Class1();
                        MainResult result = new MainResult();
                        //删除文件
                        if (File.Exists(args[18]))
                        {
                            File.Delete(args[18]);
                        }
                        MWArray A = C.fun_main(p1_0, Qm_0, eps, sd, R, d, nd, r1, F, L1, L2, I1, I2, A1, A2);
                        double[,] AA = (double[, ])A.ToArray();
                        result.Qm    = AA[0, 0];
                        result.p1    = AA[0, 1];
                        result.tQ    = AA[0, 2];
                        result.d1    = AA[0, 3];

                        MWArray B = C.func_getTc(sd, R, d, nd, r1, AA[0, 0], AA[0, 1], AA[0, 2], F, tc, eps1);
                        double[,] BB = (double[, ])B.ToArray();
                        result.t     = BB[0, 0];
                        result.a1tc  = BB[0, 1];
                        result.d2    = BB[0, 5];
                        XmlHelper.Serialize <MainResult>(result, args[18]);
                        Console.ReadKey();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (C != null)
                        {
                            C.Dispose();
                        }
                    }
                }

                #endregion

                #region 导出Sd-Qm查询表

                else if (methodName == MethodName.SdQmTable)
                {
                    // 项目路径-保存表路径
                    string projectForlder = args[1];
                    string xmlPath        = Path.Combine(projectForlder, ConfigNames.RainStormSub);
                    //暴雨衰减赋值
                    BYSJResult bysj = null;
                    if (File.Exists(xmlPath))
                    {
                        bysj = XmlHelper.Deserialize <BYSJResult>(xmlPath);
                    }
                    //暴雨损失赋值
                    BYSSResult byss = null;
                    xmlPath = Path.Combine(projectForlder, ConfigNames.RainStormLoss);
                    if (File.Exists(xmlPath))
                    {
                        byss = XmlHelper.Deserialize <BYSSResult>(xmlPath);
                    }
                    //沟道汇流赋值
                    HCHLResult hchl = null;
                    xmlPath = Path.Combine(projectForlder, ConfigNames.RiverConfluence);
                    if (File.Exists(xmlPath))
                    {
                        hchl = XmlHelper.Deserialize <HCHLResult>(xmlPath);
                    }
                    //坡面汇流赋值
                    xmlPath = Path.Combine(projectForlder, ConfigNames.SlopeConfluence);
                    PMHLResult pmhl = null;
                    if (File.Exists(xmlPath))
                    {
                        pmhl = XmlHelper.Deserialize <PMHLResult>(xmlPath);
                    }
                    //默认参数
                    xmlPath = Path.Combine(projectForlder, ConfigNames.DefaultArgModel);
                    DefaultArgModel defaultArg = null;
                    if (File.Exists(xmlPath))
                    {
                        defaultArg = XmlHelper.Deserialize <DefaultArgModel>(xmlPath);
                    }
                    if (bysj == null || byss == null || hchl == null || pmhl == null || defaultArg == null)
                    {
                        Console.WriteLine("参数不全!");
                        return;
                    }
                    double         p1    = Convert.ToDouble(defaultArg.p1);
                    double         Qm_v  = Convert.ToDouble(defaultArg.Qm);
                    double         eps_0 = Convert.ToDouble(defaultArg.esp1);
                    MWNumericArray p1_0  = new MWNumericArray(p1);
                    MWNumericArray Qm_0  = new MWNumericArray(Qm_v);;
                    MWNumericArray eps   = new MWNumericArray(eps_0);
                    MWNumericArray R     = new MWNumericArray(byss.R);
                    MWNumericArray d     = new MWNumericArray(bysj.d);
                    MWNumericArray nd    = new MWNumericArray(bysj.nd);
                    MWNumericArray r1    = new MWNumericArray(byss.r1);
                    MWNumericArray F     = new MWNumericArray(byss.F);
                    MWNumericArray L1    = new MWNumericArray(hchl.L1);
                    MWNumericArray L2    = new MWNumericArray(pmhl.L2);
                    MWNumericArray I1    = new MWNumericArray(hchl.l1);
                    MWNumericArray I2    = new MWNumericArray(pmhl.l2);
                    MWNumericArray A1    = new MWNumericArray(hchl.A1);
                    MWNumericArray A2    = new MWNumericArray(pmhl.A2);

                    DataTable  aTable = new DataTable();
                    DataColumn Sd     = new DataColumn("Sd", typeof(double));
                    DataColumn Qm     = new DataColumn("Qm", typeof(double));
                    aTable.Columns.Add(Sd);
                    aTable.Columns.Add(Qm);
                    try
                    {
                        C = new Class1();
                        double sd_0 = 10;
                        for (int i = 0; i < 1001; i++)
                        {
                            MWNumericArray sd = new MWNumericArray(sd_0);
                            MWArray        A  = C.fun_main(p1_0, Qm_0, eps, sd, R, d, nd, r1, F, L1, L2, I1, I2, A1, A2);
                            double[,] AA = (double[, ])A.ToArray();
                            DataRow row = aTable.NewRow();
                            row["Sd"] = sd_0;
                            row["Qm"] = AA[0, 0];
                            aTable.Rows.Add(row);
                            sd_0 = sd_0 + 0.1;
                        }
                        XmlHelper.SaveDataToExcelFile(aTable, args[2]);
                        Console.WriteLine("导出完成!");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("导出异常:" + ex.Message);
                    }
                    finally
                    {
                        if (C != null)
                        {
                            C.Dispose();
                        }
                    }
                }

                #endregion
            }
        }
 public DataResult(T data, MainResult status)
 {
     Data   = data;
     Status = status;
 }