private void LoadNode(IModelType type) { if (type.GetType() == typeof(Folder)) { _view.AddFolderTreeNode((Folder)type, type.ParentId); foreach (IModelType child in ((Folder)type).Children) { LoadNode(child); } } else if (type.GetType() == typeof(Bookmark)) { _view.AddBookmarkTreeNode((Bookmark)type, type.ParentId); } }
private static JsonSchema ParseType(Property property, IModelType type, IDictionary <string, JsonSchema> definitions, IEnumerable <CompositeType> modelTypes) { JsonSchema result = null; if (property == null || !property.IsReadOnly) { // A schema that matches a JSON object with specific properties, such as // { "name": { "type": "string" }, "age": { "type": "number" } } CompositeType compositeType = type as CompositeType; if (compositeType != null) { result = ParseCompositeType(property, compositeType, true, definitions, modelTypes); } else { // A schema that matches a "dictionary" JSON object, such as // { "additionalProperties": { "type": "string" } } DictionaryType dictionaryType = type as DictionaryType; if (dictionaryType != null) { result = ParseDictionaryType(property, dictionaryType, definitions, modelTypes); } else { // A schema that matches a single value from a given set of values, such as // { "enum": [ "a", "b" ] } EnumType enumType = type as EnumType; if (enumType != null) { result = ParseEnumType(property, enumType); } else { // A schema that matches simple values, such as { "type": "number" } PrimaryType primaryType = type as PrimaryType; if (primaryType != null) { result = ParsePrimaryType(property, primaryType); } else { // A schema that matches an array of values, such as // { "items": { "type": "number" } } SequenceType sequenceType = type as SequenceType; if (sequenceType != null) { result = ParseSequenceType(property, sequenceType, definitions, modelTypes); } else { Debug.Fail("Unrecognized property type: " + type.GetType()); } } } } } } return(result); }
private IModelType GetModelTypeById(IModelType type, string id) { if (id == null) { return(null); } if (type.Id == id) { return(type); } if (type.GetType() == typeof(Bookmark)) { return(null); } foreach (IModelType t in ((Folder)type).Children) { IModelType t2 = GetModelTypeById(t, id); if (t2 != null) { return(t2); } } return(null); }
private void AddNewFolder(object sender, AddFolderEventArgs e) { IModelType parentNode = GetModelTypeById(e.ParentId, _bookmarksTree); string parentId = parentNode == null ? null : parentNode.Id; string id = Guid.NewGuid().ToString(); Folder folder = new Folder(e.Label, id, parentId); if (string.IsNullOrEmpty(e.ParentId)) { _bookmarksTree.Bookmarks.Add(folder); } else { if (parentNode.GetType() == typeof(Folder)) { ((Folder)parentNode).Children.Add(folder); } else { return; } } _view.AddFolderTreeNode(folder, e.ParentId); _bookmarksTree.WriteToFile("bookmarks.xml"); }
private void AddNewBookmark(object sender, AddBookmarkEventArgs e) { IModelType parentNode = GetModelTypeById(e.ParentID, _bookmarksTree); string parentId = parentNode == null ? null : parentNode.Id; string id = Guid.NewGuid().ToString(); Bookmark bookmark = new Bookmark(e.URL, e.Label, id, parentId); if (string.IsNullOrEmpty(e.ParentID)) { _bookmarksTree.Bookmarks.Add(bookmark); } else { if (parentNode.GetType() == typeof(Folder)) { ((Folder)parentNode).Children.Add(bookmark); } else { return; } } _view.AddBookmarkTreeNode(bookmark, e.ParentID); _view.LabelText = ""; _view.UrlText = ""; _bookmarksTree.WriteToFile("bookmarks.xml"); }
public static SchemaObject Create(IModelType type) { if (type == null) { return(null); } switch (type) { case CompositeType compositeType: return(new SchemaObject(@ref: "#/definitions/" + compositeType.SerializedName)); case EnumType enumType: return(String(@enum: enumType.Values.Select(v => v.SerializedName))); case PrimaryType primaryType: return(Primary(primaryType)); case DictionaryType dictionaryType: return(Object(additionalProperties: Create(dictionaryType.ValueType))); case SequenceType sequenceType: return(new SchemaObject( type: "array", items: Create(sequenceType.ElementType))); default: throw new Exception("unknown type: " + type.Name + ", typetype: " + type.GetType()); } }
private void RemoveNode(object sender, RemoveNodeEventArgs e) { if (string.IsNullOrWhiteSpace(e.IdToRemove)) { return; } IModelType nodeToRemove = GetModelTypeById(e.IdToRemove, _bookmarksTree); bool isNodeToRemoveAFolder = nodeToRemove.GetType() == typeof(Folder); IModelType parentNode = GetModelTypeById(nodeToRemove.ParentId, _bookmarksTree); bool isParentAFolder = parentNode == null ? true : parentNode.GetType() == typeof(Folder); if (!isParentAFolder) { return; } if (isNodeToRemoveAFolder) { bool isFolderEmpty = ((Folder)nodeToRemove).Children.Count() == 0; if (!isFolderEmpty) { var diagResult = _dialogService.ShowMessageBox( "Remove folder?", "Deleting this folder will delete all children. Continue?", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning ); if (diagResult != System.Windows.Forms.DialogResult.OK) { return; } } } else { var diagResult = _dialogService.ShowMessageBox( "Delete node?", "There is no going back. Continue?", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning); if (diagResult != System.Windows.Forms.DialogResult.OK) { return; } } if (parentNode == null) { _bookmarksTree.Bookmarks.Remove(nodeToRemove); } else { Folder parentFolder = (Folder)GetModelTypeById(nodeToRemove.ParentId, _bookmarksTree); parentFolder.Children.Remove(nodeToRemove); } _view.RemoveNodeFromTree(e.IdToRemove); _bookmarksTree.WriteToFile("bookmarks.xml"); }
/// <summary> /// Determines whether the specified model type is structurally equal to this object. /// </summary> /// <param name="other">The object to compare with this object.</param> /// <returns>true if the specified object is functionally equal to this object; otherwise, false.</returns> public virtual bool StructurallyEquals(IModelType other) { if (ReferenceEquals(other, null)) { return(false); } return(GetType() == other.GetType() && Name.Equals(other.Name)); }
private void OpenBookmarkInBrowser(object sender, OpenBookmarkEventArgs e) { IModelType typeToOpen = GetModelTypeById(e.IdToOpen, _bookmarksTree); if (typeToOpen.GetType() != typeof(Bookmark)) { return; } URLOpener opener = new URLOpener(Browser.Chrome); opener.Open(((Bookmark)typeToOpen).Url); }
private IModelType CloneChildNode(IModelType node) { IModelType model = (IModelType)node.Clone(); if (model.GetType() == typeof(Folder)) { foreach (IModelType child in ((Folder)node).Children) { IModelType clonedChild = CloneChildNode(child); ((Folder)model).Children.Add(clonedChild); } } return(model); }
private static JsonSchema ParseType(Property property, IModelType type, IDictionary <string, JsonSchema> definitions, IEnumerable <CompositeType> modelTypes) { if (property == null || !property.IsReadOnly) { // A schema that matches a JSON object with specific properties, such as // { "name": { "type": "string" }, "age": { "type": "number" } } if (type is CompositeType compositeType) { return(ParseCompositeType(property, compositeType, true, definitions, modelTypes)); } // A schema that matches a "dictionary" JSON object, such as // { "additionalProperties": { "type": "string" } } if (type is DictionaryType dictionaryType) { return(ParseDictionaryType(property, dictionaryType, definitions, modelTypes)); } // A schema that matches a single value from a given set of values, such as // { "enum": [ "a", "b" ] } if (type is EnumType enumType) { return(ParseEnumType(property, enumType)); } // A schema that matches simple values, such as { "type": "number" } if (type is PrimaryType primaryType) { return(ParsePrimaryType(property, primaryType)); } // A schema that matches an array of values, such as // { "items": { "type": "number" } } if (type is SequenceType sequenceType) { return(ParseSequenceType(property, sequenceType, definitions, modelTypes)); } // A schema that matches anything if (type is MultiType) { return(new JsonSchema()); } Debug.Fail("Unrecognized property type: " + type.GetType()); } return(null); }
private void FilterChildren(string query, IModelType node, ref BookmarksTree tree) { bool isFolder = node.GetType() == typeof(Folder); if (isFolder) { if (node.Label.ToLower().Contains(query.ToLower())) { return; } Folder folder = (Folder)node; foreach (IModelType child in folder.Children.ToList()) { FilterChildren(query, child, ref tree); } if (folder.Children.Count != 0) { return; } } if (!node.Label.ToLower().Contains(query.ToLower())) { if (string.IsNullOrEmpty(node.ParentId)) { tree.Bookmarks.Remove(node); } else { Folder parentFolder = (Folder)GetModelTypeById(node.ParentId, tree); parentFolder.Children.Remove(node); } } }
private bool IsFolder(IModelType type) { return(type.GetType() == typeof(Folder)); }
private static JsonSchema ParseType(Property property, IModelType type, IDictionary<string, JsonSchema> definitions, IEnumerable<CompositeType> modelTypes) { JsonSchema result = null; if (property == null || !property.IsReadOnly) { // A schema that matches a JSON object with specific properties, such as // { "name": { "type": "string" }, "age": { "type": "number" } } CompositeType compositeType = type as CompositeType; if (compositeType != null) { result = ParseCompositeType(property, compositeType, definitions, modelTypes); } else { // A schema that matches a "dictionary" JSON object, such as // { "additionalProperties": { "type": "string" } } DictionaryType dictionaryType = type as DictionaryType; if (dictionaryType != null) { result = ParseDictionaryType(property, dictionaryType, definitions, modelTypes); } else { // A schema that matches a single value from a given set of values, such as // { "enum": [ "a", "b" ] } EnumType enumType = type as EnumType; if (enumType != null) { result = ParseEnumType(property, enumType); } else { // A schema that matches simple values, such as { "type": "number" } PrimaryType primaryType = type as PrimaryType; if (primaryType != null) { result = ParsePrimaryType(property, primaryType); } else { // A schema that matches an array of values, such as // { "items": { "type": "number" } } SequenceType sequenceType = type as SequenceType; if (sequenceType != null) { result = ParseSequenceType(property, sequenceType, definitions, modelTypes); } else { Debug.Fail("Unrecognized property type: " + type.GetType()); } } } } } } return result; }
/// <summary> /// Determines whether the specified model type is structurally equal to this object. /// </summary> /// <param name="other">The object to compare with this object.</param> /// <returns>true if the specified object is functionally equal to this object; otherwise, false.</returns> public virtual bool StructurallyEquals(IModelType other) { if (ReferenceEquals(other, null)) { return false; } return GetType() == other.GetType() && Name.Equals(other.Name); }