예제 #1
0
        private void o2MessageQueue_onMessages(IO2Message o2Message)
        {
            //first thing to do is to make sure we are on the correct thread
            if (InvokeRequired)
            {
                Invoke(new EventHandler(delegate { o2MessageQueue_onMessages(o2Message); }));
            }
            else
            {
                if (o2Message is IM_GUIAction)
                {
                    var mGuiAction = (IM_GUIAction)o2Message;
                    PublicDI.log.info("O2GuiWithDockPanel received IM_GUIAction of action: {0}", mGuiAction.GuiAction);
                    switch (mGuiAction.GuiAction)
                    {
                    case (IM_GUIActions.openControlInGui):
                        O2DockPanel.loadControl(mGuiAction.controlType, mGuiAction.o2DockState,
                                                mGuiAction.controlName);
                        break;

                    case (IM_GUIActions.setAscxDockStateAndOpenIfNotAvailable):
                        // if setDockState fails is because the control is not loaded
                        if (false == O2DockUtils.setDockState(mGuiAction.controlName, mGuiAction.o2DockState))
                        {
                            O2AscxGUI.openAscxASync(mGuiAction.controlTypeString, mGuiAction.o2DockState, mGuiAction.controlName);
                        }
                        break;
                    }
                    return;
                }
            }
        }
예제 #2
0
        public static O2DockContent addAscxControlToO2GuiWithDockPanelWithDockState(Type ascxControlToLoad,
                                                                                    DockState dockState,
                                                                                    String name, bool showControl)
        {
            if (O2AscxGUI.o2GuiWithDockPanel == null)
            {
                PublicDI.log.error(" in addAscxControlToO2GuiWithDockPanelWithDockState o2GuiWithDockPanel was null, so aborting load of {0}", ascxControlToLoad.FullName);
                return(null);
            }
            var o2DocContent = new O2DockContent(ascxControlToLoad, dockState, name);

            // add it as soon as possible to this list (in case there is a request for it from another thread)
            O2DockUtils.addO2DockContentToDIGlobalVar(o2DocContent);

            if (showControl)
            {
                //add content to DockPanel (in a thread safe way)
                showO2DockContentInDockPanel(o2DocContent);


                // wait for control to be loaded
                if (false == DebugMsg.IsDebuggerAttached())
                {
                    o2DocContent.controlLoadedIntoGui.WaitOne();
                }
                else if (false == o2DocContent.controlLoadedIntoGui.WaitOne(10000))
                {
                    PublicDI.log.error("Failed to load control {0} in 10 sec", o2DocContent.name);
                }
            }
            return(o2DocContent);
        }
        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);
                }
            }
        }
        public static Control loadControl(Type ascxControlToLoad, O2DockState dockState, String name)
        {
            var o2DockContent = addAscxControlToO2GuiWithDockPanelWithDockState(
                ascxControlToLoad, O2DockUtils.getDockStateFromO2DockState(dockState), name);

            if (o2DockContent != null)
            {
                return(o2DockContent.control);
            }

            return(null);
        }
 public static Control getAscx(string name, bool logErrorOnFail)
 {
     if (O2AscxGUI.dO2LoadedO2DockContent.ContainsKey(name))
     {
         var o2DockContent = O2DockUtils.getO2DockContent(name);
         o2DockContent.dockContent.invokeOnThread(() => o2DockContent.dockContent.Activate());
         return(o2DockContent.control);
     }
     if (logErrorOnFail)
     {
         PublicDI.log.error("in O2DockUtils.getAscx, could not find registed Ascx: {0}", name);
     }
     return(null);
 }
        private static void addControlToO2GuiWithDockPanelSync(O2GuiWithDockPanel o2GuiWithDockPanel, O2DockContent controlToAdd, EventWaitHandle controlAdded)
        {
            //if (controlToAdd.dockContent != null && controlToAdd.dockContent.okThread(
            //    delegate { addControlToO2GuiWithDockPanelSync(controlToAdd, controlAdded); }))
            //{

            //var sync = new AutoResetEvent(false);

            // add the control on the o2GuiThread
            //O2AscxGUI.o2GuiWithDockPanel.Invoke(new EventHandler(delegate {
            try
            {
                if (controlToAdd.createControlFromType())
                {
                    controlToAdd.dockContent.Show(o2GuiWithDockPanel.getDockPanel(), controlToAdd.dockState);

                    if (controlToAdd.dockState == DockState.Float && controlToAdd.dockContent.TopLevelControl != null)
                    {
                        controlToAdd.dockContent.TopLevelControl.Width  = controlToAdd.desiredWidth;
                        controlToAdd.dockContent.TopLevelControl.Height = controlToAdd.desiredHeight;
                    }
                    if (controlToAdd.dockState == DockState.Document)
                    {
                        if (O2AscxGUI.o2GuiWithDockPanel.Width < controlToAdd.desiredWidth)
                        {
                            O2AscxGUI.o2GuiWithDockPanel.Width = controlToAdd.desiredWidth + 10;
                        }
                        if (O2AscxGUI.o2GuiWithDockPanel.Height < controlToAdd.desiredHeight + 100)
                        {
                            O2AscxGUI.o2GuiWithDockPanel.Height = controlToAdd.desiredHeight + 100;
                        }
                    }
                    O2DockUtils.addO2DockContentToDIGlobalVar(controlToAdd);
                }
            }
            catch (Exception ex)
            {
                PublicDI.log.ex(ex, "in addControlToO2GuiWithDockPanelSync");
            }

            controlAdded.Set();
            //                                                 }));
            //}
            //controlAdded.WaitOne();
        }
예제 #7
0
 public static void addControlToMenu(Type ascxControlToLoad, O2DockState dockState, String guiWindowName)
 {
     O2DockPanel.addAscxControlToO2GuiWithDockPanelWithDockState(ascxControlToLoad, O2DockUtils.getDockStateFromO2DockState(dockState), guiWindowName, false);
 }
예제 #8
0
 public static bool isAscxLoaded(string ascxControlName)
 {
     return(O2DockUtils.getAscx(ascxControlName) != null);
 }
예제 #9
0
 public static Control getAscx(string ascxControlName)
 {
     return(O2DockUtils.getAscx(ascxControlName));
 }
예제 #10
0
 public static void setLogViewerDockState(O2DockState o2DockState)
 {
     O2DockUtils.setDockContentState(PublicDI.LogViewerControlName, o2DockState);
 }
        private static void o2MessageQueue_onMessages(IO2Message o2Message)
        {
            try
            {
                if (o2Message is IM_GUIAction)
                {
                    var mGuiAction = (IM_GUIAction)o2Message;
                    PublicDI.log.info("O2GuiWithDockPanel received IM_GUIAction of action: {0}", mGuiAction.GuiAction);
                    switch (mGuiAction.GuiAction)
                    {
                    case IM_GUIActions.isAscxGuiAvailable:
                        isAscxGuiAvailable();
                        break;

                    //   case (IM_GUIActions.openControlInGui): // don't handle these here
                    case IM_GUIActions.getGuiAscx:
                        if (mGuiAction.returnDataCallback != null)
                        {
                            mGuiAction.returnDataCallback(O2DockUtils.getAscx(mGuiAction.controlName));
                        }
                        break;

                    case IM_GUIActions.executeOnAscx:
                        if (mGuiAction.controlName == null || mGuiAction.targetMethod == null ||
                            mGuiAction.methodParameters == null)
                        {
                            PublicDI.log.error(
                                "in O2Environment.O2MessagesHandler.o2MessageQueue_onMessages received a O2Message for IM_GUIActions.executeOnAscx, but either the targetMethod or methodParameters are null");
                        }
                        else
                        {
                            var ascxControlToExecute = O2AscxGUI.getAscx(mGuiAction.controlName);
                            if (ascxControlToExecute == null)
                            {
                                PublicDI.log.error(
                                    "in O2MessagesHandler...IM_GUIActions.executeOnAscx, could not get control: {0}",
                                    mGuiAction.controlName);
                            }
                            else
                            {
                                o2Message.returnData = PublicDI.reflection.invoke(ascxControlToExecute,
                                                                                  mGuiAction.targetMethod,
                                                                                  mGuiAction.methodParameters);
                            }
                        }
                        break;

                    case IM_GUIActions.closeAscxParent:
                        O2AscxGUI.closeAscxParent(mGuiAction.controlName);
                        break;

                    case IM_GUIActions.openControlInGui:                // this is a special case since we should only handle this if the main GUI is not loaded
                        if (false == O2AscxGUI.isGuiLoaded())           // this tends to happen on Unit tests where we only have one control loaded
                        {
                            // and if the Gui is not loaded open this control as a stand alone FORM
                            O2AscxGUI.openAscxAsForm(mGuiAction.controlType, mGuiAction.controlName);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                PublicDI.log.ex(ex, " in O2MessagesHandler.o2MessageQueue_onMessages");
            }
        }
 private void GenericDockContent_FormClosing(object sender, FormClosingEventArgs e)
 {
     O2DockUtils.removeO2DockContentFromDIGlobalVar(Text);  // remove the control hosted by by this
 }