示例#1
0
        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            string fileName = saveFileDialog1.FileName;

            File.WriteAllText(fileName, sb.ToString());
            StatusTextBox.AppendText(Environment.NewLine + $"Saved \"{openFileDialog1.SafeFileName}\" as \"{fileName}\"");
        }
示例#2
0
 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
 {
     imageLoaded  = true;
     loadedImage  = (Bitmap)Image.FromFile(openFileDialog1.FileName);
     resizedImage = (Bitmap)Image.FromFile(openFileDialog1.FileName);
     StatusTextBox.AppendText(Environment.NewLine + $"Loaded \"{openFileDialog1.SafeFileName}\"");
 }
示例#3
0
        private void exportListsBtn_Click(object sender, EventArgs e)
        {
            if (folderDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string listDir = String.Format(@"{0}\l", folderDlg.SelectedPath);

            if (!Directory.Exists(listDir))
            {
                if (File.Exists(listDir))
                {
                    StatusTextBox.AppendText("ERROR: File '" + listDir + "' exists." + "\r\n");
                    return;
                }
                try
                {
                    Directory.CreateDirectory(listDir);
                }
                catch (Exception ex)
                {
                    StatusTextBox.AppendText("Error creating '" + listDir + "': " + ex.Message + "\r\n");
                    return;
                }
            }
            foreach (ProblemList pl in moonServer.ProblemLists)
            {
                StatusTextBox.AppendText("Exporting list '" + pl.Name + "'\r\n");
                writeProblems(pl.ProblemListEntries.Select(ple => ple.Problem), listDir, pl.Name, false);
            }
            StatusTextBox.AppendText("Done.\r\n");
        }
示例#4
0
        /// <summary>
        /// Occurs when the dialer has completed a dialing operation.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">An <see cref="DotRas.DialCompletedEventArgs"/> containing event data.</param>
        private void Dialer_DialCompleted(object sender, DialCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                StatusTextBox.AppendText("Cancelled!");
            }
            else if (e.TimedOut)
            {
                StatusTextBox.AppendText("Connection attempt timed out!");
            }
            else if (e.Error != null)
            {
                StatusTextBox.AppendText(e.Error.ToString());
            }
            else if (e.Connected)
            {
                StatusTextBox.AppendText("Connection successful!");
            }

            if (!e.Connected)
            {
                // The connection was not connected, disable the disconnect button.
                DisconnectButton.Enabled = false;
            }
        }
示例#5
0
文件: Main.cs 项目: sotaria/gsf
        // Registers or unregisters the OIDs used by GPA client applications based on user selection.
        private void ClientOIDCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (!m_checkedEventsEnabled)
            {
                return;
            }

            if (ClientOIDCheckBox.Checked)
            {
                StatusTextBox.AppendText("Registering client OIDs... ");

                foreach (string clientOID in ClientOIDs)
                {
                    RegisterOID(clientOID);
                }
            }
            else
            {
                StatusTextBox.AppendText("Unregistring client OIDs... ");

                foreach (string clientOID in ClientOIDs)
                {
                    UnregisterOID(clientOID);
                }
            }

            AppendStatusMessage("Done.");
        }
示例#6
0
        /// <summary>
        /// Occurs when the user clicks the Dial button.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">An <see cref="System.EventArgs"/> containing event data.</param>
        private void DialButton_Click(object sender, EventArgs e)
        {
            StatusTextBox.Clear();

            // This button will be used to dial the connection.
            Dialer.EntryName     = EntryName;
            Dialer.PhoneBookPath = PHONE_BOOK_PATH;

            try
            {
                // Set the credentials the dialer should use.
                Dialer.Credentials = new NetworkCredential("Test", "User");

                // NOTE: The entry MUST be in the phone book before the connection can be dialed.
                // Begin dialing the connection; this will raise events from the dialer instance.
                handle = Dialer.DialAsync();

                // Enable the disconnect button for use later.
                DisconnectButton.Enabled = true;
            }
            catch (Exception ex)
            {
                StatusTextBox.AppendText(ex.ToString());
            }
        }
示例#7
0
文件: Main.cs 项目: sotaria/gsf
        // Sets the registry key to enable or disable the automatic root certificate list updates.
        private void RootCertificateListCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (!m_checkedEventsEnabled)
            {
                return;
            }

            StatusTextBox.AppendText(string.Format("{0} automatic root certificate list update through Windows Update... ", RootCertificateListCheckBox.Checked ? "Disabling" : "Enabling"));

            using (RegistryKey authRootKey = Registry.LocalMachine.CreateSubKey(@"Software\Policies\Microsoft\SystemCertificates\AuthRoot"))
            {
                if ((object)authRootKey != null)
                {
                    if (RootCertificateListCheckBox.Checked)
                    {
                        authRootKey.SetValue("DisableRootAutoUpdate", 1);
                    }
                    else
                    {
                        authRootKey.DeleteValue("DisableRootAutoUpdate");
                    }

                    AppendStatusMessage("Done.");
                }
                else
                {
                    AppendStatusMessage("Failed. Unable to update the registry key.");
                    m_checkedEventsEnabled = false;
                    RootCertificateListCheckBox.Checked = !RootCertificateListCheckBox.Checked;
                    m_checkedEventsEnabled = true;
                }
            }
        }
示例#8
0
        private void LoadBtn_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            LoaderUtils.DataType dataType = GetDataType();
            StatusTextBox.AppendText("Loading " + LoaderUtils.DataTypeName(dataType).ToLower() + "(s) from file '" + openFileDialog.FileName + "'\n");
            String json = File.ReadAllText(openFileDialog.FileName);

            ProgressBar.Visible = true;
            ProgressLbl.Visible = true;
            try
            {
                int recordsLoaded = LoadJSON(json, dataType);
                StatusTextBox.AppendText(String.Format("Processed {0} {1}(s) from {2}\n",
                                                       recordsLoaded, LoaderUtils.DataTypeName(dataType).ToLower(), openFileDialog.FileName));
            }
            catch (DuplicateException de)
            {
                StatusTextBox.AppendText("Error: " + de.Message + "\n");
            }
            catch (JsonReaderException je)
            {
                StatusTextBox.AppendText("Error: " + je.Message + "\n");
            }
            ProgressBar.Visible = false;
            ProgressLbl.Visible = false;
        }
示例#9
0
        private byte[] ReadBySize(int size = 4)
        {
            var readEvent     = new AutoResetEvent(false);
            var buffer        = new byte[size]; //Receive buffer
            var totalRecieved = 0;

            do
            {
                var recieveArgs = new SocketAsyncEventArgs()
                {
                    UserToken = readEvent
                };
                recieveArgs.SetBuffer(buffer, totalRecieved, size - totalRecieved);//Receive bytes from x to total - x, x is the number of bytes already recieved
                recieveArgs.Completed += recieveArgs_Completed;
                sockClient.ReceiveAsync(recieveArgs);
                readEvent.WaitOne();                   //Wait for recieve

                if (recieveArgs.BytesTransferred == 0) //If now bytes are recieved then there is an error
                {
                    if (recieveArgs.SocketError != SocketError.Success)
                    {
                        StatusTextBox.AppendText($"SocketError:{recieveArgs.SocketError}");
                    }
                    //throw new ReadException(ReadExceptionCode.UnexpectedDisconnect, "Unexpected Disconnect");
                    //throw new ReadException(ReadExceptionCode.DisconnectGracefully);
                }
                totalRecieved += recieveArgs.BytesTransferred;
            } while (totalRecieved != size);//Check if all bytes has been received
            return(buffer);
        }
示例#10
0
 private void AppendStatusText(string text)
 {
     if (StatusTextBox.Text.Length != 0)
     {
         this.Invoke(() => StatusTextBox.AppendText(Environment.NewLine));
     }
     this.Invoke(() => StatusTextBox.AppendText(DateTime.Now.ToString("HH:mm:ss.fff") + " " + text));
 }
示例#11
0
 public void AppendText(string str, bool newline)
 {
     if (newline)
     {
         str += Environment.NewLine;
     }
     StatusTextBox.AppendText(str);
 }
示例#12
0
 private void AppendStatusText(string text)
 {
     if (StatusTextBox.Text.Length != 0)
     {
         this.Invoke(() => StatusTextBox.AppendText(Environment.NewLine));
     }
     this.Invoke(() => StatusTextBox.AppendText(text));
 }
示例#13
0
        private void SocketReceiveEventCompleted(object sender, SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success)
            {
                var ex = new SocketException((int)e.SocketError);
                StatusTextBox.AppendText($"RecieveComplete socket error:{ex.Message}, ErrorCode:{ex.SocketErrorCode}");

                return;
            }

            try
            {
                //_timer8.Change(Timeout.Infinite, Timeout.Infinite);
                var receivedCount = e.BytesTransferred;
                if (receivedCount == 0)
                {
                    StatusTextBox.AppendText("Received 0 byte.\n");
                    //CommunicationStateChanging(ConnectionState.Retry);
                    return;
                }
                dealwithMessage(e.Buffer, receivedCount);
                //var _msgHeader = MessageHeader.Decode(e.Buffer, 0);
                //                if (_secsDecoder.Decode(receivedCount))
                //                {
                //#if !DISABLE_T8
                //                    //_logger.Debug($"Start T8 Timer: {T8 / 1000} sec.");
                //                    //_timer8.Change(T8, Timeout.Infinite);
                //#endif
                //                }

                //                if (_secsDecoder.Buffer.Length != DecoderBufferSize)
                //                {
                //                    // buffer size changed
                //                    e.SetBuffer(_secsDecoder.Buffer, _secsDecoder.BufferOffset, _secsDecoder.BufferCount);
                //                    DecoderBufferSize = _secsDecoder.Buffer.Length;
                //                }
                //                else
                //                {
                //                    e.SetBuffer(_secsDecoder.BufferOffset, _secsDecoder.BufferCount);
                //                }

                if (sockClient is null || IsDisposed)
                {
                    return;
                }

                if (!sockClient.ReceiveAsync(e))
                {
                    SocketReceiveEventCompleted(sender, e);
                }
            }
            catch (Exception ex)
            {
                StatusTextBox.AppendText($"Unexpected exception: {ex.Message}");
                //CommunicationStateChanging(ConnectionState.Retry);
            }
        }
示例#14
0
  internal void ShowStatus(string Status)
    {
    if (IsClosing)
      return;

    // if( StatusTextBox.Text.Length > (80 * 5000))
      // StatusTextBox.Text = "";

    StatusTextBox.AppendText( Status + "\r\n" );
    }
示例#15
0
 private void Data2ReceivedHandler(object sender, SecsDataReceivedEventArgs arg)
 {
     Stream2TextBox.Text   = arg.SecsMessage.S.ToString();
     Function2TextBox.Text = arg.SecsMessage.F.ToString();
     StatusTextBox.AppendText("get msg header for device 0.\n");
     Message2TextBox.Text = arg.SecsMessage.ToString();
     Message2TextBox.AppendText("\n");
     Message2TextBox.AppendText(arg.SecsMessage.SecsItem.ToString());
     StatusTextBox.AppendText("get msg data for device 0.\n");
 }
示例#16
0
文件: Main.cs 项目: sotaria/gsf
        // Registers the service OID for the given product.
        private void RegisterServiceOID(Product product)
        {
            List <Product>   productsUsingThisOID;
            X509Certificate2 certificate;
            string           certificatePath;
            string           keyAlgorithm;

            // If the service is already registered, don't need to do anything
            if ((object)product.ServiceOID == null)
            {
                // Get the path to the certificate used to obtain the OID for this fix
                certificatePath = Path.Combine(product.InstallPath, product.Name + ".cer");

                if (File.Exists(certificatePath))
                {
                    StatusTextBox.AppendText(string.Format("Registering service OID for {0}... ", product.Name));

                    // Get the key algorithm of the certificate,
                    // which is the OID used by the service
                    certificate  = new X509Certificate2(certificatePath);
                    keyAlgorithm = certificate.GetKeyAlgorithm();

                    // Determine which other products are sharing this service OID
                    productsUsingThisOID = m_products
                                           .Where(p => p.ServiceOID == keyAlgorithm)
                                           .ToList();

                    // Set service OID to the key algorithm of the certificate
                    product.ServiceOID = keyAlgorithm;

                    // Store the OID of that certificate in case we need to unregister it later
                    using (RegistryKey productKey = Registry.LocalMachine.CreateSubKey(string.Format(@"Software\Grid Protection Alliance\{0}", product.Name)))
                    {
                        if ((object)productKey != null)
                        {
                            productKey.SetValue("ServiceOID", keyAlgorithm);
                        }
                    }

                    if (productsUsingThisOID.Count == 0)
                    {
                        RegisterOID(keyAlgorithm);
                        AppendStatusMessage("Done.");
                    }
                    else if (productsUsingThisOID.Count == 1)
                    {
                        AppendStatusMessage(string.Format("Service OID already registered for {0}.", productsUsingThisOID[0].Name));
                    }
                    else
                    {
                        AppendStatusMessage(string.Format("Service OID already registered for {0} other products.", productsUsingThisOID.Count));
                    }
                }
            }
        }
示例#17
0
 private void AppendStatusText(string text)
 {
     if (StatusTextBox.Text.Length != 0)
     {
         this.Invoke(() => StatusTextBox.AppendText(Environment.NewLine));
     }
     if (!string.IsNullOrWhiteSpace(text))
     {
         text = DateTime.Now.ToString("HH:mm:ss.fff") + " " + text;
     }
     this.Invoke(() => StatusTextBox.AppendText(text));
 }
示例#18
0
 private void ReportError(string message)
 {
     StatusTextBox.AppendText("Row: " + Count.ToString());
     StatusTextBox.AppendText(Environment.NewLine);
     StatusTextBox.AppendText("From: " + UriFrom.ToString());
     StatusTextBox.AppendText(Environment.NewLine);
     StatusTextBox.AppendText("To: " + UriTo.ToString());
     StatusTextBox.AppendText(Environment.NewLine);
     StatusTextBox.AppendText("New: " + message);
     StatusTextBox.AppendText(Environment.NewLine);
     StatusTextBox.AppendText(Environment.NewLine);
 }
示例#19
0
        private void SetStatus(string Message)
        {
            //Check for cross threading
            if (StatusTextBox.Dispatcher.CheckAccess() == false)
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action <string>)SetStatus, Message);
                return;
            }

            StatusTextBox.AppendText(Environment.NewLine + Message);
            StatusTextBox.ScrollToEnd();
        }
示例#20
0
        private void AppendStatusText(string text)
        {
            if (StatusTextBox.Text.Length != 0)
            {
                this.Invoke(() => StatusTextBox.AppendText(Environment.NewLine));
            }
            if (!string.IsNullOrWhiteSpace(text))
            {
                text = DateTime.Now.ToString("HH:mm:ss.fff") + " " + text;
            }
// ReSharper disable once AssignNullToNotNullAttribute
            this.Invoke(() => StatusTextBox.AppendText(text));
        }
示例#21
0
        internal void AppendStatusText(string text)
        {
            Form form = StatusTextBox.Parent as Form;

            if (StatusTextBox.Text.Length != 0)
            {
                form.Invoke(() => StatusTextBox.AppendText(Environment.NewLine));
            }
            if (!string.IsNullOrWhiteSpace(text))
            {
                text = DateTime.Now.ToString("HH:mm:ss.fff") + " " + text;
            }
            form.Invoke(() => StatusTextBox.AppendText(text));
        }
 //private void PostFrameCallback()
 #endregion
 #region Tool Methods
 public void SetStatusLine(string message, int line, Color?fg)
 {
     if (WindowState != FormWindowState.Minimized)
     {
         while (StatusTextBox.Lines.Length <= line)
         {
             StatusTextBox.AppendText(Environment.NewLine);
         }
         StatusTextBox.SelectionStart  = StatusTextBox.GetFirstCharIndexFromLine(line);
         StatusTextBox.SelectionLength = StatusTextBox.Lines[line].Length;
         StatusTextBox.SelectionColor  = fg ?? StatusTextBox.ForeColor;
         StatusTextBox.SelectedText    = message;
     }
 }
示例#23
0
        private void ConvertButton_Click(object sender, EventArgs e)
        {
            if (!imageLoaded)
            {
                StatusTextBox.AppendText(Environment.NewLine + $"Load an image first!" + Environment.NewLine);
                return;
            }

            resizeSlider.Value = 0;
            sb = asciiGenerator.ConvertImage(loadedImage, isDarkTheme);
            OutputTextBox.Text = sb.ToString();
            StatusTextBox.AppendText(Environment.NewLine + $"Successfully converted \"{openFileDialog1.SafeFileName}\"");
            TextLengthLabel.Text = $"Text length: { OutputTextBox.Text.Length} characters";
        }
示例#24
0
        private void btnCheckStatus_Click(object sender, EventArgs e)
        {
            string address = txtLampAddress.Text;
            ActiveHomeDeviceStatus status_code = ActiveHomeController.Instance.Query_PLC(address);

            if (status_code == ActiveHomeDeviceStatus.OFF)
            {
                StatusTextBox.AppendText(address + " is OFF\r\n");
            }
            else if (status_code == ActiveHomeDeviceStatus.ON)
            {
                StatusTextBox.AppendText(address + " is ON\r\n");
            }
        }
示例#25
0
        private void e_Completed(object sender, SocketAsyncEventArgs e)
        {
            if (e.ConnectSocket != null)
            {
                StreamReader sr = new StreamReader(new NetworkStream(e.ConnectSocket));
                StatusTextBox.AppendText("connected\n");

                Console.WriteLine("Connection Established : " + e.RemoteEndPoint + " PC NAME : " + sr.ReadLine());
            }
            else
            {
                Console.WriteLine("Connection Failed : " + e.RemoteEndPoint);
            }
        }
示例#26
0
        private void AppendStatusText(string text)
        {
            var form = StatusTextBox.Parent as Form;

            if (StatusTextBox.Text.Length != 0)
            {
                form.Invoke(() => StatusTextBox.AppendText(Environment.NewLine));
            }
            if (IsNullOrWhiteSpace(text))
            {
                return;
            }
            text = $"{DateTime.Now:HH:mm:ss.fff} {text}";
            form.Invoke(() => StatusTextBox.AppendText(text));
        }
示例#27
0
        private void AppendStatusText(string text, params object[] arguments)
        {
            var form = StatusTextBox.Parent as Form;

            if (StatusTextBox.Text.Length != 0)
            {
                form.Invoke(() => StatusTextBox.AppendText(Environment.NewLine));
            }
            if (IsNullOrWhiteSpace(text))
            {
                return;
            }
            text = DateTime.Now.ToString("HH:mm:ss.fff") + " " +
                   Format(text, arguments);
            form.Invoke(() => StatusTextBox.AppendText(text));
        }
示例#28
0
 private void AppendStatusText(string text)
 {
     if (text == null)
     {
         return;
     }
     if (StatusTextBox.Text.Length != 0)
     {
         this.Invoke(() => StatusTextBox.AppendText(Environment.NewLine));
     }
     if (!IsNullOrWhiteSpace(text))
     {
         text = $"{DateTime.Now:HH:mm:ss.fff} {text}";
     }
     this.Invoke(() => StatusTextBox.AppendText(text));
 }
示例#29
0
 private void Check1Button_Click(object sender, EventArgs e)
 {
     StatusTextBox.AppendText("Checking problems for missing Positions...\n");
     foreach (Problem p in moonServer.Problems.Where(p => p.ProblemPositions.Count == 0))
     {
         StatusTextBox.AppendText(String.Format("Problem #{0} ({1}) has no position\n", p.Id, p.Name));
     }
     StatusTextBox.AppendText("Checking problems for missing StartPositions...\n");
     foreach (Problem p in moonServer.Problems.Where(p => p.StartProblemPositions.Count == 0))
     {
         StatusTextBox.AppendText(String.Format("Problem #{0} ({1}) has no start positions\n", p.Id, p.Name));
     }
     StatusTextBox.AppendText("Checking problems for missing EndPositions...\n");
     foreach (Problem p in moonServer.Problems.Where(p => p.EndProblemPositions.Count == 0))
     {
         StatusTextBox.AppendText(String.Format("Problem #{0} ({1}) has no end positions\n", p.Id, p.Name));
     }
 }
示例#30
0
        private bool LoadGrade(GradeProxy p)
        {
            Grade  g = Deproxy.GetGrade(p);
            string objTypeAndName = p.GetDataType().ToLower() + ": " + p.FriendlyString();

            if (moonServer.Grades.Any(o => o.Id == g.Id || o.EuroName.Equals(g.EuroName) || o.AmericanName.Equals(g.AmericanName)))
            {
                if (ErrorOnDupCheckBox.Checked)
                {
                    throw new DuplicateException(objTypeAndName);
                }
                StatusTextBox.AppendText("Skipping duplicate " + objTypeAndName + "\n");
                return(false);
            }
            StatusTextBox.AppendText("Adding " + objTypeAndName + "\n");
            moonServer.Grades.Add(g);
            moonServer.SaveChanges();
            return(true);
        }