コード例 #1
0
ファイル: ExecOutputCtrl.cs プロジェクト: menees/MegaBuild
        public override bool OnOk()
        {
            bool result = true;

            List <(OutputStyle Style, Regex Pattern)>?list = null;

            foreach (ListViewItem item in this.lstPatterns.Items)
            {
                if (Enum.TryParse(item.SubItems[0].Text, out OutputStyle style) &&
                    ExecutableStep.TryParseRegex(item.SubItems[1].Text, out Regex? regex))
                {
                    list ??= new();
                    list.Add((style, regex));
                }
                else
                {
                    item.Selected = true;
                    item.EnsureVisible();
                    WindowsUtility.ShowError(this, "The selected custom style is invalid.");
                    this.lstPatterns.Focus();
                    item.Focused = true;
                    result       = false;
                    break;
                }
            }

            if (result && this.step != null)
            {
                this.step.AutoColorErrorsAndWarnings = this.chkAutoColorErrorsAndWarnings.Checked;
                this.step.CustomOutputStyles         = list;
            }

            return(result);
        }
コード例 #2
0
        public override bool OnOk()
        {
            bool result = false;

            if (this.edtCommand.Text.Trim().Length == 0)
            {
                WindowsUtility.ShowError(this, "You must enter a command.");
            }
            else if (this.numFirstSuccess.Value > this.numLastSuccess.Value)
            {
                WindowsUtility.ShowError(this, "The last success code must be greater than or equal to the first success code.");
            }
            else if (this.step != null)
            {
                this.step.Command          = this.edtCommand.Text;
                this.step.Arguments        = this.edtArguments.Text;
                this.step.WorkingDirectory = this.edtWorkingDirectory.Text;
                this.step.WindowState      = (ProcessWindowStyle)this.cbWindowState.SelectedIndex;
                this.step.UseShellExecute  = this.chkShellExecute.Checked;
                this.step.Verb             = this.edtVerb.Text;
                this.step.FirstSuccessCode = (int)this.numFirstSuccess.Value;
                this.step.LastSuccessCode  = (int)this.numLastSuccess.Value;
                this.step.RedirectStreams  = this.RedirectStreams;
                result = true;
            }

            return(result);
        }
コード例 #3
0
        private bool TryGetGizmoTypes(string assemblyName, bool showErrors)
        {
            List <string> errors = new List <string>();

            if (!File.Exists(assemblyName))
            {
                errors.Add("The specified assembly does not exist: " + assemblyName);
            }
            else
            {
                using (new WaitCursor())
                {
                    IList <GizmoInfo> gizmoTypes = Gizmo.GetGizmoTypes(assemblyName, errors);
                    bool foundTypes = gizmoTypes != null && gizmoTypes.Count > 0;

                    // Use a "dummy" list if no types are found, so that other data-bound controls will enable/disable correctly.
                    if (!foundTypes)
                    {
                        gizmoTypes = NoGizmosFound.GizmoTypes;
                    }

                    this.SetDataContext(gizmoTypes, foundTypes);
                }
            }

            bool result = errors.Count == 0;

            if (!result && showErrors)
            {
                WindowsUtility.ShowError(this, string.Join(Environment.NewLine, errors));
            }

            return(result);
        }
コード例 #4
0
ファイル: VSStepCtrl.cs プロジェクト: menees/MegaBuild
        public override bool OnOk()
        {
            bool result = false;

            if (string.IsNullOrEmpty(this.edtSolution.Text.Trim()))
            {
                WindowsUtility.ShowError(this, "You must enter a solution file name.");
            }
            else if (this.lstConfigurations.CheckedItems.Count == 0)
            {
                WindowsUtility.ShowError(this, "You must select at least one configuration to build.");
            }
            else if (this.step != null)
            {
                this.step.Solution        = this.edtSolution.Text;
                this.step.Action          = (VSAction)this.cbAction.SelectedIndex;
                this.step.Version         = (VSVersion)this.cbVersion.SelectedIndex;
                this.step.WindowState     = (ProcessWindowStyle)this.cbWindowState.SelectedIndex;
                this.step.DevEnvArguments = this.edtDevEnvArgs.Text;
                this.step.RedirectStreams = this.chkRedirectStreams.Checked;
                this.step.GetConfigurationsFromListView(this.lstConfigurations);
                result = true;
            }

            return(result);
        }
コード例 #5
0
        private void Window_Loaded(object?sender, RoutedEventArgs e)
        {
            CommandLine parser = new(false);

            parser.AddHeader(CommandLine.ExecutableFileName + " [/BringToFront]");
            bool bringToFront = false;

            parser.AddSwitch("BringToFront", "Makes the app attempt to force its way to the foreground when launched.", value => bringToFront = value);

            switch (parser.Parse())
            {
            case CommandLineParseResult.Valid:
                if (bringToFront)
                {
                    this.ExecuteWhenIdle(() => WindowsUtility.BringToFront(this));
                }

                break;

            case CommandLineParseResult.HelpRequested:
                this.ExecuteWhenIdle(() => WindowsUtility.ShowInfo(this, parser.CreateMessage()));
                break;

            default:
                this.ExecuteWhenIdle(() => WindowsUtility.ShowError(this, parser.CreateMessage()));
                break;
            }
        }
コード例 #6
0
        public override bool OnOk()
        {
            bool result = false;

            if (this.rbWavFile.Checked && string.IsNullOrEmpty(this.edtWavFile.Text.Trim()))
            {
                WindowsUtility.ShowError(this, "You must specify a .wav filename.");
            }
            else if (this.step != null)
            {
                if (this.rbSystemSound.Checked)
                {
                    this.step.Style = SoundStyle.SystemSound;
                }
                else if (this.rbWavFile.Checked)
                {
                    this.step.Style = SoundStyle.WavFile;
                }
                else
                {
                    this.step.Style = SoundStyle.Beep;
                }

                this.step.SystemSound = (SystemSound)this.cbSystemSound.SelectedItem;
                this.step.WavFile     = this.edtWavFile.Text.Trim();
                this.step.Frequency   = (int)this.edtFrequency.Value;
                this.step.Duration    = (int)this.edtDuration.Value;

                result = true;
            }

            return(result);
        }
コード例 #7
0
ファイル: EmailStepCtrl.cs プロジェクト: menees/MegaBuild
        public override bool OnOk()
        {
            bool result = false;

            if (this.edtFrom.Text.Trim().Length == 0)
            {
                WindowsUtility.ShowError(this, "You must enter an email address in the \"From\" field.");
            }
            else if (this.edtTo.Text.Trim().Length == 0)
            {
                WindowsUtility.ShowError(this, "You must enter an email address in the \"To\" field.");
            }
            else if (this.edtSubject.Text.Trim().Length == 0 && this.txtMessage.Text.Trim().Length == 0 && !this.chkAppendOutput.Checked)
            {
                WindowsUtility.ShowError(this, "You must enter something that can be emailed (e.g. Subject, Message, or Append Output).");
            }
            else if (this.step != null)
            {
                this.step.From         = this.edtFrom.Text;
                this.step.To           = this.edtTo.Text;
                this.step.CC           = this.edtCC.Text;
                this.step.Subject      = this.edtSubject.Text;
                this.step.Message      = this.txtMessage.Text;
                this.step.AppendOutput = this.chkAppendOutput.Checked;
                this.step.Priority     = (MailPriority)this.cbPriority.SelectedIndex;
                this.step.SmtpServer   = this.edtSmtpServer.Text;
                result = true;
            }

            return(result);
        }
コード例 #8
0
        private void OK_Click(object sender, EventArgs e)
        {
            // Check the variables for uniqueness and non-emptyness.
            // Since the ListView is sorted, we'll just scan and
            // check the current against the previous.
            string previousName = string.Empty;

            foreach (ListViewItem item in this.lstVariables.Items)
            {
                string name = item.Text;
                if (name.Length == 0 || name == "%%")
                {
                    WindowsUtility.ShowError(this, "A variable cannot have an empty name (i.e. %%).");
                    this.DialogResult = DialogResult.None;
                }

                if (name == previousName)
                {
                    WindowsUtility.ShowError(this, string.Format("The variable {0} is defined multiple times, but it can only be defined once.", name));
                    this.DialogResult = DialogResult.None;
                }

                previousName = name;
            }
        }
コード例 #9
0
        public override bool OnOk()
        {
            bool result = false;

            string projectFile = this.edtProject.Text.Trim();

            if (string.IsNullOrEmpty(projectFile))
            {
                WindowsUtility.ShowError(this, "You must enter a project file name.");
            }
            else
            {
                List <string> targets = new();
                foreach (string line in this.txtTargets.Lines)
                {
                    string target = line.Trim();
                    if (!string.IsNullOrEmpty(target))
                    {
                        targets.Add(target);
                    }
                }

                result = true;
                Dictionary <string, string> properties = new();
                foreach (string line in this.txtProperties.Lines)
                {
                    string[] parts = line.Trim().Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 2)
                    {
                        properties[parts[0].Trim()] = parts[1].Trim();
                    }
                    else if (parts.Length != 0)
                    {
                        WindowsUtility.ShowError(this, "Unable to parse the following as a Name=Value pair: " + line);
                        result = false;
                        break;
                    }
                }

                if (result && this.step != null)
                {
                    this.step.ProjectFile        = projectFile;
                    this.step.WorkingDirectory   = this.edtWorkingDirectory.Text.Trim();
                    this.step.Targets            = targets.ToArray();
                    this.step.Properties         = properties;
                    this.step.Verbosity          = (MSBuildVerbosity)this.cbVerbosity.SelectedIndex;
                    this.step.ToolsVersion       = (MSBuildToolsVersion)this.cbToolsVersion.SelectedValue;
                    this.step.CommandLineOptions = this.edtOtherOptions.Text;
                    this.step.Use32BitProcess    = this.chk32Bit.Checked;
                }
            }

            return(result);
        }
コード例 #10
0
ファイル: Stats.xaml.cs プロジェクト: menees/Gizmos
        private void UpdateDisplay()
        {
            try
            {
                using (new WaitCursor())
                {
                    if (this.provider == null)
                    {
                        this.provider = Provider.Create();
                    }

                    this.weather = this.provider.GetWeatherAsync(this.settings).Result;

                    // Changing the root DataContext will cause all of the bindings to update.
                    this.DataContext = this.weather;
                    this.UpdateTimer(this.weather.IsValid);
                }
            }
            catch (Exception ex)
            {
                var properties = this.GetLogProperties();
                properties.Add("Location", this.settings.UserLocation);
                Log.Error(typeof(Stats), "An error occurred updating the display.", ex, properties);
                this.UpdateTimer(false);

                // If an error occurs on every timer interval, make sure we only show one MessageBox at a time.
                if (!this.showingError)
                {
                    this.showingError = true;
                    try
                    {
                        StringBuilder sb = new StringBuilder();
                        Exceptions.ForEach(ex, (exception, depth, parent) => sb.Append('\t', depth).Append(exception.Message).AppendLine());
                        if (ApplicationInfo.IsDebugBuild)
                        {
                            // Show the root exception's type and call stack in debug builds.
                            sb.AppendLine().AppendLine(ex.ToString());
                        }

                        string message = string.Format(
                            "{0}: {1}{2}{2}{3}",
                            this.Info.GizmoName,
                            this.settings.UserLocation,
                            Environment.NewLine,
                            sb.ToString().Trim());
                        WindowsUtility.ShowError(this, message);
                    }
                    finally
                    {
                        this.showingError = false;
                    }
                }
            }
        }
コード例 #11
0
        private bool IsValid(IReadOnlyList <string> errors)
        {
            bool result = true;

            if (errors.Count > 0)
            {
                WindowsUtility.ShowError(this, string.Join(Environment.NewLine, errors));
                result = false;
            }

            return(result);
        }
コード例 #12
0
        protected override bool OnOk()
        {
            bool result = base.OnOk();

            if (result && this.Stats != null)
            {
                string logId = this.logId.Text.Trim();
                if (!string.IsNullOrEmpty(logId))
                {
                    string errorMessage = null;
                    if (!Guid.TryParseExact(logId, "N", out Guid logGuid))
                    {
                        errorMessage = "The Log ID must be exactly 32 characters long consisting of 0-9 and a-f.";
                        this.logId.Focus();
                    }
                    else if (!Stats.ValidateLogId(logId, out errorMessage))
                    {
                        errorMessage = "The specified Log ID could not be validated at RunningAhead.com." + Environment.NewLine + errorMessage;
                        this.logId.Focus();
                    }

                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        WindowsUtility.ShowError(this, errorMessage);
                        result = false;
                    }
                }

                if (result)
                {
                    using (new WaitCursor())
                    {
                        this.Stats.LogId            = logId;
                        this.Stats.RefreshInterval  = TimeSpan.FromHours(GetValue(this.hours, this.Stats.RefreshInterval.TotalHours));
                        this.Stats.UseDefaultHeader = this.useDefaultHeader.IsChecked ?? true;
                        this.Stats.Header           = this.customHeader.Text;
                        this.Stats.StatsFormat      = GetValue(this.statsFormat, this.Stats.StatsFormat);
                        this.Stats.FooterFormat     = GetValue(this.footerFormat, this.Stats.FooterFormat);

                        this.Stats.UpdateDisplay();
                    }
                }
            }

            return(result);
        }
コード例 #13
0
 private void RunClick(object sender, RoutedEventArgs e)
 {
     if (this.TryGetShortcutInfo(out ShortcutInfo info))
     {
         try
         {
             using (new WaitCursor())
             {
                 string commandLine = info.BuildCommandLine(false);
                 Process.Start(ApplicationInfo.ExecutableFile, commandLine);
             }
         }
         catch (Win32Exception ex)
         {
             WindowsUtility.ShowError(this, ex.Message);
         }
     }
 }
コード例 #14
0
        public override bool OnOk()
        {
            bool result = false;

            string name = this.edtName.Text.Trim();

            if (name.Length == 0)
            {
                WindowsUtility.ShowError(this, "You must enter a name for the step.");
            }
            else if (this.step != null)
            {
                this.step.Name        = name;
                this.step.Description = this.txtDescription.Text;
                result = true;
            }

            return(result);
        }
コード例 #15
0
        public override bool OnOk()
        {
            bool result = false;

            if (string.IsNullOrEmpty(this.edtCommand.Text.Trim()))
            {
                WindowsUtility.ShowError(this, "You must enter a script or command.");
            }
            else if (this.step != null)
            {
                this.step.Command                  = this.edtCommand.Text;
                this.step.WorkingDirectory         = this.edtWorkingDirectory.Text;
                this.step.Shell                    = (PowerShell)this.shell.SelectedIndex;
                this.step.TreatErrorStreamAsOutput = this.treatErrorAsOutput.Checked;
                result = true;
            }

            return(result);
        }
コード例 #16
0
ファイル: Stats.xaml.cs プロジェクト: menees/Gizmos
        public Stats()
        {
            this.InitializeComponent();

            this.lines = new Tuple <TextBlock, TextBlock> [MaxItems];
            for (int i = 1; i <= MaxItems; i++)
            {
                TextBlock name  = (TextBlock)this.FindName("procName" + i);
                TextBlock usage = (TextBlock)this.FindName("procUsage" + i);
                this.lines[i - 1] = new Tuple <TextBlock, TextBlock>(name, usage);
            }

            const int ItemLimit = 3;

            this.TopCount       = ItemLimit;
            this.ShowTenths     = true;
            this.timer          = new DispatcherTimer();
            this.timer.Interval = TimeSpan.FromSeconds(1);
            this.timer.Tick    += (s, e) => this.RefreshData();

            // Read a counter value up front to get it initialized and to see if we have access.
            this.overallCpuCounter = ProcessInfoCache.TryGetCounterInstance("Processor", "% Processor Time", "_Total", out Exception ex);
            if (this.overallCpuCounter != null)
            {
                this.overallCpuCounter.NextValue();
                this.cache = new ProcessInfoCache();
            }
            else
            {
                this.cpuBorder.Background = Brushes.Red;
                string message = ex != null ? ex.Message : "Unable to read the CPU performance counter data.";
                if (ex is SecurityException || ex is UnauthorizedAccessException)
                {
                    message += Environment.NewLine + "The user must be a member of the Administrators group or the Performance Monitor Users group.";
                }

                // Put this in the message pump as a low priority message to be shown after everything else is processed.
                this.Dispatcher.InvokeAsync(() => WindowsUtility.ShowError(this, message), DispatcherPriority.ApplicationIdle);
            }

            // Call this now to initialize all the counters and the display lines.
            this.RefreshData();
        }
コード例 #17
0
        private bool TryGetShortcutInfo(out ShortcutInfo info)
        {
            string  errorMessage = null;
            Control focusControl = null;

            GizmoInfo gizmo        = this.gizmos.SelectedItem as GizmoInfo;
            string    instanceName = null;

            if (gizmo == null)
            {
                errorMessage = "You must select a gizmo.";
                focusControl = this.gizmos;
            }
            else
            {
                instanceName = this.instance.Text.Trim();
                if (!gizmo.IsSingleInstance && string.IsNullOrEmpty(instanceName))
                {
                    errorMessage = "You must specify an instance name.";
                    focusControl = this.instance;
                }
            }

            bool result = string.IsNullOrEmpty(errorMessage);

            if (result)
            {
                info = new ShortcutInfo(gizmo, gizmo.IsSingleInstance ? null : instanceName, this.showInTaskbar.IsChecked ?? false);
            }
            else
            {
                info = null;
                WindowsUtility.ShowError(this, errorMessage);
            }

            if (focusControl != null)
            {
                focusControl.Focus();
            }

            return(result);
        }
コード例 #18
0
        private void OKClicked(object sender, RoutedEventArgs e)
        {
            List <string> errors = new List <string>();

            ISet <ValidationError> validationErrors = WindowsUtility.GetValidationErrors(this.grid);

            foreach (ValidationError error in validationErrors)
            {
                errors.Add(error.ErrorContent?.ToString() ?? "Validation error");
            }

            if (errors.Count == 0)
            {
                this.DialogResult = true;
            }
            else
            {
                WindowsUtility.ShowError(this, string.Join("\n", errors));
            }
        }
コード例 #19
0
        private static void Main()
        {
            using (Mutex mutex = new Mutex(true, "Menees.WorkBreak", out bool createdNew))
            {
                if (createdNew)
                {
                    WindowsUtility.InitializeApplication("Work Break", null);
                    using Program program = new Program();
                    Application.Run(program);

                    // Force the mutex to live the whole life of the program
                    // (just in case the JITer decides we're not really using it).
                    GC.KeepAlive(mutex);
                }
                else
                {
                    WindowsUtility.ShowError(null, "Another instance of Work Break is running.");
                }
            }
        }
コード例 #20
0
        private void OKClicked(object sender, RoutedEventArgs e)
        {
            List <string> errors = new List <string>();

            string folder = this.LogFolder;

            if (!string.IsNullOrEmpty(folder) && !Directory.Exists(folder))
            {
                errors.Add("The specified log folder doesn't exist.");
            }

            if (errors.Count == 0)
            {
                this.DialogResult = true;
            }
            else
            {
                WindowsUtility.ShowError(this, string.Join(Environment.NewLine, errors));
            }
        }
コード例 #21
0
ファイル: OutputStepCtrl.cs プロジェクト: menees/MegaBuild
        public override bool OnOk()
        {
            bool result = false;

            if (string.IsNullOrEmpty(this.txtMessage.Text.Trim()))
            {
                WindowsUtility.ShowError(this, "You must enter a message to be output.");
            }
            else if (this.step != null)
            {
                this.step.Message          = this.txtMessage.Text;
                this.step.IncludeTimestamp = this.chkIncludeTimestamp.Checked;
                this.step.IndentOutput     = (int)this.numIndent.Value;
                this.step.TextColor        = this.pnlColor.BackColor;
                this.step.IsHighlight      = this.chkIsHighlight.Checked;
                result = true;
            }

            return(result);
        }
コード例 #22
0
        private void OK_Click(object sender, EventArgs e)
        {
            if (this.chkLogOutput.Checked)
            {
                string logFile = this.edtLogFile.Text.Trim();
                if (logFile.Length == 0)
                {
                    WindowsUtility.ShowError(this, "You must enter a log file name.");
                    this.DialogResult = DialogResult.None;
                }

                string logPath = Manager.ExpandVariables(Path.GetDirectoryName(logFile));
                if (logPath.Length > 0 && !Directory.Exists(logPath))
                {
                    WindowsUtility.ShowError(this, "The log file path does not exist.");
                    this.DialogResult = DialogResult.None;
                }
            }

            // Check the variables for uniqueness and non-emptyness. Since the ListView
            // is sorted, we'll just scan and check the current against the previous.
            string previousName = string.Empty;

            foreach (ListViewItem item in this.lstVariables.Items)
            {
                string name = item.Text;
                if (name.Length == 0 || name == "%%")
                {
                    WindowsUtility.ShowError(this, "A variable cannot have an empty name (i.e. %%).");
                    this.DialogResult = DialogResult.None;
                }

                if (name == previousName)
                {
                    WindowsUtility.ShowError(this, string.Format("The variable {0} is defined multiple times, but it can only be defined once.", name));
                    this.DialogResult = DialogResult.None;
                }

                previousName = name;
            }
        }
コード例 #23
0
        public override bool OnOk()
        {
            bool result = false;

            string project = this.edtProject.Text.Trim();

            if (string.IsNullOrEmpty(project))
            {
                WindowsUtility.ShowError(this, "You must enter a MegaBuild project for the step.");
            }
            else if (this.step != null)
            {
                this.step.ProjectFile = this.edtProject.Text.Trim();
                this.step.InProc      = !this.chkOutOfProc.Checked;
                this.step.Exit        = this.chkExit.Checked;
                this.step.Minimize    = this.chkMinimize.Checked;
                result = true;
            }

            return(result);
        }
コード例 #24
0
        public override bool OnOk()
        {
            bool result = false;

            if (string.IsNullOrEmpty(this.edtScript.Text.Trim()))
            {
                WindowsUtility.ShowError(this, "You must specify a script.");
            }
            else if (this.step != null)
            {
                this.step.ScriptFile               = this.edtScript.Text;
                this.step.ScriptArguments          = ScrubLines(this.edtScriptArgs.Text);
                this.step.WorkingDirectory         = this.edtWorkingDirectory.Text;
                this.step.CsiVersion               = (MSBuildToolsVersion)this.cbToolsVersion.SelectedValue;
                this.step.TreatErrorStreamAsOutput = this.treatErrorAsOutput.Checked;
                this.step.CsiOptions               = ScrubLines(this.edtCsiOptions.Text);
                result = true;
            }

            return(result);
        }
コード例 #25
0
        protected override bool OnOk()
        {
            bool result = base.OnOk();

            if (result && this.Stats != null)
            {
                string    location            = this.location.Text;
                const int FirstSixDigitNumber = 100000;
                if (!this.provider.SupportsCityState && !int.TryParse(location, out int zip) && (zip <= 0 || zip >= FirstSixDigitNumber))
                {
                    WindowsUtility.ShowError(this, location + " is not a valid US Zip code.");
                    result = false;
                }
                else
                {
                    var settings = new Settings(this.location.Text, this.fahrenheit.IsChecked.GetValueOrDefault());
                    this.Stats.Settings = settings;
                }
            }

            return(result);
        }
コード例 #26
0
ファイル: MainForm.cs プロジェクト: radtek/Diff.Net
 private void ReportError(string message)
 {
     Cursor.Current = Cursors.Default;
     WindowsUtility.ShowError(this, message);
 }