Example #1
0
        public static Resource[] Show(Window owner, Resource[] resources)
        {
            StopWindow view = new StopWindow();

            view.model.AddResources(resources);
            view.Owner = owner;
            view.ShowDialog();

            if (view.DialogResult == true)
            {
                return view.model.GetSelected();
            }

            return new Resource[0];
        }
Example #2
0
 private ResourceModel Create(Resource resource)
 {
     return ResourceModel.FromResource(resource, this);
 }
Example #3
0
            public void AddResources(Resource[] resources)
            {
                this.Resources = resources.Select(this.Create).ToArray();
                this.Raise("Resources");

                this.RecalculateButtons();
                this.UpdateButtons();
            }
Example #4
0
 public static ResourceModel FromResource(Resource resource, WindowModel owner)
 {
     return new ResourceModel
     {
         Owner = owner,
         Source = resource,
         Name = resource.Name,
         Hosting = resource.Hosting,
         Size = resource.Size
     };
 }
Example #5
0
File: Facade.cs Project: amacal/ine
        public Task PersistResources(Resource[] resources)
        {
            return Task.Run(() =>
            {
                using (FileStream stream = new FileStream(GetDataPath("transfers.txt"), FileMode.Create, FileAccess.Write, FileShare.None, 16 * 1024, FileOptions.WriteThrough))
                using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
                {
                    foreach (Resource resource in resources)
                    {
                        writer.Write(resource.Hosting);
                        writer.Write('|');
                        writer.Write(resource.Name);
                        writer.Write('|');
                        writer.Write(resource.Size);
                        writer.Write('|');
                        writer.Write(resource.Url);
                        writer.WriteLine();
                    }

                    writer.Flush();
                    stream.Flush();
                }
            });
        }
Example #6
0
File: Facade.cs Project: amacal/ine
        public async Task Analyze(LinkTask task)
        {
            if (task.Links.Length > 0)
            {
                foreach (Link link in task.Links)
                {
                    task.OnStatus(link, "pending");
                }

                await Task.Run(() =>
                {
                    Parallel.ForEach(task.Links, new ParallelOptions { MaxDegreeOfParallelism = 2 }, link =>
                    {
                        task.OnStatus.Invoke(link, "checking");
                        task.OnLog.Information("Analyzing '{0}'.", link.Url);
                        task.OnLog.Information("Starting PhantomJS");

                        ProcessStartInfo info = new ProcessStartInfo
                        {
                            FileName = GetPhantomPath(),
                            Arguments = GetScriptPath(link.Hosting) + " query " + link.Url.ToString(),
                            UseShellExecute = false,
                            RedirectStandardOutput = true,
                            CreateNoWindow = true,
                            WindowStyle = ProcessWindowStyle.Hidden,
                            WorkingDirectory = GetDataPath()
                        };

                        using (Process process = Process.Start(info))
                        {
                            Resource resource = new Resource
                            {
                                Url = link.Url,
                                Hosting = link.Hosting,
                                IsAvailable = true
                            };

                            PhantomCallback callback = new PhantomCallback
                            {
                                OnDownload = url => true,
                                OnFileName = text =>
                                {
                                    resource.Name = text;
                                    return true;
                                },
                                OnFileSize = text =>
                                {
                                    resource.Size = text;
                                    return true;
                                },
                                OnFileStatus = text =>
                                {
                                    resource.IsAvailable = false;
                                    return false;
                                },
                                OnFatal = text =>
                                {
                                    task.OnLog.Warning(text);
                                    return true;
                                },
                                OnCaptcha = text => Task.FromResult(false),
                                OnDebug = text =>
                                {
                                    task.OnLog.Debug(text);
                                    return true;
                                },
                                OnFallback = text => true,
                                OnMessage = text => true,
                                OnRaw = text => { }
                            };

                            this.Handle(callback, CancellationToken.None, process).Wait();

                            if (resource.IsAvailable == false)
                            {
                                task.OnStatus(link, "unavailable");
                            }

                            if (resource.IsAvailable == true)
                            {
                                task.OnStatus(link, "available");
                            }

                            if (resource.Name != null && resource.Size != null)
                            {
                                task.OnCompleted(link, resource);
                            }

                            process.WaitForExit();
                        }
                    });
                });
            }
        }
Example #7
0
 private Task HandleResources(Resource[] resources)
 {
     return new Facade().PersistResources(resources);
 }