Ejemplo n.º 1
0
 public void Save(string fileName)
 {
     // 创建文件对象。
     System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
     // 如果文件对象所在目录不存在,则创建。
     if (!System.IO.Directory.Exists(fileInfo.DirectoryName))
     {
         System.IO.Directory.CreateDirectory(fileInfo.DirectoryName);
     }
     // 创建Xml文档。
     System.Xml.Linq.XDocument xDocument = new System.Xml.Linq.XDocument(new System.Xml.Linq.XDeclaration("1.0", "utf-8", ""));
     // 添加Xml根节点。
     xDocument.Add(new System.Xml.Linq.XElement(XmlRootName));
     // 遍历配置文件中的配置组集合。
     foreach (ConfigurationGroup configurationGroup in _ConfigurationGroupDictionary.Values)
     {
         // 创建并添加Xml组节点。
         System.Xml.Linq.XElement xGroup = new System.Xml.Linq.XElement(XmlGroupNodeName);
         xGroup.SetAttributeValue(XmlKeyAttributeName, configurationGroup.Key);
         xDocument.Root.Add(xGroup);
         // 遍历配置组中的配置项集合。
         foreach (ConfigurationItem configurationItem in configurationGroup)
         {
             // 创建并添加Xml项节点。
             System.Xml.Linq.XElement xItem = new System.Xml.Linq.XElement(XmlItemNodeName);
             xItem.SetAttributeValue(XmlKeyAttributeName, configurationItem.Key);
             xItem.SetAttributeValue(XmlValueAttributeName, configurationItem.Encrypted ? Studio.Security.DESManager.Encrypt(configurationItem.Value) : configurationItem.Value);
             xItem.SetAttributeValue(XmlEncryptedAttributeName, configurationItem.Encrypted);
             xGroup.Add(xItem);
         }
     }
     // 保存到文件。
     xDocument.Save(fileInfo.FullName);
 }
Ejemplo n.º 2
0
 public static void RS_SetAttributeValueCONDBOOL(this System.Xml.Linq.XElement el, string name, bool?val)
 {
     if (val.HasValue)
     {
         el.SetAttributeValue(name, val.Value ? "true" : "false");
     }
 }
Ejemplo n.º 3
0
        private void Create(string projectName)
        {
            List <ProjectTemplate> templateList = new List <ProjectTemplate>();

            foreach (var item in checkedListBoxTemplates.CheckedItems)
            {
                ProjectTemplate projectTemplate = new ProjectTemplate();
                projectTemplate.TemplateName = item.ToString();
                projectTemplate.ScreenParameters["OutputDirectory"] = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "projects", textBoxName.Text, "Output");
                projectTemplate.ParametersTree = new System.Xml.Linq.XElement("parameterTree", "");
                System.Xml.Linq.XElement root = new System.Xml.Linq.XElement("root");
                root.SetAttributeValue("name", "root");
                root.Add(new System.Xml.Linq.XElement("children"));
                projectTemplate.ParametersTree.Add(root);
                templateList.Add(projectTemplate);
            }
            Project project = new Project();

            project.Name = projectName;
            project.ProjectTemplateList.Clear();
            project.ProjectTemplateList.AddRange(templateList);
            ProjectContainer.GetInstance().UpdateProject(project);
            ProjectContainer.GetInstance().Save();
            ProjectContainer.GetInstance().Reload(this, EventArgs.Empty);
            Classes.Mediation.FormMediator.GetInstance().SendMessage("Project Created");
        }
Ejemplo n.º 4
0
 public static System.Xml.Linq.XElement AddAnchorElement(this System.Xml.Linq.XElement parent, string href, string text)
 {
     var el_anchor = new System.Xml.Linq.XElement("a");
     el_anchor.SetAttributeValue("href", href);
     el_anchor.Value = text;
     parent.Add(el_anchor);
     return el_anchor;
 }
Ejemplo n.º 5
0
        public static System.Xml.Linq.XElement AddAnchorElement(this System.Xml.Linq.XElement parent, string href, string text)
        {
            var el_anchor = new System.Xml.Linq.XElement("a");

            el_anchor.SetAttributeValue("href", href);
            el_anchor.Value = text;
            parent.Add(el_anchor);
            return(el_anchor);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds an attribute to an Element and sets it's value in the XMLObject.
 ///
 /// This method can also remove the attribute by setting the value to null.
 ///
 /// If Element does not exist yet it will be created automatically with an
 /// empty value as well as making the attribute as if the Element was
 /// pre-added before calling this function.
 /// </summary>
 /// <exception cref="System.ObjectDisposedException">XMLOblect is disposed.</exception>
 public void AddAttribute(string elementname, string attributename, object attributevalue)
 {
     if (disposedValue)
     {
         throw new System.ObjectDisposedException("XMLOblect is disposed.");
     }
     System.Xml.Linq.XElement elem = doc.Root.Element(elementname);
     if (elem == null)
     {
         Write(elementname, null);
         elem = doc.Root.Element(elementname);
     }
     elem.SetAttributeValue(attributename, attributevalue);
 }
Ejemplo n.º 7
0
        protected override void SetAttributes(System.Xml.Linq.XElement ele, object propertyValue)
        {
            if (propertyValue == null)
            {
                return;
            }
            Bitmap bitmap = propertyValue as Bitmap;

            if (bitmap == null)
            {
                return;
            }
            BitmapData pdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);

            try
            {
                byte[]   buffer = new byte[bitmap.Height * pdata.Stride];
                GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                try
                {
                    MemoryCopy(handle.AddrOfPinnedObject(), pdata.Scan0, buffer.Length);
                    ele.SetAttributeValue("pixelformat", bitmap.PixelFormat);
                    ele.SetAttributeValue("width", bitmap.Width);
                    ele.SetAttributeValue("height", bitmap.Height);
                    ele.SetAttributeValue("stride", pdata.Stride);
                    ele.SetValue(Convert.ToBase64String(buffer));
                }
                finally
                {
                    handle.Free();
                }
            }
            finally
            {
                bitmap.UnlockBits(pdata);
            }
        }
 public static void MergeXml(System.Xml.Linq.XElement eledest, System.Xml.Linq.XElement elesrc)
 {
     foreach (var attr in elesrc.Attributes())
     {
         eledest.SetAttributeValue(attr.Name, attr.Value);
     }
     foreach (var srcchild in elesrc.Elements())
     {
         //var dstchild = eledest.Element(srcchild.Name);
         //if (dstchild != null)
         //{
         //    MergeXml(dstchild, srcchild);
         //}
         //else
         //{
         //    dstchild = new System.Xml.Linq.XElement(srcchild);
         //    eledest.SetElementValue(srcchild.Name, dstchild);
         //}
         var dstchild = new System.Xml.Linq.XElement(srcchild);
         eledest.Add(dstchild);
     }
 }
Ejemplo n.º 9
0
        private void Save()
        {
            if (comboBoxProjects.SelectedIndex > -1)
            {
                Project project = ProjectContainer.GetInstance().ProjectList.FirstOrDefault(x => x.Name == comboBoxProjects.SelectedItem.ToString());

                List <string> checkedItems = new List <string>();
                foreach (var item in checkedListBoxTemplates.CheckedItems)
                {
                    checkedItems.Add(item.ToString());
                }

                project.ProjectTemplateList.RemoveAll(x => !checkedItems.Contains(x.TemplateName)); //if we unchecked a template remove it
                project.Name = textBoxName.Text;

                foreach (string templateName in checkedItems)
                {
                    if (!project.ProjectTemplateList.Any(x => x.TemplateName == templateName)) //iterate the list of checked items. If we're missing a template add it.
                    {
                        ProjectTemplate projectTemplate = new ProjectTemplate();
                        projectTemplate.ScreenParameters["OutputDirectory"] = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "projects", textBoxName.Text, "Output");
                        projectTemplate.ParametersTree = new System.Xml.Linq.XElement("parameterTree", "");
                        System.Xml.Linq.XElement root = new System.Xml.Linq.XElement("root");
                        root.SetAttributeValue("name", "root");
                        root.Add(new System.Xml.Linq.XElement("children"));
                        projectTemplate.ParametersTree.Add(root);
                        projectTemplate.TemplateName = templateName;
                        project.ProjectTemplateList.Add(projectTemplate);
                    }
                }

                ProjectContainer.GetInstance().UpdateProject(project);
                ProjectContainer.GetInstance().Save();
                ProjectContainer.GetInstance().Reload(this, EventArgs.Empty);
                Classes.Mediation.FormMediator.GetInstance().SendMessage("Project Updated");
            }
        }
Ejemplo n.º 10
0
 public override System.Xml.Linq.XElement ToXml(System.Xml.Linq.XElement baseElement, bool AddCommonAttributes)
 {
     baseElement.SetAttributeValue("name", this.Name);
     baseElement.SetAttributeValue("value", this.Value);
     return(baseElement);
 }