Beispiel #1
0
        private void UpdateTitleFieldsFor(ref BLModel.Alternate.Long.Airing airing, BLModel.Alternate.Title.Title primaryTitle)
        {
            if (primaryTitle.TitleType.Name != "Feature Film")
            {
                if (string.IsNullOrEmpty(airing.Title.Episode.Number))
                {
                    airing.Title.Episode.Number = primaryTitle.EpisodeNumber;
                }

                if (string.IsNullOrEmpty(airing.Title.Episode.Name))
                {
                    airing.Title.Episode.Name = primaryTitle.TitleName;
                }
            }

            if (airing.Title.ReleaseYear == 0)
            {
                airing.Title.ReleaseYear = primaryTitle.ReleaseYear;
            }

            if (airing.Title.Season.Number == 0)
            {
                airing.Title.Season.Number = primaryTitle.SeasonNumber;
            }

            if (string.IsNullOrEmpty(airing.Title.StoryLine.Long))
            {
                airing.Title.StoryLine.Long = GetStoryline(primaryTitle.Storylines, "Turner External");
            }

            if (string.IsNullOrEmpty(airing.Title.StoryLine.Short))
            {
                airing.Title.StoryLine.Short = GetStoryline(primaryTitle.Storylines, "Short (245 Characters)");
            }
        }
Beispiel #2
0
        public void AppendTitle(ref BLModel.Alternate.Long.Airing airing)
        {
            List <int> titleIds = airing.Title.TitleIds
                                  .Where(t => t.Authority == "Turner" && t.Value != null)
                                  .Select(t => int.Parse(t.Value)).ToList();

            titleIds.AddRange(airing.Title.RelatedTitleIds.Where(t => t.Authority == "Turner").Select(t => int.Parse(t.Value)).ToList());

            // Find all title ids within the airing listed as Authority=Turner that exists in Flow
            var titles = GetFlowTitlesFor(titleIds);

            // Get the first title listed as Primary from the airing
            var primaryTitleId = airing.Title.TitleIds.FirstOrDefault(t => t.Primary);

            if (primaryTitleId != null && !titles.IsNullOrEmpty())
            {
                // The assumption here is that 'primaryTitleId' will exist in 'titles'. If it doesn't then
                // from a business perspective it is not valid. However, we don't want to throw any errors
                // here but silently ignore it
                if (titles.Exists(t => t.TitleId == int.Parse(primaryTitleId.Value)))
                {
                    var primaryTitle = titles.First(t => t.TitleId == int.Parse(primaryTitleId.Value));
                    UpdateTitleFieldsFor(ref airing, primaryTitle);
                }
            }

            airing.Options.Titles = titles;
        }
Beispiel #3
0
        public void AppendPackage(ref BLModel.Alternate.Long.Airing airing, IEnumerable <Tuple <string, decimal> > acceptHeaders)
        {
            var titleIds = airing.Title.TitleIds.Where(title => (title.Authority.Equals("Turner") && isNumeric(title.Value)))
                           .Select(thisTitle => (getTitleId(thisTitle.Value)));

            var contentIds = airing.Versions.Select(version => version.ContentId);

            //double check no bad titleIds are in the array.
            titleIds = titleIds.Where(title => (title != -1)).ToList();
            var destinations = airing.Flights.SelectMany(flight =>
                                                         flight.Destinations.Select(destination => destination.Name));

            List <DLPackageModel.Package> matchingPackages         = new List <DLPackageModel.Package>();
            List <DLPackageModel.Package> titleAndAiringIdPackages = packageQueryHelper.GetBy(airing.AiringId, titleIds.ToList(), destinations.ToList()).ToList();
            List <DLPackageModel.Package> cidPackages = packageQueryHelper.GetBy(contentIds.ToList(), destinations.ToList()).ToList();

            matchingPackages.AddRange(titleAndAiringIdPackages);
            matchingPackages.AddRange(cidPackages);
            airing.Options.Packages = matchingPackages.ToViewModel <List <DLPackageModel.Package>, List <BLModel.Alternate.Package.Package> >();

            // verify the kind of serialization
            bool isXMLSerialization = (acceptHeaders.Count(c => c.Item1 == "application/xml") > 0) ? true : false;

            foreach (var package in airing.Options.Packages)
            {
                package.Data        = isXMLSerialization ? package.Data : null;
                package.PackageData = !isXMLSerialization ? package.PackageData : null;
            }
        }
Beispiel #4
0
        public void AppendDestinations(ref BLModel.Alternate.Long.Airing airing)
        {
            var destinationNames = airing.Flights
                                   .SelectMany(f => f.Destinations)
                                   .Select(d => d.Name)
                                   .Distinct()
                                   .ToList();

            var destinations = destinationQueryHelper.GetByDestinationNames(destinationNames)
                               .ToBusinessModel <List <DLDestinationModel.Destination>, List <BLModel.Alternate.Destination.Destination> >();

            foreach (BLModel.Alternate.Destination.Destination des in destinations)  //verify each destination has categories . if yes then conbine categories and properties.
            {
                if (des.Categories.Any())
                {
                    foreach (BLModel.Alternate.Destination.Category cat in des.Categories)
                    {
                        BLModel.Alternate.Destination.Property property = cat.ToBusinessModel <BLModel.Alternate.Destination.Category, BLModel.Alternate.Destination.Property>();
                        des.Properties.Add(property);
                    }
                }
            }
            FilterPropertiesByBrand(destinations, ref airing);
            new BLModel.Alternate.Destination.DeliverableFormatter(airing).Format(destinations); // destinations passed by reference for formatting
            new BLModel.Alternate.Destination.PropertyFormatter(airing).Format(destinations);    // destinations passed by reference for formatting

            airing.Options.Destinations = destinations;
        }
Beispiel #5
0
        public void AppendStatus(ref BLModel.Alternate.Long.Airing airing)
        {
            airing.Options.Status = airing.Status;  // Retrieve other status from airing collection
            // Check if file information is already included. If so, do not
            // retrieve again; else, retrieve it
            if (airing.Options.Files.IsNullOrEmpty())
            {
                if (String.IsNullOrWhiteSpace(airing.MediaId))
                {
                    airing.MediaId = String.Empty;
                }

                var titleIds   = ExtractTitleAndSeriesIdsFrom(airing);
                var versionIds = ExtractVersionIdsFrom(airing);
                var files      = fileQueryHelper.GetBy(versionIds, titleIds, airing.AiringId, airing.MediaId).ToList();

                if (!files.IsNullOrEmpty())
                {
                    airing.Options.Status["video"] = !files.Where(c => c.Video == true).IsNullOrEmpty();
                }
                else
                {
                    airing.Options.Status["video"] = false;
                }
            }
            else
            {
                airing.Options.Status["video"] = !airing.Options.Files.Where(c => c.Video == true).IsNullOrEmpty();
            }
        }
Beispiel #6
0
        public void AppendVersion(ref BLModel.Alternate.Long.Airing airing)
        {
            List <string> contentIds = airing.Versions
                                       .Select(t => t.ContentId).ToList();

            // Find version information for all content ids within the airing versions that exists in Flow
            JArray versions = GetVersionData(contentIds);

            airing.Options.Versions = versions;
        }
Beispiel #7
0
        public void AppendSeries(ref BLModel.Alternate.Long.Airing airing)
        {
            if (airing.Title.Series == null || airing.Title.Series.Id == null)
            {
                return;
            }

            var series = GetTitleFor(airing.Title.Series.Id.Value);

            airing.Options.Series.Add(series);
        }
Beispiel #8
0
        public void AppendFileBySeriesId(ref BLModel.Alternate.Long.Airing airing)
        {
            if (airing.Title.Series == null || !airing.Title.Series.Id.HasValue)
            {
                return;
            }

            var files = fileQueryHelper.Get(airing.Title.Series.Id.Value).ToList();

            airing.Options.Files.AddRange(Mapper.Map <List <DLFileModel.File>, List <BLModel.Alternate.Long.File> >(files)
                                          .ToList());
        }
Beispiel #9
0
        public void AppendPremiere(ref BLModel.Alternate.Long.Airing airing)
        {
            List <int> titleIds = airing.Title.TitleIds
                                  .Where(t => t.Authority == "Turner" && t.Value != null)
                                  .Select(t => int.Parse(t.Value)).ToList();

            titleIds.AddRange(airing.Title.RelatedTitleIds.Where(t => t.Authority == "Turner").Select(t => int.Parse(t.Value)).ToList());

            // Find permiere information for all title ids within the airing listed as Authority=Turner that exists in Flow
            JArray premieres = GetPremiereData(titleIds);

            airing.Options.Premieres = premieres;
        }
Beispiel #10
0
        public void AppendFile(ref BLModel.Alternate.Long.Airing airing)
        {
            if (String.IsNullOrWhiteSpace(airing.MediaId))
            {
                airing.MediaId = String.Empty;
            }

            var titleIds   = ExtractTitleAndSeriesIdsFrom(airing);
            var versionIds = ExtractVersionIdsFrom(airing);
            var files      = fileQueryHelper.GetBy(versionIds, titleIds, airing.AiringId, airing.MediaId).ToList();

            airing.Options.Files.AddRange(Mapper.Map <List <DLFileModel.File>, List <BLModel.Alternate.Long.File> >(files)
                                          .ToList());
        }
Beispiel #11
0
        private static List <int> ExtractTitleAndSeriesIdsFrom(BLModel.Alternate.Long.Airing airing)
        {
            var titleIds = airing.Title.TitleIds
                           .Where(t => t.Authority == "Turner" && t.Value != null)
                           .Select(t => int.Parse(t.Value))
                           .ToList();

            if (airing.Title.Series.Id.HasValue)
            {
                titleIds.Add(airing.Title.Series.Id.Value);
            }

            return(titleIds);
        }
Beispiel #12
0
        private IEnumerable <Change> Find(ref BLModel.Alternate.Long.Airing airing)
        {
            var groupedAirings = GetAiringsToDiffOn(new[] { airing });

            var changes = new List <BLModel.Alternate.Change.Change>();

            foreach (var groupedAiring in groupedAirings)
            {
                try
                {
                    if (AiringIsNew(groupedAiring))
                    {
                        var builder = new ChangeBuilder();
                        changes.Add(builder.BuildNewChange(groupedAiring.First()));
                    }
                    else if (ComparingTwoAirings(groupedAiring))
                    {
                        var currentAsset  = groupedAiring.FirstOrDefault();
                        var originalAsset = groupedAiring.LastOrDefault();
                        changes.AddRange(Find(currentAsset, originalAsset));
                    }
                    else if (ComparingThreeAirings(groupedAiring))
                    {
                        var currentAsset  = groupedAiring.FirstOrDefault();
                        var previousAsset = groupedAiring.Skip(1).FirstOrDefault();
                        var originalAsset = groupedAiring.LastOrDefault();
                        changes.AddRange(Find(currentAsset, previousAsset, originalAsset));
                    }
                    else if (AiringIsBeingDeleted(groupedAiring.Key))
                    {
                        var builder = new ChangeBuilder();
                        changes.Add(builder.BuildDeletion(groupedAiring.First()));
                    }
                }
                catch (Exception ex)
                {
                    var current = groupedAiring.FirstOrDefault();
                    if (null != current)
                    {
                        var toThrow = new Exception(String.Format("Exception occurred while detecting change for Airing Id '{0}'. ", current.AiringId), ex);
                        throw toThrow;
                    }

                    throw ex;
                }
            }

            return(changes);
        }
Beispiel #13
0
        private bool IsPropertyTitleIdsAssociatedwithAiringTitleIds(BLModel.Alternate.Long.Airing airing, BLModel.Alternate.Destination.Property property)
        {
            var titleIds = ExtractTitleAndSeriesIdsFrom(airing);

            if (titleIds.Any())
            {
                if (!property.TitleIds.Any(titleIds.Contains))
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Beispiel #14
0
        private IEnumerable <FieldChange> Find(BLModel.Alternate.Long.Airing currentAsset, BLModel.Alternate.Long.Airing originalAiring)
        {
            var changeBuilder = new ChangeBuilder();

            var currentJson  = JsonConvert.SerializeObject(currentAsset);
            var originalJson = JsonConvert.SerializeObject(originalAiring);

            var currentAssetAsJson  = JObject.Parse(currentJson);
            var originalAssetAsJson = JObject.Parse(originalJson);

            var differ = new JsonDiffer();

            var results = differ.FindDifferences(currentAssetAsJson, originalAssetAsJson);

            foreach (var change in results)
            {
                changeBuilder.SetCommonValues(change, currentAsset, originalAiring);
            }

            return(results);
        }
Beispiel #15
0
        // private Task<List<JObject>> GetPremiereDataAsync(RestClient theClient, RestRequest theRequest)
        // {
        //     var tcs = new TaskCompletionSource<List<JObject>>();

        //     theClient.ExecuteAsync<List<string>>(theRequest, response =>
        //     {
        //         var kk = response.Data[0] as JObject;
        //     });

        //     theClient.ExecuteAsync<List<JObject>>(theRequest, response =>
        //     {
        //         tcs.SetResult(response.Data);
        //     });
        //     return tcs.Task;
        // }

        private List <string> ExtractVersionIdsFrom(BLModel.Alternate.Long.Airing airing)
        {
            return(airing.Versions
                   .Select(t => t.ContentId)
                   .ToList());
        }
Beispiel #16
0
        public void AppendChanges(ref BLModel.Alternate.Long.Airing airing)
        {
            var changes = Find(ref airing);

            airing.Options.Changes = changes.ToList();
        }
Beispiel #17
0
        private void FilterPropertiesByBrand(IEnumerable <BLModel.Alternate.Destination.Destination> dataModels, ref BLModel.Alternate.Long.Airing airing)
        {
            var propertiesToRemove = new List <BLModel.Alternate.Destination.Property>();

            foreach (var destination in dataModels)
            {
                foreach (var property in destination.Properties)
                {
                    if (property.Brands.Any() && !property.Brands.Contains(airing.Brand))
                    {
                        propertiesToRemove.Add(property);
                        continue;
                    }

                    if (property.TitleIds.Any())
                    {
                        if (!IsPropertyTitleIdsAssociatedwithAiringTitleIds(airing, property)) // Any one of the title Id should match
                        {
                            propertiesToRemove.Add(property);
                        }
                    }
                }

                destination.Properties = destination.Properties.Where(p => !propertiesToRemove.Contains(p)).ToList();
            }
        }