示例#1
0
        public SingleImagesDisplaySetDescriptor(ISeriesIdentifier sourceSeries, IPresentationImageFactory presentationImageFactory)
            : base(sourceSeries, presentationImageFactory)
        {
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");

            _suffix = SR.SuffixSingleImagesDisplaySet;
        }
		private static string GetSeriesDisplaySetName(ISeriesIdentifier series)
		{
			if (string.IsNullOrEmpty(series.SeriesDescription))
				return string.Format("{0}", series.SeriesNumber);
			else
				return string.Format("{0} - {1}", series.SeriesNumber, series.SeriesDescription);
		}
示例#3
0
        private async Task <List <Season> > GetAllEpisodesInfo(ISeriesIdentifier seriesIdentifier, string authToken,
                                                               IWebProxy proxyPreferences)
        {
            List <TheTvDbEpisode> theTvDbEpisodes = new List <TheTvDbEpisode>();
            int pageNumber = 1;

            while (true)
            {
                string episodesJson =
                    await _apiDownloader.GetEpisodesAsync(seriesIdentifier, pageNumber, authToken, proxyPreferences);

                TheTvDbEpisodeResult episodesResults =
                    JsonConvert.DeserializeObject <TheTvDbEpisodeResult>(episodesJson);
                if (episodesResults?.Data == null)
                {
                    break;
                }
                theTvDbEpisodes.AddRange(episodesResults.Data);
                if (episodesResults.Links?.Next == null)
                {
                    break;
                }
                pageNumber = episodesResults.Links.Next.Value;
            }

            List <Season> seasons = Adapt(theTvDbEpisodes).ToList();

            return(seasons);
        }
        public async Task <string> GetSeriesImagesAsync(ISeriesIdentifier seriesIdentifier, string authToken, IWebProxy proxy)
        {
            string baseUrl = _configurationValues.ApiBaseUrl;
            string url     = baseUrl + string.Format(Endpoints.GetImages, seriesIdentifier.Id);

            List <string> keyTypes = new List <string> {
                "poster", "fanart", "series", "season", "seasonwide"
            };
            Dictionary <string, Task <string> > imageTasks = new Dictionary <string, Task <string> >();

            foreach (string keyType in keyTypes)
            {
                string        queryUrl = url + $"?keyType={keyType}";
                Task <string> task     = _httpDownloader.GetStringAsync(queryUrl,
                                                                        new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    { "Authorization", $"Bearer {authToken}" }
                },
                                                                        proxy);
                imageTasks.Add(keyType, task);
            }

            await Task.WhenAll(imageTasks.Values.Cast <Task>().ToArray());

            string json = "{";

            for (int i = 0; i < keyTypes.Count; i++)
            {
                string keyType    = keyTypes[i];
                string terminator = (i < (keyTypes.Count - 1)) ? "," : string.Empty;
                json += $"\t\"{keyType}\":{imageTasks[keyType].Result}{terminator}\r\n";
            }
            json += "}";
            return(json);
        }
示例#5
0
        public MREchoDisplaySetDescriptor(ISeriesIdentifier sourceSeries, int echoNumber, IPresentationImageFactory presentationImageFactory)
            : base(sourceSeries, presentationImageFactory)
        {
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");

            EchoNumber = echoNumber;
            _suffix    = String.Format(SR.SuffixFormatMREchoDisplaySet, echoNumber);
        }
        public PETFusionDisplaySetDescriptor(ISeriesIdentifier baseSeries, ISeriesIdentifier ptSeries, bool attenuationCorrection)
            : base(baseSeries, null)
        {
            _petSeries               = ptSeries;
            _attenuationCorrection   = attenuationCorrection;
            _fusionSeriesInstanceUid = DicomUid.GenerateUid().UID;

            IsComposite = true;
        }
        public virtual async Task <Series> GetEpisodesAsync(ISeriesIdentifier seriesIdentifier,
                                                            IWebProxy proxy)
        {
            string authToken = await _authenticator.GetAuthTokenAsync(proxy);

            var series = await GetAllEpisodesInfo(seriesIdentifier, authToken, proxy);

            return(series);
        }
		public PETFusionDisplaySetDescriptor(ISeriesIdentifier baseSeries, ISeriesIdentifier ptSeries, bool attenuationCorrection)
			: base(baseSeries, null)
		{
			_petSeries = ptSeries;
			_attenuationCorrection = attenuationCorrection;
			_fusionSeriesInstanceUid = DicomUid.GenerateUid().UID;

		    IsComposite = true;
		}
示例#9
0
        public MultiframeDisplaySetDescriptor(ISeriesIdentifier sourceSeries, string sopInstanceUid, int instanceNumber)
            : base(sourceSeries)
        {
            SopInstanceUid = sopInstanceUid;
            InstanceNumber = instanceNumber;
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");
            Platform.CheckForEmptyString(sopInstanceUid, "sopInstanceUid");

            _sopInstanceUid = sopInstanceUid;
            _suffix         = String.Format(SR.SuffixFormatMultiframeDisplaySet, instanceNumber);
        }
 private static string GetSeriesDisplaySetDescription(ISeriesIdentifier series)
 {
     if (string.IsNullOrEmpty(series.SeriesDescription))
     {
         return(string.Format("{0}", series.SeriesNumber));
     }
     else
     {
         return(string.Format("{0}", series.SeriesDescription));
     }
 }
        private async Task <Series> GetSeriesInfo(ISeriesIdentifier seriesIdentifier, string authToken,
                                                  IWebProxy proxy)
        {
            string seriesJson =
                await _apiDownloader.GetSeriesExtendedAsync(seriesIdentifier, authToken, proxy);

            var seriesResponse = Deserialize <SeriesExtendedRecord>(seriesJson);

            Series series = Adapt(seriesResponse.Data);

            return(series);
        }
示例#12
0
        public async Task <string> GetSeriesExtendedAsync(ISeriesIdentifier seriesIdentifier, string authToken, IWebProxy proxy)
        {
            string baseUrl = _configurationValues.ApiBaseUrl;
            string url     = baseUrl + string.Format(Endpoints.GetSeries, seriesIdentifier.Id);

            string json = await _httpDownloader.GetStringAsync(url,
                                                               new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "Authorization", $"Bearer {authToken}" }
            },
                                                               proxy);

            return(json);
        }
示例#13
0
        private async Task <Series> GetSeriesInfo(ISeriesIdentifier seriesIdentifier, string authToken,
                                                  IWebProxy proxyPreferences)
        {
            Task <string> getSeriesTask       = _apiDownloader.GetSeriesAsync(seriesIdentifier, authToken, proxyPreferences);
            Task <string> getSeriesImagesTask =
                _apiDownloader.GetSeriesImagesAsync(seriesIdentifier, authToken, proxyPreferences);

            await Task.WhenAll(getSeriesTask, getSeriesImagesTask);

            string seriesJson = getSeriesTask.Result;
            TheTvDbSeriesResult seriesResults = JsonConvert.DeserializeObject <TheTvDbSeriesResult>(seriesJson);

            string imagesJson = getSeriesImagesTask.Result;
            TheTvDbSeriesImageResults imageResults =
                JsonConvert.DeserializeObject <TheTvDbSeriesImageResults>(imagesJson);

            Series series = Adapt(seriesResults.Data, imageResults);

            return(series);
        }
示例#14
0
		public SingleFrameDisplaySetDescriptor(ISeriesIdentifier sourceSeries, Frame frame, int position)
			: base(sourceSeries)
		{
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");
            Platform.CheckForNullReference(frame, "frame");

            _seriesInstanceUid = frame.SeriesInstanceUid;
			_sopInstanceUid = frame.SopInstanceUid;
			_frameNumber = frame.FrameNumber;
			_position = position;

			if (sourceSeries.SeriesInstanceUid == frame.SeriesInstanceUid)
			{
				_suffix = String.Format(SR.SuffixFormatSingleFrameDisplaySet, frame.ParentImageSop.InstanceNumber, _frameNumber);
			}
			else
			{
				//this is a referenced frame (e.g. key iamge).
				_suffix = String.Format(SR.SuffixFormatSingleReferencedFrameDisplaySet, 
					frame.ParentImageSop.SeriesNumber, frame.ParentImageSop.InstanceNumber, _frameNumber);
			}
		}
示例#15
0
        public SingleFrameDisplaySetDescriptor(ISeriesIdentifier sourceSeries, Frame frame, int position)
            : base(sourceSeries)
        {
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");
            Platform.CheckForNullReference(frame, "frame");

            _seriesInstanceUid = frame.SeriesInstanceUid;
            _sopInstanceUid    = frame.SopInstanceUid;
            _frameNumber       = frame.FrameNumber;
            _position          = position;

            if (sourceSeries.SeriesInstanceUid == frame.SeriesInstanceUid)
            {
                _suffix = String.Format(SR.SuffixFormatSingleFrameDisplaySet, frame.ParentImageSop.InstanceNumber, _frameNumber);
            }
            else
            {
                //this is a referenced frame (e.g. key iamge).
                _suffix = String.Format(SR.SuffixFormatSingleReferencedFrameDisplaySet,
                                        frame.ParentImageSop.SeriesNumber, frame.ParentImageSop.InstanceNumber, _frameNumber);
            }
        }
示例#16
0
        public virtual async Task <Series> GetEpisodesAsync(ISeriesIdentifier seriesIdentifier,
                                                            IWebProxy proxyPreferences)
        {
            string authToken = await _authenticator.GetAuthTokenAsync(proxyPreferences);

            Task <Series>         seriesTask  = GetSeriesInfo(seriesIdentifier, authToken, proxyPreferences);
            Task <List <Season> > seasonsTask = GetAllEpisodesInfo(seriesIdentifier, authToken, proxyPreferences);

            Task.WaitAll(seriesTask, seasonsTask);

            Series series = seriesTask.Result;

            if (string.IsNullOrWhiteSpace(series.Name) &&
                !string.IsNullOrWhiteSpace(seriesIdentifier.Name))
            {
                series.Name = seriesIdentifier.Name;
            }
            List <Season> seasons = seasonsTask.Result;

            seasons.ForEach(x => x.Series = series);
            seasons.SelectMany(x => x.Episodes).ToList().ForEach(x => x.Series = series);
            series.Seasons.AddRange(seasons);
            return(series);
        }
示例#17
0
		public MREchoDisplaySetDescriptor(ISeriesIdentifier sourceSeries, int echoNumber, IPresentationImageFactory presentationImageFactory)
			: base(sourceSeries, presentationImageFactory)
		{
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");
			
            EchoNumber = echoNumber;
			_suffix = String.Format(SR.SuffixFormatMREchoDisplaySet, echoNumber);
		}
示例#18
0
		public SingleImageDisplaySetDescriptor(ISeriesIdentifier sourceSeries, ImageSop imageSop, int position)
			: base(sourceSeries)
		{
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");
            Platform.CheckForNullReference(imageSop, "imageSop");
            
            _sopInstanceUid = imageSop.SopInstanceUid;
			_seriesInstanceUid = imageSop.SeriesInstanceUid;
			_position = position;

			string laterality = imageSop.ImageLaterality;
			string viewPosition = imageSop.ViewPosition;
			if (string.IsNullOrEmpty(viewPosition))
			{
				DicomAttributeSQ codeSequence = imageSop[DicomTags.ViewCodeSequence] as DicomAttributeSQ;
                if (codeSequence != null && !codeSequence.IsNull && codeSequence.Count > 0)
					viewPosition = codeSequence[0][DicomTags.CodeMeaning].GetString(0, null);
			}

			string lateralityViewPosition = null;
			if (!String.IsNullOrEmpty(laterality) && !String.IsNullOrEmpty(viewPosition))
				lateralityViewPosition = String.Format("{0}/{1}", laterality, viewPosition);
			else if (!String.IsNullOrEmpty(laterality))
				lateralityViewPosition = laterality;
			else if (!String.IsNullOrEmpty(viewPosition))
				lateralityViewPosition = viewPosition;

			if (sourceSeries.SeriesInstanceUid == imageSop.SeriesInstanceUid)
			{
				if (lateralityViewPosition != null)
					_suffix = String.Format(SR.SuffixFormatSingleImageDisplaySetWithLateralityViewPosition, lateralityViewPosition, imageSop.InstanceNumber);
				else
					_suffix = String.Format(SR.SuffixFormatSingleImageDisplaySet, imageSop.InstanceNumber);
			}
			else
			{
				//this is a referenced image (e.g. key image).
				if (lateralityViewPosition != null)
					_suffix = String.Format(SR.SuffixFormatSingleReferencedImageDisplaySetWithLateralityViewPosition, 
						lateralityViewPosition, imageSop.SeriesNumber, imageSop.InstanceNumber);
				else
					_suffix = String.Format(SR.SuffixFormatSingleReferencedImageDisplaySet,
						imageSop.SeriesNumber, imageSop.InstanceNumber);
			}
		}
 public XDisplaySetDescriptor(IDicomAttributeProvider dicomAttributeProvider)
 {
     _seriesIdentifier = GetSeriesIdentifier(dicomAttributeProvider);
 }
        private async Task <Series> GetAllEpisodesInfo(ISeriesIdentifier seriesIdentifier, string authToken,
                                                       IWebProxy proxy)
        {
            // I will hate TheTvDb forever for how they make you get episodes now.


            // Step 1. Query the extended details of a series
            string seriesJson = await _apiDownloader.GetSeriesExtendedAsync(seriesIdentifier, authToken, proxy);

            var theTvDbSeries = Deserialize <SeriesExtendedRecord>(seriesJson);


            // Step 2. Extract all the Aired Order seasons
            var allSeasons = theTvDbSeries.Data.Seasons
                             .Where(x => x.Type.Name == "Aired Order")
                             .OrderBy(x => x.Number)
                             .ToList();


            // Step 3. For each season, query the season individually to get episodes
            var seasonsTasks = allSeasons.ToDictionary(
                x => x.Number,
                x => _apiDownloader.GetSeasonExtendedAsync(x.Id, authToken, proxy
                                                           ));
            await Task.WhenAll(seasonsTasks.Values.ToArray());

            var theTvDbEpisodes = seasonsTasks
                                  .ToDictionary(
                x => x.Key,
                x => Deserialize <SeasonExtendedRecord>(x.Value?.Result).Data.Episodes
                .Where(y => y.SeasonNumber == x.Key)         // Linting bad information
                .ToList()
                );

            // De-dupe episodes
            var dedupedEpisodes = theTvDbEpisodes
                                  .ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value.GroupBy(
                    x => x.Id,
                    x => x
                    )
                .Select(x => x.First())
                .OrderBy(x => x.Number)
                .ToList()
                );

            // Remove any seasons without episodes
            var seasonNumbersToRemove = dedupedEpisodes
                                        .Where(kvp => kvp.Value.Count == 0)
                                        .Select(kvp => kvp.Key)
                                        .ToArray();

            foreach (var seasonNumber in seasonNumbersToRemove)
            {
                dedupedEpisodes.Remove(seasonNumber);
                allSeasons.RemoveAt(allSeasons.FindIndex(x => x.Number == seasonNumber));
            }

            // Step 4. For each episode, query the translations individually to get descriptions
            var episodesTasks = dedupedEpisodes.SelectMany(kvp => kvp.Value)
                                .ToDictionary(
                x => x.Id,
                x => _apiDownloader.GetEpisodeTranslationAsync(x.Id, "eng", authToken, proxy
                                                               ));
            await Task.WhenAll(seasonsTasks.Values.ToArray());

            var overviews = episodesTasks.ToDictionary(
                x => x.Key,
                x => Deserialize <Translation>(x.Value.Result).Data
                );

            var series = Adapt(theTvDbSeries.Data, allSeasons, dedupedEpisodes, overviews);

            return(series);
        }
示例#21
0
        public SingleImageDisplaySetDescriptor(ISeriesIdentifier sourceSeries, ImageSop imageSop, int position)
            : base(sourceSeries)
        {
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");
            Platform.CheckForNullReference(imageSop, "imageSop");

            _sopInstanceUid    = imageSop.SopInstanceUid;
            _seriesInstanceUid = imageSop.SeriesInstanceUid;
            _position          = position;

            string laterality   = imageSop.ImageLaterality;
            string viewPosition = imageSop.ViewPosition;

            if (string.IsNullOrEmpty(viewPosition))
            {
                DicomAttributeSQ codeSequence = imageSop[DicomTags.ViewCodeSequence] as DicomAttributeSQ;
                if (codeSequence != null && !codeSequence.IsNull && codeSequence.Count > 0)
                {
                    viewPosition = codeSequence[0][DicomTags.CodeMeaning].GetString(0, null);
                }
            }

            string lateralityViewPosition = null;

            if (!String.IsNullOrEmpty(laterality) && !String.IsNullOrEmpty(viewPosition))
            {
                lateralityViewPosition = String.Format("{0}/{1}", laterality, viewPosition);
            }
            else if (!String.IsNullOrEmpty(laterality))
            {
                lateralityViewPosition = laterality;
            }
            else if (!String.IsNullOrEmpty(viewPosition))
            {
                lateralityViewPosition = viewPosition;
            }

            if (sourceSeries.SeriesInstanceUid == imageSop.SeriesInstanceUid)
            {
                if (lateralityViewPosition != null)
                {
                    _suffix = String.Format(SR.SuffixFormatSingleImageDisplaySetWithLateralityViewPosition, lateralityViewPosition, imageSop.InstanceNumber);
                }
                else
                {
                    _suffix = String.Format(SR.SuffixFormatSingleImageDisplaySet, imageSop.InstanceNumber);
                }
            }
            else
            {
                //this is a referenced image (e.g. key image).
                if (lateralityViewPosition != null)
                {
                    _suffix = String.Format(SR.SuffixFormatSingleReferencedImageDisplaySetWithLateralityViewPosition,
                                            lateralityViewPosition, imageSop.SeriesNumber, imageSop.InstanceNumber);
                }
                else
                {
                    _suffix = String.Format(SR.SuffixFormatSingleReferencedImageDisplaySet,
                                            imageSop.SeriesNumber, imageSop.InstanceNumber);
                }
            }
        }
示例#22
0
		public SingleImagesDisplaySetDescriptor(ISeriesIdentifier sourceSeries, IPresentationImageFactory presentationImageFactory)
			: base(sourceSeries, presentationImageFactory)
		{
		    Platform.CheckForNullReference(sourceSeries, "sourceSeries");

            _suffix = SR.SuffixSingleImagesDisplaySet;
		}
示例#23
0
 public SeriesIdentifier(ISeriesIdentifier other)
     : base(other)
 {
     CopyFrom(other);
     SeriesNumber = other.SeriesNumber;
 }
示例#24
0
		/// <summary>
		/// Protected constructor.
		/// </summary>
		protected DicomDisplaySetDescriptor(ISeriesIdentifier sourceSeries, IPresentationImageFactory presentationImageFactory)
		{
			_sourceSeries = sourceSeries;
			_presentationImageFactory = presentationImageFactory;
		}
示例#25
0
 /// <summary>
 /// Protected constructor.
 /// </summary>
 protected DicomDisplaySetDescriptor(ISeriesIdentifier sourceSeries)
     : this(sourceSeries, null)
 {
 }
示例#26
0
 public SeriesDisplaySetDescriptor(ISeriesIdentifier sourceSeries, IPresentationImageFactory presentationImageFactory)
     : base(sourceSeries, presentationImageFactory)
 {
     Platform.CheckForNullReference(sourceSeries, "sourceSeries");
     Platform.CheckForNullReference(presentationImageFactory, "presentationImageFactory");
 }
 public async Task <string> GetEpisodesAsync(ISeriesIdentifier seriesIdentifier, string authToken, IWebProxy proxy)
 {
     return(await GetEpisodesAsync(seriesIdentifier, 1, authToken, proxy));
 }
示例#28
0
		public SeriesDisplaySetDescriptor(ISeriesIdentifier sourceSeries, IPresentationImageFactory presentationImageFactory)
			: base(sourceSeries, presentationImageFactory)
		{
            Platform.CheckForNullReference(sourceSeries, "sourceSeries");
			Platform.CheckForNullReference(presentationImageFactory, "presentationImageFactory");
		}
示例#29
0
		/// <summary>
		/// Protected constructor.
		/// </summary>
		protected DicomDisplaySetDescriptor(ISeriesIdentifier sourceSeries)
			: this(sourceSeries, null)
		{
		}
示例#30
0
		public MultiframeDisplaySetDescriptor(ISeriesIdentifier sourceSeries, string sopInstanceUid, int instanceNumber)
			: base(sourceSeries)
		{
		    SopInstanceUid = sopInstanceUid;
		    InstanceNumber = instanceNumber;
		    Platform.CheckForNullReference(sourceSeries, "sourceSeries");
            Platform.CheckForEmptyString(sopInstanceUid, "sopInstanceUid");
            
            _sopInstanceUid = sopInstanceUid;
			_suffix = String.Format(SR.SuffixFormatMultiframeDisplaySet, instanceNumber);
		}
 public SeriesIdentifier(ISeriesIdentifier other)
     : base(other)
 {
     CopyFrom(other);
     SeriesNumber = other.SeriesNumber;
 }
示例#32
0
        private List <IDisplaySet> DoCreateSingleImageDisplaySets(Series series)
        {
            List <IDisplaySet> displaySets = new List <IDisplaySet>();
            int position = 0;

            foreach (Sop sop in series.Sops)
            {
                List <IPresentationImage> images = PresentationImageFactory.CreateImages(sop);
                if (images.Count == 0)
                {
                    continue;
                }

                if (sop.IsImage)
                {
                    ImageSop imageSop = (ImageSop)sop;
                    DicomDisplaySetDescriptor descriptor;

                    if (imageSop.NumberOfFrames == 1)
                    {
                        descriptor = new SingleImageDisplaySetDescriptor(series.GetIdentifier(), imageSop, position++);
                    }
                    else
                    {
                        descriptor = new MultiframeDisplaySetDescriptor(series.GetIdentifier(), sop.SopInstanceUid, sop.InstanceNumber);
                    }

                    DisplaySet displaySet = new DisplaySet(descriptor);
                    foreach (IPresentationImage image in images)
                    {
                        displaySet.PresentationImages.Add(image);
                    }

                    displaySets.Add(displaySet);
                }
                else
                {
                    //The sop is actually a container for other referenced sops, like key images.
                    foreach (IPresentationImage image in images)
                    {
                        DisplaySetDescriptor descriptor = null;
                        if (image is IImageSopProvider)
                        {
                            IImageSopProvider provider = (IImageSopProvider)image;
                            if (provider.ImageSop.NumberOfFrames == 1)
                            {
                                descriptor = new SingleImageDisplaySetDescriptor(series.GetIdentifier(), provider.ImageSop, position++);
                            }
                            else
                            {
                                descriptor = new SingleFrameDisplaySetDescriptor(series.GetIdentifier(), provider.Frame, position++);
                            }
                        }
                        else
                        {
                            //TODO (CR Jan 2010): this because the design here is funny... the factory here should actually know something about the key object series it is building for
                            ISeriesIdentifier sourceSeries = series.GetIdentifier();
                            descriptor             = new BasicDisplaySetDescriptor();
                            descriptor.Description = sourceSeries.SeriesDescription;
                            descriptor.Name        = string.Format("{0}: {1}", sourceSeries.SeriesNumber, sourceSeries.SeriesDescription);
                            descriptor.Number      = sourceSeries.SeriesNumber.GetValueOrDefault(0);
                            descriptor.Uid         = sourceSeries.SeriesInstanceUid;
                        }

                        DisplaySet displaySet = new DisplaySet(descriptor);
                        displaySet.PresentationImages.Add(image);
                        displaySets.Add(displaySet);
                    }
                }
            }

            if (displaySets.Count == 1)
            {
                //Degenerate case; single image series, which we're not supposed to create.
                displaySets[0].Dispose();
                displaySets.Clear();
            }

            return(displaySets);
        }
示例#33
0
 /// <summary>
 /// Protected constructor.
 /// </summary>
 protected DicomDisplaySetDescriptor(ISeriesIdentifier sourceSeries, IPresentationImageFactory presentationImageFactory)
 {
     _sourceSeries             = sourceSeries;
     _presentationImageFactory = presentationImageFactory;
 }