public void ShouldCreateUpdate_WithVisiblePlayers_FromConnection(
        [Frozen] Mock <IPlayerRepository> playerRepository,
        [Frozen] Mock <IConnectedClientStore> store,
        List <ConnectedClient> connectedClients,
        Player player,
        UpdateFactory sut)
    {
        var state = player.GetState();

        playerRepository.Setup(x => x.Find(state.PlayerId))
        .Returns(player);

        store.Setup(x => x.FindInGroups(It.Is <IEnumerable <string> >(
                                            en => en.Single() == $"location_{state.LocationId}")))
        .Returns(connectedClients);

        var update = (Update)sut.GetUpdateFor(state.PlayerId);

        Assert.NotEmpty(connectedClients);
        Assert.Equal(connectedClients.Count, update.VisiblePlayers.Count());
        foreach (var client in connectedClients)
        {
            Assert.Contains(client.ClientId, update.VisiblePlayers);
        }
    }
Exemple #2
0
        protected override void CustomProcessRequest(HttpContext context)
        {
            UpdateFactory   factory        = new UpdateFactory(context);
            IUpdateBehavior updateBehavior = factory.Create();

            updateBehavior.Update();
        }
Exemple #3
0
 public ConcurrentCache(SourceProducer sourceProducer, KeyProducer keyProducer, UpdateFactory updateFactory, CreateFactory createFactory, RemovedAction removedAction = null)
 {
     _sourceFactory = sourceProducer;
     _updateFactory = updateFactory;
     _createFactory = createFactory;
     _keyProducer   = keyProducer;
     _removedAction = removedAction;
 }
    public void ShouldThrow_WhenClientIdIsInvalid(UpdateFactory sut)
    {
        Assert.Throws <ArgumentNullException>(
            () => sut.GetUpdateFor(null !));

        Assert.Throws <ArgumentException>(
            () => sut.GetUpdateFor(string.Empty));
    }
    public void ShouldThrow_WhenPlayerDoesNotExist(
        PlayerId playerId,
        [Frozen] Mock <IPlayerRepository> playerRepository,
        UpdateFactory sut)
    {
        playerRepository.Setup(x => x.Find(playerId))
        .Returns <Player>(null);

        Assert.Throws <InvalidOperationException>(
            () => sut.GetUpdateFor(playerId));
    }
    public void ShouldCreateUpdate_WithCurrentLocation(
        [Frozen] Mock <IPlayerRepository> playerRepository,
        Player player,
        UpdateFactory sut)
    {
        var state = player.GetState();

        playerRepository.Setup(x => x.Find(state.PlayerId))
        .Returns(player);

        var update = (Update)sut.GetUpdateFor(state.PlayerId);

        Assert.Equal(state.LocationId, update.LocationId);
    }
        /// <inheritdoc />
        public void Tick()
        {
            using (LockingPolicy.ReaderLock(null, CancellationToken.None))
            {
                //For every player we need to do some processing so that we can entity data update values
                foreach (var guid in PlayerGuids)
                {
                    InterestCollection interest = GetEntityInterestCollection(guid);

                    //Even if we only know ourselves we should do this anyway
                    //so that the client can receieve entity data changes about itself

                    //TODO: We probably won't send an update about ALL entites, so this is some wasted allocations and time
                    List <EntityAssociatedData <FieldValueUpdate> > updates = new List <EntityAssociatedData <FieldValueUpdate> >(interest.ContainedEntities.Count);

                    foreach (var interestingEntityGuid in interest.ContainedEntities)
                    {
                        //Don't build an update for entities that don't have any changes
                        if (!ChangeTrackerHasChangesForEntity(interestingEntityGuid))
                        {
                            continue;
                        }

                        //TODO: We should cache this update value so we don't need to recompute it for ALL players who are interested
                        //This is the update collection for the particular Entity with guid interestingEntityGuid
                        //We want to use the CHANGE TRACKING bitarray for updates. If this was initial discovery we'd use the SIT bitarray to send all set values.
                        FieldValueUpdate update = UpdateFactory.Create(new EntityFieldUpdateCreationContext(ChangeTrackingCollections[interestingEntityGuid], ChangeTrackingCollections[interestingEntityGuid].ChangeTrackingArray));

                        updates.Add(new EntityAssociatedData <FieldValueUpdate>(interestingEntityGuid, update));
                    }

                    //It's possible no entity had updates, so we should not send a packet update
                    if (updates.Count != 0)
                    {
                        SendUpdate(guid, updates);
                    }
                }

                foreach (var dataEntityCollection in ChangeTrackingCollections.Values)
                {
                    dataEntityCollection.ClearTrackedChanges();
                }
            }
        }
Exemple #8
0
        private async Task CheckForUpdates()
        {
            if (Configuration?.General?.CheckForUpdates == true)
            {
                bool useBetaChannel = Configuration?.General?.IncludePrereleaseUpdates == true;

                LogTo.Info("Searching for app updates...");
                LogTo.Info($"Using beta channel for updates: {useBetaChannel}");

                try
                {
                    using (var mgr = await UpdateFactory.Construct(useBetaChannel))
                    {
                        var release = await mgr.UpdateApp();

                        Version newVersion = release?.Version?.Version;

                        if (newVersion == null)
                        {
                            LogTo.Warn("UpdateApp returned null");
                        }
                        else if (newVersion > Assembly.GetExecutingAssembly().GetName().Version)
                        {
                            LogTo.Info($"Updated app to {release.Version}");
                            Notifier.DisplayMessage(string.Format(Strings.UpdateHasBeenInstalled, release.Version),
                                                    NotificationType.Information | NotificationType.Restart);
                        }
                        else
                        {
                            LogTo.Info("App is up to date");
                        }
                    }
                }
                catch (Exception ex) when(ex.Message.Contains("Update.exe"))
                {
                }
                catch (Exception ex)
                {
                    LogTo.WarnException("Error during update check", ex);
                }
            }
        }
Exemple #9
0
        /// <inheritdoc />
        public void Tick()
        {
            foreach (var entry in GuidToInterestCollectionMappable.EnumerateWithGuid(KnownEntities, EntityType.Player))
            {
                InterestCollection interest = entry.ComponentValue;

                //Even if we only know ourselves we should do this anyway
                //so that the client can receieve entity data changes about itself

                //TODO: We probably won't send an update about ALL entites, so this is some wasted allocations and time
                List <EntityAssociatedData <FieldValueUpdate> > updates = new List <EntityAssociatedData <FieldValueUpdate> >(interest.ContainedEntities.Count);

                foreach (var interestingEntityGuid in interest.ContainedEntities)
                {
                    //Don't build an update for entities that don't have any changes
                    if (!ChangeTrackerHasChangesForEntity(interestingEntityGuid))
                    {
                        continue;
                    }

                    //TODO: We should cache this update value so we don't need to recompute it for ALL players who are interested
                    //This is the update collection for the particular Entity with guid interestingEntityGuid
                    //We want to use the CHANGE TRACKING bitarray for updates. If this was initial discovery we'd use the SIT bitarray to send all set values.
                    FieldValueUpdate update = UpdateFactory.Create(new EntityFieldUpdateCreationContext(ChangeTrackingCollections.RetrieveEntity(interestingEntityGuid), ChangeTrackingCollections.RetrieveEntity(interestingEntityGuid).ChangeTrackingArray));

                    updates.Add(new EntityAssociatedData <FieldValueUpdate>(interestingEntityGuid, update));
                }

                //It's possible no entity had updates, so we should not send a packet update
                if (updates.Count != 0)
                {
                    SendUpdate(entry.EntityGuid, updates);
                }
            }

            foreach (var dataEntityCollection in ChangeTrackingCollections.Enumerate(KnownEntities))
            {
                dataEntityCollection.ClearTrackedChanges();
            }
        }
Exemple #10
0
    private ResUpdateManager()
    {
        //this.progress = Progress.Instance;

        this.updateModel = new UpdateModel();
        NotifyFileSize   = (uint fileSize) =>
        {
            //totalZipFileSize = fileSize;
            //this.progressInfo = "(" + Math.Round(Convert.ToDouble(fileSize) / (1024d * 1024d), 3).ToString() + "M)" + LangMgr.GetString(Language.UPDATE_RES_TIPS);
            //Debug.Log("更新包字节数:" + totalZipFileSize);
        };
        //更新进度条显示;
        NotifyDownLoadedSize = (int size) =>
        {
            currZipFileSize = currZipFileSize + (uint)size;
            //float percent = Mathf.Clamp01((currZipFileSize * 1.0f) / (totalZipFileSize * 1.0f));
            //progress.Show(percent, this.progressInfo);
        };
        NotifyDownLoadError = () =>
        {
            Debug.Log("下载更新包错误");
            ClearHttpDownloadData();
            //progress.Close();
            GameObject.Destroy(HttpDownLoader.instance.gameObject);
        };
        //更新包下载完毕回调;
        NotifyDownLoadedComplete = () =>
        {
            IsDownLoadOver = true;
            GameObject.DestroyImmediate(HttpDownLoader.instance.gameObject);
            Debug.Log("更新包下载完:" + SaveZippath);
            if (!ZipHelper.UnZip(SaveZippath, this.updateModel.LocalResPathRoot))
            {
                //解压失败处理;
                if (File.Exists(SaveZippath))
                {
                    File.Delete(SaveZippath);
                }
                this.Start();
                return;
            }
            DeleteOldFile();

            // 在完成一次下载解压过程后,需要判断是否还有其他的包未下载
            // 则继续执行下载过程
            if (resServerVO.GetUrlCount() == 0)
            {
                SaveNewVersionFile(updateModel.ServerVersion.ToString());
                this.CurrentVersion = this.updateModel.ServerVersion.ToString();
                this.updateCompeleHandler();
                //BxFacade.Instance.SendNotification(NotifyDef.ResUpdateComplete);
            }
            else
            {
                Uri uri = new Uri(resServerVO.PopUrl());
                this.StartUpdatePackage(uri);
            }
        };
        this.load = UpdateFactory.CreateTcpLoad((loadHelper) =>
        {
            //MessageBoxVO vo = new MessageBoxVO();
            //vo.Confirm = "重试";
            //vo.Content = "网络故障 请重试";
            //vo.Type = MessageBoxType.SINGLE_BUTTON;
            //vo.ResultCallback = (r) =>
            //{
            //    if (r)
            //    {
            //        this.Start();
            //    }
            //};
            //BxFacade.Instance.SendNotification(NotifyDef.OPEN_MESSAGE_BOX_PANEL, vo);
        });
    }
Exemple #11
0
        public async Task OnLoad(object data)
        {
            if (!HasContexts)
            {
                var csa = new ConfirmServiceArgs(Strings.DoYouWantToAddANewAccount, Strings.NoAccountAdded);

                if (await ViewServiceRepository.Confirm(csa))
                {
                    await ViewServiceRepository.ShowAccounts(true);
                }
            }

            await CheckCredentials();

            var loadTasks = Columns.Select(c => c.Load());
            await Task.WhenAll(loadTasks);

            try
            {
                await TwitterConfig.QueryConfig();
            }
            catch (Exception ex)
            {
                LogTo.WarnException("Failed to read current config from twitter", ex);
            }

            if (Configuration?.General?.CheckForUpdates == true)
            {
                bool useBetaChannel = Configuration?.General?.IncludePrereleaseUpdates == true;

                var channelUrl = useBetaChannel
                                        ? Constants.Updates.BetaChannelUrl
                                        : Constants.Updates.ReleaseChannelUrl;

                LogTo.Info("Searching for app updates...");
                LogTo.Info($"Using beta channel for updates: {useBetaChannel}");

                try
                {
                    using (var mgr = UpdateFactory.Construct(channelUrl))
                    {
                        var release = await mgr.UpdateApp();

                        Version newVersion = release?.Version?.Version;

                        if (newVersion == null)
                        {
                            LogTo.Warn("UpdateApp returned null");
                        }
                        else if (newVersion > Assembly.GetExecutingAssembly().GetName().Version)
                        {
                            LogTo.Info($"Updated app to {release.Version}");
                            Notifier.DisplayMessage(string.Format(Strings.UpdateHasBeenInstalled, release.Version),
                                                    NotificationType.Information);
                        }
                        else
                        {
                            LogTo.Info("App is up to date");
                        }
                    }
                }
                catch (Exception ex) when(ex.Message.Contains("Update.exe"))
                {
                }
                catch (Exception ex)
                {
                    LogTo.WarnException("Error during update check", ex);
                }
            }

            await QueryRateLimit();
        }
 public Task Invoke(Update update, UpdateFactory factory)
 {
     factory.CurrentUpdate = update;
     return(_next(update));
 }
Exemple #13
0
 public GildedRose(IList <Item> Items,
                   UpdateFactory UpdateFactory)
 {
     this.Items         = Items;
     this.UpdateFactory = UpdateFactory;
 }