コード例 #1
0
 protected override void ProcessRecord()
 {
     if (this.ParameterSetName == "ByRemotePathName")
     {
         string jsonRes = base.TryGetSonarrResult(EP);
         if (!string.IsNullOrEmpty(jsonRes))
         {
             List <RemotePathMapping> mappings = SonarrHttp.ConvertToSonarrResults <RemotePathMapping>(jsonRes);
             if (this.MyInvocation.BoundParameters.ContainsKey("RemotePath"))
             {
                 var wcp = new WildcardPattern(this.RemotePath);
                 base.WriteObject(mappings.FindAll(x => wcp.IsMatch(x.RemotePath)), true);
             }
             else
             {
                 base.WriteObject(mappings, true);
             }
         }
     }
     else if (this.MyInvocation.BoundParameters.ContainsKey("MappingId"))
     {
         for (int i = 0; i < this.MappingId.Length; i++)
         {
             string jsonRes = base.TryGetSonarrResult(string.Format(EP_WITH_ID, this.MappingId[i]));
             if (!string.IsNullOrEmpty(jsonRes))
             {
                 RemotePathMapping mapping = SonarrHttp.ConvertToSonarrResult <RemotePathMapping>(jsonRes);
                 base.WriteObject(mapping);
             }
         }
     }
 }
コード例 #2
0
 protected override void ProcessRecord()
 {
     if (this.MyInvocation.BoundParameters.ContainsKey("Id"))
     {
         for (int i = 0; i < this.Id.Length; i++)
         {
             string ep      = string.Format(EP_ID, this.Id[i]);
             string jsonRes = base.TryGetSonarrResult(ep);
             if (!string.IsNullOrEmpty(jsonRes))
             {
                 QueueItem oneRes = SonarrHttp.ConvertToSonarrResult <QueueItem>(jsonRes);
                 base.WriteObject(oneRes);
             }
         }
     }
     else
     {
         string jsonRes = base.TryGetSonarrResult(EP);
         if (!string.IsNullOrEmpty(jsonRes))
         {
             List <QueueItem> resses = SonarrHttp.ConvertToSonarrResults <QueueItem>(jsonRes, out bool iso);
             base.WriteObject(resses, true);
         }
     }
 }
コード例 #3
0
ファイル: GetCommand.cs プロジェクト: camcox3/PoshSonarr
 protected override void ProcessRecord()
 {
     if (this.MyInvocation.BoundParameters.ContainsKey("JobId"))
     {
         for (int i = 0; i < this.JobId.Length; i++)
         {
             string ep      = string.Format(EP_ID, this.JobId[i]);
             string jsonRes = base.TryGetSonarrResult(ep);
             if (!string.IsNullOrEmpty(jsonRes))
             {
                 CommandResult output = SonarrHttp.ConvertToSonarrResult <CommandResult>(jsonRes);
                 base.WriteObject(output);
             }
         }
     }
     else
     {
         string jsonRes = base.TryGetSonarrResult(EP);
         if (!string.IsNullOrEmpty(jsonRes))
         {
             List <CommandResult> jobs = SonarrHttp.ConvertToSonarrResults <CommandResult>(jsonRes, out bool iso);
             base.WriteObject(jobs, true);
         }
     }
 }
コード例 #4
0
        protected override void ProcessRecord()
        {
            if (this.ParameterSetName != "ByClientId")
            {
                List <DownloadClient> clients = this.GetAllDownloadClients();
                if (clients != null)
                {
                    if (!this.MyInvocation.BoundParameters.ContainsKey("Protocol"))
                    {
                        base.WriteObject(clients, true);
                    }

                    else
                    {
                        base.WriteObject(this.FindByProtocol(clients), true);
                    }
                }
            }
            else
            {
                for (int i = 0; i < this.Id.Length; i++)
                {
                    string jsonRes = base.TryGetSonarrResult(string.Format(EP_ID, this.Id[i]));
                    if (!string.IsNullOrEmpty(jsonRes))
                    {
                        DownloadClient dlCli = SonarrHttp.ConvertToSonarrResult <DownloadClient>(jsonRes);
                        base.WriteObject(dlCli);
                    }
                }
            }
        }
コード例 #5
0
ファイル: GetStatus.cs プロジェクト: camcox3/PoshSonarr
        protected override void ProcessRecord()
        {
            string strRes = base.TryGetSonarrResult("/system/status");

            if (!string.IsNullOrWhiteSpace(strRes))
            {
                SonarrStatusResult ssr = SonarrHttp.ConvertToSonarrResult <SonarrStatusResult>(strRes);
                base.WriteObject(ssr);
            }
        }
コード例 #6
0
ファイル: NewRestriction.cs プロジェクト: camcox3/PoshSonarr
        protected override void ProcessRecord()
        {
            Restriction newRestrict = this.ParametersToRestriction(this.MyInvocation.BoundParameters);

            if (base.ShouldProcess(string.Format(SHOULD_MSG, newRestrict.Ignored.ToJson(), newRestrict.Required.ToJson()), "New"))
            {
                string jsonRes = base.TryPostSonarrResult(GetRestriction.EP, newRestrict.ToJson());
                if (!string.IsNullOrEmpty(jsonRes))
                {
                    Restriction restRes = SonarrHttp.ConvertToSonarrResult <Restriction>(jsonRes);
                    base.WriteObject(restRes);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Takes in a generic dictionary of parameters and issues a command to Sonarr with the dictionary as its payload.
        /// </summary>
        /// <param name="parameterDict">The set of parameters to build the POST body with,</param>
        protected void ProcessRequest(IDictionary parameterDict)
        {
            string cmdName = parameterDict["name"] as string;
            string verbMsg = string.Format("Issuing command - {0} at {1}", cmdName, BASE_EP);

            string postBody = JsonConvert.SerializeObject(parameterDict, Formatting.Indented);
            string cmdOut   = base.TryPostSonarrResult(BASE_EP, postBody);

            if (!string.IsNullOrEmpty(cmdOut))
            {
                CommandOutput cmdOutput = SonarrHttp.ConvertToSonarrResult <CommandOutput>(cmdOut);
                base.WriteObject(cmdOutput);
            }
        }
コード例 #8
0
ファイル: GetTag.cs プロジェクト: camcox3/PoshSonarr
 protected override void ProcessRecord()
 {
     if (this.ParameterSetName == "ByTagLabel")
     {
         string     allRes = base.TryGetSonarrResult(EP);
         List <Tag> tags   = null;
         if (!string.IsNullOrEmpty(allRes))
         {
             tags = SonarrHttp.ConvertToSonarrResults <Tag>(allRes, out bool iso);
         }
         if (tags.Count > 0)
         {
             if (this.MyInvocation.BoundParameters.ContainsKey("Label"))
             {
                 for (int i = 0; i < this.Label.Length; i++)
                 {
                     var wcp = new WildcardPattern(this.Label[i], WildcardOptions.IgnoreCase);
                     for (int t = 0; t < tags.Count; t++)
                     {
                         Tag oneTag = tags[t];
                         if (wcp.IsMatch(oneTag.Label))
                         {
                             base.WriteObject(oneTag);
                         }
                     }
                 }
             }
             else
             {
                 base.WriteObject(tags, true);
             }
         }
     }
     else
     {
         for (int i = 0; i < this.Id.Length; i++)
         {
             string ep      = string.Format(EP_ID, this.Id[i]);
             string jsonRes = base.TryGetSonarrResult(ep);
             if (!string.IsNullOrEmpty(jsonRes))
             {
                 base.WriteObject(SonarrHttp.ConvertToSonarrResult <Tag>(jsonRes));
             }
         }
     }
 }
コード例 #9
0
        protected override void ProcessRecord()
        {
            if (this.ParameterSetName == "ByProfileName")
            {
                List <QualityProfile> profs = null;
                string jsonStr = base.TryGetSonarrResult("/profile");
                if (!string.IsNullOrEmpty(jsonStr))
                {
                    profs = SonarrHttp.ConvertToSonarrResults <QualityProfile>(jsonStr, out bool iso);
                }

                if (profs != null && profs.Count > 0)
                {
                    if (this.Name != null && this.Name.Length > 0)
                    {
                        for (int n = 0; n < this.Name.Length; n++)
                        {
                            string name = this.Name[n];
                            var    wcp  = new WildcardPattern(name, WildcardOptions.IgnoreCase);
                            for (int p = 0; p < profs.Count; p++)
                            {
                                QualityProfile qp = profs[p];
                                if (wcp.IsMatch(qp.Name))
                                {
                                    base.WriteObject(qp);
                                }
                            }
                        }
                    }
                    else
                    {
                        base.WriteObject(profs, true);
                    }
                }
            }
            else
            {
                string full    = string.Format("/profile/{0}", this.Id);
                string oneProf = base.TryGetSonarrResult(full);
                if (!string.IsNullOrEmpty(oneProf))
                {
                    QualityProfile qp = SonarrHttp.ConvertToSonarrResult <QualityProfile>(oneProf);
                    base.WriteObject(qp);
                }
            }
        }
コード例 #10
0
        protected override void ProcessRecord()
        {
            var dict = new Dictionary <string, string>(1)
            {
                { "label", this.Label }
            };
            string jsonBody = JsonConvert.SerializeObject(dict, Formatting.Indented);

            if (base.ShouldProcess(string.Format("Tag - {0}", this.Label), "New"))
            {
                string jsonRes = base.TryPostSonarrResult(EP, jsonBody);

                if (!string.IsNullOrEmpty(jsonRes))
                {
                    Tag res = SonarrHttp.ConvertToSonarrResult <Tag>(jsonRes);
                    base.WriteObject(res);
                }
            }
        }
コード例 #11
0
ファイル: SearchDirectory.cs プロジェクト: camcox3/PoshSonarr
        protected override void ProcessRecord()
        {
            if (!this.Path.EndsWith(@"\"))
            {
                this.Path = this.Path + @"\";
            }

            string fullEp  = string.Format(EP, this.Path);
            string jsonRes = base.TryGetSonarrResult(fullEp);

            if (!string.IsNullOrEmpty(jsonRes))
            {
                FileSystem fs = SonarrHttp.ConvertToSonarrResult <FileSystem>(jsonRes);
                if (fs != null)
                {
                    base.WriteObject(fs.Directories, true);
                }
            }
        }
コード例 #12
0
ファイル: GetRestriction.cs プロジェクト: camcox3/PoshSonarr
        private Restriction GetRestrictionById(int id)
        {
            string jsonRes = base.TryGetSonarrResult(string.Format(EP_ID, id));

            return(SonarrHttp.ConvertToSonarrResult <Restriction>(jsonRes));
        }