Beispiel #1
0
 public BackupProgress GetBackupProgress(int tenantId)
 {
     lock (ProgressQueue.SynchRoot)
     {
         return(ToBackupProgress(ProgressQueue.GetItems().OfType <BackupProgressItem>().FirstOrDefault(t => t.TenantId == tenantId)));
     }
 }
Beispiel #2
0
 public BackupProgress GetRestoreProgress(int tenantId)
 {
     lock (SynchRoot)
     {
         return(ToBackupProgress(ProgressQueue.GetTasks <RestoreProgressItem>().FirstOrDefault(t => t.TenantId == tenantId)));
     }
 }
Beispiel #3
0
        public static void Initialize()
        {
            var backupConfiguration = BackupConfigurationSection.GetSection();

            currentWebConfigPath = ToAbsolute(backupConfiguration.RegionConfigs.GetCurrentConfig());
            if (!currentWebConfigPath.EndsWith(".config", StringComparison.OrdinalIgnoreCase))
            {
                currentWebConfigPath = Path.Combine(currentWebConfigPath, "web.config");
            }

            tmpfolder = ToAbsolute(backupConfiguration.TmpFolder);
            expire    = backupConfiguration.ExpirePeriod;

            tasks   = new ProgressQueue(backupConfiguration.ThreadCount, TimeSpan.FromMinutes(15), false);
            cleaner = new Timer(Clean, expire, expire, expire);

            ThreadPool.QueueUserWorkItem(state =>
            {
                foreach (var tenant in CoreContext.TenantManager
                         .GetTenants()
                         .Where(t => t.Status == TenantStatus.Transfering))
                {
                    tenant.SetStatus(TenantStatus.Active);
                    CoreContext.TenantManager.SaveTenant(tenant);
                    var url = tenant.TenantDomain;
                    if (!url.StartsWith("http://") && !url.StartsWith("https://"))
                    {
                        url = "http://" + url;
                    }
                    NotifyHelper.SendAboutTransferError(tenant.TenantId, string.Empty, url, string.Empty, true);
                }
            });
        }
Beispiel #4
0
        public virtual Boolean MoveNext()
        {
            Boolean result;

            if (!Completed)
            {
                if (ProgressQueue.Count > 0)
                {
                    TreeNodeType node = ProgressQueue.Dequeue();

                    foreach (TreeNodeType child in node.Children)
                    {
                        ProgressQueue.Enqueue(child);
                    }

                    CurrentItem = node;
                }
                else // Enumeration is complete.
                {
                    CurrentItem = InvalidItem;
                    Completed   = true;
                }

                result = !CurrentItem.Equals(InvalidItem);
            }
            else
            {
                result = false;
            }

            return(result);
        }
        public static void Initialize()
        {
            var backupConfiguration = BackupConfigurationSection.GetSection();

            currentWebConfigPath = ToAbsolute(backupConfiguration.RegionConfigs.GetCurrentConfig());
            if (!currentWebConfigPath.EndsWith(".config", StringComparison.OrdinalIgnoreCase))
            {
                currentWebConfigPath = Path.Combine(currentWebConfigPath, "web.config");
            }

            tmpfolder = ToAbsolute(backupConfiguration.TmpFolder);
            expire = backupConfiguration.ExpirePeriod;

            tasks = new ProgressQueue(backupConfiguration.ThreadCount, TimeSpan.FromMinutes(15), false);
            cleaner = new Timer(Clean, expire, expire, expire);

            ThreadPool.QueueUserWorkItem(state =>
                {
                    foreach (var tenant in CoreContext.TenantManager
                                                      .GetTenants()
                                                      .Where(t => t.Status == TenantStatus.Transfering))
                    {
                        tenant.SetStatus(TenantStatus.Active);
                        CoreContext.TenantManager.SaveTenant(tenant);
                        var url = tenant.TenantDomain;
                        if (!url.StartsWith("http://") && !url.StartsWith("https://"))
                        {
                            url = "http://" + url;
                        }
                        NotifyHelper.SendAboutTransferError(tenant.TenantId, string.Empty, url, string.Empty, true);
                    }
                });
        }
Beispiel #6
0
        public virtual void Reset()
        {
            CurrentItem = InvalidItem;
            Completed   = false;

            ProgressQueue.Clear();
            ProgressQueue.Enqueue(Root);
        }
Beispiel #7
0
 public void Stop()
 {
     if (ProgressQueue != null)
     {
         ProgressQueue.Terminate();
         ProgressQueue = null;
     }
 }
        public static void Initialize()
        {
            var config = BackupConfigurationSection.GetSection();

            tasks   = new ProgressQueue(config.ThreadCount, TimeSpan.FromMinutes(15), false);
            cleaner = new Timer(Clean, config.ExpirePeriod, config.ExpirePeriod, config.ExpirePeriod);

            ThreadPool.QueueUserWorkItem(_ => RestoreTransferingTenants());
        }
Beispiel #9
0
 public void ResetRestoreError(int tenantId)
 {
     lock (ProgressQueue.SynchRoot)
     {
         var progress = ProgressQueue.GetItems().OfType <RestoreProgressItem>().FirstOrDefault(t => t.TenantId == tenantId);
         if (progress != null)
         {
             progress.Error = null;
         }
     }
 }
Beispiel #10
0
 public void ResetRestoreError(int tenantId)
 {
     lock (SynchRoot)
     {
         var progress = ProgressQueue.GetTasks <RestoreProgressItem>().FirstOrDefault(t => t.TenantId == tenantId);
         if (progress != null)
         {
             progress.Exception = null;
         }
     }
 }
Beispiel #11
0
        public void Stop()
        {
            if (ProgressQueue != null)
            {
                var tasks = ProgressQueue.GetTasks();
                foreach (var t in tasks)
                {
                    ProgressQueue.CancelTask(t.Id);
                }

                ProgressQueue = null;
            }
        }
Beispiel #12
0
 public static void Stop()
 {
     if (tasks != null)
     {
         tasks.Terminate();
         tasks = null;
     }
     if (schedulerTasks != null)
     {
         schedulerTasks.Terminate();
         schedulerTasks = null;
     }
 }
 public static void Terminate()
 {
     if (tasks != null)
     {
         tasks.Terminate();
         tasks = null;
     }
     if (cleaner != null)
     {
         cleaner.Change(Timeout.Infinite, Timeout.Infinite);
         cleaner.Dispose();
         cleaner = null;
     }
 }
Beispiel #14
0
 public static void Terminate()
 {
     if (tasks != null)
     {
         tasks.Terminate();
         tasks = null;
     }
     if (cleaner != null)
     {
         cleaner.Change(Timeout.Infinite, Timeout.Infinite);
         cleaner.Dispose();
         cleaner = null;
     }
 }
Beispiel #15
0
 public void StartScheduledBackup(BackupSchedule schedule)
 {
     lock (ProgressQueue.SynchRoot)
     {
         var item = ProgressQueue.GetItems().OfType <BackupProgressItem>().FirstOrDefault(t => t.TenantId == schedule.TenantId);
         if (item != null && item.IsCompleted)
         {
             ProgressQueue.Remove(item);
             item = null;
         }
         if (item == null)
         {
             item = FactoryProgressItem.CreateBackupProgressItem(schedule, false, TempFolder, Limit, CurrentRegion, ConfigPaths);
             ProgressQueue.Add(item);
         }
     }
 }
Beispiel #16
0
 public BackupProgress StartRestore(StartRestoreRequest request)
 {
     lock (ProgressQueue.SynchRoot)
     {
         var item = ProgressQueue.GetItems().OfType <RestoreProgressItem>().FirstOrDefault(t => t.TenantId == request.TenantId);
         if (item != null && item.IsCompleted)
         {
             ProgressQueue.Remove(item);
             item = null;
         }
         if (item == null)
         {
             item = FactoryProgressItem.CreateRestoreProgressItem(request, TempFolder, UpgradesPath, CurrentRegion, ConfigPaths);
             ProgressQueue.Add(item);
         }
         return(ToBackupProgress(item));
     }
 }
Beispiel #17
0
        public static void Start(BackupConfigurationSection config)
        {
            limit         = config.Limit;
            upgradesPath  = config.UpgradesPath;
            currentRegion = config.WebConfigs.CurrentRegion;
            configPaths   = config.WebConfigs.Cast <WebConfigElement>().ToDictionary(el => el.Region, el => PathHelper.ToRootedConfigPath(el.Path));
            configPaths[currentRegion] = PathHelper.ToRootedConfigPath(config.WebConfigs.CurrentPath);

            var invalidConfigPath = configPaths.Values.FirstOrDefault(path => !File.Exists(path));

            if (invalidConfigPath != null)
            {
                Log.WarnFormat("Configuration file {0} not found", invalidConfigPath);
            }

            tasks          = new ProgressQueue(config.Service.WorkerCount, TimeSpan.FromMinutes(15), false);
            schedulerTasks = new ProgressQueue(config.Scheduler.WorkerCount, TimeSpan.FromMinutes(15), false);
        }
Beispiel #18
0
        public BackupProgress StartTransfer(int tenantId, string targetRegion, bool transferMail, bool notify)
        {
            lock (ProgressQueue.SynchRoot)
            {
                var item = ProgressQueue.GetItems().OfType <TransferProgressItem>().FirstOrDefault(t => t.TenantId == tenantId);
                if (item != null && item.IsCompleted)
                {
                    ProgressQueue.Remove(item);
                    item = null;
                }

                if (item == null)
                {
                    item = FactoryProgressItem.CreateTransferProgressItem(targetRegion, transferMail, tenantId, TempFolder, Limit, notify, CurrentRegion, ConfigPaths);
                    ProgressQueue.Add(item);
                }

                return(ToBackupProgress(item));
            }
        }
Beispiel #19
0
        public BackupProgress StartBackup(StartBackupRequest request)
        {
            lock (SynchRoot)
            {
                var item = ProgressQueue.GetTasks <BackupProgressItem>().FirstOrDefault(t => t.TenantId == request.TenantId);
                if (item != null && item.IsCompleted)
                {
                    ProgressQueue.RemoveTask(item.Id);
                    item = null;
                }
                if (item == null)
                {
                    item = FactoryProgressItem.CreateBackupProgressItem(request, false, TempFolder, Limit, CurrentRegion, ConfigPaths);
                    ProgressQueue.QueueTask(item);
                }

                item.PublishChanges();

                return(ToBackupProgress(item));
            }
        }
Beispiel #20
0
        public BackupProgress StartBackup(StartBackupRequest request)
        {
            lock (ProgressQueue.SynchRoot)
            {
                var item = ProgressQueue.GetItems().OfType <BackupProgressItem>().FirstOrDefault(t => t.TenantId == request.TenantId);
                if (item != null && item.IsCompleted)
                {
                    ProgressQueue.Remove(item);
                    item = null;
                }
                if (item == null)
                {
                    item = FactoryProgressItem.CreateBackupProgressItem(request, false, TempFolder, Limit, CurrentRegion, ConfigPaths);
                    ProgressQueue.Add(item);
                }

                var progress = ToBackupProgress(item);

                PublishProgress(progress);

                return(progress);
            }
        }
Beispiel #21
0
 public virtual void Dispose()
 {
     Root = CurrentItem = InvalidItem;
     ProgressQueue.Clear();
 }
Beispiel #22
0
        public void WriteProgress(long sourceId, ProgressRecordEx progressRecord)
        {
            ProgressQueue.Enqueue(progressRecord);

            WriteProtectedProgress(() => realWriter.WriteProgress(sourceId, progressRecord));
        }
Beispiel #23
0
        public void WriteProgress(ProgressRecordEx progressRecord)
        {
            ProgressQueue.Enqueue(progressRecord);

            WriteProtectedProgress(() => realWriter.WriteProgress(progressRecord));
        }