public void syncO2ViaSvn()
        {
            O2Thread.mtaThread(() =>
            {
                try
                {
                    showInfo("Updating Scripts via SVN");
                    if (is32Bit())
                    {
                        "32bit mode, sync using SvnClient".info();
                        SvnApi.SyncLocalFolderWithO2XRulesDatabase();
                    }
                    else
                    {
                        "64bit mode, sync using http svn access".info();
                        if (("Do you want to update the SVN rules via HTTP? ".line() + "(You are not running on a 32 bit box, so the built-in 32bit SvnClient can not be used)").askUserQuestion())
                        {
                            O2Thread.staThread(
                                () => new Wizard_SyncViaSvn().runWizard().Join())
                            .Join();
                        }
                    }
                    showInfo("SVN XRules updated Update completed");
                    1000.sleep();
                }
                catch (Exception ex)
                {
                    ex.log("in syncO2ViaSvn");
                }

                showInfo(welcomeMessage);
                svnSyncComplete.Set();
            });
            //new Wizard_SyncXRulesViaSvn().runWizard();
        }
示例#2
0
        public static bool launch(string parentFormTitle)
        {
            try
            {
                if (isGuiLoaded())
                {
                    PublicDI.log.error("There is already a GUI loaded and only one can be loaded");
                    return(false);
                }
                parentFormTitle = ClickOnceDeployment.getFormTitle_forClickOnce(parentFormTitle);
                //new O2DockPanel();

                O2Thread.staThread(() => new O2DockPanel());

                var maxTimeToWaitForGuiCreation = 20000;
                if (O2DockPanel.guiLoaded.WaitOne(maxTimeToWaitForGuiCreation))
                {
                    O2AscxGUI.o2GuiWithDockPanel.invokeOnThread(() => O2AscxGUI.o2GuiWithDockPanel.Text = parentFormTitle);
                    return(true);
                }
                if (false == DebugMsg.IsDebuggerAttached())
                {
                    //PublicDI.log.reportCriticalErrorToO2Developers(null, null, "from O2AscxGUI: GUI was not available after 20 seconds");
                    PublicDI.log.error("from O2AscxGUI: GUI was not available after 20 seconds");
                }
                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#3
0
        public static Form showDialog(this Form form, bool useNewStaThread = true)
        {
            if (form.notNull())
            {
                var controlCreation = new AutoResetEvent(false);

                form.Load += (sender, e) =>
                {
                    controlCreation.Set();
                };

                if (useNewStaThread)
                {
                    O2Thread.staThread(() =>
                    {
                        form.ShowDialog();
                    });
                }
                else
                {
                    form.ShowDialog();
                }

                var maxTimeOut = Debugger.IsAttached ? -1 : 20000;

                if (controlCreation.WaitOne(maxTimeOut).failed())
                {
                    "[Form][showDialog] Something went wrong with the creation of the form since it took more than 20s to start".error();
                }
            }
            return(form);
        }
        public static Bitmap getScreenshot(string url, int width_Browser, int height_Browser,
                                           int width_Bitmap, int height_Bitmap)
        {
            Bitmap bitmap = null;
            var    thread = O2Thread.staThread(
                () =>
            {
                var browser            = new O2BrowserIE_Screenshot();
                browser.Width_Browser  = width_Browser;
                browser.Height_Browser = height_Browser;
                browser.Width_Bitmap   = width_Bitmap;
                browser.Height_Bitmap  = height_Bitmap;

                browser.fetchWebPage(url);
                bitmap = browser.GetBitmap();
            });
            var result = thread.Join(wait);

            if (result.isFalse())
            {
                "thread result: {0}".format(result).debug();
            }
            if (bitmap == null)
            {
                "in O2BrowserIE_Screenshot.getScreenshot, failed to get screenshot for: {0}".format(url).error();
            }
            return(bitmap);
        }
        public WatiN_IE createIEObject(string url, int top, int left, int width, int height)
        {
            IEThread = O2Thread.staThread(
                () => {
                "launching a new WatIN InternetExplorer Process".info();
                try
                {
                    if (url.valid().isFalse())
                    {
                        url = "about:blank";
                    }
                    Settings.MakeNewIeInstanceVisible = false;
                    IE = new IE(url);
                    InternetExplorer         = (InternetExplorerClass)IE.InternetExplorer;
                    InternetExplorer.Top     = top;
                    InternetExplorer.Left    = left;
                    InternetExplorer.Width   = width;
                    InternetExplorer.Height  = height;
                    InternetExplorer.Visible = true;

                    InternetExplorer.OnQuit += close;
                    WaitForIELaunch.Set();
                    WaitForIEClose.WaitOne();
                }
                catch (Exception ex)
                {
                    ex.log("in WatiN_IE createIEObject");
                    WaitForIELaunch.Set();
                    WaitForIEClose.Set();
                }
            });
            WaitForIELaunch.WaitOne();
            return(this);
        }
        public void createTestForm()
        {
            o2Reflector = new ascx_O2Reflector {
                Dock = DockStyle.Fill
            };
            hostForm = new Form {
                Width = o2Reflector.Width, Height = o2Reflector.Height
            };
            hostForm.Controls.Add(o2Reflector);

            Assert.That(o2Reflector != null, "o2Reflector was null");
            Assert.That(hostForm != null, "hostForm was null");
            Assert.That(hostForm.Controls.Contains(o2Reflector), "hostForm didn't contain o2Reflector");

            // Inject dependency

            /*O2.Views.Controlers.DI.cecilUtils = new CecilUtils();
             * O2.Views.Controlers.DI.cecilDecompiler = new CecilDecompiler();
             * O2.Views.Controlers.DI.cecilASCX = new CecilASCX();
             * O2.Views.Controlers.DI.reflectionASCX = new O2FormsReflectionASCX();
             *
             * O2.Views.ASCX.DI.assemblyAnalysis = new AssemblyAnalysis();*/
            // Load form
            O2Thread.staThread(() => hostForm.ShowDialog());
        }
        public static object executeFirstMethod(this Assembly assembly, bool executeInStaThread, bool executeInMtaThread, object[] parameters)
        {
            if (assembly != null)
            {
                var methods = assembly.methods();
                foreach (var method in methods)
                {
                    if (method.IsSpecialName == false && method.IsPublic)  // we need to do this since Properties get_ and set_ also look like methods
                    //if (methods.Count >0)
                    //{
                    {
                        MethodInfo method1 = method;
                        if (executeInStaThread)
                        {
                            return(O2Thread.staThread(() => method1.executeMethod(parameters)));
                        }
                        if (executeInMtaThread)
                        {
                            return(O2Thread.mtaThread(() => method1.executeMethod(parameters)));
                        }

                        return(method.executeMethod(parameters));
                    }
                }
            }
            return(null);
        }
        public static void launchO2DockContentAsStandAloneForm(Type typeOfControlToLoad, string controlName)
        {
            if (typeOfControlToLoad == null)
            {
                PublicDI.log.error("in launchO2DockContentAsStandAloneForm typeOfControlToLoad was null");
            }
            else
            {
                try
                {
                    var sync = new AutoResetEvent(false);
                    O2Thread.staThread(() =>
                    {
                        try
                        {
                            O2AscxGUI.o2GuiStandAloneFormMode = true;
                            //var controlToLoad = (Control) Activator.CreateInstance(typeOfControlToLoad);
                            // if (typeOfControlToLoad != null)
                            // {
                            var o2DockContent = new O2DockContent(typeOfControlToLoad, DockState.Float, controlName);
                            o2DockContent.dockContent.HandleCreated += (sender, e) => sync.Set();
                            // as soons as the control HandleCreated is created, we can let this function (launchO2DockContentAsStandAloneForm end)
                            if (o2DockContent.createControlFromType())
                            {
                                o2DockContent.dockContent.Width  = o2DockContent.desiredWidth;
                                o2DockContent.dockContent.Height = o2DockContent.desiredHeight;
                                O2DockUtils.addO2DockContentToDIGlobalVar(o2DockContent);
                                o2DockContent.dockContent.Closed += (sender, e) =>
                                {
                                    if (O2AscxGUI.dO2LoadedO2DockContent.Count == 0)                                                                 // if there are no more controls trigger the end of the GUI session
                                    {
                                        O2AscxGUI.guiClosed.Set();
                                    }
                                };

                                o2DockContent.dockContent.ShowDialog();
                            }
                            else
                            {
                                PublicDI.log.error(
                                    "in launchO2DockContentAsStandAloneForm, could not create instance of controlToLoad: {0}",
                                    typeOfControlToLoad.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            PublicDI.log.ex(ex, "in launchO2DockContentAsStandAloneForm");
                        }
                        sync.Set();
                    });
                    sync.WaitOne();
                }
                catch (Exception ex)
                {
                    PublicDI.log.ex(ex);
                }
            }
        }
示例#9
0
 public static void startAppScan()
 {
     O2Thread.staThread(
         () => {
         "AppScan.exe".assembly()
         .type("MainForm")
         .method("Main").invoke(new object[] { new string[] {} });
     });
 }
示例#10
0
        public static WatiN_IE eval(this WatiN_IE ie, string script, bool waitForExecutionComplete)
        {
            var executionThread = O2Thread.staThread(() => ie.IE.RunScript(script));

            if (waitForExecutionComplete)
            {
                executionThread.Join();
            }
            return(ie);
        }
 public void showDialog(bool useNewStaThread)
 {
     if (useNewStaThread)
     {
         O2Thread.staThread(() => ShowDialog());
     }
     else
     {
         ShowDialog();
     }
     //formLoaded.WaitOne();
 }
 public static RibbonGroup add_Button_Open_Folder(this RibbonGroup ribbonGroup, string label, Action <string> onValidFolder)
 {
     return(ribbonGroup.add_Button_WithSmallImage(label, "Open_16x16.png",
                                                  () => O2Thread.staThread(
                                                      () => {
         var folder = O2Forms.askUserForDirectory("Choose Folder With Images To load");
         if (folder.valid() && folder.dirExists())
         {
             onValidFolder(folder);
         }
     })
                                                  ));
 }
示例#13
0
 public static void  showGui(Form form)
 {
     O2Thread.staThread(
         () => {
         var rpReportBug         = new ReportBug();
         rpReportBug.fParentForm = form;;
         rpReportBug.setFromEmail("*****@*****.**");
         rpReportBug.setSubject("[Comment from O2 user] ");
         rpReportBug.setMessage(Mail.getUserDetailsAsEmailFormat() + " says:" + Environment.NewLine +
                                "Hello O2 Support, " + Environment.NewLine + Environment.NewLine);
         rpReportBug.ShowDialog();
     });
 }
        public static string    clipboardText_Set(this string newClipboardText)
        {
            var sync = new AutoResetEvent(false);

            O2Thread.staThread(
                () =>
            {
                O2Forms.setClipboardText(newClipboardText);
                sync.Set();
            });
            sync.WaitOne(2000);
            return(newClipboardText);
        }
        //static for the cases where we have no live Control to get the STA thread from
        public static Bitmap captureSta(int x, int y, int width, int height)
        {
            Bitmap bitmap = null;
            var    sync   = new AutoResetEvent(false);

            O2Thread.staThread(
                () => {
                bitmap = new API_Cropper().capture(x, y, width, height);
                sync.Set();
            });
            sync.WaitOne();
            return(bitmap);
        }
示例#16
0
 public static WatiN_IE testRecorder(this WatiN_IE watinIe, bool executeInNewProcess)
 {
     if (executeInNewProcess)
     {
         Processes.startProcess("Test Recorder");
     }
     else
     {
         O2Thread.staThread(() => { "Test Recorder".assembly()
                                    .type("Program")
                                    .invokeStatic("Main", new string[] {}); });
     }
     return(watinIe);
 }
示例#17
0
        /// <summary>
        ///  opens ascx control (Sync mode)
        /// </summary>
        /// <param name="ascxControlToLoad"></param>
        /// <param name="dockState"></param>
        /// <param name="guiWindowName"></param>
        public static Control openAscx(Type ascxControlToLoad, O2DockState dockState, String guiWindowName)
        {
            Control ascxControl = null;
            var     sync        = new AutoResetEvent(false);

            O2Thread.staThread(() =>
            {
                ascxControl = O2DockPanel.loadControl(ascxControlToLoad, dockState, guiWindowName);
                sync.Set();
            });
            sync.WaitOne();

            return(ascxControl);
        }
        public static string    clipboardText_Get(this object _object)
        {
            var    sync          = new AutoResetEvent(false);
            string clipboardText = null;

            O2Thread.staThread(
                () =>
            {
                clipboardText = O2Forms.getClipboardText();
                sync.Set();
            });
            sync.WaitOne(2000);
            return(clipboardText);
        }
示例#19
0
        public static T     openForm <T>(this string textToAppendToFormTitle) where T : Form
        {
            T form = null;

            O2Thread.staThread(
                () =>
            {
                form       = (T)typeof(T).ctor();
                form.Text += textToAppendToFormTitle.valid() ? " - {0}".format(textToAppendToFormTitle) : "";
                form.ShowDialog();
            });
            MiscUtils.waitForNotNull(ref form);
            return(form);
        }
示例#20
0
        public static Thread runWizardWithSteps(List <IStep> steps, string wizardName, int width, int height, Action <WizardController, WizardController.WizardResult> onCompletion)
        {
            // this needs to run on an STA thread because some controls might require Drag & Drop support

            return(O2Thread.staThread(
                       () => {
                WizardController wizardController = new WizardController(steps);
                //wizardController.LogoImage = Resources.NerlimWizardHeader;
                var wizardResult = wizardController.StartWizard(wizardName, true, null, width, height);
                if (onCompletion != null)
                {
                    onCompletion(wizardController, wizardResult);
                }
            }));
        }
示例#21
0
        //return API_MiniFramework.askQuestion("title","subTitle");

        public static string askQuestion(string title, string subTitle)
        {
            var sync   = new AutoResetEvent(false);
            var result = "";

            O2Thread.staThread(
                () => {
                var inputDialog             = new InputDialog();
                inputDialog.InstructionText = title;
                inputDialog.Text            = subTitle;
                result = inputDialog.GetText();
                sync.Set();
            });
            sync.WaitOne();
            return(result);
        }
        public static NUnitForm nUnitGui_ShowGui(this API_NUnit_Gui nUnitGui, GuiOptions guiOptions)
        {
            "[API_NUnit_Gui] in nUnitGui_ShowGui".info();
            Func <NUnitForm> createNUnitForm =
                () => {
                var       sync      = new AutoResetEvent(false);
                NUnitForm nUnitForm = null;
                O2Thread.staThread(
                    () => {
                    if (NUnit.Util.Services.TestAgency.isNull())
                    {
                        var nunitGuiRunner = nUnitGui.Executable.parentFolder().pathCombine("lib\\nunit-gui-runner.dll");
                        nunitGuiRunner.loadAssemblyAndAllItsDependencies();

                        SettingsService settingsService = new SettingsService();
                        InternalTrace.Initialize("nunit-gui_%p.log", (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default));
                        ServiceManager.Services.AddService(settingsService);
                        ServiceManager.Services.AddService(new DomainManager());
                        ServiceManager.Services.AddService(new RecentFilesService());
                        ServiceManager.Services.AddService(new ProjectService());
                        ServiceManager.Services.AddService(new AddinRegistry());
                        ServiceManager.Services.AddService(new AddinManager());
                        ServiceManager.Services.AddService(new TestAgency());
                        ServiceManager.Services.InitializeServices();
                    }
                    else
                    {
                        "[API_NUnit_Gui] in nUnitGui_ShowGui: NUnit.Util.Services.TestAgency was not null: {0}".debug(NUnit.Util.Services.TestAgency);
                    }

                    ServiceManager.Services.AddService(new TestLoader(new GuiTestEventDispatcher()));
                    nUnitForm = new NUnitForm(guiOptions);
                    "NUnitForm".o2Cache(nUnitForm);
                    sync.Set();
                    nUnitForm.ShowDialog();
                    "NUnitForm".o2Cache(null);
                });
                sync.WaitOne();
                return(nUnitForm);
            };

            return("NUnitForm".o2Cache(createNUnitForm));
        }
示例#23
0
        public WatiN_IE attachTo(InternetExplorer ieInstanceToAttach)
        {
            IEThread = O2Thread.staThread(
                () => {
                try
                {
                    //WatiN.Core.Settings.AutoStartDialogWatcher = false;

                    WaitForIEClose.Reset();
                    "attaching to IE with LocationName '{0}'".info(ieInstanceToAttach.LocationName);

                    IE = new IE(ieInstanceToAttach);

                    //this doesn't work on external processes attach
                    //InternetExplorer = (SHDocVw.InternetExplorerClass)IE.InternetExplorer;

                    (ieInstanceToAttach as DWebBrowserEvents2_Event).OnQuit +=
                        () =>
                    {
                        //"ON WatiN_IE attachTo Quit EVENT".debug();
                        close();
                    };

                    WaitForIELaunch.Set();

                    WaitForIEClose.WaitOne();
                    //"AFTER WaitForIEClose".error();
                }
                catch (Exception ex)
                {
                    ex.log("in attachTo(InternetExplorer)", true);
                    WaitForIELaunch.Set();
                    WaitForIEClose.Set();
                }
            });
            //"before WaitForIELaunch".error();
            WaitForIELaunch.WaitOne();
            //"after WaitForIELaunch".error();
            return(this);
        }
        public static string    saveImageFromClipboard(this object _object)
        {
            var    sync       = new AutoResetEvent(false);
            string savedImage = null;

            O2Thread.staThread(
                () =>
            {
                var bitmap = new Control().fromClipboardGetImage();
                if (bitmap.notNull())
                {
                    savedImage = bitmap.save();
                    savedImage.toClipboard();
                    "Image in clipboard was saved to: {0}".info(savedImage);
                }
                sync.Set();
            });

            sync.WaitOne(2000);

            return(savedImage);
        }
示例#25
0
        //askTask("Message", "DetailsText", , "InstructionText", "Footer")
        public static MessageBoxResult askTask(string message, string detailsText, string instructionText, string footerText)
        {
            var sync = new AutoResetEvent(false);
            MessageBoxResult result = MessageBoxResult.None;

            O2Thread.staThread(
                () => {
                var taskDialog             = new TaskDialog();
                taskDialog.DetailsText     = detailsText;
                taskDialog.FooterImage     = StockIcons.Information.SmallBitmapImage;
                taskDialog.FooterText      = footerText;
                taskDialog.Image           = StockIcons.Information.LargeBitmapImage;
                taskDialog.InstructionText = instructionText;
                taskDialog.Text            = message;
                //TaskDialog dialog = dialog2;
                taskDialog.AddButton("_Accept", MessageBoxResult.Yes, StockIcons.Shield.SmallBitmapImage);
                taskDialog.DefaultButton = taskDialog.AddButton("_Reject", MessageBoxResult.No);
                result = taskDialog.ShowDialog();
                sync.Set();
            });
            sync.WaitOne();
            return(result);
        }
        public static void launchDiagramDesignerGui(bool showLogViewer)
        {
            if (showLogViewer)
            {
                O2Gui.open <ascx_LogViewer>("LogViewer", 400, 200);
            }

            O2Thread.staThread(
                () => {
                "start Sta thread".info();
                Func <System.Windows.Application> createApp =
                    () => {
                    var app             = new DiagramDesigner.App();
                    Uri resourceLocater = new Uri("/DiagramDesigner;component/app.xaml", UriKind.Relative);
                    System.Windows.Application.LoadComponent(app, resourceLocater);
                    return(app);
                };

                var application = System.Windows.Application.Current.isNull()
                                                                                                                ? createApp()
                                                                                                                : System.Windows.Application.Current;
                "WPF Application created".info();
                var window1 = new Window1();
                "DiagramDesigner Main Window created".info();
                //show.info(window1);
                window1.Top    = 10;
                window1.Left   = 10;
                window1.Width  = 700;
                window1.Height = 600;
                "Launching WPF Application".info();
                application.Run(window1);
                "WPF Application ended".info();

                //System.Windows.Application.Current.run
            });
        }
示例#27
0
        public void Test_OpenO2CorLibForm()
        {
            Test_CreateAppDomainWithO2CoreLibDll();
            // do a quick dynamic invocation to confirm that all is OK

            //o2AppDomainFactory.proxyInvokeInstance("O2_CoreLib", "Log", "info", new object[] { "test" });

            Assert.That(
                o2AppDomainFactory.appDomain.FriendlyName ==
                (string)o2AppDomainFactory.proxyInvokeInstance("O2_Kernel", "O2Proxy", "nameOfCurrentDomain"),
                "nameOfCurrentDomain  test failed");


            // get proxy for o2GuiForm
            object o2GuiWithDockPanel = o2AppDomainFactory.proxyInvokeInstance("O2_External_WinFormsUI", "O2GuiWithDockPanel", "");

            Assert.That(o2GuiWithDockPanel != null, "o2GuiWithDockPanel was null");
            Assert.That(o2GuiWithDockPanel.GetType().Name == "O2GuiWithDockPanel",
                        "o2GuiWithDockPanel had the wrong type: " + o2GuiWithDockPanel.GetType());

            if (!autoCloseForm)
            {
                o2AppDomainFactory.showMessageBox("Ready to start?");
            }

            //start o2GuiWithDockPanel on a separate STAthread
            O2Thread.staThread(() => ((Form)o2GuiWithDockPanel).ShowDialog());

            o2AppDomainFactory.proxyInvokeStatic("O2_External_WinFormsUI", "O2GuiWithDockPanel", "logDebug",
                                                 new object[] { "Good Morning you have 10 seconds for your tests" });

            if (!autoCloseForm)
            {
                int maxSleeps = 5;
                while (maxSleeps-- > 0)
                {
                    Thread.Sleep(10000);
                    if (DialogResult.No ==
                        (DialogResult)
                        o2AppDomainFactory.proxyInvokeStatic("O2_External_WinFormsUI", "O2GuiWithDockPanel", "showMessageBox",
                                                             new object[]
                    {
                        "your 10 seconds are up, Do you want another 10 Seconds? (you can ask for more " +
                        maxSleeps + " extensions",
                        "Message from O2 AppDomain Central",
                        MessageBoxButtons.YesNo
                    }))
                    {
                        break;
                    }
                }
                // show final message (using a simpler call syntax :) (using extension methods)
                o2AppDomainFactory.showMessageBox("Time's up closing all Forms", "Final Message", MessageBoxButtons.OK);
            }
            // close Form
            Thread.Sleep(1000);
            ((Form)o2GuiWithDockPanel).Close();
            if (autoCloseForm)
            {
                Assert.Ignore(
                    "Success: change value of autoCloseForm to see some dynamic intercation between this unit test and the O2GuiWithDockPanel form");
            }
            Assert.Ignore(
                "Success: remember to put the value of autoCloseForm to false, or you will have those popups all the time ");
        }
 public static Thread                            invokeStatic_StaThread(this MethodInfo methodInfo, params object[] invocationParameters)
 {
     return(O2Thread.staThread(() => methodInfo.invokeStatic(invocationParameters)));
 }
 private void screenShotTool()
 {
     O2Thread.staThread(Fusion8.Cropper.Program.Main);
 }
 public static void openGui()
 {
     O2Thread.staThread(Program.Main);
 }