private void ValidateButton_Click(object sender, EventArgs e)
        {
            ErrorTextBox.Clear();

            var user = new UserModel()
            {
                Name        = NameTextBox.Text,
                LastName    = LastnameTextBox.Text,
                BirthDate   = BirthDatePicker.Value,
                HasCar      = HasCarCheckBox.Checked,
                PlateNumber = PlateTextBox.Text
            };

            var validator = new UserValidator();

            ValidationResult result = validator.Validate(user);

            if (result.IsValid)
            {
                ErrorTextBox.AppendText("Todo correcto");
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ErrorTextBox.AppendText(error.ErrorMessage);
                    ErrorTextBox.AppendText(Environment.NewLine);
                }
            }
        }
Beispiel #2
0
 void AppendNewLine(int count = 1)
 {
     for (int index = 0; index < count; index++)
     {
         ErrorTextBox.AppendText(Environment.NewLine);
     }
 }
Beispiel #3
0
 //метод очистки
 private void ClearMethod()
 {
     PolinomtextBox.Clear();
     CodeTextBox.Clear();
     ErrorTextBox.Clear();
     MessWithErrorTextBox.Clear();
     RecoveryTextBox.Clear();
 }
Beispiel #4
0
        void EndNodeInfo(NodeInfo info)
        {
            int pos = ErrorTextBox.SelectionStart;

            info.SelectionLength = pos - info.SelectionStart;
            ErrorTextBox.Select(info.SelectionStart, info.SelectionLength);
            info.SelectionRtf = ErrorTextBox.SelectedRtf;
            ErrorTextBox.Select(pos, 0);
        }
        /**************************************************************************************************
        * Console write errors.
        *
        * @param result The result.
        **************************************************************************************************/

        private void ConsoleWriteErrors(EmitResult result)
        {
            var failures = result.Diagnostics.Where(CodeHasError);
            var err      = "";

            foreach (var diagnostic in failures)
            {
                err += $"{diagnostic.Id}: {diagnostic.GetMessage()}";
            }

            ErrorTextBox.AppendText(err);
        }
Beispiel #6
0
        public void ResetProgram()
        {
            int test = new int();

            AttemptStop();
            ErrorTextBox.Clear();
            OutputTextBox.Clear();
            Interpret.Reset();
            Settings.CanReset = false;
            SetRunToRun();
            SetOptionsToOptions();
            EnableEdit();
            PixelGridUI.NewGrid();
        }
Beispiel #7
0
        void ShowCurrentItem()
        {
            var node = ErrorTreeView.SelectedNode;

            if (node != null)
            {
                var info = node.Tag as NodeInfo;
                if (info != null)
                {
                    ErrorTextBox.Rtf            = info.SelectionRtf;
                    ErrorTextBox.SelectionStart = 0;
                    ErrorTextBox.ScrollToCaret();
                }
            }
        }
Beispiel #8
0
        ///////////////////////////////////////////////////////////////////////////
        //
        ///////////////////////////////////////////////////////////////////////////
        private void UpdateSelectedErrorTextBox(IList <IExportSelectionError> selectedErrors)
        {
            if (selectedErrors.Count() == 0)
            {
                return;
            }
            // iterate through each file
            foreach (IExportSelectionError error in selectedErrors)
            {
                string sourceType = FolderOrFile(error.InputPath) + ": ";

                // spin through our error list and update the ui per file or folder
                foreach (ExportItemSelectionError e in error.Errors)
                {
                    ErrorTextBox.AppendText(sourceType + e.ToString() + " " + error.InputPath + "\n");
                }
            }
        }
Beispiel #9
0
        private void CreateDownloadInformation(string page, out string downloadAddress, out string fileName, out bool needExtension)
        {
            if (page == null)
            {
                throw new ArgumentNullException("Page Link cannot be null");
            }
            using (WebClient client = new WebClient())
            {
                int    counter   = 0;
                string hyperText = null;
TryGetWebPage:
                if (counter == 10)
                {
                    downloadAddress = null;
                    fileName        = null;
                    needExtension   = false;
                    return;
                }
                try
                {
                    Invoke(new MethodInvoker(() => ErrorTextBox.Clear()));
                    hyperText = client.DownloadString(page);
                }
                catch (WebException ex)
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        ErrorTextBox.AppendText("Timed out, will retry in 3 secs\n");
                        ErrorTextBox.AppendText($"{ex.StackTrace}\n");
                        Thread.Sleep(3000);
                    }));
                    counter++;
                    goto TryGetWebPage;
                }

                downloadAddress = CreateDownloadAddress(page, DownloadKey(hyperText));
                fileName        = GetFileName(hyperText, out needExtension);
            }
        }
Beispiel #10
0
        public void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            Invoke(new MethodInvoker(() =>
            {
                UnlockButtons();
                OutputTextBox.Clear();
            }));

            if (e.Cancelled)
            {
                Invoke(new MethodInvoker(() => OutputTextBox.Text = $"Cancelled downloading for {((DownloadSession)sender).FileName}"));
            }

            if (e.Error != null)
            {
                Invoke(new MethodInvoker(() =>
                {
                    ErrorTextBox.Clear();
                    ErrorTextBox.AppendText($@"{e.Error.Message} 
                    \n { e.Error.StackTrace}
                    \n { e.Error?.InnerException?.Message }
                    \n { e.Error?.InnerException?.StackTrace}");
                }));
            }

            else
            {
                Invoke(new MethodInvoker(() => OutputTextBox.AppendText($"Done with {((DownloadSession)sender).FileName}")));
            }

            IsDownloading = false;

            if (NotifyOnDone)
            {
                Invoke(new MethodInvoker(() => Notify()));
            }
        }
Beispiel #11
0
        void AppendText(string text, Font font = null)
        {
            if (text == null)
            {
                return;
            }
            if (font == null)
            {
                font = _small;
            }
            int pos = ErrorTextBox.SelectionStart;

            ErrorTextBox.AppendText(text);
            int len = ErrorTextBox.TextLength - pos;

            ErrorTextBox.Select(pos, len);
            ErrorTextBox.SelectionFont = font;
            ErrorTextBox.Select(ErrorTextBox.TextLength, 0);
            // Reset to small font
            if (ErrorTextBox.SelectionFont != _small)
            {
                ErrorTextBox.SelectionFont = _small;
            }
        }
Beispiel #12
0
        // Builds the tree in the left pane.
        // Each TreeViewItem.Tag will contain a list of Inlines
        // to display in the right-hand pane When it is selected.
        void BuildTree(Exception e, string summaryMessage)
        {
            try
            {
                LockWindowUpdate(ErrorTextBox.Handle);
                ErrorTextBox.Clear();

                // The first node in the tree contains the summary message and all the
                // nested exception messages.
                var firstItem = new TreeNode();
                firstItem.Text     = "All Messages";
                firstItem.NodeFont = new System.Drawing.Font(ErrorTreeView.Font, FontStyle.Bold);

                var tag = StartNewNodeInfo();
                firstItem.Tag = tag;

                ErrorTreeView.Nodes.Clear();
                ErrorTreeView.Nodes.Add(firstItem);

                // Now add top-level nodes for each exception while building
                // the contents of the first node.
                int count = 0;
                var items = new List <Exception>();
                if (e != null)
                {
                    items.Add(e);
                }
                while (items.Count > 0)
                {
                    e = items[0];
                    if (count > 0)
                    {
                        AppendText("____________________________________________________");
                        AppendNewLine(2);
                    }

                    AddException(e);

                    var aggEx = e as AggregateException;
                    if (aggEx != null)
                    {
                        foreach (var e2 in aggEx.InnerExceptions)
                        {
                            items.Add(e2);
                        }
                    }
                    else if (e.InnerException != null)
                    {
                        items.Add(e.InnerException);
                    }

                    items.RemoveAt(0);
                    ++count;
                }

                EndNodeInfo(tag);
                ErrorTreeView.SelectedNode = firstItem;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError("ErrorDialog.BuildTree - {0}: {1}\r\n{2}", ex.GetType().Name, ex.Message, ex);
            }
            finally
            {
                LockWindowUpdate(IntPtr.Zero);
            }
        }
Beispiel #13
0
        private void RefreshIndexes()
        {
            if (_currentTabPage == null)
            {
                _refreshThread = null;
                return;
            }

            var buttons = ButtonsOnCurrentPage;

            if (buttons != null)
            {
                Invoke(() =>
                {
                    foreach (var button in buttons)
                    {
                        button.Enabled = false;
                    }
                });
            }
            Invoke(() => _currentTabPage.Enabled = false);

            var isError = false;

            _stopEvent = true;
            Invoke(() => ErrorTextBox.Text = $"{DateTimeHelper.GetNowTime()} Чтение регистров \"{_currentTabPage.Text}\"");

            foreach (var c in _currentTabPage.Controls)
            {
                var control   = c as Control;
                var baseIndex = control?.Tag as BaseIndex;
                if (baseIndex != null)
                {
                    try
                    {
                        if (_threadAborted)
                        {
                            _threadAborted = false;
                            _refreshThread = null;
                            Invoke(StartRefreshIndexes);
                            return;
                        }

                        var x = ModbusTool.Read(baseIndex, _compressorSetting);

                        if (_threadAborted)
                        {
                            _threadAborted = false;
                            _refreshThread = null;
                            Invoke(StartRefreshIndexes);
                            return;
                        }

                        if (c is CheckBox)
                        {
                            Invoke(() => ((CheckBox)c).Checked = x == 1);
                        }
                        else if (c is TextBox)
                        {
                            Invoke(() => ((TextBox)c).Text = x.ToString());
                        }
                        else if (c is NumericUpDown)
                        {
                            Invoke(() =>
                            {
                                ((NumericUpDown)c).Value = x;
                                ValidateRegister((NumericUpDown)c);
                            });

                            /*
                             * catch (Exception ex)
                             * {
                             *  isError = true;
                             *  Invoke(() => ExceptionHelper.ShowException(ErrorTextBox, ex, true,
                             *      $"{DateTimeHelper.GetNowTime()} Ошибка чтения регистра {baseIndex.Address} с функцией {baseIndex.Function}, значение {x} не входит в заданные рамки [{((NumericUpDown) c).Minimum} - {((NumericUpDown) c).Maximum}]"));
                             * }
                             */
                        }
                        else if (c is ComboBox)
                        {
                            var source = ((ComboBox)c).DataSource as List <CustomValue>;
                            Invoke(() => ((ComboBox)c).SelectedValue = x);
                            if (source != null)
                            {
                                Invoke(() => ((ComboBox)c).SelectedItem = source.FirstOrDefault(u => u.Value == x));
                            }
                        }
                        else
                        {
                            Invoke(() => control.Text = x.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        isError = true;
                        Invoke(() => ExceptionHelper.ShowException(ErrorTextBox, ex, true,
                                                                   $"{DateTimeHelper.GetNowTime()} Ошибка чтения регистра {baseIndex.Address} с функцией {baseIndex.Function}"));
                    }
                }
            }
            _stopEvent = false;
            if (!isError)
            {
                Invoke(() => ErrorTextBox.AppendText($"\r\n{DateTimeHelper.GetNowTime()} Все регистры \"{_currentTabPage.Text}\" прочитаны без ошибок"));
            }

            var rButton = RefreshButton;

            if (rButton != null)
            {
                Invoke(() => rButton.Enabled = true);
            }
            Invoke(() => _currentTabPage.Enabled = true);

            /*
             * if (buttons != null)
             *  Invoke(() =>
             *  {
             *      foreach (var button in buttons)
             *      {
             *          button.Enabled = true;
             *      }
             *  });
             */
            _refreshThread = null;
        }
Beispiel #14
0
        public void BeginChainDownloading()
        {
            currentPage = PageNumberBox.Text;
            searchText  = SearchBox.Text;
            bool currentHasNextPage;

            do
            {
                IsDownloading = true;
                if (!HasFiltred)
                {
                    Filter();
                }
                Invoke(new MethodInvoker(() =>
                {
                    OutputTextBox.AppendText($"\n\nStarting Page { currentPage } \n\n");
                }));
                foreach (DataGridViewRow row in Grid.Rows)
                {
                    if (row.Cells[0].Value == null)
                    {
                        continue;
                    }
                    CreateDownloadInformation(row.Cells["Address"].Value as string, out string downloadAddress, out string fileName, out bool needExtension);
                    if (downloadAddress == null)
                    {
                        Invoke(new MethodInvoker(() => ErrorTextBox.Text = "Timed Out. Please try again later."));
                        return;
                    }
                    if (File.Exists(downloadLocation + fileName))
                    {
                        Invoke(new MethodInvoker(() => OutputTextBox.AppendText($"File {fileName} Exists\n\n")));
                        continue;
                    }
                    using (WebClient client = new WebClient())
                    {
                        Invoke(new MethodInvoker(() => OutputTextBox.AppendText($"Started Download of {fileName}\n\n")));
                        try
                        {
                            File.WriteAllBytes(
                                string.Format(@"\\?\{0}{1}{2}",
                                              downloadLocation,
                                              fileName,
                                              needExtension ? row.Cells["Extension"].Value : string.Empty)
                                , client.DownloadData(downloadAddress));
                        }
                        catch (WebException we)
                        {
                            Invoke(new MethodInvoker(() =>
                            {
                                ErrorTextBox.Clear();
                                _logger.Error(Severity.HUGE, "Failed Download!!"
                                              , downloadAddress, fileName);
                                ErrorTextBox.AppendText($"For File {fileName}\n");
                                ErrorTextBox.AppendText($"{we.Message}\n");
                                ErrorTextBox.AppendText($"{we.StackTrace}\n");
                                ErrorTextBox.AppendText($"{we?.InnerException?.Message}\n");
                                ErrorTextBox.AppendText($"{we.InnerException?.StackTrace}\n");
                                OutputTextBox.AppendText($"Download For {fileName} failed.\n\n");
                            }));
                            continue;
                        }
                    }
                    Invoke(new MethodInvoker(() =>
                    {
                        OutputTextBox.AppendText($"Successful Download of {fileName}\n\n");
                    }));
                }
                currentHasNextPage = HasNextPage;
                CreatePage(searchText, currentPage = (int.Parse(currentPage) + 1).ToString());
            } while (currentHasNextPage);

            IsDownloading = false;

            Invoke(new MethodInvoker(() =>
            {
                OutputTextBox.AppendText($"Finished Chain Downloading \n");
            }));
        }
Beispiel #15
0
 private void TextBox_OnTextChanged(object sender, TextChangedEventArgs e)
 {
     ErrorTextBox.ScrollToEnd();
 }
Beispiel #16
0
        ///////////////////////////////////////////////////////////////////////////
        //
        ///////////////////////////////////////////////////////////////////////////
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            // Get the file manager
            IFileManager fm = application_.FileManager;

            // Block User Pop Ups
            application_.UserInteractionManager.SuppressUserInteraction = true;

            try
            {
                // clear out prior errors
                ErrorTextBox.Clear();

                // Add Files
                List <string> itemsForExport = new List <string>();
                itemsForExport.AddRange(FilesListBox.Items.Cast <string>());

                IList <IExportSelectionError> selectedErrors
                    = new List <IExportSelectionError>();

                switch (OutputFormat.SelectedIndex)
                {
                /////////////////////////////////////////////
                // Tagged image file format
                /////////////////////////////////////////////
                case 0:
                    ITiffExportSettings tifSettings = (ITiffExportSettings)fm.CreateExportSettings(ExportFileType.Tiff);

                    // Specifics
                    tifSettings.IncludeAllExperimentInformation = true;

                    baseSettings_ = tifSettings;
                    break;

                /////////////////////////////////////////////
                // Comma Seperated Values
                /////////////////////////////////////////////
                case 1:
                    ICsvExportSettings csvSettings = (ICsvExportSettings)fm.CreateExportSettings(ExportFileType.Csv);

                    List <CsvTableFormat> list = new List <CsvTableFormat>();
                    list.Add(CsvTableFormat.Frame);
                    list.Add(CsvTableFormat.Region);
                    list.Add(CsvTableFormat.Wavelength);
                    list.Add(CsvTableFormat.Column);
                    list.Add(CsvTableFormat.Intensity);
                    list.Add(CsvTableFormat.Row);

                    // Specifics
                    csvSettings.TableFormat          = list;
                    csvSettings.HeaderType           = CsvExportHeader.Long;
                    csvSettings.IncludeFormatMarkers = true;
                    csvSettings.Layout = CsvLayout.Matrix;

                    // Set culture to regional with the default separator
                    csvSettings.FieldSeparator = CsvFieldSeparator.Auto;
                    csvSettings.NumberFormat   = CsvNumberFormat.Regional;

                    baseSettings_ = csvSettings;
                    break;

                /////////////////////////////////////////////
                // Galactic SPC spectroscopy file type
                /////////////////////////////////////////////
                case 2:
                    ISpcExportSettings spcSettings = (ISpcExportSettings)fm.CreateExportSettings(ExportFileType.Spc);

                    // Specifics
                    spcSettings.GlobalTimeUnit = TimeUnit.Milliseconds;

                    baseSettings_ = spcSettings;
                    break;

                /////////////////////////////////////////////
                // Grams Fits file format
                /////////////////////////////////////////////
                case 3:
                    IFitsExportSettings fitsSettings = (IFitsExportSettings)fm.CreateExportSettings(ExportFileType.Fits);

                    // Specifics
                    fitsSettings.IncludeAllExperimentInformation = true;

                    baseSettings_ = fitsSettings;
                    break;

                /////////////////////////////////////////////
                // AVI file format
                /////////////////////////////////////////////
                case 4:
                    IAviExportSettings aviSettings = (IAviExportSettings)fm.CreateExportSettings(ExportFileType.Avi);

                    // Specifics
                    aviSettings.FrameRate       = 30.0;
                    aviSettings.Compressed      = false;
                    aviSettings.AlwaysAutoScale = true;

                    baseSettings_ = aviSettings;
                    break;
                }
                // Common Settings for all types
                baseSettings_.CustomOutputPath = customPath_;
                baseSettings_.OutputPathOption = options_;
                baseSettings_.OutputMode       = (ExportOutputMode)Enum.Parse(typeof(ExportOutputMode), ModeCombo.Text);

                selectedErrors = baseSettings_.Validate(itemsForExport);

                // Show any errors
                UpdateSelectedErrorTextBox(selectedErrors);

                // Async Mode
                if (AsyncCheckBox.IsChecked == true)
                {
                    fm.ExportCompleted += new EventHandler <ExportCompletedEventArgs>(fm_ExportCompleted);

                    application_.UserInteractionManager.ApplicationBusyStatus = ApplicationBusyStatus.Busy;
                    fm.ExportAsync(baseSettings_, itemsForExport);

                    // Enable cancel
                    CancelButton.IsEnabled = true;
                    ExportButton.IsEnabled = false;
                }
                // Sync Mode
                else
                {
                    ExportButton.IsEnabled = false;

                    // Busy cursor during write
                    using (new AddInStatusHelper(application_, ApplicationBusyStatus.Busy))
                    {
                        fm.Export(baseSettings_, itemsForExport);
                    }
                    ExportButton.IsEnabled = true;
                }
            }
            finally
            {
                application_.UserInteractionManager.SuppressUserInteraction = false;
            }
        }