示例#1
0
 public bool SetMetadata(SNC.Content content, string currentDirectory, bool isNewContent, bool needToValidate, bool updateReferences)
 {
     if (_xmlDoc == null)
         return true;
     _transferringContext = new ImportContext(
         _xmlDoc.SelectNodes("/ContentMetaData/Fields/*"), currentDirectory, isNewContent, needToValidate, updateReferences);
     bool result = content.ImportFieldData(_transferringContext);
     _contentId = content.ContentHandler.Id;
     return result;
 }
示例#2
0
        internal bool UpdateReferences(SNC.Content content, bool needToValidate)
        {
            if (_transferringContext == null)
                _transferringContext = new ImportContext(_xmlDoc.SelectNodes("/ContentMetaData/Fields/*"), null, false, needToValidate, true);
            else
                _transferringContext.UpdateReferences = true;

            var node = content.ContentHandler;
            node.NodeModificationDate = node.NodeModificationDate;
            node.ModificationDate = node.ModificationDate;
            node.NodeModifiedBy = node.NodeModifiedBy;
            node.ModifiedBy = node.ModifiedBy;

            if (!content.ImportFieldData(_transferringContext))
                return false;
            if (!HasPermissions && !HasBreakPermissions)
                return true;
            var permissionsNode = _xmlDoc.SelectSingleNode("/ContentMetaData/Permissions");
            content.ContentHandler.Security.ImportPermissions(permissionsNode, this._metaDataPath);

            return true;
        }
示例#3
0
文件: Field.cs 项目: sztomi/sensenet
 /// <summary>
 /// For old-way-import
 /// </summary>
 /// <param name="fieldNode"></param>
 /// <param name="context"></param>
 protected abstract void ImportData(XmlNode fieldNode, ImportContext context);
示例#4
0
		private static bool SetMetadata(SnC.Content snContent, Content content, bool isNewContent, bool updateReferences)
		{
			XmlDocument xml = new XmlDocument();
			xml.LoadXml(content.Data);
			var context = new ImportContext(xml.SelectNodes("/ContentMetaData/Fields/*"), null, isNewContent, true, updateReferences);
			bool result = snContent.ImportFieldData(context);
			var contentId = snContent.ContentHandler.Id;
			content.HasReference = context.HasReference;
			return result;
		}
示例#5
0
文件: Field.cs 项目: sztomi/sensenet
        /*========================================================================= Import - Export */

        /// <summary>
        /// For old-way-import
        /// </summary>
        /// <param name="fieldNode"></param>
        /// <param name="context"></param>
        internal void Import(XmlNode fieldNode, ImportContext context)
        {
            ImportData(fieldNode, context);
        }
示例#6
0
        /// <summary>
        /// For old-way-import
        /// </summary>
        /// <param name="fieldNode"></param>
        /// <param name="context"></param>
		protected abstract void ImportData(XmlNode fieldNode, ImportContext context);
示例#7
0
		/*========================================================================= Import - Export */

        /// <summary>
        /// For old-way-import
        /// </summary>
        /// <param name="fieldNode"></param>
        /// <param name="context"></param>
		internal void Import(XmlNode fieldNode, ImportContext context)
		{
			ImportData(fieldNode, context);
		}
示例#8
0
        protected virtual void BuildSearchForm()
        {
            if (string.IsNullOrEmpty(SearchFormCtd))
                return;
            var nt = (from t in ActiveSchema.NodeTypes
                      where t.NodeTypePath.Equals(SearchFormCtd.Remove(0, 33))
                      select t).FirstOrDefault();
            if (nt == null) return;
            
            var c = Content.CreateNew(nt.Name, Repository.Root, null);
                
            var s = State;

            if (_state != null && !string.IsNullOrWhiteSpace(_state.ExportQueryFields))
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(_state.ExportQueryFields);
                XmlNodeList allFields = xmlDoc.SelectNodes("/ContentMetaData/Fields/*");
                var transferringContext = new ImportContext(allFields, "", c.Id == 0, true, false);
                //import flat properties
                c.ImportFieldData(transferringContext, false);
                //update references
                transferringContext.UpdateReferences = true;
                c.ImportFieldData(transferringContext, false);
            }

            //override content filed from url parameters
            foreach (KeyValuePair<string, Field> keyValuePair in c.Fields)
            {
                var portletSpecKey = GetPortletSpecificParamName(keyValuePair.Key);
                var requestValue = GetValueFromRequest(portletSpecKey);
                
                if (!string.IsNullOrEmpty(requestValue) && c.Fields.ContainsKey(keyValuePair.Key))
                        c.Fields[keyValuePair.Key].Parse(requestValue);
            }

            var cv = string.IsNullOrEmpty(SearchFormRenderer)
                         ? ContentView.Create(c, this.Page, ViewMode.InlineNew)
                         : ContentView.Create(c, this.Page, ViewMode.InlineNew, SearchFormRenderer);

            //Attach search event
            var iCsView = cv as IContentSearchView;
            if (iCsView != null)
            {
                iCsView.Search += new EventHandler(ContentSearchView_Search_OnClick);
            }
            else
            {
                var btn = cv.FindControl(SearchBtnId) as Button;
                if (btn == null)
                {
                    btn = new Button {ID = SearchBtnId, Text = SenseNetResourceManager.Current.GetString(ResourceCalssName, "SearchBtnText"), CssClass = "sn-submit"};
                    cv.Controls.Add(btn);
                }
                btn.Click += new EventHandler(ContentSearchView_Search_OnClick);
            }
            SearchForm = cv;
        }
示例#9
0
文件: Put.cs 项目: maxpavlov/FlexNet
        private void HandleContent(string parentPath, string fileName, Node parentNode, Node node)
        {
            Content content = null;
            var contentXml = new XmlDocument();
            string contentString = Tools.GetStreamString(_handler.Context.Request.InputStream);

            if (!string.IsNullOrEmpty(contentString))
            {
                contentXml.LoadXml(contentString);

                //new content or previously uploded binary exists!
                if (node == null || node is IFile)
                {
                    string ctName = contentXml.SelectSingleNode("/ContentMetaData/ContentType").InnerText;

                    if (node == null || ctName.CompareTo(node.NodeType.Name) != 0)
                    {
                        var nodeType = ActiveSchema.NodeTypes[ctName];
                        node = nodeType.CreateInstance(parentNode);
                        node.Name = fileName;
                    }
                }

                content = Content.Create(node);

                XmlNodeList allFields = contentXml.SelectNodes("/ContentMetaData/Fields/*");
                XmlNodeList binaryFields = contentXml.SelectNodes("/ContentMetaData/Fields/*[@attachment]");

                //set attachments first
                foreach (XmlNode field in binaryFields)
                {
                    string attachmentName = field.Attributes["attachment"].Value;
                    var attachment = Node.LoadNode(RepositoryPath.Combine(parentPath, attachmentName)) as SN.File;

                    //previously uploaded attachment found
                    if (attachment != null && attachment.Id != node.Id)
                    {
                        attachment.Name = Guid.NewGuid().ToString();
                        attachment.Save();

                        SetBinaryStream(content.ContentHandler, attachment.Binary.GetStream(), field.Name, attachmentName);
                        attachment.Delete();
                    }
                }

                var transferringContext = new ImportContext(allFields, "", node.Id == 0, true, false);

                //import flat properties
                content.ImportFieldData(transferringContext);

                //update references
                transferringContext.UpdateReferences = true;
                content.ImportFieldData(transferringContext);
            }

            _handler.Context.Response.StatusCode = 200;
        }