Example #1
0
        // ******************************************************************
        public bool Register()
        {
            int virtualKeyCode = KeyInterop.VirtualKeyFromKey(Key);

            Id = virtualKeyCode + ((int)KeyModifiers * 0x10000);
            bool result = RegisterHotKey(IntPtr.Zero, Id, (UInt32)KeyModifiers, (UInt32)virtualKeyCode);

            if (_dictHotKeyToCalBackProc == null)
            {
                _dictHotKeyToCalBackProc = new Dictionary <int, HotKey>();
                ComponentDispatcher.ThreadFilterMessage += ComponentDispatcherThreadFilterMessage;
            }

            try
            {
                _dictHotKeyToCalBackProc.Add(Id, this);
            }
            catch (Exception)
            {
                Logger.Record("[Register]: Error when registering HotKey, duplicate key. Possible error on Unregistering", "KeyboardHook", "error");
            }

            Debug.Print(result.ToString() + ", " + Id + ", " + virtualKeyCode);
            return(result);
        }
Example #2
0
        public Bitmap CaptureSnippet()
        {
            int minX = 0, minY = 0, maxX = 0, maxY = 0;

            foreach (var oneScreen in Screen.AllScreens)
            {
                Logger.Record("\t[CaptureSnippet]: AllScreens[]: SNIPPET" + oneScreen.Bounds.ToString(), "ScreenShot", "info");
                minX = Math.Min(minX, oneScreen.Bounds.Left);
                minY = Math.Min(minY, oneScreen.Bounds.Top);
                maxX = Math.Max(maxX, oneScreen.Bounds.Width + oneScreen.Bounds.X);
                maxY = Math.Max(maxY, oneScreen.Bounds.Height + oneScreen.Bounds.Y);
            }
            maxY = Math.Abs(maxY) + Math.Abs(minY);
            maxX = Math.Abs(maxX) + Math.Abs(minX);

            var snipForm = new SnippetForm
            {
                Top              = minY,
                Left             = minX,
                Width            = maxX,
                Height           = maxY,
                ScreenStartImage = CaptureScreenShot()
            };

            snipForm.ShowDialog();
            if (snipForm.Cancelled || snipForm.Snippet == null)
            {
                Canceled = true;
            }
            return(snipForm.Snippet ?? new Bitmap(1, 1));
        }
Example #3
0
        public App()
        {
            Logger.Record("[App]: >>>> Rapid Reporter Starting", "App", "info");

            Logger.Record("[App]: Applic Name: " + System.Diagnostics.Process.GetCurrentProcess().ProcessName, "App", "info");
            // OS Version can be analyzed with the help of:
            //  http://stackoverflow.com/questions/545666/how-to-translate-ms-windows-os-version-numbers-into-product-names-in-net
            //  http://www.eggheadcafe.com/software/aspnet/35878122/how-to-determine-windows-flavor-in-net.aspx
            Logger.Record("[App]: OS  Version: " + System.Environment.OSVersion, "App", "info");

            // Framework can be analyzed with the help of:
            //  http://en.wikipedia.org/wiki/List_of_.NET_Framework_versions
            Logger.Record("[App]: Env version: " + System.Environment.Version, "App", "info");

            // Locale can be analyzed with the help of:
            //  http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
            //  http://msdn.microsoft.com/en-us/goglobal/bb895996
            Logger.Record("[App]: Keyb Locale: " + InputLanguage.CurrentInputLanguage.Culture.KeyboardLayoutId, "App", "info");

            Logger.Record("[App]: Instances #: " + System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length.ToString(), "App", "info");
            Logger.Record("[App]: Working Set: " + System.Environment.WorkingSet.ToString(), "App", "info");
            Logger.Record("[App]: Current Dir: " + System.Environment.CurrentDirectory, "App", "info");
            Logger.Record("[App]: CommandLine: " + System.Environment.CommandLine, "App", "info");
            Logger.Record("[App]: Network  On: " + SystemInformation.Network, "App", "info");
            Logger.Record("[App]: Monitor num: " + SystemInformation.MonitorCount, "App", "info");
            Logger.Record("[App]: WorkingArea: " + SystemInformation.WorkingArea, "App", "info");
        }
Example #4
0
        public Bitmap CaptureScreenShot()
        {
            Logger.Record("[CaptureScreenshot]: Will take a screenshot of the monitor.", "ScreenShot", "info");
            int minX = 0, minY = 0, maxX = 0, maxY = 0;

            /*
             *
             * Composite desktop calculations for multiple monitors
             *
             *  A, B            E, B                     ||                  E, B
             +--------------+                       ||   *              +---------------+ D, B
             |              |E, G                   ||                  |               |
             |              +---------------+ D, G  ||   +--------------+ E, C          |
             |              |               |       ||   |A, C          |               |
             |              |               |       ||   |              |               |
             |              |               |       ||   |              |               |
             +--------------+ E, C          |       ||   |              +---------------+ D, G
             |  A, C             |               |       ||   |              |E, G
             +---------------+ D, F  ||   +--------------+               *
             |                  E, F                     ||   A, F           E, F
             |
             * We capture from "A, B" to "D, F".
             *   That is, we look for the minimum X,Y coordinate first.
             *   Then we look for the largest width,height.
             *
             */

            foreach (var oneScreen in Screen.AllScreens)
            {
                Logger.Record("\t[CaptureScreenshot]: AllScreens[]: " + oneScreen.Bounds.ToString(), "ScreenShot", "info");
                minX = Math.Min(minX, oneScreen.Bounds.Left);
                minY = Math.Min(minY, oneScreen.Bounds.Top);
                maxX = Math.Max(maxX, oneScreen.Bounds.Width + oneScreen.Bounds.X);
                maxY = Math.Max(maxY, oneScreen.Bounds.Height + oneScreen.Bounds.Y);
            }
            var fullBounds = new Rectangle(minX, minY, maxX - minX, maxY - minY);

            Logger.Record("[CaptureScreenshot]: fullScreen[]: " + fullBounds, "ScreenShot", "info");

            var hDesk = GetDesktopWindow();
            var hSrce = GetWindowDC(hDesk);
            var hDest = CreateCompatibleDC(hSrce);
            // Our bitmap will have the size of the composite screenshot
            var hBmp    = CreateCompatibleBitmap(hSrce, fullBounds.Width, fullBounds.Height);
            var hOldBmp = SelectObject(hDest, hBmp);

            // We write on coordinate 0,0 of the bitmap buffer, of course. But we write the the fullBoundsX,Y pixels.
            BitBlt(hDest, 0, 0, fullBounds.Width, fullBounds.Height, hSrce, fullBounds.X, fullBounds.Y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
            var bmp = Image.FromHbitmap(hBmp);

            SelectObject(hDest, hOldBmp);
            DeleteObject(hBmp);
            DeleteDC(hDest);
            ReleaseDC(hDesk, hSrce);
            Logger.Record("[CaptureScreenshot]: BMP object ready, returning it to calling function", "ScreenShot", "info");
            return(bmp);
        }
Example #5
0
        private void LoadCsvIntoSession(string csvFile)
        {
            Logger.Record("[LoadCsvIntoSession]: Grabbing CSV file variables", "Session", "info");

            bool exDrRetry;

            do
            {
                exDrRetry = false;
                try
                {
                    foreach (var line in File.ReadAllLines(csvFile, Encoding.UTF8))
                    {
                        if ("" == line)
                        {
                            continue;
                        }
                        var thisLine = line.Split(',');
                        if (thisLine.Length <= 2)
                        {
                            continue;
                        }
                        var note = thisLine[2].Replace("\"", "");
                        switch (thisLine[1])
                        {
                        case @"Session Reporter":
                            Tester       = note;
                            StartingTime = DateTime.Parse(thisLine[0]);
                            break;

                        case @"Scenario ID":
                            ScenarioId = note;
                            break;

                        case @"Session Charter":
                            Charter = note;
                            break;

                        case @"Environment":
                            Environment = note;
                            break;

                        case @"Versions":
                            Versions = note;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Record("[LoadCsvIntoSession]: EXCEPTION reached - Session Report file could not be read (" + csvFile + ")", "Session", "error");
                    exDrRetry = Logger.FileErrorMessage(ex, "LoadCsvIntoSession", csvFile);
                }
            } while (exDrRetry);
            Logger.Record("[LoadCsvIntoSession]: Grabbing CSV file variables done.", "Session", "info");
        }
Example #6
0
        /** Sessions **/
        /**************/

        // Start Session and Close Session prepare/finalize the log file
        public void StartSession()
        {
            Logger.Record("[StartSession]: Session configuration starting", "Session", "info");

            StartingTime     = DateTime.Now; // The time the session started is used for many things, like knowing the session file name
            WorkingDir       = Directory.GetCurrentDirectory() + @"\" + StartingTime.ToString("yyyyMMdd_HHmmss") + @"\";
            _sessionFile     = StartingTime.ToString("yyyyMMdd_HHmmss") + ".csv";
            _sessionFileFull = WorkingDir + _sessionFile; // All files should be written to a working directory -- be it current or not.
            CreateWorkingDir(WorkingDir);
            SaveToSessionNotes(ColumnHeaders + "\n");     // Headers of the notes table
            //UpdateNotes("Reporter Tool Version", System.Windows.Forms.Application.ProductVersion);
            UpdateNotes("Session Reporter", Tester);
            UpdateNotes("Scenario ID", ScenarioId);
            UpdateNotes("Session Charter", Charter);
            UpdateNotes("Environment", Environment);
            UpdateNotes("Versions", Versions);
        }
Example #7
0
        // Save all notes on file, after every single note
        private void SaveToSessionNotes(string note)
        {
            Logger.Record("[SaveToSessionNotes]: File will be updated and saved to " + _sessionFile, "Session", "info");
            bool exDrRetry;

            do
            {
                exDrRetry = false;
                try
                {
                    File.AppendAllText(_sessionFileFull, note, Encoding.UTF8);
                }
                catch (Exception ex)
                {
                    Logger.Record("\t[SaveToSessionNotes]: EXCEPTION reached - Session Note file could not be saved (" + _sessionFile + ")", "Session", "error");
                    exDrRetry = Logger.FileErrorMessage(ex, "SaveToSessionNotes", _sessionFile);
                }
            } while (exDrRetry);
        }
Example #8
0
        public void CloseSession() // Not closing directly, we first finalize the session
        {
            Logger.Record("[CloseSession]: Session closing...", "Session", "info");

            // Why this if? We will only add the 'end session' note if we were past the charter step.
            if (!String.Equals(Versions, ""))
            {
                TimeSpan duration = DateTime.Now - StartingTime;
                UpdateNotes("Session End. Duration",
                            duration.Hours.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0') + ":" +
                            duration.Minutes.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0') + ":" +
                            duration.Seconds.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0'));
                Logger.Record("[CloseSession]: Starting csv to html method...", "Session", "info");
                if (createHTML)
                {
                    Csv2Html(_sessionFileFull, false);
                }
            }

            Logger.Record("[CloseSession]: ...Session closed", "Session", "info");
        }
Example #9
0
        internal bool ResumeSession()
        {
            Logger.Record("[ResumeSession]: Session configuration starting", "Session", "info");

            var csvFile = SelectSessionCsvForOpen();

            if (string.IsNullOrWhiteSpace(csvFile))
            {
                return(false);
            }
            LoadCsvIntoSession(csvFile);
            if (string.IsNullOrWhiteSpace(Tester) || string.IsNullOrWhiteSpace(Charter) ||
                string.IsNullOrWhiteSpace(Versions) || string.IsNullOrWhiteSpace(Environment) ||
                string.IsNullOrWhiteSpace(ScenarioId))
            {
                return(false);
            }
            _sessionFile     = Path.GetFileName(csvFile);
            WorkingDir       = Path.GetDirectoryName(csvFile) + @"\";
            _sessionFileFull = csvFile;
            return(true);
        }
Example #10
0
        public void Csv2Html(string csvFile, bool relativePath)
        {
            Logger.Record("[CSV2HTML]: HTML Report building", "Session", "info");
            var  csvFileFull  = relativePath ? WorkingDir + csvFile : csvFile;
            var  htmlFileFull = DiscoverSavePath(csvFile);
            bool exDrRetry;

            do
            {
                exDrRetry = false;
                var htmlFileBufferPopups = "";
                try
                {
                    var imgCount = 0;
                    var ptnCount = 0;
                    var t        = "th";
                    var title    = string.Format("{0}{1}", ScenarioId, Htmlstrings.HtmlTitle);
                    File.Delete(htmlFileFull);
                    var htmlTop = string.Format("{0}{1}{2}{3}{4}{5}{1}{6}", (object)Htmlstrings.AHtmlHead,
                                                (object)title, (object)Htmlstrings.BTitleOut, (object)Htmlstrings.CStyle,
                                                (object)Htmlstrings.DJavascript, (object)Htmlstrings.EBody, (object)Htmlstrings.GTable);
                    var topNotes    = "";
                    var bottomNotes = "";

                    foreach (var line in File.ReadAllLines(csvFileFull, Encoding.UTF8))
                    {
                        if ("" == line)
                        {
                            continue;
                        }
                        var note     = "";
                        var thisLine = line.Split(',');
                        if (thisLine.Length > 2)
                        {
                            note = thisLine[2].Replace("\"", "");
                            switch (thisLine[1])
                            {
                            case @"Screenshot":
                                if (!File.Exists(WorkingDir + note))
                                {
                                    note += " not found.";
                                    break;
                                }
                                note = HtmlEmbedder.BuildSessionRow_Img(imgCount, WorkingDir + note);
                                htmlFileBufferPopups += HtmlEmbedder.BuildPopUp_Img(imgCount);
                                imgCount++;
                                break;

                            case @"PlainText Note":
                                if (!File.Exists(WorkingDir + note))
                                {
                                    note += " not found.";
                                    break;
                                }
                                htmlFileBufferPopups += HtmlEmbedder.BuildPopUp_PTNote(ptnCount, WorkingDir + note);
                                note = HtmlEmbedder.BuildSessionRow_PTNote(ptnCount);
                                ptnCount++;
                                break;
                            }
                        }

                        if (thisLine[1] == "Type" || thisLine[1] == "Session Reporter" ||
                            (thisLine[1] == "Scenario ID" || thisLine[1] == "Session Charter") ||
                            (thisLine[1] == "Environment" || thisLine[1] == "Versions" || thisLine[1] == "Summary"))
                        {
                            topNotes += BuildTableRow(t, thisLine[1], thisLine[0], note);
                        }
                        else
                        {
                            bottomNotes += BuildTableRow(t, thisLine[1], thisLine[0], note);
                        }
                        t = "td";
                    }
                    topNotes = topNotes + BuildTableRow("td", "", "", "");
                    var output = htmlTop +
                                 string.Format("{0}{1}{2}{3}{4}", topNotes, bottomNotes,
                                               Htmlstrings.JTableEnd, htmlFileBufferPopups, Htmlstrings.MHtmlEnd);

                    File.WriteAllText(htmlFileFull, output, Encoding.UTF8);
                    MessageBox.Show("The HTML was created successfully!\nFile created: " + htmlFileFull, "HTML Conversion Successful!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    Logger.Record("[CSV2HTML]: EXCEPTION reached - Session Report file could not be saved (" + htmlFileFull + ")", "Session", "error");
                    exDrRetry = Logger.FileErrorMessage(ex, "CSV to HTML", htmlFileFull);
                }
            } while (exDrRetry);
            Logger.Record("[CSV2HTML]: HTML Report built, done.", "Session", "info");
        }
Example #11
0
 internal void UpdateNotes(string type, string note, string screenshot = "", string rtfNote = "")
 {
     SessionNote = DateTime.Now + "," + type + ",\"" + note + "\"," + rtfNote + "\n";
     SaveToSessionNotes(SessionNote);
     Logger.Record("[UpdateNotes ss]: Note added to session log (" + screenshot + ", " + rtfNote + ")", "Session", "info");
 }
Example #12
0
        /** Notes **/
        /***********/
        // Notes are always saved on file, not only when program exists (so no data loss in case of crash)

        // UpdateNotes: There are two overloads: One receives all strings (custom messages), the other an int (typed messages)
        internal void UpdateNotes(int type, string note, string screenshot, string rtfNote)
        {
            UpdateNotes(NoteTypes[type], note, screenshot, rtfNote);
            Logger.Record("[UpdateNotes isss]: Note added to session log. Attachments: (" + (screenshot.Length > 0) + " | " + (rtfNote.Length > 0) + ")", "Session", "info");
        }