Example #1
0
        public Models.BackupPlanPathNode CreateOrUpdatePathNodes(Models.StorageAccount account, Models.BackupPlanFile file)
        {
            PathNodes pathNodes = new PathNodes(file.Path);

            bool nodeExists = true;             // Start assuming it exists.

            Models.BackupPlanPathNode previousNode = null;
            Models.BackupPlanPathNode planPathNode = null;
            foreach (var pathNode in pathNodes.Nodes)
            {
                // If it does not exist, it does not make sense to lookup inner directories/files.
                if (nodeExists)
                {
                    planPathNode = _dao.GetByStorageAccountAndTypeAndPath(
                        account, Models.EntryTypeExtensions.ToEntryType(pathNode.Type), pathNode.Path);

                    // If we couldn't find the current `Models.BackupPlanPathNode`, it's safe to assume the inner
                    // directories/files don't exist either. From now on, all nodes will be created/inserted.
                    if (planPathNode == null)
                    {
                        nodeExists = false;
                    }
                }

                if (!nodeExists)
                {
                    //BackupPlanFile planFile = daoBackupPlanFile.GetByPlanAndPath(Backup.BackupPlan, file.Path);
                    //Assert.NotNull(planFile, string.Format("Required {0} not found in the database.", typeof(BackupPlanFile).Name))
                    planPathNode = new Models.BackupPlanPathNode(file,
                                                                 Models.EntryTypeExtensions.ToEntryType(pathNode.Type),
                                                                 pathNode.Name, pathNode.Path, previousNode);

                    if (previousNode != null)
                    {
                        planPathNode.Parent = previousNode;
                        previousNode.SubNodes.Add(planPathNode);
                    }


                    _dao.Insert(_tx, planPathNode);
                    _dao.Refresh(planPathNode);
                }

                previousNode = planPathNode;

                //session.Evict(planPathNode); // Force future queries to re-load it and its relationships.
            }

            return(previousNode);
        }
Example #2
0
 public BackupPlanPathNode(BackupPlanFile planFile, EntryType type, string name, string path, BackupPlanPathNode parent)
     : this()
 {
     _StorageAccountType = planFile.StorageAccountType;
     _StorageAccount     = planFile.StorageAccount;
     _Type = type;
     // Only assign `PlanFile` if this is for a node that represents a FILE.
     if (_Type == EntryType.FILE)
     {
         _PlanFile = planFile;
     }
     _Name   = name;
     _Path   = path;
     _Parent = parent;
 }
Example #3
0
        //
        // Loads or creates `RestorePlanFile`s for each file in `files`.
        // Returns the complete list of `RestorePlanFile`s that are related to `files`.
        // NOTE: Does not save to the database because this method is run by a secondary thread.
        //
        private LinkedList <Models.RestorePlanFile> DoLoadOrCreateRestorePlanFiles(Models.RestorePlan plan, LinkedList <CustomVersionedFile> files)
        {
            Assert.IsNotNull(plan);
            Assert.IsNotNull(files);
            Assert.IsNotNull(AllFilesFromPlan);

            LinkedList <Models.RestorePlanFile> result      = new LinkedList <Models.RestorePlanFile>();
            BackupPlanPathNodeRepository        daoPathNode = new BackupPlanPathNodeRepository();

            // Check all files.
            foreach (CustomVersionedFile file in files)
            {
                // Throw if the operation was canceled.
                CancellationToken.ThrowIfCancellationRequested();

                //
                // Create or update `RestorePlanFile`.
                //
                Models.RestorePlanFile restorePlanFile = null;
                bool backupPlanFileAlreadyExists       = AllFilesFromPlan.TryGetValue(file.Path, out restorePlanFile);

                if (!backupPlanFileAlreadyExists)
                {
                    restorePlanFile           = new Models.RestorePlanFile(plan, file.Path);
                    restorePlanFile.CreatedAt = DateTime.UtcNow;
                }

                Models.BackupPlanPathNode pathNode = daoPathNode.GetByStorageAccountAndTypeAndPath(plan.StorageAccount, Models.EntryType.FILE, file.Path);
                Assert.IsNotNull(pathNode, string.Format("{0} has no corresponding {1}", file.Path, typeof(Models.BackupPlanPathNode).Name));
                restorePlanFile.PathNode      = pathNode;
                restorePlanFile.VersionedFile = file;
                result.AddLast(restorePlanFile);
            }

            return(result);
        }