示例#1
0
        public bool Send(NzbModel nzb)
        {
            //Get the Template
            //Get SMTP Server Information, To/From Address, etc

            var toAddress = _config.GetValue("EmailToAddress", String.Empty, false);
            var fromAddress = _config.GetValue("EmailFromAddress", String.Empty, false);
            var host = _config.GetValue("SmtpServerHost", String.Empty, false);
            int port = Convert.ToInt32(_config.GetValue("SmtpServerPort", "25", true));
            bool ssl = Convert.ToBoolean(_config.GetValue("SmtpServerSsl", "0", true));
            bool authentication = Convert.ToBoolean(_config.GetValue("SmtpServerAthentication", "0", true));
            var username = _config.GetValue("SmtpServerUsername", String.Empty, false);
            var password = _config.GetValue("SmtpServerPassword", String.Empty, false);

            MailMessage email = new MailMessage(); //Create a new MailMessage named email

            email.To.Add(toAddress);
            email.From = new MailAddress(fromAddress); //Create a new MailAddress for the senders address;

            //Todo: Need to Build these from a template
            email.Subject = String.Empty; //Set the subject of the email
            email.Body = String.Empty; //set the body of the email

            SmtpClient client = new SmtpClient(); //Create a new SMTP client
            client.Host = host; //Set the host for the client
            client.Port = port; //Set the port for the client

            try
            {
                client.Send(email); //Try to send the message
            }

                        catch (Exception ex)
            {
                Logger.DebugException(ex.Message, ex);
                return false;
            }

            //return true;
            throw new NotImplementedException("Email Provider - Send");
        }
示例#2
0
        public bool Run(string name, NzbModel nzb)
        {
            //result should be output from the script...
            var scriptDir = Path.GetFullPath(_config.GetValue("ScriptDir", AllScripts(), true));

            var scriptPath = Path.GetFullPath(scriptDir + Path.DirectorySeparatorChar + name);

            if (!_disk.FileExists(scriptPath))
            {
                Logger.Error("Script does not exist.");
                return false;
            }

            //1 	The final directory of the job (full path)
            //2 	The original name of the NZB file
            //3 	Clean version of the job name (no path info and ".nzb" removed)
            //4 	Indexer's report number (if supported) - Don't have this information right now....
            //5 	User-defined category
            //6 	Group that the NZB was posted in e.g. alt.binaries.x
            //7 	Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+21

            var arguments = String.Format("{0} {1} {2} {3} {4} {5} {6}", GetStringForArgument(nzb.FinalDirectory), GetStringForArgument(nzb.Name), GetStringForArgument(nzb.Name), String.Empty, nzb.Category, nzb.Files[0].Groups[0], (int)nzb.PostProcessingStatus);

            var process = new Process();
            process.StartInfo.UseShellExecute = false; //Must be false to redirect the output
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.FileName = scriptPath;
            process.StartInfo.Arguments = arguments;
            process.Start(); //Start the Process
            process.WaitForExit(); //Wait for the Process to Exit

            nzb.ScriptOutput = process.StandardOutput.ReadToEnd(); //Save the output of the script to ScriptOutput (For later use in History)

            if (process.ExitCode != 0)
                return false;

            return true;
        }
示例#3
0
        public NzbModel Process(NzbImportModel import)
        {
            XNamespace ns = "http://www.newzbin.com/DTD/2003/nzb";
            import.Stream.Seek(0, SeekOrigin.Begin);
            XDocument xDoc = XDocument.Load(import.Stream);

            var nzb = from n in xDoc.Descendants(ns + "nzb") select n;

            if (nzb.Count() != 1)
                return null;

            NzbModel newNzb = new NzbModel();
            newNzb.Name = !String.IsNullOrEmpty(import.NewName) ? import.NewName : import.Name;
            newNzb.Id = Guid.NewGuid();
            newNzb.Status = NzbStatus.Queued;
            newNzb.Priority = (Priority)import.Priority;
            newNzb.Script = import.Script;
            newNzb.Category = import.Category;
            newNzb.PostProcessing = GetPostProcessing(import);

            var nzbFileList = new List<NzbFileModel>();

            //Get all the files for this NZB
            var files = from f in nzb.Elements(ns + "file") select f;
            foreach (var file in files)
            {
                var nzbFile = new NzbFileModel();
                nzbFile.Status = NzbFileStatus.Queued;
                nzbFile.NzbId = newNzb.Id;
                var segmentList = new List<NzbSegmentModel>();

                //Get the Age of the File and Convert to DateTime
                var date = Convert.ToInt64((from d in file.Attributes("date") select d.Value).FirstOrDefault());
                nzbFile.DatePosted = TicksToDateTime(date);

                //Get the Subject and set the NzbFile's Filename
                var subject = (from s in file.Attributes("subject") select s).FirstOrDefault();
                int fileNameStart = subject.Value.IndexOf("\"") + 1;
                int fileNameEnd = subject.Value.LastIndexOf("\"") - fileNameStart;
                nzbFile.Filename = subject.Value.Substring(fileNameStart, fileNameEnd);

                //Get the groups for the NzbFile
                nzbFile.Groups = (from g in file.Descendants(ns + "group") select g.Value).ToList();

                //Get the Segments for this file
                var segments = from s in file.Descendants(ns + "segment") select s;
                foreach (var segment in segments)
                {
                    var nzbFileSegment = new NzbSegmentModel();
                    nzbFileSegment.Status = NzbSegmentStatus.Queued;
                    nzbFileSegment.NzbFileName = nzbFile.Name;
                    nzbFileSegment.Number = Convert.ToInt32((from n in segment.Attributes("number") select n.Value).FirstOrDefault());
                    nzbFileSegment.Size = Convert.ToInt64((from n in segment.Attributes("bytes") select n.Value).FirstOrDefault());
                    nzbFileSegment.SegmentId = segment.Value;
                    segmentList.Add(nzbFileSegment);
                }
                nzbFile.Segments = segmentList;
                nzbFileList.Add(nzbFile);
            }
            newNzb.Files = nzbFileList;
            return newNzb;
        }
示例#4
0
 public bool Insert(NzbModel nzb, int index)
 {
     _list.Insert(index, nzb);
     return true;
 }
示例#5
0
 public bool Add(NzbModel nzb)
 {
     _list.Add(nzb);
     return true;
 }