public void FromXml(XElement x) { if (x == null) return; Type = (PaletteType) Enum.Parse(typeof (PaletteType), x.GetString("Type", "Gradient")); var stps = x.Elements(); Stops = new List<PaletteStop>(); foreach (var s in stps) { var ps = new PaletteStop(); ps.FromXml(s); Stops.Add(ps); } }
public override void FromXml(XElement element, string directoryName) { Description = element.GetString("Description"); CanEdit = element.GetBool("CanEdit"); CanCreate = element.GetBool("CanCreate"); SyncDelay = element.GetInt("SyncDelay", 500); ShareOnline = element.GetBool("ShareOnline"); TabBarVisible = element.GetBool("TabBarVisible", true); MinResolution = element.GetDouble("MinResolution"); MaxResolution = element.GetDouble("MaxResolution", -1.0); FilterLocation = element.GetBool("FilterLocation"); SelectionMode = (SelectionMode)Enum.Parse(typeof(SelectionMode), element.GetString("SelectionMode", "None")); ShowTimeline = element.GetBool("ShowTimeline", false); ShowAnalysis = element.GetBool("ShowAnalysis", false); SublayersVisible = element.GetBool("SublayersVisible", true); OpenTab = element.GetBool("OpenTab", false); Icon = element.GetString("Icon", ""); LayerOrder = element.GetString("LayerOrder", ""); AutoStart = element.GetBool("AutoStart", false); BackupInterval = element.GetInt("BackupInterval", 0); var xLabels = element.Element("Labels"); if (xLabels == null) return; foreach (var l in xLabels.Elements()) { Labels.Add(l.Name.LocalName, l.Value); } }
public override void FromXml(XElement element, string directoryName) { Id = element.GetGuid("id"); Name = element.GetString("name", string.Empty); Layer = element.GetString("layer", string.Empty); ConnectionStringFull = element.GetString("connection", string.Empty); ConnectionStringReference = element.GetString("connectionReference", string.Empty); Query = (string)element.GetElement("Query"); PoiTypeId = element.GetString("poiTypeId", string.Empty); IsEnabled = element.GetBool("isEnabled"); UpdateType = (UpdateTypes)Enum.Parse(typeof(UpdateTypes), element.GetString("updateType", string.Empty)); var options = element.GetElement("Options"); if (options != null) { var relationShip = options.GetString("relationship", string.Empty); Options = new SqlQueryOptions { ControlInputParameterIndex = options.GetInt("controlInputParameterIndex"), DesiredResultFormula = options.GetString("desiredResultFormula"), DesiredResultLabel = options.GetString("desiredResultLabel"), DesiredAccuracyInputParameterIndex = options.GetInt("desiredAccuracyInputParameterIndex"), MaxTriesInputParameterIndex = options.GetInt("maxTriesInputParameterIndex", 5), ActualResultOutputParameterIndex = options.GetInt("actualResultOutputParameterIndex"), Relationship = string.IsNullOrEmpty(relationShip) ? SqlInputOutputRelationship.Linear : (SqlInputOutputRelationship)Enum.Parse(typeof(SqlInputOutputRelationship), relationShip) }; } var inputs = element.Element("Inputs"); if (inputs != null) foreach (var input in inputs.Elements()) { InputParameters.Add(new SqlInputParameter { LabelName = input.GetString("labelName", string.Empty), Type = (SqlParameterTypes)Enum.Parse(typeof(SqlParameterTypes), input.GetString("type", string.Empty)) }); } var outputs = element.Element("Outputs"); if (outputs == null) return; foreach (var output in outputs.Elements()) { OutputParameters.Add(new SqlOutputParameter { Name = output.GetString("name", string.Empty), OutputType = (SqlOutputType)Enum.Parse(typeof(SqlOutputType), output.GetString("type", string.Empty)) }); } }
/// <summary> /// Shreds an XML element into a Status object /// </summary> /// <param name="status">XML element with info</param> /// <returns>Newly populated status object</returns> public static Status CreateStatus(XElement status) { if (status == null) { return null; } var createdAtDate = status.Element("created_at") == null || status.Element("created_at").Value == string.Empty ? DateTime.MinValue : DateTime.ParseExact( status.Element("created_at").Value, "ddd MMM dd HH:mm:ss %zzzz yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); var favorite = status.Element("favorited") == null || status.Element("favorited").Value == string.Empty ? "false" : status.Element("favorited").Value; var user = status.Element("user"); var retweet = status.Element("retweeted_status"); var retweetCount = status.Element("retweet_count") == null || status.Element("retweet_count").Value == string.Empty ? 0 : int.Parse(status.Element("retweet_count").Value.TrimEnd('+')); var retweeted = status.Element("retweeted") == null || status.Element("retweeted").Value == string.Empty ? false : bool.Parse(status.Element("retweeted").Value); var retweetDate = retweet == null ? null : retweet.Element("created_at").Value; var retweetedAtDate = String.IsNullOrEmpty(retweetDate) ? DateTime.MinValue : DateTime.ParseExact( retweetDate, "ddd MMM dd HH:mm:ss %zzzz yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); List<Contributor> contributors = null; XElement contributorElement = status.Element("contributors"); if (contributorElement != null) { if (contributorElement.Elements("user").Count() > 0) { contributors = (from contr in contributorElement.Elements("user") select new Contributor { ID = contr.Element("id").Value, ScreenName = contr.Element("screen_name").Value }) .ToList(); } else { contributors = (from id in contributorElement.Elements("user_id") select new Contributor { ID = id.Value, ScreenName = string.Empty }) .ToList(); } } XNamespace geoRss = "http://www.georss.org/georss"; var geoStr = status.Element("geo") != null && status.Element("geo").Element(geoRss + "point") != null ? status.Element("geo").Element(geoRss + "point").Value : string.Empty; Geo geo = new Geo(); if (!string.IsNullOrEmpty(geoStr)) { var coordArr = geoStr.Split(' '); double tempLatitude = 0; double tempLongitide = 0; if (double.TryParse(coordArr[Coordinate.LatitudePos], out tempLatitude) && double.TryParse(coordArr[Coordinate.LongitudePos], out tempLongitide)) { geo = new Geo { Latitude = tempLatitude, Longitude = tempLongitide }; } } var coordStr = status.Element("coordinates") != null && status.Element("coordinates").Element(geoRss + "point") != null ? status.Element("coordinates").Element(geoRss + "point").Value : string.Empty; Coordinate coord = new Coordinate(); if (!string.IsNullOrEmpty(coordStr)) { var coordArr = coordStr.Split(' '); double tempLatitude = 0; double tempLongitide = 0; if (double.TryParse(coordArr[Coordinate.LatitudePos], out tempLatitude) && double.TryParse(coordArr[Coordinate.LongitudePos], out tempLongitide)) { coord = new Coordinate { Latitude = tempLatitude, Longitude = tempLongitide }; } } var place = Place.CreatePlace(status.Element("place")); var annotation = Annotation.CreateAnnotation(status.Element("annotation")); var entities = Entities.CreateEntities(status.Element("entities")); var newStatus = new Status { CreatedAt = createdAtDate, Favorited = bool.Parse(favorite), StatusID = status.GetString("id"), InReplyToStatusID = status.GetString("in_reply_to_status_id"), InReplyToUserID = status.GetString("in_reply_to_user_id"), Source = status.GetString("source"), Text = status.GetString("text"), Truncated = status.GetBool("truncated"), InReplyToScreenName = status.GetString("in_reply_to_screen_name"), Contributors = contributors, Geo = geo, Coordinates = coord, Place = place, Annotation = annotation, User = User.CreateUser(user), Entities = entities, Retweeted = retweeted, RetweetCount = retweetCount, Retweet = retweet == null ? null : new Retweet { ID = retweet.GetString("id"), CreatedAt = retweetedAtDate, Favorited = retweet.GetBool("favorited"), InReplyToScreenName = retweet.GetString("in_reply_to_screen_name"), InReplyToStatusID = retweet.GetString("in_reply_to_status_id"), InReplyToUserID = retweet.GetString("in_reply_to_user_id"), Source = retweet.GetString("source"), Text = retweet.GetString("text"), Retweeted = retweet.GetBool("retweeted"), RetweetCount = //retweet.GetInt("retweet_count"), retweet.Element("retweet_count") == null || retweet.Element("retweet_count").Value == string.Empty ? 0 : int.Parse(retweet.Element("retweet_count").Value.TrimEnd('+')), Truncated = retweet.GetBool("truncated", true), RetweetingUser = User.CreateUser(retweet.Element("user")) } }; return newStatus; }
public void FromXml(XElement el) { Type = el.GetString("Type"); Id = el.GetString("Id"); if (string.IsNullOrEmpty(Id)) Id = Type; var xp = el.Element("InputParameters"); if (xp == null) return; Parameters = new List<ModelParameter>(); foreach (var l in xp.Elements()) { Parameters.Add(new ModelParameter { Direction = ModelParameterDirection.input, Name = l.Name.LocalName, Value = l.Value, Source = (ModelParameterSource) Enum.Parse(typeof(ModelParameterSource), l.GetString("source", ModelParameterSource.direct.ToString())) }); } }
public virtual void FromXml(XElement hx) { try { // TODO Should we set the property or the backing field? Title = hx.GetString("Title"); UsesMultipleCriteria = hx.GetBool("usesMultipleCriteria"); ShowInGui = hx.GetBool("ShowInGui", true); IsActive = hx.GetBool("IsActive"); IsDynamic = hx.GetBool("IsDynamic"); HighlighterType = (HighlighterTypes)Enum.Parse(typeof(HighlighterTypes), hx.GetString("HighlighterType", "Highlight")); VisualType = (VisualTypes)Enum.Parse(typeof(VisualTypes), hx.GetString("VisualType", "StrokeColor")); ValueType = (ValueTypes)Enum.Parse(typeof(ValueTypes), hx.GetString("ValueType", "String")); MinValue = hx.GetDouble("MinValue"); MaxValue = hx.GetDouble("MaxValue"); ThresholdType = (ThresholdTypes)Enum.Parse(typeof(ThresholdTypes), hx.GetString("ThresholdType", "Equal")); SelectionCriteria = hx.GetString("SelectionCriteria", string.Empty); SelectionType = (SelectionTypes)Enum.Parse(typeof(SelectionTypes), hx.GetString("SelectionType", "Label")); ThresHoldValue = hx.GetDouble("ThresHoldValue", 0.0); StringValue = hx.GetString("StringValue", string.Empty); StringFormat = hx.GetString("StringFormat", string.Empty); PoiType = hx.GetString("PoiType", string.Empty); var px = hx.Element("Palette"); Category = hx.GetString("Category", DefaultCategory); if (px == null) return; Palette = new Palette(); Palette.FromXml(px); if (!usesMultipleCriteria) return; var crit = hx.GetString("criteria").Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (var c in crit) { var criterion = c.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (criterion.Length < 3) continue; var st = (SelectionTypes)Enum.Parse(typeof(SelectionTypes), criterion[0], true); double result; if (double.TryParse(criterion[2], NumberStyles.Number, CultureInfo.CurrentCulture, out result)) criteria.Add(new PoiProperty { Name = criterion[1], Type = st, Weight = result }); } inMcaMode = hx.GetBool("inMcaMode"); CreateResultFormula(hx.GetString("mathFormula")); } catch (Exception e) { Logger.Log("AnalysisMetaInfo", "Error parsing xml", e.Message, Logger.Level.Error); } }
public void FromXmlBase(ref XElement res, string directoryName) { //var xmlSerializer = new XmlSerializer(typeof (PoI)); //var p = xmlSerializer.Deserialize(res.CreateReader()); try { Id = res.GetGuid("Id"); if (Id == Guid.Empty) Id = Guid.NewGuid(); var n = res.GetString("Name"); ContentId = res.GetString("PoiId", ""); if (String.IsNullOrEmpty(ContentId)) ContentId = n; Priority = res.GetInt("Priority", 2); UserId = res.GetString("UserId"); DateLong = res.GetLong("Date", DateTime.Now.ToEpoch()); UpdatedLong = res.GetLong("Updated", DateTime.Now.ToEpoch()); Layer = res.GetString("Layer"); MaxItems = res.GetNullInt("MaxItems"); var xMid = res.Element("MetaInfoData"); PoiTypeId = res.GetString("PoiTypeId", ""); IsVisibleInMenu = res.GetBool("IsVisibleInMenu", true); Orientation = res.GetDouble("Orientation", 0.0); //if (!string.IsNullOrEmpty(PoiTypeId)) //{ //} if (xMid != null) { var metaInfo = new MetaInfoCollection(); foreach (var xMi in xMid.Elements()) { var mi = new MetaInfo(); mi.FromXml(xMi); metaInfo.Add(mi); } MetaInfo = metaInfo; } if (res.Element("WKT") != null) { var xElement = res.Element("WKT"); if (xElement != null) WktText = xElement.Value; } var xlabels = res.Element("Labels"); if (xlabels != null) { Labels = new Dictionary<string, string>(); foreach (var xk in xlabels.Elements()) { var k = xk.Name.LocalName; // Restore keys starting with numbers or having % or '. k = k.Replace(LabelPercentSubst, "%"); k = k.Replace(LabelQuoteSubst, "'"); if (k.StartsWith(LabelNumPrefix)) { k = k.Substring(LabelNumPrefix.Length); } var s = xk.InnerXml(); Labels[k] = s.RestoreInvalidCharacters(); Labels[k] = Labels[k].Replace("<", "<").Replace(">", ">"); } } var xkeywords = res.Element("Keywords"); if (xkeywords != null) { Keywords = new WordHistogram(); Keywords.FromXml(xkeywords); } if (res.Element("Style") != null) { try { var newStyle = new PoIStyle(); newStyle.FromXml(res.Element("Style"), directoryName, false); //, Service.Settings); // TODO REVIEW: Settings were ignored. Style = newStyle; } catch (Exception) { // OK, keep the old style. } } var media = res.Element("AllMedia"); if (media != null) { AllMedia = new BindableCollection<Media>(); foreach (var m in media.Elements()) { var me = new Media { Content = this }; me.FromXml(m); AllMedia.Add(me); } } var xpos = res.Element("Position"); if (xpos != null) Position = new Position(xpos.GetDouble(Position.LONG_LABEL), xpos.GetDouble(Position.LAT_LABEL), xpos.GetDouble(Position.ALT_LABEL)); // TODO Remember other Position attributes. var px = res.Element("Points"); var mo = res.Element("Models"); if (mo != null) { Models = new List<Model>(); foreach (var xm in mo.Elements()) { var m = new Model(); m.FromXml(xm); Models.Add(m); } } if (px == null) return; var pp = px.Value; Points = new ObservableCollection<Point>(); var ppo = pp.Split(' '); foreach (var poss in ppo) { var split = poss.Split(','); var pt = new Point( Double.Parse(split[0], CultureInfo.InvariantCulture), Double.Parse(split[1], CultureInfo.InvariantCulture)); Points.Add(pt); } } catch (SystemException e) { Logger.Log("DataServer.BaseContent", "Error reading XML " + res + " from " + directoryName, e.Message, Logger.Level.Error, true); } }
public override void FromXml(XElement res, string directoryName) { FromXmlBase(ref res,directoryName); var n = res.GetString("Name"); ContentId = res.GetString("EventId"); if (string.IsNullOrEmpty(ContentId)) ContentId = n; PoiTypeId = res.GetString("EventTypeId"); Icon = res.GetString("Icon"); if (string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(n)) Name = n; if (string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(ContentId)) Name = ContentId; }
public void FromXml(XElement res, string directoryName, bool catchException) { try { Folder = directoryName; BaseStyle = res.GetString("BaseStyle"); FillColor = res.GetNullColor("FillColor"); StrokeColor = res.GetNullColor("StrokeColor"); var dm = res.GetString("DrawingMode"); if (!string.IsNullOrEmpty(dm)) DrawingMode = (DrawingModes) Enum.Parse(typeof (DrawingModes), dm); strokeWidth = res.GetNullDouble("StrokeWidth"); IconWidth = res.GetNullDouble("IconWidth"); IconHeight = res.GetNullDouble("IconHeight"); Icon = res.GetString("IconUri"); Category = res.GetString("Category"); CallOutFillColor = res.GetNullColor("CallOutFillColor"); CallOutForeground = res.GetNullColor("CallOutForeground"); var tm = res.GetString("TapMode"); if (tm!=null) TapMode = (TapMode) Enum.Parse(typeof (TapMode), tm); var ttm = res.GetString("TitleMode"); if (ttm != null) TitleMode = (TitleModes) Enum.Parse(typeof (TitleModes), ttm); MinResolution = res.GetNullDouble("MinResolution"); MaxResolution = res.GetNullDouble("MaxResolution"); NameLabel = res.GetString("NameLabel"); AutoCallOutLabels = res.GetNullBool("AutoCallOutLabels"); StrokeOpacity = res.GetNullDouble("StrokeOpacity"); FillOpacity = res.GetNullDouble("FillOpacity"); Visible = res.GetNullBool("Visible"); Name = res.GetString("Name"); CanRotate = res.GetNullBool("CanRotate"); CanMove = res.GetNullBool("CanMove"); CanEdit = res.GetNullBool("CanEdit"); CanDelete = res.GetNullBool("CanDelete"); CallOutTimeOut = res.GetNullInt("CallOutTimeOut"); ShowOnTimeline = res.GetString("ShowOnTimeline"); MaxTitleResolution = res.GetNullDouble("MaxTitleResolution"); CallOutMaxWidth = res.GetNullDouble("CallOutMaxWidth"); CallOutMinHeight = res.GetNullDouble("CallOutMinHeight"); InnerTextLabel = res.GetString("InnerTextLabel"); InnerTextColor = res.GetNullColor("InnerTextColor"); Cluster = res.GetBool("Cluster"); ScalePoi = res.GetNullBool("ScalePoi"); ScaleStartResolution = res.GetNullDouble("ScaleStartResolution"); ScaleUnits = res.GetNullDouble("ScaleUnits"); MaxScale = res.GetNullDouble("MaxScale"); SubTitles = res.GetString("SubTitles"); var am = res.GetString("AddMode"); if (am!=null) AddMode = (AddModes) Enum.Parse(typeof (AddModes), am); var coo = res.GetString("CallOutOrientation"); if (coo!=null) CallOutOrientation = (CallOutOrientation)Enum.Parse(typeof (CallOutOrientation),coo); var tb = res.GetString("TimelineBehaviour"); if (tb != null) TimelineBehaviour = (TimelineBehaviours) Enum.Parse(typeof (TimelineBehaviours), tb); var ami = res.Element("AnalysisMetaInfo"); if (ami == null) return; Analysis = new AnalysisMetaInfo(); var hlx = ami.Element("Highlights"); if (hlx == null) return; Analysis.Highlights = new List<Highlight>(); foreach (var hx in hlx.Elements()) { var h = new Highlight(); h.FromXml(hx); h.Style = this; Analysis.Highlights.Add(h); } } catch (Exception e) { if (!catchException) { throw e; } Logger.Log("Poi Parser", "Error parsing style", e.Message, Logger.Level.Warning); } }
public override void FromXml(XElement res, string directoryName) { FromXmlBase(ref res,directoryName); Title = res.GetString("Title"); TaskId = res.GetString("TaskId"); ContentId = TaskId; State = (TaskState)Enum.Parse(typeof(TaskState), res.GetString("State")); Description = res.Element("Description") == null ? string.Empty : res.Element("Description").Value; }
public void FromXml(XElement element) { Id = element.GetString("Id"); Title = element.GetString("Title"); Type = (MediaType) Enum.Parse(typeof (MediaType), element.GetString("Type")); PublicUrl = element.GetString("PublicUrl"); }
public void FromXml(XElement element) { _language = element.GetString("Language"); _frequencies.Clear(); XElement xhistogram = element.Element("Histogram"); foreach (XElement xhelement in xhistogram.Elements()) { string key = xhelement.GetString("Word"); int value = xhelement.GetInt("Count"); _frequencies[key] = value; } }