public static VirtualWebDir CreateWebSite(string webSiteName, LimnorProject project, Form caller) { try { return(LimnorWebApp.CreateWebSite(project, webSiteName, caller)); } catch (Exception err) { MathNode.Log(err, "Cannot create website [{0}] on {1}", webSiteName, project.WebPhysicalFolder(caller)); } return(null); }
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); }