/// <exception cref="InvalidOperationException"><see cref="Initialize"/> method invoke required before update</exception>
        /// <exception cref="TrainingCatalogUpdateException"></exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="updateEvent"/> or
        /// <paramref name="context"/>
        /// is <see langword="null" />.</exception>
        public virtual async Task UpdateAsync(UpdateEvent updateEvent, UpdateDbContext context,
                                              bool useArchiveData = false, bool logUpdateToDb = true)
        {
            if (updateEvent == null)
            {
                throw new ArgumentNullException("updateEvent");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!IsInitialized)
            {
                throw new InvalidOperationException("Initialize(...) method invoke required before update");
            }

            try
            {
                var updateParseResult = await GetUpdateAsync();

                var changesProcessor = CreateChangesProcessor(updateParseResult, useArchiveData);

                var updateProcessor = CreateUpdateProcessor(context, logUpdateToDb);
                await updateProcessor.ProcessUpdateAsync(updateEvent, changesProcessor);

                await UpdateMediaContentAsync(context);
            }
            catch (Exception ex)
            {
                var message = string.Format(Resources.TrainingCatalogUpdateException_Message, TrainingProviderName);
                throw new TrainingCatalogUpdateException(message, ex);
            }
        }
        /// <exception cref="ArgumentNullException"><paramref name="context"/> is <see langword="null" />.</exception>
        /// <exception cref="MediaContentUpdateException"></exception>
        public async Task UpdateMediaContentAsync(UpdateDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            try
            {
                var categoryMediaContentDirectory = _mediaPath.CategoriesLogoPath[_trainingProviderId];

                var dbCategoriesLogo = await context.Categories
                                       .Where(x => x.LogoFileName != null)
                                       .Select(x => new MediaContentInfo {
                    Url = x.LogoUrl, FileName = x.LogoFileName
                })
                                       .ToListAsync();

                var fsCategoriesLogo = _fileSystemProxy.EnumerateFiles(categoryMediaContentDirectory)
                                       .Select(Path.GetFileName);

                await UpdateMediaContentAsync(dbCategoriesLogo, fsCategoriesLogo, categoryMediaContentDirectory);


                var authorsMediaContentDirectory = _mediaPath.AuthorsLogoPath[_trainingProviderId];

                var dbAuthorsLogo = await context.Authors
                                    .Where(x => x.Avatar.Name != null && x.Avatar.Name != "")
                                    .Select(x => new MediaContentInfo {
                    Url = x.Avatar.SiteUrl, FileName = x.Avatar.Name
                })
                                    .ToListAsync();

                var fsAuthorsLogo = _fileSystemProxy.EnumerateFiles(authorsMediaContentDirectory)
                                    .Select(Path.GetFileName);

                await UpdateMediaContentAsync(dbAuthorsLogo, fsAuthorsLogo, authorsMediaContentDirectory);


                var badgesMediaContentDirectory = _mediaPath.BadgesPath[_trainingProviderId];

                var dbBadgesLogo = await context.Authors
                                   .Where(x => x.Badge.ImageName != null && x.Badge.ImageName != "")
                                   .GroupBy(x => new { x.Badge.ImageName, x.Badge.ImageSiteUrl }, x => "")
                                   .Select(x => new MediaContentInfo {
                    Url = x.Key.ImageSiteUrl, FileName = x.Key.ImageName
                })
                                   .ToListAsync();

                var fsBadgesLogo = _fileSystemProxy.EnumerateFiles(badgesMediaContentDirectory)
                                   .Select(Path.GetFileName);

                await UpdateMediaContentAsync(dbBadgesLogo, fsBadgesLogo, badgesMediaContentDirectory);
            }
            catch (Exception ex)
            {
                var message = string.Format(Resources.MediaContentUpdateException_Message, _trainingProviderName);
                throw new MediaContentUpdateException(message, ex);
            }
        }
        internal async Task UpdateTrainingCatalogAsync(UpdateDbContext context, TrainingProvider trainingProvider,
                                                       string description, ServerMediaPathsContainer pathsContainer, bool useArchiveData = false, bool logUpdateToDb = true)
        {
            var updateEvent = new UpdateEvent(trainingProvider.Id, description, _dateTimeProxy.UtcNow);

            context.UpdateEvents.Add(updateEvent);

            await context.SaveChangesAsync();

            using (var catalog = _activatorProxy.CreateInstance <ITrainingCatalog>(trainingProvider.AssemblyType))
            {
                catalog.Initialize(trainingProvider.Name, trainingProvider.Id, trainingProvider.SiteUrl,
                                   trainingProvider.SourceUrl, trainingProvider.SourceLocation, pathsContainer, _archiveDirectoryPath);
                try
                {
                    await catalog.UpdateAsync(updateEvent, context, useArchiveData, logUpdateToDb);

                    updateEvent.EndedOn = _dateTimeProxy.UtcNow;
                    if (context.AuthorsResolves.Local.Any())
                    {
                        updateEvent.UpdateResult = UpdateResult.NeedManualResolve;
                    }
                    else
                    {
                        updateEvent.UpdateResult = UpdateResult.Success;
                    }

                    await context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    updateEvent.EndedOn      = _dateTimeProxy.UtcNow;
                    updateEvent.UpdateResult = UpdateResult.Error;

                    var aggregateException = ex as AggregateException;
                    var errorData          = aggregateException != null
                  ? aggregateException.Flatten().ToString()
                  : ex.ToString();

                    updateEvent.ErrorData = errorData;

                    updateEvent.AuthorsUpdates    = null;
                    updateEvent.CategoriesUpdates = null;
                    updateEvent.CoursesUpdates    = null;

                    context.SetStateToDetached(updateEvent);

                    using (var ctx = _contextFactory.CreateDbContext())
                    {
                        ctx.SetStateToModified(updateEvent);
                        ctx.SaveChanges();
                    }
                }
            }
        }
      /// <exception cref="ArgumentNullException"><paramref name="context"/> is <see langword="null" />.</exception>
      /// <exception cref="MediaContentUpdateException"></exception>
      public async Task UpdateMediaContentAsync(UpdateDbContext context)
      {
         if(context == null) 
            throw new ArgumentNullException("context");
         try
         {
            var categoryMediaContentDirectory = _mediaPath.CategoriesLogoPath[_trainingProviderId];

            var dbCategoriesLogo = await context.Categories
               .Where(x => x.LogoFileName != null)
               .Select(x => new MediaContentInfo {Url = x.LogoUrl, FileName = x.LogoFileName})
               .ToListAsync();

            var fsCategoriesLogo = _fileSystemProxy.EnumerateFiles(categoryMediaContentDirectory)
               .Select(Path.GetFileName);

            await UpdateMediaContentAsync(dbCategoriesLogo, fsCategoriesLogo, categoryMediaContentDirectory);


            var authorsMediaContentDirectory = _mediaPath.AuthorsLogoPath[_trainingProviderId];

            var dbAuthorsLogo = await context.Authors
               .Where(x => x.Avatar.Name != null && x.Avatar.Name != "")
               .Select(x => new MediaContentInfo {Url = x.Avatar.SiteUrl, FileName = x.Avatar.Name})
               .ToListAsync();

            var fsAuthorsLogo = _fileSystemProxy.EnumerateFiles(authorsMediaContentDirectory)
               .Select(Path.GetFileName);

            await UpdateMediaContentAsync(dbAuthorsLogo, fsAuthorsLogo, authorsMediaContentDirectory);


            var badgesMediaContentDirectory = _mediaPath.BadgesPath[_trainingProviderId];

            var dbBadgesLogo = await context.Authors
               .Where(x => x.Badge.ImageName != null && x.Badge.ImageName != "")
               .GroupBy(x => new {x.Badge.ImageName, x.Badge.ImageSiteUrl}, x => "")
               .Select(x => new MediaContentInfo {Url = x.Key.ImageSiteUrl, FileName = x.Key.ImageName})
               .ToListAsync();

            var fsBadgesLogo = _fileSystemProxy.EnumerateFiles(badgesMediaContentDirectory)
               .Select(Path.GetFileName);

            await UpdateMediaContentAsync(dbBadgesLogo, fsBadgesLogo, badgesMediaContentDirectory);
         }
         catch(Exception ex)
         {
            var message = string.Format(Resources.MediaContentUpdateException_Message, _trainingProviderName);
            throw new MediaContentUpdateException(message, ex);
         }
      }
Example #5
0
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> or
        /// <paramref name="catalogBackupProcessor"/> is <see langword="null" />.</exception>
        protected TrainingCatalogUpdateProcessor(int trainingProviderId, UpdateDbContext context,
                                                 ICatalogBackupProcessor <TCategoryParseModel, TCourseParseModel, TAuthorParseModel> catalogBackupProcessor,
                                                 bool logUpdateToDb)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (catalogBackupProcessor == null)
            {
                throw new ArgumentNullException("catalogBackupProcessor");
            }

            TrainingProviderId     = trainingProviderId;
            Context                = context;
            CatalogBackupProcessor = catalogBackupProcessor;
            LogUpdateToDb          = logUpdateToDb;
        }
 public HomeManager(UpdateDbContext context) : base(context)
 {
 }
 public CategoriesManager(UpdateDbContext context)
    : base(context)
 {
 }
      protected virtual void Dispose(bool disposing)
      {
         if (disposing && _context != null)
         {
            _context.Dispose();
            _context = null;

            _disposed = true;
         }
      }
      internal async Task UpdateTrainingCatalogAsync(UpdateDbContext context, TrainingProvider trainingProvider,
         string description, ServerMediaPathsContainer pathsContainer, bool useArchiveData = false, bool logUpdateToDb = true)
      {
         var updateEvent = new UpdateEvent(trainingProvider.Id, description, _dateTimeProxy.UtcNow);

         context.UpdateEvents.Add(updateEvent);

         await context.SaveChangesAsync();

         using (var catalog = _activatorProxy.CreateInstance<ITrainingCatalog>(trainingProvider.AssemblyType))
         {
            catalog.Initialize(trainingProvider.Name, trainingProvider.Id, trainingProvider.SiteUrl,
               trainingProvider.SourceUrl, trainingProvider.SourceLocation, pathsContainer,_archiveDirectoryPath);
            try
            {
               await catalog.UpdateAsync(updateEvent, context, useArchiveData, logUpdateToDb);

               updateEvent.EndedOn = _dateTimeProxy.UtcNow;
               if (context.AuthorsResolves.Local.Any())
               {
                  updateEvent.UpdateResult = UpdateResult.NeedManualResolve;
               } else
               {
                  updateEvent.UpdateResult = UpdateResult.Success;
               }

               await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
               updateEvent.EndedOn = _dateTimeProxy.UtcNow;
               updateEvent.UpdateResult = UpdateResult.Error;

               var aggregateException = ex as AggregateException;
               var errorData = aggregateException != null
                  ? aggregateException.Flatten().ToString()
                  : ex.ToString();

               updateEvent.ErrorData = errorData;

               updateEvent.AuthorsUpdates = null;
               updateEvent.CategoriesUpdates = null;
               updateEvent.CoursesUpdates = null;

               context.SetStateToDetached(updateEvent);

               using (var ctx = _contextFactory.CreateDbContext())
               {
                  ctx.SetStateToModified(updateEvent);
                  ctx.SaveChanges();
               }
            }
         }
      }
 /// <exception cref="InvalidOperationException"><see cref="Initialize"/> method invoke required before update</exception>
 public abstract Task ReassignCourseSpecializationsAsync(UpdateDbContext context, bool useArchiveData = false);
 CreateUpdateProcessor(UpdateDbContext context, bool logUpdateToDb);
 private Task UpdateMediaContentAsync(UpdateDbContext context)
 {
     return(_mediaContentProcessor.UpdateMediaContentAsync(context));
 }
 public CoursesManager(UpdateDbContext context)
    : base(context)
 {
 }
 protected override void Dispose(bool disposing)
 {
    if (disposing)
    {
       db.Dispose();
       db = null;
    }
    base.Dispose(disposing);
 }
 public AuthorsManager(UpdateDbContext context)
    : base(context)
 {
 }
Example #16
0
      internal async Task<UpdateEventInfo> GetLastUpdateEventInfoAsync(int trainingProviderId, UpdateDbContext context)
      {
         var lastUpdateEventInfo = await context.UpdateEvents
              .Where(x => x.TrainingProviderId == trainingProviderId)
              .OrderByDescending(x => x.StartedOn)
              .Select(x => new UpdateEventInfo { StartedOn = x.StartedOn, UpdateResult = x.UpdateResult })
              .FirstOrDefaultAsync();

         return lastUpdateEventInfo;
      }
 protected override void Dispose(bool disposing)
 {
    if (disposing && _db != null)
    {
       _db.Dispose();
       _db = null;
    }
    base.Dispose(disposing);
 }
 protected CatalogManagerBase(UpdateDbContext context)
 {
    _context = context;
 }
Example #19
0
        internal async Task <UpdateEventInfo> GetLastUpdateEventInfoAsync(int trainingProviderId, UpdateDbContext context)
        {
            var lastUpdateEventInfo = await context.UpdateEvents
                                      .Where(x => x.TrainingProviderId == trainingProviderId)
                                      .OrderByDescending(x => x.StartedOn)
                                      .Select(x => new UpdateEventInfo {
                StartedOn = x.StartedOn, UpdateResult = x.UpdateResult
            })
                                      .FirstOrDefaultAsync();

            return(lastUpdateEventInfo);
        }
 public SyndicationFeedsManager(UpdateDbContext context)
    : base(context)
 {
 }
 public TrainingProvidersManager(UpdateDbContext context)
    : base(context)
 {
 }