public static void AddToDefaultView(FieldSetting fieldSetting, ContentList contentList) { if (fieldSetting == null || contentList == null) return; var iv = LoadDefaultView(contentList) as IView; if (iv == null) return; var viewNode = iv as Node; if (viewNode == null) return; //if the view is global, create local copy first if (!viewNode.Path.StartsWith(contentList.Path)) { viewNode = ViewManager.CopyViewLocal(contentList.Path, viewNode.Path, true); iv = viewNode as IView; } fieldSetting.Owner = ContentType.GetByName("ContentList"); iv.AddColumn(new Column { FullName = fieldSetting.FullName, BindingName = fieldSetting.BindingName, Title = fieldSetting.DisplayName, Index = iv.GetColumns().Count() + 1 }); viewNode.Save(); }
// Returns the node itself cast to ContentList if it's a ContentList, or the // ContentList containing the node. public static ContentList GetContentListForNode(Node n) { ContentList result = n as ContentList; if (result == null && n != null) { result = n.LoadContentList() as ContentList; } return(result); }
public SlotTable(Dictionary <string, List <string> > bindings) { _slotTable = new Dictionary <DataType, List <int> >(); _currentSlots = new Dictionary <DataType, int>(); foreach (DataType dataType in Enum.GetValues(typeof(DataType))) { _slotTable.Add(dataType, new List <int>()); _currentSlots.Add(dataType, -1); } foreach (string key in bindings.Keys) { foreach (string binding in bindings[key]) { DataType dataType; int ordinalNumber; ContentList.DecodeBinding(binding, out dataType, out ordinalNumber); _slotTable[dataType].Add(ordinalNumber); } } }
public static File LoadDefaultView(ContentList list) { return LoadView(list, list.DefaultView); }
//=================================================================== IViewManager Members void IViewManager.AddToDefaultView(FieldSetting fieldSetting, ContentList contentList) { AddToDefaultView(fieldSetting, contentList); }
public void ContentList_FieldNameCannotContainsADot() { string path = RepositoryPath.Combine(this._testRoot.Path, "Cars"); if (Node.Exists(path)) Node.ForceDelete(path); //---- valid string listTypeDef = @"<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields><ContentListField name='#Valid_Field_Name' type='ShortText'/></Fields> </ContentListDefinition> "; var list = new ContentList(this._testRoot); list.Name = "Cars"; list.ContentListDefinition = listTypeDef; list.Save(); var validIsExist = Node.LoadNode(path) != null; if (validIsExist) Node.ForceDelete(path); Assert.IsTrue(validIsExist, "#1"); //---- invalid listTypeDef = @"<ContentType name=""Valid_ContentType_Namee"" parentType=""GenericContent"" handler=""SenseNet.ContentRepository.GenericContent"" xmlns=""http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition""> <Fields><Field name=""Invalid.Field.Name"" type=""ShortText"" /></Fields> </ContentType>"; bool exceptionIsThrown = false; bool validExceptionIsThrown = false; try { list = new ContentList(this._testRoot); list.Name = "Cars"; list.ContentListDefinition = listTypeDef; list.Save(); exceptionIsThrown = false; } catch (ContentRegistrationException e) { exceptionIsThrown = true; validExceptionIsThrown = true; } catch (Exception e) { exceptionIsThrown = true; } var invalidIsExist = Node.LoadNode(path) != null; if (invalidIsExist) Node.ForceDelete(path); Assert.IsTrue(exceptionIsThrown, "#2"); Assert.IsTrue(validExceptionIsThrown, "#3"); Assert.IsFalse(invalidIsExist, "#4"); }