Пример #1
0
        public void NotAddFoundEntityToRepository()
        {
            var factory = new PackageFactory(PackageTestFixtures.GetDtoWithTwoShapes());
            var package = Isolate.Fake.Instance<Package>();
            var repos = Isolate.Fake.Instance<IRepository<Package>>();

            Isolate.NonPublic.WhenCalled(factory, "Find").WillReturn(package);
            Isolate.WhenCalled(() => repos.Add(package)).IgnoreCall();
            factory.Get();

            Isolate.Verify.WasNotCalled(() => repos.Add(package));
        }
Пример #2
0
        private void PackageKeyTest()
        {
            CipherDescription cd1 = new CipherDescription(
                SymmetricEngines.RHX,
                192, IVSizes.V128,
                CipherModes.CTR,
                PaddingModes.None,
                BlockSizes.B128,
                RoundCounts.R22);

            CSPPrng rnd = new CSPPrng();

            byte[] di = new byte[16];
            byte[] oi = new byte[16];
            byte[] pi = new byte[16];
            byte[] pd = new byte[32];
            byte[] ti = new byte[16];
            rnd.GetBytes(di);
            rnd.GetBytes(oi);
            rnd.GetBytes(pi);
            rnd.GetBytes(pd);
            rnd.GetBytes(ti);
            KeyAuthority ka1 = new KeyAuthority(di, oi, pi, pd, KeyPolicies.IdentityRestrict | KeyPolicies.NoExport | KeyPolicies.NoNarrative, 1, ti);

            MemoryStream mk  = new MemoryStream();
            PackageKey   pk1 = new PackageKey(ka1, cd1, 100);

            PackageFactory pf = new PackageFactory(mk, ka1);

            pf.Create(pk1);

            byte[]     bpk = pk1.ToBytes();
            PackageKey pk2 = new PackageKey(bpk);

            if (!pk1.Equals(pk2))
            {
                throw new Exception("KeyFactoryTest: PackageKey serialization has failed!");
            }

            PackageKey pk3 = new PackageKey(mk);

            if (!pk1.Equals(pk3))
            {
                throw new Exception("KeyFactoryTest: PackageKey serialization has failed!");
            }
            if (pk1.GetHashCode() != pk2.GetHashCode() || pk1.GetHashCode() != pk3.GetHashCode())
            {
                throw new Exception("KeyFactoryTest: PackageKey hash code test has failed!");
            }
            pf.Dispose();
        }
Пример #3
0
        public void GetPackage()
        {
            PackageFactory test = new PackageFactory(PlatformManagerMock.Object, ManifestExtractorMock.Object, PackageVerifierMock.Object);

            IResult <IPackage> result = test.GetPackage(TempDirectory);

            string fqn = PackageManifest.Namespace + "." + PackageManifest.Name;

            Assert.Equal(ResultCode.Success, result.ResultCode);
            Assert.Equal(TempDirectory, result.ReturnValue.DirectoryName);
            Assert.Equal(fqn, result.ReturnValue.FQN);
            Assert.Equal(PackageManifest.Name, result.ReturnValue.Manifest.Name);
            Assert.Equal(PackageManifest.Namespace, result.ReturnValue.Manifest.Namespace);
        }
Пример #4
0
            public void InitializesPackageWithMetadata()
            {
                // Arrange
                var path = Path.Combine(_directory, "package.nupkg");

                TestData.CopyResourceToPath(TestData.PackageResource, path);

                // Act
                var package = PackageFactory.Open(path);

                // Assert
                Assert.Equal(TestData.PackageId, package.Id);
                Assert.Equal(TestData.PackageVersion, package.Version);
            }
Пример #5
0
    public Package()
    {
        //初始化ASP.NET内置对象
        Response    = System.Web.HttpContext.Current.Response;
        Request     = System.Web.HttpContext.Current.Request;
        Server      = System.Web.HttpContext.Current.Server;
        Session     = System.Web.HttpContext.Current.Session;
        Application = System.Web.HttpContext.Current.Application;

        tools     = ToolsFactory.CreateTools();
        MyBLL     = PackageFactory.CreatePackage();
        MyBLLPRO  = ProductFactory.CreateProduct();
        MyProduct = new Product();
    }
Пример #6
0
        public void UpdateAllPackagesFromUpdatesAndInstallAnotherPackage()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                var installed1 = PackageFactory.Create("update1", new Version(1, 0));
                var installed2 = PackageFactory.Create("update2", new Version(1, 0));
                this.PackageManager.InstalledPackages.Add(installed1);
                this.PackageManager.InstalledPackages.Add(installed2);

                var remote1 = PackageFactory.Create("update1", new Version(2, 0));
                var remote2 = PackageFactory.Create("update2", new Version(2, 0));
                var remote3 = PackageFactory.Create("install1", new Version(1, 0));
                this.PackageManager.RemotePackages.Add(remote1);
                this.PackageManager.RemotePackages.Add(remote2);
                this.PackageManager.RemotePackages.Add(remote3);

                // Perform UpdateAll now

                ButtonBarViewModel buttonBarViewModel = this.CreateViewModel(thread);
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_Updated, installed1.Id);

                this.ClickButton(thread, buttonBarViewModel, buttonBarViewModel.UpdateAllButton, PackageViewModelAction.UpdateAll);
                Assert.True(buttonBarViewModel.NuGetViewModel.IsLicensePageVisible, "The license page should be shown.");
                Assert.True(buttonBarViewModel.NuGetViewModel.IsUpdatingAll, "Updating all should be true");
                Assert.False(buttonBarViewModel.NuGetViewModel.NotUpdatingAll, "Not Updating all should be false");
                Assert.Equal <PackageViewModelAction>(PackageViewModelAction.UpdateAll, buttonBarViewModel.NuGetViewModel.PackageAction);

                this.ClickButton(thread, buttonBarViewModel, buttonBarViewModel.AcceptButton);

                // Perform Install Now
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_All, remote3.Id);

                this.ClickButton(thread, buttonBarViewModel, buttonBarViewModel.InstallButton, PackageViewModelAction.InstallOrUninstall);
                Assert.True(buttonBarViewModel.NuGetViewModel.IsDetailsPaneVisible, "The details page should be shown.");
                Assert.Equal <PackageViewModelAction>(PackageViewModelAction.InstallOrUninstall, buttonBarViewModel.NuGetViewModel.PackageAction);

                this.ClickButton(thread, buttonBarViewModel, buttonBarViewModel.YesButton);
                Assert.True(buttonBarViewModel.NuGetViewModel.IsLicensePageVisible, "The license page should be shown.");
                Assert.False(buttonBarViewModel.NuGetViewModel.IsUpdatingAll, "Updating all should be false");
                Assert.True(buttonBarViewModel.NuGetViewModel.NotUpdatingAll, "Not Updating all should be true");
                Assert.Equal <PackageViewModelAction>(PackageViewModelAction.InstallOrUninstall, buttonBarViewModel.NuGetViewModel.PackageAction);

                this.ClickButton(thread, buttonBarViewModel, buttonBarViewModel.AcceptButton);

                var installedPackages = this.PackageManager.InstalledPackages.ToArray();
                Assert.Equal(remote1, installedPackages[0]);
                Assert.Equal(remote2, installedPackages[1]);
                Assert.Equal(remote3, installedPackages[2]);
            }
        }
        public override void Arrive()
        {
            // 1) send event
            var json = PackageFactory.CreateArrivalMessage(GetComponent <ShipData>().uid);

            SocketHandler.EmitNow("unit-arrival", json);

            // 2) schedule event
            ((GameMp)Game.Shared).ScheduleAt("unit-arrival", json["scheduleId"].ToObject <long>(), json["packageId"].ToObject <int>(), () =>
            {
                var uid = json["uid"].ToObject <int>();
                Registry.Ships[uid].GetComponent <PlayMakerFSM>().SendEvent("Arrive");
            });
        }
Пример #8
0
        public void GetPackageArchiveVerified()
        {
            PackageVerifierMock.Setup(p => p.VerifyPackage(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(true);

            PackageFactory test = new PackageFactory(PlatformManagerMock.Object, ManifestExtractorMock.Object, PackageVerifierMock.Object);

            IResult <IPackageArchive> result = test.GetPackageArchive(Guid.NewGuid().ToString());

            Assert.Equal(ResultCode.Success, result.ResultCode);
            Assert.Equal(PackageVerification.Verified, result.ReturnValue.Verification);
            Assert.Equal(PackageManifest.Name, result.ReturnValue.Manifest.Name);
            Assert.Equal(PackageManifest.Namespace, result.ReturnValue.Manifest.Namespace);
        }
Пример #9
0
        public void SelectAnotherSourceHidesDetails()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                var feedSource1     = new FeedSource("http://1.com", "source1");
                var feedSource2     = new FeedSource("http://2.com", "source2");
                var sources         = new FeedSource[] { feedSource1, feedSource2 };
                var feedSourceStore = new InMemoryFeedSourceStore(feedSource1, sources);

                var packageSourcesViewModel = new PackageSourcesViewModel(new PackageSourcesModel(feedSource1, feedSourceStore));

                var packageManager = new InMemoryPackageManager();
                packageManager.RemotePackages.Add(PackageFactory.Create("select me"));

                NuGetViewModel viewModel = null;
                thread.Dispatcher.Invoke((Action)(() =>
                {
                    viewModel = new NuGetViewModel(
                        this.Descriptor.Object,
                        this.Host.Object,
                        packageSourcesViewModel,
                        (uri, site) => packageManager,
                        this.ReadonlyDestination,
                        thread.Scheduler);
                }));
                viewModel.WaitUntilComplete();

                Assert.Equal <FeedSource>(feedSource1, viewModel.SelectedFeedSource);

                var firstFilter  = viewModel.Filters[0];
                var itemToSelect = firstFilter.FilteredItems.OfType <object>().First();
                thread.Invoke(() =>
                {
                    viewModel.SelectedItem = itemToSelect;

                    // show the details page
                    viewModel.IsDetailsPaneVisible = true;
                });

                thread.Dispatcher.Invoke((Action)(() =>
                {
                    viewModel.SelectedFeedSourceItem = feedSource2;
                }));
                viewModel.WaitUntilComplete();

                Assert.Equal <FeedSource>(feedSource2, viewModel.SelectedFeedSource);
                Assert.False(viewModel.IsDetailsPaneVisible, "The details pane should be hidden now.");
            }
        }
Пример #10
0
 public CreateProjectHandler(
     SheepItDbContext dbContext,
     PackageFactory packageFactory,
     DeploymentProcessFactory deploymentProcessFactory,
     EnvironmentFactory environmentFactory,
     ProjectFactory projectFactory,
     ComponentFactory componentFactory)
 {
     _dbContext                = dbContext;
     _packageFactory           = packageFactory;
     _deploymentProcessFactory = deploymentProcessFactory;
     _environmentFactory       = environmentFactory;
     _projectFactory           = projectFactory;
     _componentFactory         = componentFactory;
 }
        public void InstalledPackageSelectedInstalledFilter()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                var package = PackageFactory.Create("installed");
                this.PackageManager.InstalledPackages.Add(package);

                ButtonBarViewModel buttonBarViewModel = this.CreateViewModel(thread);
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_Installed, package.Id);

                Assert.Equal(
                    new ButtonViewModel[] { buttonBarViewModel.UninstallButton, buttonBarViewModel.CloseButton },
                    buttonBarViewModel.ActionButtons);
            }
        }
Пример #12
0
        /// <summary>
        ///     Handles the specified package.
        /// </summary>
        /// <param name="message">The package.</param>
        /// <param name="senderEndpoint">The sender's endpoint.</param>
        private void HandlePackage(Package message, PlayerNetworkSession playerSession)
        {
            TraceReceive(message);

            if (typeof(UnknownPackage) == message.GetType())
            {
                return;
            }

            if (typeof(McpeBatch) == message.GetType())
            {
                McpeBatch batch = (McpeBatch)message;

                var messages = new List <Package>();

                // Get bytes
                byte[] payload = batch.payload;
                // Decompress bytes

                MemoryStream stream = new MemoryStream(payload);
                if (stream.ReadByte() != 0x78)
                {
                    throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
                }
                stream.ReadByte();
                using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
                {
                    // Get actual package out of bytes
                    MemoryStream destination = new MemoryStream();
                    defStream2.CopyTo(destination);
                    byte[] internalBuffer = destination.ToArray();
                    messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer));
                }
                foreach (var msg in messages)
                {
                    HandlePackage(msg, playerSession);
                }
            }

            playerSession.Player.HandlePackage(message);
            playerSession.LastUpdatedTime = DateTime.UtcNow;

            if (typeof(DisconnectionNotification) == message.GetType())
            {
                PlayerNetworkSession value;
                _playerSessions.TryRemove(playerSession.EndPoint, out value);
            }
        }
Пример #13
0
    private void OnBlockUpdateAfterPopulation(object[] param)
    {
        ChunkBlockChangedPackage package = PackageFactory.GetPackage(PackageType.ChunkBlockChanged) as ChunkBlockChangedPackage;
        WorldPos pos       = (WorldPos)param[0];
        int      x         = (int)param[1];
        int      y         = (int)param[2];
        int      z         = (int)param[3];
        Block    b         = (Block)param[4];
        Int16    index     = ClientChangedChunk.GetChunkIndex(x, y, z);
        byte     blockType = (byte)b.BlockType;
        byte     extendId  = b.ExtendId;

        package.pos          = pos;
        package.changedBlock = new ClientChangedBlock(index, blockType, extendId);
        SendPackage(package);
    }
Пример #14
0
        public void SelectMandatoryPackage()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                this.PackageManager.SupportsEnableDisable = true;

                var installed = PackageFactory.Create("WebMatrixExtensionsGallery", new Version(1, 0));
                this.PackageManager.InstalledPackages.Add(installed);

                ButtonBarViewModel buttonBarViewModel = this.CreateViewModel(thread);
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_Installed, installed.Id);

                Assert.False(buttonBarViewModel.NuGetViewModel.UninstallCommand.CanExecute(null), "The uninstall command should be disabled");
                Assert.True(buttonBarViewModel.NuGetViewModel.DisableCommand.CanExecute(null), "The disable command should be enabled");
            }
        }
Пример #15
0
            public void InitializesPackageWithSupportedFrameworks()
            {
                // Arrange
                var path = Path.Combine(_directory, "package.nupkg");

                TestData.CopyResourceToPath(TestData.PackageResource, path);

                // Act
                var package = PackageFactory.Open(path);

                // Assert
                var frameworks = package.GetSupportedFrameworks();
                var framework  = Assert.Single(frameworks);

                Assert.Equal(VersionUtility.ParseFrameworkName("net40-client"), framework);
            }
Пример #16
0
    private void OnChunkDataRemoveFinish(object[] param)
    {
        NetRemovedChunk netRemovedChunk = param[0] as NetRemovedChunk;
        Chunk           chunk           = netRemovedChunk.chunk;
        //当chunk为移除时,向服务器发送chunk移除消息
        PlayerRemoveChunkPackage removePackage = PackageFactory.GetPackage(PackageType.PlayerRemoveChunk) as PlayerRemoveChunkPackage;

        removePackage.pos = chunk.worldPos;
        SendPackage(removePackage);

        if (netRemovedChunk.needSave)
        {
            for (int i = 0; i < netRemovedChunk.changedEntityInfos.Count; i++)
            {
                EntityData       entityData = new EntityData();
                ClientEntityInfo info       = netRemovedChunk.changedEntityInfos[i];
                entityData.id     = info.entityId;
                entityData.type   = info.type;
                entityData.pos    = info.position;
                entityData.exData = info.extData;
                chunk.AddEntityData(entityData);
            }
            NetChunkData netChunkData = WorldPersistanceManager.Instance.GetNetChunkData(chunk, roleId);
            //如果当前客户端是主机客户端,直接保存文件到当前本地,否则,将数据发送给服务器,保存在主机
            if (isMainClient)
            {
                World.world.WorldGenerator.DataProcessorManager.EnqueueSaveNetChunkData(netChunkData);
            }
            else
            {
//				//上面已经移除掉了
//				//先移除
//				PlayerRemoveChunkPackage removeChunkPackage = PackageFactory.GetPackage(PackageType.PlayerRemoveChunk) as PlayerRemoveChunkPackage;
//				removeChunkPackage.pos = chunk.worldPos;
//				SendPackage(removeChunkPackage);
                //先需要从服务器上拿最新的entity数据,更新后再保存
                //再保存
                PlayerSaveChunkOnServerPackage package = PackageFactory.GetPackage(PackageType.PlayerSaveChunkOnServer)
                                                         as PlayerSaveChunkOnServerPackage;
                package.pos           = chunk.worldPos;
                package.chunkByteData = netChunkData.data.data;
                package.compressType  = (byte)netChunkData.data.compressType;
                package.roleId        = netChunkData.roleId;
                SendPackage(package);
            }
        }
    }
Пример #17
0
        void ApplyPatches(PackageInfo package, PackageSystem vfs)
        {
            Version currentVersion = package.Version;
            Version nextVersion    = currentVersion;

            List <PackageInfo> applyList = new List <PackageInfo>();

            // search latest patch version
            PackageInfo best = null;

            do
            {
                best = null;

                foreach (PackageInfo info in PackageInfos)
                {
                    if (info.GameName == package.Package)
                    {
                        if (info.Type == PackageType.Patch)
                        {
                            if (info.BaseVersion == currentVersion && info.Version > nextVersion)
                            {
                                best        = info;
                                nextVersion = info.Version;
                            }
                        }
                    }
                }

                if (best != null)
                {
                    currentVersion = nextVersion;
                    applyList.Add(best);
                }
            } while (best != null);

            // apply patches
            foreach (PackageInfo info in applyList)
            {
                if (!vfs.ExistsMount(info.Package))
                {
                    PackageFactory factory = new PackageFactory();
                    IPackage       p       = factory.OpenPackage(basePath + info.Package);
                    vfs.Mount(info.Package, p);
                }
            }
        }
Пример #18
0
        private void HandleSplitMessage(PlayerNetworkSession playerSession, ConnectedPackage package, SplitPartPackage splitMessage)
        {
            int spId    = package._splitPacketId;
            int spIdx   = package._splitPacketIndex;
            int spCount = package._splitPacketCount;

            if (!playerSession.Splits.ContainsKey(spId))
            {
                playerSession.Splits.TryAdd(spId, new SplitPartPackage[spCount]);
            }

            SplitPartPackage[] spPackets = playerSession.Splits[spId];
            spPackets[spIdx] = splitMessage;

            bool haveEmpty = false;

            for (int i = 0; i < spPackets.Length; i++)
            {
                haveEmpty = haveEmpty || spPackets[i] == null;
            }

            if (!haveEmpty)
            {
                Log.DebugFormat("Got all {0} split packages for split ID: {1}", spCount, spId);

                SplitPartPackage[] waste;
                playerSession.Splits.TryRemove(spId, out waste);

                MemoryStream stream = new MemoryStream();
                for (int i = 0; i < spPackets.Length; i++)
                {
                    SplitPartPackage splitPartPackage = spPackets[i];
                    byte[]           buf = splitPartPackage.Message;
                    stream.Write(buf, 0, buf.Length);
                    splitPartPackage.PutPool();
                }

                byte[] buffer = stream.ToArray();

                Package fullMessage = PackageFactory.CreatePackage(buffer[0], buffer) ?? new UnknownPackage(buffer[0], buffer);
                fullMessage.DatagramSequenceNumber = package._datagramSequenceNumber;
                fullMessage.OrderingChannel        = package._orderingChannel;
                fullMessage.OrderingIndex          = package._orderingIndex;
                HandlePackage(fullMessage);
                fullMessage.PutPool();
            }
        }
Пример #19
0
    private void InitServerMainPlayerInfo()
    {
        //初始化主玩家的一些信息
        MainClientInitPackage package    = PackageFactory.GetPackage(PackageType.MainClientInit) as MainClientInitPackage;
        GameObject            mainPlayer = HasActionObjectManager.Instance.playerManager.getMyPlayer();

        package.roleId          = roleId;
        package.position        = mainPlayer.transform.position;
        package.aoId            = mainPlayer.GetComponent <PlayerAttributes>().aoId;
        package.playerId        = mainPlayer.GetComponent <PlayerAttributes>().playerId;
        package.worldConfigName = WorldConfig.Instance.name;
        package.seed            = WorldConfig.Instance.seed;
        package.time            = DayNightTime.Instance.TotalTime;
        SendPackage(package);

        //初始化当前玩家内存中的chunk信息到服务器
        foreach (var key in World.world.chunks)
        {
            WorldPos chunkPos = key.Key;
            int      sign     = key.Value.GetSign();
            PlayerAddChunkPackage addChunkPackage = PackageFactory.GetPackage(PackageType.PlayerAddChunk) as PlayerAddChunkPackage;
            addChunkPackage.pos  = chunkPos;
            addChunkPackage.sign = sign;
            SendPackage(addChunkPackage);
        }

        //初始化主玩家的entity信息到服务器上(暂时只同步怪物)
        MainClientEntityInitPackage entityInitPackage = PackageFactory.GetPackage(PackageType.MainClientEntityInit) as MainClientEntityInitPackage;
        List <ClientEntityInfo>     list        = new List <ClientEntityInfo>();
        List <GameObject>           listMonster = HasActionObjectManager.Instance.monsterManager.listObj();

        for (int i = 0; i < listMonster.Count; i++)
        {
            GOMonsterController controller = listMonster[i].GetComponent <GOMonsterController>();
            ClientEntityInfo    info       = new ClientEntityInfo();
            EntityData          entityData = controller.GetEntityData();
            info.roleId   = roleId;
            info.aoId     = controller.monsterAttribute.aoId;
            info.entityId = entityData.id;
            info.type     = EntityType.MONSTER;
            info.position = entityData.pos;
            info.extData  = entityData.exData;
            list.Add(info);
        }
        entityInitPackage.entityInfos = list;
        SendPackage(entityInitPackage);
    }
Пример #20
0
        public void OnJSONEvent(JObject json, string senderId)
        {
            var message = json["message"].ToString();

            if (message.Equals("ping"))
            {
                PingTime = Time.time;
                GooglePlayServiceHelper.Shared.RtsHandler.BroadcastMessage(PackageFactory.CreatePong());
            }

            if (message.Equals("pong"))
            {
                PingLabel.text = Time.time - PingTime + "ms";
                PingTime       = Time.time;
                GooglePlayServiceHelper.Shared.RtsHandler.BroadcastMessage(PackageFactory.CreatePing());
            }
        }
Пример #21
0
        public Builder(string name)
        {
            this.name          = name;
            TopicRouter        = new TopicRouter();
            MonitorCache       = new MonitorCache();
            RequestRouter      = new RequestRouter();
            PackageFactory     = new PackageFactory();
            TopicDispatcher    = new TopicDispatcher();
            RequestDispatcher  = new RequestDispatcher();
            SubscriptionsCache = new SubscriptionsCache();
            SerializerCache    = new SerializerCache();

            SenderCache     = new SenderCache(RequestRouter, MonitorCache);
            ReceiverCache   = new ReceiverCache(MonitorCache);
            PublisherCache  = new PublisherCache(MonitorCache);
            SubscriberCache = new SubscriberCache(TopicRouter, MonitorCache, SubscriptionsCache);
        }
Пример #22
0
        public void OnJSONEvent(JObject json)
        {
            var message = json["message"].ToString();

            if (message.Equals("ping"))
            {
                SocketHandler.EmitNow("pong", PackageFactory.CreatePong());
            }

            if (message.Equals("latency"))
            {
                Game.ExecuteOnMainThread.Enqueue(() =>
                {
                    guiText.text = json["latency"] + " ms";
                });
            }
        }
Пример #23
0
    private void SyncMonsterAction()
    {
        List <GameObject> list = HasActionObjectManager.Instance.monsterManager.listObj();

        for (int i = 0; i < list.Count; i++)
        {
            MonsterSyncActionPakage package = PackageFactory.GetPackage(PackageType.MonsterSyncAction)
                                              as MonsterSyncActionPakage;
            GameObjectController controller = list[i].GetComponent <GameObjectController>();
            package.aoId      = controller.baseAttribute.aoId;
            package.direction = controller.gameObjectInputState.moveDirection;
            package.isJump    = controller.gameObjectInputState.jump;
            package.actionId  = controller.goActionController.curAction.actionData.id;
            package.yRotate   = list[i].transform.localRotation.eulerAngles.y;
            SendPackage(package);
        }
    }
        public void UpdateAllNotShownWhenOnly1PackageHasUpdates()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                var installedPackage1 = PackageFactory.Create("update1", new Version(1, 0));
                this.PackageManager.InstalledPackages.Add(installedPackage1);

                var remotePackage1 = PackageFactory.Create("update1", new Version(2, 0));
                this.PackageManager.RemotePackages.Add(remotePackage1);

                ButtonBarViewModel buttonBarViewModel = this.CreateViewModel(thread);
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_Updated, installedPackage1.Id);

                Assert.False(buttonBarViewModel.ActionButtons.Contains(buttonBarViewModel.UpdateAllButton));
                Assert.True(buttonBarViewModel.ActionButtons.Contains(buttonBarViewModel.UpdateButton));
            }
        }
Пример #25
0
        public void FirstTryToFindAnEntityInTheRepository()
        {
            var factory = new PackageFactory(PackageTestFixtures.GetDtoWithTwoShapes());
            var package = Isolate.Fake.Instance<Package>();
            Isolate.NonPublic.WhenCalled(factory, "Find").WillReturn(package);
            factory.Get();

            try
            {
                Isolate.Verify.NonPublic.WasCalled(factory, "Find");
            }
            catch (Exception e)
            {
                if(e.GetType() != typeof(VerifyException)) throw;
                Assert.Fail();
            }
        }
        public void DisablablePackageSelected()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                this.PackageManager.SupportsEnableDisable = true;

                var installedPackage = PackageFactory.Create("disable", new Version(1, 0));
                this.PackageManager.InstalledPackages.Add(installedPackage);

                ButtonBarViewModel buttonBarViewModel = this.CreateViewModel(thread);
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_Installed, installedPackage.Id);

                Assert.Equal(
                    new ButtonViewModel[] { buttonBarViewModel.DisableButton, buttonBarViewModel.UninstallButton, buttonBarViewModel.CloseButton },
                    buttonBarViewModel.ActionButtons);
            }
        }
Пример #27
0
        private void OnBatch(Package message)
        {
            McpeBatch batch = (McpeBatch)message;

            var messages = new List <Package>();

            // Get bytes
            byte[] payload = batch.payload;
            // Decompress bytes

            MemoryStream stream = new MemoryStream(payload);

            if (stream.ReadByte() != 0x78)
            {
                throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
            }
            stream.ReadByte();
            using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
            {
                // Get actual package out of bytes
                MemoryStream destination = new MemoryStream();
                defStream2.CopyTo(destination);
                destination.Position = 0;
                NbtBinaryReader reader = new NbtBinaryReader(destination, true);
                do
                {
                    int    len            = reader.ReadInt32();
                    byte[] internalBuffer = reader.ReadBytes(len);
                    var    package        = PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer);
                    messages.Add(package);

                    if (!(package is McpeFullChunkData))
                    {
                        Log.Debug($"Batch: {package.GetType().Name} 0x{package.Id:x2} \n{Package.HexDump(internalBuffer)}");
                    }
                } while (destination.Position < destination.Length);
            }
            foreach (var msg in messages)
            {
                msg.DatagramSequenceNumber = batch.DatagramSequenceNumber;
                msg.OrderingChannel        = batch.OrderingChannel;
                msg.OrderingIndex          = batch.OrderingIndex;
                HandlePackage(msg);
                msg.PutPool();
            }
        }
Пример #28
0
    // Main -- Fill a priority queue with packages, then remove a random number of them
    static void Main()
    {
        Console.WriteLine("Create a priority queue:");
        PriorityQueue <Package> pq = new PriorityQueue <Package>();

        Console.WriteLine("Add a random number (0 - 20) of random packages to the queue:");
        Package        pack;
        PackageFactory fact = new PackageFactory();

        // Generate a random number less than 20
        Random rand        = new Random();
        int    numToCreate = rand.Next(20); // Random int from 0 - 20

        Console.WriteLine("\tCreating {0} packages: ", numToCreate);

        for (int i = 0; i < numToCreate; i++)
        {
            Console.Write("\t\tGenerating and adding random package {0}", i);
            pack = fact.CreatePackage();
            Console.WriteLine(" with priority {0}", pack.Priority);
            pq.Enqueue(pack);
        }

        Console.WriteLine("See what we got:");
        int total = pq.Count;

        Console.WriteLine("Packages received: {0}", total);
        Console.WriteLine("Remove a random number of packages (0 - 20): ");
        int numToRemove = rand.Next(20);

        Console.WriteLine("\tRemoving up to {0} packages", numToRemove);

        for (int i = 0; i < numToRemove; i++)
        {
            pack = pq.Dequeue();
            if (pack != null)
            {
                Console.WriteLine("\t\tShipped package with priority {0}",
                                  pack.Priority);
            }
        }

        // See how many were shipped
        Console.WriteLine("Shipped {0} packages", total - pq.Count);
    }
Пример #29
0
        public void UninstallPackageFromInstalled()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                var package = PackageFactory.Create("uninstall");
                this.PackageManager.InstalledPackages.Add(package);

                ButtonBarViewModel buttonBarViewModel = this.CreateViewModel(thread);
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_Installed, package.Id);

                this.ClickButton(thread, buttonBarViewModel, buttonBarViewModel.UninstallButton);
                Assert.True(buttonBarViewModel.NuGetViewModel.IsUninstallPageVisible, "The uninstall page should be shown.");

                this.ClickButton(thread, buttonBarViewModel, buttonBarViewModel.YesButton);

                Assert.False(this.PackageManager.InstalledPackages.Any(), "The package should be uninstalled");
            }
        }
        public void UpdatablePackageSelectedUpdatesFilter()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                var installedPackage = PackageFactory.Create("update", new Version(1, 0));
                this.PackageManager.InstalledPackages.Add(installedPackage);

                var remotePackage = PackageFactory.Create("update", new Version(2, 0));
                this.PackageManager.RemotePackages.Add(remotePackage);

                ButtonBarViewModel buttonBarViewModel = this.CreateViewModel(thread);
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_Updated, installedPackage.Id);

                Assert.Equal(
                    new ButtonViewModel[] { buttonBarViewModel.UpdateButton, buttonBarViewModel.UninstallButton, buttonBarViewModel.CloseButton },
                    buttonBarViewModel.ActionButtons);
            }
        }
        /**
         * a += i1
         * b += i2
         *
         * (b-a) * t + a
         * t = [0...1]
         */
        private static void Send()
        {
            if (!Game.IsRunning())
            {
                return;
            }

            for (var i = 0; i < _selected.Count - 1; ++i)
            {
                //Debug.Log("send " + _selected[i] + " to " + _selected[_selected.Count - 1]);

                var source      = Registry.Islands[_selected[i]];
                var destination = Registry.Islands[_selected[_selected.Count - 1]];

                var toMovePlanes = new List <int>();

                foreach (var pair in Registry.Ships)
                {
                    // UnityEngine.Debug.Log("bla: " + (source.transform == Registry.Instance.Ships[pair.Key].transform.parent));
                    if (source.transform == Registry.Ships[pair.Key].transform.parent)
                    {
                        var plane = Registry.Ships[pair.Key];

                        // only move if you own it
                        if (plane.GetComponent <ShipData>().PlayerData.uid != Game.Shared.ClientUid)
                        {
                            continue;
                        }

                        if (plane.GetComponent <ShipData>().uid != pair.Key)
                        {
                            Debug.Log("WARNING! ship id != registry id on move-units");
                        }

                        // add to move-unit list
                        toMovePlanes.Add(pair.Key);
                    }
                }
                if (toMovePlanes.Count > 0)
                {
                    SocketHandler.Emit("move-unit", PackageFactory.CreateMoveUnitMessage(destination.GetComponent <IslandData>().Uid, toMovePlanes.ToArray()));
                }
            }
        }
        public void UninstallPageButtons()
        {
            using (var thread = new TemporaryDispatcherThread())
            {
                var package = PackageFactory.Create("installed");
                this.PackageManager.InstalledPackages.Add(package);

                ButtonBarViewModel buttonBarViewModel = this.CreateViewModel(thread);
                this.SelectPackage(thread, buttonBarViewModel.NuGetViewModel, Resources.Filter_Installed, package.Id);

                Assert.True(buttonBarViewModel.UninstallButton.Command.CanExecute(null));
                thread.Invoke(() => { buttonBarViewModel.UninstallButton.Command.Execute(null); });
                buttonBarViewModel.NuGetViewModel.WaitUntilComplete();

                Assert.Equal(
                    new ButtonViewModel[] { buttonBarViewModel.YesButton, buttonBarViewModel.NoButton },
                    buttonBarViewModel.ActionButtons);
            }
        }