Exemplo n.º 1
0
        public static OperationResult GetSynopsis(string descriptionLink)
        {
            var result = new OperationResult();

            using (var client = new HttpClient())
            {
                try
                {
                    //the implementation if forced to run synchronous to avoid ip banning from scrapped sites
                    var request = client.GetAsync(descriptionLink).Result;
                    request.EnsureSuccessStatusCode();

                    if (request.Content == null)
                    {
                        result.FailWithMessage("No content");
                    }

                    var response = request.Content.ReadAsStreamAsync().Result;

                    if (response == null || response.Length == 0)
                    {
                        return(result.FailWithMessage("Invalid response!"));
                    }

                    result.AdditionalDataReturn = ExtractSynopsisFromDocument(descriptionLink, response);
                }
                catch (Exception ex)
                {
                    return(result.FailWithMessage(ex));
                }
            }

            return(result);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public static OperationResult ConvertThemeToEnum()
        {
            var result = new OperationResult();

            using (var conn = new SqlCeConnection(Constants.ConnectionString))
            {
                conn.Open();
                var tx = conn.BeginTransaction();

                try
                {
                    try
                    {
                        var updateSQL = @"
                            UPDATE FileDetail
                               SET Theme =
                                CASE Theme
                                    WHEN 'Craciun' THEN 1
                                    WHEN 'Helloween' THEN 2
                                    WHEN 'Iarna' THEN 3
                                    WHEN 'Pasti' THEN 4
                                    WHEN 'Sinterklass' THEN 5
                                    WHEN 'Valentine''s day' THEN 6
                                    ELSE 0
	                            END"    ;

                        //var cmd = new SqlCeCommand(updateSQL, conn);
                        //cmd.ExecuteNonQuery();
                        using (var cmd = new SqlCeCommand(updateSQL, conn))
                            cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();
                        return(result.FailWithMessage(ex));
                    }
                }
                finally
                {
                    tx.Commit();
                }
            }

            return(result);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public static OperationResult ImportSeriale()
        {
            var result = new OperationResult();

            try
            {
                var connDest   = new SqlCeConnection(Constants.ConnectionString);
                var connSource = new SqlCeConnection("Data Source = Desene.sdf;Max Database Size=4091;Persist Security Info=False");

                connDest.Open();
                connSource.Open();

                const string insertString =
                    @"
                    INSERT INTO FileDetail (
                        ParentId,
                        FileName,
                        Year,
                        Theme,
                        Season,
                        InsertedDate,
                        LastChangeDate,
                        Recommended,
                        RecommendedLink,
                        DescriptionLink,
                        Poster,
                        Notes)
                    VALUES (
                        @ParentId,
                        @FileName,
                        @Year,
                        @Theme,
                        @Season,
                        @InsertedDate,
                        @LastChangeDate,
                        @Recommended,
                        @RecommendedLink,
                        @DescriptionLink,
                        @Poster,
                        @Notes)";

                try
                {
                    var commandSource = new SqlCeCommand("select * from Seriale", connSource);

                    using (var reader = commandSource.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (string.IsNullOrEmpty(reader["Titlu"].ToString()))
                            {
                                continue;
                            }

                            var cmd = new SqlCeCommand(insertString, connDest)
                            {
                                CommandType = CommandType.Text
                            };
                            cmd.Parameters.AddWithValue("@ParentId", -1);
                            cmd.Parameters.AddWithValue("@FileName", reader["Titlu"].ToString());
                            cmd.Parameters.AddWithValue("@Theme", string.Empty);
                            cmd.Parameters.AddWithValue("@Year", string.Empty);
                            cmd.Parameters.AddWithValue("@Season", string.Empty);

                            if (!(reader["DataAdaugare"] is DBNull))
                            {
                                cmd.Parameters.AddWithValue("@InsertedDate", (DateTime)reader["DataAdaugare"]);
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@InsertedDate", DBNull.Value);
                            }

                            if (!(reader["DataUM"] is DBNull))
                            {
                                cmd.Parameters.AddWithValue("@LastChangeDate", (DateTime)reader["DataUM"]);
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@LastChangeDate", DBNull.Value);
                            }

                            cmd.Parameters.AddWithValue("@Recommended", reader["Recomandat"].ToString());
                            cmd.Parameters.AddWithValue("@RecommendedLink", reader["RecomandatLink"].ToString() != "0" ? reader["RecomandatLink"].ToString() : string.Empty);
                            cmd.Parameters.AddWithValue("@DescriptionLink", reader["MoreInfo"].ToString());
                            cmd.Parameters.AddWithValue("@Notes", reader["Obs"].ToString());

                            if (!(reader["Cover"] is DBNull))
                            {
                                cmd.Parameters.AddWithValue("@Poster", (byte[])reader["Cover"]);
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@Poster", DBNull.Value);
                            }


                            cmd.ExecuteNonQuery();
                            cmd.CommandText = "Select @@Identity";
                            var seriesId = (int)(decimal)cmd.ExecuteScalar();

                            var commandSource2 = new SqlCeCommand("select * from Episoade where SerialId = " + reader["Id"], connSource);

                            using (var readerEp = commandSource2.ExecuteReader())
                            {
                                while (readerEp.Read())
                                {
                                    var cmdEp = new SqlCeCommand(insertString, connDest)
                                    {
                                        CommandType = CommandType.Text
                                    };
                                    cmdEp.Parameters.AddWithValue("@ParentId", seriesId);
                                    cmdEp.Parameters.AddWithValue("@FileName", readerEp["Titlu"].ToString());
                                    cmdEp.Parameters.AddWithValue("@Year", readerEp["An"].ToString());
                                    cmdEp.Parameters.AddWithValue("@Theme", readerEp["Tematica"].ToString());
                                    cmdEp.Parameters.AddWithValue("@Season", readerEp["Sezon"].ToString());

                                    if (!(readerEp["DataAdaugare"] is DBNull))
                                    {
                                        cmdEp.Parameters.AddWithValue("@InsertedDate", (DateTime)readerEp["DataAdaugare"]);
                                    }
                                    else
                                    {
                                        cmdEp.Parameters.AddWithValue("@InsertedDate", DBNull.Value);
                                    }

                                    if (!(readerEp["DataUM"] is DBNull))
                                    {
                                        cmdEp.Parameters.AddWithValue("@LastChangeDate", (DateTime)readerEp["DataUM"]);
                                    }
                                    else
                                    {
                                        cmdEp.Parameters.AddWithValue("@LastChangeDate", DBNull.Value);
                                    }

                                    cmdEp.Parameters.AddWithValue("@Recommended", DBNull.Value);
                                    cmdEp.Parameters.AddWithValue("@RecommendedLink", DBNull.Value);
                                    cmdEp.Parameters.AddWithValue("@DescriptionLink", DBNull.Value);
                                    cmdEp.Parameters.AddWithValue("@Notes", DBNull.Value);
                                    cmdEp.Parameters.AddWithValue("@Poster", DBNull.Value);

                                    cmdEp.ExecuteNonQuery();
                                }
                            }
                        }
                    }
                }
                finally
                {
                    connDest.Close();
                    connSource.Close();
                }
            }
            catch (Exception e)
            {
                result.FailWithMessage(e);
            }

            return(result);
        }
Exemplo n.º 6
0
        /*
         * public static OperationResult ImportFilmeHD()
         * {
         *  var result = new OperationResult();
         *
         *  try
         *  {
         *      var connDest = new SqlCeConnection(Constants.ConnectionString);
         *      var connSource = new SqlCeConnection("Data Source = Desene.sdf;Persist Security Info=False");
         *      connDest.Open();
         *      connSource.Open();
         *
         *      const string insertString =
         *          @"
         *          INSERT INTO MovieOrSeries (
         *              Recommended,
         *              RecommendedLink,
         *              DescriptionLink,
         *              Poster,
         *              IsSerie,
         *              Notes)
         *          VALUES (
         *              @Recommended,
         *              @RecommendedLink,
         *              @DescriptionLink,
         *              @Poster,
         *              @IsSerie,
         *              @Notes)";
         *
         *      const string insertString2 =
         *          @"
         *          INSERT INTO FileDetail (
         *              MovieOrSeriesId,
         *              FileName,
         *              Year,
         *              Theme,
         *              InsertedDate,
         *              LastChangeDate)
         *          VALUES (
         *              @MovieOrSeriesId,
         *              @FileName,
         *              @Year,
         *              @Theme,
         *              @InsertedDate,
         *              @LastChangeDate)";
         *
         *      //var sr =  File.CreateText("googllinks.txt");
         *      var googleUrls = File.ReadAllLines(@"goo.gl to long url.csv")
         *                           .Select(ShortToLongUrl.FromCsv)
         *                           .ToList();
         *
         *      var urlSLErrors = "";
         *
         *      try
         *      {
         *          var commandSource = new SqlCeCommand("select * from Filme", connSource);
         *
         *          using (var reader = commandSource.ExecuteReader())
         *          {
         *              while (reader.Read())
         *              {
         *                  if (string.IsNullOrEmpty(reader["Titlu"].ToString())) continue;
         *
         *                  var cmd = new SqlCeCommand(insertString, connDest) { CommandType = CommandType.Text };
         *
         *                  cmd.Parameters.AddWithValue("@Recommended", reader["Recomandat"].ToString());
         *                  cmd.Parameters.AddWithValue("@RecommendedLink", reader["RecomandatLink"].ToString() != "0" ?  reader["RecomandatLink"].ToString() : string.Empty);
         *                  cmd.Parameters.AddWithValue("@IsSerie", false);
         *                  cmd.Parameters.AddWithValue("@Notes", reader["Obs"].ToString());
         *                  //cmd.Parameters.AddWithValue("@DescriptionLink", reader["MoreInfo"].ToString() != "0" ?  reader["MoreInfo"].ToString() : string.Empty);
         *
         *
         *                  if (reader["MoreInfo"].ToString() == "0" || string.IsNullOrEmpty(reader["MoreInfo"].ToString()))
         *                  {
         *                      cmd.Parameters.AddWithValue("@DescriptionLink", string.Empty);
         *                  }
         *                  else
         *                  {
         *                      if (reader["MoreInfo"].ToString().Contains("goo.gl"))
         *                      {
         *                          var shortUrl = reader["MoreInfo"].ToString().Replace("#", "");
         *                          var longUrlObj = googleUrls.FirstOrDefault(s => s.ShortUrl == shortUrl);
         *
         *                          if (longUrlObj == null)
         *                          {
         *                              cmd.Parameters.AddWithValue("@DescriptionLink", reader["MoreInfo"].ToString());
         *                              urlSLErrors += reader["Id"].ToString() + ", ";
         *                          }
         *                          else
         *                          {
         *                              cmd.Parameters.AddWithValue("@DescriptionLink", longUrlObj.LongUrl);
         *                          }
         *
         *                          //sr.WriteLine(reader["MoreInfo"].ToString().Replace("#", ""));
         *                      }
         *                      else
         *                      {
         *                          cmd.Parameters.AddWithValue("@DescriptionLink", reader["MoreInfo"].ToString());
         *                      }
         *                  }
         *
         *                  if (!(reader["Cover"] is DBNull))
         *                      cmd.Parameters.AddWithValue("@Poster", (byte[])reader["Cover"]);
         *                  else
         *                      cmd.Parameters.AddWithValue("@Poster", DBNull.Value);
         *
         *
         *                  cmd.ExecuteNonQuery();
         *
         *
         *                  cmd.CommandText = "Select @@Identity";
         *                  var newId = (int)(decimal)cmd.ExecuteScalar();
         *
         *                  cmd = new SqlCeCommand(insertString2, connDest) { CommandType = CommandType.Text };
         *                  cmd.Parameters.AddWithValue("@MovieOrSeriesId", newId);
         *                  cmd.Parameters.AddWithValue("@FileName", reader["Titlu"].ToString());
         *                  cmd.Parameters.AddWithValue("@Year", reader["An"].ToString());
         *                  cmd.Parameters.AddWithValue("@Theme", reader["Tematica"].ToString());
         *
         *                  if (!(reader["DataAdaugare"] is DBNull))
         *                      cmd.Parameters.AddWithValue("@InsertedDate", (DateTime)reader["DataAdaugare"]);
         *                  else
         *                      cmd.Parameters.AddWithValue("@InsertedDate", DBNull.Value);
         *
         *                  if (!(reader["DataUM"] is DBNull))
         *                      cmd.Parameters.AddWithValue("@LastChangeDate", (DateTime)reader["DataUM"]);
         *                  else
         *                      cmd.Parameters.AddWithValue("@LastChangeDate", DBNull.Value);
         *
         *                  cmd.ExecuteNonQuery();
         *              }
         *          }
         *      }
         *      finally
         *      {
         *          connDest.Close();
         *          connSource.Close();
         *
         *          //sr.Close();
         *      }
         *  }
         *  catch (Exception e)
         *  {
         *      result.FailWithMessage(e);
         *  }
         *
         *  return result;
         * }
         *
         * public static OperationResult ImportSeriale()
         * {
         *  var result = new OperationResult();
         *
         *  try
         *      {
         *      var connDest = new SqlCeConnection(Constants.ConnectionString);
         *      var connSource = new SqlCeConnection("Data Source = Desene.sdf;Persist Security Info=False");
         *
         *      connDest.Open();
         *      connSource.Open();
         *
         *      const string insertString =
         *          @"
         *          INSERT INTO MovieOrSeries (
         *              Recommended,
         *              RecommendedLink,
         *              DescriptionLink,
         *              Poster,
         *              IsSerie,
         *              Notes)
         *          VALUES (
         *              @Recommended,
         *              @RecommendedLink,
         *              @DescriptionLink,
         *              @Poster,
         *              @IsSerie,
         *              @Notes)";
         *
         *      const string insertString2 =
         *          @"
         *          INSERT INTO FileDetail (
         *              MovieOrSeriesId,
         *              ParentId,
         *              FileName,
         *              Year,
         *              Theme,
         *              Season,
         *              InsertedDate,
         *              LastChangeDate)
         *          VALUES (
         *              @MovieOrSeriesId,
         *              @ParentId,
         *              @FileName,
         *              @Year,
         *              @Theme,
         *              @Season,
         *              @InsertedDate,
         *              @LastChangeDate)";
         *
         *      try
         *      {
         *          var commandSource = new SqlCeCommand("select * from Seriale", connSource);
         *
         *          using (var reader = commandSource.ExecuteReader())
         *          {
         *              while (reader.Read())
         *              {
         *                  if (string.IsNullOrEmpty(reader["Titlu"].ToString())) continue;
         *
         *                  var cmd = new SqlCeCommand(insertString, connDest) { CommandType = CommandType.Text };
         *
         *                  cmd.Parameters.AddWithValue("@Recommended", reader["Recomandat"].ToString());
         *                  cmd.Parameters.AddWithValue("@RecommendedLink", reader["RecomandatLink"].ToString() != "0" ?  reader["RecomandatLink"].ToString() : string.Empty);
         *                  cmd.Parameters.AddWithValue("@DescriptionLink", reader["MoreInfo"].ToString());
         *                  cmd.Parameters.AddWithValue("@IsSerie", true);
         *                  cmd.Parameters.AddWithValue("@Notes", reader["Obs"].ToString());
         *
         *                  if (!(reader["Cover"] is DBNull))
         *                      cmd.Parameters.AddWithValue("@Poster", (byte[])reader["Cover"]);
         *                  else
         *                      cmd.Parameters.AddWithValue("@Poster", DBNull.Value);
         *
         *
         *                  cmd.ExecuteNonQuery();
         *
         *                  cmd.CommandText = "Select @@Identity";
         *                  var newId = (int)(decimal)cmd.ExecuteScalar();
         *
         *                  cmd = new SqlCeCommand(insertString2, connDest) { CommandType = CommandType.Text };
         *                  cmd.Parameters.AddWithValue("@MovieOrSeriesId", newId);
         *                  cmd.Parameters.AddWithValue("@ParentId", -1);
         *                  cmd.Parameters.AddWithValue("@FileName", reader["Titlu"].ToString());
         *                  cmd.Parameters.AddWithValue("@Theme", string.Empty);
         *                  cmd.Parameters.AddWithValue("@Year", string.Empty);
         *                  cmd.Parameters.AddWithValue("@Season", string.Empty);
         *
         *                  if (!(reader["DataAdaugare"] is DBNull))
         *                      cmd.Parameters.AddWithValue("@InsertedDate", (DateTime)reader["DataAdaugare"]);
         *                  else
         *                      cmd.Parameters.AddWithValue("@InsertedDate", DBNull.Value);
         *
         *                  if (!(reader["DataUM"] is DBNull))
         *                      cmd.Parameters.AddWithValue("@LastChangeDate", (DateTime)reader["DataUM"]);
         *                  else
         *                      cmd.Parameters.AddWithValue("@LastChangeDate", DBNull.Value);
         *
         *
         *                  cmd.ExecuteNonQuery();
         *                  cmd.CommandText = "Select @@Identity";
         *                  var newId2 = (int)(decimal)cmd.ExecuteScalar();
         *
         *                  var commandSource2 = new SqlCeCommand("select * from Episoade where SerialId = " + reader["Id"], connSource);
         *
         *                  using (var readerEp = commandSource2.ExecuteReader())
         *                  {
         *                      while (readerEp.Read())
         *                      {
         *                          var cmdEp = new SqlCeCommand(insertString2, connDest) { CommandType = CommandType.Text };
         *                          cmdEp.Parameters.AddWithValue("@MovieOrSeriesId", newId);
         *                          cmdEp.Parameters.AddWithValue("@ParentId", newId2);
         *                          cmdEp.Parameters.AddWithValue("@FileName", readerEp["Titlu"].ToString());
         *                          cmdEp.Parameters.AddWithValue("@Year", readerEp["An"].ToString());
         *                          cmdEp.Parameters.AddWithValue("@Theme", readerEp["Tematica"].ToString());
         *                          cmdEp.Parameters.AddWithValue("@Season", readerEp["Sezon"].ToString());
         *
         *                          if (!(readerEp["DataAdaugare"] is DBNull))
         *                              cmdEp.Parameters.AddWithValue("@InsertedDate", (DateTime)readerEp["DataAdaugare"]);
         *                          else
         *                              cmdEp.Parameters.AddWithValue("@InsertedDate", DBNull.Value);
         *
         *                          if (!(readerEp["DataUM"] is DBNull))
         *                              cmdEp.Parameters.AddWithValue("@LastChangeDate", (DateTime)readerEp["DataUM"]);
         *                          else
         *                              cmdEp.Parameters.AddWithValue("@LastChangeDate", DBNull.Value);
         *
         *
         *                          cmdEp.ExecuteNonQuery();
         *                      }
         *                  }
         *              }
         *          }
         *      }
         *      finally
         *      {
         *          connDest.Close();
         *          connSource.Close();
         *      }
         *  }
         *  catch (Exception e)
         *  {
         *      result.FailWithMessage(e);
         *  }
         *
         *  return result;
         * }
         */

        public static OperationResult ImportFilmeHD()
        {
            var result = new OperationResult();

            try
            {
                var connDest   = new SqlCeConnection(Constants.ConnectionString);
                var connSource = new SqlCeConnection("Data Source = Desene.sdf;Max Database Size=4091;Persist Security Info=False");
                connDest.Open();
                connSource.Open();

                const string insertString =
                    @"
                    INSERT INTO FileDetail (
                        FileName,
                        Year,
                        Theme,
                        InsertedDate,
                        LastChangeDate,
                        Recommended,
                        RecommendedLink,
                        DescriptionLink,
                        Poster,
                        Trailer,
                        Notes,
                        NlAudioSource)
                    VALUES (
                        @FileName,
                        @Year,
                        @Theme,
                        @InsertedDate,
                        @LastChangeDate,
                        @Recommended,
                        @RecommendedLink,
                        @DescriptionLink,
                        @Poster,
                        @Trailer,
                        @Notes,
                        @NlAudioSource)";

                //var sr =  File.CreateText("googllinks.txt");
                var googleUrls = File.ReadAllLines(@"goo.gl to long url.csv")
                                 .Select(ShortToLongUrl.FromCsv)
                                 .ToList();

                var urlSLErrors = "";

                try
                {
                    var commandSource = new SqlCeCommand("select * from Filme", connSource);

                    using (var reader = commandSource.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (string.IsNullOrEmpty(reader["Titlu"].ToString()))
                            {
                                continue;
                            }

                            var cmd = new SqlCeCommand(insertString, connDest)
                            {
                                CommandType = CommandType.Text
                            };
                            var titluCorectat = reader["Titlu"].ToString().Replace(": ", " - ");
                            cmd.Parameters.AddWithValue("@FileName", titluCorectat);
                            cmd.Parameters.AddWithValue("@Year", reader["An"].ToString());
                            cmd.Parameters.AddWithValue("@Theme", reader["Tematica"].ToString());

                            if (!(reader["DataAdaugare"] is DBNull))
                            {
                                cmd.Parameters.AddWithValue("@InsertedDate", (DateTime)reader["DataAdaugare"]);
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@InsertedDate", DBNull.Value);
                            }

                            if (!(reader["DataUM"] is DBNull))
                            {
                                cmd.Parameters.AddWithValue("@LastChangeDate", (DateTime)reader["DataUM"]);
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@LastChangeDate", DBNull.Value);
                            }

                            cmd.Parameters.AddWithValue("@Recommended", reader["Recomandat"].ToString());
                            cmd.Parameters.AddWithValue("@RecommendedLink", reader["RecomandatLink"].ToString() != "0" ? reader["RecomandatLink"].ToString() : string.Empty);

                            var obsList = new List <string>
                            {
                                reader["Obs"].ToString().Trim(),
                                reader["Obs2"].ToString().Trim(),
                                reader["Obs3"].ToString().Trim()
                            };
                            obsList.RemoveAll(n => n == string.Empty);

                            var notes = string.Join(Environment.NewLine, obsList);

                            cmd.Parameters.AddWithValue("@Notes", notes);
                            //cmd.Parameters.AddWithValue("@DescriptionLink", reader["MoreInfo"].ToString() != "0" ?  reader["MoreInfo"].ToString() : string.Empty);
                            cmd.Parameters.AddWithValue("@Trailer", reader["Trailer"].ToString());
                            cmd.Parameters.AddWithValue("@NlAudioSource", reader["Nlsource"].ToString());

                            if (reader["MoreInfo"].ToString() == "0" || string.IsNullOrEmpty(reader["MoreInfo"].ToString()))
                            {
                                cmd.Parameters.AddWithValue("@DescriptionLink", string.Empty);
                            }
                            else
                            {
                                if (reader["MoreInfo"].ToString().Contains("goo.gl"))
                                {
                                    var shortUrl   = reader["MoreInfo"].ToString().Replace("#", "");
                                    var longUrlObj = googleUrls.FirstOrDefault(s => s.ShortUrl == shortUrl);

                                    if (longUrlObj == null)
                                    {
                                        cmd.Parameters.AddWithValue("@DescriptionLink", reader["MoreInfo"].ToString());
                                        urlSLErrors += reader["Id"].ToString() + ", ";
                                    }
                                    else
                                    {
                                        cmd.Parameters.AddWithValue("@DescriptionLink", longUrlObj.LongUrl);
                                    }

                                    //sr.WriteLine(reader["MoreInfo"].ToString().Replace("#", ""));
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@DescriptionLink", reader["MoreInfo"].ToString());
                                }
                            }

                            if (!(reader["Cover"] is DBNull))
                            {
                                cmd.Parameters.AddWithValue("@Poster", (byte[])reader["Cover"]);
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@Poster", DBNull.Value);
                            }



                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                finally
                {
                    connDest.Close();
                    connSource.Close();

                    //sr.Close();
                }
            }
            catch (Exception e)
            {
                result.FailWithMessage(e);
            }

            return(result);
        }
Exemplo n.º 7
0
        private OperationResult MixFileNames()
        {
            var result = new OperationResult();

            var translatedFNLine = string.Empty;
            var originalFNLine   = string.Empty;
            var mixLines         = new List <string>();

            try
            {
                var ext = EnumHelpers.GetEnumDescription(_namesMix_Ext);
                var epProcessedList1 = 0;
                var epProcessedList2 = 0;

                foreach (var myString1 in rtbLanguage1.Lines)
                {
                    translatedFNLine = myString1;

                    var charLocation1 = myString1.IndexOf(".", StringComparison.Ordinal);

                    if (charLocation1 == -1)
                    {
                        continue;
                    }

                    var episodeNo1 = myString1.Substring(0, charLocation1);

                    if (!int.TryParse(episodeNo1, out int episodeNoVal1))
                    {
                        continue;
                    }

                    epProcessedList1++;

                    if (rtbLanguage2.Lines.Count() == 0)
                    {
                        var epNo   = episodeNoVal1 < 10 ? string.Format("0{0}", episodeNoVal1) : episodeNoVal1.ToString();
                        var title1 = myString1.Substring((charLocation1 + 1), myString1.Length - (charLocation1 + 1)).Trim();

                        mixLines.Add(
                            string.Format("E{0}{3}{1}{2}",
                                          epNo,
                                          title1,
                                          ext,
                                          EnumHelpers.GetEnumDescription(_namesMix_NameType))
                            );

                        epProcessedList2++;
                    }
                    else
                    {
                        var episodeIn2 = false;

                        foreach (var myString2 in rtbLanguage2.Lines)
                        {
                            originalFNLine = myString2;

                            var charLocation2 = myString2.IndexOf(".", StringComparison.Ordinal);

                            if (charLocation2 == -1)
                            {
                                continue;
                            }

                            var episodeNo2 = myString2.Substring(0, charLocation2);

                            if (episodeNo1 != episodeNo2)
                            {
                                continue;
                            }

                            if (!int.TryParse(episodeNo2, out int episodeNoVal2))
                            {
                                continue;
                            }

                            var epNo   = episodeNoVal2 < 10 ? string.Format("0{0}", episodeNoVal2) : episodeNoVal2.ToString();
                            var title1 = myString1.Substring((charLocation1 + 1), myString1.Length - (charLocation1 + 1)).Trim();
                            var title2 = myString2.Substring((charLocation2 + 1), myString2.Length - (charLocation2 + 1)).Trim();

                            switch (_namesMix_ProcessFN)
                            {
                            case NamesMix_ProcessFN.none:
                                break;

                            case NamesMix_ProcessFN.ToSentenceCase:
                                title1 = title1.ToSentenceCase(true);
                                title2 = title2.ToSentenceCase(true);
                                break;

                            case NamesMix_ProcessFN.ToTitleCase:
                                title1 = title1.ToTitleCase(true);
                                title2 = title2.ToTitleCase(true);
                                break;
                            }

                            mixLines.Add(
                                title1 == title2
                                    ? string.Format("E{0}{3}{1}{2}",
                                                    epNo,
                                                    title1,
                                                    ext,
                                                    EnumHelpers.GetEnumDescription(_namesMix_NameType))
                                    : string.Format("E{0}{4}{1} ({2}){3}",
                                                    epNo,
                                                    title1,
                                                    title2,
                                                    ext,
                                                    EnumHelpers.GetEnumDescription(_namesMix_NameType))
                                );

                            epProcessedList2++;
                            episodeIn2 = true;
                            break;
                        }

                        if (!episodeIn2)
                        {
                            return(result.FailWithMessage(string.Format("The episode {0} could not be found in the 'Original' list!", episodeNo1)));
                        }
                    }
                }

                if (epProcessedList1 != epProcessedList2)
                {
                    return(result.FailWithMessage("The episodes lists do not contain the same amount of episodes!"));
                }

                if (mixLines.Any(s => s.Contains("/") || s.Contains("+")) && _replaceSlashWithAnd == null)
                {
                    _replaceSlashWithAnd =
                        MsgBox.Show("Replace '/' and '+' with '&' ?", "Confirmation",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes;
                }

                var mixReplaceDef = Helpers.GetDefaultMixFileNameReplaceValues();
                mixReplaceDef.Add(new MixFileNameReplaceDef("/", _replaceSlashWithAnd.GetValueOrDefault(false) ? " & " : string.Empty));
                mixReplaceDef.Add(new MixFileNameReplaceDef("+", _replaceSlashWithAnd.GetValueOrDefault(false) ? " & " : string.Empty));

                foreach (var replaceDef in mixReplaceDef)
                {
                    var tmplist = new List <string>();

                    foreach (var mixFileName in mixLines)
                    {
                        if (!mixFileName.Contains(replaceDef.OldValue))
                        {
                            tmplist.Add(mixFileName);
                            continue;
                        }

                        var lineElements = mixFileName.Split(new string[] { replaceDef.OldValue }, StringSplitOptions.None).Select(s => s.Trim()).ToList();
                        tmplist.Add(string.Join(replaceDef.NewValue, lineElements));
                    }

                    mixLines = new List <string>(tmplist);
                }

                result.AdditionalDataReturn = mixLines;
                _mustRebuild = false;
            }
            catch (Exception ex)
            {
                var msg =
                    string.Format("{0}{1}{1}Translated file names line:{1}{2}{1}{1}Original file names line:{3}",
                                  OperationResult.GetErrorMessage(ex),
                                  Environment.NewLine,
                                  translatedFNLine,
                                  originalFNLine);

                return(result.FailWithMessage(msg));
            }

            return(result);
        }
Exemplo n.º 8
0
        public static OperationResult GetCommonSenseMediaData(string recommendedLink)
        {
            var             result  = new OperationResult();
            CSMScrapeResult csmData = null;

            using (var client = new HttpClient())
            {
                try
                {
                    //the implementation if forced to run synchronous to avoid ip banning from scrapped sites
                    var request = client.GetAsync(recommendedLink).Result;
                    request.EnsureSuccessStatusCode();

                    if (request.Content == null)
                    {
                        result.FailWithMessage("No content");
                    }

                    var response = request.Content.ReadAsStreamAsync().Result;

                    if (response == null || response.Length == 0)
                    {
                        return(result.FailWithMessage("Invalid response!"));
                    }

                    csmData = new CSMScrapeResult();
                    var parser   = new HtmlParser();
                    var document = parser.ParseDocument(response);

                    var expandableSinopsis = document.GetElementsByClassName("field-name-field-review-recommended-age");

                    var greenAge = document.GetElementsByClassName("csm-green-age").FirstOrDefault();
                    csmData.GreenAge = greenAge == null ? null : greenAge.TextContent;

                    var csmRatingL0 = document.GetElementsByClassName("field-name-field-stars-rating").FirstOrDefault();

                    if (csmRatingL0 != null)
                    {
                        var csmRatingLx = csmRatingL0.QuerySelectorAll("div.field_stars_rating").FirstOrDefault();

                        if (csmRatingLx != null)
                        {
                            var ratingClass = csmRatingLx.ClassList.FirstOrDefault(_ => _.StartsWith("rating-"));

                            if (ratingClass != null)
                            {
                                if (int.TryParse(ratingClass.Replace("rating-", ""), out int ratingInt))
                                {
                                    csmData.Rating = ratingInt;
                                }
                            }

                            var shortDescriptionObj = csmRatingL0.QuerySelectorAll("meta[property=\"description\"]").FirstOrDefault();
                            if (shortDescriptionObj != null)
                            {
                                var metaElement = (AngleSharp.Html.Dom.IHtmlMetaElement)shortDescriptionObj;
                                csmData.ShortDescription = metaElement.Content;
                            }

                            var reviewObj = csmRatingL0.QuerySelectorAll("meta[property=\"reviewBody\"]").FirstOrDefault();
                            if (reviewObj != null)
                            {
                                var metaElement = (AngleSharp.Html.Dom.IHtmlMetaElement)reviewObj;

                                var rx = new System.Text.RegularExpressions.Regex("<[^>]*>");
                                csmData.Review = rx.Replace(metaElement.Content, "");
                            }
                        }
                    }



                    var statisticsAdult = document.GetElementsByClassName("user-review-statistics adult").FirstOrDefault();
                    if (statisticsAdult != null)
                    {
                        var adultAge = statisticsAdult.GetElementsByClassName("stat-wrapper age").FirstOrDefault();
                        csmData.AdultRecomendedAge = adultAge == null ? null : adultAge.TextContent;


                        var adultRating = statisticsAdult.GetElementsByClassName("field-stars-rating").FirstOrDefault();
                        if (adultRating != null)
                        {
                            var ratingClass = adultRating.ClassList.FirstOrDefault(_ => _.StartsWith("rating-"));
                            //result.AdultRating = ratingClass.Replace("rating-", "");
                            if (int.TryParse(ratingClass.Replace("rating-", ""), out int ratingInt))
                            {
                                csmData.AdultRating = ratingInt;
                            }
                        }
                    }

                    var statisticsChild = document.GetElementsByClassName("user-review-statistics child").FirstOrDefault();
                    if (statisticsChild != null)
                    {
                        var childAge = statisticsChild.GetElementsByClassName("stat-wrapper age").FirstOrDefault();
                        csmData.ChildRecomendedAge = childAge == null ? null : childAge.TextContent;

                        var childRating = statisticsChild.GetElementsByClassName("field-stars-rating").FirstOrDefault();
                        if (childRating != null)
                        {
                            var ratingClass = childRating.ClassList.FirstOrDefault(_ => _.StartsWith("rating-"));
                            //result.ChildRating = ratingClass.Replace("rating-", "");
                            if (int.TryParse(ratingClass.Replace("rating-", ""), out int ratingInt))
                            {
                                csmData.ChildRating = ratingInt;
                            }
                        }
                    }

                    var storyParent = document.GetElementsByClassName("pane-node-field-what-is-story").FirstOrDefault();
                    if (storyParent != null)
                    {
                        var storyEl = storyParent.QuerySelectorAll("p").FirstOrDefault();
                        csmData.Story = storyEl == null ? null : storyEl.TextContent;
                    }

                    var isItAnyGoodParent = document.GetElementsByClassName("pane-node-field-any-good").FirstOrDefault();
                    if (isItAnyGoodParent != null)
                    {
                        var isItAnyGoodEl = isItAnyGoodParent.QuerySelectorAll("p").FirstOrDefault();
                        csmData.IsItAnyGood = isItAnyGoodEl == null ? null : isItAnyGoodEl.TextContent;
                    }

                    var talkWithKidsAboutParent = document.GetElementsByClassName("pane-node-field-family-topics").FirstOrDefault();
                    if (talkWithKidsAboutParent != null)
                    {
                        var talkWithKidsAboutEl = talkWithKidsAboutParent.QuerySelectorAll("p");

                        if (talkWithKidsAboutEl.Any())
                        {
                            csmData.TalkWithKidsAbout = new List <string>();

                            foreach (var item in talkWithKidsAboutEl)
                            {
                                csmData.TalkWithKidsAbout.Add(item.TextContent);
                            }
                        }
                    }

                    ALotOrALittle tmp = null;

                    tmp = Get_ALotOrALittle(document, "content-grid-item-educational", ALotOrAlittleElements.EducationalValue);
                    if (tmp != null)
                    {
                        csmData.ALotOrALittle.Add(tmp);
                    }

                    tmp = Get_ALotOrALittle(document, "content-grid-item-message", ALotOrAlittleElements.PositiveMessages);
                    if (tmp != null)
                    {
                        csmData.ALotOrALittle.Add(tmp);
                    }

                    tmp = Get_ALotOrALittle(document, "content-grid-item-role_model", ALotOrAlittleElements.PositiveRoleModelsAndRepresentations);
                    if (tmp != null)
                    {
                        csmData.ALotOrALittle.Add(tmp);
                    }

                    tmp = Get_ALotOrALittle(document, "content-grid-item-violence", ALotOrAlittleElements.ViolenceAndScariness);
                    if (tmp != null)
                    {
                        csmData.ALotOrALittle.Add(tmp);
                    }

                    tmp = Get_ALotOrALittle(document, "content-grid-item-sex", ALotOrAlittleElements.SexyStuff);
                    if (tmp != null)
                    {
                        csmData.ALotOrALittle.Add(tmp);
                    }

                    tmp = Get_ALotOrALittle(document, "content-grid-item-language", ALotOrAlittleElements.Language);
                    if (tmp != null)
                    {
                        csmData.ALotOrALittle.Add(tmp);
                    }

                    tmp = Get_ALotOrALittle(document, "content-grid-item-consumerism", ALotOrAlittleElements.Consumerism);
                    if (tmp != null)
                    {
                        csmData.ALotOrALittle.Add(tmp);
                    }

                    tmp = Get_ALotOrALittle(document, "content-grid-item-drugs", ALotOrAlittleElements.DrinkingDrugsAndSmoking);
                    if (tmp != null)
                    {
                        csmData.ALotOrALittle.Add(tmp);
                    }
                }
                catch (Exception ex)
                {
                    return(result.FailWithMessage(ex));
                }
            }

            result.AdditionalDataReturn = csmData;
            return(result);

            ALotOrALittle Get_ALotOrALittle(IHtmlDocument document, string elementId, ALotOrAlittleElements category)
            {
                ALotOrALittle result2 = null;

                var parentElement = document.GetElementById(elementId);

                if (parentElement != null)
                {
                    var stars       = 0;
                    var description = string.Empty;

                    var ratingEl = parentElement.QuerySelectorAll("div.field_content_grid_rating").FirstOrDefault();
                    if (ratingEl != null)
                    {
                        var ratingClass = ratingEl.ClassList.FirstOrDefault(_ => _.StartsWith("content-grid-") && char.IsDigit(_[_.Length - 1]));
                        //stars = ratingClass.Replace("content-grid-", "");

                        if (int.TryParse(ratingClass.Replace("content-grid-", ""), out int ratingInt))
                        {
                            stars = ratingInt;
                        }
                    }

                    var ratingDescEl = parentElement.QuerySelectorAll("div.field-name-field-content-grid-rating-text").FirstOrDefault();
                    if (ratingDescEl != null)
                    {
                        var ratingDescEl2 = ratingDescEl.QuerySelectorAll("p").FirstOrDefault();
                        if (ratingDescEl2 != null)
                        {
                            description = ratingDescEl2.TextContent;
                        }
                    }

                    result2 = new ALotOrALittle()
                    {
                        Rating = stars, Description = description, Category = category
                    };
                }

                return(result2);
            }
        }