public RestrictionCreatedOrUpdated(string externalIdentifier, List <string> salesAreas,
                                    DateTime startDate, DateTime?endDate, TimeSpan?startTime, TimeSpan?endTime, string restrictionDays,
                                    IncludeOrExcludeOrEither schoolHolidayIndicator, IncludeOrExcludeOrEither publicHolidayIndicator,
                                    IncludeOrExclude?liveProgrammeIndicator, RestrictionType?restrictionType, RestrictionBasis?restrictionBasis,
                                    string externalProgRef, string programmeCategory, string programmeClassification, IncludeOrExclude?programmeClassificationIndicator,
                                    int timeToleranceMinsBefore, int timeToleranceMinsAfter, int?indexType, int?indexThreshold,
                                    int?productCode, string clashCode, string clearanceCode, string clockNumber, int?episodeNo)
 {
     ExternalIdentifier               = externalIdentifier;
     SalesAreas                       = salesAreas;
     StartDate                        = startDate;
     EndDate                          = endDate;
     StartTime                        = startTime;
     EndTime                          = endTime;
     RestrictionDays                  = restrictionDays;
     SchoolHolidayIndicator           = schoolHolidayIndicator;
     PublicHolidayIndicator           = publicHolidayIndicator;
     LiveProgrammeIndicator           = liveProgrammeIndicator;
     RestrictionType                  = restrictionType;
     RestrictionBasis                 = restrictionBasis;
     ExternalProgRef                  = externalProgRef;
     ProgrammeCategory                = programmeCategory;
     ProgrammeClassification          = programmeClassification;
     ProgrammeClassificationIndicator = programmeClassificationIndicator;
     TimeToleranceMinsBefore          = timeToleranceMinsBefore;
     TimeToleranceMinsAfter           = timeToleranceMinsAfter;
     IndexType                        = indexType;
     IndexThreshold                   = indexThreshold;
     ProductCode                      = productCode;
     ClashCode                        = clashCode;
     ClearanceCode                    = clearanceCode;
     ClockNumber                      = string.IsNullOrWhiteSpace(clockNumber) ? "0" : clockNumber;
     EpisodeNo                        = episodeNo;
 }
 public void Delete(
     List <string> salesAreaNames,
     bool matchAllSpecifiedSalesAreas,
     DateTime?dateRangeStart,
     DateTime?dateRangeEnd,
     RestrictionType?restrictionType)
 {
     throw new NotImplementedException();
 }
Exemple #3
0
 protected CallMethodResult DeleteByCriteria(
     List <string> salesAreaNames,
     DateTime?startDate,
     DateTime?endDate,
     RestrictionType?restrictionType,
     bool matchAllSpecifiedSalesAreas)
 {
     DbContext.WaitForIndexesAfterSaveChanges();
     Repository.Delete(salesAreaNames, matchAllSpecifiedSalesAreas, startDate, endDate, restrictionType);
     DbContext.SaveChanges();
     return(CallMethodResult.CreateHandled());
 }
        public IHttpActionResult Delete([FromUri] List <string> salesAreaNames = null, DateTime?dateRangeStart = null,
                                        DateTime?dateRangeEnd           = null,
                                        RestrictionType?restrictionType = null)
        {
            if (!ModelState.IsValid)
            {
                return(this.Error().InvalidParameters());
            }
            if (dateRangeStart == null && dateRangeEnd == null &&
                restrictionType == null && (salesAreaNames == null || !salesAreaNames.Any()))
            {
                _restrictionRepository.Truncate();
            }
            else
            {
                _restrictionRepository.Delete(salesAreaNames, false, dateRangeStart, dateRangeEnd, restrictionType);
            }

            return(Ok());
        }
        public void Delete(
            List <string> salesAreaNames,
            bool matchAllSpecifiedSalesAreas,
            DateTime?dateRangeStart,
            DateTime?dateRangeEnd,
            RestrictionType?restrictionType
            )
        {
            lock (_session)
            {
                var restrictions = Get(salesAreaNames, matchAllSpecifiedSalesAreas, dateRangeStart, dateRangeEnd, restrictionType)?.ToList();
                if (restrictions == null || !restrictions.Any())
                {
                    return;
                }

                foreach (var restriction in restrictions)
                {
                    _session.Delete <Restriction>(restriction.Id);
                }
            }
        }
Exemple #6
0
        protected CallMethodResult SearchRestrictions(
            List <string> salesAreaNames,
            DateTime?startDate,
            DateTime?endDate,
            RestrictionType?restrictionType,
            bool matchAllSpecifiedSalesAreas)
        {
            var queryModel = new RestrictionSearchQueryModel
            {
                SalesAreaNames              = salesAreaNames,
                DateRangeStart              = startDate,
                DateRangeEnd                = endDate,
                RestrictionType             = restrictionType,
                MatchAllSpecifiedSalesAreas = matchAllSpecifiedSalesAreas
            };
            var res = Repository.Get(queryModel);

            TestContext.LastOperationCount   = res?.Items?.Count ?? 0;
            TestContext.LastCollectionResult = res?.Items;
            TestContext.LastSingleResult     = null;

            return(CallMethodResult.CreateHandled());
        }
        public IEnumerable <Restriction> Get(List <string> salesAreaNames, bool matchAllSpecifiedSalesAreas, DateTime?dateRangeStart, DateTime?dateRangeEnd, RestrictionType?restrictionType)
        {
            lock (_session)
            {
                var where = new List <Expression <Func <Restriction, bool> > >();

                if (salesAreaNames != null && salesAreaNames.Any())
                {
                    if (matchAllSpecifiedSalesAreas)   // Restrictions that relate to all specified sales areas
                    {
                        where.Add(p => (p.SalesAreas == null) || (!p.SalesAreas.Any()) || (p.SalesAreas.Intersect(salesAreaNames).Count() == salesAreaNames.Count));
                    }
                    else    // Restrictions that relate to any of the specified sales areas
                    {
                        where.Add(p => (p.SalesAreas == null) || (!p.SalesAreas.Any()) || (p.SalesAreas.Intersect(salesAreaNames).Any()));
                    }
                }

                if (dateRangeStart != null)
                {
                    where.Add(p => p.StartDate >= dateRangeStart.Value.Date);
                }

                if (dateRangeEnd != null)
                {
                    //When “dateRangeEnd” is given as null, we need to ensure that we include items with null as end date.
                    //Null end date means the restrictions apply forever.
                    where.Add(p => p.EndDate < dateRangeEnd.Value.Date.AddDays(1) || p.EndDate == null);
                }

                if (restrictionType != null)
                {
                    where.Add(p => p.RestrictionType == restrictionType);
                }

                var restrictions = _session.GetAll(where.AggregateAnd());

                return(restrictions);
            }
        }
Exemple #8
0
        protected override Stream GetPreviewImagesDocumentStream(Content content, IEnumerable <SNCR.Image> previewImages, DocumentFormat documentFormat, RestrictionType?restrictionType = null)
        {
            if (documentFormat == DocumentFormat.NonDefined)
            {
                documentFormat = GetFormatByName(content.Name);
            }

            // Unfortunately we need to create a new memory stream here
            // instead of writing into the output stream directly, because
            // Aspose needs to Seek the stream during document creation,
            // which is not supported by the Http Response output stream.

            switch (documentFormat)
            {
            case DocumentFormat.Doc:
            case DocumentFormat.Docx: return(GetPreviewImagesWordStream(content, previewImages, restrictionType));

            case DocumentFormat.NonDefined:
            case DocumentFormat.Pdf: return(GetPreviewImagesPdfStream(content, previewImages, restrictionType));

            case DocumentFormat.Ppt:
            case DocumentFormat.Pptx: return(GetPreviewImagesPowerPointStream(content, previewImages, restrictionType));

            case DocumentFormat.Xls:
            case DocumentFormat.Xlsx: return(GetPreviewImagesExcelStream(content, previewImages, restrictionType));
            }

            return(null);
        }
Exemple #9
0
        protected Stream GetPreviewImagesPowerPointStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Slides);

            try
            {
                var ms              = new MemoryStream();
                var extension       = ContentNamingProvider.GetFileExtension(content.Name).ToLower();
                var oldPpt          = Common.PRESENTATION_EXTENSIONS.Contains(extension);
                var saveFormat      = oldPpt ? AsposeSlides.Export.SaveFormat.Ppt : AsposeSlides.Export.SaveFormat.Pptx;
                var docPresentation = new AsposeSlides.Presentation();
                var index           = 1;
                var imageOptions    = new PreviewImageOptions()
                {
                    RestrictionType = restrictionType
                };

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    using (var imgStream = GetRestrictedImage(previewImage, imageOptions))
                    {
                        var image            = System.Drawing.Image.FromStream(imgStream);
                        var imageForDocument = ResizeImage(image, Math.Min(image.Width, Common.PREVIEW_POWERPOINT_WIDTH), Math.Min(image.Height, Common.PREVIEW_POWERPOINT_HEIGHT));

                        if (imageForDocument != null)
                        {
                            try
                            {
                                var img   = docPresentation.Images.AddImage(imageForDocument);
                                var slide = docPresentation.Slides[0];
                                if (index > 1)
                                {
                                    docPresentation.Slides.AddClone(slide);
                                    slide = docPresentation.Slides[index - 1];
                                }

                                slide.Shapes.AddPictureFrame(AsposeSlides.ShapeType.Rectangle, 10, 10,
                                                             imageForDocument.Width, imageForDocument.Height,
                                                             img);
                            }
                            catch (IndexOutOfRangeException ex)
                            {
                                SnLog.WriteException(ex, "Error during document generation. Path: " + previewImage.Path);
                                break;
                            }
                        }
                    }

                    index++;
                }

                docPresentation.Save(ms, saveFormat);
                ms.Seek(0, SeekOrigin.Begin);

                return(ms);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);
            }

            return(null);
        }
Exemple #10
0
        protected Stream GetPreviewImagesExcelStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Cells);

            try
            {
                var ms           = new MemoryStream();
                var oldExcel     = content.Name.ToLower().EndsWith(".xls");
                var fileFormat   = oldExcel ? AsposeCells.FileFormatType.Excel97To2003 : AsposeCells.FileFormatType.Xlsx;
                var saveFormat   = oldExcel ? AsposeCells.SaveFormat.Excel97To2003 : AsposeCells.SaveFormat.Xlsx;
                var document     = new AsposeCells.Workbook(fileFormat);
                var index        = 1;
                var imageOptions = new PreviewImageOptions()
                {
                    RestrictionType = restrictionType
                };

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    using (var imgStream = GetRestrictedImage(previewImage, imageOptions))
                    {
                        var image            = System.Drawing.Image.FromStream(imgStream);
                        var imageForDocument = ResizeImage(image, Math.Min(image.Width, PREVIEW_EXCEL_WIDTH), Math.Min(image.Height, PREVIEW_EXCEL_HEIGHT));

                        if (imageForDocument != null)
                        {
                            using (var imageStream = new MemoryStream())
                            {
                                imageForDocument.Save(imageStream, Common.PREVIEWIMAGEFORMAT);

                                try
                                {
                                    var ws = index == 1 ? document.Worksheets[0] : document.Worksheets.Add("Sheet" + index);
                                    ws.Pictures.Add(0, 0, imageStream);
                                }
                                catch (IndexOutOfRangeException ex)
                                {
                                    SnLog.WriteException(ex, "Error during document generation. Path: " + previewImage.Path);
                                    break;
                                }
                            }
                        }
                    }

                    index++;
                }

                document.Save(ms, saveFormat);
                ms.Seek(0, SeekOrigin.Begin);

                return(ms);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);
            }

            return(null);
        }
Exemple #11
0
        protected Stream GetPreviewImagesWordStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Words);

            try
            {
                var ms             = new MemoryStream();
                var document       = new AsposeWords.Document();
                var builder        = new AsposeWords.DocumentBuilder(document);
                var index          = 1;
                var saveFormat     = content.Name.ToLower().EndsWith(".docx") ? AsposeWords.SaveFormat.Docx : AsposeWords.SaveFormat.Doc;
                var pageAttributes = GetPageAttributes(content);
                var imageOptions   = new PreviewImageOptions()
                {
                    RestrictionType = restrictionType
                };

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    // use the stored rotation value for this page if exists
                    int?rotation = pageAttributes.ContainsKey(previewImage.Index)
                        ? pageAttributes[previewImage.Index].degree
                        : null;

                    imageOptions.Rotation = rotation;

                    using (var imgStream = GetRestrictedImage(previewImage, imageOptions))
                    {
                        int newWidth;
                        int newHeight;

                        // Compute dimensions using a SQUARE (max width and height are equal).
                        ComputeResizedDimensionsWithRotation(previewImage, PREVIEW_WORD_HEIGHT, rotation, out newWidth, out newHeight);

                        try
                        {
                            // skip to the next page
                            if (index > 1)
                            {
                                builder.Writeln("");
                            }

                            // If the final image is landscape, we need to rotate the page
                            // to fit the image. It does not matter if the original image
                            // was landscape or the rotation made it that way.
                            // Switch orientation only if needed.
                            if (newWidth > newHeight)
                            {
                                if (builder.PageSetup.Orientation != AsposeWords.Orientation.Landscape)
                                {
                                    if (index > 1)
                                    {
                                        builder.InsertBreak(AsposeWords.BreakType.SectionBreakContinuous);
                                    }

                                    builder.PageSetup.Orientation = AsposeWords.Orientation.Landscape;
                                }
                            }
                            else
                            {
                                if (builder.PageSetup.Orientation != AsposeWords.Orientation.Portrait)
                                {
                                    if (index > 1)
                                    {
                                        builder.InsertBreak(AsposeWords.BreakType.SectionBreakContinuous);
                                    }

                                    builder.PageSetup.Orientation = AsposeWords.Orientation.Portrait;
                                }
                            }

                            builder.InsertImage(imgStream,
                                                RelativeHorizontalPosition.LeftMargin,
                                                -5,
                                                RelativeVerticalPosition.TopMargin,
                                                -50,
                                                newWidth,
                                                newHeight,
                                                WrapType.Square);
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            SnLog.WriteException(ex, "Error during document generation. Path: " + previewImage.Path);
                            break;
                        }
                    }

                    index++;
                }

                document.Save(ms, saveFormat);

                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);
            }

            return(null);
        }
Exemple #12
0
        // ===================================================================================================== Generate documents

        protected Stream GetPreviewImagesPdfStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Pdf);

            try
            {
                var ms = new MemoryStream();
                using var document = new AsposePdf.Document();
                var index          = 1;
                var pageAttributes = GetPageAttributes(content);
                var imageOptions   = new PreviewImageOptions()
                {
                    RestrictionType = restrictionType
                };

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    // use the stored rotation value for this page if exists
                    int?rotation = pageAttributes.ContainsKey(previewImage.Index)
                        ? pageAttributes[previewImage.Index].degree
                        : null;

                    imageOptions.Rotation = rotation;

                    using (var imgStream = GetRestrictedImage(previewImage, imageOptions))
                    {
                        int newWidth;
                        int newHeight;

                        // Compute dimensions using a SQUARE (max width and height are equal).
                        ComputeResizedDimensionsWithRotation(previewImage, PREVIEW_PDF_HEIGHT, rotation, out newWidth, out newHeight);

                        var imageStamp = new AsposePdf.ImageStamp(imgStream)
                        {
                            TopMargin           = 10,
                            HorizontalAlignment = AsposePdf.HorizontalAlignment.Center,
                            VerticalAlignment   = AsposePdf.VerticalAlignment.Top,
                            Width  = newWidth,
                            Height = newHeight
                        };

                        try
                        {
                            var page = index == 1 ? document.Pages[1] : document.Pages.Add();

                            // If the final image is landscape, we need to rotate the page
                            // to fit the image. It does not matter if the original image
                            // was landscape or the rotation made it that way.
                            if (newWidth > newHeight)
                            {
                                page.Rotate = AsposePdf.Rotation.on90;
                            }

                            page.AddStamp(imageStamp);
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            SnLog.WriteException(ex, "Error during pdf generation. Path: " + previewImage.Path);
                            break;
                        }
                    }

                    index++;
                }

                document.Save(ms);

                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);
            }

            return(null);
        }
        protected Stream GetPreviewImagesWordStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Words);

            try
            {
                var ms         = new MemoryStream();
                var document   = new Aspose.Words.Document();
                var builder    = new DocumentBuilder(document);
                var index      = 1;
                var saveFormat = content.Name.ToLower().EndsWith(".docx") ? Aspose.Words.SaveFormat.Docx : Aspose.Words.SaveFormat.Doc;

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    int newWidth;
                    int newHeight;

                    ComputeResizedDimensions((int)previewImage["Width"], (int)previewImage["Height"], PREVIEW_WORD_WIDTH, PREVIEW_WORD_HEIGHT, out newWidth, out newHeight);

                    using (var imgStream = GetRestrictedImage(previewImage, restrictionType: restrictionType))
                    {
                        var image = System.Drawing.Image.FromStream(imgStream);

                        try
                        {
                            //skip to the next page
                            if (index > 1)
                            {
                                builder.Writeln("");
                            }

                            builder.InsertImage(image,
                                                RelativeHorizontalPosition.LeftMargin,
                                                -5,
                                                RelativeVerticalPosition.TopMargin,
                                                -50,
                                                newWidth,
                                                newHeight,
                                                WrapType.Square);
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            Logger.WriteException(
                                new Exception("Error during document generation. Path: " + previewImage.Path, ex));
                            break;
                        }
                    }

                    index++;
                }

                document.Save(ms, saveFormat);

                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
            }

            return(null);
        }
        //===================================================================================================== Generate documents

        protected Stream GetPreviewImagesPdfStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Pdf);

            try
            {
                var ms       = new MemoryStream();
                var pdf      = new Pdf();
                var document = new Aspose.Pdf.Document(pdf);
                var index    = 1;

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    using (var imgStream = GetRestrictedImage(previewImage, restrictionType: restrictionType))
                    {
                        int newWidth;
                        int newHeight;

                        ComputeResizedDimensions((int)previewImage["Width"], (int)previewImage["Height"], PREVIEW_PDF_WIDTH, PREVIEW_PDF_HEIGHT, out newWidth, out newHeight);

                        var imageStamp = new ImageStamp(imgStream)
                        {
                            TopMargin           = 10,
                            HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
                            VerticalAlignment   = Aspose.Pdf.VerticalAlignment.Top,
                            Width  = newWidth,
                            Height = newHeight
                        };

                        try
                        {
                            var page = index == 1 ? document.Pages[1] : document.Pages.Add();
                            page.AddStamp(imageStamp);
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            Logger.WriteException(new Exception("Error during pdf generation. Path: " + previewImage.Path, ex));
                            break;
                        }
                    }

                    index++;
                }

                document.Save(ms);

                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
            }

            return(null);
        }