private ValidException CheckValidation()
        {
            ValidException validException = new ValidException(true, "Неверные данные");

            validException.IsValid = IsValid(Dx);
            return(validException);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     设置异常
        /// </summary>
        /// <param name="log">日志操作</param>
        /// <param name="exception">异常</param>
        public static ILog Exception(this ILog log, ValidException exception)
        {
            if (exception == null)
            {
                return(log);
            }

            return(log.Set <LogContent>(content => {
                content.ErrorCode = exception.Code;
                content.Exception = exception;
            }));
        }
        private void Draw_Click(object sender, RoutedEventArgs e)
        {
            try {
                ValidException validException = CheckValidation();

                isAsync = async.IsChecked == true;
                isSync  = sync.IsChecked == true;

                Dx.Text = Dx.Text.Replace(" ", string.Empty).Replace(".", ",");

                if (!validException.IsValid)
                {
                    throw validException;
                }
                dx = double.Parse(Dx.Text);

                Draw(dx);
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 4
0
        private void Graphic_Click(object sender, RoutedEventArgs e)
        {
            try {
                GC.Collect();
                ValidException validException = CheckValidation();

                if (!validException.IsValid)
                {
                    throw validException;
                }

                r.Text = r.Text.Replace(" ", string.Empty).Replace(".", ",");
                g.Text = g.Text.Replace(" ", string.Empty).Replace(".", ",");
                l.Text = l.Text.Replace(" ", string.Empty).Replace(".", ",");
                n.Text = n.Text.Replace(" ", string.Empty).Replace(".", ",");

                GraphicWindow w = new GraphicWindow();
                w.Alohas = new IAloha[] {
                    new Asynchronous(
                        int.Parse(n.Text),
                        int.Parse(r.Text),
                        double.Parse(g.Text),
                        int.Parse(l.Text)
                        ),
                    new Synchronous(
                        int.Parse(n.Text),
                        int.Parse(r.Text),
                        double.Parse(g.Text),
                        int.Parse(l.Text)
                        ),
                };
                w.ShowDialog();

                GC.Collect();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 5
0
        private void Go_Click(object sender, RoutedEventArgs e)
        {
            try {
                GC.Collect();
                states = states ?? new Dictionary <Helpers.Type, State[]>();
                ValidException validException = CheckValidation();
                Graphic.IsEnabled = validException.IsValid;
                bool isAsync = Async.IsChecked == true;
                bool isSync  = Sync.IsChecked == true;

                this.listbox.Items.Clear();
                states?.Clear();

                r.Text = r.Text.Replace(" ", string.Empty).Replace(".", ",");
                g.Text = g.Text.Replace(" ", string.Empty).Replace(".", ",");
                l.Text = l.Text.Replace(" ", string.Empty).Replace(".", ",");
                n.Text = n.Text.Replace(" ", string.Empty).Replace(".", ",");

                this.listbox.Items.Add("Aloha считает...");

                if (!validException.IsValid)
                {
                    throw validException;
                }

                if (isSync || isAsync)
                {
                    if (isAsync)
                    {
                        states.Add(Helpers.Type.Async, AlohaState(new Asynchronous(
                                                                      int.Parse(n.Text),
                                                                      int.Parse(r.Text),
                                                                      double.Parse(g.Text),
                                                                      int.Parse(l.Text)
                                                                      )));
                    }
                    if (isSync)
                    {
                        states.Add(Helpers.Type.Sync, AlohaState(new Synchronous(
                                                                     int.Parse(n.Text),
                                                                     int.Parse(r.Text),
                                                                     double.Parse(g.Text),
                                                                     int.Parse(l.Text)
                                                                     )));
                    }
                }
                else
                {
                    throw new Exception("Выбирите хотя бы один метод Алоха!");
                }

                this.listbox.Items.Clear();

                foreach (Helpers.Type number in states.Keys)
                {
                    switch (number)
                    {
                    case Helpers.Type.Async:
                        this.listbox.Items.Add("------Асинхронная------");
                        break;

                    case Helpers.Type.Sync:
                        this.listbox.Items.Add("------Синхронная------");
                        break;
                    }

                    foreach (State state in states[number])
                    {
                        this.listbox.Items.Add(state.ToString());
                    }

                    this.listbox.Items.Add("/*******************************************************************/");
                }

                Report.IsEnabled = states.Count == 2;
                this.listbox.Items.RemoveAt(listbox.Items.Count - 1);
                GC.Collect();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }