예제 #1
0
        /// <summary>
        /// Reads the saved thumbnails (from the database) and, convert them to smaller size and save them on disk
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void formPI_DoWork_GenerateSiteMovies_Thumbnails(FrmProgressIndicator sender, DoWorkEventArgs e)
        {
            var args = (BgwArgument_Work)e.Argument;
            var errorsWhileSaving = new List <TechnicalDetailsImportError>();

            var i = 0;

            foreach (var movieShortInfo in args.MSI)
            {
                if (sender.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                i++;
                sender.SetProgress(i, Path.GetFileName(movieShortInfo.FileName));

                try
                {
                    var stills = Desene.DAL.LoadMovieStills(movieShortInfo.Id).MovieStills;

                    if (stills == null || stills.Count == 0)
                    {
                        continue;
                    }

                    movieShortInfo.ThumbnailGenerated = true;

                    for (var j = 0; j < stills.Count; j++)
                    {
                        var fileName = Path.Combine(args.SiteGenLocation,
                                                    string.Format("Imgs\\{0}\\Thumbnails\\thumb-{1}-{2}.jpg", args.SubFolder, movieShortInfo.Id, j));

                        if (File.Exists(fileName))
                        {
                            continue;
                        }

                        using (var ms = new MemoryStream(stills[j]))
                        {
                            var imgOgj = CreateStillThumbnail(250, Image.FromStream(ms));

                            imgOgj.Save(fileName, ImageFormat.Jpeg);
                        }
                    }
                }
                catch (Exception ex)
                {
                    errorsWhileSaving.Add(
                        new TechnicalDetailsImportError
                    {
                        FilePath    = movieShortInfo.FileName,
                        ErrorMesage = OperationResult.GetErrorMessage(ex)
                    });
                }
            }

            e.Result = errorsWhileSaving;
        }
예제 #2
0
        /// <summary>
        /// Reads the saved posters from the database, convert them to smaller size and save them on disk
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void formPI_DoWork_GenerateSitePosters(FrmProgressIndicator sender, DoWorkEventArgs e)
        {
            var args = (BgwArgument_Work)e.Argument;
            var errorsWhileSaving = new List <TechnicalDetailsImportError>();

            var i = 0;

            foreach (var movieShortInfo in args.MSI)
            {
                if (sender.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                i++;
                sender.SetProgress(i, Path.GetFileName(movieShortInfo.FileName));

                if (!movieShortInfo.HasPoster)
                {
                    continue;
                }

                var fileName = Path.Combine(args.SiteGenLocation, string.Format("Imgs\\{0}\\poster-{1}.jpg", args.SubFolder, movieShortInfo.Id));
                if (File.Exists(fileName))
                {
                    continue;                        //?? wasn't it excluded before this ?
                }
                try
                {
                    var cover = Desene.DAL.GetPoster(movieShortInfo.Id);

                    using (var ms = new MemoryStream(cover))
                    {
                        var imgOgj = GraphicsHelpers.CreatePosterThumbnail(250, 388, Image.FromStream(ms));

                        imgOgj.Save(fileName, ImageFormat.Jpeg);
                    }
                }
                catch (Exception ex)
                {
                    errorsWhileSaving.Add(
                        new TechnicalDetailsImportError
                    {
                        FilePath    = movieShortInfo.FileName,
                        ErrorMesage = OperationResult.GetErrorMessage(ex)
                    });
                }
            }

            e.Result = errorsWhileSaving;
        }
예제 #3
0
        public static OperationResult CreateCatalog(PdfGenParams pdfGenParams)
        {
            var result = new OperationResult();

            try
            {
                var toBeProcessedCount = Desene.DAL.GetCount(pdfGenParams.ForMovies, pdfGenParams.PDFGenType);

                var document = new Document();
                document.Info.Title  = "Movies Catalog";
                document.Info.Author = "Calin Marinescu";

                var formProgressIndicator = new FrmProgressIndicator("Movies Catalog generator", "Loading, please wait ...", toBeProcessedCount);
                formProgressIndicator.Argument = new KeyValuePair <Document, PdfGenParams>(document, pdfGenParams);
                formProgressIndicator.DoWork  += formPI_DoWork_GenerateMoviesCatalog;

                switch (formProgressIndicator.ShowDialog())
                {
                case DialogResult.Cancel:
                    result.Success            = false;
                    result.CustomErrorMessage = "Operation has been canceled";

                    return(result);

                case DialogResult.Abort:
                    result.Success            = false;
                    result.CustomErrorMessage = formProgressIndicator.Result.Error.Message;

                    return(result);

                case DialogResult.OK:
                    //var fillDoc = (Document)formProgressIndicator.Result.Result;
                    //MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "d:\\MigraDoc.pdf");

                    var pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
                    pdfRenderer.Document = document;
                    pdfRenderer.RenderDocument();

                    pdfRenderer.PdfDocument.Save(pdfGenParams.FileName);

                    break;
                }
            }
            catch (Exception ex)
            {
                return(result.FailWithMessage(ex));
            }

            return(result);
        }
예제 #4
0
        private static void formPI_DoWork_ImportCommonSenseMedia(FrmProgressIndicator sender, DoWorkEventArgs e)
        {
            var moviesData = (List <SynopsisImportMovieData>)e.Argument;

            var technicalDetailsImportErrorBgw = new List <TechnicalDetailsImportError>();

            var i = 0;

            foreach (var movieData in moviesData)
            {
                if (sender.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                var opRes = GetCommonSenseMediaData(movieData.DescriptionLink);

                if (!opRes.Success)
                {
                    technicalDetailsImportErrorBgw.Add(
                        new TechnicalDetailsImportError
                    {
                        FilePath    = movieData.DescriptionLink,
                        ErrorMesage = opRes.CustomErrorMessage
                    });
                }
                else
                {
                    //immediate save
                    opRes = Desene.DAL.SaveCommonSenseMediaData(movieData.MovieId, (CSMScrapeResult)opRes.AdditionalDataReturn);

                    if (!opRes.Success)
                    {
                        technicalDetailsImportErrorBgw.Add(
                            new TechnicalDetailsImportError
                        {
                            FilePath    = movieData.DescriptionLink,
                            ErrorMesage = opRes.CustomErrorMessage
                        });
                    }
                }

                i++;

                sender.SetProgress(i, Path.GetFileName(movieData.FileName));
            }

            e.Result = technicalDetailsImportErrorBgw;
        }
예제 #5
0
        /*
         * public static OperationResult ImportSynopsis()
         * {
         *  var result = new OperationResult();
         *
         *  var dlgResult =
         *      MsgBox.Show("Do you want to preserve existing data?", "Confirmation", MessageBoxButtons.YesNoCancel,
         *          MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
         *
         *  if (dlgResult == DialogResult.Cancel)
         *  {
         *      result.AdditionalDataReturn = -1;
         *      return result;
         *  }
         *
         *  var opRes = Desene.DAL.GetMoviesForSynopsisImport(dlgResult == DialogResult.Yes);
         *  if (!opRes.Success)
         *      return opRes;
         *
         *  var moviesData = (List<SynopsisImportMovieData>)opRes.AdditionalDataReturn;
         *  if (moviesData == null || !moviesData.Any())
         *      return result.FailWithMessage("Existing movies data incorrectly determined!");
         *
         *  var importResult = new List<SynopsisImportMovieData>();
         *
         *  foreach (var movieData in moviesData)
         *  {
         *      opRes = GetSynopsis(movieData.DescriptionLink);
         *      if (!opRes.Success)
         *      {
         *          movieData.SkipReason = opRes.CustomErrorMessage;
         *          importResult.Add(movieData);
         *      }
         *      else
         *      {
         *          movieData.Synopsis = (string)opRes.AdditionalDataReturn;
         *          importResult.Add(movieData);
         *      }
         *  }
         *
         *  return result;
         * }
         */

        #region Synopsis

        public static OperationResult ImportSynopsis(bool preserveExisting)
        {
            var result = new OperationResult();

            try
            {
                var opRes = Desene.DAL.GetMoviesForSynopsisImport(preserveExisting);
                if (!opRes.Success)
                {
                    return(opRes);
                }

                var moviesData = (List <SynopsisImportMovieData>)opRes.AdditionalDataReturn;

                var formProgressIndicator = new FrmProgressIndicator("Synopsis Import", "Loading, please wait ...", moviesData.Count);
                formProgressIndicator.Argument = moviesData;
                formProgressIndicator.DoWork  += formPI_DoWork_ImportSynopsis;

                switch (formProgressIndicator.ShowDialog())
                {
                case DialogResult.Cancel:
                    result.Success            = false;
                    result.CustomErrorMessage = "Operation has been canceled";

                    return(result);

                case DialogResult.Abort:
                    result.Success            = false;
                    result.CustomErrorMessage = formProgressIndicator.Result.Error.Message;

                    return(result);

                case DialogResult.OK:
                    result.AdditionalDataReturn = formProgressIndicator.Result.Result;

                    break;
                }
            }
            catch (Exception ex)
            {
                return(result.FailWithMessage(ex));
            }

            return(result);
        }
예제 #6
0
        /// <summary>
        /// Checks the thumbnail existence on disk and if found, it set the thumbnail presence marker (into the current loaded lists)
        /// Fires when no thumbnail generation is made, but the user opt in for existing thumbnail preservation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void formPI_DoWork_GenerateSiteMovies_Thumbnails2(FrmProgressIndicator sender, DoWorkEventArgs e)
        {
            var args = (BgwArgument_Work)e.Argument;
            var errorsWhileSaving = new List <TechnicalDetailsImportError>();

            var path = Path.Combine(args.SiteGenLocation, string.Format("Imgs\\{0}\\Thumbnails\\", args.SubFolder));

            var i = 0;

            foreach (var movieShortInfo in args.MSI)
            {
                if (sender.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                i++;
                sender.SetProgress(i, Path.GetFileName(movieShortInfo.FileName));

                try
                {
                    var fnPattern = string.Format("thumb-{0}-*.jpg", movieShortInfo.Id);

                    if (Directory.EnumerateFiles(path, fnPattern).Any())
                    {
                        movieShortInfo.ThumbnailGenerated = true;
                    }
                }
                catch (Exception ex)
                {
                    errorsWhileSaving.Add(
                        new TechnicalDetailsImportError
                    {
                        FilePath    = movieShortInfo.FileName,
                        ErrorMesage = OperationResult.GetErrorMessage(ex)
                    });
                }
            }

            e.Result = errorsWhileSaving;
        }
예제 #7
0
        private static void formPI_DoWork_GenerateMoviesCatalog(FrmProgressIndicator sender, DoWorkEventArgs e)
        {
            var catalogGenDet = (KeyValuePair <Document, PdfGenParams>)e.Argument;
            var document      = catalogGenDet.Key;
            var pdfGenParams  = catalogGenDet.Value;

            var movies = Desene.DAL.GetMoviesForPDF(pdfGenParams);

            //var style = document.Styles["Normal"];
            //style.Font.Name = "Arial Narrow";
            //style.Font.Size = 10;

            var section = document.AddSection();

            section.PageSetup.PageFormat    = PageFormat.A4;
            section.PageSetup.MirrorMargins = true;
            section.PageSetup.TopMargin     = Unit.FromCentimeter(0.5);
            section.PageSetup.BottomMargin  = Unit.FromCentimeter(0.5);
            section.PageSetup.LeftMargin    = Unit.FromCentimeter(2);
            section.PageSetup.RightMargin   = Unit.FromCentimeter(1);

            var table = section.AddTable();

            var sectionWidth =
                (int)document.DefaultPageSetup.PageWidth -
                (int)section.PageSetup.LeftMargin -
                (int)section.PageSetup.RightMargin;

            var columnWidth = sectionWidth / 4;

            var column = table.AddColumn();

            column.Width = columnWidth;
            var column2 = table.AddColumn();

            column2.Width = columnWidth;
            var column3 = table.AddColumn();

            column3.Width = columnWidth;
            var column4 = table.AddColumn();

            column4.Width = columnWidth;

            Row row = null;

            var indexPos = 0;

            for (var i = 0; i < movies.Count; i += 4)
            {
                if (sender.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                row = table.AddRow();

                for (var j = 0; j < 4; j++)
                {
                    var k = i + j;
                    if (k >= movies.Count)
                    {
                        break;
                    }

                    var movieObj = movies[k];

                    indexPos++;
                    sender.SetProgress(indexPos, movieObj.FN);

                    var imgOgj = GraphicsHelpers.CreatePosterThumbnailForPDF(150, 232, movieObj.Cover, movieObj.R, movieObj.A,
                                                                             pdfGenParams.PDFGenType == PDFGenType.All
                            ? movieObj.T == "Craciun"
                                ? Properties.Resources.Christmas_Tree_icon
                                : movieObj.T == "Helloween"
                                    ? Properties.Resources.Pumpkin_icon
                                    : null
                            : null);

                    row.Cells[j].Format.Alignment  = ParagraphAlignment.Center;
                    row.Cells[j].VerticalAlignment = VerticalAlignment.Center;
                    row.Cells[j].AddParagraph().AddImage(MigraDocFilenameFromByteArray(imgOgj));
                }

                row = table.AddRow();

                for (var j = 0; j < 4; j++)
                {
                    var k = i + j;
                    if (k >= movies.Count)
                    {
                        break;
                    }

                    var movieObj = movies[k];

                    var dataTable = new Table();
                    var columnD1  = dataTable.AddColumn();
                    columnD1.Width = columnWidth;

                    var rowD1 = dataTable.AddRow();
                    rowD1.Cells[0].Format.Alignment = ParagraphAlignment.Center;
                    rowD1.Cells[0].Format.Font.Name = "Arial Narrow";
                    rowD1.Cells[0].Format.Font.Size = 10;

                    var tm = new TextMeasurement(rowD1.Cells[0].Format.Font);
                    //var strWidth = tm.MeasureString(movieObj.FN).Width;

                    var movieTitle = movieObj.FN;
                    var lineCount  = tm.GetSplittedLineCount(movieTitle, columnWidth, null);

                    if (lineCount > 2)
                    {
                        movieTitle = tm.GetStringWithEllipsis(movieObj.FN, columnWidth, 2);
                    }

                    rowD1.Cells[0].AddParagraph(movieTitle);

                    row.Cells[j].Elements.Add(dataTable);
                }
            }

            //e.Result = document;
        }
예제 #8
0
        private static OperationResult SaveThumbnails(SiteGenParams siteGenParams, List <MovieShortInfo> data, string subFolder)
        {
            var result   = new OperationResult();
            var imgsPath = Path.Combine(siteGenParams.Location, "Imgs", subFolder, "Thumbnails");

            if (siteGenParams.SaveEpisodesThumbnals)
            {
                var existingThumbnailsForIds = new List <int>();

                if (!Directory.Exists(imgsPath))
                {
                    Directory.CreateDirectory(imgsPath);
                }
                else
                {
                    var d     = new DirectoryInfo(imgsPath);
                    var Files = d.GetFiles("*.jpg");

                    foreach (FileInfo file in Files)
                    {
                        var id = int.Parse(file.Name.Split('-')[1]);
                        if (!existingThumbnailsForIds.Contains(id))
                        {
                            existingThumbnailsForIds.Add(id);
                        }
                    }
                }

                var thumbnailsToSave = new List <MovieShortInfo>(data.Where(x => !existingThumbnailsForIds.Contains(x.Id) && x.HasThumbnails)); // && x.ThumbnailGenerated --> this is NOT "HasThumbnails"

                if (thumbnailsToSave.Any())
                {
                    var formProgressIndicator = new FrmProgressIndicator(string.Format("Site generation - {0} thumbnails", subFolder), "-", thumbnailsToSave.Count);
                    formProgressIndicator.Argument =
                        new BgwArgument_Work
                    {
                        SiteGenLocation = siteGenParams.Location,
                        SubFolder       = subFolder,
                        MSI             = thumbnailsToSave
                    };

                    formProgressIndicator.DoWork += formPI_DoWork_GenerateSiteMovies_Thumbnails;

                    switch (formProgressIndicator.ShowDialog())
                    {
                    case DialogResult.Cancel:
                        result.Success            = false;
                        result.CustomErrorMessage = "Operation has been canceled";

                        return(result);

                    case DialogResult.Abort:
                        result.Success            = false;
                        result.CustomErrorMessage = formProgressIndicator.Result.Error.Message;

                        return(result);

                    case DialogResult.OK:
                        result.AdditionalDataReturn = formProgressIndicator.Result.Result;
                        break;
                    }
                }

                //setting the marker for all previous existing thumbnails
                foreach (var msi in data.Where(x => existingThumbnailsForIds.Contains(x.Id)))
                {
                    msi.ThumbnailGenerated = true;
                }
            }
            else
            if (siteGenParams.PreserveMarkesForExistingThumbnails && Directory.Exists(imgsPath))
            {
                var formProgressIndicator = new FrmProgressIndicator("Setting the movies thumbnails marker from existing files", "-", data.Count);
                formProgressIndicator.Argument =
                    new BgwArgument_Work
                {
                    SiteGenLocation = siteGenParams.Location,
                    SubFolder       = subFolder,
                    MSI             = data
                };

                formProgressIndicator.DoWork += formPI_DoWork_GenerateSiteMovies_Thumbnails2;

                switch (formProgressIndicator.ShowDialog())
                {
                case DialogResult.Cancel:
                    result.Success            = false;
                    result.CustomErrorMessage = "Operation has been canceled";

                    return(result);

                case DialogResult.Abort:
                    result.Success            = false;
                    result.CustomErrorMessage = formProgressIndicator.Result.Error.Message;

                    return(result);

                case DialogResult.OK:
                    result.AdditionalDataReturn = formProgressIndicator.Result.Result;
                    break;
                }
            }

            return(result);
        }
예제 #9
0
        private static OperationResult SavePosters(string siteGenLocation, List <MovieShortInfo> data, string subFolder)
        {
            var result = new OperationResult();

            var imgsPath = Path.Combine(siteGenLocation, "Imgs", subFolder);
            var existingPostersForIds = new List <int>();

            if (!Directory.Exists(imgsPath))
            {
                Directory.CreateDirectory(imgsPath);
            }
            else
            {
                var d     = new DirectoryInfo(imgsPath);
                var Files = d.GetFiles("*.jpg");

                foreach (FileInfo file in Files)
                {
                    var id = int.Parse(file.Name.Split('-', '.')[1]);
                    if (!existingPostersForIds.Contains(id))
                    {
                        existingPostersForIds.Add(id);
                    }
                }
            }

            var postersToSave = new List <MovieShortInfo>(data.Where(x => !existingPostersForIds.Contains(x.Id) && x.HasPoster));

            if (postersToSave.Any())
            {
                var formProgressIndicator = new FrmProgressIndicator(string.Format("Site generation - {0} posters", subFolder), "-", postersToSave.Count);
                formProgressIndicator.Argument =
                    new BgwArgument_Work
                {
                    SiteGenLocation = siteGenLocation,
                    SubFolder       = subFolder,
                    MSI             = postersToSave
                };

                formProgressIndicator.DoWork += formPI_DoWork_GenerateSitePosters;

                switch (formProgressIndicator.ShowDialog())
                {
                case DialogResult.Cancel:
                    result.Success            = false;
                    result.CustomErrorMessage = "Operation has been canceled";

                    return(result);

                case DialogResult.Abort:
                    result.Success            = false;
                    result.CustomErrorMessage = formProgressIndicator.Result.Error.Message;

                    return(result);

                case DialogResult.OK:
                    result.AdditionalDataReturn = formProgressIndicator.Result.Result;
                    break;
                }
            }

            return(result);
        }