示例#1
0
        public void ExpectAddToThrowIfFunctionIsAlreadyAdded()
        {
            Action <float> func       = dt => {};
            var            updateList = new UpdateList();

            updateList.Add(func);
            Assert.Throws <Exception>(() =>
            {
                updateList.Add(func);
            });
        }
示例#2
0
        public void ExpectRemoveAndReAddWithinAnUpdateLoopToNotRemove()
        {
            var updateList = new UpdateList();

            Action <float> func2 = dt => { };
            Action <float> func1 = dt =>
            {
                updateList.Remove(func2);
                updateList.Add(func2);
            };

            updateList.Add(func1);
            updateList.Add(func2);

            updateList.Update(0f);

            Assert.IsTrue(updateList.Contains(func2));
        }
示例#3
0
        public void ExpectContainsToReturnFalseAfterRemoveWasCalled()
        {
            Action <float> func       = dt => { };
            var            updateList = new UpdateList();

            updateList.Add(func);
            updateList.Remove(func);
            Assert.IsFalse(updateList.Contains(func));
        }
示例#4
0
        public void ExpectContainsToReturnTrueOnlyIfFunctionWasAdded()
        {
            Action <float> func       = dt => {};
            var            updateList = new UpdateList();

            Assert.IsFalse(updateList.Contains(func));
            updateList.Add(func);
            Assert.IsTrue(updateList.Contains(func));
        }
示例#5
0
        public OpenWorldGameMode(ViewportAdapter viewPort, IPossibleMovements possibleMovements, string worldName, EntityManager entityManager, StoryEngine storyEngine, EventHandler clickEvent) : base(clickEvent)
        {
            _entityManager      = entityManager;
            EntityRenderersDict = new Dictionary <Entity, AbstractEntityRenderer>();
            _possibleMovements  = possibleMovements;
            _content            = ContentManagerFactory.RequestContentManager();
            RenderList          = new List <IRenderable>();
            Map = _content.Load <TiledMap>($"TopDownRpg/{worldName}");
            var graphics = StaticServiceLocator.GetService <GraphicsDevice>();

            _mapRenderer = new FullMapRenderer(graphics);
            _mapRenderer.SwapMap(Map);
            _tileSize     = new Vector2(Map.TileWidth, Map.TileHeight);
            _moverManager = new MoverManager();
            var collisionSystem = new CompositeAbstractCollisionSystem(_possibleMovements);

            _expiringSpatialHash = new ExpiringSpatialHashCollisionSystem <Entity>(_possibleMovements);
            _spatialHashMover    = new SpatialHashMoverManager <Entity>(collisionSystem, _expiringSpatialHash);
            AddPlayer();
            var entityController = EntityControllerFactory.AddEntityController(PlayerEntity.Instance, _possibleMovements, _moverManager);
            var texture          = _content.Load <Texture2D>("TopDownRpg/Path");
            var endTexture       = _content.Load <Texture2D>("TopDownRpg/BluePathEnd");

            collisionSystem.AddCollisionSystem(new TiledCollisionSystem(_possibleMovements, Map, "Collision-Layer"));
            collisionSystem.AddCollisionSystem(_expiringSpatialHash);
            CollisionSystem = collisionSystem;
            AddClickController(PlayerEntity.Instance);
            PathRenderer = new PathRenderer(_moverManager, PlayerEntity.Instance, texture, endTexture, _tileSize.ToPoint(), Map.Width, Map.Height);
            UpdateList.Add(_expiringSpatialHash);
            UpdateList.Add(entityController);
            UpdateList.Add(_spatialHashMover);
            UpdateList.Add(_moverManager);
            CameraTracker = CameraTrackerFactory.CreateTracker(viewPort, EntityRenderersDict[PlayerEntity.Instance], Map);
            UpdateList.Add(CameraTracker);
            LoadEntities();
            var dialogFont = _content.Load <SpriteFont>("dialog");
            var settings   = StaticServiceLocator.GetService <IControllerSettings>();

            DialogBox = new EntityStoryBoxDialog(ScreenSize.Size, dialogFont, settings.GamePadEnabled);
            GuiManager.AddGuiLayer(DialogBox);
            storyEngine.LoadWorld(AddEntity, RemoveEntity, CollisionSystem.CheckMovementCollision, worldName);
            InteractEvent += (sender, args) =>
            {
                var facingDirection = PlayerEntity.Instance.FacingDirection;
                var interactTarget  = (PlayerEntity.Instance.Position + facingDirection).ToPoint();
                Interact(interactTarget);
            };
            AddInteractionController();
            CameraController.AddCameraZoomController(CameraTracker, ClickController);
            CameraController.AddCameraMovementController(CameraTracker, ClickController);
        }
示例#6
0
        public void ExpectUpdateToPassDeltaTimeToAllFunctions()
        {
            const float dtParam = 0.112f;

            Action <float> func = dt =>
            {
                Assert.AreEqual(dt, dtParam);
            };

            var updateList = new UpdateList();

            updateList.Add(func);
            updateList.Update(dtParam);
        }
示例#7
0
        //public bool CheckUpdateSync()
        //{
        //    bool _clean = true;
        //    //_clean = readDir("/APPS_CS/", Code.ToLower());
        //    using (var client = new SftpClient(ShareServer.IP.ToString(), ShareServer.User, ShareServer.Password))
        //    {
        //        client.Connect();
        //        _clean = readDirSSH(client,"/APPS_CS/", Code.ToLower(),true);
        //    }
        //    return _clean;
        //}

        private async Task <bool> readDir(string basePath, string relativePath)
        {
            bool _clean = true;
            List <DirectoryItem> list;

            using (var ftp = new cFTP(ShareServer, basePath + relativePath))
            {
                list = await ftp.GetDirectoryList("", getDateTimes : true);
            }
            list.Where(x => x.IsDirectory).ToList().ForEach(async a =>
            {
                _clean = (await readDir(basePath, relativePath + "/" + a.Name) && _clean);
            });
            list.Where(x => !x.IsDirectory).ToList().ForEach(a =>
            {
                if (Exists(LOCAL_PATH + relativePath + "/" + a.Name))
                {
                    if (GetLastWriteTime(LOCAL_PATH + relativePath + "/" + a.Name) != a.DateCreated)
                    {
                        UpdateList.Add(new cUpdateListItem()
                        {
                            AppBotCode = this.Code,
                            AppPath    = this.LocalPath,
                            //ServerPath = basePath + relativePath + "/" + a.Name,
                            LocalPath = LOCAL_PATH + relativePath + "/" + a.Name,
                            Item      = a,
                            Status    = LogonItemUpdateStatus.PENDING
                        });
                        _clean = false;
                    }
                }
                else
                {
                    UpdateList.Add(new cUpdateListItem()
                    {
                        AppBotCode = this.Code,
                        AppPath    = this.LocalPath,
                        //ServerPath = basePath + relativePath + "/" + a.Name,
                        LocalPath = LOCAL_PATH + relativePath + "/" + a.Name,
                        Item      = a,
                        Status    = LogonItemUpdateStatus.PENDING
                    });
                    _clean = false;
                }
            });


            return(_clean);
        }
示例#8
0
        public void ExpectAddedFunctionToBeCalledWhenUpdated()
        {
            var            wasCalled = false;
            Action <float> func      = dt =>
            {
                wasCalled = true;
            };

            var updateList = new UpdateList();

            updateList.Add(func);
            Assert.IsFalse(wasCalled);
            updateList.Update(0f);
            Assert.IsTrue(wasCalled);
        }
示例#9
0
        /// <summary>
        /// Add new key into list of completed update tasks or update existing key
        /// </summary>
        /// <param name="newKey">Name of new key</param>
        /// <param name="updateDone">State of key</param>
        /// <returns></returns>
        public async Task AddKeyAsync(string newKey, bool updateDone = false)
        {
            if ((await GetKeyListAsync()).Contains(item: newKey))
            {
                UpdateList.FirstOrDefault(predicate: x => x.Key == newKey).UpdateDone = updateDone;
            }
            else
            {
                UpdateList.Add(item: new UpdateItem()
                {
                    Key = newKey, UpdateDone = updateDone
                });
            }

            await SaveDataAsync();
        }
示例#10
0
        public void TestPreviousKnownBreakingEdgecases()
        {
            var updateList = new UpdateList();

            // we have to create another ref to the functions so we can self remove within closures
            Action <float> func2 = null;
            Action <float> func0 = null;

            Action <float> update2 = dt =>
            {
                // Do nothing special
            };

            Action <float> update1 = dt =>
            {
                updateList.Remove(func2);
            };

            Action <float> update0 = dt =>
            {
                updateList.Remove(func0);
            };

            func2 = update2;
            func0 = update0;

            updateList.Add(update0);
            updateList.Add(update1);
            updateList.Add(update2);

            updateList.Update(0f);

            Assert.IsFalse(updateList.Contains(update0));
            Assert.IsTrue(updateList.Contains(update1));
            Assert.IsFalse(updateList.Contains(update2));

            // now dead test that index 2 is not marked as dead. by adding new updates, running them and checking they still exist
            updateList.Remove(update1);

            Action <float> update3Index0 = dt => { };
            Action <float> update4Index1 = dt => { };
            Action <float> update5Index2 = dt => { };


            updateList.Add(update3Index0);
            updateList.Add(update4Index1);
            updateList.Add(update5Index2);

            updateList.Update(0f);

            Assert.IsTrue(updateList.Contains(update3Index0));
            Assert.IsTrue(updateList.Contains(update4Index1));
            Assert.IsTrue(updateList.Contains(update5Index2));
        }
示例#11
0
        /// <summary>
        /// List内对象属性值变化后的处理
        /// </summary>
        /// <param name="e"></param>
        private void ItemChanged(ListChangedEventArgs e)
        {
            if ("IsChecked".Equals(e.PropertyDescriptor.Name))
            {
                return;
            }

            //***************************
            //是否要过滤TBModel以外的属性
            //***************************

            if (!InsertList.Contains(this[e.NewIndex]) && !DeleteList.Contains(this[e.NewIndex]) &&
                !UpdateList.Contains(this[e.NewIndex]))
            {
                UpdateList.Add(this[e.NewIndex]);
            }
        }
示例#12
0
        public void ExpectFunctionToNotBeCalledIfRemoveWasCalled()
        {
            var            wasCalled = false;
            Action <float> func      = dt =>
            {
                wasCalled = true;
            };

            var updateList = new UpdateList();

            updateList.Add(func);
            Assert.IsFalse(wasCalled);
            updateList.Remove(func);
            Assert.IsFalse(wasCalled);

            updateList.Update(0f);
            Assert.IsFalse(wasCalled);
        }
示例#13
0
        public void ExpectContainsToReturnFalseAfterRemoveWasCalledDuringFrame()
        {
            // we have to create another ref to the function so we can self remove within closure
            Action <float> funcRef = null;

            var updateList = new UpdateList();

            Action <float> func = dt =>
            {
                updateList.Remove(funcRef);

                Assert.IsFalse(updateList.Contains(funcRef));
            };

            funcRef = func;

            updateList.Add(funcRef);

            updateList.Update(0f);
        }
示例#14
0
        //Register

        /// <summary>
        /// Registers a command class
        /// </summary>
        /// <typeparam name="T">The command class to register</typeparam>
        public void RegisterCommands <T>(ulong?guildid = null) where T : SlashCommandModule
        {
            UpdateList.Add(new KeyValuePair <ulong?, Type>(guildid, typeof(T)));
        }
 public void AddTimer(Timer timer)
 {
     activeTimers.Add(timer);
 }
示例#16
0
        public bool CheckUpdatedXML()
        {
            bool     clean            = true;
            XElement xe               = null;
            XElement xs               = null;
            XElement zipFile          = null;
            string   zipFileName      = "";
            string   zipFilePath      = "";
            DateTime zipFileDateTime  = DateTime.MinValue;
            string   zipLocalFilePath = "";

            try
            {
                if (Special)
                {
                    xs               = XMLSystemState.Descendants("special").First(s => s.Attribute("name").Value == Code.ToLower());
                    zipFile          = xs.Descendants("File").First();
                    zipFileName      = zipFile.Attribute("fileName").Value;
                    zipFilePath      = zipFile.Attribute("path").Value.Replace("\\", "/");
                    zipFileDateTime  = DateTime.Parse(zipFile.Attribute("fileTime").Value);
                    zipLocalFilePath = LOCAL_PATH + zipFilePath + zipFileName;
                    if (File.Exists(zipLocalFilePath))
                    {
                        File.Delete(zipLocalFilePath);
                    }
                }
                xe = XMLSystemState.Descendants("system").First(s => s.Attribute("name").Value == Code.ToLower());
            } catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
            foreach (var file in xe.Descendants("File").ToList())
            {
                var fileName      = file.Attribute("fileName").Value;
                var filePath      = file.Attribute("path").Value.Replace("\\", "/");
                var fileDateTime  = DateTime.Parse(file.Attribute("fileTime").Value);
                var localFilePath = LOCAL_PATH + filePath + fileName;
                if (File.Exists(localFilePath))
                {
                    if (!Special)
                    {
                        var localFileDate = GetLastWriteTime(localFilePath);
                        //var localFileInfo = new FileInfo(localFilePath);
                        if ((localFileDate - fileDateTime).Duration().TotalSeconds > 10)
                        {
                            clean = false;
                        }
                    }
                }
                else
                {
                    clean = false;
                }
                if (!clean)
                {
                    if (Special) //adds only the zip file
                    {
                        UpdateList.Add(new cUpdateListItem()
                        {
                            AppBotCode = this.Code,
                            AppPath    = this.LocalPath,
                            Item       = new DirectoryItem()
                            {
                                Server      = ShareServer,
                                DateCreated = zipFileDateTime,
                                IsDirectory = false,
                                Name        = zipFileName,
                                BaseUri     = new UriBuilder("ftp://" + ShareServer.HostName + "/APPS_CS/" + zipFilePath).Uri
                            },
                            LocalPath = zipLocalFilePath,
                            Status    = LogonItemUpdateStatus.PENDING,
                            zipFile   = true
                                        //ThreadNum = UpdateList.Count % Values.MaxNumThreads
                        });
                        break;
                    }
                    else
                    {
                        UpdateList.Add(new cUpdateListItem()
                        {
                            AppBotCode = this.Code,
                            AppPath    = this.LocalPath,
                            Item       = new DirectoryItem()
                            {
                                Server      = ShareServer,
                                DateCreated = fileDateTime,
                                IsDirectory = false,
                                Name        = fileName,
                                BaseUri     = new UriBuilder("ftp://" + ShareServer.HostName + "/APPS_CS/" + filePath).Uri
                            },
                            LocalPath = localFilePath,
                            Status    = LogonItemUpdateStatus.PENDING,
                            //ThreadNum = UpdateList.Count % Values.MaxNumThreads
                        });
                    }
                }
            }
            return(clean);
        }
示例#17
0
        // CheckUpdated -> Returns true if all the files for this APP are updated.
        public async Task <bool> CheckUpdated(bool force = false)
        {
            //ShowStatus(AppBotStatus.CHECKING);

            bool _clean = true;

            if (!File.Exists(LocalPath) || File.Exists(LocalPath) && FileVersionInfo.GetVersionInfo(LocalPath).FileVersion.ToString() != version || Special == true || force == true)
            {
                using (var client = new FtpClient())
                {
                    client.ConnectTimeout     = 120000;
                    client.Host               = ShareServer.IP.ToString();
                    client.Credentials        = new NetworkCredential(ShareServer.User, ShareServer.Password);
                    client.DataConnectionType = FtpDataConnectionType.EPSV;
                    try
                    {
                        await client.ConnectAsync();
                    }
                    catch
                    {
                        await Task.Delay(500);

                        try
                        {
                            await client.ConnectAsync();
                        }
                        catch
                        {
                            await Task.Delay(500);

                            await client.ConnectAsync();
                        }
                    }
                    if (Special)
                    {
                        var         specialFilePath = LOCAL_PATH + Code.ToLower() + ".zip";
                        FtpListItem a;
                        try
                        {
                            a = (await client.GetListingAsync("/APPS_CS/")).FirstOrDefault(x => x.Name == Code.ToLower() + ".zip");
                        } catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return(false);
                        }
                        if (GetLastWriteTime(specialFilePath) != a.Modified || !Exists(specialFilePath) || !Directory.Exists(Path.GetDirectoryName(LocalPath)))
                        {
                            UpdateList.Add(new cUpdateListItem()
                            {
                                AppBotCode = this.Code,
                                AppPath    = this.LocalPath,
                                Item       = new DirectoryItem()
                                {
                                    Server      = ShareServer,
                                    DateCreated = a.Modified,
                                    IsDirectory = false,
                                    Name        = a.Name,
                                    BaseUri     = new UriBuilder("ftp://" + ShareServer.HostName + "/APPS_CS").Uri
                                },
                                LocalPath = specialFilePath,
                                Status    = LogonItemUpdateStatus.PENDING,
                                //ThreadNum = UpdateList.Count % Values.MaxNumThreads
                            });
                            _clean = false;
                        }
                        else
                        {
                            _clean = true;
                        }
                    }
                    else
                    {
                        _clean = await readDirFTP(client, "/APPS_CS/", Code.ToLower());
                    }
                }
            }
            return(_clean);
        }
示例#18
0
        public void AddInteractionController()
        {
            var controller     = new SmartController();
            var buttonsCreated = StaticServiceLocator.ContainsService <List <IButtonAble> >();

            if (!buttonsCreated)
            {
                var interactButton = new List <IButtonAble>
                {
                    new KeyButton(Keys.E),
                    new GamePadButton(Buttons.A)
                };
                StaticServiceLocator.AddService(interactButton);
            }
            var buttons     = StaticServiceLocator.GetService <List <IButtonAble> >();
            var smartButton = new CompositeSmartButton(buttons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    if (!DialogBox.Interact())
                    {
                        InteractEvent?.Invoke(this, null);
                    }
                }
            };

            controller.AddButton(smartButton);
            var upButton = new List <IButtonAble> {
                new DirectionGamePadButton(Buttons.DPadUp, PlayerIndex.One, false)
            };
            var smartUpButton = new CompositeSmartButton(upButton)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    DialogBox.Up();
                }
            };

            controller.AddButton(smartUpButton);
            var downButton = new List <IButtonAble> {
                new DirectionGamePadButton(Buttons.DPadDown, PlayerIndex.One, false)
            };
            var smartDownButton = new CompositeSmartButton(downButton)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    DialogBox.Down();
                }
            };

            controller.AddButton(smartDownButton);
            var optionsButtons = new List <IButtonAble>
            {
                new KeyButton(Keys.Escape),
                new GamePadButton(Buttons.Start)
            };
            var optionsAction = new CompositeSmartButton(optionsButtons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    _backButtonClickEvent.Invoke(this, null);
                }
            };

            controller.AddButton(optionsAction);
            UpdateList.Add(controller);
        }
示例#19
0
        //public bool CheckUpdatedSync()
        //{
        //    ShowStatus(AppBotStatus.CHECKING);
        //    bool _clean = true;
        //    using (var client = new FtpClient())
        //    {
        //        client.ConnectTimeout = 60000;
        //        client.Host = ShareServer.HostName;
        //        client.Credentials = new NetworkCredential(ShareServer.User, ShareServer.Password);
        //        client.DataConnectionType = FtpDataConnectionType.AutoActive;
        //        client.Connect();
        //        _clean = readDirFTP(client, "/APPS_CS/", Code.ToLower());
        //    }
        //    if (!_clean)
        //        ShowStatus(AppBotStatus.PENDING_UPDATE);
        //    return _clean;
        //}


        private async Task <bool> readDirFTP(FtpClient client, string basePath, string relativePath, bool _checkFiles = true)
        {
            bool _clean = true;
            //client.ChangeDirectory(basePath + relativePath);
            var _path = basePath + relativePath;



            var list = await client.GetListingAsync(_path);

            foreach (var a in list.Where(x => x.Type == FtpFileSystemObjectType.Directory))
            {
                bool _condition = !Directory.Exists(LOCAL_PATH + relativePath + "/" + a.Name);
                if (_condition == false)
                {
                    _condition = (a.Modified != Directory.GetLastWriteTime(LOCAL_PATH + relativePath + "/" + a.Name));
                }
                if (_condition)
                {
                    UpdateDir.Add(new cUpdateListItem()
                    {
                        AppBotCode = this.Code,
                        AppPath    = this.LocalPath,
                        Item       = new DirectoryItem()
                        {
                            Server      = ShareServer,
                            DateCreated = a.Modified,
                            IsDirectory = true,
                            Name        = ".",
                            BaseUri     = new UriBuilder("ftp://" + ShareServer.HostName + "/APPS_CS/" + relativePath + "/" + a.Name).Uri
                        },
                        LocalPath = LOCAL_PATH + relativePath + "/" + a.Name,
                        Status    = LogonItemUpdateStatus.PENDING
                    });
                }
                _clean = await readDirFTP(client, basePath, relativePath + "/" + a.Name, _condition) && _clean;
            }
            ;

            if (_checkFiles)
            {
                foreach (var a in list.Where(x => x.Type == FtpFileSystemObjectType.File))
                {
                    if (Exists(LOCAL_PATH + relativePath + "/" + a.Name))
                    {
                        if (GetLastWriteTime(LOCAL_PATH + relativePath + "/" + a.Name) != a.Modified)
                        {
                            //if (Status != AppBotStatus.PENDING_UPDATE)
                            //    ShowStatus(AppBotStatus.PENDING_UPDATE);
                            UpdateList.Add(new cUpdateListItem()
                            {
                                AppBotCode = this.Code,
                                AppPath    = this.LocalPath,
                                Item       = new DirectoryItem()
                                {
                                    Server      = ShareServer,
                                    DateCreated = a.Modified,
                                    IsDirectory = false,
                                    Name        = a.Name,
                                    BaseUri     = new UriBuilder("ftp://" + ShareServer.HostName + "/APPS_CS/" + relativePath).Uri
                                },
                                LocalPath = LOCAL_PATH + relativePath + "/" + a.Name,
                                Status    = LogonItemUpdateStatus.PENDING
                            });
                            _clean = false;
                        }
                    }
                    else
                    {
                        UpdateList.Add(new cUpdateListItem()
                        {
                            AppBotCode = this.Code,
                            AppPath    = this.LocalPath,
                            Item       = new DirectoryItem()
                            {
                                Server      = ShareServer,
                                DateCreated = a.Modified,
                                IsDirectory = false,
                                Name        = a.Name,
                                BaseUri     = new UriBuilder("ftp://" + ShareServer.HostName + "/APPS_CS/" + relativePath).Uri
                            },
                            LocalPath = LOCAL_PATH + relativePath + "/" + a.Name,
                            Status    = LogonItemUpdateStatus.PENDING
                        });
                        _clean = false;
                    }
                }
            }
            // this part added to remove local files not present in remote directory
            if (Directory.Exists(LOCAL_PATH + relativePath + "/"))
            {
                var localList = new DirectoryInfo(LOCAL_PATH + relativePath + "/").EnumerateFileSystemInfos();
                foreach (var _file in localList)
                {
                    if (list.FirstOrDefault(x => x.Name == _file.Name) == null)
                    {
                        if (_file is FileInfo)
                        {
                            _file.Delete();
                        }
                        if (_file is DirectoryInfo)
                        {
                            ((DirectoryInfo)_file).Delete(true);
                        }
                    }
                }
            }
            return(_clean);
        }