Exemple #1
0
        private static void RestProcessorForOperation(string groupKey, FileNameInfo file, ConcurrentDictionary <string, ConcurrentBag <Operation> > groupOperations)
        {
            var folder  = Path.GetDirectoryName(file.FilePath);
            var ymlPath = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(file.FilePath)}.yml");

            try
            {
                var operation = RestTransformer.ProcessOperation(groupKey, ymlPath, file.FilePath);
                if (operation != null)
                {
                    var key        = string.IsNullOrEmpty(file.Version) ? operation.GroupId : $"{file.Version}_{operation.GroupId}";
                    var operations = groupOperations.GetOrAdd(key, new ConcurrentBag <Operation>());
                    operations.Add(operation);
                }
                Console.WriteLine($"Done generate yml model for {file.FilePath}");
            }
            catch (Exception ex)
            {
                ErrorList.Add($"Error generate yml files for {file.FilePath}, details: {ex}");
            }
            finally
            {
                if (File.Exists(file.FilePath))
                {
                    File.Delete(file.FilePath);
                }
            }
        }
Exemple #2
0
        public static void RestProcessor(IList <RestFileInfo> restFileInfos)
        {
            var(groupFiles, groupOperationFiles) = ExtractRestFiles(restFileInfos);
            var groupOperations = new ConcurrentDictionary <string, ConcurrentBag <Operation> >();

            //foreach (var groupOperationPath in groupOperationPaths)
            //{
            //    var firstOperationPath = groupOperationPath.Value.First();
            //    Console.WriteLine($"Start generate yml model for {firstOperationPath}");
            //    RestProcessorForOperation(groupOperationPath.Key, firstOperationPath, groupOperations);
            //    var otherOperationPaths = groupOperationPath.Value.Skip(1);
            //    foreach (var filePath in otherOperationPaths)
            //    {
            //        RestProcessorForOperation(groupOperationPath.Key, filePath, groupOperations);
            //    }
            //}
            //foreach (var filePath in groupPaths)
            //{
            //    var folder = Path.GetDirectoryName(filePath);
            //    var ymlPath = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(filePath)}.yml");
            //    try
            //    {
            //        RestTransformer.ProcessGroup(ymlPath, filePath, groupOperations);
            //        Console.WriteLine($"Done generate yml model for {filePath}");
            //    }
            //    catch (Exception ex)
            //    {
            //        ErrorList.Add($"Error generate yml files for {filePath}, details: {ex}");
            //    }

            //    if (File.Exists(filePath))
            //    {
            //        File.Delete(filePath);
            //    }
            //}

            Parallel.ForEach(groupOperationFiles, new ParallelOptions {
                MaxDegreeOfParallelism = 8
            }, (groupOperationFile) =>
            {
                var firstOperationFile = groupOperationFile.Value.First();
                RestProcessorForOperation(groupOperationFile.Key, firstOperationFile, groupOperations);
                var otherOperationFiles = groupOperationFile.Value.Skip(1);
                Parallel.ForEach(otherOperationFiles, new ParallelOptions {
                    MaxDegreeOfParallelism = 8
                }, (file) =>
                {
                    RestProcessorForOperation(groupOperationFile.Key, file, groupOperations);
                });
            });

            Parallel.ForEach(groupFiles, new ParallelOptions {
                MaxDegreeOfParallelism = 8
            }, (file) =>
            {
                var folder  = Path.GetDirectoryName(file.FilePath);
                var ymlPath = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(file.FilePath)}.yml");
                try
                {
                    RestTransformer.ProcessGroup(ymlPath, file.FilePath, groupOperations, file.Version);
                    Console.WriteLine($"Done generate yml model for {file.FilePath}");
                }
                catch (Exception ex)
                {
                    ErrorList.Add($"Error generate yml files for {file.FilePath}, details: {ex}");
                }

                if (File.Exists(file.FilePath))
                {
                    File.Delete(file.FilePath);
                }
            });
        }