Esempio n. 1
0
        /// <summary>
        /// Get socket option
        /// </summary>
        /// <param name="option"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task <ulong> GetSocketOptionAsync(SocketOption option,
                                                       CancellationToken ct)
        {
            if (!Links.Any())
            {
                return(_optionCache.ContainsKey(option) ? _optionCache[option] : 0);
            }
            var cts = new CancellationTokenSource();

            ct.Register(() => {
                cts.Cancel();
            });
            var tasks = Links.Select(
                i => i.GetSocketOptionAsync(option, cts.Token)).ToList();
            Exception e = null;

            while (tasks.Count > 0)
            {
                var result = await Task.WhenAny(tasks).ConfigureAwait(false);

                try {
                    ulong value = await result.ConfigureAwait(false);

                    cts.Cancel(); // Cancel the rest
                    return(value);
                }
                catch (Exception thrown) {
                    tasks.Remove(result);
                    e = thrown;
                }
            }
            throw new SocketException(e);
        }
 private void AddNewOneToManyRelation(object source, string property, object target)
 {
     if (!Links.Any(x => x.Source == source && x.SourceProperty == property && x.Target == target))
     {
         this.AddLink(source, property, target);
     }
 }
Esempio n. 3
0
 public bool HasLink(int x, int y)
 {
     if (!IsInCurrentArea(x, y))
     {
         return(false);
     }
     return(Links.Any(l => l.x == x && l.z == -y && l.DestinationID != Guid.Empty));
 }
Esempio n. 4
0
 public bool HasLink(int x, int y)
 {
     if (!IsInCurrentArea(x, y))
     {
         return(false);
     }
     return(Links.Any(l => l.DestinationX == x && l.DestinationY == y && l.IsVisible));
 }
        /// <summary>
        /// Receive from one of the contained streams
        /// </summary>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task ReceiveAsync(CancellationToken ct)
        {
            if (!Links.Any())
            {
                throw new SocketException(SocketError.Closed);
            }

            // Fill receive queue from any of the link's receive queue.  If queue is empty
            // replenish it from all streams...
            Message message;

            while (true)
            {
                foreach (var link in Links)
                {
                    while (link.ReceiveQueue.TryDequeue(out message))
                    {
                        if (message.TypeId == MessageContent.Close)
                        {
                            // Remote side closed, close link
                            Links.Remove(link);
                            try {
                                await link.CloseAsync(CancellationToken.None).ConfigureAwait(false);
                            }
                            catch { }

                            if (!Links.Any())
                            {
                                throw new SocketException("Remote side closed",
                                                          null, SocketError.Closed);
                            }
                        }
                        else
                        {
                            ReceiveQueue.Enqueue(message);
                        }
                    }
                }
                if (ReceiveQueue.Any())
                {
                    return;
                }
                else
                {
                    try {
                        var tasks = Links.Select(i => i.ReceiveAsync(ct));
                        await Task.WhenAny(tasks).ConfigureAwait(false);
                    }
                    catch (AggregateException ae) {
                        throw new SocketException("Receive await failed",
                                                  ae, ae.GetSocketError());
                    }
                }
            }
        }
Esempio n. 6
0
        public override string ToWebApiString(Func <int> aliasIndexer = null)
        {
            var definition = DefinitionCache.GetEntityDefinition(EntityName);

            if (!string.IsNullOrEmpty(PagingInfo.PagingCookie))
            {
                return(PagingInfo.PagingCookie.Substring(definition.EntityCollectionName.Length + 1));
            }

            var sb = new StringBuilder();

            sb.Append("$select=");
            foreach (var attribute in Attributes)
            {
                sb.Append(definition.GetWebApiAttributeName(attribute)).Append(",");
            }
            sb.Remove(sb.Length - 1, 1);

            if (Links.Any(l => l.Attributes.Any()))
            {
                sb.Append("&$expand=");
                foreach (var link in Links.Where(l => l.Attributes.Any()))
                {
                    sb.Append(link.ToWebApiString(() => _indexValue++)).Append(",");
                }

                sb.Remove(sb.Length - 1, 1);
            }

            if (Criteria.Conditions.Any() || Criteria.Filters.Any())
            {
                sb.Append("&$filter=");
                sb.Append(Criteria.ToWebApiString(() => _indexValue++));
            }

            if (_orders.Any())
            {
                sb.Append("&$orderby=");
                foreach (var order in _orders)
                {
                    sb.Append($"{definition.GetWebApiAttributeName(order.Item1)} ").Append(order.Item2 ? "desc," : "asc,");
                }

                sb.Remove(sb.Length - 1, 1);
            }

            if (TopCount.HasValue)
            {
                sb.Append($"&$top={TopCount}");
            }

            sb.Append(Criteria.WebApiAliasString);

            return(sb.ToString());
        }
Esempio n. 7
0
 /// <summary>
 /// Send to all contained streams
 /// </summary>
 /// <param name="message"></param>
 /// <param name="ct"></param>
 /// <returns></returns>
 public Task SendAsync(Message message, CancellationToken ct)
 {
     if (!Links.Any())
     {
         throw new SocketException(SocketError.Closed);
     }
     try {
         return(Task.WhenAll(Links.Select(i => i.SendAsync(message, ct))));
     }
     catch (Exception e) {
         throw new SocketException(e);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Initializes the c data.
        /// </summary>
        /// <param name="database">
        /// The database.
        /// </param>
        public void InitCData(CRMDatabase database)
        {
            if (_cdataInitialized)
            {
                return;
            }

            _cdataInitialized = true;
            var infoAreaIdString = InfoAreaId;

            _tableInfo = database.GetTableInfoByInfoArea(infoAreaIdString);
            if (_tableInfo == null)
            {
                return;
            }

            _sourceFieldCount = _fieldIds?.Count ?? 0;
            _intArray         = new FieldIdType[_sourceFieldCount + 1];
            _fieldCount       = 0;
            var linkFields = GetUPContainerFieldMetaInfoLinkFields();

            _cLinkFieldCount = 0;
            _cLinkMapCount   = 0;

            if (linkFields?.Any() == true)
            {
                PopulateLinkMapAndCLinkFieldsFromLinkFields(linkFields);
            }
            else if (Links?.Any() == true)
            {
                PopulateLinkMapAndCLinkFieldsFromLinks();
            }
            else
            {
                _cLinkFields = null;
                _linkMap     = null;
            }

            _recordTemplate = new RecordTemplate(
                database,
                _isSync,
                infoAreaIdString,
                _fieldCount,
                _intArray,
                _cLinkFieldCount,
                _cLinkFields?.ToList(),
                false,
                false);
        }
Esempio n. 9
0
 /// <summary>
 /// Send socket option message to all streams
 /// </summary>
 /// <param name="option"></param>
 /// <param name="value"></param>
 /// <param name="ct"></param>
 public async Task SetSocketOptionAsync(SocketOption option, ulong value,
                                        CancellationToken ct)
 {
     if (!Links.Any())
     {
         _optionCache[option] = value;
     }
     try {
         await Task.WhenAll(Links.Select(
                                i => i.SetSocketOptionAsync(option, value, ct))).ConfigureAwait(false);
     }
     catch (Exception e) {
         throw new SocketException(e);
     }
 }
Esempio n. 10
0
        public bool ConnectionHasErrors(Pin input, Pin output, out string error)
        {
            error = null;

            if (input.Node == output.Node)
            {
                error = "Pins are on the same node";
                return(true);
            }

            if (input.IsInput == output.IsInput)
            {
                error = $"Both pins are {(input.IsInput ? "input" : "output")}";
                return(true);
            }

            if (input.IsExec != output.IsExec)
            {
                error = "Cannot connect data to exec";
                return(true);
            }

            if (Links.Any(l => l.Input == input && l.Output == output))
            {
                error = "Existing connection";
                return(true);
            }

            if (!input.IsExec)
            {
                // TODO: Check if a cast node is defined and spawn it
                if (!output.Type.HasCastDefined(input.Type))
                {
                    error = "No cast defined";
                    return(true);
                }
            }

            if (input.Graph != output.Graph)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 11
0
        public void RepopulateHyperMedia()
        {
            if (Links == null)
            {
                Links = new List <Link>();                // make sure resource.Links.Add() can safely be called inside the overload
            }
            CreateHypermedia();

            if (!string.IsNullOrEmpty(Href) && Links.Count(l => l.Rel == "self") == 0)
            {
                Links.Insert(0, new Link {
                    Rel = "self", Href = Href
                });
            }

            if ((Links != null) && !Links.Any())
            {
                Links = null;                 // prevent _links property serialisation
            }
        }
Esempio n. 12
0
        public bool HasPendingLinkChanges()
        {
            var hasChanges = Links.Any(e => e.State != EntityStates.Unchanged);

            return(hasChanges);
        }
Esempio n. 13
0
 public bool HasLinks(Pin pin)
 {
     return(Links.Any(l => l.Input == pin || l.Output == pin));
 }
Esempio n. 14
0
 /// <summary>
 /// Check if this element has any links matching the argument
 /// </summary>
 /// <param name="word"></param>
 /// <returns></returns>
 public bool HasMatch(byte word)
 {
     return(Links.Any(u => u.IsMatch(word)));
 }
Esempio n. 15
0
        /// <summary>
        /// Receive from one of the contained streams
        /// </summary>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task ReceiveAsync(CancellationToken ct)
        {
            if (!Links.Any())
            {
                throw new SocketException(SocketError.Closed);
            }

            // Fill receive queue from any of the link's receive queue.  If queue is empty
            // replenish it from all streams...
            while (true)
            {
                foreach (var link in Links)
                {
                    Message message;
                    var     queue = link.ReceiveQueue;
                    if (queue == null)
                    {
                        Links.Remove(link);
                    }
                    else
                    {
                        while (queue.TryDequeue(out message))
                        {
                            if (message.TypeId == MessageContent.Close)
                            {
                                // Remote side closed, close link
                                Links.Remove(link);
                                try {
                                    await link.CloseAsync(ct).ConfigureAwait(false);
                                }
                                catch { }
                            }
                            else
                            {
                                ReceiveQueue.Enqueue(message);
                            }
                        }
                    }
                    if (!Links.Any())
                    {
                        throw new SocketException("Remote side closed",
                                                  null, SocketError.Closed);
                    }
                }
                if (ReceiveQueue.Any())
                {
                    return;
                }
                else
                {
                    try {
                        var tasks    = Links.Select(i => i.ReceiveAsync(ct));
                        var selected = await Task.WhenAny(tasks).ConfigureAwait(false);

                        await selected.ConfigureAwait(false);
                    }
                    catch (OperationCanceledException) {
                        throw;
                    }
                    catch (Exception e) {
                        ct.ThrowIfCancellationRequested();
                        throw new SocketException("Receive await failed",
                                                  e, e.GetSocketError());
                    }
                }
            }
        }
Esempio n. 16
0
 public AddDownloadDialog()
 {
     this.InitializeComponent();
     ProgressControl.IsEnabled = false;
     Links.CollectionChanged  += (s, e) => ProgressControl.IsEnabled = Links.Any();
 }
Esempio n. 17
0
 public virtual bool HasLink(string url)
 {
     return(Links.Any(l => l.Url == url));
 }
 public bool ShouldSerializeLinks()
 {
     return(Links.Any());
 }
Esempio n. 19
0
        internal Model(XmlNode node)
        {
            Name          = node.Attributes?["name"]?.Value;
            CanonicalLink = node.Attributes?["canonical_link"]?.Value;

            List <Include> includes = new List <Include>();
            List <Model>   models   = new List <Model>();
            List <Frame>   frames   = new List <Frame>();
            List <Link>    links    = new List <Link>();

            Includes = includes.AsReadOnly();
            Models   = models.AsReadOnly();
            Frames   = frames.AsReadOnly();
            Links    = links.AsReadOnly();

            foreach (XmlNode child in node.ChildNodes)
            {
                switch (child.Name)
                {
                case "static":
                    Static = BoolElement.ValueOf(child);
                    break;

                case "self_collide":
                    SelfCollide = BoolElement.ValueOf(child);
                    break;

                case "allow_auto_disable":
                    AllowAutoDisable = BoolElement.ValueOf(child);
                    break;

                case "include":
                    includes.Add(new Include(child));
                    break;

                case "model":
                    models.Add(new Model(child));
                    break;

                case "enable_wind":
                    EnableWind = BoolElement.ValueOf(child);
                    break;

                case "frame":
                    frames.Add(new Frame(child));
                    break;

                case "pose":
                    Pose = new Pose(child);
                    break;

                case "link":
                    links.Add(new Link(child));
                    break;
                }
            }

            HasIncludes =
                Includes.Count != 0 ||
                Models.Any(model => model.HasIncludes) ||
                Links.Any(link => link.HasUri);
        }