コード例 #1
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ShutDownDialog = ((Shiny.AlertShutDownDialog)(target));
                return;

            case 2:
                this.shutDownTextLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 3:
                this.yesButton = ((System.Windows.Controls.Button)(target));

            #line 15 "..\..\AlertShutDownDialog.xaml"
                this.yesButton.Click += new System.Windows.RoutedEventHandler(this.yesButton_Click);

            #line default
            #line hidden
                return;

            case 4:
                this.noButton = ((System.Windows.Controls.Button)(target));

            #line 16 "..\..\AlertShutDownDialog.xaml"
                this.noButton.Click += new System.Windows.RoutedEventHandler(this.noButton_Click);

            #line default
            #line hidden
                return;

            case 5:
                this.commentBox = ((System.Windows.Controls.RichTextBox)(target));

            #line 17 "..\..\AlertShutDownDialog.xaml"
                this.commentBox.GotFocus += new System.Windows.RoutedEventHandler(this.RichTextBox_GotFocus);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
コード例 #2
0
        // Active alert table Status column click event
        private void ActiveAlertTable_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (sender != null)
            {
                DataGrid grid = sender as DataGrid;
                if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1)
                {
                    bool missionDone = false;
                    //  store ID & IP
                    string ID = ((DataRowView)ActiveAlertTable.CurrentCell.Item).Row.ItemArray[0].ToString();
                    string IP = ((DataRowView)ActiveAlertTable.CurrentCell.Item).Row.ItemArray[4].ToString();
                    //  dialog to shut down
                    AlertShutDownDialog win2   = new AlertShutDownDialog();
                    Tuple <int, string> result = win2.ReturnResult(ID);
                    if (result.Item1 == 1)
                    {
                        string          connStr = "server=earthpwn.ddns.net;user=anan;database=anan;port=6969;password=anan;SslMode=none"; //global
                        MySqlConnection conn    = new MySqlConnection(connStr);
                        try
                        {
                            ConsoleAddItem("Alarm shut down mission has started for Alarm #" + ID);
                            // Mission: Shut the Alarm Down!   Part 1: Sending Signal to Client
                            try
                            {
                                var client      = new TcpClient();
                                var asyncresult = client.BeginConnect(IP, 5001, null, null);
                                var success     = asyncresult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(1));
                                if (success)
                                {
                                    ConsoleAddItem("Server exist");
                                    using (NetworkStream nwStream = client.GetStream())
                                    {
                                        // YAZ
                                        String textToSend  = "1";
                                        byte[] bytesToSend = Encoding.UTF8.GetBytes(textToSend);
                                        nwStream.Write(bytesToSend, 0, bytesToSend.Length);
                                        ConsoleAddItem(">>>>>>>>>>>>> " + textToSend);
                                        // OKU,
                                        byte[] bytesToRead = new byte[client.ReceiveBufferSize];
                                        int    bytesRead   = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
                                        ConsoleAddItem("Received : " + Encoding.ASCII.GetString(bytesToRead, 0, bytesRead));
                                        // Verify server understood the command
                                        if (Encoding.ASCII.GetString(bytesToRead, 0, bytesRead) == textToSend)
                                        {
                                            ConsoleAddItem("Initiating hibernation sequence" /* Tospaa, 10.11.2018 */);
                                            missionDone = true;
                                        }
                                        else
                                        {
                                            ConsoleAddItem("Handshake failed. Skipping the DB update.");
                                        }
                                    }
                                }
                                else
                                {
                                    ConsoleAddItem("Server is unreachable. Skipping DB update.");
                                }
                            }
                            catch (SocketException)
                            {
                                ConsoleAddItem(String.Format("Couldn't send the signal to Alarm #{0}. Target is not online. Skipping the DB update.", ID));
                            }
                            catch (IOException)
                            {
                                ConsoleAddItem(String.Format("Couldn't send the signal to Alarm #{0}. Target is not online. Skipping the DB update.", ID));
                            }

                            conn.Open();
                            ConsoleAddItem("DB Connection established!");

                            // Mission accomplished! Update DB
                            if (missionDone)
                            {
                                // Mission: Shut the Alarm Down!   Part 2: Database Conversation

                                // Status Update
                                StatusUpdate(Status.OFF, ID, result.Item2.Trim(new char[] { '\r', '\n' }), false, conn);

                                // Activity Update
                                ActivityUpdate(Activity.OFF_AdminShutDown, ID, false, conn);
                            }
                            // Houston, we may have a problem.
                            else
                            {
                                //MessageBox.Show("Alarm deaktif hale getirelemedi.")
                                ConsoleAddItem($"ID: {ID} IP: {IP} - Alarm deaktif hale getirelemedi.");
                                SbarMessage($"#{ID} numaralı alarm deaktif hale getirelemedi.");
                            }

                            // Refresh Alerts
                            RetrieveAlerts(false, conn);
                        }
                        catch (Exception ex)
                        {
                            ConsoleAddItem("Error while changing alarm status: " + ex.Message);
                        }
                        if (conn.State == ConnectionState.Open)
                        {
                            try
                            {
                                conn.Close();
                                ConsoleAddItem("DB Connection Closed.");
                            }
                            catch (Exception ex)
                            {
                                ConsoleAddItem($"{ex.Message} You should've never seen this.");
                            }
                        }
                    }
                }
            }
        }