コード例 #1
0
ファイル: ImportItemCommand.cs プロジェクト: magudb/Console
        public void Deserialize(Item item)
        {
            var reference = new ItemReference(item);

            if (Recurse.IsPresent)
            {
                var path = PathUtils.GetDirectoryPath(reference.ToString());
                Deserialize(path);
            }
            else
            {
                var path = PathUtils.GetFilePath(reference.ToString());
                Deserialize(path);
            }
        }
コード例 #2
0
        public string GetPath(string itemUri)
        {
            var item      = Database.GetItem(new ItemUri(itemUri));
            var reference = new ItemReference(item);

            return(PathUtils.GetFilePath(reference.ToString()));
        }
コード例 #3
0
        /// <summary>
        /// Loads a preset from serialized items on disk.
        /// </summary>
        public void LoadTree(AdvancedLoadOptions options)
        {
            Assert.ArgumentNotNull(options, "options");

            _itemsProcessed = 0;

            var reference = new ItemReference(options.Preset.Database, options.Preset.Path);
            var physicalPath = PathUtils.GetDirectoryPath(reference.ToString());

            options.Progress.ReportStatus("Loading serialized items from " + physicalPath, MessageType.Info);

            if (!Directory.Exists(physicalPath)) throw new FileNotFoundException("The root serialization path " + physicalPath + " did not exist!", physicalPath);

            if (options.DisableEvents)
            {
                using (new EventDisabler())
                {
                    LoadTreePaths(physicalPath, options);
                }

                string targetDatabase = GetTargetDatabase(physicalPath, options);
                DeserializationFinished(targetDatabase);

                return;
            }

            LoadTreePaths(physicalPath, options);
        }
コード例 #4
0
        /// <summary>
        /// Loads a preset from serialized items on disk.
        /// </summary>
        public void LoadTree(AdvancedLoadOptions options)
        {
            Assert.ArgumentNotNull(options, "options");

            _itemsProcessed = 0;

            var reference    = new ItemReference(options.Preset.Database, options.Preset.Path);
            var physicalPath = PathUtils.GetDirectoryPath(reference.ToString());

            options.Progress.ReportStatus("Loading serialized items from " + physicalPath, MessageType.Info);

            if (!Directory.Exists(physicalPath))
            {
                throw new FileNotFoundException("The root serialization path " + physicalPath + " did not exist!", physicalPath);
            }

            if (options.DisableEvents)
            {
                using (new EventDisabler())
                {
                    LoadTreePaths(physicalPath, options);
                }

                string targetDatabase = GetTargetDatabase(physicalPath, options);
                DeserializationFinished(targetDatabase);

                return;
            }

            LoadTreePaths(physicalPath, options);
        }
コード例 #5
0
ファイル: SerializedDatabase.cs プロジェクト: kamsar/Rhino
        private string GetPhysicalPath(ItemReference reference)
        {
            Assert.ArgumentNotNull(reference, "reference");

            // note: there is no overload of GetFilePath() that takes a custom root - so we use GetDirectoryPath and add the extension like GetFilePath does
            return(PathUtils.GetDirectoryPath(reference.ToString(), _serializationPath) + PathUtils.Extension);
        }
コード例 #6
0
ファイル: PresetWorker.cs プロジェクト: sobek85/Console
 public int Deserialize(LoadOptions options)
 {
     processed = 0;
     var reference = new ItemReference(entry.Database, entry.Path);
     if (entry is SingleEntry)
     {
         Manager.LoadItem(PathUtils.GetFilePath(reference.ToString()), options);
         processed++;
     }
     else
     {
         var messagesInit = MessageCount;
         Manager.LoadItem(PathUtils.GetFilePath(reference.ToString()), options);
         Manager.LoadTree(PathUtils.GetDirectoryPath(reference.ToString()), options);
         processed += (MessageCount - messagesInit);
     }
     return processed;
 }
コード例 #7
0
        public int Deserialize(LoadOptions options)
        {
            processed = 0;
            var reference = new ItemReference(entry.Database, entry.Path);

            if (entry is SingleEntry)
            {
                Manager.LoadItem(PathUtils.GetFilePath(reference.ToString()), options);
                processed++;
            }
            else
            {
                var messagesInit = MessageCount;
                Manager.LoadItem(PathUtils.GetFilePath(reference.ToString()), options);
                Manager.LoadTree(PathUtils.GetDirectoryPath(reference.ToString()), options);
                processed += (MessageCount - messagesInit);
            }
            return(processed);
        }
コード例 #8
0
        private SyncItem ReadSerializedVersion(Item item)
        {
            Assert.IsNotNull(item, "Item cannot be null");

            var reference = new ItemReference(item);
            var path      = PathUtils.GetFilePath(reference.ToString());

            if (!File.Exists(path))
            {
                return(null);
            }

            using (var file = new StreamReader(path))
            {
                return(SyncItem.ReadItem(new Tokenizer(file)));
            }
        }
コード例 #9
0
        private void SerializeToTarget(Item item, string target, bool recursive)
        {
            if (!string.IsNullOrEmpty(target) && ItemPathsAbsolute.IsPresent)
            {
                target = target.EndsWith("\\")
                    ? target + item.Parent.Paths.FullPath.Replace("/", "\\")
                    : target + "\\" + item.Parent.Paths.FullPath.Replace("/", "\\");
            }

            var message = string.Format("Serializing item '{0}' to target '{1}'", item.Name, target);

            WriteVerbose(message);
            WriteDebug(message);

            var fileName = target;

            if (string.IsNullOrEmpty(fileName))
            {
                var itemReference = new ItemReference(item);
                fileName = PathUtils.GetFilePath(itemReference.ToString());
            }
            if (!ShouldProcess(item.GetProviderPath(), string.Format("Serializing item to '{0}'", fileName)))
            {
                return;
            }

            if (string.IsNullOrEmpty(target))
            {
                Manager.DumpItem(item);
            }
            else
            {
                target = target.EndsWith("\\") ? target + item.Name : target + "\\" + item.Name;
                Manager.DumpItem(target + ".item", item);
            }
            if (recursive)
            {
                foreach (Item child in item.GetChildren(ChildListOptions.IgnoreSecurity))
                {
                    SerializeToTarget(child, target, true);
                }
            }
        }
コード例 #10
0
        protected override void Process(WriteItemHeaderPipeline pipeline)
        {
            var status = 0;

            try
            {
                var reference = new ItemReference(pipeline.Item);
                var path      = PathUtils.GetFilePath(reference.ToString());

                if (FileUtil.FileExists(path))
                {
                    status = GetStatus(pipeline.Item, path);
                }
            }
            catch
            {
                status = 3;
            }

            pipeline.Output.WriteAttributeString("serializationstatus", status.ToString(CultureInfo.InvariantCulture));
        }
コード例 #11
0
        public string Execute([NotNull] string id, [NotNull] string databaseName)
        {
            Assert.ArgumentNotNull(id, nameof(id));
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));

            var database = Factory.GetDatabase(databaseName);

            if (database == null)
            {
                throw new Exception("Database not found");
            }

            var item = database.GetItem(id);

            if (item == null)
            {
                throw new Exception("Item not found");
            }

            var reference = new ItemReference(item);

            return(PathUtils.GetFilePath(reference.ToString()));
        }
コード例 #12
0
ファイル: ImportItemCommand.cs プロジェクト: sobek85/Console
 public void Deserialize(Item item)
 {
     var reference = new ItemReference(item);
     if (Recurse.IsPresent)
     {
         var path = PathUtils.GetDirectoryPath(reference.ToString());
         Deserialize(path);
     }
     else
     {
         var path = PathUtils.GetFilePath(reference.ToString());
         Deserialize(path);
     }
 }
コード例 #13
0
        private SyncItem ReadSerializedVersion(Item item)
        {
            Assert.IsNotNull(item, "Item cannot be null");

            var reference = new ItemReference(item);
            var path = PathUtils.GetFilePath(reference.ToString());

            if (!File.Exists(path)) return null;

            using (var file = new StreamReader(path))
            {
                 return SyncItem.ReadItem(new Tokenizer(file));
            }
        }
コード例 #14
0
ファイル: SerializedDatabase.cs プロジェクト: Vittel/Rhino
		private string GetPhysicalPath(ItemReference reference)
		{
			Assert.ArgumentNotNull(reference, "reference");

			// note: there is no overload of GetFilePath() that takes a custom root - so we use GetDirectoryPath and add the extension like GetFilePath does
			return PathUtils.GetDirectoryPath(reference.ToString(), _serializationPath) + PathUtils.Extension;
		}
コード例 #15
0
        protected override string BuildPackage()
        {
            var project = new PackageProject();

            var sourceCollection = new SourceCollection <PackageEntry>();

            var itemSource = new ExplicitItemSource
            {
                SkipVersions = false
            };

            sourceCollection.Add(itemSource);

            var list = new List <ID>();

            foreach (var item in Items)
            {
                var i = item;
                if (list.Any(id => id == i.ID))
                {
                    continue;
                }

                list.Add(item.ID);

                var reference = new ItemReference(item.Database.Name, item.Paths.Path, item.ID, LanguageManager.DefaultLanguage, Data.Version.Latest).Reduce();

                itemSource.Entries.Add(reference.ToString());
            }

            var fileSource = new ExplicitFileSource();

            sourceCollection.Add(fileSource);

            foreach (var fileName in Files)
            {
                if (FileUtil.IsFolder(fileName))
                {
                    foreach (var file in Directory.GetFiles(FileUtil.MapPath(fileName), "*", SearchOption.AllDirectories))
                    {
                        var fileInfo = new FileInfo(file);
                        if ((fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                        {
                            continue;
                        }

                        if ((fileInfo.Attributes & FileAttributes.System) == FileAttributes.System)
                        {
                            continue;
                        }

                        fileSource.Entries.Add(file);
                    }
                }
                else
                {
                    fileSource.Entries.Add(fileName);
                }
            }

            project.Sources.Add(sourceCollection);

            project.Name = "Sitecore Package";
            project.Metadata.PackageName = PackageName;
            project.Metadata.Author      = Author;
            project.Metadata.Version     = Version;
            project.Metadata.Publisher   = Publisher;
            project.Metadata.License     = License;
            project.Metadata.Comment     = Comment;
            project.Metadata.Readme      = Readme;
            project.Metadata.PostStep    = PostStep;

            var context          = new SimpleProcessingContext();
            var intermediateFile = GetIntermediateFileName(FileName);

            try
            {
                using (var writer = new PackageWriter(PathUtils.MapPath(intermediateFile)))
                {
                    writer.Initialize(context);
                    PackageGenerator.GeneratePackage(project, writer);
                }

                Commit(intermediateFile, FileName);
            }
            catch
            {
                Cleanup(intermediateFile);
                throw;
            }

            return(FileName);
        }