Exemple #1
0
        public string ResolveVersion(string input)
        {
            var key = IDFSTR.FirstOrDefault(x => x.Value.Contains(input.ToUpper())).Key;

            if (key == null)
            {
                return(null);
            }


            var downloaded = DownloadMainfest();

            try
            {
                return(ResolveVersionFromMainfestFile(key));
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to read '{Config.ManifestJsonFilePath}'", ex);

                if (downloaded)
                {
                    throw;
                }

                Log.Warn($"Failed to executed {nameof(ResolveVersionFromMainfestFile)}; Mainfest was already downloaded, downloading it again, so it's up-to-date", ex);
                DownloadMainfest(true);

                return(ResolveVersionFromMainfestFile(key));
            }
        }
        private void ProcessStateChange(ProcessStateChange obj)
        {
            var(key, target) = _targetProcesses.FirstOrDefault(p => p.Key.Contains(obj.Name));
            if (string.IsNullOrWhiteSpace(key))
            {
                return;
            }

            target.Tell(obj);
        }
Exemple #3
0
        /// <summary>
        /// 获取枚举字段
        /// </summary>
        /// <param name="enumType"></param>
        /// <returns></returns>
        public static EnumField[] GetEnumFields(string enumType)
        {
            if (enumType == null)
            {
                throw new ArgumentNullException("enumType");
            }
            KeyValuePair <Type, EnumField[]> keyValuePair = EnumFiledCache.FirstOrDefault((KeyValuePair <Type, EnumField[]> x) => x.Key.Name == enumType || x.Key.FullName == enumType);

            if (keyValuePair.Key == null)
            {
                return(Array.Empty <EnumField>());
            }
            return(GetEnumFields(keyValuePair.Key));
        }
Exemple #4
0
        public int?FindDistanceWithRecursion(Point start, Point end)
        {
            var queue   = new Queue <(Point Point, int Distance, int Level)>();
            var visited = new HashSet <(Point, int)>();

            queue.Enqueue((start, 0, 0));

            while (queue.Count > 0)
            {
                var(point, distance, level) = queue.Dequeue();

                if (point == end && level == 0)
                {
                    return(distance);
                }

                if (visited.Contains((point, level)))
                {
                    continue;
                }

                visited.Add((point, level));

                foreach (var(neighbour, resLevel) in AdjacentFunction(point, level))
                {
                    queue.Enqueue((neighbour, distance + 1, resLevel));
                }
            }

            return(null);

            IEnumerable <(Point Point, int Level)> AdjacentFunction(Point point, int level)
            {
                var entity = _mapArr[point];

                if (entity is PortalEntity pe)
                {
                    var(matchingPortal, _) = _mapArr.FirstOrDefault(x => x.Value.Identifier == entity.Identifier && x.Key != point);

                    if (matchingPortal is null)
                    {
                        return(GetAdjacentNonWalls(point, level));
                    }

                    var newLevel = pe.PortalType == PortalType.Outer
                        ? level - 1
                        : level + 1;

                    return(GetAdjacentNonWalls(point, level).Concat(new[] { (matchingPortal, newLevel) }));
 public ConfiguredProject GetInnerConfiguredProject(ITargetFramework target)
 {
     return(_configuredProjectsByTargetFramework.FirstOrDefault((x, t) => t.Equals(x.Key), target).Value);
 }
Exemple #6
0
        public ReplicatorActor(ReplicaId myself, ReplicatorSettings settings)
        {
            this.myself            = myself;
            this.settings          = settings;
            replicatorRelativePath = Self.Path.ToStringWithoutAddress();

            Receive <ClusterEvent.MemberUp>(up =>
            {
                if (HasRole(up.Member) && up.Member.Address != cluster.SelfAddress)
                {
                    // send invitation to a new member
                    var path = up.Member.Address.ToString() + replicatorRelativePath;
                    Context.ActorSelection(path).Tell(new Invitation(myself, Self));
                }
            });
            Receive <ClusterEvent.IMemberEvent>(_ => { /* ignore */ });
            Receive <Broadcast <T> >(bcast =>
            {
                var version   = localVersion.Increment(myself);
                var versioned = new Versioned <T>(version, bcast.Message);
                var send      = new Send <T>(myself, myself, versioned);

                if (log.IsInfoEnabled)
                {
                    log.Info("Sending {0} to: {1}", send, string.Join(", ", members));
                }

                foreach (var member in members)
                {
                    member.Value.Forward(send);
                }

                var pendingAck = new PendingAck <T>(myself, versioned, DateTime.UtcNow, members.Keys.ToImmutableHashSet());

                this.pendingAcks  = pendingAcks.Add(pendingAck);
                this.localVersion = version;
            });
            Receive <Send <T> >(send =>
            {
                if (AlreadySeen(send.Versioned.Version))
                {
                    log.Info("Received duplicate message {0}", send);
                }
                else
                {
                    var receivers = members.Remove(send.Origin);

                    var forward = send.WithLastSeenBy(myself);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Broadcasting message {0} to: {1}", forward, string.Join(", ", receivers.Values));
                    }

                    foreach (var member in receivers.Values)
                    {
                        member.Forward(forward);
                    }

                    if (members.TryGetValue(send.LastSeenBy, out var sender))
                    {
                        sender.Tell(new SendAck(myself, send.Versioned.Version), ActorRefs.NoSender);
                    }

                    var deliver = new Deliver <T>(send.Origin, send.Versioned);
                    Self.Forward(deliver);

                    this.pendingDelivery = pendingDelivery.Add(deliver);
                    this.pendingAcks     = pendingAcks.Add(new PendingAck <T>(myself, send.Versioned, DateTime.UtcNow, receivers.Keys.ToImmutableHashSet()));
                }
            });
            Receive <SendAck>(ack =>
            {
                log.Info("Received ACK from {0} (version: {1})", Sender, ack.Version);

                var pendingAck  = this.pendingAcks.First(x => x.Versioned.Version == ack.Version);
                var membersLeft = pendingAck.Members.Remove(ack.ReplicaId);

                this.pendingAcks = pendingAcks.Remove(pendingAck);
                if (!membersLeft.IsEmpty)
                {
                    this.pendingAcks = pendingAcks.Add(pendingAck.WithMembers(membersLeft));
                }
            });
            Receive <Deliver <T> >(deliver =>
            {
                TryToCasuallyDeliver(deliver);

                remoteVersions      = remoteVersions.SetItem(deliver.Origin, deliver.Versioned.Version);
                latestStableVersion = UpdateStableVersion(remoteVersions);
            });
            Receive <Resend>(_ =>
            {
                var now     = DateTime.UtcNow;
                var builder = pendingAcks.ToBuilder();
                foreach (var ack in pendingAcks)
                {
                    if (now - ack.Timestamp > settings.RetryTimeout)
                    {
                        builder.Remove(ack);
                        var send = new Send <T>(myself, myself, ack.Versioned);
                        foreach (var replicaId in ack.Members)
                        {
                            if (members.TryGetValue(replicaId, out var member))
                            {
                                member.Tell(send, ActorRefs.NoSender);
                            }
                        }
                        builder.Add(ack.WithTimestamp(now));
                    }
                }
                pendingAcks = builder.ToImmutable();
            });
            Receive <Invitation>(invitation =>
            {
                log.Info("Received invitation from {0} (ID: {1})", invitation.ReplicatorRef, invitation.ReplicaId);
                members = members.Add(invitation.ReplicaId, invitation.ReplicatorRef);
                Context.Watch(invitation.ReplicatorRef);
            });
            Receive <StableReq>(sync =>
            {
                var reply = sync.Versions.Where(ver => latestStableVersion >= ver).ToArray();
                Sender.Tell(new StableRep(reply));
            });
            Receive <Subscribe <T> >(subscribe =>
            {
                subscribers = subscribers.Add(subscribe.Ref);
                if (subscribe.Ack != null)
                {
                    subscribe.Ref.Tell(subscribe.Ack);
                }
            });
            Receive <Unsubscribe>(unsubscribe =>
            {
                subscribers = subscribers.Remove(unsubscribe.Ref);
                if (unsubscribe.Ack != null)
                {
                    unsubscribe.Ref.Tell(unsubscribe.Ack);
                }
            });
            Receive <Terminated>(terminated =>
            {
                subscribers   = subscribers.Remove(terminated.ActorRef);
                var replicaId = members.FirstOrDefault(kv => Equals(kv.Value, terminated.ActorRef));
                members       = members.Remove(replicaId.Key);
            });

            resendTask = Context.System.Scheduler
                         .ScheduleTellOnceCancelable(settings.ResendInterval, Self, Resend.Instance, ActorRefs.NoSender);
        }