Exemplo n.º 1
0
        public void GenerateTasks()
        {
            var countOofTaskXShouldBeGenerated = (int)Math.Round(Math.Pow(2, Z));

            for (int x = 0; x < countOofTaskXShouldBeGenerated; x++)
            {
                var currentX = x;
                lock (taskOfXes)
                {
                    Task.Factory.StartNew(() =>
                    {
                        var taskOfX = new TaskOfX()
                        {
                            Url = string.Format(UrlTemplate, "", "", currentX.ToString()),
                            X   = currentX,
                            Y   = Y,
                            Z   = Z
                        };
                        taskOfXes.Add(taskOfX);

                        //Console.WriteLine( taskOfX.Url);
                        //Console.WriteLine($"{taskOfXes.Count} / {countOofTaskXShouldBeGenerated} {taskOfX.Url}");
                        if (taskOfXes.Count == countOofTaskXShouldBeGenerated)
                        {
                            AllTasksGeneratedEvent?.Invoke(this);
                        }
                    });
                }
            }

            //throw new NotImplementedException();
        }
Exemplo n.º 2
0
        public void GenerateTasksAndDownload()
        {
            var countOofTaskXShouldBeGenerated = (int)Math.Round(Math.Pow(2, Z));

            for (int x = 0; x < countOofTaskXShouldBeGenerated; x++)
            {
                var currentX = x;
                lock (taskOfXes)
                {
                    Task.Factory.StartNew(() =>
                    {
                        var taskOfX = new TaskOfX()
                        {
                            Url      = string.Format(UrlTemplate, "", "", currentX.ToString()),
                            X        = currentX,
                            Y        = Y,
                            Z        = Z,
                            Filename = Path.Combine(DirPath, $"{currentX}.png")
                        };


                        taskOfX.Finished += (sender, size) =>
                        {
                            if (TasksFininshedIncreasedByEvent != null)
                            {
                                TasksFininshedIncreasedByEvent.Invoke(this, 1, size);
                            }
                        };


                        if (TasksGeneratedIncreasedByEvent != null)
                        {
                            TasksGeneratedIncreasedByEvent.Invoke(this, 1);
                        }

                        Task.Factory.StartNew(() =>
                        {
                            taskOfXes.Add(taskOfX);
                        });

                        taskOfX.Download();



                        //Console.WriteLine( taskOfX.Url);
                        //Console.WriteLine($"{taskOfXes.Count} / {countOofTaskXShouldBeGenerated} {taskOfX.Url}");
                        if (taskOfXes.Count == countOofTaskXShouldBeGenerated)
                        {
                            AllTasksGeneratedEvent?.Invoke(this);
                        }
                    });
                }
            }
        }