private void OpenServer_Click(object sender, EventArgs e)
        {
            accept        = true;
            waitPlayers   = true;
            waitAsk       = true;
            waitAnswer    = true;
            isStarted     = false;
            isTreminating = false;
            try
            {
                if (!isListening)
                {
                    serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    serverSocket.ReceiveTimeout = 10000;        //
                    isListening = true;
                    clientList  = new List <Client>();
                }
                IPEndPoint ipendP = new IPEndPoint(IPAddress.Any, int.Parse(textBox_PortNum.Text));
                serverSocket.Bind(ipendP);
                serverSocket.Listen(20);     //can be more ???????????????????



                Console.AppendText("\nListening...");
                Thread AcceptThread = new Thread(new ThreadStart(Accept));
                AcceptThread.IsBackground = true;
                AcceptThread.Start();
            }
            catch
            {
                AppendTextBox("\nProblem occured... Please try with another Port Number");
            }
        }
Esempio n. 2
0
 void ConsolePrint(string text)
 {
     Console.AppendText("[" + DateTime.Now.ToShortTimeString() + "] - " + text, "Lime");
     Console.AppendText(Environment.NewLine);
     Console.CaretPosition = Console.Document.ContentEnd;
     Console.ScrollToEnd();
 }
Esempio n. 3
0
    public static void Print(LogType type, string message)
    {
        if (instance != null)
        {
            switch (type)
            {
            case LogType.Assert:
                message = "<color=orange>" + message + "</color>";
                break;

            case LogType.Error:
                message = "<color=red>" + message + "</color>";
                break;

            case LogType.Exception:
                message = "<color=red>" + message + "</color>";
                break;

            case LogType.Warning:
                message = "<color=yellow>" + message + "</color>";
                break;
            }

            instance.AppendText(message + "\n");
        }
    }
Esempio n. 4
0
        public void Log_Console(string log, logType logtype = logType.CommonLog, bool addNewLine = true)
        {
            if (addNewLine)
            {
                log += Environment.NewLine;
            }

            Color color = new Color();

            switch (logtype)
            {
            case logType.CommonLog:
                color = Color.Green;
                break;

            case logType.Warning:
                color = Color.Orange;
                break;

            case logType.Error:
                color = Color.Red;
                break;
            }

            Console.SelectionStart  = Console.TextLength;
            Console.SelectionLength = 0;
            Console.SelectionColor  = color;

//            string text = $@"[{DateTime.Now.ToLongTimeString()}] {log}";
            Console.Focus(); //warning:这句话没有的话会使得Console不能跟踪到最新的log
            Console.AppendText(log);

            Console.SelectionColor = Console.ForeColor;
        }
Esempio n. 5
0
        public void checkPatches(string computerName, int evalState)
        {
            ManagementScope scp = new ManagementScope(string.Format(@"\\{0}\root\ccm\clientsdk", computerName));
            ManagementClass cls = new ManagementClass(@"CCM_SoftwareUpdateManager");

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(string.Format("SELECT * FROM CCM_SOFTWAREUPDATE WHERE EVALUATIONSTATE = {0}", evalState));

            cls.Scope = searcher.Scope = scp;

            ManagementObjectCollection collection = searcher.Get();
            List <ManagementObject>    lUpdates   = new List <ManagementObject>();

            int counter = 0;

            foreach (ManagementObject o in collection)
            {
                object[] args = { o };

                object[] methodArgs = { args, null };

                Console.AppendText(o.Properties["Name"].Value + Environment.NewLine);
                counter++;
            }
            Console.AppendText("Number of patches available: " + counter + Environment.NewLine);
        }
Esempio n. 6
0
        public bool Replace(string[] data)
        {
            try
            {
                System.IO.File.Replace(data[2], obj.appName, "backupApp.exe");
                System.IO.File.Delete("backupApp.exe");
            }
            catch (Exception ex)
            {
                this.Show();
                ex.ToString();
                string[] exception = ex.ToString().Split('\n');
                Console.AppendText(nL);
                Console.AppendText("Wystapił błąd: " + exception);

                DeleteFiles(data, int.Parse(data[1]));
                Console.AppendText(nL + nL);
                Console.AppendText("Zakończono proces aktualizacji: (400) nie udało się zaktualizować");
                this.Show();
                this.TopMost = false;
                MessageBox.Show("Nie udało się zaktualizować", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
            return(true);
        }
Esempio n. 7
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            string selectedComPort;

            if (discoverradio.Checked || connectradio.Checked)
            {
                if (discoverradio.Checked)
                {
                    if (ComPortComboBox.Items.Count == 0)
                    {
                        MessageBox.Show("No connection type selected.");
                        return;
                    }
                    selectedComPort = ComPortComboBox.SelectedItem.ToString();
                }
                else
                {
                    selectedComPort = comportselection.Text;
                }

                Console.AppendText("Connecting to com port " + selectedComPort + "...\n");
                //Connect connects to the tactor controller via serial with the given name
                //we should be hooking up a response callback but for simplicity of the
                //tutorial we wont be. Reference the ResponseCallback tutorial for more information
                int ret = Tdk.TdkInterface.Connect(selectedComPort,
                                                   (int)Tdk.TdkDefines.DeviceTypes.Serial,
                                                   System.IntPtr.Zero);
                if (ret >= 0)
                {
                    Console.AppendText("Successfully connected.\n");
                    ConnectedBoardID       = ret;
                    DiscoverButton.Enabled = false;
                    ConnectButton.Enabled  = false;
                    Tdk.TdkInterface.ChangeFreq(ConnectedBoardID, 1, frequency, 0);
                    connected = true;
                    if (fileLoaded)
                    {
                        StartButton.Enabled = true;
                    }

                    //discoverradio.Checked = true;
                }
                else
                {
                    Console.AppendText(Tdk.TdkDefines.GetLastEAIErrorString() + "\n");
                }
            }
            else
            {
                MessageBox.Show("Please select a Connection Mode!");
            }

            Cursor = Cursors.Default;
            if (fileLoaded)
            {
                StartButton.Enabled = true;
            }
        }
Esempio n. 8
0
        public void Write(string text)
        {
            Console.SelectionColor = System.Drawing.Color.Blue;

            Console.AppendText(text + "\n");

            Console.SelectionColor = Console.ForeColor;
        }
 private void Instance_MessageLogged(object sender, Log.LogEvents e)
 {
     Console.Dispatcher.BeginInvoke((Action)(() =>
     {
         Console.AppendText(e.Message);
         Console.ScrollToEnd();
     }));
 }
Esempio n. 10
0
 private System.Threading.Tasks.Task Client_Log(LogMessage arg)
 {
     Invoke((Action) delegate
     {
         Console.AppendText(arg + "\n");
     });
     return(null);
 }
Esempio n. 11
0
 private void button1_Click(object sender, EventArgs e)
 {
     speechS.SpeakAsync(SayBox.Text);
     Console.AppendText("Margery : " + SayBox.Text + "\n");
     if (!KeepText.Checked)
     {
         SayBox.Clear();
     }
 }
Esempio n. 12
0
 private void PrintToConsole(string message)
 {
     Console.Invoke((MethodInvoker) delegate()
     {
         Console.AppendText(message);
         Console.SelectionStart = Console.Text.Length;
         Console.ScrollToCaret();
     });
 }
Esempio n. 13
0
 private void CheckTDKErrors(int ret)
 {
     //if a tdk method returns less then zero then we should display the last error
     //in the tdk interface
     if (ret < 0)
     {
         Console.AppendText(Tdk.TdkDefines.GetLastEAIErrorString() + "\n");
     }
 }
Esempio n. 14
0
        bool chceckVerion(string newVersion)
        {
            string actualVersion = "";

            try
            {
                StreamReader plikR = new StreamReader(obj.versionFile);
                actualVersion = plikR.ReadLine();
                plikR.Close();
            }
            catch (Exception ex)
            {
                ex.ToString();
                string[] exception = ex.ToString().Split('\n');
                this.Show();
                Console.AppendText(nL);
                Console.AppendText("Wystąpił błąd: " + exception);
                Console.AppendText(nL + nL);
                Console.AppendText("Zakończono proces aktualizacji: (400) nie udało się zaktualizować");
                this.TopMost = false;
                return(false);
            }
            if (actualVersion == null)
            {
                actualVersion = "0";
            }

            try
            {
                if (float.Parse(newVersion) <= float.Parse(actualVersion))
                {
                    this.Show();
                    this.TopMost = false;
                    Console.AppendText("Wersja programu: " + actualVersion + " - aktualizacja niewymagana");
                    MessageBox.Show("Posiadasz najnowszą wersję", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Console.AppendText(nL + nL);
                    Console.AppendText("Zakończono proces aktualizacji: (204) nie wymaga aktualizacji");
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                ex.ToString();
                string[] exception = ex.ToString().Split('\n');
                this.Show();
                Console.AppendText(nL);
                Console.AppendText("Wystąpił błąd: Błędny format danych w pliku " + obj.versionFile);
                Console.AppendText(nL + nL);
                Console.AppendText("Zakończono proces aktualizacji: (400) nie udało się zaktualizować");
                this.TopMost = false;
                return(false);
            }
        }
Esempio n. 15
0
 private void GMHyperOutputHandler(object sender, DataReceivedEventArgs e)
 {
     if (!string.IsNullOrEmpty(e.Data))
     {
         Dispatcher.Invoke(() =>
         {
             Console.AppendText(e.Data + Environment.NewLine);
             Console.ScrollToEnd();
         });
     }
 }
Esempio n. 16
0
        public void checkReboot(string computerName)
        {
            ManagementScope scp = new ManagementScope(string.Format(@"\\{0}\root\ccm\clientsdk", computerName));
            ManagementClass cls = new ManagementClass(scp.Path.Path, "ccm_clientutilities", null);

            // Get the reboot status
            ManagementBaseObject outSiteParams = cls.InvokeMethod("DetermineIfRebootPending", null, null);

            // Display the status
            Console.AppendText(computerName + " Reboot Pending: " + outSiteParams["RebootPending"].ToString() + Environment.NewLine);
        }
Esempio n. 17
0
 private void CheckTDKErrors(int ret)
 {
     //if a tdk method returns less then zero then we should display the last error
     //in the tdk interface
     if (ret < 0)
     {
         //the GetLastEAIErrorString returns a string that represents the last error code
         //recorded in the tdk interface.
         Console.AppendText(Tdk.TdkDefines.GetLastEAIErrorString() + "\n");
     }
     //else Console.AppendText("Success\r\n");
 }
 private void TpaButton_Click(object sender, RoutedEventArgs e)
 {
     // ignore if already runnong
     if (_tpaGraph.IsRendering)
     {
         Console.AppendText("Already capturing the Pinball Arcade. Launch a game if you don't see anything!\n");
         return;
     }
     _grabberWindow.Hide();
     Console.AppendText("Starting pulling frames from the Pinball Arcade.\n");
     SwitchGraph(_tpaGraph);
 }
        //Add actual text to the console
        public void AddConsoleText(string text)
        {
            if (Console.InvokeRequired)
            {
                AddConsoleTextCallback d = new AddConsoleTextCallback(AddConsoleText);
                Invoke(d, new object[] { text });
            }
            else
            {
                string          tokens = "(UP-TO-DATE|SKIPPED|BUILD SUCCESSFUL)";
                Regex           rex    = new Regex(tokens);
                MatchCollection mc     = rex.Matches(text);
                int             startcursorposition = Console.SelectionStart;
                int             start = Console.TextLength;
                Console.AppendText(text + "\n");
                int end = Console.TextLength; // now longer by length of appended text
                foreach (Match m in mc)
                {
                    // Select text that was appended
                    Console.Select(start + m.Index, end - start);

                    Console.SelectionColor = Color.YellowGreen;
                    Console.SelectionFont  = new Font(Console.Font, FontStyle.Bold);

                    // Unselect text
                    Console.SelectionLength = startcursorposition;
                    Console.SelectionStart  = Console.Text.Length;
                    Console.SelectionColor  = Color.Black;
                    Console.SelectionFont   = new Font(Console.Font, FontStyle.Regular);
                }

                tokens = "(FAILED|BUILD FAILED)";
                rex    = new Regex(tokens);
                mc     = rex.Matches(text);
                foreach (Match m in mc)
                {
                    // Select text that was appended
                    Console.Select(start + m.Index, end - start);

                    Console.SelectionColor = Color.Red;
                    Console.SelectionFont  = new Font(Console.Font, FontStyle.Bold);

                    // Unselect text
                    Console.SelectionLength = startcursorposition;
                    Console.SelectionStart  = Console.Text.Length;
                    Console.SelectionColor  = Color.Black;
                    Console.SelectionFont   = new Font(Console.Font, FontStyle.Regular);
                }
                Console.ScrollToCaret();
                Console.DetectUrls = true;
            }
        }
Esempio n. 20
0
        public void patchEverything(string computerName)
        {
            ManagementScope          sc = new ManagementScope(string.Format(@"\\{0}\root\ccm\clientsdk", computerName));
            ManagementClass          c  = new ManagementClass(@"CCM_SoftwareUpdatesManager");
            ManagementObjectSearcher s  = new ManagementObjectSearcher("SELECT * FROM CCM_SOFTWAREUPDATE WHERE COMPLIANCESTATE=0 AND EVALUATIONSTATE < 2");

            c.Scope = s.Scope = sc;

            ManagementObjectCollection col      = s.Get();
            List <ManagementObject>    lUpdates = new List <ManagementObject>();

            int index = 1;

            foreach (ManagementObject o in col)
            {
                System.Management.ManagementBaseObject[] args = { o };

                object[] methodArgs = { args };

                c.InvokeMethod("InstallUpdates", methodArgs);

                System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    Console.AppendText(computerName + ": Now Installing Update " + index + " of " + col.Count + Environment.NewLine);
                }));


                UInt32 evalState = 0;


                while (evalState < 7)
                {
                    try
                    {
                        o.Get();
                        evalState = (UInt32)o.Properties["EvaluationState"].Value;
                    }

                    catch
                    {
                        break;
                    }
                }
                System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    Console.AppendText(computerName + ": Update " + index + " of " + col.Count + " completed" + Environment.NewLine);
                }));

                index++;
            }
        }
Esempio n. 21
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (sb.Length > 0)
            {
                Console.AppendText(sb.ToString());
                sb.Clear();
            }

            if (scrollAttemptsRemaining > 0)
            {
                Console.ScrollToEnd();
                scrollAttemptsRemaining--;
            }
        }
Esempio n. 22
0
        public InfinitePrecisionMatchingForm()
        {
            //Sound Code
            mySoundEngine = new ISoundEngine();
            mySoundEngine.Play2D("chimes.wav");

            InitializeComponent();
            //To initialize the TDKInterface we need to call InitializeTI before we use any
            //of its functionality
            Console.AppendText("Initializing Tactor Interface.\n");
            CheckTDKErrors(Tdk.TdkInterface.InitializeTI());
            //this.tabControl1.TabPages.Remove(this.MatchingTab);
            //this.tabControl1.TabPages.Remove(this.tabPage1);
        }
Esempio n. 23
0
 private void Log(string value)
 {
     if (Console.InvokeRequired)
     {
         Action <string> act = (text) =>
         {
             Console.AppendText(text);
         };
         Console.Invoke(act, value);
     }
     else
     {
         Console.AppendText(value);
     }
 }
Esempio n. 24
0
        public void checkSite(string computerName)
        {
            try {
                ManagementScope scp = new ManagementScope(string.Format(@"\\{0}\root\ccm", computerName));
                ManagementClass cls = new ManagementClass(scp.Path.Path, "sms_client", null);

                // Get current site code.
                ManagementBaseObject outSiteParams = cls.InvokeMethod("GetAssignedSite", null, null);

                // Display current site code.
                Console.AppendText(computerName + " Site Code: " + outSiteParams["sSiteCode"].ToString() + Environment.NewLine);
            }
            catch {
                Console.AppendText(computerName + ": Error!  Client may not be installed or you do not have access" + Environment.NewLine);
            }
        }
        private void ScreenButton_Click(object sender, RoutedEventArgs e)
        {
            // this one we stop if it's running and button was clicked again
            if (_screenGraph.IsRendering)
            {
                _grabberWindow.Hide();
                _currentRenderer.Dispose();
                _currentSource.Dispose();
                _currentRenderer = null;
                Console.AppendText("Stopped pulling frames from desktop.\n");
                return;
            }

            _grabberWindow.Show();
            SwitchGraph(_screenGraph);
            Console.AppendText("Started pulling frames from desktop.\n");
        }
Esempio n. 26
0
        public void getAppliedPatches(string computerName, int days)
        {
            //computerName = getFQDN(computerName);
            EventLog ev       = new EventLog("System", computerName);
            DateTime t1       = DateTime.Now;
            DateTime fromDate = DateTime.Now.AddDays(-days);
            int      i        = 0;

            for (i = ev.Entries.Count - 1; i >= 0; i--)
            {
                if (ev.Entries[i].InstanceId == 19 && ev.Entries[i].TimeGenerated > fromDate)
                {
                    Console.AppendText(computerName + " " + ev.Entries[i].TimeGenerated + " " + ev.Entries[i].InstanceId + " " + ev.Entries[i].Message + Environment.NewLine);
                }
            }
            Console.AppendText("End of log entries" + Environment.NewLine);
        }
Esempio n. 27
0
        private void speak(string input, string output, bool keepCommand)
        {
            Console.AppendText("User : "******"\n");
            Console.AppendText("Margery : " + output + "\n");
            speechS.SpeakAsync(output);

            if (alwaysActive == true)
            {
                active = true;
            }
            else
            {
                active = false;
            }
            if (keepCommand == true)
            {
                lastCommand = output;
            }
        }
Esempio n. 28
0
 public void DeleteFiles(string[] data, int val)
 {
     for (int i = 2; i < val + 2; i++)
     {
         Console.AppendText(nL);
         Console.AppendText("usuwanie pliku " + data[i] + ": ");
         try
         {
             System.IO.File.Delete(obj.adres + data[i]);
         }
         catch (Exception)
         {
             Console.AppendText("nie udało się usunąć pliku");
         }
         Console.AppendText("ukończone");
         this.Show();
     }
     return;
 }
Esempio n. 29
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            string selectedComPort;

            if (discoverradio.Checked || connectradio.Checked)
            {
                if (discoverradio.Checked)
                {
                    selectedComPort = ComPortComboBox.SelectedItem.ToString();
                }
                else
                {
                    selectedComPort = comportselection.Text;
                }

                Console.AppendText("Attempting to connect to com port " + selectedComPort + "...\n");
                //Connect connects to the tactor controller via serial with the given name
                //we should be hooking up a response callback but for simplicity of the
                //tutorial we wont be. Reference the ResponseCallback tutorial for more information
                int ret = Tdk.TdkInterface.Connect(selectedComPort,
                                                   (int)Tdk.TdkDefines.DeviceTypes.Serial,
                                                   System.IntPtr.Zero);
                if (ret >= 0)
                {
                    ConnectButton.Enabled     = false;
                    ConnectedBoardID          = ret;
                    DiscoverButton.Enabled    = false;
                    PulseTactorButton.Enabled = true;
                    StartButton.Enabled       = true;
                    connected = true;
                    Console.AppendText("Success!\n");
                }
                else
                {
                    Console.AppendText(Tdk.TdkDefines.GetLastEAIErrorString() + "\n");
                }
            }
            else
            {
                MessageBox.Show("Please select a Connection Mode!");
            }
        }
Esempio n. 30
0
        private void DiscoverButton_Click(object sender, EventArgs e)
        {
            Cursor.Current      = Cursors.WaitCursor;
            StartButton.Enabled = false;

            Console.AppendText("Discover Started...\n");
            //Discovers all serial tactor devices and returns the amount found
            int ret = Tdk.TdkInterface.Discover((int)Tdk.TdkDefines.DeviceTypes.Serial);

            Cursor.Current = Cursors.Default;

            if (ret > 0)
            {
                Console.AppendText("Discover Found:\n");
                //populate combo box with discovered names
                for (int i = 0; i < ret; i++)
                {
                    //Gets the discovered device name at the index i
                    System.IntPtr discoveredNamePTR = Tdk.TdkInterface.GetDiscoveredDeviceName(i);
                    if (discoveredNamePTR != null)
                    {
                        string sComName = Marshal.PtrToStringAnsi(discoveredNamePTR);
                        Console.AppendText(sComName + "\n");
                        ComPortComboBox.Items.Add(sComName);
                    }
                    else
                    {
                        Console.AppendText(Tdk.TdkDefines.GetLastEAIErrorString() + "\n");
                    }
                }
                ComPortComboBox.SelectedIndex = 0;
                DiscoverButton.Enabled        = false;
                ConnectButton.Enabled         = true;
                StartButton.Enabled           = true;
            }
            else
            {
                Console.AppendText("Discover Failed:\n");
                Console.AppendText(Tdk.TdkDefines.GetLastEAIErrorString() + "\n");
            }
        }