Exemplo n.º 1
0
        public void GenerateFile()
        {
            FileGenerator.CreateFile("abc");

            Assert.IsNotNull(FileGenerator.FilesPath);
            Assert.IsTrue(Directory.Exists(FileGenerator.FilesPath));
            Assert.IsTrue(Directory.EnumerateFiles(FileGenerator.FilesPath).Any());

            FileGenerator.RemoveFiles();

            Assert.IsTrue(Directory.Exists(FileGenerator.FilesPath));
            Assert.IsFalse(Directory.EnumerateFiles(FileGenerator.FilesPath).Any());
        }
Exemplo n.º 2
0
        public virtual async Task InitializeAsync()
        {
            if (!Directory.Exists(FilesDirectory))
            {
                Directory.CreateDirectory(FilesDirectory);
            }

            foreach (var row in Rows)
            {
                var filename = await FileGenerator.CreateFile(row, FilesDirectory);

                UnsortedFiles.Add(row, filename);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.Write("Digite o caminho da imagem desejada: ");
            string path = @Console.ReadLine();

            string text = Extract.ExtractTextFromImage(path);

            Console.Write("\nA parada foi extraída. Agora, escolha um nome para o arquivo: ");
            string name = Console.ReadLine();

            Console.WriteLine("\n\n\nSalvando a porra toda...\n");
            FileGenerator.CreateFile(@"C:\Users\ronye.rocha\Desktop\" + name + ".txt", text);

            Console.WriteLine("\n\nAbrindo o rolê...");
            Process.Start(@"C:\Users\ronye.rocha\Desktop\" + name + ".txt");

            Console.WriteLine("\n\n\n---Fim---\n");
            Console.ReadLine();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates a HASS Config File for the instances given with the list.
        /// </summary>
        /// <typeparam name="T">Type of an instance</typeparam>
        /// <param name="instances">the instances to add to yaml</param>
        /// <param name="filePath">path where the file should be stored (e.g. @"c:\temp\lights.yaml")</param>
        public static void GenerateConfigFile <T>(List <T> instances, string filePath)
        {
            Debug.WriteLine($"Starting Generation of config....");

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Type typeList = instances.GetType();
            Type typeItem;

            // check if the given list is really a generic list   //TEST
            if (!typeList.IsGenericType || typeList.GetGenericTypeDefinition() != typeof(List <>))
            {
                throw new ImplementationException("Argument 'instances' is not a generic type.");
            }
            typeItem = typeList.GetGenericArguments()[0];

            // check if the item type exists in the DeviceTypes namespace (including assembly)  //TEST
            var    myClassType = Type.GetType($"{Constants.DeviceTypeDefinitionNamespace}.{typeItem.Name}, {typeItem.Assembly.FullName}");
            object instance    = myClassType == null ? null : Activator.CreateInstance(myClassType); //Check if exists, instantiate if so.

            if (instance == null)
            {
                throw new ImplementationException($"Type of instance does not exist in {Constants.DeviceTypeDefinitionNamespace}.");
            }

            // create content
            string content = "";

            foreach (var listItem in instances)
            {
                content += YamlStringify.CreateInstanceString(listItem);
            }
            sw.Stop();

            Debug.WriteLine($"Done. Milliseconds to generate: {sw.Elapsed.TotalMilliseconds}");
            Debug.WriteLine("Finished content: \n\n");
            Debug.WriteLine(content);

            // store file
            FileGenerator.CreateFile(filePath, content);
        }
Exemplo n.º 5
0
        public static async Task Main(string[] args)
        {
            var rows             = 10_000_000;
            var sourceFilename   = $"unsorted.{rows}.csv";
            var unsortedFilePath = Path.Combine(FileGenerator.FileLocation, sourceFilename);

            if (!File.Exists(unsortedFilePath))
            {
                System.Console.WriteLine($"{sourceFilename} does not exists, creating...");
                await FileGenerator.CreateFile(rows, FileGenerator.FileLocation);

                System.Console.WriteLine($"{sourceFilename} has been created");
            }

            var comparer = new CsvColumnSorter_Substring(2);
            var command  = new ExternalMergeSorter(new ExternalMergeSorterOptions
            {
                Sort = new ExternalMergeSortSortOptions
                {
                    Comparer = comparer
                }
            });
            var commandName = comparer.GetType().Name;
            var sourceFile  = File.OpenRead(Path.Combine(FileGenerator.FileLocation, sourceFilename));
            var targetFile  = File.OpenWrite(Path.Combine(FileGenerator.FileLocation, $"{commandName}.{rows}.csv".ToLower()));
            var stopwatch   = Stopwatch.StartNew();
            await command.Sort(sourceFile, targetFile, CancellationToken.None);

            stopwatch.Stop();
            System.Console.WriteLine($"{commandName} done, took {stopwatch.Elapsed}");

            //var splitFileProgressHandler = new Progress<double>(x =>
            //{
            //    var percentage = x * 100;
            //    System.Console.WriteLine($"Split progress: {percentage:##.##}%");
            //});
            //var sortFilesProgressHandler = new Progress<double>(x =>
            //{
            //    var percentage = x * 100;
            //    System.Console.WriteLine($"Sort progress: {percentage:##.##}%");
            //});
            //var mergeFilesProgressHandler = new Progress<double>(x =>
            //{
            //    var percentage = x * 100;
            //    System.Console.WriteLine($"Merge progress: {percentage:##.##}%");
            //});

            //var sortCommand = new ExternalMergeSorter(new ExternalMergeSorterOptions
            //{
            //    Split = new ExternalMergeSortSplitOptions
            //    {
            //        ProgressHandler = splitFileProgressHandler
            //    },
            //    Sort = new ExternalMergeSortSortOptions
            //    {
            //        ProgressHandler = sortFilesProgressHandler
            //    },
            //    Merge = new ExternalMergeSortMergeOptions
            //    {
            //        ProgressHandler = mergeFilesProgressHandler
            //    }
            //});

            //var sourceFile = Path.Combine(FileGenerator.FileLocation, sourceFilename);
            //var targetFile = File.OpenWrite(Path.Combine(FileGenerator.FileLocation, $"sorted.{rows}.csv"));
            //System.Console.WriteLine($"Starting to sort {sourceFilename}...");
            //var stopwatch = Stopwatch.StartNew();
            //await sortCommand.Sort(File.OpenRead(sourceFile), targetFile, CancellationToken.None);
            //stopwatch.Stop();
            //System.Console.WriteLine($"MergeSort done, took {stopwatch.Elapsed}");

            //System.Console.WriteLine("Starting to sort In-memory...");
            //stopwatch.Restart();
            //var unsortedRows = await File.ReadAllLinesAsync(unsortedFilePath);
            //Array.Sort(unsortedRows);
            //await File.WriteAllLinesAsync(Path.Combine(FileGenerator.FileLocation, "sorted.inmemory.csv"), unsortedRows);
            //stopwatch.Stop();
            //System.Console.WriteLine($"In-memory done, took {stopwatch.Elapsed}");
        }