private async void _view_InsertButtonClick(object sender, EventArgs e)
        {
            _view.Status = "Виконується формування ряду. Будь ласка, зачекайте...";

            string       Row      = _view.TextRow;
            DataGridView datagrid = _view.RowGrid;
            TimeRow      rowtable = new TimeRow();

            _view.StatusProgress.Visible = true;
            Func <bool> func = () =>
            {
                try
                {
                    char spliter = ' ';

                    for (int i = 0; i < Row.Length; i++)
                    {
                        if (!(Char.IsDigit(Row[i])) && Row[i] != ',' && Row[i] != '-')
                        {
                            if (Row[i - 1] != ' ')
                            {
                                Row = Row.Replace(Row[i], ' ');
                            }
                            else
                            {
                                Row = Row.Remove(i, 1); i--;
                            }
                        }
                    }
                    if (!(Char.IsDigit(Row[Row.Length - 1])))
                    {
                        Row = Row.Remove(Row.Length - 1, 1);
                    }

                    float[] array = Row.Split(spliter).Select((x) => (float)Convert.ToDouble(x)).ToArray();
                    rowtable.Row = array;

                    return(true);
                }
                catch (Exception exception)
                {
                    _message.ShowMessage(exception.Message);
                    return(false);
                }
            };

            bool task = await Task <bool> .Factory.StartNew(func);

            string message = task ? "Готово!" : "Невдача!";

            _view.StatusProgress.Visible = false;
            _view.Status = message;

            _view.TextRow = Row;
            _view.SetRowGrid(rowtable.Row);

            RowGridDataChanged?.Invoke(this, EventArgs.Empty);
            _view.StartBtnEnable = task;

            rowtable.Dispose();
            datagrid = null;
            Row      = null;
            GC.Collect();
        }
        private async void _view_RandomRowClick(object sender, EventArgs e)
        {
            _view.Status = "Генерується ряд випадкових чисел. Будь ласка, зачекайте...";

            string  N        = _view.N;
            string  Row      = "";
            TimeRow rowtable = new TimeRow();

            _view.StatusProgress.Visible = true;
            Func <bool> func = () =>
            {
                try
                {
                    TimeRow row       = new TimeRow(Convert.ToInt32(N), 100);
                    int     max       = row.GetSize();
                    int     move      = 0;
                    int     invokeVal = max / 10;
                    rowtable = row;
                    for (int i = 0; i < row.GetSize(); i++)
                    {
                        Row += Math.Round(row[i], 4);
                        if (i < row.GetSize() - 1)
                        {
                            Row += '\r';
                            Row += '\n';
                        }
                        move++;
                        if (move % invokeVal == 0)
                        {
                            ProgressAction?.Invoke(10, move / invokeVal);
                        }
                    }

                    row.Dispose();
                    return(true);
                }
                catch (Exception exception)
                {
                    //_message.ShowError("Невірно задані параметри.");
                    _message.ShowError(exception.Message);
                    return(false);
                }
            };

            bool task = await Task <bool> .Factory.StartNew(func);

            string message = task ? "Готово!" : "Невдача!";

            _view.StatusProgress.Visible = false;

            _view.Status  = message;
            _view.TextRow = Row;
            _view.SetRowGrid(rowtable.Row);

            RowGridDataChanged?.Invoke(this, EventArgs.Empty);
            _view.StartBtnEnable = task;

            Row = null;
            rowtable.Dispose();
            GC.Collect();
        }
        private async void _view_FxButtonClick(object sender, EventArgs e)
        {
            _view.Status = "Будується числовий ряд функції. Будь ласка, зачекайте...";
            var   expression = "";
            var   nativeFx   = _view.Fx;
            int   start      = Convert.ToInt32(_view.RowStart);
            int   n          = Convert.ToInt32(_view.RowEnd);
            float step       = (float)Convert.ToDouble(_view.RowStep);

            float[] rowtable = new float[(int)(Math.Round(((n - start) / step)))];
            string  Row      = "";

            _view.StatusProgress.Visible = true;

            Func <bool> func = () => {
                try
                {
                    int move      = 0;
                    int invokeVal = n / 10;
                    for (float i = start; i < n; i += step)                              // 0 + step
                    {
                        expression     = nativeFx;
                        expression     = expression.Replace("x", Convert.ToString(i).Replace(',', '.'));
                        Row           += Math.Round(Convert.ToDouble(new Expression(expression).Evaluate()), 4);
                        rowtable[move] = (float)(Math.Round(Convert.ToDouble(new Expression(expression).Evaluate()), 4));
                        if (move % invokeVal == 0)
                        {
                            ProgressAction?.Invoke(10, move / invokeVal);
                        }
                        move++;
                        if (i < n - step)
                        {
                            Row += "\r\n";
                        }
                    }
                    if (move < n)
                    {
                        ProgressAction?.Invoke(n, n);
                    }
                    return(true);
                }
                catch (Exception exception)
                {
                    _message.ShowExclamation(exception.Message);
                    return(false);
                }
            };

            bool task = await Task <bool> .Factory.StartNew(func);

            string message = task ? "Готово!" : "Невдача!";

            _view.StatusProgress.Visible = false;
            _view.Status  = message;
            _view.TextRow = Row;
            _view.SetRowGrid(rowtable);
            RowGridDataChanged?.Invoke(this, EventArgs.Empty);

            _view.StartBtnEnable = task;
            rowtable             = null;
            GC.Collect();
        }
        private async void _view_OpenClick(object sender, EventArgs e)
        {
            _view.Status = "Завантажується проект. Будь ласка, зачекайте...";

            Image diagramRasterized = new Bitmap(_view.DiagramBox.Width, _view.DiagramBox.Height);
            Image diagramDistance   = new Bitmap(_view.DistanceBox.Width, _view.DistanceBox.Height);
            Image scaleDistance     = new Bitmap(_view.DistanceScaleBox.Width, _view.DistanceScaleBox.Height);

            _view.PointDiagram.Series[0].Points.Clear();
            _view.SplineDiagram.Series[0].Points.Clear();
            Chart pointDiagram = _view.PointDiagram.Copy();
            Chart lineDiagram  = _view.SplineDiagram.Copy();

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter           = "txt files (*.txt)|*.txt|wav files (*.wav)|*.wav|Recurrent plot projects (*.rpp)|*.rpp";
            dialog.FilterIndex      = 3;
            dialog.RestoreDirectory = true;

            string  path           = "";
            string  AnalysisResult = "";
            Project loaded         = new Project();

            float epsilon = 1;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                if (dialog.OpenFile() != null)
                {
                    try
                    {
                        path = dialog.FileName;
                    }
                    catch (Exception exception)
                    {
                        _message.ShowMessage(exception.Message);
                    }
                }
            }

            _view.StatusProgress.Visible = true;

            Func <bool> func = () =>
            {
                try
                {
                    if (dialog.FilterIndex == 2)
                    {                                                           //Sound
                        loaded.Epsilon = 0.1F;
                        loaded.Row     = Audio.prepare(path);
                        char[] charArray = path.ToCharArray();
                        loaded.Name = String.Concat(charArray.Reverse().Skip(4).TakeWhile((p) => p != '\\').Reverse());
                        charArray   = null;
                    }
                    else if (dialog.FilterIndex == 1)
                    {
                        char         spliter = ' ';
                        StreamReader reader  = new StreamReader(path);
                        string       Row     = reader.ReadToEnd();

                        for (int i = 0; i < Row.Length; i++)
                        {
                            if (!(Char.IsDigit(Row[i])) && Row[i] != ',' && Row[i] != '-')
                            {
                                if (Row[i - 1] != ' ')
                                {
                                    Row = Row.Replace(Row[i], ' ');
                                }
                                else
                                {
                                    Row = Row.Remove(i, 1); i--;
                                }
                            }
                            ProgressAction?.Invoke(Row.Length, i);
                        }
                        if (!(Char.IsDigit(Row[Row.Length - 1])))
                        {
                            Row = Row.Remove(Row.Length - 1, 1);
                        }

                        float[] array = Row.Split(spliter).Select((x) => (float)(Convert.ToDouble(x))).ToArray();
                        loaded.Epsilon = 1;
                        loaded.Row     = array;
                        char[] charArray = path.ToCharArray();
                        loaded.Name = String.Concat(charArray.Reverse().Skip(4).TakeWhile((p) => p != '\\').Reverse());
                    }                       //Numbers
                    else
                    {                       //Project
                        StreamReader reader = new StreamReader(path, Encoding.Unicode);
                        string       json   = reader.ReadToEnd();
                        loaded = JsonConvert.DeserializeObject <Project>(json);
                        reader.Close();

                        ManageDiagrams(new TimeRow(loaded.Row), loaded.Epsilon, ref diagramRasterized,
                                       ref diagramDistance, ref scaleDistance, ref pointDiagram, ref lineDiagram, ref AnalysisResult);
                    }
                    return(true);
                }
                catch (Exception exception)
                {
                    _message.ShowMessage(exception.Message);
                    return(false);
                }
            };

            bool task = await Task <bool> .Factory.StartNew(func);

            string message = task ? "Готово!" : "Невдача!";

            _view.StatusProgress.Visible = false;
            _view.Status = message;

            _view.PointDiagram.Series[0]  = pointDiagram.Series[0];
            _view.SplineDiagram.Series[0] = lineDiagram.Series[0];
            _view.DiagramBox.Image        = diagramRasterized;
            _view.DistanceBox.Image       = diagramDistance;
            _view.DistanceScaleBox.Image  = scaleDistance;
            _view.Analysis = AnalysisResult;

            _view.E = epsilon.ToString();
            _view.SetRowGrid(loaded.Row);

            RowGridDataChanged?.Invoke(this, EventArgs.Empty);
            _view.StartBtnEnable = task;

            /*** project reload ***/
            project        = loaded;
            _view.FormName = project.Name + appName;

            loaded            = null;
            AnalysisResult    = null;
            diagramRasterized = null;
            diagramDistance   = null;
            scaleDistance     = null;
            pointDiagram      = null;
            lineDiagram       = null;

            GC.Collect();
        }