Ejemplo n.º 1
0
        /*
         * Target: RefreshQueue - Function
         * Purpose: Handles the refreshing of lstQueue.
         * This is done by clearing it then re-adding all objects,
         * except for whatever object may have changed or been removed.
         * This is mostly used for if the frequency has been changed.
         * Date: 6/11/2019
         * Date-Last-Edited: 6/12/2019
         * FUNCTION NOT IN USE CURRENTLY
         *
         * private void RefreshQueue()
         * {
         *  ArrayList tempArr = new ArrayList();
         *  string tempStr = "";
         *
         *  for (int i = 0; i < lstQueue.Items.Count; i++)
         *  {
         *      tempStr = lstQueue.Items[i].ToString().Substring(lstQueue.Items[i].ToString().IndexOf('-') + 2);
         *      //parsing the string to get rid of the time in the beginning.
         *
         *      tempArr.Add(tempStr);
         *
         *  }
         *
         *  lstQueue.Items.Clear();
         *
         *  for(int i = 0; i < hiddenData.Count; i++)
         *  {
         *      for(int j = 0; j < tempArr.Count; j++)
         *      {
         *          if(((ProcessData)hiddenData[i]).winTitle == tempArr[j].ToString())
         *          {
         *              lstQueue.Items.Add(((ProcessData)hiddenData[i]).freq/60000 + "min - " + tempArr[j].ToString());
         *              //add the new string with the data.
         *              break;
         *          }
         *      }
         *  }
         * }
         */

        /*
         * Target: SwapApp - Function
         * Purpose: Handles changing the focus placed on
         * windows. This is done using the individual handle that is
         * assigned to the window. The interval for the timer is also
         * controlled and set here. This is called on the btnSwapper click.
         * If the process that is opened is Explorer or Edge, then we will
         * close and reopen that process. This is done to refresh the content
         * that is being shown on that page.
         * Date: 6/3/2019
         * Date-Last-Edited: 6/13/2019
         */
        private void SwapApp()
        {
            IntPtr handle  = IntPtr.Zero;
            string tempStr = lstQueue.SelectedItem.ToString().Substring(lstQueue.SelectedItem.ToString().IndexOf('-') + 2);
            //parse and store the string without the time in the beginning.
            int pid = 0;

            const short SWP_NOACTIVATE = 0X0010;
            const short SWP_NOMOVE     = 0X0002;
            const int   SW_SHOWNORMAL  = 1;
            const int   SW_MAXIMIZE    = 3;

            try
            {
                for (int i = 0; i < hiddenData.Count; ++i)
                {
                    if (((ProcessData)hiddenData[i]).winTitle == tempStr)
                    {
                        handle             = ((ProcessData)hiddenData[i]).handle;
                        pid                = int.Parse(((ProcessData)hiddenData[i]).id);
                        timerSwap.Interval = ((ProcessData)hiddenData[i]).freq;
                        //Grabbing the necessary data to perform a window swap.
                        break;
                    }
                }

                int           chars = 256;
                StringBuilder buff  = new StringBuilder(chars);

                IntPtr fHandle = GetForegroundWindow();
                //grab the window currently shown for comparison

                //this if statement checks to make sure that our window is valid
                if (GetWindowText(fHandle, buff, chars) > 0)
                {
                    if (handle != IntPtr.Zero)
                    {
                        SetForegroundWindow(handle);
                        //if the handle of the window is valid then we can go ahead and set
                        //it as the foreground window.

                        if (tempStr.ToLower() == "pluto tv")
                        {
                            if (chyronActive)
                            {
                                myScreen = Screen.FromHandle(handle);
                                //grab the screen that the window is on so that we can
                                //dynamically size the window according to screen size.

                                int trueHeight = (int)(myScreen.WorkingArea.Height * .15);
                                trueHeight = myScreen.WorkingArea.Height - trueHeight;
                                int trueWidth = myScreen.WorkingArea.Width;

                                if (handle != IntPtr.Zero)
                                {
                                    ShowWindowAsync(handle, SW_SHOWNORMAL);

                                    SetWindowPos(handle, 0, 0, 0, trueWidth, trueHeight, SWP_NOACTIVATE | SWP_NOMOVE);
                                }
                            }
                            else
                            {
                                ShowWindowAsync(handle, SW_MAXIMIZE);
                            }
                        }

                        if (Process.GetProcessById(pid).ProcessName == "iexplore" || Process.GetProcessById(pid).ProcessName == "MicrosoftEdge") //I despise this method...
                        {
                            Process.GetProcessById(pid).Kill();
                            //since we are using IE to do a specific task with our prod metrics data
                            //in order to refresh this page I am simply closing it and reopening it every
                            //time it comes up in the queue.

                            for (int i = 0; i < hiddenData.Count; i++)
                            {
                                if (((ProcessData)hiddenData[i]).id == pid.ToString())
                                {
                                    ProcessData temp    = (ProcessData)hiddenData[i];
                                    Process     newData = Process.Start(@"C:\Program Files\Internet Explorer\iexplore.exe", "http://bowebtier:8080/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=4609440&sType=wid&sRefresh=Y&sWindow=Same?logonSuccessful=true&shareId=0&sOutputFormat=H");
                                    //start a new instance of IE with our link to be opened

                                    Cursor.Current = Cursors.WaitCursor;
                                    System.Threading.Thread.Sleep(10000);
                                    Cursor.Current = Cursors.Default;

                                    if (!newData.HasExited)
                                    {
                                        temp.id       = newData.Id.ToString();
                                        temp.winTitle = newData.MainWindowTitle;
                                        temp.handle   = newData.MainWindowHandle;
                                        temp.restart  = false;
                                        temp.freq     = ((ProcessData)hiddenData[i]).freq;

                                        hiddenData.RemoveAt(i);
                                        hiddenData.Insert(i, temp);
                                        //We have to essentially re-add the old item back into the list since we closed,
                                        //and re-opened it. the process data has been changed in doing this so the
                                        //new process data and new window handle need to be saved over the old.
                                    }

                                    int index = lstQueue.Items.IndexOf(((ProcessData)hiddenData[i]).freq / 60000 + "min" + " - " + ((ProcessData)hiddenData[i]).winTitle);
                                    lstQueue.Items.Remove(((ProcessData)hiddenData[i]).freq / 60000 + "min" + " - " + ((ProcessData)hiddenData[i]).winTitle);
                                    //We need to remove the old instance of the link from the list to be readded.

                                    lstQueue.Items.Insert(index, ((ProcessData)hiddenData[i]).freq / 60000 + "min" + " - " + ((ProcessData)hiddenData[i]).winTitle);
                                    lstQueue.SelectedItem = (((ProcessData)hiddenData[i]).freq / 60000 + "min" + " - " + ((ProcessData)hiddenData[i]).winTitle);
                                    //Re-add the item to the queue then reselect it.
                                    //This method has been known to mess up some.

                                    RefreshDropDown();
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        /*
         * Target: EditFrequency - Function
         * Purpose: Handle the popup for the second form. The second form
         * is where the user inputs the new frequency. The frequency that
         * the user enters on the second form is then pulled in this function
         * and saved into the hiddenData() ArrayList. This is called on btnEditFreq click.
         * Date: 6/3/2019
         * Date-Last-Edited: 6/13/2019
         */
        private void EditFrequency()
        {
            if (lstQueue.SelectedIndex >= 0)
            {
                try
                {
                    string tempStr = lstQueue.SelectedItem.ToString().Substring(lstQueue.SelectedItem.ToString().IndexOf('-') + 2);
                    // the above line may be confusing, but since I need the string name of the application
                    // but I append the time to the beginning, all this does is parse that part out.

                    for (int i = 0; i < hiddenData.Count; i++)
                    {
                        if (tempStr == ((ProcessData)hiddenData[i]).winTitle)
                        {
                            processDataToEdit = (ProcessData)hiddenData[i];
                        }
                    }

                    frmEditFreq frmTwo = new frmEditFreq();
                    frmTwo.ShowDialog();

                    if (frmTwo.secondsFreq > 0)
                    {
                        for (int i = 0; i < hiddenData.Count; i++)
                        {
                            if (((ProcessData)hiddenData[i]).handle == processDataToEdit.handle)
                            {
                                //create a new ProcessData item that will be stored over the previous item
                                //but with the same values other than the new frequency
                                ProcessData temp      = (ProcessData)hiddenData[i];
                                int         indexFreq = temp.freq;

                                temp.freq = frmTwo.secondsFreq * 60000;
                                hiddenData.RemoveAt(i);
                                hiddenData.Insert(i, temp);

                                int index = lstQueue.Items.IndexOf(indexFreq / 60000 + "min" + " - " + ((ProcessData)hiddenData[i]).winTitle);
                                lstQueue.Items.Remove(indexFreq / 60000 + "min" + " - " + ((ProcessData)hiddenData[i]).winTitle);
                                //We need to remove the old instance of the link from the list to be readded.

                                lstQueue.Items.Insert(index, ((ProcessData)hiddenData[i]).freq / 60000 + "min" + " - " + ((ProcessData)hiddenData[i]).winTitle);
                                lstQueue.SelectedItem = (((ProcessData)hiddenData[i]).freq / 60000 + "min" + " - " + ((ProcessData)hiddenData[i]).winTitle);
                                //Re-add the item to the queue then reselect it.
                                //This method has been known to mess up some.

                                RefreshDropDown();
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show("Please Select an item from the queue", "Selection Error");
            }
        }