public Link[] GetLinks(params int[] pingIds) { if (pingIds.Length == 0) { return(new Link[0]); } else if (pingIds.Length == 1) { return(Links .Find(Query.EQ("PingId", pingIds[0])) .OrderBy(l => l.User) .ToArray()); } else { var arr = new BsonArray(); foreach (int id in pingIds) { arr.Add(id); } return(Links .Find(Query.In("PingId", arr)) .OrderBy(l => l.User) .ToArray()); } }
public async Task <Response> Get( ReadAllStreamMessageOperation operation, CancellationToken cancellationToken) { var message = await operation.Invoke(_streamStore, cancellationToken); if (message.MessageId == Guid.Empty) { return(new Response( new HALResponse(new HALModelConfig()) .AddLinks(Links.Feed()) .AddLinks(Links.Find()), 404)); } var payload = await message.GetJsonData(cancellationToken); return(new Response( new HALResponse(new { message.MessageId, message.CreatedUtc, message.Position, message.StreamId, message.StreamVersion, message.Type, payload, metadata = message.JsonMetadata }).AddLinks( Links.Self(message), Links.Message(message), Links.Feed(), Links.Find()))); }
public async void Update(Link.Link Link) { while (this.locked) { await Task.Delay(1); } this.locked = true; Link.Link existingLink = Links.Find(l => l.SourceNode == Link.SourceNode && l.TargetNode == Link.TargetNode); // && l.IPv4InterfaceAddress == Link.IPv4InterfaceAddress); if (existingLink == null && Link.OperationalStatus) { Links.Add(Link); this.OnLinkUpCallback?.Invoke(Link); } else { if (Link.OperationalStatus) { Links[Links.IndexOf(existingLink)] = Link; } else { Links.Remove(existingLink); this.OnLinkDownCallback?.Invoke(Link); } } this.OnLinkUpdateCallback?.Invoke(Link); this.locked = false; }
public Link GetLinkByRel(string rel) { Contract.Requires(!string.IsNullOrWhiteSpace(rel)); Contract.Ensures(null != Contract.Result <Link>()); return(Links.Find(l => l.Rel == rel)); }
public LinkSe Link(Predicate <ElementSe> predicate) { try { return(Links.Find(predicate)); } catch (Exception) { return(null); } }
public bool IsProcessing(string url) { var obj = Links.Find(p => p.Url == url); if (obj != null) { if (obj.WorkState == WorkState.Processing) { return(true); } } return(false); }
public Link Link(NodeType type, int startIndex, int endIndex) { Debug.Assert(Enum.IsDefined(typeof(NodeType), type)); Debug.Assert(startIndex >= 0); Debug.Assert(endIndex >= 0); var target = Links.Find(link => link.Type == type && link.StartIndex == startIndex && link.EndIndex == endIndex); if (target != null) { return(target); } target = new Link(type, startIndex, endIndex); AddLink(target); return(target); }
public Link[] GetLinks(string user = null, HashSet <string> guilds = null) { if (string.IsNullOrEmpty(user)) { if (guilds != null && guilds.Any()) { var arr = new BsonArray(); foreach (string guild in guilds) { arr.Add(guild); } return(Links .Find(Query.In("Guild", arr)) .OrderByDescending(l => l.PingId) .ToArray()); } else { return(Links .FindAll() .OrderByDescending(l => l.PingId) .ToArray()); } } else { if (guilds != null && guilds.Any()) { return(Links .Find(Query.EQ("User", user)) .Where(l => guilds.Contains(l.Guild)) .OrderByDescending(l => l.PingId) .ToArray()); } else { return(Links .Find(Query.EQ("User", user)) .OrderByDescending(l => l.PingId) .ToArray()); } } }
private async void ProcessRpmMessage(JObject data) { while (this.locked) { await Task.Delay(1); } this.locked = true; string source_address = (string)data["source_address"]; long rtt = (long)data["rtt"]; var existingLink = Links.Find(l => l.IPv4InterfaceAddress == source_address); if (existingLink != null) { existingLink.Rtt = rtt; } this.locked = false; }
public async Task <Response> Post( AppendStreamOperation operation, CancellationToken cancellationToken) { var result = await operation.Invoke(_streamStore, cancellationToken); var response = new Response( new HALResponse(result) .AddLinks(Links.Self(operation)) .AddLinks(Links.Feed(operation)) .AddLinks(Links.Find()), result.CurrentVersion == 0 ? 201 : 200); if (operation.ExpectedVersion == ExpectedVersion.NoStream) { response.Headers[Constants.Headers.Location] = new[] { $"streams/{operation.StreamId}" }; } return(response); }
private void LoadFile(string filename) { XDocument xdoc = XDocument.Load(filename); XElement node = xdoc.Element("robot"); Name = node.Attribute("name")?.Value; Materials = node.ReadMaterials(); // multiple Links = node.ReadLinks(); // multiple Joints = node.ReadJoints(); // multiple // build tree structure from link and joint lists: foreach (Link.Link link in Links) { link.Joints = Joints.FindAll(v => v.Parent == link.Name); } foreach (Joint.Joint joint in Joints) { joint.ChildLink = Links.Find(v => v.Name == joint.Child); } // save root node only: Root = FindRootLink(Links, Joints); }
public async Task <Response> Get(ReadStreamOperation operation, CancellationToken cancellationToken) { if (!operation.IsUriCanonical) { return(new Response(new HALResponse(null), 308) { Headers = { [Constants.Headers.Location] = new[] { operation.Self } } }); } var page = await operation.Invoke(_streamStore, cancellationToken); var streamMessages = page.Messages.OrderByDescending(m => m.Position).ToArray(); var payloads = await Task.WhenAll( Array.ConvertAll( streamMessages, message => operation.EmbedPayload ? message.GetJsonData(cancellationToken) : SkippedPayload.Instance)); var response = new Response( new HALResponse(new { page.LastStreamVersion, page.LastStreamPosition, page.FromStreamVersion, page.NextStreamVersion, page.IsEnd }) .AddLinks(Links.Self(operation)) .AddLinks(Links.Navigation(page, operation)) .AddLinks(Links.Feed(operation)) .AddLinks(Links.Metadata(operation)) .AddLinks(Links.Index()) .AddLinks(Links.Find()) .AddEmbeddedResource( Constants.Relations.AppendToStream, Schemas.AppendToStream) .AddEmbeddedResource( Constants.Relations.Delete, Schemas.DeleteStream) .AddEmbeddedCollection( Constants.Relations.Message, streamMessages.Zip( payloads, (message, payload) => new HALResponse(new { message.MessageId, message.CreatedUtc, message.Position, message.StreamId, message.StreamVersion, message.Type, payload, metadata = message.JsonMetadata }) .AddLinks( Links.Message.Self(message), Links.Message.Feed(message)))), page.Status == PageReadStatus.StreamNotFound ? 404 : 200); if (page.TryGetETag(out var eTag)) { response.Headers.Add(eTag); } return(response); }
public async Task <Response> Get( ReadStreamMessageByStreamVersionOperation operation, CancellationToken cancellationToken) { var message = await operation.Invoke(_streamStore, cancellationToken); if (message.MessageId == Guid.Empty) { return(new Response( new HALResponse(new { operation.StreamId, operation.StreamVersion }) .AddLinks(Links.Self(operation)) .AddLinks(Links.Navigation(operation)) .AddLinks(Links.Message(operation)) .AddLinks(Links.Find()), 404)); } if (operation.StreamVersion == StreamVersion.End) { return(new Response(new HALResponse(new object()), 307) { Headers = { [Constants.Headers.Location] = new[] { $"{message.StreamVersion}" } } }); } var payload = await message.GetJsonData(cancellationToken); var eTag = ETag.FromStreamVersion(message.StreamVersion); return(new Response( new HALResponse(new { message.MessageId, message.CreatedUtc, message.Position, message.StreamId, message.StreamVersion, message.Type, payload, metadata = message.JsonMetadata }) .AddEmbeddedResource( Constants.Relations.Delete, Schemas.DeleteStreamMessage) .AddLinks(Links.Self(operation)) .AddLinks(Links.Navigation(operation, message)) .AddLinks(Links.Message(operation)) .AddLinks(Links.Find())) { Headers = { eTag, CacheControl.OneYear } }); }
public async Task <Response> Get( ReadAllStreamOperation operation, CancellationToken cancellationToken) { if (_useCanonicalUrls && !operation.IsUriCanonical) { return(new Response(new HALResponse(null), 308) { Headers = { [Constants.Headers.Location] = new[] { operation.Self } } }); } var page = await operation.Invoke(_streamStore, cancellationToken); var streamMessages = page.Messages.OrderByDescending(m => m.Position).ToArray(); var payloads = await Task.WhenAll( Array.ConvertAll( streamMessages, message => operation.EmbedPayload ? message.GetJsonData(cancellationToken) : SkippedPayload.Instance)); var response = new Response( new HALResponse(new { page.FromPosition, page.NextPosition, page.IsEnd }) .AddLinks(Links.Self(operation)) .AddLinks(Links.Navigation(page, operation)) .AddLinks(Links.Feed(operation)) .AddLinks(Links.Find()) .AddEmbeddedCollection( Constants.Relations.Message, streamMessages.Zip( payloads, (message, payload) => new HALResponse(new { message.MessageId, message.CreatedUtc, message.Position, message.StreamId, message.StreamVersion, message.Type, payload, metadata = message.JsonMetadata }) .AddLinks( Links.Message.Self(message), Links.Message.Feed(message))))); if (operation.FromPositionInclusive == Position.End) { var headPosition = streamMessages.Length > 0 ? streamMessages[0].Position : Position.End; response.Headers[Constants.Headers.HeadPosition] = new[] { $"{headPosition}" }; } if (page.TryGetETag(operation.FromPositionInclusive, out var eTag)) { response.Headers.Add(eTag); response.Headers.Add(CacheControl.NoCache); } else { response.Headers.Add(CacheControl.OneYear); } return(response); }
public bool GetMatch(int id, out BaseNode ele) { ele = Links.Find(u => u.IdSet.Contains(id) || u.Id == id); return(ele != null); }