示例#1
0
        static async Task Main(string[] args)
        {
            await ThreadBuilder.Start();

            ConsoleOutputHelper.Write("No more items are being monitored.\nPress any key to close application");
            System.Console.ReadKey();
        }
示例#2
0
        /// <summary>
        /// 多线程并行建图
        /// </summary>
        /// <param name="threadCount">并行线程数量</param>
        /// <param name="log">日志处理</param>
        private void buildGraph(int threadCount, AutoCSer.Log.ILog log)
        {
            LeftArray <Node> reader = new LeftArray <Node>(Boot.Nodes.Values.getArray());
            int  taskCount          = threadCount - 1;
            bool isError            = false;

            AutoCSer.Threading.AutoWaitCount waitCount = new AutoCSer.Threading.AutoWaitCount(taskCount);
            ThreadBuilder[] builders = new ThreadBuilder[threadCount];
            try
            {
                for (int builderIndex = 0; builderIndex != builders.Length; builders[builderIndex++] = new ThreadBuilder(Boot, waitCount))
                {
                    ;
                }
                do
                {
                    Node[] readerArray = reader.Array;
                    int    count = reader.Length / threadCount, index = 0;
                    for (int builderIndex = 0; builderIndex != taskCount; ++builderIndex)
                    {
                        builders[builderIndex].SetThread(readerArray, index, count);
                        index += count;
                    }
                    builders[taskCount].Set(readerArray, index, reader.Length);
                    builders[taskCount].Build();
                    waitCount.WaitSet(taskCount);
                    reader.Length = 0;
                    foreach (ThreadBuilder builder in builders)
                    {
                        if (builder.ThreadException == null)
                        {
                            reader.Add(ref builder.Writer);
                        }
                        else
                        {
                            log.add(Log.LogType.Error, builder.ThreadException);
                            isError = true;
                        }
                    }
                }while (reader.Length != 0 && !isError);
            }
            finally
            {
                foreach (ThreadBuilder builder in builders)
                {
                    if (builder != null && builder.ThreadException == null)
                    {
                        builder.FreeThread();
                    }
                }
            }
        }
示例#3
0
        public async Task <Unit> Handle(SeedCommand request, CancellationToken cancellationToken)
        {
            var thread = await _dbContext.Threads.FirstOrDefaultAsync(e => e.Title == "New Thread", cancellationToken);

            if (thread != null)
            {
                return(Unit.Value);
            }

            var user = await _dbContext.Users.FirstOrDefaultAsync(e => e.Username == "Admin",
                                                                  cancellationToken : cancellationToken) ?? new UserBuilder()
                       .WithPassword(BCrypt.Net.BCrypt.EnhancedHashPassword("admin"))
                       .WithUsername("Admin")
                       .WithEmailAddress("*****@*****.**")
                       .WithJoinDateUtc(_dateTimeService.UtcNow)
                       .Build();

            var subForum = await _dbContext.SubForums.FirstOrDefaultAsync(e => e.Title == "Main", cancellationToken) ??
                           new SubForumBuilder()
                           .WithName("Main")
                           .Build();

            var generalTopic =
                await _dbContext.Topics.FirstOrDefaultAsync(e => e.Title == "General", cancellationToken) ??
                new TopicBuilder()
                .WithName("General")
                .UnderSubForum(subForum)
                .Build();

            var postBuilder = new PostBuilder()
                              .WithContent("Hello World")
                              .CreatedDateUtc(_dateTimeService.UtcNow)
                              .CreatedByUser(user);

            thread = new ThreadBuilder()
                     .WithTitle("New Thread")
                     .InTopic(generalTopic)
                     .WithPost(postBuilder)
                     .CreatedBy(user)
                     .CreatedDate(_dateTimeService.UtcNow)
                     .Build();

            _dbContext.Threads.Add(thread);
            await _dbContext.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
示例#4
0
        static void Main(string[] args)
        {
            var            defaultThreadNumber = Environment.ProcessorCount;
            var            file_path           = Constants.PATH_GRAPH;
            var            ods_path            = Constants.PATH_ODs;
            var            logToFile           = Constants.LOG_TO_FILE;
            EmailSender    emailSender         = null;
            IConfiguration config = GetConfig();

            string helpMessage = "====================> Region search program <====================\n";

            helpMessage += "\n==========> Description <==========\n";
            helpMessage += "\tThis program it's for research purpose and search the best path between two informed regions (set of nodes)\n";
            helpMessage += "\tusing the informed strategy and the graph also informed. It is also needed the radius to build the region and the number of\n";
            helpMessage += "\tpairs of origin and destinations to make data to the research. May also be informed the number of threads of execution\n";
            helpMessage += "\tto run the program (the default depends on the machine that is running this script)\n";
            helpMessage += "\n==========> Legend <==========\n";
            helpMessage += "\t1. None \"< or >\" must be used, they are just to delimiter parameters \n";
            helpMessage += "\t2. Arguments\n";
            helpMessage += "\t\t(*) <mandatory arguments>\n";
            helpMessage += "\t\t(#) <default arguments> (also optional) #default value\n";
            helpMessage += "\t\t( ) <optional arguments>\n";
            helpMessage += "\t\t    <any kind of argument> :type\n";
            helpMessage += "\t\t    <any kind of argument> (description)\n";
            helpMessage += "\t3. The order of the parameters must be followed (you can \n\tuse 'i' to avoid change default values or to ignore optional arguments)\n";
            helpMessage += "\n==========> Arguments <==========\n";
            helpMessage += "\t(*) <Strategy> : string (<C> to Collapse, <BF> to BruteForce)\n";
            helpMessage += "\t(*) <File name> : string #" + Constants.PATH_GRAPH + "<File name>\n";
            helpMessage += "\t(*) <Distance> :double (radius to search) \n";
            helpMessage += "\t(*) <OD size> :int (number of Origin and Destination to run) #" + Constants.PATH_ODs + "<OD size>\n";
            helpMessage += "\t(#) <Number of threads to use> :int #" + defaultThreadNumber + " (The number of logical processors in this machine)\n";
            helpMessage += "\t(#) <Log to file> :bool #" + logToFile + " (<!> to negate the default value) (Whether the log should be written only to the console or to a file as well)\n";
            helpMessage += "\t( ) <don't use default paths> :bool(<t> to true) (to use just the path on the <File path> argument when searching for graphs)\n";


            if (args.Length == 1 && (args[0] == "-h" || args[0] == "--help"))
            {
                Console.WriteLine(helpMessage);
                return;
            }
            else if (args.Length < 4 || args.Length > 7)
            {
                throw new ArgumentException("Must inform 4~7 argument must be passed\n" + helpMessage);
            }

            // Console.WriteLine(args);
            // args.ToList().ForEach(Console.WriteLine);

            var argument = 0;

            string strategy = args[argument++];
            var    path     = args[argument++];
            var    radius   = double.Parse(args[argument++]);
            var    OD       = Int32.Parse(args[argument++]);

            if (args.Length >= argument + 1)
            {
                defaultThreadNumber = args[argument++] == "i"? defaultThreadNumber : Int32.Parse(args[argument - 1]);
            }

            if (args.Length >= argument + 1)
            {
                logToFile = args[argument++] == "!"? !logToFile: logToFile;
            }

            if (args.Length >= argument + 1 && args[argument++] == "t")
            {
                file_path = "";
            }

            Graph graph = Import.LoadCityFromText(file_path + path);
            var   ods   = Import.LoadODsFromTxt(ods_path, graph.Name, OD);
//sudo dotnet run C /home/danielaragao/Documents/Git/Colapsar/caracterizacao-dados-reviews/graphs/giantscomponentes/Mumbai-network-osm-2018-1.txt 50 300 i i t
            SearchStrategyFactory strategyFactory = SearchStrategyFactory.GetFactory(strategy);

            LoggerFactory.Define(logToFile, "MultithreadSearch-" + strategyFactory.SearchName);

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            if (bool.Parse(config["EmailConfiguration:useEmail"]))
            {
                emailSender = new EmailSender(config);
            }

            var threadBuilder = new ThreadBuilder(graph, strategyFactory, ods, radius, defaultThreadNumber, emailSender);

            threadBuilder.Begin();
        }