コード例 #1
0
ファイル: ContentVersion.cs プロジェクト: Biswo/n2cms
        internal static ContentItem Deserialize(Importer importer, IUrlParser parser, string xml)
        {
            if (importer == null)
                throw new ArgumentException("Importer cannot be null.", "importer");
            
            if (parser == null)
                throw new ArgumentException("Parser cannot be null.", "parser");

            if (String.IsNullOrEmpty(xml))
                return null; // nothing to deserialize

            var journal = importer.Read(new StringReader(xml));
            foreach (var link in journal.UnresolvedLinks.Where(ul => ul.IsChild == false))
            {
                var item = importer.Persister.Get(link.ReferencedItemID);
                if (item != null)
                    link.Setter(item);
            }

            if (journal.ReadItems == null)
                throw new Exception("Journal couldn't read items due to journal.ReadItems == null. " + xml);

            try
            {
                foreach (var item in journal.ReadItems)
                    (item as IInjectable<IUrlParser>).Set(parser);
            }
            catch (NullReferenceException nilX)
            {
                throw new Exception("Ran into a null reference while attempting to read items from the journal: " + xml, nilX);
            }

            if (journal.RootItem == null)
                return null;

            if (journal.RootItem.VersionOf.HasValue && journal.RootItem.VersionOf.Value != null)
                journal.RootItem.Parent = journal.RootItem.VersionOf.Parent;

            ReorderBySortOrderRecursive(journal.RootItem);

            return journal.RootItem;
        }
コード例 #2
0
ファイル: ContentVersion.cs プロジェクト: jupeterson/n2cms
		internal static ContentItem Deserialize(Importer importer, IUrlParser parser, string xml)
		{
			var journal = importer.Read(new StringReader(xml));
			foreach (var link in journal.UnresolvedLinks.Where(ul => ul.IsChild == false))
			{
				var item = importer.Persister.Get(link.ReferencedItemID);
				if (item != null)
					link.Setter(item);
			}
			foreach (var item in journal.ReadItems)
				(item as IInjectable<IUrlParser>).Set(parser);
			return journal.RootItem;
		}
コード例 #3
0
        /* public void WriteFile(string name, string data)
        {
            var path = Path.Combine(_path, name);

            using (var ms = new MemoryStream())
            {
                var bytes = Encoding.UTF8.GetBytes(data);
                ms.Write(bytes, 0, bytes.Length);
                ms.Position = 0;
                _fs.WriteFile(path, ms);
            }
        } */

        public IImportRecord SyncItem(ReplicatedItem item)
        {
            lock (this)
            {
                try
                {
                    var reader = new ItemXmlReader(_definitions, _activator, _persister.Repository);
                    var importer = new Importer(null, reader, null);

                    // TODO download
                    var ins = _fs.OpenFile(item.Path, true);
                    var record = importer.Read(ins, item.Path);
                    if (record.RootItem != null)
                        ContentVersion.ReorderBySortOrderRecursive(record.RootItem);
                    return record;
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("IMPORT Error: {0} - {1}", item.ID, ex.Message), ex);
                    throw;
                }
            }
        }