Пример #1
0
        private void mnuExportEmptyLanguageFile_Click(object sender, EventArgs e)
        {
            var exp = new Language();
            var sfd = new SaveFileDialog();

            sfd.Filter = "XML Language File|*.xml";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var fs = new FileStream(sfd.FileName, System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read);
                var tw = new StreamWriter(fs, System.Text.Encoding.UTF8);
                tw.Serialize(exp);
                fs.Close();
                var xDoc = new System.Xml.XmlDocument();
                xDoc.LoadXml(System.IO.File.ReadAllText(sfd.FileName));
                string comment = "Examples:\n";
                var    t       = lang.GetType();
                foreach (var prop in t.GetProperties())
                {
                    var value = prop.GetValue(prop.Name);
                    comment += string.Format("{0}: {1}\n", prop.Name, value);
                }

                xDoc.CreateComment(comment);
            }
        }
Пример #2
0
        private Configuration LoadWebConfig(string projectDir)
        {
            string webConfigFilePath = Path.Combine(projectDir, Constants.WebConfig);

            if (File.Exists(webConfigFilePath))
            {
                try
                {
                    XElement webConfigXml = XElement.Load(webConfigFilePath);
                    System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
                    xmlDocument.Load(webConfigFilePath);

                    // Comment out connection strings if type has a configProtectionProvider
                    // This can comment out connection strings that do not have "EncryptedData"
                    IEnumerable <XElement> encryptedConnectionStringElement =
                        from element in webConfigXml.Elements("connectionStrings")
                        where (string)element.Attribute("configProtectionProvider") != null
                        select element;

                    if (encryptedConnectionStringElement.HasAny())
                    {
                        System.Xml.XmlNode elementToComment = xmlDocument.SelectSingleNode("/configuration/connectionStrings");
                        string             commentContents  = elementToComment.OuterXml;

                        // Its contents are the XML content of target node
                        System.Xml.XmlComment commentNode = xmlDocument.CreateComment(commentContents);

                        // Get a reference to the parent of the target node
                        System.Xml.XmlNode parentNode = elementToComment.ParentNode;

                        // Replace the target node with the comment
                        parentNode.ReplaceChild(commentNode, elementToComment);
                        xmlDocument.Save(webConfigFilePath);
                    }

                    var fileMap = new ExeConfigurationFileMap()
                    {
                        ExeConfigFilename = webConfigFilePath
                    };
                    var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
                    return(configuration);
                }
                catch (Exception ex)
                {
                    LogHelper.LogError(ex, string.Format("Error processing web.config file {0}", webConfigFilePath));
                }
            }
            return(null);
        }
Пример #3
0
        private void cxBtnOk_Click(object sender, EventArgs e)
        {
            string sSQLServOldPwd, sSQLServNewPwd;

            if (cxTextEditOldPwd.EditValue == null || Convert.ToString(cxTextEditOldPwd.EditValue).Trim() == "")
            {
                oSecMainFrm.MessageDlg("Old Password cannot be blank...", "mtWarning", "mbOk", 0);
                return;
            }
            if (cxTextEditNewPwd.EditValue == null || Convert.ToString(cxTextEditNewPwd.EditValue).Trim() == "")
            {
                oSecMainFrm.MessageDlg("Please enter the new password.", "mtWarning", "mbOk", 0);
                return;
            }
            if (cxTextEditConfirmPwd.EditValue == null || Convert.ToString(cxTextEditConfirmPwd.EditValue).Trim() == "")
            {
                oSecMainFrm.MessageDlg("Please enter the confirm password.", "mtWarning", "mbOk", 0);
                return;
            }

            try
            {
                sSQLServOldPwd = XpedeonCrypto.XpedeonServerDecrypt(PCFSecurity.oSecDM.sSuperUserPassword);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (!Convert.ToString(cxTextEditOldPwd.EditValue).Equals(sSQLServOldPwd, StringComparison.InvariantCulture))
            {
                oSecMainFrm.MessageDlg("Old Password does not match.", "mtWarning", "mbOk", 0);
                return;
            }
            if (Convert.ToString(cxTextEditNewPwd.EditValue) != Convert.ToString(cxTextEditConfirmPwd.EditValue))
            {
                oSecMainFrm.MessageDlg("New Password and Confirm Password dont match.", "mtWarning", "mbOk", 0);
                return;
            }

            try
            {
                sSQLServNewPwd = XpedeonCrypto.XpedeonServerEncrypt(Convert.ToString(cxTextEditNewPwd.EditValue));
                UpdateSQLServPassword(Convert.ToString(cxTextEditUserName.EditValue), Convert.ToString(cxTextEditNewPwd.EditValue), Convert.ToString(cxTextEditOldPwd.EditValue));

                string sAppPath = Application.StartupPath.ToString();
                System.Xml.XmlDocument xdDataBaseConnection = new System.Xml.XmlDocument();
                xdDataBaseConnection.Load(@sAppPath + "\\PCFSecurityAccessInfo.xml");
                if (xdDataBaseConnection.GetElementsByTagName("PASSWORD").Count > 0)
                {
                    // Get the target node using XPath
                    System.Xml.XmlNode xnOldPwd = xdDataBaseConnection.SelectSingleNode("//PASSWORD");
                    // Create a new comment node with XML content of the target node
                    System.Xml.XmlComment xcOldPwd = xdDataBaseConnection.CreateComment(xnOldPwd.OuterXml);
                    // Replace the target node with the comment
                    xdDataBaseConnection.DocumentElement.ReplaceChild(xcOldPwd, xnOldPwd);

                    // Create a new node
                    System.Xml.XmlElement xeNewPwd = xdDataBaseConnection.CreateElement("PASSWORD");
                    xeNewPwd.InnerText = sSQLServNewPwd;
                    // Add the node to the document
                    xdDataBaseConnection.DocumentElement.AppendChild(xeNewPwd);
                }
                xdDataBaseConnection.Save(@sAppPath + "\\PCFSecurityAccessInfo.xml");

                PCFSecurity.oSecDM.DataModuleCreate();

                oSecMainFrm.MessageDlg("Password Changed Successfully.", "mtConfirmation", "mbOk", 0);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        Create()
        {
            Core.PackageUtilities.IdentifyAllPackages();

            var masterPackage     = Core.Graph.Instance.MasterPackage;
            var masterPackageName = masterPackage.Name;
            var projectPathname   = masterPackage.GetDebugPackageProjectPathname();

            RootUri = new System.Uri(projectPathname);

            var projectDir = System.IO.Path.GetDirectoryName(projectPathname);

            Core.IOWrapper.CreateDirectoryIfNotExists(projectDir);

            var mainSourceFile = System.IO.Path.Combine(projectDir, "main.cs");

            WriteEntryPoint(mainSourceFile);

            Document.AppendChild(Document.CreateComment("Automatically generated by BuildAMation"));
            var project = CreateElement("Project", Document);

            CreateAttribute("ToolsVersion", "12.0", project);
            CreateAttribute("DefaultsTarget", "Build", project);

            CreateImport(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props", true, project);

            var generalProperties = CreatePropertyGroup(parent: project);

            CreateElement("Configuration", condition: @" '$(Configuration)' == '' ", parent: generalProperties, value: "Debug");
            CreateElement("Platform", condition: @" '$(Platform)' == '' ", parent: generalProperties, value: "AnyCPU");
            CreateElement("ProjectGuid", parent: generalProperties, value: System.Guid.NewGuid().ToString("B").ToUpper());
            CreateElement("OutputType", parent: generalProperties, value: "Exe");
            CreateElement("RootNamespace", parent: generalProperties, value: masterPackageName);
            CreateElement("AssemblyName", parent: generalProperties, value: masterPackageName);
            CreateElement("TargetFrameworkVersion", parent: generalProperties, value: "v4.5");
            CreateElement("WarningLevel", parent: generalProperties, value: "4");
            CreateElement("TreatWarningsAsErrors", parent: generalProperties, value: "true");

            var debugProperties = CreatePropertyGroup(condition: @" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ", parent: project);

            CreateElement("PlatformTarget", parent: debugProperties, value: "AnyCPU");
            CreateElement("DebugSymbols", parent: debugProperties, value: "true");
            CreateElement("DebugType", parent: debugProperties, value: "full");
            CreateElement("Optimize", parent: debugProperties, value: "false");
            CreateElement("OutputPath", parent: debugProperties, value: @"bin\Debug\");
            CreateElement("CheckForOverflowUnderflow", parent: debugProperties, value: "true");
            CreateElement("AllowUnsafeBlocks", parent: debugProperties, value: "false");
            CreateElement("DefineConstants", parent: debugProperties, value: GetPreprocessorDefines());

            var references = CreateItemGroup(parent: project);

            foreach (var desc in masterPackage.DotNetAssemblies)
            {
                CreateReference(desc.Name, references, targetframework: desc.RequiredTargetFramework);
            }
            if (Core.Graph.Instance.ProcessState.RunningMono)
            {
                CreateReference("Mono.Posix", references);
            }
            foreach (var assembly in masterPackage.BamAssemblies)
            {
                var assemblyPath = System.IO.Path.Combine(Core.Graph.Instance.ProcessState.ExecutableDirectory, assembly.Name) + ".dll";
                CreateReference(assembly.Name, references, hintpath: assemblyPath);
            }

            var mainSource = CreateItemGroup(parent: project);

            CreateCompilableSourceFile(mainSourceFile, null, mainSource);
            foreach (var package in Core.Graph.Instance.Packages)
            {
                var packageSource = CreateItemGroup(parent: project);

                CreateOtherSourceFile(package.XMLFilename, package, packageSource);

                foreach (var script in package.GetScriptFiles(allBuilders: true))
                {
                    CreateCompilableSourceFile(script, package, packageSource);
                }
            }

            var resourceFilePathName = Core.PackageListResourceFile.WriteResXFile(projectPathname);
            var resources            = CreateItemGroup(parent: project);

            CreateEmbeddedResourceFile(resourceFilePathName, resources);

            CreateImport(@"$(MSBuildBinPath)\Microsoft.CSharp.Targets", false, project);

            var xmlWriterSettings = new System.Xml.XmlWriterSettings();

            xmlWriterSettings.Indent             = true;
            xmlWriterSettings.CloseOutput        = true;
            xmlWriterSettings.OmitXmlDeclaration = false;
            using (var writer = System.Xml.XmlWriter.Create(projectPathname, xmlWriterSettings))
            {
                Document.WriteTo(writer);
            }

            Core.Log.Info("Successfully created debug project for package '{0}'", masterPackage.FullName);
            Core.Log.Info("\t{0}", projectPathname);
        }
Пример #5
0
        void IProject.Serialize()
        {
            System.Xml.XmlDocument xmlDocument = null;
            try
            {
                var projectLocationUri = new System.Uri(this.PathName, System.UriKind.RelativeOrAbsolute);

                xmlDocument = new System.Xml.XmlDocument();

                xmlDocument.AppendChild(xmlDocument.CreateComment("Automatically generated by BuildAMation v" + Bam.Core.State.VersionString));

                // TODO: this needs to be from the Toolset
                var versionString = DotNetFramework.DotNet.VersionString;
                var project = new MSBuildProject(xmlDocument, versionString);

                var generalGroup = project.CreatePropertyGroup();
                generalGroup.CreateProperty("ProjectGuid", this.ProjectGuid.ToString("B").ToUpper());
                // default configuration and platform
                {
                    var defaultConfiguration = generalGroup.CreateProperty("Configuration", "Debug");
                    defaultConfiguration.Condition = " '$(Configuration)' == '' ";
                }
                {
                    var defaultPlatform = generalGroup.CreateProperty("Platform", "AnyCPU");
                    defaultPlatform.Condition = " '$(Platform)' == '' ";
                }
                generalGroup.CreateProperty("TargetFrameworkVersion", "v" + versionString);

                // configurations
                // TODO: convert to var
                foreach (ProjectConfiguration configuration in this.ProjectConfigurations)
                {
                    configuration.SerializeCSBuild(project, projectLocationUri);
                }

                // source files
                if (this.SourceFileCollection.Count > 0)
                {
                    this.SourceFileCollection.SerializeCSBuild(project, projectLocationUri, this.PackageUri);
                }

                // application definition and page files
                if ((this.ApplicationDefinitionFile != null) ||
                    (this.PageFiles.Count > 0))
                {
                    var applicationDefinitionGroup = project.CreateItemGroup();

                    // application definition
                    if (this.ApplicationDefinitionFile != null)
                    {
                        var xamlRelativePath = Bam.Core.RelativePathUtilities.GetPath(this.ApplicationDefinitionFile.RelativePath, projectLocationUri);

                        var applicationDefinition = applicationDefinitionGroup.CreateItem("ApplicationDefinition", xamlRelativePath);
                        applicationDefinition.CreateMetaData("Generator", "MSBuild:Compile");
                        applicationDefinition.CreateMetaData("SubType", "Designer");

                        var sourcePathname = xamlRelativePath + ".cs";
                        var associatedSource = applicationDefinitionGroup.CreateItem("Compile", sourcePathname);
                        associatedSource.CreateMetaData("DependentUpon", System.IO.Path.GetFileName(xamlRelativePath));
                        associatedSource.CreateMetaData("SubType", "Code");
                    }

                    // page files
                    // TODO: convert to var
                    foreach (ProjectFile pageFile in this.PageFiles)
                    {
                        var xamlRelativePath = Bam.Core.RelativePathUtilities.GetPath(pageFile.RelativePath, projectLocationUri);

                        var applicationDefinition = applicationDefinitionGroup.CreateItem("Page", xamlRelativePath);
                        applicationDefinition.CreateMetaData("Generator", "MSBuild:Compile");
                        applicationDefinition.CreateMetaData("SubType", "Designer");

                        var sourcePathname = xamlRelativePath + ".cs";
                        var associatedSource = applicationDefinitionGroup.CreateItem("Compile", sourcePathname);
                        associatedSource.CreateMetaData("DependentUpon", System.IO.Path.GetFileName(xamlRelativePath));
                        associatedSource.CreateMetaData("SubType", "Code");
                    }
                }

                // project dependencies
                if (this.DependentProjectList.Count > 0)
                {
                    var dependencyItemGroup = project.CreateItemGroup();
                    foreach (var dependentProject in this.DependentProjectList)
                    {
                        var relativePath = Bam.Core.RelativePathUtilities.GetPath(dependentProject.PathName, this.PathName);
                        var projectReference = dependencyItemGroup.CreateItem("ProjectReference", relativePath);
                        projectReference.CreateMetaData("Project", dependentProject.Guid.ToString("B").ToUpper());
                        projectReference.CreateMetaData("Name", dependentProject.Name);
                    }
                }

                // project references
                if (this.ReferencesList.Count > 0)
                {
                    var referenceItemGroup = project.CreateItemGroup();
                    foreach (var reference in this.ReferencesList)
                    {
                        var noExtReference = reference;
                        if (noExtReference.EndsWith(".dll"))
                        {
                            noExtReference = reference.Remove(noExtReference.Length - 4);
                        }
                        referenceItemGroup.CreateItem("Reference", noExtReference);
                    }
                }

                // import C# project props
                project.CreateImport(@"$(MSBuildBinPath)\Microsoft.CSharp.targets");
            }
            catch (Bam.Core.Exception exception)
            {
                var message = System.String.Format("Xml construction error from project '{0}'", this.PathName);
                throw new Bam.Core.Exception(message, exception);
            }

            // write XML to disk
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(this.PathName));

            var xmlWriterSettings = new System.Xml.XmlWriterSettings();
            xmlWriterSettings.Indent = true;
            xmlWriterSettings.CloseOutput = true;
            xmlWriterSettings.OmitXmlDeclaration = false;
            xmlWriterSettings.NewLineOnAttributes = false;

            try
            {
                using (var xmlWriter = System.Xml.XmlWriter.Create(this.PathName, xmlWriterSettings))
                {
                    xmlDocument.Save(xmlWriter);
                    xmlWriter.WriteWhitespace(xmlWriterSettings.NewLineChars);
                }
            }
            catch (Bam.Core.Exception exception)
            {
                var message = System.String.Format("Serialization error from project '{0}'", this.PathName);
                throw new Bam.Core.Exception(message, exception);
            }
        }