コード例 #1
0
        /// <summary>
        /// Recursive method that loads a given tree and retries failures already present if any
        /// </summary>
        protected virtual void LoadTreeRecursive(ISerializedReference root, IDeserializeFailureRetryer retryer, IConsistencyChecker consistencyChecker)
        {
            Assert.ArgumentNotNull(root, "root");
            Assert.ArgumentNotNull(retryer, "retryer");

            var included = Predicate.Includes(root);

            if (!included.IsIncluded)
            {
                Logger.SkippedItemPresentInSerializationProvider(root, Predicate.GetType().Name, SerializationProvider.GetType().Name, included.Justification ?? string.Empty);
                return;
            }

            try
            {
                // load the current level
                LoadOneLevel(root, retryer, consistencyChecker);

                // check if we have child paths to recurse down
                var children = root.GetChildReferences(false);

                if (children.Length > 0)
                {
                    // make sure if a "templates" item exists in the current set, it goes first
                    if (children.Length > 1)
                    {
                        int templateIndex = Array.FindIndex(children, x => x.ItemPath.EndsWith("templates", StringComparison.OrdinalIgnoreCase));

                        if (templateIndex > 0)
                        {
                            var zero = children[0];
                            children[0]             = children[templateIndex];
                            children[templateIndex] = zero;
                        }
                    }

                    // load each child path recursively
                    foreach (var child in children)
                    {
                        LoadTreeRecursive(child, retryer, consistencyChecker);
                    }

                    // pull out any standard values failures for immediate retrying
                    retryer.RetryStandardValuesFailures(item => DoLoadItem(item, null));
                }                 // children.length > 0
            }
            catch (ConsistencyException)
            {
                throw;
            }
            catch (Exception ex)
            {
                retryer.AddTreeRetry(root, ex);
            }
        }
コード例 #2
0
        protected virtual void DeleteItemRecursive(ISerializedReference reference)
        {
            foreach (var child in reference.GetChildReferences(false))
            {
                DeleteItemRecursive(child);
            }

            // kill the serialized file
            var fileItem = reference.GetItem();

            if (fileItem != null && File.Exists(fileItem.ProviderId))
            {
                File.Delete(fileItem.ProviderId);
            }

            // remove any serialized children
            var directory = SerializationPathUtility.GetReferenceDirectoryPath(reference);

            if (Directory.Exists(directory))
            {
                Directory.Delete(directory, true);
            }

            // clean up any hashpaths for this item
            var shortDirectory = SerializationPathUtility.GetShortSerializedReferencePath(_rootPath, reference);

            if (Directory.Exists(shortDirectory))
            {
                Directory.Delete(shortDirectory, true);
            }

            // clean up empty parent folder(s)
            var parentDirectory = Directory.GetParent(directory);

            if (!parentDirectory.Exists)
            {
                return;
            }

            do
            {
                if (parentDirectory.GetFileSystemInfos().Length > 0)
                {
                    break;
                }

                parentDirectory.Delete(true);
                parentDirectory = parentDirectory.Parent;
            } while (parentDirectory != null && parentDirectory.Exists);
        }
コード例 #3
0
        /// <summary>
        /// Recursive method that loads a given tree and retries failures already present if any
        /// </summary>
        protected virtual void LoadTreeRecursive(ISerializedReference root, IDeserializeFailureRetryer retryer, IConsistencyChecker consistencyChecker)
        {
            Assert.ArgumentNotNull(root, "root");
            Assert.ArgumentNotNull(retryer, "retryer");

            var included = Predicate.Includes(root);
            if (!included.IsIncluded)
            {
                Logger.SkippedItemPresentInSerializationProvider(root, Predicate.GetType().Name, SerializationProvider.GetType().Name, included.Justification ?? string.Empty);
                return;
            }

            try
            {
                // load the current level
                LoadOneLevel(root, retryer, consistencyChecker);

                // check if we have child paths to recurse down
                var children = root.GetChildReferences(false);

                if (children.Length > 0)
                {
                    // make sure if a "templates" item exists in the current set, it goes first
                    if (children.Length > 1)
                    {
                        int templateIndex = Array.FindIndex(children, x => x.ItemPath.EndsWith("templates", StringComparison.OrdinalIgnoreCase));

                        if (templateIndex > 0)
                        {
                            var zero = children[0];
                            children[0] = children[templateIndex];
                            children[templateIndex] = zero;
                        }
                    }

                    // load each child path recursively
                    foreach (var child in children)
                    {
                        LoadTreeRecursive(child, retryer, consistencyChecker);
                    }

                    // pull out any standard values failures for immediate retrying
                    retryer.RetryStandardValuesFailures(item => DoLoadItem(item, null));
                } // children.length > 0
            }
            catch (ConsistencyException)
            {
                throw;
            }
            catch (Exception ex)
            {
                retryer.AddTreeRetry(root, ex);
            }
        }
コード例 #4
0
        protected virtual void DeleteItemRecursive(ISerializedReference reference)
        {
            foreach (var child in reference.GetChildReferences(false))
            {
                DeleteItemRecursive(child);
            }

            // kill the serialized file
            var fileItem = reference.GetItem();
            if (fileItem != null && File.Exists(fileItem.ProviderId)) File.Delete(fileItem.ProviderId);

            // remove any serialized children
            var directory = SerializationPathUtility.GetReferenceDirectoryPath(reference);

            if (Directory.Exists(directory)) Directory.Delete(directory, true);

            // clean up any hashpaths for this item
            var shortDirectory = SerializationPathUtility.GetShortSerializedReferencePath(_rootPath, reference);

            if (Directory.Exists(shortDirectory)) Directory.Delete(shortDirectory, true);

            // clean up empty parent folder(s)
            var parentDirectory = Directory.GetParent(directory);

            if (!parentDirectory.Exists) return;

            do
            {
                if (parentDirectory.GetFileSystemInfos().Length > 0) break;

                parentDirectory.Delete(true);
                parentDirectory = parentDirectory.Parent;

            } while (parentDirectory != null && parentDirectory.Exists);
        }