public static XElement DumpAssembly(string assemblyFile, bool includeParentMemebers=false) { AssemblyDefinition source = AssemblyDefinition.ReadAssembly(assemblyFile); if (source == null) { return null; } List<TypeDefinition> sourceTypes; try { sourceTypes = source.Modules.SelectMany(m => m.Types).Where(t => t.IsPublic).ToList(); (source.MainModule.AssemblyResolver as DefaultAssemblyResolver).AddSearchDirectory(Path.GetDirectoryName(assemblyFile)); sourceTypes.AddRange(source.Modules.SelectMany(m => m.ExportedTypes).Select(r => r.Resolve()).Where(t => t.IsPublic)); } catch (Exception) { //we don't care about broken or empty files return null; } XElement asmXml = new XElement("Assembly"); asmXml.SetAttributeValue("Name", source.Name.Name); asmXml.SetAttributeValue("Info", source.FullName); foreach (TypeDefinition typeDefinition in sourceTypes) { asmXml.Add(DumpType(typeDefinition, includeParentMemebers)); } return asmXml; }
public XElement getXElement() { XElement battleElement = new XElement(battleType.ToString("G")); battleElement.SetAttributeValue("map", "1"); battleElement.SetAttributeValue("areasenable", battleName + ".bin"); XElement countryNode = new XElement("list"); countryNode.SetAttributeValue("name", "country"); foreach (Country country in countryList) { countryNode.Add(country.getXElement()); } XElement areaNode = new XElement("list"); areaNode.SetAttributeValue("name", "area"); foreach (Area area in areaList) { areaNode.Add(area.getXElement()); } XElement dialogueNode = new XElement("list"); dialogueNode.SetAttributeValue("name", "dialogue"); if (battleType == BattleType.battle) { foreach (Dialogue dialogue in dialogueList) { dialogueNode.Add(dialogue.getXElement()); } } battleElement.Add(countryNode); battleElement.Add(areaNode); battleElement.Add(dialogueNode); return battleElement; }
public virtual void ParseScheduleDataToXmlNode(XElement node, TallySchedule scheduleDataEntry) { node.SetAttributeValue("frequency", scheduleDataEntry.Frequency); node.SetAttributeValue("dayOfWeek", scheduleDataEntry.DayofWeek); node.SetAttributeValue("date", scheduleDataEntry.StartDate); var lastExecutedDate = node.TryGet(p => p.Attribute("lastExecutedDate"), p => p.Value); node.SetAttributeValue("lastExecutedDate", lastExecutedDate); var hasExecuted = node.TryGet(p => p.Attribute("hasExecuted"), p => p.Value).ToBoolean(false); if (scheduleDataEntry.HasExecuteChanged) { hasExecuted = false; } node.SetAttributeValue("hasExecuted", hasExecuted); node.SetAttributeValue("action", scheduleDataEntry.ActionType); node.SetAttributeValue("fromAccountId", scheduleDataEntry.FromAccountId); node.SetAttributeValue("toAccountId", scheduleDataEntry.ToAccountId); node.SetAttributeValue("categoryId", scheduleDataEntry.CategoryId); node.SetAttributeValue("amount", scheduleDataEntry.Money); node.SetAttributeValue("currency", scheduleDataEntry.Currency); node.SetAttributeValue("notes", scheduleDataEntry.Notes); node.SetAttributeValue("itemType", (int)scheduleDataEntry.RecordType); node.SetAttributeValue("isClaim", scheduleDataEntry.IsClaim); node.SetAttributeValue("active", scheduleDataEntry.IsActive); node.SetAttributeValue("transferingPoundageAmount", scheduleDataEntry.TransferingPoundageAmount); node.SetAttributeValue("dataProvider", scheduleDataEntry.DataProvider); node.SetAttributeValue("actionHandlerType", scheduleDataEntry.ActionHandlerType); node.SetAttributeValue("actionHandlerType", scheduleDataEntry.ActionHandlerType); node.SetAttributeValue("pictureIds", scheduleDataEntry.PictureIds); node.SetAttributeValue("peopleIds", scheduleDataEntry.PeopleIds); }
public void Stage(DeploymentStager stager, XElement xmlElement) { FileInfo file = new FileInfo(path); // Get the pre-compress data. hash = FileVerification.GetSHA1Hash(path); size = file.Length; // Compress. if (!Directory.Exists("staging")) Directory.CreateDirectory("staging"); string compressPath = "staging\\" + file.Name + ".lzma"; SevenzipCompresser compresser = new SevenzipCompresser(path); int ExitCode = compresser.compress(compressPath); // Get the data for the compressed file. FileInfo archive = new FileInfo(compressPath); downloadHash = FileVerification.GetSHA1Hash(compressPath); downloadSize = archive.Length; // Update the XML. xmlElement.SetAttributeValue("hash", hash); xmlElement.SetAttributeValue("downloadHash", downloadHash); xmlElement.SetAttributeValue("size", size); xmlElement.SetAttributeValue("downloadSize", downloadSize); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { // Add the Mobile Web Part Adapter to the compat.browser file SPWebApplication webApp = null; if (properties.Feature.Parent is SPSite) { SPSite spSite = properties.Feature.Parent as SPSite; webApp = spSite.WebApplication; } else if (properties.Feature.Parent is SPWebApplication) { webApp = properties.Feature.Parent as SPWebApplication; } String pathToCompatBrowser = webApp.IisSettings[SPUrlZone.Default].Path + @"\App_Browsers\compat.browser"; XElement compatBrowser = XElement.Load(pathToCompatBrowser); // Get the node for the default browser. XElement controlAdapters = compatBrowser.XPathSelectElement("./browser[@refID = \"default\"]/controlAdapters"); // Create and add the markup. XElement newAdapter = new XElement("adapter"); newAdapter.SetAttributeValue("controlType", controlType); newAdapter.SetAttributeValue("adapterType", webPartFQN); controlAdapters.Add(newAdapter); compatBrowser.Save(pathToCompatBrowser); } catch { } }
public static void Generate() { using (var db = new SalesContext()) { var sales = new XElement("sales"); foreach (var supermarket in db.Supermarkets) { var sale = new XElement("sale"); sale.SetAttributeValue("vendor", supermarket.Name); var records = db.Records .Where(x => x.Supermarket.Id == supermarket.Id) .GroupBy(x => x.Date) .OrderBy(x => x.Key) .Select(x => new { Date = x.Key, Sum = x.Sum(y => y.Quantity * y.UnitPrice) }); foreach (var record in records) { var summary = new XElement("summary"); summary.SetAttributeValue("date", record.Date.ToShortDateString()); summary.SetAttributeValue("total-sum", record.Sum.ToString("00")); sale.Add(summary); } sales.Add(sale); } sales.Save(FilePath); //Console.WriteLine(File.ReadAllText(FilePath)); } }
void UpdateVs2010Compatibility(XDocument document, string file) { var elements = document.Descendants().Where(element => element.Name.LocalName == "VSToolsPath" || element.Name.LocalName == "VisualStudioVersion" ); var xElements = elements as XElement[] ?? elements.ToArray(); bool save=xElements.Any(); xElements.Remove(); elements=document.Descendants().Where(element => element.Name.LocalName == "Import" && (element.Attribute("Project").Value.StartsWith("$(MSBuildExtensionsPath)")|| element.Attribute("Project").Value.StartsWith("$(MSBuildExtensionsPath32)"))); var enumerable = elements as XElement[] ?? elements.ToArray(); if (!save) save = enumerable.Any(); if (IsWeb(document, GetOutputType(document))&& !document.Descendants().Any(element => element.Name.LocalName == "Import" && element.Attribute("Project").Value.StartsWith("$(VSToolsPath)")&& element.Attribute("Condition").Value.StartsWith("'$(VSToolsPath)' != ''"))) { var element = new XElement(_xNamespace+"Import"); element.SetAttributeValue("Project",@"$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets"); element.SetAttributeValue("Condition", @"'$(VSToolsPath)' != ''"); Debug.Assert(document.Root != null, "document.Root != null"); document.Root.Add(element); save = true; } enumerable.Remove(); if (save) DocumentHelper.Save(document, file); }
public XElement GetData() { XElement data = new XElement(XMLName); data.SetAttributeValue("Name", Name); data.SetAttributeValue("Type", Type); return data; }
public static void SaveBundleFromViewModel(BundleViewModel bundle, string bundleType) { var doc = XDocument.Load(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); var bundleEl = new XElement(bundleType + "Bundle"); if (doc.Descendants(bundleType + "Bundle").Any(x => x.Attribute("virtualPath").Value == bundle.VirtualPath)) bundleEl = doc.Descendants(bundleType + "Bundle") .Single(x => x.Attribute("virtualPath").Value == bundle.VirtualPath); else { bundleEl.SetAttributeValue("virtualPath", bundle.VirtualPath); doc.Descendants("bundles").Single().Add(bundleEl); } bundleEl.SetAttributeValue("disableMinification", bundle.DisableMinification.ToString()); bundleEl.Elements().Remove(); if (bundle.Files != null) { foreach (var file in bundle.Files) { var includeEl = new XElement("include"); includeEl.SetAttributeValue("virtualPath", file); bundleEl.Add(includeEl); } } doc.Save(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); HttpRuntime.UnloadAppDomain(); }
/// <summary> /// Adds a button from navigation link. /// </summary> /// <param name="navigationLinkItem">The navigation link item.</param> /// <param name="addFirst">if set to <c>true</c> [add first].</param> /// <returns></returns> public bool AddButtonFromNavigationLink(Item navigationLinkItem, bool addFirst) { XElement submitDiv = (from f in this.firstPart.Descendants() where f.Attribute("type") != null && f.Attribute("type").Value == "submit" select f.Parent).FirstOrDefault(); if (submitDiv != null) { string title = Utils.ItemUtil.GetNavigationLinkTitle(navigationLinkItem); string path = Utils.ItemUtil.GetNavigationLinkPath(navigationLinkItem); var btn = new XElement("input"); btn.SetAttributeValue("type", "submit"); btn.SetAttributeValue("value", title); btn.SetAttributeValue("onclick", "javascript:location.href='" + path + "';return false;"); if (addFirst) { submitDiv.AddFirst(btn); } else { submitDiv.Add(btn); } this.args.Result.FirstPart = this.GetResultFirstPart(); return true; } return false; }
/// <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("class", this.ClassStyle); baseElement.SetAttributeValue("default", this.IsDefault.ToString()); return(baseElement); }
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 static void CreateXml(string filePath) { using (SupermarketDBContext sqldb = new SupermarketDBContext()) { string format = "dd-MMM-yyyy"; XElement sales = new XElement("sales"); foreach (var vendor in sqldb.Vendors.ToList().Where( x=> x.Products.Any(y => y.SalesReports.Count > 0))) { XElement elSale = new XElement("sale"); elSale.SetAttributeValue("vendor", vendor.VendorName.ToString()); foreach (var product in vendor.Products.ToList()) { foreach (var report in product.SalesReports.ToList()) { XElement summary = new XElement("summary"); summary.SetAttributeValue("date", report.ReportDate.ToString(format)); summary.SetAttributeValue("total-sum", report.Sum.ToString()); elSale.Add(summary); } } sales.Add(elSale); } sales.Save(filePath); } }
private static void ExportGamesToXml(IEnumerable<FinishedGame> games) { var doc = new XDocument(); var rootNode = new XElement("games"); doc.Add(rootNode); foreach (var game in games) { var gameNode = new XElement("game"); gameNode.SetAttributeValue("name", game.Name); if (game.Duration != null) { gameNode.SetAttributeValue("duration", game.Duration); } var usersNode = new XElement("users"); gameNode.Add(usersNode); foreach (var user in game.Users) { var userNode = new XElement("user"); userNode.SetAttributeValue("username", user.Username); userNode.SetAttributeValue("ip-address", user.IpAddress); usersNode.Add(userNode); } rootNode.Add(gameNode); } doc.Save(ExportPath + Filename); Console.WriteLine("File path: {0}", Path.GetFullPath(ExportPath + Filename)); }
public void CreateConfigFile(Config config) { XDocument xdoc = new XDocument(); xdoc.Declaration = new XDeclaration("1.0", "utf-8", "no"); XElement root = new XElement("Config"); XElement element = new XElement("Map"); element.SetAttributeValue("ShowGrid", config.ShowMapGrid ?? "On"); element.SetAttributeValue("BottomAxes", config.BottomAxes ?? "CD"); element.SetAttributeValue("MDInverse", config.MDInverse); element.SetAttributeValue("CDInverse", config.CDInverse); element.SetAttributeValue("BackgroundColor", config.BackgroundColor ?? "#FFFFFF"); element.SetAttributeValue("GridColor", config.GridColor ?? "#AFAFAF"); element.SetAttributeValue("XPrecision", config.XPrecision); element.SetAttributeValue("YPrecision", config.YPrecision); element.SetAttributeValue("ScrollingRange", config.ScrollingRange ?? ""); root.Add(element); foreach (var item in config.Legends) { XElement el = new XElement("Legend"); el.SetAttributeValue("ClassID", item.ClassID); el.SetAttributeValue("Name", item.Name); el.SetAttributeValue("Color", item.Color); el.SetAttributeValue("Shape", item.Shape); root.Add(el); } xdoc.Add(root); if (!Directory.Exists(_xmlDirectory)) { Directory.CreateDirectory(_xmlDirectory); } xdoc.Save(_xmlPath); }
private string CreateXDT(BuildConfig config) { XNamespace xdt = "http://schemas.microsoft.com/XML-Document-Transform"; var doc = XDocument.Parse("<?xml version=\"1.0\"?><configuration xmlns:xdt=\"http://schemas.microsoft.com/XML-Document-Transform\"></configuration>"); var connectionStrings = new XElement(XName.Get("connectionStrings")); doc.Root.Add(connectionStrings); foreach (var item in config.ConnectionStrings) { XElement cnstr = new XElement(XName.Get("add")); connectionStrings.Add(cnstr); cnstr.SetAttributeValue(XName.Get("name"), item.Name); cnstr.SetAttributeValue(XName.Get("connectionString"), item.ConnectionString); cnstr.SetAttributeValue(xdt + "Transform", "SetAttributes"); cnstr.SetAttributeValue(xdt + "Locator", "Match(name)"); if(item.ProviderName!=null){ cnstr.SetAttributeValue(XName.Get("providerName"), item.ProviderName); } } var appSettings = new XElement(XName.Get("appSettings")); doc.Root.Add(appSettings); foreach (var item in config.AppSettings) { XElement cnstr = new XElement(XName.Get("add")); appSettings.Add(cnstr); cnstr.SetAttributeValue(XName.Get("key"), item.Key); cnstr.SetAttributeValue(XName.Get("value"), item.Value); cnstr.SetAttributeValue(xdt + "Transform", "SetAttributes"); cnstr.SetAttributeValue(xdt + "Locator", "Match(key)"); } return doc.ToString(SaveOptions.OmitDuplicateNamespaces); }
public static ICollection<XElement> GetPlaceResultForMobile(Mobile.Server.Transaction transaction, Token token) { ICollection<XElement> elements = new List<XElement>(); if (token != null && token.AppType == AppType.Mobile) { Token placeToken = new Token(token.UserID, token.UserType, AppType.TradingConsole); string tranCode; TransactionError error = Application.Default.TradingConsoleServer.Place(placeToken, Application.Default.StateServer, transaction.ToXmlNode(), out tranCode); if (error == TransactionError.Action_ShouldAutoFill) { error = TransactionError.OK; } foreach (Mobile.Server.Order order in transaction.Orders) { XElement orderErrorElement = new XElement("Order"); orderErrorElement.SetAttributeValue("Id", order.Id); orderErrorElement.SetAttributeValue("ErrorCode", error.ToString()); elements.Add(orderErrorElement); } Mobile.Manager.UpdateWorkingOrder(token, transaction.Id, error); return elements; } return null; }
internal XElement Serialize() { XElement xElement = new XElement(this.ns + "Role"); xElement.SetAttributeValue("name", this.Name); XElement xElement1 = new XElement(this.ns + "Instances"); xElement1.SetAttributeValue("count", this.InstanceCount); xElement.Add(xElement1); XElement xElement2 = new XElement(this.ns + "ConfigurationSettings"); xElement.Add(xElement2); foreach (KeyValuePair<string, string> setting in this.Settings) { XElement xElement3 = new XElement(this.ns + "Setting"); xElement3.SetAttributeValue("name", setting.Key); xElement3.SetAttributeValue("value", setting.Value); xElement2.Add(xElement3); } XElement xElement4 = new XElement(this.ns + "Certificates"); xElement.Add(xElement4); foreach (KeyValuePair<string, CertificateConfiguration> certificate in this.Certificates) { XElement xElement5 = new XElement(this.ns + "Certificate"); xElement5.SetAttributeValue("name", certificate.Key); xElement5.SetAttributeValue("thumbprint", certificate.Value.Thumbprint); xElement5.SetAttributeValue("thumbprintAlgorithm", certificate.Value.ThumbprintAlgorithm); xElement4.Add(xElement5); } return xElement; }
public static void ProjectOpened(Project project) { XDocument document; if (!File.Exists(Path.Combine(MainWindow.UserPath, "Settings", "recent.xml"))) { document = new XDocument(); document.Add(new XElement("projects")); } else document = XDocument.Load(Path.Combine(MainWindow.UserPath, "Settings", "recent.xml")); var newProject = new XElement("project"); newProject.SetAttributeValue("config", project.File); newProject.SetAttributeValue("name", project.Name); XElement toRemove = null; foreach (var element in document.Root.Elements()) { if (element.Attribute("config").Value == newProject.Attribute("config").Value) { toRemove = element; break; } } if (toRemove != null) toRemove.Remove(); document.Root.AddFirst(newProject); if (document.Root.Elements().Count() > 10) { var elements = document.Root.Elements().Take(10); document.Root.RemoveAll(); document.Root.Add(elements); } document.Save(Path.Combine(MainWindow.UserPath, "Settings", "recent.xml")); }
public bool AddUser(string sessionId, User user) { lock (this._SycBlock) { if (!ClientManager.Default.Contains(sessionId)) return false; if (IsUserExistWhenAdd(user)) return false; try { user.LastModifedDate = DateTime.Now; user.Id = Guid.NewGuid(); XElement root = XElement.Load(configFile); XElement userElement = new XElement("User"); userElement.SetAttributeValue("Id", user.Id.ToString()); userElement.SetAttributeValue("Name", user.Name); userElement.SetAttributeValue("Pwd", user.Pwd); userElement.SetAttributeValue("Date", user.LastModifedDate.ToStandardDatetimeString()); root.Add(userElement); root.Save(configFile); user.Operation = UserOperateEnum.Added; ClientManager.Default.Push(new UserMsg(user)); return true; } catch (Exception exception) { AppDebug.LogEvent("ManagerService.QuotationManager.Service.AddUser", exception.ToString(), EventLogEntryType.Error); return false; } } }
/// <summary> /// Exports to XML all remaining products and the shops they are located in /// </summary> /// <param name="db"></param> public static void RemainingQuantities() { //create root element and database var db = new SQLServerContextFactory().Create(); XElement root = new XElement("products"); //make a collection with all the data you want to export to XML. Use as many joins as needed var products = db.Products.OrderBy(p => p.QuantityInStock); //go through all items in the collection foreach (var product in products) { //for every nested element you must create new instance of XElement XElement currentProduct = new XElement("product"); //create tag currentProduct.SetAttributeValue("name", product.Name); //set attribute currentProduct.SetAttributeValue("description", product.Description); //set another attribute XElement productInfo = new XElement("info"); //nest element after "Product" productInfo.Add(new XElement("price", product.Price)); //add element inside "Info" //you can create those as new XElement like the creation of "Info" productInfo.Add(new XElement("quantity", product.QuantityInStock)); //add info to product currentProduct.Add(productInfo); //add current set of tags to root root.Add(currentProduct); } string methodName = MethodBase.GetCurrentMethod().Name; root.Save(Helpers.NamingFactory.BuildName(methodName, fileType)); }
private SXL.XElement _ToXml(string elname) { if (this.Formula != null || this.HasResult) { var el = new SXL.XElement(elname); if (this.HasResult) { el.Value = this.GetResultString(); } if (this.Formula != null) { el.SetAttributeValue("F", this.Formula); } if (this.Unit == CellUnit.Inch) { el.SetAttributeValue("Unit", "IN"); } else if (this.Unit == CellUnit.Point) { el.SetAttributeValue("Unit", "PT"); } return el; } return null; }
public void Write(Project project) { var file = Path.Combine(project.Directory, PackagesConfig); XElement document; if (_fileSystem.FileExists(file)) { document = XElement.Load(file); document.RemoveAll(); } else { document = new XElement("packages"); } project.Dependencies.Each(x => { var package = new XElement("package"); package.SetAttributeValue("id", x.Name); // TODO -- Make this easier to query var solutionLevel = project.Solution.Dependencies.Find(x.Name); package.SetAttributeValue("version", solutionLevel.Version.ToString()); // TODO -- Probably shouldn't hardcode this... package.SetAttributeValue("targetFramework", "net40"); document.Add(package); }); document.Save(file); }
private void AddCompositePrimaryKey() { var id = new XElement(_xmlns + "composite-id"); id.SetAttributeValue("name", "Key"); id.SetAttributeValue("class", _table.NetName + "Key"); foreach (string colName in _table.PrimaryKey.Columns) { //two possibilities: //* <key-property name="OrderId" column="Order_Id" /> //* <key-many-to-one name="Order" column="Order_Id" /> var keyType = "key-property"; //"key-many-to-one"; var column = _table.FindColumn(colName); if (column == null) continue; //corruption in our model //if (column.ForeignKeyTable == null) //{ // //the database may be missing a fk reference // keyType = "key-property"; //} var propertyName = _codeWriterSettings.Namer.PrimaryKeyName(column); var key = new XElement(_xmlns + keyType); key.SetAttributeValue("column", SqlSafe(colName)); key.SetAttributeValue("name", propertyName); //if (column.ForeignKeyTable != null) // key.SetAttributeValue("class", column.ForeignKeyTable.NetName); id.Add(key); } _classElement.Add(id); }
public XElement getXElement() { XElement battle = new XElement("battle"); battle.SetAttributeValue("map", map); if (battleName != "") { battle.SetAttributeValue("areasenable", battleName + ".bin"); } XElement countryNode = new XElement("list"); countryNode.SetAttributeValue("name", "country"); foreach (Country country in countryList) { countryNode.Add(country.getXElement()); } XElement areaNode = new XElement("list"); areaNode.SetAttributeValue("name", "area"); foreach (Area area in areaList) { areaNode.Add(area.getXElement()); } battle.Add(countryNode); battle.Add(areaNode); return battle; }
private SXL.XElement _ToXml(string elname) { if (this.Formula != null || this.HasResult) { var el = new SXL.XElement(elname); if (this.HasResult) { el.Value = this.GetResultString(); } if (this.Formula != null) { el.SetAttributeValue("F", this.Formula); } if (this.Unit == CellUnit.Inch) { el.SetAttributeValue("Unit", "IN"); } else if (this.Unit == CellUnit.Point) { el.SetAttributeValue("Unit", "PT"); } return(el); } return(null); }
public XElement CreateElement() { XElement e = new XElement("graphics"); e.SetAttributeValue("bank", Bank); e.SetAttributeValue("name", Name); return e; }
protected void Page_Load(object sender, EventArgs e) { if (!Request.GetUser().Browse) { Response.StatusCode = 401; return; } Response.Clear(); Response.ContentType = "application/xml"; var result = new XElement("result"); try { var id = RouteData.GetRouteString("ID"); if (string.IsNullOrWhiteSpace(id)) result.Add(Directory.EnumerateFiles(Server.MapPath("~/Data"), "*.task").Select(path => new XElement("task", new XAttribute("id", Path.GetFileNameWithoutExtension(path))))); else { var root = XHelper.Load(FileHelper.GetDataPath(id + ".task")).Root; if (root.AttributeCaseInsensitive("pid") != null) root.SetAttributeValue("running", !CloudTask.IsBackgroundRunnerKilled(root.GetAttributeValue<int>("pid"))); result.Add(root); } } catch (Exception exc) { result.SetAttributeValue("status", "error"); result.SetAttributeValue("message", exc.GetMessage()); } Response.Write(result.ToString()); }
private void AddContentTypeMetadata(XElement head) { var meta = new XElement("meta"); meta.SetAttributeValue("http-equiv", "content-type"); meta.SetAttributeValue("content", "text/html; charset=UTF-8"); head.AddFirst(meta); }
private void HandleTarget(BSharpBuilderWriteTarget target) { foreach (var bsClass in target.Entity.Elements()) { var bSharpClass = new XElement(BSharpBuilderDefaults.BSharpClassContainerName); var bSharpIndexSet = new XElement( BSharpBuilderDefaults.DefaultClassIndexContainerName, bSharpClass ); var writeTarget = new BSharpBuilderWriteTarget { Directory = Project.GetOutputDirectory(), Entity = bSharpIndexSet, EntityContainerName = BSharpBuilderDefaults.DefaultClassIndexContainerName, Extension = BSharpBuilderDefaults.IndexFileExtension, Filename = BSharpBuilderDefaults.IndexFileName, MergeIfExists = true }; WriteIndexAttributeIfExists(bSharpClass, bsClass,BSharpSyntax.ClassNameAttribute); WriteIndexAttributeIfExists(bSharpClass, bsClass, BSharpSyntax.ClassPrototypeAttribute); WriteIndexAttributeIfExists(bSharpClass, bsClass, BSharpSyntax.ClassRuntimeAttribute); bSharpClass.SetAttributeValue("file", target.Path.Remove(0, Project.GetOutputDirectory().Length).Replace("\\","/")); if (bsClass.Attribute(BSharpSyntax.ClassFullNameAttribute) != null) { bSharpClass.SetAttributeValue(BSharpSyntax.Namespace, BSharpBuilderClassUtils.GetNamespace(bsClass.Attribute(BSharpSyntax.ClassFullNameAttribute).Value)); } WriteManager.Add(writeTarget); } }
public XElement getXML() { XElement locationElement = new XElement("location"); locationElement.SetAttributeValue("id", id); locationElement.SetAttributeValue("x", x); locationElement.SetAttributeValue("y", y); XElement nameElement = new XElement("name", name); nameElement.SetAttributeValue("x", x + Constants.LabelOffsetX); nameElement.SetAttributeValue("y", y - Constants.LabelOffsetY); locationElement.Add(nameElement); if(Label != null) { locationElement.Add(Label.GetXML()); } if(Urgent) { locationElement.Add(new XElement("urgent")); return locationElement; } if (Committed) { locationElement.Add(new XElement("committed")); return locationElement; } return locationElement; }
public void Serialize(System.Xml.Linq.XElement node, XmlSerializeContext context) { if (this.Name.IsNotEmpty()) { node.SetAttributeValue("_N", this.Name); } if (this.MessageTemplate.IsNotEmpty()) { node.SetAttributeValue("_MT", this.MessageTemplate); } if (this.Tag.IsNotEmpty()) { node.SetAttributeValue("_tag", this.Tag); } if (this.TypeDescription.IsNotEmpty()) { node.SetAttributeValue("_TD", this.TypeDescription); } if (this._Parameters != null) { this._Parameters.Serialize(node, context); } }
public XElement CreateElement() { XElement e = new XElement("track"); e.SetAttributeValue("value", Value.ToHexString()); e.SetAttributeValue("name", Name); return e; }
/// <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("description", this.Description); baseElement.SetAttributeValue("type", this.PropertyType); return(baseElement); }
void IXElementSerializable.Serialize(System.Xml.Linq.XElement node, XmlSerializeContext context) { XElement items = new XElement(ns + "items"); node.SetAttributeValue(ns + "name", Name); node.SetAttributeValue(ns + "desc", Description); foreach (PropertyValueCollection item in Items) { XElement subitem = new XElement(ns + "item"); item.Serialize(subitem, context); items.Add(subitem); } node.Add(items); }
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); }
public void Serialize(System.Xml.Linq.XElement node, XmlSerializeContext context) { if (this.ParamName.IsNotEmpty()) { node.SetAttributeValue("_parName", this.ParamName); } if (this.DataType != PropertyDataType.String) { node.SetAttributeValue("_dType", this.DataType); } if (this.ParamValue.IsNotEmpty()) { node.SetAttributeValue("_parV", this.ParamValue); } }
/// <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); }
protected override void SetAttributes(System.Xml.Linq.XElement ele, object propertyValue) { IRasterDrawing drawing = propertyValue as IRasterDrawing; ele.SetAttributeValue("filename", drawing.FileName); XElement bandsElement = new XElement("SelectedBandNos"); bandsElement.SetValue(GetSelectedBandNosString(drawing)); ele.Add(bandsElement); }
/// <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); if (!string.IsNullOrEmpty(this.Description)) { baseElement.SetAttributeValue("description", this.Description); } if (!string.IsNullOrEmpty(this.PropertyType)) { baseElement.SetAttributeValue("type", this.PropertyType); } if (!string.IsNullOrEmpty(this.Getter)) { baseElement.SetAttributeValue("getter", this.Getter); } return(baseElement); }
/// <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) { System.Diagnostics.Debug.Assert(baseElement != null, "The XElement shouldn't be null"); baseElement.SetAttributeValue("controlType", this.ControlType); baseElement.SetAttributeValue("refGroupName", this.GroupName); if (this.Exceptions.Count > 0) { StringBuilder exeptionsString = new StringBuilder(); foreach (var key in this.Exceptions.Keys) { if (exeptionsString.Length > 0) { exeptionsString.Append(", "); } exeptionsString.Append(key); exeptionsString.Append("."); exeptionsString.Append(this.Exceptions[key]); } baseElement.SetAttributeValue("except", exeptionsString.ToString()); } return(baseElement); }
public static string EnsureXmlAttribute(this string xml, string name, object value) { System.Xml.Linq.XElement ele = XElement.Parse(xml); if (ele == null) { return(xml); } var att = ele.Attribute(name); if (att == null) { att = new XAttribute(name, value); ele.Add(att); } else { ele.SetAttributeValue(name, value); } return(ele.ToString()); }
public static XElement AddAttribute(this XElement e, string name, int value) { e.SetAttributeValue(name, value); return(e); }
public override System.Xml.Linq.XElement ToXml(System.Xml.Linq.XElement baseElement, bool AddCommonAttributes) { baseElement.SetAttributeValue("name", this.Name); AddToXMLChildElementsByName(baseElement, "classes", this.Classes); return(baseElement); }
public static XElement AddAttribute(this XElement e, XAttribute arribute) { e.SetAttributeValue(arribute.Name, arribute.Value); return(e); }
/// <summary> /// Gets information from Dynamics entity based on FetchXML query /// </summary> /// <param name="FetchXML">Quer</param> /// <param name="top">True for top 50 or all rows</param> /// <returns></returns> public DataTable GetData(String FetchXML, Boolean top) { if (string.IsNullOrEmpty(FetchXML)) { throw new Exception("FetchXML query is empty"); } try { if (service == null) { throw new Exception("No Organization Service Available"); } DataTable dTable = new DataTable(); EntityCollection result = new EntityCollection(); bool AddCol = true; int page = 1; AttributeMetadata mdta; System.Xml.Linq.XElement xe = XElement.Parse(FetchXML.Trim()); if (xe.Attribute("mapping") == null) { xe.SetAttributeValue("mapping", "logical"); } do { if (top) { if (xe.Attribute("distinct") == null) { xe.SetAttributeValue("distinct", "false"); } if (xe.Attribute("count") == null) { xe.SetAttributeValue("count", "50"); } else { xe.Attribute("count").SetValue("50"); } result = service.RetrieveMultiple(new FetchExpression(xe.ToString())); result.MoreRecords = false; } else { if (xe.Attribute("paging-cookie") == null) { xe.SetAttributeValue("paging-cookie", result.PagingCookie); } else { xe.Attribute("paging-cookie").SetValue(result.PagingCookie); } if (xe.Attribute("count") == null) { xe.SetAttributeValue("count", "5000"); } if (xe.Attribute("page") == null) { xe.SetAttributeValue("page", System.Convert.ToString(page)); } else { xe.Attribute("page").SetValue(System.Convert.ToString(page)); } page++; result = service.RetrieveMultiple(new FetchExpression(xe.ToString())); } RetrieveEntityRequest mdRequest = new RetrieveEntityRequest() { EntityFilters = EntityFilters.Attributes, LogicalName = result.EntityName, RetrieveAsIfPublished = false }; RetrieveEntityResponse entityResponse = (RetrieveEntityResponse)service.Execute(mdRequest); entMetadata = entityResponse.EntityMetadata; if (AddCol) { foreach (Entity entity in result.Entities) { for (int iElement = 0; iElement <= entity.Attributes.Count - 1; iElement++) { string columnName = entity.Attributes.Keys.ElementAt(iElement); if (!dTable.Columns.Contains(columnName)) { mdta = entMetadata.Attributes.FirstOrDefault(m => m.LogicalName == columnName); if (SupportedTypes.isValidAttribute(mdta)) { switch (mdta.AttributeType.Value) { // break; case AttributeTypeCode.BigInt: dTable.Columns.Add(columnName, typeof(Int64)); break; case AttributeTypeCode.Boolean: dTable.Columns.Add(columnName, typeof(bool)); break; case AttributeTypeCode.DateTime: dTable.Columns.Add(columnName, typeof(DateTime)); break; case AttributeTypeCode.Decimal: dTable.Columns.Add(columnName, typeof(decimal)); break; case AttributeTypeCode.Double: case AttributeTypeCode.Money: dTable.Columns.Add(columnName, typeof(float)); break; case AttributeTypeCode.Integer: case AttributeTypeCode.Picklist: case AttributeTypeCode.State: case AttributeTypeCode.Status: dTable.Columns.Add(columnName, typeof(Int32)); break; case AttributeTypeCode.Uniqueidentifier: case AttributeTypeCode.Customer: case AttributeTypeCode.Lookup: case AttributeTypeCode.PartyList: case AttributeTypeCode.Owner: dTable.Columns.Add(columnName, typeof(Guid)); break; default: dTable.Columns.Add(columnName, typeof(string)); break; } } } } } } else { AddCol = false; } foreach (Entity entity in result.Entities) { DataRow dRow = dTable.NewRow(); for (int i = 0; i <= entity.Attributes.Count - 1; i++) { string colName = entity.Attributes.Keys.ElementAt(i); mdta = entMetadata.Attributes.FirstOrDefault(m => m.LogicalName == colName); if (mdta != null) { switch (mdta.AttributeType.Value) { //case AttributeTypeCode.Boolean: // dRow[colName] = entity.Attributes.Values.ElementAt(i).ToString() == "1" || entity.Attributes.Values.ElementAt(i).ToString().Trim().ToLower() == "true"; // break; case AttributeTypeCode.Picklist: case AttributeTypeCode.State: case AttributeTypeCode.Status: dRow[colName] = ((Microsoft.Xrm.Sdk.OptionSetValue)entity.Attributes.Values.ElementAt(i)).Value; break; case AttributeTypeCode.Customer: case AttributeTypeCode.Lookup: case AttributeTypeCode.PartyList: case AttributeTypeCode.Owner: dRow[colName] = (Guid)((Microsoft.Xrm.Sdk.EntityReference)entity.Attributes.Values.ElementAt(i)).Id; break; case AttributeTypeCode.BigInt: dRow[colName] = (Int64?)entity.Attributes.Values.ElementAt(i); break; case AttributeTypeCode.Decimal: dRow[colName] = (decimal?)entity.Attributes.Values.ElementAt(i); break; case AttributeTypeCode.Double: dRow[colName] = (double?)entity.Attributes.Values.ElementAt(i); break; case AttributeTypeCode.Integer: dRow[colName] = (int?)entity.Attributes.Values.ElementAt(i); break; case AttributeTypeCode.Money: dRow[colName] = ((Microsoft.Xrm.Sdk.Money)entity.Attributes.Values.ElementAt(i)).Value; break; case AttributeTypeCode.DateTime: dRow[colName] = (DateTime?)entity.Attributes.Values.ElementAt(i); break; case AttributeTypeCode.Uniqueidentifier: dRow[colName] = (Guid?)entity.Attributes.Values.ElementAt(i); break; case AttributeTypeCode.Boolean: dRow[colName] = (bool?)entity.Attributes.Values.ElementAt(i); break; default: dRow[colName] = (string)entity.Attributes.Values.ElementAt(i); break; } } } dTable.Rows.Add(dRow); } }while (result.MoreRecords); return(dTable); } catch (Exception e) { throw e; } }
public static void SetAttributeValueDouble(this SXL.XElement el, SXL.XName name, double value) { var culture = System.Globalization.CultureInfo.InvariantCulture; el.SetAttributeValue(name, value.ToString(culture)); }