/// <summary>
        /// Fills the XML data.
        /// </summary>
        /// <param name="xml">The XML.</param>
        protected override void FillXmlData(XElement xml)
        {
            base.FillXmlData(xml);

            xml.SetValue( nodeName_Event, this.Event);
            xml.SetValue( nodeName_EventKey, this.EventKey);
        }
        public void AddToElement(SXL.XElement parent)
        {
            var prop_el = Internal.XMLUtil.CreateVisioSchema2003Element("Prop");

            if (this.Name != null)
            {
                prop_el.SetElementValue("Name", this.Name);
            }

            prop_el.SetAttributeValue("NameU", this.NameU);
            prop_el.SetAttributeValue("ID", this.ID);
            prop_el.SetElementValueConditional("Del", this._del);

            if (this.Value != null)
            {
                var val_el = new SXL.XElement(Internal.Constants.VisioXmlNamespace2003 + "Value");
                prop_el.Add(val_el);
                val_el.SetAttributeValue("Unit", "STR");
                val_el.SetValue(this.Value);
            }
            prop_el.Add(this.Prompt.ToXml("Prompt"));
            prop_el.Add(this.Label.ToXml("Label"));
            prop_el.Add(this.Format.ToXml("Format"));
            prop_el.Add(this.SortKey.ToXml("SortKey"));
            prop_el.Add(this.Type.ToXml("Type"));
            prop_el.Add(this.Invisible.ToXml("Invisible"));
            prop_el.Add(this.LangID.ToXml("LangID"));
            prop_el.Add(this.Calendar.ToXml("Calendar"));
            parent.Add(prop_el);
        }
Beispiel #3
0
        private bool AddCreateTranslationsTranslation()
        {
            var translationsFilePath = GetTranslationFilePathPath();
            var translationsFile = XDocument.Load(translationsFilePath, LoadOptions.PreserveWhitespace);
            var success = true;
            try
            {
                var actions = translationsFile.XPathSelectElements(XPathQueryXmlTranslationActionArea).Single();
                if (!actions.XPathSelectElements(XPathQueryXmlCreateTranslationsKey).Any())
                {
                    var translation = new XElement("key", new XAttribute("alias", "polyglotCreateTranslations"));
                    translation.SetValue("Create translations");
                    actions.Add(translation);
                }
            }
            catch (Exception)
            {
                success = false;
            }

            if (success)
            {
                try
                {
                    translationsFile.Save(translationsFilePath, SaveOptions.DisableFormatting);
                }
                catch (Exception)
                {
                    success = false;
                }
            }

            return success;
        }
        public void EncodeXml(XElement root)
        {
            var attr = root.Attribute("Protected");
            if (attr != null && Convert.ToBoolean(attr.Value))
            {
                var protectedStringBytes = UTF8Encoding.UTF8.GetBytes(root.Value);
                int protectedByteLength = protectedStringBytes.Length;


                var cipher = cryptoRandomStream.GetRandomBytes((uint)protectedByteLength);
                byte[] pbPlain = new byte[protectedStringBytes.Length];


                for (int i = 0; i < pbPlain.Length; ++i)
                    pbPlain[i] = (byte)(protectedStringBytes[i] ^ cipher[i]);

                string mypass = Convert.ToBase64String(pbPlain);
                root.SetValue(mypass);
            }

            foreach (var node in root.Elements())
            {
                EncodeXml(node);
            }
        }
 private static void AddField(XElement doc, string name, string value)
 {
     var x = new XElement("field");
     x.SetAttributeValue("name", name);
     x.SetValue(value);
     doc.Add(x);
 }
Beispiel #6
0
        public XElement Generate(TestCase testCase)
        {
            XElement main = new XElement("div");

            XElement tr = new XElement("tr");
            XElement tdName = new XElement("td", testCase.Desription);
            XElement tdStatus = new XElement("td", testCase.Result);
            XElement tdTime = new XElement("td", testCase.Time);

            XElement trMessage = new XElement("tr");
            XElement tdMessage = new XElement("td");


            if (testCase.Message != null || testCase.StackTrace != null)
            {
                XElement preMessage = new XElement("pre", testCase.Message);
                XElement preStackTrace = new XElement("pre", testCase.StackTrace);
                tdMessage.SetValue("MESSAGE:\n");

                tdMessage.Add(preMessage);
                tdMessage.Add(preStackTrace);
                trMessage.Add(tdMessage);
            }
            else if (!string.IsNullOrEmpty(testCase.Reason))
            {
                XElement reasonMessage = new XElement("pre", testCase.Reason);
                tdMessage.Add(reasonMessage);
                trMessage.Add(tdMessage);
            }

            tr.Add(tdName);
            tr.Add(tdStatus);
            tr.Add(tdTime);

            main.Add(tr);
            main.Add(trMessage);

            tdName.SetAttributeValue("style", "text-align:left;");
            trMessage.SetAttributeValue("style", "font-size:11px; text-align:left;");
            trMessage.SetAttributeValue("bgcolor", "lightgrey");
            tdMessage.SetAttributeValue("colspan", "3");


            switch (testCase.Result)
            {
                case "Success":
                    tdStatus.SetAttributeValue("bgcolor", "green");
                    break;
                case "Ignored":
                    tdStatus.SetAttributeValue("bgcolor", "yellow");
                    break;
                case "Failure":
                    tdStatus.SetAttributeValue("bgcolor", "red");
                    break;
                default:
                    break;
            }

            return main;
        }
        public void AddToElement(SXL.XElement parent)
        {
            var prop_el = Internal.XMLUtil.CreateVisioSchema2003Element("Prop");
            if (this.Name != null)
            {
                prop_el.SetElementValue("Name", this.Name);
            }

            prop_el.SetAttributeValue("NameU", this.NameU);
            prop_el.SetAttributeValue("ID", this.ID);
            prop_el.SetElementValueConditional("Del", this._del);

            if (this.Value!=null)
            {
                var val_el = new SXL.XElement(Internal.Constants.VisioXmlNamespace2003 + "Value");
                prop_el.Add(val_el);
                val_el.SetAttributeValue("Unit", "STR");
                val_el.SetValue(this.Value);                
            }
            prop_el.Add(this.Prompt.ToXml("Prompt"));
            prop_el.Add(this.Label.ToXml("Label"));
            prop_el.Add(this.Format.ToXml("Format"));
            prop_el.Add(this.SortKey.ToXml("SortKey"));
            prop_el.Add(this.Type.ToXml("Type"));
            prop_el.Add(this.Invisible.ToXml("Invisible"));
            prop_el.Add(this.LangID.ToXml("LangID"));
            prop_el.Add(this.Calendar.ToXml("Calendar"));
            parent.Add(prop_el);
        }
        protected override string Serialize(IDictionary<string, Dictionary<string, string>> data)
        {
            XDocument xml = new XDocument(new XElement(RootName));

            foreach (KeyValuePair<string, Dictionary<string, string>> sectionAndKeys in data)
            {
                string sectionName = sectionAndKeys.Key;
                var keys = sectionAndKeys.Value;

                if (keys.Any())
                {
                    XElement section = new XElement(SectionElementName);
                    section.SetAttributeValue(AttributeName, sectionName);

                    foreach (KeyValuePair<string, string> keyAndValue in keys)
                    {
                        string keyName = keyAndValue.Key;
                        string value = keyAndValue.Value;

                        XElement key = new XElement(KeyElementName);
                        key.SetAttributeValue(AttributeName, keyName);
                        key.SetValue(value);

                        section.Add(key);
                    }

                    xml.Root.Add(section);
                }
            }

            string output = this.OutputXml(xml);

            return output;
        }
        /// <summary>
        /// The generate xml.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string GenerateXml(IContent page)
        {
            if (page == null)
            {
                return string.Empty;
            }

            XDocument xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new object[0]);

            XElement xElement = new XElement("content");
            xElement.SetAttributeValue("name", XmlConvert.EncodeName(page.Name));

            List<KeyValuePair<string, string>> propertyValues = page.GetPropertyValues();

            foreach (KeyValuePair<string, string> content in propertyValues)
            {
                XElement xElement3 = new XElement(XmlConvert.EncodeName(content.Key));
                xElement3.SetValue(TextIndexer.StripHtml(content.Value, content.Value.Length));
                xElement.Add(xElement3);
            }

            xDocument.Add(xElement);

            return xDocument.ToString();
        }
		private static byte[] GetRequestContent(String username, String password, String application, String accessKey, String privateAccessKey, Encoding encoding)
		{
			XDocument document = new XDocument(new XDeclaration("1.0", encoding.BodyName, "yes"));
			XElement root = new XElement("appAuthorization");

			XElement userNameElement = new XElement("username");
			userNameElement.SetValue(username);
			root.Add(userNameElement);

			XElement passwordElement = new XElement("password");
			passwordElement.SetValue(password);
			root.Add(passwordElement);

			XElement appElement = new XElement("application");
			appElement.SetValue(application);
			root.Add(appElement);

			XElement accessKeyElement = new XElement("accessKeyId");
			accessKeyElement.SetValue(accessKey);
			root.Add(accessKeyElement);

			XElement privateAccessKeyElement = new XElement("privateAccessKey");
			privateAccessKeyElement.SetValue(privateAccessKey);
			root.Add(privateAccessKeyElement);


			document.Add(root);
			return document.Encode(encoding);
		}
        public ActionResult CheckDate(string app_id, string client_id)
        {
            XElement root;
            int appid = utility_functions.getAppID(app_id);

            if (appid == 0)
            {
                root = new XElement("error");
                root.SetValue("No such app - " + app_id);
                return new XmlResult(root);
            }

            DateTime eventdate = eventmodel.getLastEventUpdate(appid);
            DateTime messagedate = messagemodel.getLastMessageUpdate(appid);
            DateTime homescreendate = utility_functions.getHomeScreenUpdate(appid);
            root = new XElement("items");
            XElement messagenode = new XElement("messages");
            XElement eventnode = new XElement("events");
            XElement homenode = new XElement("hometext");

            messagenode.SetValue(messagedate.ToString("yyyy-MM-dd HH:mm:ss"));
            eventnode.SetValue(eventdate.ToString("yyyy-MM-dd HH:mm:ss"));
            homenode.SetValue(homescreendate.ToString("yyyy-MM-dd HH:mm:ss"));
            root.Add(eventnode);
            root.Add(messagenode);
            root.Add(homenode);

            utility_functions.insertServerEvent("date checked", app_id, client_id, Request.RawUrl, Request.UserHostAddress);

            return new XmlResult(root);
        }
Beispiel #12
0
        public void Execute()
        {
            //
            // 親要素を持たない要素を作成し、特定のXMLツリーの中に組み込む. (アタッチ)
            //
            var noParent = new XElement("NoParent", true);
            var tree1 = new XElement("Parent", noParent);

            var noParent2 = tree1.Element("NoParent");
            Output.WriteLine("参照が同じ? = {0}", noParent == noParent2);
            Output.WriteLine(tree1);

            // 値を変更して確認.
            noParent.SetValue(false);
            Output.WriteLine(noParent.Value);
            Output.WriteLine(tree1.Element("NoParent")?.Value);

            Output.WriteLine("==========================================");

            //
            // 親要素を持つ要素を作成し、特定のXMLツリーの中に組み込む. (クローン)
            //
            var origTree = new XElement("Parent", new XElement("WithParent", true));
            var tree2 = new XElement("Parent", origTree.Element("WithParent"));

            Output.WriteLine("参照が同じ? = {0}", origTree.Element("WithParent") == tree2.Element("WithParent"));
            Output.WriteLine(tree2);

            // 値を変更して確認
            origTree.Element("WithParent")?.SetValue(false);
            Output.WriteLine(origTree.Element("WithParent")?.Value);
            Output.WriteLine(tree2.Element("WithParent")?.Value);
        }
Beispiel #13
0
        internal static XElement createData(String _elename, String _dataitem_name, String _dataitem_subType, String _dataItem_id, XElement data)
        {
            String timestamp = data.Attribute("timestamp").Value;
            String sequence = data.Attribute("sequence").Value;
            XElement re = new XElement(MTConnectNameSpace.mtStreams + _elename, new XAttribute("name", _dataitem_name), new XAttribute("timestamp", timestamp), new XAttribute("sequence", sequence));
            re.Add(new XAttribute("dataItemId", _dataItem_id));
            if (_dataitem_subType != null)
                re.Add(new XAttribute("subType", _dataitem_subType));
            XAttribute temp = data.Attribute("partId");
            if ( temp != null )
                re.Add(new XAttribute("partId",temp.Value));
            temp = data.Attribute("workPieceId");
            if ( temp != null )
                re.Add(new XAttribute("workPieceId", temp.Value));
            temp = data.Attribute("state");
            if (temp != null)
                re.Add(new XAttribute("state", temp.Value));
            temp = data.Attribute("code");
            if (temp != null)
                re.Add(new XAttribute("code", temp.Value));
            temp = data.Attribute("severity");
            if (temp != null)
                re.Add(new XAttribute("severity", temp.Value));
            temp = data.Attribute("nativeCode");
            if (temp != null)
                re.Add(new XAttribute("nativeCode", temp.Value));

            re.SetValue(data.Value);
            return re;
        }
		public void Sync(string pathSource, string pathTarget, string relative)
		{
			var source = XDocument.Load(pathSource);
			var target = XDocument.Load(pathTarget);

			var targetGroup = GutTarget(target);
			if (targetGroup == null)
				return;

			var sourceFiles = source.XPathSelectElements("//msbuild:ItemGroup/msbuild:Compile", _namespaceManager);
			foreach (var sourceFile in sourceFiles)
			{
				var attrInclude = sourceFile.Attribute(XName.Get("Include"));
				if (attrInclude == null) continue;
				if (attrInclude.Value.StartsWith(@"Properties\")) continue;

				var newIncludeText = relative + attrInclude.Value;
				var newLinkText = attrInclude.Value;

				var compileElement = new XElement(_ns + "Compile");
				compileElement.SetAttributeValue("Include", newIncludeText);
				var linkElement = new XElement(_ns + "Link");
				;
				linkElement.SetValue(newLinkText);

				compileElement.Add(linkElement);
				targetGroup.Add(compileElement);
			}

            target.Save(pathTarget);
		}
Beispiel #15
0
        XElement ToXml(string elementName, object o)
        {
            if (o == null) o = new { };

            var result = new XElement(XmlConvert.EncodeName(elementName));

            if (IsPrimitive(o))
            {
                result.SetValue(o);

                return result;
            }

            if (o is IEnumerable)
            {
                foreach (var item in o as IEnumerable) result.Add(ToXml("item", item));

                return result;
            }

            var properties = o.GetType().GetProperties();

            foreach (var property in properties) result.Add(ToXml(property.Name, property.GetValue(o, null)));

            return result;
        }
        // Partially taken from https://github.com/kipusoep/UrlTracker/blob/b2bc998adaae2f74779e1119fd7b1e97a3b71ed2/UI/Installer/UrlTrackerInstallerService.asmx.cs

        public static bool InstallDashboard(string section, string caption, string control)
        {
            bool result = false;
            try
            {
                string dashboardConfig;
                string dashboardConfigPath = HttpContext.Current.Server.MapPath("~/config/dashboard.config");
                using (StreamReader streamReader = File.OpenText(dashboardConfigPath))
                    dashboardConfig = streamReader.ReadToEnd();
                if (string.IsNullOrEmpty(dashboardConfig))
                    throw new Exception("Unable to add dashboard: Couldn't read current ~/config/dashboard.config, permissions issue?");
                XDocument dashboardDoc = XDocument.Parse(dashboardConfig, LoadOptions.PreserveWhitespace);
                if (dashboardDoc == null)
                    throw new Exception("Unable to add dashboard: Unable to parse current ~/config/dashboard.config file, invalid XML?");
                XElement dashBoardElement = dashboardDoc.Element("dashBoard");
                if (dashBoardElement == null)
                    throw new Exception("Unable to add dashboard: dashBoard element not found in ~/config/dashboard.config file");
                List<XElement> sectionElements = dashBoardElement.Elements("section").ToList();
                if (sectionElements == null || !sectionElements.Any())
                    throw new Exception("Unable to add dashboard: No section elements found in ~/config/dashboard.config file");
                XElement existingSectionElement = sectionElements.SingleOrDefault(x => x.Attribute("alias") != null && x.Attribute("alias").Value == section);
                if (existingSectionElement == null)
                    throw new Exception(string.Format("Unable to add dashboard: '{0}' section not found in ~/config/dashboard.config", section));

                List<XElement> tabs = existingSectionElement.Elements("tab").ToList();
                if (!tabs.Any())
                    throw new Exception(string.Format("Unable to add dashboard: No existing tabs found within the '{0}' section", section));

                List<XElement> existingTabs = tabs.Where(x => x.Attribute("caption").Value == caption).ToList();
                if (existingTabs.Any())
                {
                    foreach (XElement tab in existingTabs)
                    {
                        List<XElement> existingTabControls = tab.Elements("control").ToList();
                        if (existingTabControls.Any(x => x.Value == control))
                            return true;
                    }
                }

                XElement lastTab = tabs.Last();
                XElement newTab = new XElement("tab");
                newTab.Add(new XAttribute("caption", caption));
                XElement newControl = new XElement("control");
                newControl.Add(new XAttribute("addPanel", true));
                newControl.SetValue(control);
                newTab.Add(newControl);
                newControl.AddBeforeSelf(string.Concat(Environment.NewLine, "      "));
                newControl.AddAfterSelf(string.Concat(Environment.NewLine, "    "));
                lastTab.AddAfterSelf(newTab);
                lastTab.AddAfterSelf(string.Concat(Environment.NewLine, "    "));
                dashboardDoc.Save(dashboardConfigPath, SaveOptions.None);
                result = true;
            }
            catch (Exception ex)
            {
                ExceptionHelper.LogExceptionMessage(typeof(DashboardHelper), ex);
            }
            return result;
        }
Beispiel #17
0
 public XElement Serialize()
 {
     var sbEl = new XElement("ScoreBoost");
     sbEl.SetAttributeValue("Score", Score.ToString(CultureInfo.InvariantCulture));
     sbEl.SetAttributeValue("Plain", plain.ToString(CultureInfo.InvariantCulture));
     sbEl.SetValue(matchStr);
     return sbEl;
 }
Beispiel #18
0
        public static XElement Export(SynergyV5List lst)
        {
            XElement synergyListEl =
                    new XElement(TAG_SYNERGY_LIST);

            synergyListEl.Add(new XAttribute(ATTRIBUTE_LIST_NAME, lst.ListName));

            string activatedAt =
                TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(lst.ActivatedAt);
            string shelvedAt =
                TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(lst.ShelvedAt);

            synergyListEl.Add(
                new XAttribute(ATTRIBUTE_ACTIVATED_AT, activatedAt));
            synergyListEl.Add(
                new XAttribute(ATTRIBUTE_SHELVED_AT, shelvedAt));

            for (int i = 0; i < lst.ListItems.Count; i++)
            {
                SynergyV5ListItem item = lst.ListItems[i];

                XElement synergyItemEl =
                    new XElement(TAG_SYNERGY_ITEM);

                synergyItemEl.Add(new XAttribute(ATTRIBUTE_POSITION, i));

                XElement itemValueEl =
                    new XElement(TAG_ITEM_VALUE);

                itemValueEl.SetValue(item.ItemValue);

                synergyItemEl.Add(itemValueEl);

                SynergyV5ToDo toDo = item.ToDo;

                if (toDo != null)
                {
                    string toDoActivatedAt =
                        TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.ActivatedAt);
                    string toDoCompletedAt =
                        TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.CompletedAt);
                    string toDoArchivedAt =
                        TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.ArchivedAt);

                    XElement toDoEl =
                        new XElement(TAG_TO_DO,
                            new XAttribute(ATTRIBUTE_ACTIVATED_AT, toDoActivatedAt),
                            new XAttribute(ATTRIBUTE_COMPLETED_AT, toDoCompletedAt),
                            new XAttribute(ATTRIBUTE_ARCHIVED_AT, toDoArchivedAt));

                    synergyItemEl.Add(toDoEl);
                }

                synergyListEl.Add(synergyItemEl);
            }

            return synergyListEl;
        }
 public void BeforeParsing(XDocument document)
 {
     XElement html = document.Root;
     XElement head = html.Element("head");
     Check.NotNull(head, "<head> section is missing from document");
     XElement style = new XElement("style");
     style.SetValue(this.StylesheetContent);
     head.AddFirst(style);
 }
Beispiel #20
0
 public XElement GetXML()
 {
     var tmp = new XElement("label");
     tmp.SetAttributeValue("kind", kind);
     tmp.SetAttributeValue("x", x);
     tmp.SetAttributeValue("y", y);
     tmp.SetValue(content);
     return tmp;
 }
 public void DocumentParsingEventHandler(object sender, DocumentParsingEventArgs e)
 {
     XElement html = e.Document.Root;
     XElement head = html.Element("head");
     Check.NotNull(head, "<head> section is missing from document");
     XElement style = new XElement("style");
     style.SetValue(StylesheetContent);
     head.AddFirst(style);
 } 
 public void BeforeParsing(XDocument document)
 {
     var html = document.Root;
     var head = html.Element("head");
     Check.NotNull(head, "<head> section is missing from document");
     m_Script = new XElement("script");
     m_Script.SetAttributeValue(XName.Get("type"), "text/javascript");
     m_Script.SetValue("");
     head.Add(m_Script);
 }
        /// <summary>
        /// Fills the XML data.
        /// </summary>
        /// <param name="xml">The XML.</param>
        protected override void FillXmlData(XElement xml)
        {
            base.FillXmlData(xml);
            xml.SetValue("ArticleCount", this.ImageCollection.Count.ToString(), true);

            if (this.ImageCollection != null)
            {
                xml.Add(this.ImageCollection.ToXml());
            }
        }
 public void BeforeParsing(XDocument document)
 {
     var html = document.Root;
     var head = html.Element("head");
     Check.NotNull(head, "<head> section is missing from document");
     m_Link = new XElement("link");
     m_Link.SetAttributeValue(XName.Get("type"), "text/css");
     m_Link.SetAttributeValue(XName.Get("rel"), "stylesheet");
     m_Link.SetValue("");
     head.Add(m_Link);
 }
Beispiel #25
0
        public void InstantiateElement_CanInstantiateValue_WhenInteger()
        {
            var sut = GetSUT();

            var expected = 13;
            var elem = new XElement("tag");
            elem.SetValue(expected);

            var actual = sut.InstantiateFromElement(elem, null);
            Assert.AreEqual(expected.ToString(), actual);
        }
 //
 internal static XElement createConditionData(String _timestamp, String _value, String _condition, String _sequence, String _nativeCode, String _code)
 {
     XElement re = new XElement("Data", new XAttribute("timestamp", _timestamp), new XAttribute("sequence", _sequence), new XAttribute("condition", _condition));
     if (_nativeCode != null)
         re.Add(new XAttribute("nativeCode", _nativeCode));
     if (_code != null)
         re.Add(new XAttribute("code", _code));
     if(_value!=null)
     re.SetValue(_value);
     return re;
 }
        public CsProjPropertyValue(XElement element, object replacementValue = null)
        {
            _element = element;

            if (replacementValue != null && _element != null &&
                ((replacementValue is string && _element.Value != replacementValue.ToString().TrimEnd()) ||
                (!(replacementValue is string) && _element.Value.ToLower() != replacementValue.ToString().TrimEnd().ToLower())))
            {
                _element.SetValue(replacementValue.ToString().TrimEnd());
            }
        }
Beispiel #28
0
 public string ToXML()
 {
     XElement domain = new XElement("domain");
     XElement domainName = new XElement("name");
     domainName.SetValue(this.Name);
     domain.Add(domainName);
     XElement domainAdmin = new XElement("administrator");
     domainAdmin.SetValue(this.Adminstrator);
     domain.Add(domainAdmin);
     XElement adminPassword = new XElement("password");
     adminPassword.SetValue(this.Password);
     domain.Add(adminPassword);
     return domain.ToString();
 }
Beispiel #29
0
        private void btnguardar_Click(object sender, EventArgs e)
        {
            string file = Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf('\\') + 1) + "conexion.xml";
            XDocument doc = new XDocument();

            XElement xRoot = new XElement("Root");
            doc.Add(xRoot);

            XElement servidor = new XElement("Servidor");
            servidor.SetValue(txtServidor.Text);
            xRoot.Add(servidor);

            doc.Save(file);
            this.Close();
        }
        private XElement MapUrl(Url url)
        {
            DateTime expires;
            if (url.Expires == null) expires = new DateTime(2999, 12, 31);
            else expires = (DateTime)url.Expires;

            XElement u = new XElement("url");
            u.SetAttributeValue("id", url.Id);
            u.SetAttributeValue("src", url.Src);
            u.SetAttributeValue("userid", url.UserId);
            u.SetAttributeValue("created", url.CreatedOn.ToString("o"));
            u.SetAttributeValue("expires", expires.ToString("o"));
            u.SetValue(url.Redirect);

            return u;
        }
        private static byte[] GetCreateFileRequestContent(String displayName, String mediaType, Encoding encoding)
        {
            XDocument document = new XDocument(new XDeclaration("1.0", encoding.BodyName, "yes"));
            XElement root = new XElement("file");

            XElement displayNameElement = new XElement("displayName");
            displayNameElement.SetValue(displayName);
            root.Add(displayNameElement);

            XElement mediaTypeElement = new XElement("mediaType");
            mediaTypeElement.SetValue(mediaType);
            root.Add(mediaTypeElement);

            document.Add(root);
            return document.Encode(encoding);
        }
Beispiel #32
0
        /// <summary>
        /// To the XML.
        /// </summary>
        /// <param name="baseElement">The base element.</param>
        /// <param name="AddCommonAttributes">if set to <c>true</c> [add common attributes].</param>
        /// <returns></returns>
        public override System.Xml.Linq.XElement ToXml(System.Xml.Linq.XElement baseElement, bool AddCommonAttributes)
        {
            baseElement.SetAttributeValue("name", this.Name);
            baseElement.SetAttributeValue("controlType", this.ControlType);
            baseElement.SetAttributeValue("target", this.Target);
            baseElement.SetAttributeValue("isDefault", this.IsDefault);
            StringBuilder value = new StringBuilder();

            value.AppendLine();
            foreach (string key in _styleAttributes.Keys)
            {
                string serializedAttribute = string.Format("{0}:{1};", key, _styleAttributes[key]);
                value.Append("          ");
                value.AppendLine(serializedAttribute);
            }
            value.Append("      ");
            baseElement.SetValue(value.ToString());
            return(baseElement);
        }