public bool Import(NzbDocumentWrapper document) { Contract.Requires(document != null); Dictionary <string, object> postParameters = new Dictionary <string, object>(); var parameter = new FileParameter(document.Buffer, $"{document.Name}.nzb", "application/x-nzb"); postParameters.Add("mode", "addfile"); postParameters.Add("nzbname", document.Name); postParameters.Add("nzbfile", parameter); postParameters.Add("apikey", SABnzbdConfiguration.Current.ApiKey); LogManager.Current.Debug($"Import de : {document.Name} "); var retour = false; using (var reponse = this.InterfaceWebManager.DataPost(postParameters)) { var returnStatus = string.Empty; Contract.Requires(reponse != null); using (var responseReader = new StreamReader(reponse.GetResponseStream())) { returnStatus = responseReader.ReadToEnd().TrimFullToEnd(); } LogManager.Current.Debug($"Aprés import, {reponse.StatusCode}, Chaine retour: {returnStatus}"); retour = reponse.StatusCode == HttpStatusCode.OK; } return(retour); }
public void DoNzb(string nzbFullPath) { var contents = File.ReadAllBytes(nzbFullPath); var nzbDocument = NzbPut.GetNzbDocument(contents); var key = NzbPut.GetKeyName(nzbFullPath, nzbDocument); var xDocument = new NzbDocumentWrapper(key, nzbFullPath, contents, nzbDocument); this.DoNzb(xDocument); }
public void DoNzb(NzbDocumentWrapper xDocument) { Contract.Requires(xDocument != null); if (!(this.SABnzbdService.IsWorkingProcess() && this.SABnzbdService.IsAlive())) { throw new NzbException("state exception"); } this.FireNzbEvent($"préparation du démarage de {xDocument.Name}"); this.SABnzbdService.Import(xDocument); this.FireNzbEvent($"lancement de {xDocument.Name}"); }
public void DoZip(string nzbFullPath) { bool erreur = false; var erreurFiles = new List <string>(); using (var zip = ZipFile.OpenRead(nzbFullPath)) { foreach (var fil1 in zip.Entries) { var extension = this.GetManagedFile(fil1.FullName); if (extension == ManagedFile.Other) { var fileName = Path.Combine(KnownFolders.GetPath(KnownFolder.Downloads), Path.GetFileName(fil1.FullName)); fil1.ExtractToFile(fileName, true); erreurFiles.Add(fileName); erreur = true; } else { var fileName = Path.GetTempFileName(); fil1.ExtractToFile(fileName, true); var contents = File.ReadAllBytes(fileName); var nzbDocument = NzbPut.GetNzbDocument(contents); var key = NzbPut.GetKeyName(nzbFullPath, nzbDocument); var xDocument = new NzbDocumentWrapper(key, nzbFullPath, contents, nzbDocument); this.DoNzb(xDocument); File.Delete(fileName); } } } if (erreur) { throw new NzbZipException($"copy bad file ({String.Join(", ", erreurFiles)} in {KnownFolders.GetPath(KnownFolder.Downloads)}"); } }