Пример #1
0
        public void WorldUpdatesAutoupdateables()
        {
            var tmxStream = FileStreams.SmallTmx();
            var tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream());

            TmxSerializer   serializer = new TmxSerializer();
            Map             map        = serializer.Deserialize(tmxStream);
            TestingToyWorld toyWorld   = new TestingToyWorld(map, tilesetTableStreamReader);

            toyWorld.SetRegister(new AutoupdateRegister());

            Mock <IAutoupdateableGameActor> mock1 = new Mock <IAutoupdateableGameActor>();
            Mock <IAutoupdateableGameActor> mock2 = new Mock <IAutoupdateableGameActor>();

            toyWorld.AutoupdateRegister.Register(mock1.Object, 1);
            toyWorld.AutoupdateRegister.Register(mock2.Object, 2);

            // Act
            toyWorld.Update();

            // Assert
            mock1.Verify(x => x.Update(It.IsAny <Atlas>(), It.IsAny <TilesetTable>()));
            mock2.Verify(x => x.Update(It.IsAny <Atlas>(), It.IsAny <TilesetTable>()), Times.Never());

            // Act
            toyWorld.Update();

            // Assert
            mock2.Verify(x => x.Update(It.IsAny <Atlas>(), It.IsAny <TilesetTable>()));
        }
Пример #2
0
        protected virtual FileStreamWriter GetFileStream(EventHandler <FileLoggerCallbackArgs> callback)
        {
            var wrapper = !FilePath.IsNullOrEmpty() && FileStreams.ContainsKey(FilePath)
                                ? FileStreams[FilePath] as FileStreamWriter
                                : null;

            if (wrapper != null)
            {
                if (wrapper.FileStream.Length < Settings.MaxFileSize)
                {
                    wrapper.SaveToFile(Settings.LineDelimiter);
                    return(wrapper);
                }
                FileStreams.Remove(wrapper.FilePath);
                wrapper.Close();
            }

            FilePath = GetNewFilePath();
            wrapper  = new FileStreamWriter(FilePath, callback)
            {
                IsFileCompressionEnabled = Settings.UseGzipCompression,
                GzipFileExt = Settings.GzipFileExtension
            };
            wrapper.Callback += OnFileStreamAction;
            FileStreams.Add(FilePath, wrapper);

            if (!Settings.OpeningLine.IsNullOrEmpty())
            {
                wrapper.SaveToFile(Settings.OpeningLine);
            }
            return(wrapper);
        }
Пример #3
0
        public void WorldWithNullTilesetThrows()
        {
            Stream tmxStream = FileStreams.SmallTmx();

            TmxSerializer serializer = new TmxSerializer();
            Map           map        = serializer.Deserialize(tmxStream);

            Assert.Throws <ArgumentNullException>(() => new ToyWorld(map, null));
        }
Пример #4
0
 protected virtual void Dispose(FileStreamWrapperBase wrapper)
 {
     wrapper.Callback -= OnFileStreamAction;
     if (FileStreams.ContainsKey(wrapper.FilePath))
     {
         FileStreams.Remove(wrapper.FilePath);
     }
     wrapper.Dispose();
 }
Пример #5
0
        public TilesetTableTest()
        {
            var tilesetTableMemoryStream = FileStreams.TilesetTableStream();
            var tilesetTableStreamReader = new StreamReader(tilesetTableMemoryStream);

            tilesetTableStreamReader.DiscardBufferedData();
            tilesetTableMemoryStream.Position = 0;
            var tilesetTable = new TilesetTable(null, tilesetTableStreamReader);
        }
Пример #6
0
 public GLRendererTestBase()
 {
     using (var tmxStream = FileStreams.FullTmxStream())
         using (var tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream()))
         {
             var gameSetup = new GameSetup(tmxStream, tilesetTableStreamReader);
             m_gameController = ControllerFactory.GetController(gameSetup);
             m_gameController.Init();
         }
 }
Пример #7
0
        public ToyWorldTests()
        {
            Stream       tmxStream = FileStreams.SmallTmx();
            StreamReader tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream());

            TmxSerializer serializer = new TmxSerializer();
            Map           map        = serializer.Deserialize(tmxStream);

            m_world = new ToyWorld(map, tilesetTableStreamReader);
        }
Пример #8
0
        public AtlasTests()
        {
            Stream       tmxStream = FileStreams.SmallPickupTmx();
            StreamReader tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream());

            TmxSerializer serializer = new TmxSerializer();
            Map           map        = serializer.Deserialize(tmxStream);
            ToyWorld      world      = new ToyWorld(map, tilesetTableStreamReader);

            m_atlas = world.Atlas;
        }
Пример #9
0
    private void BeginReadFile(Stream stream, FileStream fileStream)
    {
        if (this.buff == null)
        {
            this.buff = new byte[BUFFER_SIZE];
        }

        var streams = new FileStreams();

        streams.stream     = stream;
        streams.fileStream = fileStream;
        stream.BeginRead(this.buff, 0, BUFFER_SIZE, this.OnEndReadFlush, streams);
    }
Пример #10
0
        public GameControllerTestBase()
        {
            var tmxMemoryStream          = FileStreams.SmallTmx();
            var tilesetTableMemoryStream = FileStreams.TilesetTableStream();

            var tilesetTableStreamReader = new StreamReader(tilesetTableMemoryStream);

            var gameSetup = new GameSetup(tmxMemoryStream, tilesetTableStreamReader);

            GameController = GetController(gameSetup);

            GameController.Init();
        }
Пример #11
0
        public MapLoaderTests()
        {
            // initiate streamReaders
            var tmxMemoryStream          = FileStreams.SmallTmx();
            var tilesetTableMemoryStream = FileStreams.TilesetTableStream();

            var tilesetTableStreamReader = new StreamReader(tilesetTableMemoryStream);

            var serializer = new TmxSerializer();
            Map map        = serializer.Deserialize(tmxMemoryStream);

            var tilesetTable = new TilesetTable(map, tilesetTableStreamReader);

            // create atlas
            m_atlas = MapLoader.LoadMap(map, tilesetTable, (GameActor actor) => { });
        }
Пример #12
0
        public void LoadFromFile(string filePath, EventHandler <FileLoggerCallbackArgs> callback)
        {
            try
            {
                if (!Settings.IsEnabled)
                {
                    const string errMsg =
                        "reading from log file is aborted. Logger is disabled.\r\nTo enable logger set 'Settings.IsEnabled = true'.";
#if UNITY_3D || UNITY3D
                    UnityEngine.Debug.LogWarning(errMsg);
#else
                    Debug.WriteLine(errMsg);
#endif
                    return;
                }

                ArgumentValidator.AssertNotNullOrEmpty(filePath, "filePath");

                if (!File.Exists(filePath))
                {
                    throw new FileNotFoundException(filePath);
                }
                if (FileStreams.ContainsKey(filePath))
                {
                    throw new OperationCanceledException("File with path '" + filePath + "' is in process.");
                }

                var wrapper = new FileStreamReader(filePath, callback)
                {
                    IsFileCompressionEnabled = Settings.UseGzipCompression
                };
                wrapper.Callback += OnFileStreamAction;
                FileStreams.Add(filePath, wrapper);
                wrapper.LoadFromFile();
            }
            catch (Exception e)
            {
                FileStreamWrapperBase.InvokeFileActionEvent(callback, null, filePath, null, null, FileLoggerAction.Read,
                                                            FileLoggerResult.Error, e);

                if (callback == null)
                {
                    throw;
                }
            }
        }
Пример #13
0
        public static FileStream RequestFileStream(FileStreams requested)
        {
            if (fileStreamBusy)
            {
                return(null);
            }
            else
            {
                switch (requested)
                {
                case FileStreams.RussianDictionary:
                    return(RussianDictionaryFS);

                default:
                    return(null);
                }
            }
        }
Пример #14
0
 public void Flush()
 {
     if (FileStreams.IsNullOrEmpty())
     {
         return;
     }
     try
     {
         FileStreams.Values.ForEach(file => file.Dispose());
     }
     catch (Exception)
     {
         // TODO write exc to some console
     }
     finally
     {
         FileStreams.Clear();
         FilePath = null;
     }
 }
Пример #15
0
        public void AvatarLoosingEnergy()
        {
            Stream       tmxStream = FileStreams.SmallPickupTmx();
            StreamReader tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream());

            TmxSerializer serializer = new TmxSerializer();
            Map           map        = serializer.Deserialize(tmxStream);

            m_worldPickupWorld = new ToyWorld(map, tilesetTableStreamReader);

            m_eater = m_worldPickupWorld.GetAvatar(m_worldPickupWorld.GetAvatarsIds()[0]);

            // Act
            for (int i = 0; i < 100; i++)
            {
                m_eater.Update(m_worldPickupWorld.Atlas, It.IsAny <TilesetTable>());
            }

            // Assert
            Assert.True(m_eater.Energy < 1);
        }
Пример #16
0
        public void AvatarCanPickUp()
        {
            Stream       tmxStream = FileStreams.SmallPickupTmx();
            StreamReader tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream());

            TmxSerializer serializer = new TmxSerializer();
            Map           map        = serializer.Deserialize(tmxStream);

            m_worldPickupWorld = new ToyWorld(map, tilesetTableStreamReader);

            m_avatarPickuper        = m_worldPickupWorld.GetAvatar(m_worldPickupWorld.GetAvatarsIds()[0]);
            m_avatarPickuper.PickUp = true;

            Assert.Equal(null, m_avatarPickuper.Tool);

            // Act
            m_avatarPickuper.Update(m_worldPickupWorld.Atlas, It.IsAny <TilesetTable>());

            // Assert
            Assert.IsType <Apple>(m_avatarPickuper.Tool);
            Assert.False(m_avatarPickuper.PickUp);
        }
Пример #17
0
        public void TestAssignInternetZoneIdentifierToFile()
        {
            var testFile = Path.Combine(Path.GetTempPath(), "ZoneTest" + Guid.NewGuid().ToString("N") + ".txt");

            using (var s = FileHelper.OpenForWrite(testFile))
            {
                s.WriteByte(61);
                s.WriteByte(62);
            }

            var FS = new FileStreams(testFile);

            //Remove Zone.Identifier if it already exists since we can't trust it
            //Not sure if this can happen.
            int i = FS.IndexOf("Zone.Identifier");

            if (i != -1)
            {
                FS.Remove("Zone.Identifier");
            }

            FS.Add("Zone.Identifier");
            using (FileStream fs = FS["Zone.Identifier"].Open(FileMode.OpenOrCreate, FileAccess.Write))
            {
                var writer = new StreamWriter(fs);
                writer.WriteLine("[ZoneTransfer]");
                writer.WriteLine("ZoneId=3");
                writer.Flush();
                fs.Flush();
            }

            FS = new FileStreams(testFile);

            i = FS.IndexOf("Zone.Identifier");
            //TODO: why does this fail?
            //Assert.NotEqual(-1, i);
        }
Пример #18
0
 public HttpParamers AddFile(string key, IFileItem stream)
 {
     FileStreams.Add(key, stream);
     return(this);
 }
Пример #19
0
        /// <summary>
        /// Method used to handle the event.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">The task information.</param>
        private void OnDownloadCompleted(object sender, TaskEventArgs e)
        {
            if (e.Task == null)
            {
                return;
            }

            string fileLocation  = Path.Combine(e.Task.DownloadFilesBase, e.Task.DownloadItem.File.LocalName);
            string finalLocation = Path.Combine(e.Task.DownloadItem.TargetFolder, e.Task.DownloadItem.File.LocalName);

            _log.InfoFormat("Finished downloading enclosure '{0}' from item '{1}' in feed '{2}' to {3}",
                            e.Task.DownloadItem.Enclosure.Url, e.Task.DownloadItem.OwnerItemId,
                            e.Task.DownloadItem.OwnerFeedId, finalLocation);


            // We have a UI for managing enclosures we'll need to keep the task around !
            //DownloadRegistryManager.Current.UnRegisterTask(e.Task);

            try
            {
                /*
                 * Add Zone.Identifier to File to indicate that the file was downloaded from the Web
                 * See http://geekswithblogs.net/ssimakov/archive/2004/08/17/9805.aspx for more details
                 */
                try
                {
                    var FS = new FileStreams(fileLocation);

                    //Remove Zone.Identifier if it already exists since we can't trust it
                    //Not sure if this can happen.
                    int i = FS.IndexOf("Zone.Identifier");
                    if (i != -1)
                    {
                        FS.Remove("Zone.Identifier");
                    }

                    FS.Add("Zone.Identifier");
                    using (FileStream fs = FS["Zone.Identifier"].Open(FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        var writer = new StreamWriter(fs);
                        writer.WriteLine("[ZoneTransfer]");
                        writer.WriteLine("ZoneId=3");
                        writer.Flush();
                    }
                }
                catch (Exception ex)
                {
                    _log.ErrorFormat("Failed to assign Internet (Download) Zone to {0}: {1}", fileLocation, ex.Message);
                }

                if (!Directory.Exists(e.Task.DownloadItem.TargetFolder))
                {
                    Directory.CreateDirectory(e.Task.DownloadItem.TargetFolder);
                }

                /* Move file to TargetFolder from temporary download location*/
                FileHelper.MoveFile(fileLocation, finalLocation, MoveFileFlag.CopyAllowed | MoveFileFlag.ReplaceExisting);

                e.Task.FileName = finalLocation;
                /* Initiate callback to waiting callers */
                if (DownloadCompleted != null)
                {
                    DownloadCompleted(this, new DownloadItemEventArgs(e.Task.DownloadItem));
                }

                var downloader = sender as IDownloader;
                if (downloader != null)
                {
                    Release(downloader);
                }
            }
            catch (Exception error)
            {
                OnDownloadError(this, new DownloadTaskErrorEventArgs(e.Task, error));
                return;
            }

            e.Task.State = DownloadTaskState.Downloaded;
            DownloadRegistryManager.Current.UpdateTask(e.Task);
        }
Пример #20
0
 public void WorldWithNullMapThrows()
 {
     Assert.Throws <ArgumentNullException>(() => new ToyWorld(null, new StreamReader(FileStreams.TilesetTableStream())));
 }
 public ContentController(FileStreams fileStreams)
 {
     _fileStreams = fileStreams;
 }