コード例 #1
0
        private void btWeb_Click(object sender, EventArgs e)
        {
            DialogNewWeb dlg = new DialogNewWeb();
            string       ph  = txtWebFolder.Text;
            string       wn  = txtWebName.Text;

            if (string.IsNullOrEmpty(ph) && _webSite != null)
            {
                ph = _webSite.PhysicalDirectory;
            }
            if (string.IsNullOrEmpty(wn))
            {
                wn = _webSiteName;
            }
            dlg.LoadData("Create a test web site", wn, ph, true);
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                if (dlg.Ret != null)
                {
                    _webSite          = dlg.Ret;
                    txtWebName.Text   = _webSite.WebName;
                    txtWebFolder.Text = _webSite.PhysicalDirectory;
                    txtUrl.Text       = string.Format(CultureInfo.InvariantCulture, "http://localhost/{0}", txtWebName.Text);
                    picWeb.Image      = Resource1._webOK.ToBitmap();
                }
            }
        }
コード例 #2
0
        public static VirtualWebDir CreateWebSite(LimnorProject project, string websitename, Form owner)
        {
            bool          iisError = false;
            VirtualWebDir webSite  = project.GetTestWebSite(owner);

            if (webSite == null)
            {
                webSite = IisUtility.FindLocalWebSiteByName(owner, websitename, out iisError);
            }
            if (webSite == null && !iisError)
            {
                webSite = IisUtility.FindLocalWebSite(websitename);
                if (webSite == null)
                {
                    //create the web site
                    DialogProjectOutput dlg = new DialogProjectOutput();
                    dlg.LoadData(project, websitename);
                    if (dlg.ShowDialog(owner) == DialogResult.OK)
                    {
                        if (dlg.WebSite != null)
                        {
                            webSite = dlg.WebSite;
                        }
                    }
                }
            }
            return(webSite);
        }
コード例 #3
0
 public string TestWebSiteName(Form owner)
 {
     if (this.Project != null)
     {
         VirtualWebDir web = this.Project.GetTestWebSite(owner);
         if (web != null)
         {
             return(web.WebName);
         }
     }
     //_webName is the default name
     return(_webName);
 }
コード例 #4
0
        public void LoadData(LimnorProject project, string siteName)
        {
            _prj         = project;
            txtPrj.Text  = _prj.ProjectName;
            _webSiteName = siteName;
            VirtualWebDir vw = _prj.GetTestWebSite(this);

            if (vw != null)
            {
                _webSite = vw;
                if (!VirtualWebDir.IsNetworkDrive(vw.PhysicalDirectory))
                {
                    txtWebFolder.Text = vw.PhysicalDirectory;
                }
                if (string.IsNullOrEmpty(vw.WebName))
                {
                    txtWebName.Text = _webSiteName;
                }
                else
                {
                    txtWebName.Text = vw.WebName;
                }
                if (vw.IsValid)
                {
                    picWeb.Image = Resource1._webOK.ToBitmap();
                }
                else
                {
                    picWeb.Image = Resource1._webNotOK.ToBitmap();
                }
            }
            else
            {
                txtWebName.Text = _webSiteName;
                string sh = _prj.WebPhysicalFolder(this);
                if (!VirtualWebDir.IsNetworkDrive(sh))
                {
                    txtWebFolder.Text = sh;
                }
                picWeb.Image = Resource1._webNotOK.ToBitmap();
            }
            txtUrl.Text = string.Format(CultureInfo.InvariantCulture, "http://localhost/{0}", txtWebName.Text);
            IList <OutputFolder> lst = _prj.GetOutputFolders();

            foreach (OutputFolder f in lst)
            {
                checkedListBox1.Items.Add(f, !f.Disabled);
            }
        }
コード例 #5
0
        public VirtualWebDir CreateWebSite(Form owner, out bool newName)
        {
            newName = false;
            string wname = WebSiteName;

            if (wname != null)
            {
                wname = wname.Trim();
            }
            if (string.IsNullOrEmpty(wname))
            {
                throw new DesignerException("WebSiteName property is empty");
            }
            VirtualWebDir webSite = CreateWebSite(Project, wname, owner);

            if (webSite != null)
            {
                if (string.Compare(wname, webSite.WebName, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    newName = true;
                }
            }
            return(webSite);
        }
コード例 #6
0
        public static IWebHost CreateHtmlHost(ILimnorDesignerLoader loader, Form caller)
        {
            IWebHost      host    = null;
            Encoding      encode  = Encoding.Unicode;
            string        docType = null;
            VirtualWebDir webSite = WebHost.GetWebSite(loader.Project, caller);

            if (webSite != null)
            {
                installHtmlEdiotr(caller);
                if (!loader.Project.WebFolderGranted)
                {
                    string err = VPLUtil.GrantFolderFullPermission(webSite.PhysicalDirectory);
                    if (string.IsNullOrEmpty(err))
                    {
                        loader.Project.SetWebFolderGranted();
                    }
                    else
                    {
                        MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error granting permissions to [{0}]. {1}", webSite.PhysicalDirectory, err), "Web Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                WebPage wpage      = loader.RootObject as WebPage;
                bool    openWebTab = true;
                string  hf         = WebHost.GetHtmlFile(loader.ComponentFilePath);                 //saved HTML file
                string  editFile   = Path.Combine(webSite.PhysicalDirectory, Path.GetFileName(hf)); //in WebFiles
                //create editFile contents
                if (File.Exists(hf))
                {
                    try
                    {
                        //set editing file to the doc type for editing (IE requirement)
                        //for Chrome, try not to do it
                        string        line;
                        StringBuilder sbBeforeHtml = new StringBuilder();
                        bool          gotHtml      = false;
                        StreamReader  sr           = new StreamReader(hf, true);
                        encode = sr.CurrentEncoding;
                        while (!sr.EndOfStream)
                        {
                            line = sr.ReadLine();
                            if (gotHtml)
                            {
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(line))
                                {
                                    int pos = line.IndexOf("<html", StringComparison.OrdinalIgnoreCase);
                                    if (pos >= 0)
                                    {
                                        if (pos > 0)
                                        {
                                            sbBeforeHtml.Append(line.Substring(0, pos));
                                        }
                                        docType = sbBeforeHtml.ToString();
                                        gotHtml = true;
                                        break;                                         //for Chrome
                                    }
                                    else
                                    {
                                        sbBeforeHtml.Append(line);
                                        sbBeforeHtml.Append("\r\n");
                                    }
                                }
                            }
                        }
                        sr.Close();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying [{0}] to [{1}]. {2}", hf, editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        openWebTab = false;
                    }
                    //for Chrome
                    if (openWebTab)
                    {
                        try
                        {
                            File.Copy(hf, editFile, true);
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying from [{0}] to [{1}]. {2}.", hf, editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            openWebTab = false;
                        }
                    }
                    if (openWebTab)
                    {
                        int p0 = hf.LastIndexOf('.');
                        if (p0 > 0)
                        {
                            string css = string.Format(CultureInfo.InvariantCulture, "{0}.css", hf.Substring(0, p0));
                            if (File.Exists(css))
                            {
                                string tgt = Path.Combine(webSite.PhysicalDirectory, Path.GetFileName(css));
                                try
                                {
                                    File.Copy(css, tgt, true);
                                }
                                catch (Exception err)
                                {
                                    MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying from [{0}] to [{1}]. {2}.", css, tgt, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    openWebTab = false;
                                }
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        StreamWriter sw = new StreamWriter(editFile);
                        sw.Write(Resources.emptyPageEdit);
                        sw.Close();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error creating empty html file for editing: [{0}]. {1}", editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        openWebTab = false;
                    }
                }
                if (openWebTab)
                {
                    try
                    {
                        CopyJsLib(webSite.PhysicalDirectory);
                        CopyJsColor(webSite.PhysicalDirectory);
                    }
                    catch (Exception err)
                    {
                        MathNode.Log(err, "Error preparing html file for editing: [{0}]", editFile);
                        openWebTab = false;
                    }
                    bool   bErr;
                    string rootPath = IisUtility.FindLocalRootWebPath(caller, out bErr);
                    if (string.IsNullOrEmpty(rootPath))
                    {
                        MathNode.Log("Cannot get physical path for web root.");
                    }
                    else
                    {
                        string libjs = Path.Combine(rootPath, "libjs");
                        if (!Directory.Exists(libjs))
                        {
                            try
                            {
                                Directory.CreateDirectory(libjs);
                            }
                            catch (Exception err2)
                            {
                                MathNode.Log(err2, "Error creating web folder: [{0}]", libjs);
                            }
                        }
                        string jsfile = Path.Combine(libjs, "htmlEditorClient.js");
                        if (!File.Exists(jsfile))
                        {
                            try
                            {
                                StreamWriter sw = new StreamWriter(jsfile, false, Encoding.ASCII);
                                sw.Write(Resources.htmleditorClient);
                                sw.Close();
                            }
                            catch (Exception err3)
                            {
                                MathNode.Log(err3, "Error creating file: [{0}]", jsfile);
                            }
                        }
                    }
                }
                if (openWebTab)
                {
#if USECEF
                    if (IntPtr.Size == 4)
                    {
                        WebHostX86 hx86 = new WebHostX86();
                        host = hx86;
                        hx86.LoadWebHost(loader.Project.ProjectFolder, webSite.PhysicalDirectory, webSite.WebName, editFile, encode, docType, wpage);
                    }
                    else
                    {
                    }
                    //host.SetHtmlFile(editFile, webSite.WebName);
#else
                    host = new WebHost(loader.Project.ProjectFolder, webSite.PhysicalDirectory, webSite.WebName, editFile, encode, docType, wpage);
                    host.SetEncode(encode);
                    if (!string.IsNullOrEmpty(docType))
                    {
                        host.SetDocType(docType);
                    }
#endif
                    wpage.RefreshWebDisplay();
                }
            }
            return(host);
        }
コード例 #7
0
        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);
        }