예제 #1
0
        public void DecodeFile(string sourceFilepath, string destinationFilepath)
        {
            fileReader.Open(sourceFilepath);
            fileWriter.Open(destinationFilepath);

            fileReader.Close();
            fileWriter.Close();

            throw new System.NotImplementedException();
        }
        public void TestThatFileIsCopiedCorrectlyForNumberOfBitsBetween1And8(string fileTextContents)
        {
            TestMethods.CreateFileWithTextContents(filepathSource, fileTextContents);
            var random = new Random();

            fileReader.Open(filepathSource);
            fileWriter.Open(filepathDestination);

            while (!fileReader.ReachedEndOfFile)
            {
                var numberOfBits = fileReader.BitsLeft < 8
                    ? (byte)fileReader.BitsLeft
                    : (byte)random.Next(1, 8);

                var readStuff = fileReader.ReadBits(numberOfBits);
                fileWriter.WriteValueOnBits(readStuff, numberOfBits);
            }

            fileReader.Close();
            fileWriter.Close();

            Assert.IsTrue(TestMethods.FilesHaveTheSameContent(filepathSource, filepathDestination));
        }
예제 #3
0
        public void EncodeFile(string sourceFilepath, string destinationFilepath)
        {
            fileReader.Open(sourceFilepath);
            var sourceFileBytes = GetAllBytesFromSourceFile();

            fileReader.Close();

            InitializeSymbolDictionaryFromBytes(sourceFileBytes);


            fileWriter.Open(destinationFilepath);
            fileWriter.Close();

            throw new System.NotImplementedException();
        }
        public ImageMatrices Decode(string sourceFilepath, string destinationFilepath)
        {
            fileReader.Open(sourceFilepath);
            fileWriter.Open(destinationFilepath);

            CopyBitmapHeader();
            var usedOptions          = GetOptions();
            var errorMatrixReader    = NearLosslessErrorMatrixReaderSelector.GetErrorMatrixReader(usedOptions.SaveMode);
            var quantizedErrorMatrix = errorMatrixReader.ReadErrorMatrix(fileReader);
            var imageMatrices        = ErrorMatrixHelper.GetImageMatricesFromQuantizedErrorMatrix(quantizedErrorMatrix, usedOptions);

            WriteImageCodes(imageMatrices.Decoded);

            fileReader.Close();
            fileWriter.Close();

            return(imageMatrices);
        }
예제 #5
0
        private void RunForThisNumberOfBits(byte numberOfBits)
        {
            fileReader.Open(filepathSource);
            fileWriter.Open(filepathDestination);

            while (!fileReader.ReachedEndOfFile)
            {
                var numberOfBitsForCurrentIteration = fileReader.BitsLeft < numberOfBits
                    ? (byte)fileReader.BitsLeft
                    : numberOfBits;

                var readStuff = fileReader.ReadBits(numberOfBitsForCurrentIteration);
                fileWriter.WriteValueOnBits(readStuff, numberOfBitsForCurrentIteration);
            }

            fileReader.Close();
            fileWriter.Close();
        }
        public void Encode(string sourceFilepath, string destinationFilepath, NearLosslessOptions nearLosslessOptions)
        {
            var image         = GetImageOrThrow(sourceFilepath);
            var imageMatrices = new ImageMatrices(image);

            image.Dispose();

            PredictionMatrixHelper.SetImageMatrices(imageMatrices, nearLosslessOptions);

            fileReader.Open(sourceFilepath);
            fileWriter.Open(destinationFilepath);

            CopyBitmapHeader();
            WriteOptions(nearLosslessOptions);
            var errorMatrixWriter = NearLosslessErrorMatrixWriterSelector.GetErrorMatrixWriter(nearLosslessOptions.SaveMode);

            errorMatrixWriter.WriteErrorMatrix(imageMatrices.QuantizedErrors, fileWriter);
            fileWriter.Flush();

            fileReader.Close();
            fileWriter.Close();
        }
예제 #7
0
        public static int Main(string[] args)
        {
            RecordSchema schema = null;
            IFileWriter <GenericRecord> writer = null;

            var options = args.ToDictionary(arg => arg.TrimStart('-').Split('=').FirstOrDefault(), arg => arg.Split('=').LastOrDefault().Trim(new[] { '\'', '"' }));

            if (string.IsNullOrEmpty(options.GetOrDefault("output")))
            {
                PrintHelpMessage();
                return(1);
            }

            var builder = new SqlConnectionStringBuilder
            {
                DataSource     = options.GetOrDefault("server", "localhost"),
                InitialCatalog = options.GetOrDefault("database", "RabotaUA2")
            };

            if (!string.IsNullOrEmpty(options.GetOrDefault("password")))
            {
                builder.UserID   = options.GetOrDefault("username", "sa");
                builder.Password = options.GetOrDefault("password", "");
            }
            else
            {
                builder.IntegratedSecurity = true;
            }

            var query    = options.GetOrDefault("query", null) ?? File.ReadAllText(options.GetOrDefault("input"));
            var provider = new CSharpCodeProvider();
            var command  = new SqlCommand(query, new SqlConnection(builder.ConnectionString))
            {
                CommandTimeout = 0
            };

            command.Connection.Open();
            var reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    if (schema == null)
                    {
                        schema = Schema.Parse(JsonConvert.SerializeObject(new
                        {
                            type   = "record",
                            name   = "row",
                            fields = Enumerable.Range(0, reader.FieldCount).Select(index => new
                            {
                                name = reader.GetName(index),
                                type = new[] {
                                    provider.GetTypeOutput(new CodeTypeReference(reader.GetFieldType(index))),
                                    "null"
                                }
                            })
                        })) as RecordSchema;

                        writer = DataFileWriter <GenericRecord> .OpenWriter(new GenericDatumWriter <GenericRecord>(schema), options.GetOrDefault("output"), Codec.CreateCodec(Codec.Type.Deflate));
                    }

                    var r = new GenericRecord(schema);
                    for (var i = 0; i < reader.FieldCount; i++)
                    {
                        r.Add(reader.GetName(i), reader.IsDBNull(i) ? null : reader[i]);
                    }
                    writer.Append(r);
                }
                writer?.Close();
                return(0);
            }
            return(1);
        }
 public override void FinalizeOutput(IFileWriter writer)
 {
     writer.Close();
     //base.SetFileAuthor(writer.ExportFilePath);
 }
예제 #9
0
 public void Close()
 {
     _fileReader?.Close();
     _fileWriter?.Close();
 }