protected override object OnEditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, System.Windows.Forms.Design.IWindowsFormsEditorService service, object value) { IWithProject mc = context.Instance as IWithProject; if (mc != null) { if (mc.Project == null) { MathNode.Log(TraceLogClass.GetForm(provider), new DesignerException("Project not set for {0} [{1}]", mc, mc.GetType())); } else { GetterClass val = value as GetterClass; System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position; rc.X = curPoint.X; rc.Y = curPoint.Y; DlgMethod dlg = val.CreateMethodEditor(rc); try { dlg.SetNameReadOnly(); dlg.LoadMethod(val, EnumParameterEditType.ReadOnly); dlg.Text = val.ToString(); if (service.ShowDialog(dlg) == DialogResult.OK) { value = val; ILimnorDesignerLoader l = LimnorProject.ActiveDesignerLoader as ILimnorDesignerLoader; if (l != null) { //save the property and hence save the getter DesignUtil.SaveCustomProperty(LimnorProject.ActiveDesignerLoader.Node, l.Writer, val.Property); //save actions List <IAction> actions = val.GetActions(); if (actions != null) { foreach (IAction a in actions) { l.GetRootId().SaveAction(a, l.Writer); } } LimnorProject.ActiveDesignerLoader.NotifyChanges(); } } } catch (Exception err) { MathNode.Log(TraceLogClass.GetForm(provider), err); } finally { val.ExitEditor(); } } } return(value); }
public bool Compile(string projectFile, string classFile, string kioskBackgroundName, string rootNamespace, string mSBuildProjectDirectory, string webPhysicalFolder, string outputFullpath, UInt32[] classIds, string[] classNames, string appName, string webJsFolder, string webJavaScriptFolder, string webPhpFolder, string appCodeName, string pluginsFolder, string[] sessionVarNames, string[] sessionVarValues, int sessionTimeoutMinutes, int sessionVarCount, bool webDebugMode, int webClientDebugLevel, int ajaxtimeout, bool debug) { _project = new LimnorProject(projectFile); _rootNamespace = rootNamespace; _outputFullpath = outputFullpath; _classIdList = classIds; _classNames = classNames; _appName = appName; _webJsFolder = webJsFolder; _webPhysicalFolder = webPhysicalFolder; _webJavaScriptFolder = webJavaScriptFolder; _webPhpFolder = webPhpFolder; _appCodeName = appCodeName; _kioskBackgroundName = kioskBackgroundName; _pluginsFolder = pluginsFolder; _sessionVarNames = sessionVarNames; _sessionVarValues = sessionVarValues; _sessionTimeoutMinutes = sessionTimeoutMinutes; _sessionVarCount = sessionVarCount; _webDebugMode = webDebugMode; _webClientDebugLevel = webClientDebugLevel; _ajaxtimeout = ajaxtimeout; XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.Load(classFile); try { Type t = XmlUtil.GetLibTypeAttribute(doc.DocumentElement); _isForm = (typeof(Form).Equals(t) || t.IsSubclassOf(typeof(Form))); if (_project.ProjectType == EnumProjectType.Kiosk) { if (typeof(LimnorKioskApp).Equals(t)) { string bkname = kioskBackgroundName; if (!string.IsNullOrEmpty(bkname)) { XmlNode propNode = doc.DocumentElement.SelectSingleNode(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}[@{1}='BackGroundType']", XmlTags.XML_PROPERTY, XmlTags.XMLATT_NAME)); if (propNode == null) { propNode = doc.CreateElement(XmlTags.XML_PROPERTY); doc.DocumentElement.AppendChild(propNode); } propNode.InnerText = bkname; } } } else if (_project.ProjectType == EnumProjectType.WebAppAspx || _project.ProjectType == EnumProjectType.WebAppPhp) { if (typeof(LimnorWebApp).IsAssignableFrom(t)) { XmlNode wnNode = doc.DocumentElement.SelectSingleNode(string.Format(CultureInfo.InvariantCulture, "{0}[@{1}='WebSiteName']", XmlTags.XML_PROPERTY, XmlTags.XMLATT_NAME)); if (wnNode != null) { string wn = wnNode.InnerText.Trim(); if (wn.StartsWith("$", StringComparison.Ordinal)) { wn = XmlUtil.GetNameAttribute(doc.DocumentElement); if (string.IsNullOrEmpty(wn)) { wn = string.Format(CultureInfo.InvariantCulture, "web_{0}", Guid.NewGuid().ToString("x", CultureInfo.InvariantCulture)); } wnNode.InnerText = wn; doc.Save(classFile); } } } } // LogMessage("Creating handler: {0}", classFile); CodeCompiler cc = new CodeCompiler(this, _project, doc, classFile, rootNamespace, mSBuildProjectDirectory, _appName, _kioskBackgroundName, debug); bool bOK = true; LogMessage("Loading into handler: {0}", cc.ComponentFile); try { bool b = cc.Load(); if (!b) { ArrayList errors = cc.Errors; for (int j = 0; j < errors.Count; j++) { string msg; Exception e = errors[j] as Exception; if (e != null) { msg = TraceLogClass.ExceptionMessage0(e); } else { msg = errors[j].ToString(); } LogError(msg); } bOK = false; } else { _classId = cc.ClassData.ClassId; if (cc.RootObject is LimnorApp) { _isApp = true; } LimnorWebApp wapp = cc.RootObject as LimnorWebApp; if (wapp != null) { FormCompile frm = new FormCompile(); _startWebPageId = wapp.StartPageId; try { bool newName; frm.Show(); VirtualWebDir webSite = wapp.CreateWebSite(frm, out newName); if (webSite != null) { } } catch (Exception err) { LogError("Cannot create website [{0}] for testing purpose. The web application is generated at [{1}]. You may copy the files in that folder to a website to test it. Error message:{2} Stack trace: {3}", wapp.WebSiteName, webPhysicalFolder, err.Message, err.StackTrace); } finally { frm.Close(); frm = null; } } else { IWebPage wp = cc.RootObject as IWebPage; if (wp != null) { _isWebPage = true; _htmlFile = cc.HtmlFile; } } LogMessage("Loaded: {0}", cc.ComponentFile); } } catch (Exception err0) { string msg = TraceLogClass.ExceptionMessage0(err0); LogError(msg); LogMessage("Loading failed for {0}", cc.ComponentFile); bOK = false; } if (bOK) { IList <Guid> l = cc.ClassData.GetDatabaseConnectionsUsed(); if (l.Count > 0) { foreach (Guid g in l) { if (!_databaseConnectionIDs.Contains(g)) { _databaseConnectionIDs.Add(g); } } } if (cc.UsePageNavigator()) { _usePageNavigator = true; } if (cc.UseCopyProtection()) { _useCopyProtection = true; } LogMessage("Compiling {0}", cc.ComponentFile); try { //flush is trigged bool b = cc.GenerateCodeFiles(); if (!b) { ArrayList errors = cc.Errors; for (int j = 0; j < errors.Count; j++) { string msg; Exception e = errors[j] as Exception; if (e != null) { msg = TraceLogClass.ExceptionMessage0(e); } else { msg = errors[j].ToString(); } LogError(msg); } bOK = false; } else { //must do it before cleanup List <IAppConfigConsumer> acs = cc.AppConfigConsumers; if (acs != null && acs.Count > 0) { List <IAppConfigConsumer> appConsumers = new List <IAppConfigConsumer>(); foreach (IAppConfigConsumer ia in acs) { bool bExist = false; foreach (IAppConfigConsumer ia0 in appConsumers) { if (ia0.IsSameConsumer(ia)) { bExist = true; break; } } if (!bExist) { appConsumers.Add(ia); } } if (appConsumers.Count > 0) { CompilerFolders folders = new CompilerFolders(mSBuildProjectDirectory); _appConfigFile = Path.Combine(folders.SourceFolder, "app.config"); XmlDocument appCfg = new XmlDocument(); XmlNode cfgRoot; if (File.Exists(_appConfigFile)) { appCfg.Load(_appConfigFile); } cfgRoot = appCfg.DocumentElement; if (cfgRoot == null) { cfgRoot = appCfg.CreateElement("configuration"); appCfg.AppendChild(cfgRoot); } foreach (IAppConfigConsumer ia in appConsumers) { ia.MergeAppConfig(cfgRoot, _project.ProjectFolder, rootNamespace); } appCfg.Save(_appConfigFile); } } if (cc.UseDatetimePicker) { _usedatetimepicker = true; } LogMessage("Compiled: {0}\r\n", cc.ComponentFile); } } catch (Exception err0) { string msg = TraceLogClass.ExceptionMessage0(err0); LogError(msg); LogMessage("Compiling failed for {0}\r\n", cc.ComponentFile); bOK = false; } finally { cc.Cleanup(); } } else { cc.Cleanup(); } if (bOK) { Dictionary <string, Assembly> assemblyLocations = new Dictionary <string, Assembly>(); cc.FindReferenceLocations(assemblyLocations); foreach (string s in assemblyLocations.Keys) { _assemblyLocations.Add(s); } addAssemblySupportFiles(assemblyLocations); if (cc.IsWebService) { _isWebService = true; } _use32bit = cc.Report32Usage(); if (string.IsNullOrEmpty(_use32bit)) { _use32bit = use32bitAssembly(assemblyLocations); } if (cc.UseResources || cc.UseResourcesX) { LogMessage("Use resources by {0}", cc.ComponentFile); if (_project.ProjectType != EnumProjectType.WebAppPhp) { cc.GenerateResourceFile(); } if (cc.UseResources) { _lstResxFiles.Add(cc.Resources); _useResources = true; } if (cc.UseResourcesX) { _lstResxFiles.Add(cc.ResourcesX); _useResourcesX = true; } } else { LogMessage("Not use resources by {0}", cc.ComponentFile); } _lstSourceFiles.Add(cc.SourceFile); if (cc.UseResourcesX) { _lstSourceFiles.Add(cc.SourceFileX); } if (cc.ResourceFiles != null) { _embededFiles = cc.ResourceFiles; } } if (cc.ObjectType != null) { _assemblyQualifiedTypeName = cc.ObjectType.AssemblyQualifiedName; if (cc.ObjectType.Assembly != null) { _isBaseTypeInGAC = cc.ObjectType.Assembly.GlobalAssemblyCache; _assemblyLocation = cc.ObjectType.Assembly.Location; } } _resourceFile = cc.ResourceFile; _resourceFileX = cc.ResourceFileX; _sourceFile = cc.SourceFile; _sourceFileX = cc.SourceFileX; LogMessage("Finish compiling file :{0}", classFile); return(bOK); } catch (Exception err) { LogError(err); } return(false); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (service != null) { DataTypePointer typeScope = null; ITypeScopeHolder th = context.Instance as ITypeScopeHolder; if (th != null) { typeScope = th.GetTypeScope(context.PropertyDescriptor.Name); } if (typeScope == null) { foreach (Attribute a in context.PropertyDescriptor.Attributes) { TypeScopeAttribute ts = a as TypeScopeAttribute; if (ts != null && ts.Scope != null) { if (ts.Scope.IsGenericParameter) { Type[] ctps = ts.Scope.GetGenericParameterConstraints(); if (ctps != null && ctps.Length > 0) { typeScope = new DataTypePointer(new TypePointer(ctps[0])); break; } } else { typeScope = new DataTypePointer(new TypePointer(ts.Scope)); break; } } } } MethodClass scopeMethod = null; IScopeMethodHolder mh = context.Instance as IScopeMethodHolder; if (mh != null) { scopeMethod = mh.GetScopeMethod(); } IWithProject mc = context.Instance as IWithProject; if (mc == null) { ComponentInterfaceWrapper ciw = context.Instance as ComponentInterfaceWrapper; if (ciw != null) { mc = ciw.Value as IWithProject; } } if (mc == null) { MathNode.Log(TraceLogClass.GetForm(provider), new DesignerException("{0} does not implement IWithProject", context.Instance.GetType())); } else { if (mc.Project == null) { MathNode.Log(TraceLogClass.GetForm(provider), new DesignerException("Project not set for {0} [{1}]", mc, mc.GetType())); } else { MethodDiagramViewer mdv = mc as MethodDiagramViewer; if (mdv != null) { WebClientEventHandlerMethod wcehm = mdv.Method as WebClientEventHandlerMethod; if (wcehm != null) { if (string.CompareOrdinal("ReturnType", context.PropertyDescriptor.Name) == 0) { return(value); } } } bool isMethodReturn = false; IObjectPointer op = value as IObjectPointer; DataTypePointer val = new DataTypePointer(); if (op != null) { val.SetDataType(op); } for (int i = 0; i < context.PropertyDescriptor.Attributes.Count; i++) { MethodReturnAttribute mra = context.PropertyDescriptor.Attributes[i] as MethodReturnAttribute; if (mra != null) { isMethodReturn = true; break; } } // bool bUseDropDown = false; EnumWebRunAt runAt = EnumWebRunAt.Inherit; PropertyClassWebClient pcwc = context.Instance as PropertyClassWebClient; if (pcwc != null) { bUseDropDown = true; runAt = EnumWebRunAt.Client; } else { PropertyClassWebServer pcws = context.Instance as PropertyClassWebServer; if (pcws != null) { bUseDropDown = true; runAt = EnumWebRunAt.Server; } } if (!bUseDropDown) { ParameterClass pc = context.Instance as ParameterClass; if (pc != null) { ConstructorClass cc = pc.Method as ConstructorClass; if (cc != null) { ClassPointer cp = cc.Owner as ClassPointer; if (cp != null) { if (typeof(Attribute).IsAssignableFrom(cp.BaseClassType)) { //use drop down bUseDropDown = true; } } } } } // if (bUseDropDown) { TypeSelector drp = TypeSelector.GetAttributeParameterDialogue(service, runAt, val.BaseClassType); service.DropDownControl(drp); if (drp.SelectedType != null) { val.SetDataType(drp.SelectedType); bool bIsForLocalType = false; if (string.Compare(context.PropertyDescriptor.Name, ActionAssignInstance.Instance_Type, StringComparison.Ordinal) == 0) { PropertiesWrapper pw = context.Instance as PropertiesWrapper; if (pw != null) { AB_SingleAction sa = pw.Owner as AB_SingleAction; if (sa != null) { ActionAssignInstance aa = sa.ActionData as ActionAssignInstance; if (aa != null) { bIsForLocalType = true; aa.SetParameterValue(ConstObjectPointer.VALUE_Type, drp.SelectedType); } } } } if (bIsForLocalType) { } else { value = val; } } } else { Type typeAttr = null; MethodClass mc0 = scopeMethod; if (mc0 == null) { mc0 = mc as MethodClass; } if (mc0 == null) { MethodDiagramViewer mcv = mc as MethodDiagramViewer; if (mcv != null) { mc0 = mcv.Method; } } if (mc0 != null) { if (mc.Project.ProjectType == EnumProjectType.WebAppPhp) { if (mc0.WebUsage == EnumMethodWebUsage.Server) { typeAttr = typeof(PhpTypeAttribute); } else { typeAttr = typeof(JsTypeAttribute); } } else if (mc.Project.ProjectType == EnumProjectType.WebAppAspx) { if (mc0.WebUsage == EnumMethodWebUsage.Client) { typeAttr = typeof(JsTypeAttribute); } } } FrmObjectExplorer dlg = DesignUtil.GetDataTypeSelectionDialogue(mc.Project, scopeMethod, val, isMethodReturn, typeScope, typeAttr); if (service.ShowDialog(dlg) == DialogResult.OK) { val.SetDataType(dlg.SelectedDataType); bool bIsForLocalType = false; if (string.Compare(context.PropertyDescriptor.Name, ActionAssignInstance.Instance_Type, StringComparison.Ordinal) == 0) { PropertiesWrapper pw = context.Instance as PropertiesWrapper; if (pw != null) { AB_SingleAction sa = pw.Owner as AB_SingleAction; if (sa != null) { ActionAssignInstance aa = sa.ActionData as ActionAssignInstance; if (aa != null) { bIsForLocalType = true; aa.SetParameterValue(ActionAssignInstance.Instance_Type, dlg.SelectedDataType); } } } } else { ComponentIconLocal cil = context.Instance as ComponentIconLocal; bIsForLocalType = (cil != null); if (bIsForLocalType) { cil.LocalPointer.ClassType = dlg.SelectedDataType; } } if (bIsForLocalType) { } else { ExceptionHandlerList.PropertyDescriptorExceptionHandler pdeh = context.PropertyDescriptor as ExceptionHandlerList.PropertyDescriptorExceptionHandler; if (pdeh != null) { pdeh.Handler.ExceptionType = val; } else { value = val; } } } } } } } } return(value); }
public static void ShowError(Form caller, Exception e) { ShowError(caller, TraceLogClass.ExceptionMessage0(e)); }
void itemList_MouseMove(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left || itemList.SelectedIndex <= 0 || itemList.SelectedIndex != nSelectedIndex) { bPrepareDrag = false; } if (bPrepareDrag) { if (Math.Abs(e.X - x0) > 3 || Math.Abs(e.Y - y0) > 3) { ToolboxItem tbi = itemList.Items[itemList.SelectedIndex] as ToolboxItem; xToolboxItem xt = tbi as xToolboxItem; InterfaceVOB vob = ((IServiceContainer)toolbox.Host).GetService(typeof(InterfaceVOB)) as InterfaceVOB; IToolboxService tbs = ((IServiceContainer)toolbox.Host).GetService(typeof(IToolboxService)) as IToolboxService; if (tbs == null) { if (vob == null) { bool b = true; TraceLogClass log = new TraceLogClass(); log.Log("service InterfaceVOB not available", ref b); } else { PassData data = new PassData(); vob.SendNotice(enumVobNotice.GetToolbox, data); tbs = data.Data as IToolboxService; } } if (tbs != null) { bool bCanDrop = true; if (vob != null) { if (xt != null) { if (xt.Properties != null && xt.Properties.Contains("ClassId")) { ToolboxItemXType.SelectedToolboxClassId = (UInt32)(xt.Properties["ClassId"]); ToolboxItemXType.SelectedToolboxType = null; ToolboxItemXType.SelectedToolboxTypeKey = null; ToolboxItemXType.SelectedToolboxClassName = (string)(xt.Properties["DisplayName"]); } else { PassData pd = new PassData(); pd.Key = xt.Type; pd.Data = true; pd.Attributes = xt.Properties; vob.SendNotice(enumVobNotice.ObjectCanCreate, pd); bCanDrop = (bool)pd.Data; if (bCanDrop && pd.Attributes != null) { ToolboxItem tx0 = pd.Attributes as ToolboxItem; if (tx0 != null) { tbi = tx0; } } } } } if (bCanDrop) { try { DataObject d = tbs.SerializeToolboxItem(tbi) as DataObject; toolbox.HideToolBox(this, null); itemList.DoDragDrop(d, DragDropEffects.Copy); } catch (Exception ex) { bool b = true; TraceLogClass log = new TraceLogClass(); log.Log(this.FindForm(), ex, ref b); } } } } } }