Пример #1
0
        private void AddCore(DownloadLink link)
        {
            var tokeSource   = new CancellationTokenSource();
            var tasks        = link.Downloader.EmitTasks(link.Request, tokeSource.Token);
            var downloadTask = new DownloadTask(tasks, tokeSource.Token);
            var box          = new DownloadBox(downloadTask, link)
            {
                TokenSource = tokeSource
            };

            box.Canceled           += Box_Canceled;
            downloadTask.MovedNext += (a, b) =>
            {
                MovedNext?.Invoke(this, a, b);
            };
            downloadTask.Seeked += (a, b) =>
            {
                Seeked?.Invoke(this, a, b);
            };
            downloadTask.Done += async w =>
            {
                await RemoveAsync(box.Address);

                Done?.Invoke(this, box);
            };
            downloadMap.Add(link.Request.Entity.ComicUrl, box);
            downloadManager.Add(downloadTask);
            Added?.Invoke(this, box);
        }
        public JsonResult UpdateDownloadLink(DownloadLink downloadLink)
        {
            _downloadLinkData.UpdateDownloadLink(downloadLink);

            return(Json(new Response {
                ErrorMessage = "Kaydedilmiştir", IsSuccess = false
            }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult DeleteDownloadLink(DownloadLink downloadLink)
        {
            _downloadLinkData.DeleteDownloadLink(downloadLink.DownloadId);

            return(Json(new Response {
                ErrorMessage = "Silinmiştir", IsSuccess = false
            }, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        protected virtual Task OnAddAsync(DownloadLink link)
        {
            AddCore(link);
#if NETSTANDARD2_0
            return(Task.CompletedTask);
#else
            return(Task.FromResult(true));
#endif
        }
Пример #5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Address?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (Name?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (DownloadLink?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
Пример #6
0
        public void DeleteDownloadLink(int downloadLinkId)
        {
            using (AlacaYazilimWebSiteEntities entities = new AlacaYazilimWebSiteEntities())
            {
                DownloadLink dbKullanici = entities.DownloadLink.FirstOrDefault(f => f.DownloadId == downloadLinkId);

                entities.DownloadLink.Remove(dbKullanici);

                entities.SaveChanges();
            }
        }
Пример #7
0
        public void SaveDownloadLink(DownloadLink downloadLink)
        {
            using (AlacaYazilimWebSiteEntities entities = new AlacaYazilimWebSiteEntities())
            {
                downloadLink.CreateDate = DateTime.Now;
                downloadLink.Aktif      = 1;
                entities.DownloadLink.Add(downloadLink);

                entities.SaveChanges();
            }
        }
Пример #8
0
        public async Task GetResourcesDownload(string pathFile)
        {
            try
            {
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, urlDiskApi + "/resources/download?path=" + pathFile);
                var response = await client.SendAsync(request);

                DownloadLink answer       = JsonConvert.DeserializeObject <DownloadLink>(await response.Content.ReadAsStringAsync());
                int          position     = answer.href.IndexOf("?");
                string       downloadlink = answer.href.Substring(0, position);
                string[]     subs         = answer.href[(position + 1)..].Split('&');
Пример #9
0
        public void GivenValueInit_PropertyValueMustEqualGiven()
        {
            var tsk  = new DownloadTask(new Func <Task> [0]);
            var addr = "adsads";
            var link = new DownloadLink(null, null, new ComicDownloadRequest(null, new ComicEntity {
                ComicUrl = addr
            }, null, null, null));
            var box = new DownloadBox(tsk, link);

            Assert.AreEqual(tsk, box.Task);
            Assert.AreEqual(link, box.Link);
            Assert.AreEqual(addr, box.Address);
        }
Пример #10
0
        private void CalculateDownloadLinkIdentifier()
        {
            if (string.IsNullOrEmpty(DownloadLink))
            {
                DownloadLinkIdentifier = string.Empty;
                return;
            }

            var splittedByPath = DownloadLink.Split(new[] { @"/" }, StringSplitOptions.RemoveEmptyEntries);
            var linkIdentifier = splittedByPath.Last();

            DownloadLinkIdentifier = linkIdentifier;
        }
        public JsonResult SaveDownloadLink(DownloadLink downloadLink)
        {
            if (Session[Constants.SessionInformation] != null)
            {
                var user = (User)Session[Constants.SessionInformation];
                downloadLink.CreateUser = user.Id;
            }
            _downloadLinkData.SaveDownloadLink(downloadLink);

            return(Json(new Response {
                ErrorMessage = "Kaydedilmiştir", IsSuccess = false
            }, JsonRequestBehavior.AllowGet));
        }
Пример #12
0
        // First step of the return flux
        public DownloadLink BuildLink(OperatorResolution _resolution)
        {
            DownloadLink downloadLink = new DownloadLink
            {
                PublicId = Guid.NewGuid()
            };

            downloadLink.ShapefileRequest = _resolution.ShapefileRequest;
            downloadLink.Timestamp        = DateTime.Now;
            downloadLink.Validity         = 24;
            downloadLink.InternalLink     = domain + "/" + downloadLink.PublicId;           // the guid is used to create the unique download link

            return(downloadLink);
        }
Пример #13
0
 public static void DownloadSingleFile(DownloadLink dl, string outputDir)
 {
     try
     {
         if (DownloadProcess(dl, outputDir) == false)
         {
             Logger.Warn(LOGNAME, "File has not been downloaded");
         }
     }
     catch (Exception ex)
     {
         Logger.Error(LOGNAME, ex.Message, ex);
     }
 }
Пример #14
0
        public void UpdateDownloadLink(DownloadLink downloadLink)
        {
            using (AlacaYazilimWebSiteEntities entities = new AlacaYazilimWebSiteEntities())
            {
                DownloadLink dbKullanici = entities.DownloadLink.FirstOrDefault(f => f.DownloadId == downloadLink.DownloadId);

                dbKullanici.DownloadAdi = downloadLink.DownloadAdi;
                dbKullanici.DownloadUrl = downloadLink.DownloadUrl;
                dbKullanici.Aciklama    = downloadLink.Aciklama;
                dbKullanici.Aktif       = downloadLink.Aktif;

                entities.SaveChanges();
            }
        }
Пример #15
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = CreatedAt.GetHashCode();
         hashCode = (hashCode * 397) ^ UpdatedAt.GetHashCode();
         hashCode = (hashCode * 397) ^ (DownloadLink != null ? DownloadLink.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (FileId != null ? FileId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Filename != null ? Filename.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Hash != null ? Hash.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (MimeType != null ? MimeType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Size != null ? Size.Value : 0);
         return(hashCode);
     }
 }
Пример #16
0
        private bool GetId()
        {
            try
            {
                VideoId = (DownloadLink.Split('/'))[8];
                return true;
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            }
            
        }
Пример #17
0
 private void TimerClipper()
 {
     if (IsClipboardCaptureSelected)
     {
         Application.Current.Dispatcher.Invoke(() =>
         {
             if (DownloadLink == null)
             {
                 DownloadLink = Clipboard.GetText();
             }
             if (!DownloadLink.Contains(Clipboard.GetText()))
             {
                 DownloadLink = Clipboard.GetText();
             }
         }, System.Windows.Threading.DispatcherPriority.Send);
     }
 }
Пример #18
0
        public bool IsValid()
        {
            var validUrlChars = new[] { '/', ':', '.', '=', '?', '-', '_', '+', '#', '&', '[', ']' };

            var validityCriteria = new[] {
                DownloadLink != null,
                OutputFormat != null,
                !string.IsNullOrWhiteSpace(DownloadLink),
                !string.IsNullOrWhiteSpace(OutputFormat),
                DownloadLink?.Length >= 8,
                OutputFormat?.Length >= 3,
                DownloadLink?.All(c => char.IsDigit(c) || char.IsLetter(c) || validUrlChars.Contains(c)),
                Uri.TryCreate(DownloadLink, UriKind.Absolute, out _),
                Enum.TryParse(typeof(OutputFormat), OutputFormat, true, out _),
            };

            return(validityCriteria.All(c => c == true));
        }
Пример #19
0
        private static void Download()
        {
            try
            {
                while (_isStarted)
                {
                    try
                    {
                        DbFile dbf = Db.FileToDownload();
                        if (dbf == null)
                        {
                            Task.Delay(WAIT).Wait();
                            continue;
                        }
                        DownloadLink dl = DownloadLink.Parse(dbf.DownloadLink);
                        if (dl == null)
                        {
                            Logger.Warn(LOGNAME, "Cannot parse DownloadLink: " + dbf.Id);
                            continue;
                        }

                        //ne pas faire de savoir pr ne pas ecraser le fichier Database
                        if (DownloadProcess(dl, Utilities.FolderDownload) == true)
                        {
                            //todo a revoir
                        }
                        else
                        {
                            //todo a revoir
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(LOGNAME, ex.Message, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(LOGNAME, ex.Message, ex);
            }
        }
Пример #20
0
 private static void ModeDownload(string dlLink, string outputDir)
 {
     try
     {
         if (string.IsNullOrEmpty(outputDir))
         {
             outputDir = Utilities.FolderDownload;
         }
         DownloadLink dl = DownloadLink.Parse(dlLink);
         if (dl == null)
         {
             Console.WriteLine("Invalid Link");
             return;
         }
         FileDownloader.DownloadSingleFile(dl, outputDir);
     }
     catch (Exception ex)
     {
         Logger.Error(LOGNAME, ex.Message, ex);
     }
 }
        private void tsTop_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Name)
            {
            case "tsbCopyLink":
                List <DownloadLink> downloadLinks = bsResult.DataSource as List <DownloadLink>;

                frmShowText frmText = new frmShowText(DownloadLink.GetAllLinksText(downloadLinks));

                frmText.Show();

                break;

            case "tsbPatchDownload":
                List <DownloadLink> allDownloadLinks = bsResult.DataSource as List <DownloadLink>;

                downloadLinkParser.PatchDownloadByClient(allDownloadLinks);

                break;
            }
        }
Пример #22
0
        private bool CheckFamiliesVersion(DownloadLink link)
        {
            var checkResult = false;

            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Building360", true))
            {
                if (key != null)
                {
                    var v1 = key.GetValue(link.keyName).ToString();
                    var versionInstalled = new Version(v1);
                    var v2 = link.version;

                    if (versionInstalled.CompareTo(new Version(0, 0, 0)) == 0)
                    {
                        checkResult = true;
                    }
                }
            }

            return(checkResult);
        }
Пример #23
0
        public async Task AddAsync(DownloadLink link)
        {
            var url = link.Request.Entity.ComicUrl;

            if (!NeedToAdd(url))
            {
                return;
            }
            await semaphoreSlim.WaitAsync();

            try
            {
                if (!NeedToAdd(url))
                {
                    return;
                }
                await OnAddAsync(link);
            }
            finally
            {
                semaphoreSlim.Release();
            }
        }
Пример #24
0
 private static void ModeConvert(string dlLink, string outputDir)
 {
     try
     {
         DownloadLink dl = DownloadLink.Parse(dlLink);
         if (dl == null)
         {
             Console.WriteLine("Invalid Link");
             return;
         }
         if (dl.ToNzb(outputDir) == true)
         {
             Console.WriteLine("Nzb successfully generated");
         }
         else
         {
             Console.WriteLine("An error occured processing Nzb");
         }
     }
     catch (Exception ex)
     {
         Logger.Error(LOGNAME, ex.Message, ex);
     }
 }
Пример #25
0
 private bool CanDownload()
 {
     return(!String.IsNullOrEmpty(DownloadLink) && DownloadLink.StartsWith("https://www.youtube.com/"));
 }
Пример #26
0
        public BukgetPluginVersion(BukgetPlugin plugin, String jsonCode)
        {
            {
                InitFields();
                //create JSON object
                JsonObject json = (JsonObject)JsonConvert.Import(jsonCode);

                Plugin = plugin;

                if (json["version"] == null)
                {
                    VersionNumber = null;
                    return;
                }

                VersionNumber = json["version"].ToString();

                {
                    CompatibleBuilds =
                        JsonParser.ParseJsonStringList(
                            json["game_versions"]);
                }


                if (json["download"] != null)
                {
                    // BukkitDev Compliancy
                    // Since this program is distributed using dev.bukkit.org, every download url needs to have the "http://dev.bukkit.org" part hardcoded

                    DownloadLink = json["download"].ToString();
                    if (DownloadLink.StartsWith("http://") || DownloadLink.StartsWith("https://"))
                    {
                        DownloadLink = DownloadLink.Substring(DownloadLink.IndexOf('/', 10));
                        DownloadLink = "http://dev.bukkit.org/" + DownloadLink;
                    }
                }


                if (json["link"] != null)
                {
                    PageLink = json["link"].ToString();
                }


                if (json["date"] != null)
                {
                    ReleaseDate = new DateTime(1970, 1, 1).AddSeconds(Convert.ToDouble(json["date"].ToString()));
                }


                if (json["filename"] != null)
                {
                    Filename = json["filename"].ToString();
                }


                if (json["status"] != null)
                {
                    Type = (PluginStatus)Enum.Parse(typeof(PluginStatus), json["status"].ToString().Replace("-", "_"));
                }
            }
        }
Пример #27
0
        public static bool UploadProcess(DbFile dbf)
        {
            try
            {
                DirectoryInfo workingDir = new DirectoryInfo(Utilities.FolderTemp);
                //On clean le workingdir
                FileInfo[] filesToRemove = workingDir.GetFiles();
                foreach (FileInfo fileToRemove in filesToRemove)
                {
                    Utilities.FileDelete(fileToRemove.FullName);
                }

                Stopwatch perfTotal  = new Stopwatch();
                Stopwatch perfPar    = new Stopwatch();
                Stopwatch perfUpload = new Stopwatch();

                Logger.Info(LOGNAME, "[" + dbf.Id + "] Start");
                FileInfo fi = new FileInfo(dbf.Id);
                perfTotal.Start();

                Guid   usenetId     = Guid.NewGuid();
                byte[] encKey       = Crypto.GenerateEncryptionKey(usenetId, dbf.EncryptionMode);
                string usenetIdStr  = usenetId.ToString();
                string posterEmail  = Pokemon.GetEmail();
                string tempFilePath = Path.Combine(workingDir.FullName, usenetIdStr);

                //1- Copying file to temp
                fi.CopyTo(tempFilePath);

                //2- Checksum
                string checksum = Checksum.Calculate(new FileInfo(tempFilePath));
                dbf.Checksum = checksum;
                Logger.Info(LOGNAME, "[" + dbf.Id + "] Checksum: " + checksum);

                //3- Create Parity File
                perfPar.Start();
                Logger.Info(LOGNAME, "[" + dbf.Id + "] Par2");
                if (FilePariter.Create(workingDir, new FileInfo(tempFilePath), usenetIdStr + FilePariter.EXT_PAR2) == false)
                {
                    Logger.Info(LOGNAME, "Par2 error: " + dbf.Id);
                    return(false);
                }
                perfPar.Stop();

                //4- Preparing Chunks
                Logger.Info(LOGNAME, "[" + dbf.Id + "] Chunks");
                List <BinaryReader> listOfBrs           = new List <BinaryReader>();
                FileInfo[]          listOfFilesToUpload = workingDir.GetFiles();
                long totalSize = (from x in listOfFilesToUpload select x.Length).Sum();
                Dictionary <string, long> dicoOfSizePerExtension = new Dictionary <string, long>();
                Dictionary <string, List <UsenetChunk> > dicoOfChunksPerExtension = new Dictionary <string, List <UsenetChunk> >(); //key: extension - value: ListOfChunks
                foreach (FileInfo fileToUpload in listOfFilesToUpload)
                {
                    string extension = fileToUpload.Name.Replace(usenetIdStr, "");
                    if (string.IsNullOrEmpty(extension))
                    {
                        extension = Utilities.EXT_RAW;
                    }
                    dicoOfSizePerExtension[extension] = fileToUpload.Length;
                    int          nbChunks = (int)Math.Ceiling((double)fileToUpload.Length / Utilities.ARTICLE_SIZE);
                    BinaryReader br       = new BinaryReader(new FileStream(fileToUpload.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, Utilities.BUFFER_SIZE));
                    listOfBrs.Add(br);
                    dicoOfChunksPerExtension[extension] = new List <UsenetChunk>(nbChunks);
                    for (int i = 0; i < nbChunks; i++)
                    {
                        UsenetChunk chunk = new UsenetChunk(br, fileToUpload.Name, usenetId, extension, i, nbChunks, dbf.EncryptionMode);
                        dicoOfChunksPerExtension[extension].Add(chunk);
                        UsenetUploader.AddChunk(chunk);
                    }
                }

                //5- Run Upload Tasks
                Logger.Info(LOGNAME, "[" + dbf.Id + "] Upload");
                perfUpload.Start();
                UsenetUploader.Run(posterEmail, encKey);

                //6- Checking for end
                while (UsenetUploader.IsFinished() == false)
                {
                    Task.Delay(50).Wait();
                }
                perfUpload.Stop();

                //7- Process Finished
                foreach (BinaryReader br in listOfBrs)
                {
                    br.Close();
                }
                foreach (FileInfo fileToDelete in listOfFilesToUpload)
                {
                    Utilities.FileDelete(fileToDelete.FullName);
                }

                //8- Upload check
                List <UsenetChunk> mainChunkList = dicoOfChunksPerExtension[Utilities.EXT_RAW];
                int  nbSuccess     = (from x in mainChunkList where x.PassNumber != UsenetServer.MAX_PASS select x).Count();
                int  percSuccess   = (nbSuccess * 100) / mainChunkList.Count();
                bool uploadSuccess = true;
                if (percSuccess < Settings.Settings.Current.PercentSuccess)
                {
                    uploadSuccess = false;
                }

                if (uploadSuccess == true)
                {
                    //9- Generate DownloadLink
                    Dictionary <string, DownloadLinkFileInfo> dicoOfPassNumberPerExtension = new Dictionary <string, DownloadLinkFileInfo>(); //key: fileExtension|filesize - value: listOfPassNumber
                    foreach (KeyValuePair <string, List <UsenetChunk> > kvp in dicoOfChunksPerExtension)
                    {
                        string extension          = kvp.Key;
                        DownloadLinkFileInfo dlfi = new DownloadLinkFileInfo()
                        {
                            Size = dicoOfSizePerExtension[kvp.Key], ListOfPassNumber = (from x in kvp.Value orderby x.ChunkNumber ascending select x.PassNumber).ToList()
                        };
                        dicoOfPassNumberPerExtension[extension] = dlfi;
                    }

                    DownloadLink dl = new DownloadLink(DownloadLink.VERSION, usenetId, dbf.Name, dbf.Checksum, Utilities.UnixTimestampFromDate(DateTime.UtcNow), dbf.EncryptionMode, dicoOfPassNumberPerExtension);;
                    dbf.DownloadLink = DownloadLink.ToString(dl);
                }

                perfTotal.Stop();
                Logger.Info(LOGNAME, "[" + dbf.Id + "] " + (uploadSuccess == true ? "Success" : "Fail") + " (chunks: " + percSuccess + "% - files: " + listOfFilesToUpload.Length + " - size: " + Utilities.ConvertSizeToHumanReadable(totalSize) + " - par: " + (long)(perfPar.ElapsedMilliseconds / 1000) + "s - up: " + (long)(perfUpload.ElapsedMilliseconds / 1000) + "s - speed: " + Utilities.ConvertSizeToHumanReadable(totalSize / ((perfUpload.ElapsedMilliseconds < 1000 ? 1000 : perfUpload.ElapsedMilliseconds) / 1000)) + "b/s)");
                return(uploadSuccess);
            }
            catch (Exception ex)
            {
                Logger.Error(LOGNAME, ex.Message, ex);
            }
            return(false);
        }
Пример #28
0
 public DownloadBox(DownloadTask task, DownloadLink link)
 {
     Task = task;
     Link = link;
 }
Пример #29
0
        static void Main(string[] args)
        {
            var x = new DownloadLink
            {
                LinkName    = "testlink",
                Recipe      = "dafgf",
                CreateDate  = null,
                EndDate     = DateTime.Now,
                AnotherLink = new DownloadLink
                {
                    LinkName   = "testlink2",
                    Recipe     = "123asdfdafgf",
                    CreateDate = DateTime.Now.AddDays(8),
                    EndDate    = DateTime.Now,
                },
                AnotherLink2 = new DownloadLink
                {
                    LinkName   = "testlink2",
                    Recipe     = "123asdfdafgf",
                    CreateDate = DateTime.Now.AddDays(8),
                    EndDate    = DateTime.Now,
                },
                Listy = new List <DownloadLink>
                {
                    new DownloadLink
                    {
                        LinkName   = "1",
                        Recipe     = "11",
                        CreateDate = DateTime.Now.AddDays(8),
                        EndDate    = DateTime.Now,
                    },
                    new DownloadLink
                    {
                        LinkName   = "2",
                        Recipe     = "22",
                        CreateDate = DateTime.Now.AddDays(8),
                        EndDate    = DateTime.Now,
                    },
                    new DownloadLink
                    {
                        LinkName   = "3",
                        Recipe     = "33",
                        CreateDate = DateTime.Now.AddDays(8),
                        EndDate    = DateTime.Now,
                    }
                },
                Listy2 = new List <DownloadLink>
                {
                    new DownloadLink
                    {
                        LinkName   = "111",
                        Recipe     = "1111",
                        CreateDate = DateTime.Now.AddDays(8),
                        EndDate    = DateTime.Now,
                    },
                    new DownloadLink
                    {
                        LinkName   = "222",
                        Recipe     = "2222",
                        CreateDate = DateTime.Now.AddDays(8),
                        EndDate    = DateTime.Now,
                    },
                    new DownloadLink
                    {
                        LinkName   = "333",
                        Recipe     = "3333",
                        CreateDate = DateTime.Now.AddDays(8),
                        EndDate    = DateTime.Now,
                    }
                }
            };

            var ex = new ExcelSerializer.ExcelSerializer();

            ex.Serialize(x, "text.xlsx");

            Process.Start("text.xlsx");
        }
 public DownloadLink SaveDownloadLink(DownloadLink downloadLink)
 {
     this.DownLoadLinks.Add(downloadLink);
     this.SaveChanges();
     return(downloadLink);
 }