Beispiel #1
0
        public override void Save()
        {
            if (!this.Path.StartsWith(Repository.ContentTypesFolderPath))
            {
                base.Save();
                return;
            }

            if (!Object.ReferenceEquals(this, ContentTypeManager.Current.GetContentTypeByName(this.Name)))
            {
                string src = this.ToXml();
                ContentTypeManager.LoadOrCreateNew(src);
            }
            else
            {
                //-- Name check
                Stream stream = this.Binary.GetStream();
                long   pos    = stream.Position;
                stream.Seek(0, SeekOrigin.Begin);
                StreamReader reader = new StreamReader(stream);
                string       xml    = reader.ReadToEnd();
                stream.Seek(pos, SeekOrigin.Begin);
                StringReader   sr       = new StringReader(xml);
                XPathDocument  xpathDoc = new XPathDocument(sr);
                XPathNavigator nav      = xpathDoc.CreateNavigator().SelectSingleNode("/*[1]/@name");
                string         name     = nav.Value;
                if (name != this.Name)
                {
                    throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_InconsistentContentTypeName, this.Name);
                }
            }
            ContentTypeManager.ApplyChanges(this);
            base.Save();
            ContentTypeManager.Current.AddContentType(this);
        }
Beispiel #2
0
        private void Install(CTD ctd)
        {
            ContentType contentType = ContentTypeManager.LoadOrCreateNew(ctd.Document);

            ContentTypeManager.ApplyChangesInEditor(contentType, _editor);
            contentType.Save(false);
            ContentTypeManager.Current.AddContentType(contentType);
        }
Beispiel #3
0
 internal static void Start()
 {
     if (_initializing)
     {
         return;
     }
     ContentTypeManager m = Current;
 }
 public override void DoAction(bool onRemote, bool isFromMe)
 {
     // Local echo of my action: Return without doing anything
     if (onRemote && isFromMe)
     {
         return;
     }
     ContentTypeManager.ResetPrivate();
 }
Beispiel #5
0
        internal static ContentTypeManager CreateForTests()
        {
            var result = new ContentTypeManager();

            result._contentPaths = new Dictionary <string, string>();
            result._contentTypes = new Dictionary <string, ContentType>();
            result.AllFieldNames = new List <string>();

            return(result);
        }
        internal static void ApplyChanges(ContentType settings)
        {
            SchemaEditor editor = new SchemaEditor();

            editor.Load();
            ApplyChangesInEditor(settings, editor);
            editor.Register();

            // The ContentTypeManager distributes its reset, no custom DistributedAction call needed
            ContentTypeManager.Reset();
        }
        private void Install(CTD ctd)
        {
            var contentType = ContentTypeManager.LoadOrCreateNew(ctd.Document);

            // skip notification during content type install to avoid missing field errors
            contentType.DisableObserver(TypeResolver.GetType(NodeObserverNames.NOTIFICATION, false));

            ContentTypeManager.ApplyChangesInEditor(contentType, _editor);
            contentType.Save(false);
            ContentTypeManager.Current.AddContentType(contentType);
        }
Beispiel #8
0
            public override STT.Task DoActionAsync(bool onRemote, bool isFromMe, CancellationToken cancellationToken)
            {
                // Local echo of my action: Return without doing anything
                if (onRemote && isFromMe)
                {
                    return(STT.Task.CompletedTask);
                }

                ContentTypeManager.ResetPrivate();

                return(STT.Task.CompletedTask);
            }
Beispiel #9
0
 private static void ResetPrivate()
 {
     lock (_syncRoot)
     {
         Logger.WriteInformation("ContentTypeManager.Reset executed.", Logger.Categories(),
                                 new Dictionary <string, object> {
             { "AppDomain", AppDomain.CurrentDomain.FriendlyName }
         });
         //-- Do not call ActiveSchema.Reset();
         _current           = null;
         _indexingInfoTable = new Dictionary <string, PerFieldIndexingInfo>();
     }
 }
Beispiel #10
0
        internal static void ApplyChanges(ContentType settings, bool reset)
        {
            SchemaEditor editor = new SchemaEditor();

            editor.Load();
            ApplyChangesInEditor(settings, editor);
            editor.Register();

            // The ContentTypeManager distributes its reset, no custom DistributedAction call needed
            if (reset)
            {
                ContentTypeManager.Reset(); // necessary (ApplyChanges) calls ContentType.Save
            }
        }
Beispiel #11
0
        private static void ResetPrivate()
        {
            lock (_syncRoot)
            {
                SnLog.WriteInformation("ContentTypeManager.Reset executed.", EventId.RepositoryRuntime,
                                       properties: new Dictionary <string, object> {
                    { "AppDomain", AppDomain.CurrentDomain.FriendlyName }
                });

                // Do not call ActiveSchema.Reset();
                _current           = null;
                _indexingInfoTable = new Dictionary <string, PerFieldIndexingInfo>();
                ContentType.OnTypeSystemRestarted();
            }
        }
        internal void RemoveContentType(string name)
        {
            // Caller: ContentType.Delete()
            lock (_syncRoot)
            {
                ContentType contentType;
                if (_contentTypes.TryGetValue(name, out contentType))
                {
                    SchemaEditor editor = new SchemaEditor();
                    editor.Load();
                    RemoveContentType(contentType, editor);
                    editor.Register();

                    // The ContentTypeManager distributes its reset, no custom DistributedAction call needed
                    ContentTypeManager.Reset();
                }
            }
        }
Beispiel #13
0
        //=======================================================================================================

        public static string TracePerFieldIndexingInfo()
        {
            var items = (from ct in ContentType.GetContentTypes()
                         from ft in ct.FieldSettings
                         select new { Name = ft.Name, ShortName = ft.ShortName }).Distinct().ToArray();
            var fsettinginfo = new Dictionary <string, string>();

            foreach (var item in items)
            {
                if (!fsettinginfo.ContainsKey(item.Name))
                {
                    fsettinginfo.Add(item.Name, item.ShortName);
                }
            }

            var sb = new StringBuilder();

            sb.AppendLine("Field\tFieldType\tMode\tStore\tTermVector\tAnalyzer\tIndexFieldHandler");
            sb.Append("[default]\t\t");
            sb.Append(PerFieldIndexingInfo.DefaultIndexingMode).Append("\t");
            sb.Append(PerFieldIndexingInfo.DefaultIndexStoringMode).Append("\t");
            sb.Append(PerFieldIndexingInfo.DefaultTermVectorStoringMode).Append("\t");
            sb.AppendLine("[null]");
            foreach (var item in ContentTypeManager.GetPerFieldIndexingInfo())
            {
                //var fs = fsettinginfo.Where(f=>f.Name==item.Key).First();
                sb.Append(item.Key).Append("\t");
                if (fsettinginfo.ContainsKey(item.Key))
                {
                    sb.Append(fsettinginfo[item.Key]).Append("\t");
                }
                else
                {
                    sb.Append("\t").Append("\t");
                }
                sb.Append(item.Value.IndexingMode).Append("\t");
                sb.Append(item.Value.IndexStoringMode).Append("\t");
                sb.Append(item.Value.TermVectorStoringMode).Append("\t");
                sb.Append((item.Value.Analyzer ?? "[null]").Replace("Lucene.Net.Analysis.", String.Empty)).Append("\t");
                sb.AppendLine(item.Value.IndexFieldHandler.GetType().FullName.Replace("SenseNet.Search.", String.Empty));
            }
            return(sb.ToString());
        }
        private void Install(Ctd ctd)
        {
            var contentType = ContentTypeManager.LoadOrCreateNew(ctd.Document);

            if (contentType.IsInvalid)
            {
                // registering a content type with an invalid handler or field is not allowed
                throw new ContentRegistrationException(
                          $"Error during installing content type {contentType.Name}. Please check the log for " +
                          "a registration error or warning.");
            }

            // skip notification during content type install to avoid missing field errors
            contentType.DisableObserver(TypeResolver.GetType(NodeObserverNames.NOTIFICATION, false));

            ContentTypeManager.ApplyChangesInEditor(contentType, _editor);
            contentType.Save(false);
            ContentTypeManager.Instance.AddContentType(contentType);
        }
Beispiel #15
0
        private void SetFieldSlots(FieldSetting fieldSetting, ISupportsDynamicFields handler)
        {
            if (fieldSetting.DataTypes.Length == 0)
            {
                return;
            }
            var handlerType = handler.GetType();

            Type[][] slots = fieldSetting.HandlerSlots;
            var      dynamicFieldMetadata = handler.GetDynamicFieldMetadata();

            for (int i = 0; i < fieldSetting.Bindings.Count; i++)
            {
                string       propName = fieldSetting.Bindings[i];
                PropertyInfo propInfo = null;
                propInfo = handlerType.GetProperty(propName);
                Type propertyType = null;
                bool readOnly     = false;
                if (propInfo != null)
                {
                    //-- code property
                    propertyType = propInfo.PropertyType;
                    readOnly     = readOnly || !ContentTypeManager.PropertyHasPublicSetter(propInfo);
                }
                else
                {
                    //-- generic property
                    propertyType = dynamicFieldMetadata[propName].PropertyType;
                    readOnly     = !dynamicFieldMetadata[propName].CanWrite;
                }
                for (int j = 0; j < slots[i].Length; j++)
                {
                    if (slots[i][j].IsAssignableFrom(propertyType))
                    {
                        fieldSetting.HandlerSlotIndices[i] = j;
                        fieldSetting.PropertyIsReadOnly    = readOnly;
                        break;
                    }
                }
            }
            fieldSetting.Initialize();
        }
Beispiel #16
0
        public void ExecuteBatch()
        {
            //-- Install considering dependencies

            if (_contentTypeCTD != null)
            {
                Install(_contentTypeCTD);
            }

            List <CTD>  docList = new List <CTD>(_docs.Values);
            Stack <CTD> stack   = new Stack <CTD>();
            CTD         parent  = null;

            while (docList.Count > 0)
            {
                CTD doc = parent ?? docList[0];
                docList.Remove(doc);
                _docs.Remove(doc.Name);
                if (_docs.ContainsKey(doc.ParentName))
                {
                    stack.Push(doc);
                    parent = _docs[doc.ParentName];
                }
                else
                {
                    Install(doc);
                    while (stack.Count > 0)
                    {
                        Install(stack.Pop());
                    }
                    parent = null;
                }
            }
            _editor.Register();

            // The ContentTypeManager distributes its reset, no custom DistributedAction call needed
            ContentTypeManager.Reset();
        }
Beispiel #17
0
		private static void ResetPrivate()
		{
			lock (_syncRoot)
			{
				Logger.WriteInformation("ContentTypeManager.Reset executed.", Logger.Categories(),
				   new Dictionary<string, object> { { "AppDomain", AppDomain.CurrentDomain.FriendlyName } });
				//-- Do not call ActiveSchema.Reset();
				_current = null;
				_indexingInfoTable = new Dictionary<string, PerFieldIndexingInfo>();
			}
		}
Beispiel #18
0
 public static void RemoveContentType(ContentType contentType)
 {
     contentType.Delete();
     // The ContentTypeManager distributes its reset, no custom DistributedAction call needed
     ContentTypeManager.Reset();
 }
Beispiel #19
0
        private void SetFieldSlots(Type handlerType)
        {
            //-- Field slot indices and readonly.
            if (handlerType == null)
            {
                throw new ContentRegistrationException(String.Concat("Unknown ContentHandler: '", this.HandlerName, "'. ContentType: ", this.Name));
            }
            foreach (FieldSetting fieldSetting in this.FieldSettings)
            {
                if (fieldSetting.DataTypes.Length == 0)
                {
                    continue;
                }
                Type[][] slots = fieldSetting.HandlerSlots;
                for (int i = 0; i < fieldSetting.Bindings.Count; i++)
                {
                    string       propName = fieldSetting.Bindings[i];
                    PropertyInfo propInfo = null;
                    propInfo = handlerType.GetProperty(propName);
                    Type propertyType = null;
                    bool readOnly     = false;
                    if (propInfo != null)
                    {
                        //-- code property
                        propertyType = propInfo.PropertyType;
                        readOnly     = readOnly || !ContentTypeManager.PropertyHasPublicSetter(propInfo);
                    }
                    else
                    {
                        //-- generic property
                        if (handlerType != typeof(GenericContent) &&
                            !handlerType.IsSubclassOf(typeof(GenericContent)))
                        {
                            throw new ContentRegistrationException(String.Concat("Unknown property: ", propName), this.Name, fieldSetting.Name);
                        }
                        RepositoryDataType dataType = fieldSetting.DataTypes[i];
                        switch (dataType)
                        {
                        case RepositoryDataType.String:
                        case RepositoryDataType.Text:
                            propertyType = typeof(string);
                            break;

                        case RepositoryDataType.Int:
                            propertyType = typeof(Int32);
                            break;

                        case RepositoryDataType.Currency:
                            propertyType = typeof(decimal);
                            break;

                        case RepositoryDataType.DateTime:
                            propertyType = typeof(DateTime);
                            break;

                        case RepositoryDataType.Binary:
                            propertyType = typeof(BinaryData);
                            break;

                        case RepositoryDataType.Reference:
                            propertyType = typeof(NodeList <Node>);
                            break;

                        default:
                            throw new ContentRegistrationException(String.Concat("Unknown datatype: ", dataType), this.Name, fieldSetting.Name);
                        }
                    }
                    for (int j = 0; j < slots[i].Length; j++)
                    {
                        ////-- for your information:
                        //typeof(Node).IsAssignableFrom(typeof(User)) ==> true
                        //typeof(User).IsAssignableFrom(typeof(Node)) ==> false
                        //-- this is the bad code:
                        //if (propertyType.IsAssignableFrom(slots[i][j]))
                        //-- this is the good:
                        if (slots[i][j].IsAssignableFrom(propertyType))
                        {
                            fieldSetting.HandlerSlotIndices[i] = j;
                            fieldSetting.PropertyIsReadOnly    = readOnly;
                            break;
                        }
                    }
                }
                fieldSetting.Initialize();
            }
        }