public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    MethodClass scopeMethod = context.Instance as MethodClass;
                    if (scopeMethod != null)
                    {
                        //this version only edit FinalActions
                        ILimnorDesignPane dp = scopeMethod.Project.GetTypedData <ILimnorDesignPane>(scopeMethod.RootPointer.ClassId);
                        if (dp != null)
                        {
                            //save the method contents
                            BranchList           bl         = scopeMethod.ActionList;
                            string               methodName = scopeMethod.MethodName;
                            ParameterClass       returnType = scopeMethod.ReturnValue;
                            List <ComponentIcon> icons      = scopeMethod.ComponentIconList;

                            //switch method contents
                            scopeMethod.ActionList = scopeMethod.FinalActions.Actions;
                            scopeMethod.SetName("FinalActions");
                            List <ComponentIcon> icons2 = new List <ComponentIcon>();
                            foreach (ComponentIcon ic in icons)
                            {
                                icons2.Add((ComponentIcon)ic.Clone());
                            }
                            foreach (ComponentIconSubscopeVariable ic in scopeMethod.FinalActions.ComponentIconList)
                            {
                                icons2.Add((ComponentIcon)ic.Clone());
                            }
                            scopeMethod.SetComponentIcons(icons2);
                            //
                            Rectangle rc = new Rectangle(Cursor.Position, new Size(32, 232));
                            if (scopeMethod.Owner == null)
                            {
                                scopeMethod.Owner = dp.Loader.GetRootId();
                            }
                            DlgMethod dlg = scopeMethod.CreateBlockScopeMethodEditor(rc, 1);
                            try
                            {
                                dlg.LoadMethod(scopeMethod, EnumParameterEditType.ReadOnly);
                                dlg.Text = string.Format(CultureInfo.InvariantCulture, "Specify final actionsfor {0}", methodName);
                                if (edSvc.ShowDialog(dlg) == DialogResult.OK)
                                {
                                    scopeMethod.FinalActions.Actions = scopeMethod.ActionList;
                                    List <ComponentIconSubscopeVariable> lst = new List <ComponentIconSubscopeVariable>();
                                    foreach (ComponentIcon ic in scopeMethod.ComponentIconList)
                                    {
                                        ComponentIconSubscopeVariable sv = ic as ComponentIconSubscopeVariable;
                                        if (sv != null)
                                        {
                                            lst.Add(sv);
                                        }
                                    }
                                    scopeMethod.FinalActions.ComponentIconList = lst;
                                    XmlObjectWriter xw = dp.Loader.Writer;
                                    xw.WriteObject(scopeMethod.FinalActions.DataXmlNode, scopeMethod.FinalActions, null);
                                    value = scopeMethod.FinalActions;
                                }
                            }
                            catch (Exception err)
                            {
                                MathNode.LogError(DesignerException.FormExceptionText(err));
                            }
                            finally
                            {
                                //restore method contents
                                scopeMethod.SetName(methodName);
                                scopeMethod.ActionList = bl;
                                scopeMethod.SetComponentIcons(icons);
                                scopeMethod.ExitEditor();
                            }
                        }
                    }
                }
            }
            return(value);
        }
 public void LogErrorFromException(Exception e)
 {
     _currentProject.SetError(DesignerException.FormExceptionText(e));
 }
 private void buttonFolder_Click(object sender, EventArgs e)
 {
     try
     {
         OpenFileDialog dlg = new OpenFileDialog();
         dlg.Title  = "Select Limnor Studio project file";
         dlg.Filter = "Limnor Studio project|*.lrproj";
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             bool        bSelected = false;
             XmlDocument docP      = new XmlDocument();
             docP.PreserveWhitespace = false;
             docP.Load(dlg.FileName);
             if (docP.DocumentElement != null)
             {
                 XmlNode ndNs = docP.DocumentElement.SelectSingleNode("x:PropertyGroup/x:RootNamespace", LimnorProject.GetProjectNamespace());
                 if (ndNs != null)
                 {
                     string ns   = ndNs.InnerText;
                     string sVob = dlg.FileName + ".vob";
                     if (System.IO.File.Exists(sVob))
                     {
                         XmlDocument doc = new XmlDocument();
                         doc.PreserveWhitespace = false;
                         doc.Load(sVob);
                         if (doc.DocumentElement != null)
                         {
                             XmlNodeList ndList = doc.DocumentElement.SelectNodes(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                                                "//{0}/{1}",
                                                                                                XmlTags.XML_WebServiceList, XmlTags.XML_Item));
                             if (ndList != null && ndList.Count > 0)
                             {
                                 List <AsmxURL> list = new List <AsmxURL>();
                                 foreach (XmlNode nd in ndList)
                                 {
                                     string s1 = XmlUtil.GetAttribute(nd, XmlTags.XMLATT_asmxUrl);
                                     if (!string.IsNullOrEmpty(s1))
                                     {
                                         string s0 = XmlUtil.GetAttribute(nd, XmlTags.XMLATT_filename);
                                         list.Add(new AsmxURL(s1, s0, XmlUtil.GetAttribute(nd, XmlTags.XMLATT_proxy), XmlUtil.GetAttribute(nd, XmlTags.XMLATT_wsdl)));
                                     }
                                 }
                                 if (list.Count > 0)
                                 {
                                     _urls      = list;
                                     _prjFile   = dlg.FileName;
                                     _folder    = System.IO.Path.GetDirectoryName(dlg.FileName);
                                     _namespace = ns;
                                     if (string.IsNullOrEmpty(_namespace))
                                     {
                                         _namespace = "LimnorStudio";
                                     }
                                     bSelected = true;
                                 }
                             }
                         }
                     }
                 }
             }
             if (bSelected)
             {
                 textBoxFolder.Text = _prjFile;
                 listBox1.Items.Clear();
                 foreach (AsmxURL a in _urls)
                 {
                     listBox1.Items.Add(a);
                 }
                 if (listBox1.Items.Count > 0)
                 {
                     listBox1.SelectedIndex = 0;
                 }
             }
             else
             {
                 MessageBox.Show(this, "No web services found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
             }
         }
     }
     catch (Exception err)
     {
         MessageBox.Show(this, DesignerException.FormExceptionText(err), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
     }
 }
示例#4
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    ExceptionHandlerList.PropertyDescriptorExceptionHandler pd = context.PropertyDescriptor as ExceptionHandlerList.PropertyDescriptorExceptionHandler;
                    if (pd == null)
                    {
                        throw new DesignerException("Property descriptor [{0}] is not a PropertyDescriptorExceptionHandler", context.PropertyDescriptor == null ? "null" : context.PropertyDescriptor.GetType().FullName);
                    }
                    ExceptionHandler     eh       = pd.Handler;
                    BranchList           branches = eh.ActionList;
                    ExceptionHandlerList ehs      = context.Instance as ExceptionHandlerList;
                    if (ehs != null)
                    {
                        MethodClass scopeMethod = ehs.OwnerMethod;
                        if (scopeMethod != null)
                        {
                            if (branches == null)
                            {
                                branches = new BranchList(eh, new List <ActionBranch>());
                            }

                            ILimnorDesignPane dp = scopeMethod.Project.GetTypedData <ILimnorDesignPane>(scopeMethod.RootPointer.ClassId);
                            if (dp != null)
                            {
                                //save the method contents
                                BranchList           bl         = scopeMethod.ActionList;
                                string               methodName = scopeMethod.MethodName;
                                ParameterClass       returnType = scopeMethod.ReturnValue;
                                List <ComponentIcon> icons      = scopeMethod.ComponentIconList;

                                //switch method contents
                                scopeMethod.ActionList = branches;
                                scopeMethod.SetName(string.Format(CultureInfo.InvariantCulture, "HandlerFor{0}", eh.ExceptionType.Name));
                                scopeMethod.ReturnValue = null;
                                List <ComponentIcon> icons2 = new List <ComponentIcon>();
                                foreach (ComponentIcon ic in icons)
                                {
                                    icons2.Add((ComponentIcon)ic.Clone());
                                }
                                foreach (ComponentIconSubscopeVariable ic in eh.ComponentIconList)
                                {
                                    icons2.Add((ComponentIcon)ic.Clone());
                                }
                                icons2.Add(eh.ExceptionObject);
                                scopeMethod.SetComponentIcons(icons2);
                                //
                                Rectangle rc = new Rectangle(Cursor.Position, new Size(32, 232));
                                if (scopeMethod.Owner == null)
                                {
                                    scopeMethod.Owner = dp.Loader.GetRootId();
                                }
                                DlgMethod dlg = scopeMethod.CreateBlockScopeMethodEditor(rc, eh.ExceptionType.MemberId);
                                try
                                {
                                    dlg.LoadMethod(scopeMethod, EnumParameterEditType.ReadOnly);
                                    dlg.Text = string.Format(CultureInfo.InvariantCulture, "Create exception handler for {0}", eh.ExceptionType.Name);
                                    if (edSvc.ShowDialog(dlg) == DialogResult.OK)
                                    {
                                        bool delete = false;
                                        eh.ActionList = scopeMethod.ActionList;
                                        if (eh.ActionList.Count == 0)
                                        {
                                            if (MessageBox.Show(string.Format(CultureInfo.CurrentUICulture, "Do you want to remove this exception [{0}]?", eh.ExceptionType.Name), "Capture exception", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                            {
                                                delete = true;
                                            }
                                        }
                                        if (delete)
                                        {
                                            scopeMethod.RemoveExceptionCapture(eh);
                                        }
                                        else
                                        {
                                            List <ComponentIconSubscopeVariable> lst = new List <ComponentIconSubscopeVariable>();
                                            foreach (ComponentIcon ic in scopeMethod.ComponentIconList)
                                            {
                                                ComponentIconSubscopeVariable sv = ic as ComponentIconSubscopeVariable;
                                                if (sv != null)
                                                {
                                                    lst.Add(sv);
                                                }
                                            }
                                            eh.ComponentIconList = lst;
                                            scopeMethod.RootPointer.SaveMethod(scopeMethod, eh);
                                        }
                                    }
                                }
                                catch (Exception err)
                                {
                                    MathNode.LogError(DesignerException.FormExceptionText(err));
                                }
                                finally
                                {
                                    //restore method contents
                                    scopeMethod.SetName(methodName);
                                    scopeMethod.ActionList  = bl;
                                    scopeMethod.ReturnValue = returnType;
                                    scopeMethod.SetComponentIcons(icons);
                                    scopeMethod.ExitEditor();
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }