/// <summary> /// Constructor from XML /// </summary> /// <param name="element"></param> /// <param name="client"></param> public Product(XElement element, IContentAPI client) : this() { this.Client = client; this.DueDate = element.GetChildValueAsDateTime("DueDate"); this.Title = element.GetChildValue("Title"); this.PrimaryCategory = element.GetChildValueAsInt32("PrimaryCategory"); this.TopLevelCategory = element.GetChildValueAsInt32("TopLevelCategory"); this.CategoryPath = element.GetChildValue("CategoryPath"); XElement description = element.Element("Description"); if (description != null) { this.Description = new ProductDescription(description); } this.AssetID = element.GetChildValueAsInt32("AssetID"); this.ProjectURL = element.GetChildValue("ProjectURL"); this.ProjectID = element.GetChildValueAsInt32("ProjectID"); if (element.Element("SourceLanguage") != null) { this.SourceLanguage = new SourceLanguage(element.Element(XName.Get("SourceLanguage"))); } this.SKUs = SKU.CreateEnumerable(element.Element("SKUs")).ToList<SKU>(); XElement targetLanguages = element.Element(XName.Get("TargetLanguages")); if (targetLanguages != null) { this.TargetLanguages = TargetLanguage.CreateEnumerable(targetLanguages).ToArray<TargetLanguage>(); } }
/// <summary> /// Create an AccountInformation instance from an XML string /// </summary> /// <param name="element">An Account element</param> internal AccountInformation(XElement element) : this() { if (element != null) { this.Email = element.GetChildValue("Email"); this.Currency = element.GetChildValue("Currency"); this.TotalSpent = element.GetChildValueAsDecimal("TotalSpent"); this.TranslationCredit = element.GetChildValueAsInt32("TranslationCredit"); this.TranslationCreditUsed = element.GetChildValueAsInt32("TranslationCreditUsed"); this.PrepaidCredit = element.GetChildValueAsDecimal("PrepaidCredit"); this.ProductCount = element.GetChildValueAsInt32("ProductCount"); XElement targetLanguagesElement = element.Element("TargetLanguages"); if (targetLanguagesElement != null) { List<TargetLanguage> targets = new List<TargetLanguage>(); foreach (XElement targetLanguageElement in targetLanguagesElement.Elements("TargetLanguage")) { TargetLanguage targetLanguage = new TargetLanguage(targetLanguageElement); targets.Add(targetLanguage); } this.TargetLanguages = targets; } } }
/// <summary> /// /// </summary> /// <param name="element"></param> public ProductTranslation(XElement element) : this() { // Source SKUs XElement skus = element.Element("SKUs"); if (skus != null) { this.SourceSKUs = SKU.CreateEnumerable(skus).ToArray<SKU>(); } this.AssetID = element.GetChildValueAsInt32("AssetID"); this.SourceTitle = element.GetChildValue("SourceTitle"); this.Service = element.GetChildValueAsInt32("Service"); this.Language = element.GetChildValue("Language"); //Translated Fields XElement translatedFields = element.Element("TranslatedFields"); if (translatedFields != null) { this.Title = translatedFields.GetChildValue("Title"); this.PrimaryCategory = translatedFields.GetChildValueAsInt32("PrimaryCategory"); XElement description = translatedFields.Element("Description"); if (description != null) { this.Description = new ProductDescription(description); } skus = translatedFields.Element("SKUs"); if (skus != null) { this.SKUs = SKU.CreateEnumerable(skus).ToArray<SKU>(); } } }
/// <summary> /// Create an Error instance from an XML element /// </summary> /// <param name="statusCode">The status code from the HTTP web response</param> /// <param name="errorElement">An XML Error element</param> public Error(HttpStatusCode statusCode, XElement errorElement) { /* The error element should have a structure similar to the one shown here: <Error> <ReasonCode>403</ReasonCode> <SimpleMessage>Already exists.</SimpleMessage> <DetailedMessage>A user with this email address already exists.</DetailedMessage> </Error> */ this.HttpStatusCode = statusCode; if (errorElement != null) { this.ReasonCode = errorElement.GetChildValueAsInt32("ReasonCode"); this.SimpleMessage = errorElement.GetChildValue("SimpleMessage"); this.DetailedMessage = errorElement.GetChildValue("DetailedMessage"); if (string.IsNullOrEmpty(this.SimpleMessage) && string.IsNullOrEmpty(this.DetailedMessage)) { this.SimpleMessage = errorElement.Value; } } else { this.SimpleMessage = this.HttpStatusCode.ToString(); } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="client"></param> public ProjectNotification(XElement element, ContentAPI client) : this() { if (element != null) { this.ProjectID = element.GetChildValueAsInt32("ProjectID"); this.Status = element.GetChildValue("Status"); this.URL = new Uri(element.GetChildValue("URL")); this.CreationDate = element.GetChildValueAsDateTime("CreationDate"); this.DueDate = element.GetChildValueAsDateTime("DueDate"); this.CompletionDate = element.GetChildValueAsDateTime("CompletionDate"); XElement errors = element.Element("Errors"); if (errors != null) { foreach (XElement error in errors.Elements("Error")) { this.ErrorsList.Add(error.Value); } } XElement sourceLanguage = element.Element("SourceLanguage"); if (sourceLanguage != null) { this.SourceLanguage = sourceLanguage.GetChildValue("LanguageCode"); } XElement targetLanguages = element.Element("TargetLanguages"); if (targetLanguages != null) { foreach (XElement targetLanguage in targetLanguages.Descendants("LanguageCode")) { this.TargetLanguagesList.Add(targetLanguage.Value); } } XElement products = element.Element("Products"); if (products != null) { this.Products = Product.CreateEnumerable(products, client); } XElement files = element.Element("Files"); if (files != null) { this.Files = File.CreateEnumerable(files, client); } } }
/// <summary> /// Constructor from XML /// </summary> /// <param name="element"></param> internal Locale(XElement element) { if (element != null) { this.Name = element.GetChildValue("Name"); this.Code = element.GetChildValue("Code"); } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="client"></param> public QuoteAuthorization(XElement element, IContentAPI client) { this.Status = element.GetChildValue("Status"); this.PaymentURL = element.GetChildValue("PaymentURL"); this.QuoteURL = element.GetChildValue("QuoteURL"); this.Projects = Project.CreateEnumerable(element.Element("Projects"), client).ToArray(); }
/// <summary> /// Creates an AddCreditBalance object from a response /// </summary> /// <param name="element">The root element</param> internal AddCreditBalance(XElement element) { if (element != null) { this.Amount = element.GetChildValueAsDecimal("Amount"); this.Currency = element.GetChildValue("Currency"); this.PaymentURL = new Uri(element.GetChildValue("PaymentURL")); } }
/// <summary> /// Constructor from XML /// </summary> /// <param name="element"></param> /// <param name="client"></param> internal Payment(XElement element) : this() { if (element != null) { this.Type = element.GetChildValue("PaymentType"); this.Description = element.GetChildValue("PaymentDescription"); this.Currency = element.GetChildValue("PaymentCurrency"); this.Amount = element.GetChildValueAsDecimal("PaymentAmount"); } }
public void TestGetChildValue_SpecialCharacter() { var expect = "D<V>VC&PD IC"; var ele = new XElement("Root", new XElement("Test", expect, new XAttribute("attr",3.4), new XElement("Another", 5))); var value = ele.GetChildValue("Test"); Assert.AreEqual(expect, value); }
/// <summary> /// Create a Source Language from XML /// </summary> /// <param name="element">The SourceLanguage parent element</param> internal SourceLanguage(XElement element) : this() { if (element != null) { this.LanguageCode = element.GetChildValue("LanguageCode"); } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="client"></param> internal Service(XElement element, IContentAPI client) : this() { this.Client = client; if (element != null) { this.ServiceID = element.GetChildValueAsInt32("ServiceID"); this.Name = element.GetChildValue("Name"); this.Description = element.GetChildValue("Description"); this.PriceDescription = element.GetChildValue("PriceDescription"); this.ValidInputs = new ValidInputs(element.Element("ValidInputs")); XElement sourceLanguages = element.Element("SourceLanguages"); if (sourceLanguages != null) { foreach (XElement sourceLanguage in sourceLanguages.Descendants("LanguageCode")) { this.SourceLanguagesList.Add(sourceLanguage.Value); } } XElement targetLanguages = element.Element("TargetLanguages"); if (targetLanguages != null) { foreach (XElement targetLanguage in targetLanguages.Descendants("LanguageCode")) { this.TargetLanguagesList.Add(targetLanguage.Value); } } } }
public AssemblyReference(XElement referenceElement) { ParseInclude(referenceElement); ReferenceName = referenceElement.GetChildValue("Name"); HintPath = referenceElement.GetChildValue("HintPath"); SpecificVersion = GetChildBooleanValue(referenceElement, true, "SpecificVersion"); RequiredTargetFramework = TryParseFrameworkVersion(referenceElement.GetChildValue("RequiredTargetFramework")); Private = GetChildBooleanValue(referenceElement, false, "Private"); ExecutableExtension = referenceElement.GetChildValue("ExecutableExtension"); FusionName = referenceElement.GetChildValue("FusionName"); Aliases = referenceElement.GetChildValue("Aliases"); }
/// <summary> /// Create an account from XML /// </summary> /// <param name="element"></param> internal Account(XElement element) : this() { if (element != null) { this.MerchantID = element.GetChildValue("MerchantID"); this.Status = element.GetChildValue("Status"); this.Email = element.GetChildValue("EmailAddress"); this.FirstName = element.GetChildValue("FirstName"); this.LastName= element.GetChildValue("LastName"); this.CompanyName = element.GetChildValue("CompanyName"); this.Country = element.GetChildValue("Country"); this.AccessKeyID = element.GetChildValue("AccessKeyID"); this.SecretAccessKey = element.GetChildValue("SecretAccessKey"); } }
/// <summary> /// Constructor from XML /// </summary> /// <param name="element"></param> /// <param name="client"></param> internal Estimate(XElement element, IContentAPI client) : this() { this.Client = client; if (element != null) { XElement service = element.Element("Service"); int serviceID = service.GetChildValueAsInt32("ServiceID"); if (this.Client != null) { this.Service = this.Client.GetService(serviceID); } this.Currency = element.GetChildValue("Currency"); this.TotalCost = element.GetChildValueAsDecimal("TotalCost"); } }
public ProjectReference(XElement projectReferenceElement, string refPath) { projectFile = new FileInfo(Path.Combine(refPath, projectReferenceElement.Attribute("Include").Value)); ProjectName = projectReferenceElement.GetChildValue("Name"); ProjectGuid = new Guid(projectReferenceElement.GetChildValue("Project")); }
private static bool GetChildBooleanValue(XElement parent, bool defaultVal, string childName) { bool parsedBool; if (bool.TryParse(parent.GetChildValue(childName), out parsedBool)) { return parsedBool; } else { return defaultVal; } }
public override void LoadFromXml(XElement option) { cbValue.Checked = option.GetChildValue(key, defaultValue); }
public void TestGetChildValue_Empty() { var ele = new XElement("Root", new XElement("Test", new XAttribute("attr", 3.4), new XElement("Another", 5))); var value = ele.GetChildValue("Test"); Assert.AreEqual(string.Empty, value); }
/// <summary> /// Update the Project from XML /// </summary> /// <param name="element"></param> internal void UpdateFromXElement(XElement element) { if (element != null) { this.ProjectID = element.GetChildValueAsInt32("ProjectID"); this.ServiceID = element.GetChildValueAsInt32("ServiceID"); this.Status = element.GetChildValue("Status"); this.URL = element.GetChildValueAsUri("ProjectURL"); this.Name = element.GetChildValue("ProjectName"); this.Price = element.GetChildValueAsDecimal("Price"); this.Currency = element.GetChildValue("Currency"); this.CreationDate = element.GetChildValueAsDateTime("CreationDate"); this.DueDate = element.GetChildValueAsDateTime("ProjectDueDate"); this.DueDate = (this.DueDate == DateTime.MinValue) ? element.GetChildValueAsDateTime("DueDate") : this.DueDate; this.CompletionDate = element.GetChildValueAsDateTime("CompletionDate"); XElement sourceLanguage = element.Element("SourceLanguage"); if (element.Element("SourceLanguage") != null) { this.SourceLanguage = sourceLanguage.GetChildValue("LanguageCode"); } XElement targetLanguages = element.Element("TargetLanguages"); this.TargetLanguagesList = new List<string>(); if (targetLanguages != null) { foreach (XElement targetLanguage in targetLanguages.Descendants("LanguageCode")) { this.TargetLanguagesList.Add(targetLanguage.Value); } } if (element.Element("Products") != null) { this.ProductsList = new List<Product>(Product.CreateEnumerable(element.Element("Products"), this.Client)); } if (element.Element("Files") != null) { if (this.FilesList != null && this.FilesList.Count == element.Descendants("File").Count()) { for (int i = 0; i < this.FilesList.Count; i++) { this.FilesList[i].UpdateFromXElement(element.Descendants("File").InDocumentOrder().ElementAt(i)); } } else { this.FilesList = new List<File>(File.CreateEnumerable(element.Element("Files"), this.Client)); } } if (element.Element("ReferenceFiles") != null) { if (this.ReferenceFilesList != null && this.ReferenceFilesList.Count == element.Descendants("ReferenceFile").Count()) { for (int i = 0; i < this.ReferenceFilesList.Count; i++) { this.ReferenceFilesList[i].UpdateFromXElement(element.Descendants("ReferenceFile").InDocumentOrder().ElementAt(i)); } } else { this.ReferenceFilesList = new List<File>(File.CreateEnumerable(element.Element("ReferenceFiles"), this.Client)); } } } }
/// <summary> /// Update an existing file object from XML /// </summary> /// <param name="element"></param> internal void UpdateFromXElement(XElement element) { if (element != null) { this.AssetID = element.GetChildValueAsInt32("AssetID"); String fileStatus = element.GetChildValue("Status"); if (!String.IsNullOrEmpty(fileStatus) && Enum.IsDefined(typeof(FileStatus), fileStatus.Replace(" ", ""))) { this.Status = (FileStatus)(Enum.Parse(typeof(FileStatus), fileStatus.Replace(" ", ""))); } this.URL = element.GetChildValueAsUri("URL"); this.ProjectID = element.GetChildValueAsInt32("ProjectID"); this.Name = element.GetChildValue("Name"); this.Name = String.IsNullOrEmpty(this.Name) ? element.GetChildValue("FileName") : this.Name; this.UploadDate = element.GetChildValueAsDateTime("UploadDate"); this.SourceLanguage = new SourceLanguage(element.Element("SourceLanguage")); XElement targetLanguagesElement = element.Element("TargetLanguages"); if (targetLanguagesElement != null) { List<TargetLanguage> targetLanguages = new List<TargetLanguage>(); foreach (XElement targetLanguageElement in targetLanguagesElement.Elements("TargetLanguage")) { TargetLanguage targetLanguage = new TargetLanguage(targetLanguageElement); targetLanguages.Add(targetLanguage); } this.TargetLanguages = targetLanguages.ToArray<TargetLanguage>(); } } }
/// <summary> /// /// </summary> /// <param name="element"></param> internal void UpdateFromXElement(XElement element) { if (element != null) { this.QuoteID = element.GetChildValueAsInt32("QuoteID"); this.Status = element.GetChildValue("Status"); this.AuthorizeURL = element.GetChildValue("AuthorizeURL"); this.RejectURL = element.GetChildValue("RejectURL"); this.PaymentURL = element.GetChildValue("PaymentURL"); this.Currency = element.GetChildValue("Currency"); this.TotalCost = element.GetChildValueAsDecimal("TotalCost"); this.PrepaidCredit = element.GetChildValueAsDecimal("PrepaidCredit"); this.AmountDue = element.GetChildValueAsDecimal("AmountDue"); this.TotalTranslations = element.GetChildValueAsInt32("TotalTranslations"); this.TranslationCredit = element.GetChildValueAsInt32("TranslationCredit"); this.CreationDate = element.GetChildValueAsDateTime("CreationDate"); if (element.Element("Projects") != null) { this.Projects = Project.CreateEnumerable(element.Element("Projects"), this.Client); } if (element.Element("Payments") != null) { this.Payments = Payment.CreateEnumerable(element.Element("Payments")); } } }