Example #1
0
        public static void Opening_Check(ref Dictionary <string, object> SendMessage, ref Dictionary <string, object> MainResultArray, ref string SendString, string GroupName, ref int ExcelStepCounter, ref int TotalStepCount, ref ISheet sheet, ref int SocketDataCheck, ref string halfSocketRemark)
        {
            FuncClass.IdsStatus();
            SendMessage.Add("SavePath", dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
            try { SendString = dll_PublicFuntion.Other.DictionaryToXml(SendMessage); } catch { }
            FuncClass.IDS_Check(SendMessage, ref MainResultArray, false);

            if (!File.Exists((string)SendMessage["SavePath"]))
            {
                MainResultArray[Parameters.Status] = "Fail";
                MainResultArray[Parameters.Remark] = "IDS connect error.";
            }
            // Parameter => IconName / PicturePath
            Dictionary <string, object> FDic = new Dictionary <string, object>();

            try { FDic = dll_PublicFuntion.Other.XmlToDictionary(SendMessage[Parameters.Parameter].ToString()); } catch { }

            // Picture comparison
            if (File.Exists((string)SendMessage["SavePath"]))
            {
                Image FullScreen = FuncClass.OperateImage((string)SendMessage["SavePath"]);

                Image SmallPic = FuncClass.OperateImage((string)FDic["PicturePath"]);

                dll_opencv.OpenCV openCV = new dll_opencv.OpenCV();
                openCV.SourceLoadImage(FullScreen);
                openCV.SourceToGray();
                openCV.MatchLoadImage(SmallPic);
                openCV.MatchToGray();
                dll_opencv.OpenCV.MatchDataList matchDataList = openCV.GetMatchPos(Parameters.Confidential, false);

                double resultConfident = matchDataList.MaxConfidencevalue;
                Thread.Sleep(50);
                // Delete NowImage in case of wrong time
                FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
                if (resultConfident < Parameters.Confidential)
                {
                    MainResultArray[Parameters.Status] = "Pass";
                    MainResultArray[Parameters.Remark] = "Didn't find the title icon.";
                }
                else
                {
                    bool socketResult = false;
                    MainResultArray[Parameters.Status] = "Pass";
                    do
                    {
                        SendMessage[Parameters.Behavior] = Behavior.Send_Enter;
                        // Send to server
                        main.ConnectNet(dll_PublicFuntion.Other.DictionaryToXml(SendMessage), TotalStepCount, sheet, GroupName, ExcelStepCounter, ref socketResult, Behavior.Send_Enter);
                        dll_PublicFuntion.Other.Wait(1.5);
                    } while (SocketDataCheck == 1);

                    if (socketResult == false)
                    {
                        MainResultArray[Parameters.Status] = "Fail";
                        MainResultArray[Parameters.Remark] = halfSocketRemark;
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 一般螢幕圖片比對
        /// </summary>
        public static void Normal_ScreenCheck(Image SmallPicture, ref Dictionary <string, object> ResultArray)
        {
            ResultArray["Status"] = "Pass";

            // Screen shot
            try
            {
                if (Parameters.bmpScreenshot != null)
                {
                    Parameters.bmpScreenshot.Dispose();
                }
                Parameters.bmpScreenshot = new Bitmap(Resolution_.DESKTOP.Width, Resolution_.DESKTOP.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                if (Parameters.gfxScreenshot != null)
                {
                    Parameters.gfxScreenshot.Dispose();
                }
                Parameters.gfxScreenshot = Graphics.FromImage(Parameters.bmpScreenshot);
                Parameters.gfxScreenshot.CopyFromScreen(0, 0, 0, 0, Resolution_.DESKTOP);
                Image BigShot = (Image)Parameters.bmpScreenshot;
                Thread.Sleep(300);

                dll_opencv.OpenCV openCV = new dll_opencv.OpenCV();
                openCV.SourceLoadImage(BigShot);
                openCV.SourceToGray();
                openCV.MatchLoadImage(SmallPicture);
                openCV.MatchToGray();
                dll_opencv.OpenCV.MatchDataList matchDataList = openCV.GetMatchPos(Parameters.Confidential, false);
                double resultConfident = matchDataList.MaxConfidencevalue;
                double ScreenScale     = Resolution_.ScaleX;
                if (resultConfident > Parameters.Confidential)
                {
                    int CursorX = 0;
                    int CursorY = 0;
                    foreach (var item in matchDataList.MatchData)
                    {
                        CursorX = item.Rectangle.X + (item.Rectangle.Width / 2);
                        CursorY = item.Rectangle.Y + (item.Rectangle.Height / 2);
                    }
                    Parameters.Windows.SetCursorPos(Convert.ToInt32(Math.Round(CursorX / ScreenScale, 0)), Convert.ToInt32(Math.Round(CursorY / ScreenScale, 0)));
                    Thread.Sleep(300);

                    ResultArray["Remark"] = "Success";
                }
                else
                {
                    ResultArray["Status"] = "Fail";
                    ResultArray["Remark"] = "No match.";
                }
            }
            catch (Exception ep)
            {
                ResultArray["Status"] = "Fail";
                ResultArray["Remark"] = ep.Message;
            }
        }
Example #3
0
        /// <summary>
        /// 螢幕截圖(框小圖)檢查
        /// </summary>
        /// <param name="SmallPicture"></param>
        /// <param name="ResultArray"></param>
        public static void ErrorMsg_Check(Image SmallPicture, ref Dictionary <string, object> ResultArray)
        {
            UpFrontDVD();
            // Screen shot
            //Parameters.Windows.mouse_event(MOUSEEVENTF_LEFTDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0);
            //Thread.Sleep(20);
            //Parameters.Windows.mouse_event(MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
            //Thread.Sleep(20);
            ResultArray["Status"] = "Pass";

            try
            {
                if (Parameters.bmpScreenshot != null)
                {
                    Parameters.bmpScreenshot.Dispose();
                }
                Parameters.bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                if (Parameters.gfxScreenshot != null)
                {
                    Parameters.gfxScreenshot.Dispose();
                }
                Parameters.gfxScreenshot = Graphics.FromImage(Parameters.bmpScreenshot);
                Parameters.gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                Image BigShot = (Image)Parameters.bmpScreenshot;
                Thread.Sleep(300);
                //Image SmallPic = Image.FromFile(Application.StartupPath + @"\ScreenCut\" + (string)ParameterData["PictureName"] + ".jpg");
                dll_opencv.OpenCV openCV = new dll_opencv.OpenCV();
                openCV.SourceLoadImage(BigShot);
                openCV.SourceToGray();
                openCV.MatchLoadImage(SmallPicture);
                openCV.MatchToGray();
                dll_opencv.OpenCV.MatchDataList matchDataList = openCV.GetMatchPos(Parameters.Confidential, false);

                double resultConfident = matchDataList.MaxConfidencevalue;
                // Get screen scale percent
                double ScreenScale = Resolution_.ScaleX;
                if (resultConfident > Parameters.Confidential)
                {
                    double CursorX = 0;
                    double CursorY = 0;
                    foreach (var item in matchDataList.MatchData)
                    {
                        CursorX = item.Rectangle.X + (item.Rectangle.Width / 2);
                        CursorY = item.Rectangle.Y + (item.Rectangle.Height / 2);
                    }
                    Parameters.Windows.SetCursorPos(Convert.ToInt32(Math.Round(CursorX / ScreenScale, 0)), Convert.ToInt32(Math.Round(CursorY / ScreenScale, 0)));
                    Thread.Sleep(2000);
                    ResultArray["Remark"] = "OnCancel";
                }
                else
                {
                    ResultArray["Status"] = "Fail";
                    ResultArray["Remark"] = "No match.";
                }
            }
            catch (Exception ep)
            {
                ResultArray["Status"] = "Fail";
                ResultArray["Remark"] = ep.Message;
            }
        }
Example #4
0
        /// <summary>
        /// PowerDVD 是否播放中
        /// </summary>
        /// <param name="SendMessage"></param>
        /// <param name="MainResultArray"></param>
        /// <param name="SendString"></param>
        /// <param name="GroupName"></param>
        /// <param name="ExcelStepCounter"></param>
        /// <param name="TotalStepCount"></param>
        /// <param name="sheet"></param>
        /// <param name="SocketDataCheck"></param>
        /// <param name="halfSocketRemark"></param>
        /// <param name="AnswerDic"></param>
        public static void Movie_Play_Check(ref Dictionary <string, object> SendMessage, ref Dictionary <string, object> MainResultArray, ref string SendString, string GroupName, ref int ExcelStepCounter, ref int TotalStepCount, ref ISheet sheet, ref int SocketDataCheck, ref string halfSocketRemark, ref Dictionary <string, object> AnswerDic)
        {
            FuncClass.IdsStatus();
            bool socketResult = false;
            // Socket send data
            Dictionary <string, object> SendMessageMovie = new Dictionary <string, object>
            {
                { Parameters.Group, GroupName },
                { Parameters.Behavior, Behavior.Movie_Play_Check },
                { Parameters.Necessary, "" },
                { Parameters.Parameter, "" },
                { Parameters.ServerIP, Parameters.ip },
                { Parameters.Answer, dll_PublicFuntion.Other.DictionaryToXml(AnswerDic) },
            };

            // Parameter => IconName / PicturePath / Wait
            Dictionary <string, object> FDic = new Dictionary <string, object>();

            try { FDic = dll_PublicFuntion.Other.XmlToDictionary(SendMessage[Parameters.Parameter].ToString()); } catch { }

            // Loop five times, break until success
            for (int i = 0; i < 5; i++)
            {
                MainResultArray[Parameters.Remark] = "";
                // Add save path to dictionary at first time
                if (i == 0)
                {
                    SendMessageMovie.Add("SavePath", dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
                    try { SendString = dll_PublicFuntion.Other.DictionaryToXml(SendMessageMovie); } catch { }
                }

                do
                {
                    // Send to server
                    main.ConnectNet(dll_PublicFuntion.Other.DictionaryToXml(SendMessageMovie), TotalStepCount, sheet, GroupName, ExcelStepCounter, ref socketResult, Behavior.Movie_Play_Check);
                    dll_PublicFuntion.Other.Wait(1.5);
                } while (SocketDataCheck == 1);

                if (!socketResult)
                {
                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = "Can't find powerDVD.";
                    break;
                }

                // take a picture
                FuncClass.IDS_Check(SendMessageMovie, ref MainResultArray, true);

                Thread.Sleep(200);

                if (!File.Exists((string)SendMessageMovie["SavePath"]))
                {
                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = "IDS connect error.";
                    break;
                }


                // Picture comparison
                if (File.Exists((string)SendMessageMovie["SavePath"]) && socketResult)
                {
                    Image FullScreen = FuncClass.OperateImage((string)SendMessageMovie["SavePath"]);

                    Image SmallPic = FuncClass.OperateImage((string)FDic["PicturePath"]);

                    dll_opencv.OpenCV openCV = new dll_opencv.OpenCV();
                    openCV.SourceLoadImage(FullScreen);
                    openCV.SourceToGray();
                    openCV.MatchLoadImage(SmallPic);
                    openCV.MatchToGray();
                    dll_opencv.OpenCV.MatchDataList matchDataList = openCV.GetMatchPos(Parameters.Confidential, false);

                    double resultConfident = matchDataList.MaxConfidencevalue;
                    Thread.Sleep(50);

                    // Delete NowImage in case of wrong time
                    FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");

                    if (resultConfident < Parameters.Confidential)
                    {
                        MainResultArray[Parameters.Status] = "Fail";
                        MainResultArray[Parameters.Remark] = "No match.";
                    }
                    else
                    {
                        MainResultArray[Parameters.Status] = "Pass";
                        break;
                    }
                }
            }
            if ((string)MainResultArray[Parameters.Status] == "Fail")
            {
                // Socket send data
                Dictionary <string, object> SendMessageRestart = new Dictionary <string, object>
                {
                    { Parameters.Group, GroupName },
                    { Parameters.Behavior, Behavior.DVD_Restart },
                    { Parameters.Necessary, "" },
                    { Parameters.Parameter, "" },
                    { Parameters.ServerIP, Parameters.ip },
                    { Parameters.Answer, "" },
                };
                do
                {
                    // Send to server
                    main.ConnectNet(dll_PublicFuntion.Other.DictionaryToXml(SendMessageRestart), TotalStepCount, sheet, GroupName, ExcelStepCounter, ref socketResult, Behavior.DVD_Restart);
                    dll_PublicFuntion.Other.Wait(1.5);
                } while (SocketDataCheck == 1);
                if (socketResult == false)
                {
                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = halfSocketRemark;
                }
                WaitTime(ref SendMessage);
            }
        }