public void TestSerialization()
        {
            var resources = new List <LocalizationResource>
            {
                new LocalizationResource()
                {
                    Id               = 1,
                    Author           = "migration-tool",
                    ResourceKey      = "test-key",
                    ModificationDate = new DateTime(2016, 1, 1),
                    Translations     = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation
                        {
                            Id       = 11,
                            Language = "en",
                            Value    = "test value"
                        }
                    }
                }
            };

            var serializer = new JsonDataSerializer();
            var result     = serializer.Serialize(resources);

            Assert.NotNull(result);
        }
        public void TestSerialization()
        {
            var resources = new List<LocalizationResource>
                            {
                                new LocalizationResource()
                                {
                                    Id = 1,
                                    Author = "migration-tool",
                                    ResourceKey = "test-key",
                                    ModificationDate = new DateTime(2016, 1, 1),
                                    Translations = new List<LocalizationResourceTranslation>
                                                   {
                                                       new LocalizationResourceTranslation
                                                       {
                                                           Id = 11,
                                                           Language = "en",
                                                           Value = "test value"
                                                       }
                                                   }
                                }
                            };

            var serializer = new JsonDataSerializer();
            var result = serializer.Serialize(resources);

            Assert.NotNull(result);
        }
Пример #3
0
        /// <summary>
        /// Запуск приложения-сервера передачи котировок.
        /// </summary>
        internal void Run()
        {
            UdpClient sender = new UdpClient();

            IPAddress  remoteAddress = IPAddress.Parse(_endPointSettings.IPAddress);
            IPEndPoint endPoint      = new IPEndPoint(remoteAddress, _endPointSettings.Port);

            int counter = 0;

            while (true)
            {
                //получаем цену котировок
                double price = _quotesService.GetPrice();

                //отправляемая информацию о котировке
                QuoteDTO package = new QuoteDTO()
                {
                    Price = price,
                    Index = counter++
                };

                byte[] buffer = JsonDataSerializer.Serialize(package);
                sender.Send(buffer, buffer.Length, endPoint);
            }
        }
Пример #4
0
        private void SerializeHeader(MemoryStream fileHeaderStream, IBlobFileMetadata fileMetadata, long contentLength, DateTime versionTimeCreated)
        {
            if (fileHeaderStream == null)
            {
                throw new ArgumentNullException("fileHeaderStream");
            }

            if (fileMetadata == null)
            {
                throw new ArgumentNullException("fileMetadata");
            }

            //текущая версия заголовка = BlobConsts.BlobFile.FileHeaderCurrentVersion
            JsonBlobFileHeaderV1 header = new JsonBlobFileHeaderV1()
            {
                ContentAbsoluteStartPosition = this.BlobStream.Position,
                ContentLength   = contentLength,
                FileName        = fileMetadata.Name,
                FolderUrl       = fileMetadata.FolderMetadata.Url,
                UniqueID        = fileMetadata.UniqueID,
                TimeCreated     = versionTimeCreated,
                VersionUniqueID = fileMetadata.VersionUniqueID,
            };

            JsonDataSerializer.Serialize(fileHeaderStream, header);
        }
Пример #5
0
        public FileResult ExportResources()
        {
            var stream     = new MemoryStream();
            var writer     = new StreamWriter(stream, Encoding.UTF8);
            var serializer = new JsonDataSerializer();

            var resources = new GetAllResources.Query().Execute();

            writer.Write(serializer.Serialize(resources));
            writer.Flush();
            stream.Position = 0;

            return(File(stream, "application/json", $"localization-resources-{DateTime.Now.ToString("yyyyMMdd")}.json"));
        }
Пример #6
0
        public void JsonDataSerializer_SerializeJsonData_Success()
        {
            // Arrange
            var data        = @"{""Alpha2Code"":""mt""}";
            var mockCountry = new MockCountry()
            {
                Alpha2Code = "mt"
            };

            // Act
            var value = _sut.Serialize(mockCountry);

            // Assert
            Assert.NotNull(data);
            Assert.Equal(data, value);
        }
Пример #7
0
        public void JsonSerializationAndDeserlializationTest()
        {
            DataContext dataContext = new DataContext();
            IDataFiller dataFiller  = new DataManualFiller();

            dataFiller.InsertData(dataContext);

            JsonDataSerializer.Serialize(dataContext, pathToFile);

            DataContext deserializedDataContext = JsonDataSerializer.Deserialize <DataContext>(pathToFile);

            CollectionAssert.AreEqual(dataContext.Clients, deserializedDataContext.Clients);
            CollectionAssert.AreEqual(dataContext.Cars, deserializedDataContext.Cars);
            CollectionAssert.AreEqual(dataContext.WarehouseItems, deserializedDataContext.WarehouseItems);

            CollectionAssert.AreEqual(dataContext.BoughtCars, deserializedDataContext.BoughtCars);
            CollectionAssert.AreEqual(dataContext.SoldCars, deserializedDataContext.SoldCars);
        }
        public static void Main(string[] args)
        {
            _settings = ParseArguments(args);

            if (_settings.ShowHelp)
            {
                ShowHelp(_settings.OptionSet);
                return;
            }

            if (string.IsNullOrEmpty(_settings.SourceDirectory))
            {
                Console.WriteLine("ERROR: Source directory parameter is missing!");
                Console.WriteLine();
                ShowHelp(_settings.OptionSet);
                return;
            }

            if (!Directory.Exists(_settings.SourceDirectory))
            {
                throw new IOException($"Source directory {_settings.SourceDirectory} does not exist!");
            }

            Directory.SetCurrentDirectory(_settings.SourceDirectory);
            ReadConnectionString(_settings);
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(_settings.SourceDirectory, "App_Data"));

            if (_settings.ExportResources)
            {
                try
                {
                    Console.WriteLine("Export started.");
                    var extractor = new ResourceExtractor();
                    var resources = extractor.Extract(_settings);
                    string generatedScript;

                    if (_settings.Json)
                    {
                        var serializer = new JsonDataSerializer();
                        generatedScript = serializer.Serialize(resources);
                    }
                    else
                    {
                        var scriptGenerator = new SqlScriptGenerator();
                        generatedScript = scriptGenerator.Generate(resources, _settings.ScriptUpdate);
                    }

                    var scriptFileWriter = new ResultFileWriter();
                    var outputFile = scriptFileWriter.Write(generatedScript, _settings.TargetDirectory, _settings.Json);

                    Console.WriteLine($"Output file: {outputFile}");
                    Console.WriteLine("Export completed!");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error running tool: {e.Message}");
                    return;
                }
            }

            if (_settings.ImportResources)
            {
                Console.WriteLine("Import started!");

                var importer = new ResourceImporter();
                importer.Import(_settings);

                Console.WriteLine("Import completed!");
            }

            if (!_settings.ExportResources && !_settings.ImportResources)
            {
                Console.WriteLine("No command specified.");
                Console.WriteLine("Try 'DbLocalizationProvider.MigrationTool.exe --help' for more information.");
            }

            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }
        }
Пример #9
0
        public static void Main(string[] args)
        {
            _settings = ParseArguments(args);

            if (_settings.ShowHelp)
            {
                ShowHelp(_settings.OptionSet);
                return;
            }

            if (string.IsNullOrEmpty(_settings.SourceDirectory))
            {
                Console.WriteLine("ERROR: Source directory parameter is missing!");
                Console.WriteLine();
                ShowHelp(_settings.OptionSet);
                return;
            }

            if (!Directory.Exists(_settings.SourceDirectory))
            {
                throw new IOException($"Source directory `{_settings.SourceDirectory}` does not exist!");
            }

            if (!File.Exists(Path.Combine(_settings.SourceDirectory, "web.config")))
            {
                throw new IOException($"File `web.config` file not found in `{_settings.SourceDirectory}`!");
            }

            Directory.SetCurrentDirectory(_settings.SourceDirectory);
            ReadConnectionString(_settings);
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(_settings.SourceDirectory, "App_Data"));

            if (_settings.ExportResources)
            {
                try
                {
                    Console.WriteLine("Export started.");
                    var    extractor = new ResourceExtractor();
                    var    resources = extractor.Extract(_settings);
                    string generatedScript;

                    if (_settings.Json)
                    {
                        var serializer = new JsonDataSerializer();
                        generatedScript = serializer.Serialize(resources);
                    }
                    else
                    {
                        var scriptGenerator = new SqlScriptGenerator();
                        generatedScript = scriptGenerator.Generate(resources, _settings.ScriptUpdate);
                    }

                    var scriptFileWriter = new ResultFileWriter();
                    var outputFile       = scriptFileWriter.Write(generatedScript, _settings.TargetDirectory, _settings.Json);

                    Console.WriteLine($"Output file: {outputFile}");
                    Console.WriteLine("Export completed!");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error running tool: {e.Message}");
                    return;
                }
            }

            if (_settings.ImportResources)
            {
                Console.WriteLine("Import started!");

                var importer = new ResourceImporter();
                importer.Import(_settings);

                Console.WriteLine("Import completed!");
            }

            if (!_settings.ExportResources && !_settings.ImportResources)
            {
                Console.WriteLine("No command specified.");
                Console.WriteLine("Try 'DbLocalizationProvider.MigrationTool.exe --help' for more information.");
            }

            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }
        }
Пример #10
0
 public void Serialize <T>(T value, Stream stream)
 {
     _dataSerializer.Serialize <T>(value, stream);
 }