private async Task ExecuteGeneratorAsync(
            GeneratorTask task,
            ITypeLookup typeLookup,
            ISet <string> usedNames)
        {
            string fileName = task.Generator.CreateFileName(task.Descriptor);

            fileName = Path.Combine(_directoryName, fileName);

            lock (usedNames)
            {
                if (!usedNames.Add(fileName))
                {
                    throw new InvalidOperationException(
                              $"The file name `{fileName}` was already used.");
                }
            }

            using (FileStream stream = File.Create(fileName))
            {
                using (var sw = new StreamWriter(stream, Encoding.UTF8))
                {
                    using (var cw = new CodeWriter(sw))
                    {
                        await task.Generator.WriteAsync(
                            cw, task.Descriptor, typeLookup);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Save "Task" in file.xml
        /// </summary>
        /// <param name="task"></param>
        /// <param name="filePath"></param>
        public static void SaveTask(GeneratorTask task, string filePath)
        {
            var xmlSerialize = new XmlSerializer(typeof(GeneratorTask));

            var fileInfo = new FileInfo(filePath);

            if (!string.IsNullOrEmpty(fileInfo.DirectoryName) && !Directory.Exists(fileInfo.DirectoryName))
            {
                Directory.CreateDirectory(fileInfo.DirectoryName);
            }

            using (var rs = new StreamWriter(filePath))
            {
                xmlSerialize.Serialize(rs, task);
            }
        }
Exemplo n.º 3
0
        private static bool Generate(string path)
        {
            Console.WriteLine($"Generating {path}");
            var projectName = Path.GetFileName(path);
            var projFile    = $"{path}/{projectName}.csproj";
            var data        = XElement.Load(projFile);

            IDictionary <string, string> properties = data.Elements("PropertyGroup")
                                                      .Descendants()
                                                      .ToDictionary(x => x.Name.ToString(), y => y.Value);

            var previousWorkDir = Environment.CurrentDirectory;
            var task            = new GeneratorTask();

            task.Fill(properties);
            task.CurrentDirectory = path;


            var mockedBuildEngine = new Mock <IBuildEngine>();

            mockedBuildEngine.Setup(x => x.LogErrorEvent(It.IsAny <BuildErrorEventArgs>())).Callback((BuildErrorEventArgs args) =>
            {
                Console.Error.WriteLine(args.Message);
                throw new Exception(args.Message);
            });
            mockedBuildEngine.Setup(x => x.LogMessageEvent(It.IsAny <BuildMessageEventArgs>())).Callback((BuildMessageEventArgs args) =>
            {
                Console.WriteLine(args.Message);
            });
            mockedBuildEngine.Setup(x => x.LogWarningEvent(It.IsAny <BuildWarningEventArgs>())).Callback((BuildWarningEventArgs args) =>
            {
                Console.WriteLine(args.Message);
            });

            task.BuildEngine = mockedBuildEngine.Object;

            var success = task.ByPassExecute();

            Environment.CurrentDirectory = previousWorkDir;
            return(success);
        }
Exemplo n.º 4
0
        private void WorkerProcessOne(GeneratorTask task, IVoxelTerrainGenerator generator, IVoxelTerrainMesher mesher)
        {
            var chunk = task.Chunk;

            // Chunk generation rules/problems:
            // - To generate chunk mesh, the chunk must have all neighbor chunks
            // - Neighbor chunk can be still generating (how to deal with this?)
            // - We cannot make the chunk active (chunk.IsActive=true), until meshing finishes

            // TODO: Chunk processing implementation

            // Temporary
            if (task.GenerateVoxels)
            {
                chunk.State = VoxelTerrainChunkState.GeneratingVoxels;
                chunk.WorkerGenerateVoxels(generator);
            }

            if (task.GenerateMesh)
            {
                chunk.State = VoxelTerrainChunkState.GeneratingMesh;
                chunk.WorkerGenerateMesh(mesher);
            }
        }
        public void Start(GeneratorTask task)
        {
            if (string.IsNullOrEmpty(task.NodesDescription))
            {
                return;
            }

            ThreadCount = task.ThreadsCount;

            lock (ForcedLock)
            {
                LastState = SuperUtilities.RestoreLastState(ConfigurationManager.AppSettings["LastStatePath"]);
            }

            var nodes = task.Nodes;

            if (task.NodesDescription.Equals(LastState.NodesDescription))
            {
                var curN = nodes.SkipWhile(x => x != LastState.CurrentNodesCount).ToList();
                nodes = curN.Any() ? curN : nodes;
            }
            else
            {
                LastState = new LastState();
                LastState.NodesDescription = task.NodesDescription;
            }

            _report.ReportId        = Guid.NewGuid();
            _report.ComputerInfo    = SuperUtilities.GetProcessorInfo();
            _report.ThreadCount     = task.ThreadsCount;
            _report.StudentFullName = task.StudentFullName;
            _report.ExtendedInfo    = new ExtendedInformation {
                Descriptions = new List <ParametersDescription>()
            };

            foreach (var nodesCount in nodes)
            {
                Console.WriteLine($"Synthesis for nodes count: {nodesCount}");

                var paramDescription = new ParametersDescription
                {
                    OptimalCirculants = new List <CirculantParameters>()
                };

                var result = GenerateOptimalCirculants(nodesCount, task.Dimension);

                if (result == null || ForcedStop)
                {
                    // _report.TotalTime += result?.FirstOrDefault()?.TotalMilliseconds ?? TotalTime;

                    paramDescription.IsFinished = false;
                    _report.ExtendedInfo.Descriptions.Add(paramDescription);
                    paramDescription.LastState = LastState;

                    break;
                }

                paramDescription.IsFinished = true;
                paramDescription.OptimalCirculants.AddRange(result);
                _report.TotalTime += result?.FirstOrDefault()?.TotalMilliseconds ?? 0;
                _report.ExtendedInfo.Descriptions.Add(paramDescription);

                SuperUtilities.SaveResultsInFolder(result, task.OutputFolderPath);
            }

            ReportBuilder.SaveInfo(_report, Path.Combine(task.OutputFolderPath, $"{_report.ValidFullName}-{DateTime.Now:yyyyMMdd.hhmm}.bin"));

            Console.WriteLine($"Synthesis is ended, type stop (or another chars) for exit.");
            //Console.In.Close();
            //Console.ReadKey(true);
        }