Example #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);
             }
         }
     }
 }
Example #2
0
        protected override void ProcessRecord()
        {
            string msg = string.Format("Host: {0}; LocalPath: '{1}'; RemotePath: '{2}'", this.HostName, this.LocalPath, this.RemotePath);

            if (base.ShouldProcess(msg, "New"))
            {
                RemotePathMapping rpm = base.SendSonarrPost <RemotePathMapping>(EP, this.GetBodyParameters());
                base.SendToPipeline(rpm);
            }
        }
Example #3
0
        public void adding_duplicated_mapping_should_throw(string host, string remotePath, string localPath)
        {
            localPath = localPath.AsOsAgnostic();

            GivenMapping();

            var mapping = new RemotePathMapping {
                Host = host, RemotePath = remotePath, LocalPath = localPath
            };

            Assert.Throws <InvalidOperationException>(() => Subject.Add(mapping));
        }
Example #4
0
 private IEnumerable <RemotePathMapping> GetRemotePathMappingsByIds()
 {
     foreach (int oneId in _ids)
     {
         string            endpoint = string.Format(EP_WITH_ID, oneId);
         RemotePathMapping rpm      = base.SendSonarrGet <RemotePathMapping>(endpoint);
         if (rpm != null)
         {
             yield return(rpm);
         }
     }
 }
Example #5
0
        public void should_be_able_to_add_new_mapping(string host, string remotePath, string localPath)
        {
            GivenMapping();

            localPath = localPath.AsOsAgnostic();

            var mapping = new RemotePathMapping {
                Host = host, RemotePath = remotePath, LocalPath = localPath
            };

            Subject.Add(mapping);

            Mocker.GetMock <IRemotePathMappingRepository>().Verify(c => c.Insert(mapping), Times.Once());
        }
Example #6
0
        public void should_trim_whitespace_on_add(string remotePath, string cleanedPath)
        {
            GivenMapping();

            var mapping = new RemotePathMapping
            {
                Host       = "my-server.localdomain",
                RemotePath = remotePath,
                LocalPath  = @"D:\mountedstorage\downloads\tv".AsOsAgnostic()
            };

            var result = Subject.Add(mapping);

            result.RemotePath.Should().Be(cleanedPath);
        }
Example #7
0
        public static RemotePathMappingResource ToResource(this RemotePathMapping model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new RemotePathMappingResource
            {
                Id = model.Id,

                Host = model.Host,
                RemotePath = model.RemotePath,
                LocalPath = model.LocalPath
            });
        }