public void WHEN_ObjectRelWhere_GIVEN_Array_With_Multiple_Matching_Links_THEN_Get_All() { var link1 = new ReferenceLink { Rel = "farm" }; var link2 = new ReferenceLink { Rel = "farm" }; var links = new[] { new ReferenceLink { Rel = "other" }, link1, new ReferenceLink { Rel = "other2" }, link2, new ReferenceLink { Rel = "field" }, }; var result = links.ObjectRelWhere <Farm>(); Assert.Equal(2, result.Count); Assert.Contains(link1, result); Assert.Contains(link2, result); }
public ReferenceLink PushVar(XmlQualifiedName name) { ReferenceLink id = NewReference(); _slots.Add(new NameSlot(id, name)); return(id); }
static IList <string> linksToStringList(int blanksPrefix, ReferenceLinks referenceLinks) { IList <string> strs = new List <string>(); if (referenceLinks == null || referenceLinks.Links == null) { return(strs); } strs.Add(createBlanks(blanksPrefix) + "Links: "); foreach (var link in referenceLinks.Links) { if (link.Value is ReferenceLink) { ReferenceLink referenceLink = (ReferenceLink)link.Value; strs.Add(createBlanks(blanksPrefix + 4) + link.Key + ": " + referenceLink.Href); } else { strs.Add(createBlanks(blanksPrefix + 4) + link.Key + ": " + link.Value); } } return(strs); }
protected string?GetContentId(ReferenceLink referenceLink) { string?contentId = null; var linkEntry = referenceLink.LinkData.ToDictionary(TypeCache); if (_deferredBatchWriter != null) { contentId = _deferredBatchWriter.Value.GetContentId(linkEntry, referenceLink.LinkData); } return(contentId); }
protected override void OnElementChanged(ElementChangedEventArgs <Label> elementChangedEventArgs) { base.OnElementChanged(elementChangedEventArgs); if (elementChangedEventArgs.NewElement != null) { referenceLink = (ReferenceLink)elementChangedEventArgs.NewElement; if (referenceLink == null) { return; } UpdateUi(); } }
public ModelEnvelope <FieldBoundary> Convert(FieldBoundaryDto fieldBoundaryDto) { var fieldBoundary = new FieldBoundary { TimeScopes = new List <TimeScope>() { new TimeScope { TimeStamp1 = new DateTime(fieldBoundaryDto.CropYear, 1, 1), TimeStamp2 = new DateTime(fieldBoundaryDto.CropYear, 12, 31) } }, Description = $"{fieldBoundaryDto.CropYear} Boundary" }; var fieldBoundaryUniqueId = fieldBoundary.Id; var boundaryUniqueId = _uniqueIdFactory.CreateInt(fieldBoundaryDto.Id); fieldBoundaryUniqueId.UniqueIds.Add(boundaryUniqueId); var selfLink = new ReferenceLink { Id = fieldBoundaryUniqueId, Rel = Relationships.Self, Link = $"/FieldBoundaries/{boundaryUniqueId.Source}/{boundaryUniqueId.Id}" }; var fieldUniqueId = _uniqueIdFactory.CreateGuid(fieldBoundaryDto.FieldUid); var fieldCompoundId = fieldUniqueId.ToCompoundIdentifier(); fieldBoundary.FieldId = fieldCompoundId.ReferenceId; var fieldLink = new ReferenceLink { Id = fieldCompoundId, Rel = typeof(Field).ObjectRel(), Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}" }; // NOTE: Skipped SpatialData to not introduce Spatial Dependencies in conversion. var fieldBoundaryEnvelope = new ModelEnvelope <FieldBoundary>(fieldBoundary); fieldBoundaryEnvelope.Links.Add(selfLink); fieldBoundaryEnvelope.Links.Add(fieldLink); return(fieldBoundaryEnvelope); }
public ModelEnvelope <Farm> Convert(FarmDto farmDto) { var farm = new Farm() { Description = farmDto.Name }; var farmUniqueId = _uniqueIdFactory.CreateGuid(farmDto.Uid); var farmCompoundId = farm.Id; farmCompoundId.UniqueIds.Add(farmUniqueId); var selfLink = new ReferenceLink { Id = farmCompoundId, Rel = Relationships.Self, Link = $"/Farms/{farmUniqueId.Source}/{farmUniqueId.Id}", Type = "get" }; var growerUniqueId = _uniqueIdFactory.CreateGuid(farmDto.GrowerUid); var growerCompoundId = growerUniqueId.ToCompoundIdentifier(); farm.GrowerId = growerCompoundId.ReferenceId; var growerLink = new ReferenceLink { Id = growerCompoundId, Rel = typeof(Grower).ObjectRel(), Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}", Type = "get" }; var fieldsLink = new ReferenceLink { Rel = typeof(Field).ListRel(), Link = $"/Farms/{farmUniqueId.Source}/{farmUniqueId.Id}/Fields", Type = "get" }; var farmEnvelope = new ModelEnvelope <Farm>(farm); farmEnvelope.Links.Add(growerLink); farmEnvelope.Links.Add(selfLink); farmEnvelope.Links.Add(fieldsLink); return(farmEnvelope); }
public void WHEN_SelfSingle_GIVEN_Array_With_Link_THEN_Get_Link() { var self = new ReferenceLink { Rel = "self" }; var links = new[] { self, new ReferenceLink { Rel = "other" }, }; var result = links.SelfLinkSingle(); Assert.NotNull(result); Assert.Equal(self, result); }
public ModelEnvelope <CropZone> Convert(CropZoneDto cropZoneDto) { var cropZone = new CropZone() { Description = cropZoneDto.Name, TimeScopes = new List <TimeScope>() { new TimeScope { TimeStamp1 = new DateTime(cropZoneDto.CropYear, 1, 1), TimeStamp2 = new DateTime(cropZoneDto.CropYear, 12, 31) } } }; var cropZoneUniqueId = _uniqueIdFactory.CreateInt(cropZoneDto.Id); var cropZoneCompoundId = cropZone.Id; cropZone.Id.UniqueIds.Add(cropZoneUniqueId); var selfLink = new ReferenceLink { Id = cropZoneCompoundId, Rel = Relationships.Self, Link = $"/CropZones/{cropZoneUniqueId.Source}/{cropZoneUniqueId.Id}" }; var fieldUniqueId = _uniqueIdFactory.CreateGuid(cropZoneDto.FieldUid); var fieldCompoundId = fieldUniqueId.ToCompoundIdentifier(); var fieldLink = new ReferenceLink { Id = fieldCompoundId, Rel = typeof(Field).Name.ToLower(), Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}" }; cropZone.FieldId = fieldCompoundId.ReferenceId; // NOTE: Skipped BoundingRegion to not introduce Spatial Dependencies in conversion. var cropZoneEnvelope = new ModelEnvelope <CropZone>(cropZone); cropZoneEnvelope.Links.Add(selfLink); cropZoneEnvelope.Links.Add(fieldLink); return(cropZoneEnvelope); }
public TeamProjectReference GetProjectDetails() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient <ProjectHttpClient>(); // Get the details for the specified project TeamProject project = projectClient.GetProject(projectName, includeCapabilities: true, includeHistory: true).Result; // Get the "web" URL for this project ReferenceLink webLink = project.Links.Links["web"] as ReferenceLink; Console.WriteLine("Details for project {0}:", projectName); Console.WriteLine(); Console.WriteLine(" ID : {0}", project.Id); Console.WriteLine(" Description : {0}", project.Description); Console.WriteLine(" Web URL : {0}", (webLink != null ? webLink.Href : "(not available)")); return(project); }
public ModelEnvelope <Grower> Convert(GrowerDto pmGrower) { var grower = new Grower() { Name = pmGrower.Name }; var growerCompoundId = grower.Id; var growerUniqueId = _uniqueIdFactory.CreateGuid(pmGrower.Uid); growerCompoundId.UniqueIds.Add(growerUniqueId); var growerLink = new ReferenceLink { Id = growerCompoundId, Rel = Relationships.Self, Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}", Type = "get" }; var farmsLink = new ReferenceLink { Rel = typeof(Farm).ListRel(), Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}/Farms" }; var fieldsLink = new ReferenceLink { Rel = typeof(Field).ListRel(), Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}/Fields" }; grower.Id.UniqueIds.Add(growerUniqueId); var growerEnvelope = new ModelEnvelope <Grower>(grower); growerEnvelope.Links.Add(growerLink); growerEnvelope.Links.Add(farmsLink); growerEnvelope.Links.Add(fieldsLink); return(growerEnvelope); }
protected override void OnElementChanged(ElementChangedEventArgs <View> elementChangedEventArgs) { base.OnElementChanged(elementChangedEventArgs); if (elementChangedEventArgs.NewElement != null) { referenceLink = (ReferenceLink)elementChangedEventArgs.NewElement; if (referenceLink == null) { return; } referenceLink.PropertyChanged += OnPropertyChanged; NSAttributedString attributedString = null; var htmlData = NSData.FromString(referenceLink.HtmlText); if (htmlData != null) { NSError error = new NSError(); attributedString = new NSAttributedString(htmlData, new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML, StringEncoding = NSStringEncoding.UTF8 }, ref error); } var action = referenceLink.Action; textView = new UITextView(); textView.TextColor = UIColor.Gray; textView.ApplySubtitlesLinks(action(), referenceLink.Sources, attributedString); textView.Editable = false; textView.ScrollEnabled = false; textView.Font = UIFont.SystemFontOfSize((nfloat)referenceLink.FontSize); // replace old Label with new TextView SetNativeControl(textView); } }
public void WHEN_ListRelSingleOrDefault_GIVEN_Array_With_Matching_Link_THEN_Get_It() { var link = new ReferenceLink { Rel = "farms" }; var links = new[] { new ReferenceLink { Rel = "other" }, link, new ReferenceLink { Rel = "other2" }, new ReferenceLink { Rel = "field" }, }; var result = links.ListRelSingleOrDefault <Farm>(); Assert.Equal(link, result); }
protected override void OnElementChanged(ElementChangedEventArgs <Label> elementChangedEventArgs) { base.OnElementChanged(elementChangedEventArgs); if (elementChangedEventArgs.NewElement != null) { referenceLink = (ReferenceLink)elementChangedEventArgs.NewElement; if (referenceLink == null) { return; } var srcList = referenceLink.Sources; var action = referenceLink.Action; var spannableTextBuilder = new SpannableTextBuilder(); ISpanned spannedText; string html = new HtmlTagHelper().FormatAdditionalTags(referenceLink.HtmlText); if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { spannedText = Html.FromHtml(html, FromHtmlOptions.ModeLegacy); } else { #pragma warning disable 618 spannedText = Html.FromHtml(html); #pragma warning restore 618 } Control.TextFormatted = spannableTextBuilder.CreateSubtitlesText(action(), spannedText, srcList); // Make links clickable Control.MovementMethod = LinkMovementMethod.Instance; Control.AutoLinkMask = MatchOptions.All; Control.Clickable = true; Control.LinksClickable = true; } }
public ModelEnvelope <Field> Convert(FieldDto fieldDto) { if (fieldDto == null) { return(null); } var field = new Field() { Description = fieldDto.Name }; var fieldCompoundId = field.Id; var fieldUniqueId = _uniqueIdFactory.CreateGuid(fieldDto.Uid); fieldCompoundId.UniqueIds.Add(fieldUniqueId); var farmUniqueId = _uniqueIdFactory.CreateGuid(fieldDto.FarmUid); var farmCompoundId = farmUniqueId.ToCompoundIdentifier(); field.FarmId = farmCompoundId.ReferenceId; var growerUniqueId = _uniqueIdFactory.CreateGuid(fieldDto.GrowerUid); var growerCompoundId = growerUniqueId.ToCompoundIdentifier(); var selfLink = new ReferenceLink { Id = fieldCompoundId, Rel = Relationships.Self, Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}" }; var growerLink = new ReferenceLink { Id = growerCompoundId, Rel = typeof(Grower).ObjectRel(), Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}" }; var farmLink = new ReferenceLink { Id = farmCompoundId, Rel = typeof(Farm).ObjectRel(), Link = $"/Farms/{farmUniqueId.Source}/{farmUniqueId.Id}" }; var cropZonesLink = new ReferenceLink { Rel = typeof(CropZone).ListRel(), Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}/CropZones" }; var boundaryLink = new ReferenceLink { Rel = typeof(FieldBoundary).ListRel(), Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}/FieldBoundaries" }; field.Id.UniqueIds.Add(fieldUniqueId); var fieldEnvelope = new ModelEnvelope <Field>(field); fieldEnvelope.Links.Add(selfLink); fieldEnvelope.Links.Add(growerLink); fieldEnvelope.Links.Add(farmLink); fieldEnvelope.Links.Add(cropZonesLink); fieldEnvelope.Links.Add(boundaryLink); return(fieldEnvelope); }
public NameSlot(ReferenceLink id, XmlQualifiedName name) { this.id = id; this.name = name; }
public void AddReferenceLink(Guid mapId, CompendiumNode refenceNode, CompendiumNode originNode) { var xmlLink = new ReferenceLink(mapId, refenceNode, originNode, Doc, _xmlElementLinks); xmlLink.CreateElement(); }
private static ReferenceNode BuildReferenceTree(object graph) { var queue = new Queue <ReferenceNode>(); var rootNode = new ReferenceNode(graph); var referenceMapping = new Dictionary <object, ReferenceNode>(new ReferenceEqualsComparer <object>()); queue.Enqueue(rootNode); referenceMapping.Add(graph, rootNode); while (queue.Count > 0) { var activeNode = queue.Dequeue(); var values = new List <Tuple <object, string> >(); var objectType = activeNode.Object.GetType(); var publicProperties = objectType.GetProperties(BindingFlags.Public | BindingFlags.Instance); var nonpublicProperties = objectType.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance); foreach (var propertyInfo in publicProperties.Concat(nonpublicProperties)) { object value = null; try { if (propertyInfo.GetIndexParameters().Length == 0) { value = propertyInfo.GetValue(activeNode.Object, null); } } catch (Exception) { } if (value == null || value.GetType().IsValueType) { continue; } values.Add(new Tuple <object, string>(value, propertyInfo.Name)); } if (activeNode.Object is IEnumerable) { var enumerable = activeNode.Object as IEnumerable; int count = 0; foreach (var subobject in enumerable) { if (subobject == null || subobject.GetType().IsValueType) { break; } values.Add(new Tuple <object, string>(subobject, "[" + count + "]")); count++; } } foreach (var valueTuple in values) { var value = valueTuple.First; var valueAsCollection = value as ICollection; var valueAsGeometry = value as IGeometry; if (value == null || //skip null values (valueAsCollection != null && valueAsCollection.Count == 0) || //skip empty collections valueAsGeometry != null) //skip geometry { continue; } ReferenceNode referenceNode = null; bool addPath = false; if (referenceMapping.ContainsKey(value)) { referenceNode = referenceMapping[value]; } else { referenceNode = new ReferenceNode(value); referenceMapping.Add(value, referenceNode); queue.Enqueue(referenceNode); addPath = true; } var link = new ReferenceLink(activeNode, referenceNode, valueTuple.Second); activeNode.Links.Add(link); if (addPath) { var path = new List <ReferenceLink>(activeNode.Path); path.Add(link); referenceNode.Path = path; } } } return(rootNode); }