Exemple #1
0
 /// <summary>
 /// Removes a specified <see cref="PresetModel"/> object from the preset collection of the workspace.
 /// </summary>
 /// <param name="workspace"></param>
 /// <param name="state"><see cref="PresetModel"/> object to remove.</param>
 internal static void RemovePreset(this WorkspaceModel workspace, PresetModel state)
 {
     if (workspace.Presets.Contains(state))
     {
         workspace.presets.Remove(state);
     }
 }
        public async Task UpdatePresetByNameAsync(PresetModel presetModel)
        {
            try
            {
                List <PresetModel> presetModels = await _storageService.LoadAsync <List <PresetModel> >(Constants.PresetsKey);

                if (presetModels == null || presetModels.Count == 0)
                {
                    await AddPresetAsync(presetModel);

                    return;
                }
                var updating = presetModels.Find(x => x.Name == presetModel.Name);
                if (updating != null)
                {
                    await RemovePresetAsync(updating.id);

                    updating.FirstPanel  = presetModel.FirstPanel;
                    updating.SecondPanel = presetModel.SecondPanel;
                    updating.ThirdPanel  = presetModel.ThirdPanel;
                    await AddPresetAsync(updating);
                }
                else
                {
                    await AddPresetAsync(presetModel);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("UpdatePresetByNameAsync");
                Debug.WriteLine(ex.Message);
            }
        }
        private static void LoadPresets()
        {
            if (LoadPresets(out var list))
            {
                _presets = new PresetList();

                foreach (var item in list)
                {
                    item.GetValues(item);
                    if (item.Name.Length != 0 && !_presets.Contains(item))
                    {
                        _presets.Add(item);
                    }
                }

                var index = _presets.IndexOf(_defaultPreset);
                if (index == -1)
                {
                    _presets.Add(_defaultPreset);
                }
                else
                {
                    _defaultPreset = _presets[index];
                }

                CollectionHelper.Sort(_presets);
            }
        }
Exemple #4
0
        private static PresetModel PresetFromXml(XmlElement stateNode, IEnumerable <NodeModel> nodesInNodeGraph)
        {
            var instance = new PresetModel(nodesInNodeGraph);

            instance.Deserialize(stateNode, SaveContext.File);
            return(instance);
        }
Exemple #5
0
        public void BuildPresetList(XmlNode node)
        {
            PresetModel model = new PresetModel()
            {
                Ids = new List <string>()
            };

            model.Name                   = node.Attributes["name"].Value;
            model.Desc                   = node.Attributes["desc"].Value;
            model.BulkUpdate             = node.Attributes["bulkUpdate"]?.Value != null ? node.Attributes["bulkUpdate"]?.Value == "true" : model.BulkUpdate;
            model.Children               = node.Attributes["children"]?.Value != null ? node.Attributes["children"]?.Value == "true" : model.Children;
            model.Overwrite              = node.Attributes["overwrite"]?.Value != null ? node.Attributes["overwrite"]?.Value == "true" : model.Overwrite;
            model.EventDisabler          = node.Attributes["eventDisabler"]?.Value != null ? node.Attributes["eventDisabler"]?.Value == "true" : model.EventDisabler;
            model.PullParent             = node.Attributes["pullParent"]?.Value != null ? node.Attributes["pullParent"]?.Value == "true" : model.PullParent;
            model.RemoveLocalNotInRemote = node.Attributes["removeLocalNotInRemote"]?.Value != null ? node.Attributes["removeLocalNotInRemote"]?.Value == "true" : model.RemoveLocalNotInRemote;
            model.IgnoreRevId            = node.Attributes["ignoreRevId"]?.Value != null ? node.Attributes["ignoreRevId"]?.Value == "true" : model.IgnoreRevId;
            model.UseItemBlaster         = node.Attributes["useItemBlaster"]?.Value != null ? node.Attributes["useItemBlaster"]?.Value == "true" : model.UseItemBlaster;

            foreach (XmlNode xml in node.ChildNodes)
            {
                if (xml.Name.ToLower() == "serverblacklist")
                {
                    model.BlackList.Add(xml.InnerText.Trim('/'));
                }
                else if (xml.Name.ToLower() == "serverwhitelist")
                {
                    model.WhiteList.Add(xml.InnerText.Trim('/'));
                }
                else if (xml.Name.ToLower() == "source")
                {
                    model.Ids.Add(xml.InnerText.Trim());
                }
            }
            PresetList.Add(model.Name, model);
        }
 private void EditPreset(Window window, PresetModel preset)
 {
     preset = _dialogService.EditPreset(window, preset);
     if (preset != null)
     {
         Image.Preset = preset;
     }
 }
Exemple #7
0
 public override void OnNavigatingTo(NavigationParameters parameters)
 {
     base.OnNavigatingTo(parameters);
     if (parameters.TryGetValue("Preset", out PresetModel presetModel))
     {
         PresetModel = presetModel;
     }
 }
        public void RemovePreset(PresetModel preset)
        {
            if (preset == _defaultPreset)
            {
                throw new InvalidOperationException("Cannot remove default preset.");
            }

            _presets.Remove(preset);
        }
Exemple #9
0
        private void SavePreset()
        {
            PresetModel presetModel;

            if (PresetName == null)
            {
                presetModel = SelectedPresetModel;
            }
            else
            {
                var endpointModel = _settingsStorage
                                    .GetValue <string>(SettingsKeys.Endpoint)
                                    .FromJson <EndpointModel>(JsonConverter);

                presetModel = new PresetModel
                {
                    Name = PresetName,
                    Uri  = endpointModel.Uri
                };

                PresetModels.Add(presetModel);
                PresetModels = PresetModels.ToList();

                SelectedPresetModel = presetModel;
            }

            foreach (var quadCell in QuadCellViewModels.Select((vm, i) => new { vm, i }))
            {
                presetModel.ProfileTokens[quadCell.i] = quadCell.vm.SelectedProfileModel?.Token;
            }

            var presetModels = _settingsStorage
                               .GetValue <string>(SettingsKeys.Presets)?
                               .FromJson <ICollection <PresetModel> >(JsonConverter) ?? new List <PresetModel>();

            var savedPresetModel = presetModels.SingleOrDefault(pm => pm.Id == presetModel.Id);

            if (savedPresetModel != null)
            {
                savedPresetModel.Uri           = presetModel.Uri;
                savedPresetModel.Name          = presetModel.Name;
                savedPresetModel.ProfileTokens = presetModel.ProfileTokens;
            }
            else
            {
                presetModels.Add(presetModel);
            }

            _settingsStorage.AddOrUpdateValue(SettingsKeys.Presets, presetModels.ToJson(JsonConverter));

            var toastMesage = new ToastMessage(this, "Saved");

            Messenger.Publish(toastMesage);

            PresetName = null;
        }
        public string BrowseBoot(Window owner, PresetModel preset, BootType type)
        {
            using (var dialog = new FileOpenDialog())
            {
                const string BiosFileName = "etfsboot.com";
                const string UefiFileName = "efisys.bin";

                string bootFolderPath;
                string bootFileName;
                string bootFileExtension;
                string extension;
                string clientGuid;
                string title;
                string fileName;

                if (type == BootType.Bios)
                {
                    GetFilePathInfo(preset.BiosBoot, out bootFolderPath, out bootFileName, out bootFileExtension);
                    extension  = Path.GetExtension(BiosFileName);
                    clientGuid = "E8BEE349-1A4A-4E04-B8B9-B15FF1EF9125";
                    title      = "BIOS";
                    fileName   = bootFileName ?? BiosFileName;
                }
                else if (type == BootType.Uefi)
                {
                    GetFilePathInfo(preset.UefiBoot, out bootFolderPath, out bootFileName, out bootFileExtension);
                    extension  = Path.GetExtension(UefiFileName);
                    clientGuid = "A6A65946-6FCD-4DCA-AEB1-85ABF5FE3CAE";
                    title      = "UEFI";
                    fileName   = bootFileName ?? UefiFileName;
                }
                else
                {
                    throw new InvalidOperationException("The specified boot type is not implemented.");
                }

                dialog.SetClientGuid(new Guid(clientGuid));
                dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                dialog.SetTitle($"{title} boot sector file");
                dialog.SetFileTypes($"Boot files (*{extension})|*{extension}|All files (*.*)|*.*");
                dialog.SetFileName(fileName);
                dialog.SetFileTypeIndex(bootFileExtension == null || bootFileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase) ? 1 : 2);
                dialog.SetOkButtonLabel("Select");
                dialog.SetCancelButtonLabel("Cancel");
                dialog.SetFileNameLabel("Boot sector file :");
                dialog.DontAddToRecent = true;

                if (PathHelper.DirectoryExists(bootFolderPath))
                {
                    dialog.SetFolder(bootFolderPath);
                }

                return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null);
            }
        }
        public PresetModel EditPreset(Window owner, PresetModel preset)
        {
            var viewModel = new PresetViewModel(preset);
            var view      = new PresetView {
                Owner = owner, DataContext = viewModel
            };

            view.ShowDialog();

            return(viewModel.GetResult());
        }
        public override void ExecuteCommand(string userId, string command)
        {
            ServerPresetsStatus vncData = deserialize.Deserialize <ServerPresetsStatus>(command);

            if (vncData == null)
            {
                return;
            }

            List <PresetModel> presetList = new List <PresetModel>();

            foreach (PresetsEntry entry in vncData.UserPresetList)
            {
                List <ApplicationModel> appList = new List <ApplicationModel>();
                foreach (ApplicationEntry appEntry in entry.ApplicationList)
                {
                    ApplicationModel appModel = new ApplicationModel()
                    {
                        AppliationId    = appEntry.Identifier,
                        ApplicationName = appEntry.Name,
                    };
                    appList.Add(appModel);
                }

                List <VncModel> vncList = new List <VncModel>();
                foreach (VncEntry vncEntry in entry.VncList)
                {
                    VncModel vncModel = new VncModel()
                    {
                        Identifier    = vncEntry.Identifier,
                        DisplayName   = vncEntry.DisplayName,
                        VncServerIp   = vncEntry.IpAddress,
                        VncServerPort = vncEntry.Port,
                    };

                    vncList.Add(vncModel);
                }

                PresetModel model = new PresetModel()
                {
                    PresetId        = entry.Identifier,
                    PresetName      = entry.Name,
                    ApplicationList = appList,
                    VncList         = vncList,
                    VisionInputList = entry.InputList,
                };

                presetList.Add(model);
            }

            ApplicationSettings.GetInstance().PresetList = vncData.UserPresetList;
            client.RefreshPresetList(presetList);
        }
        public void AddPreset(PresetModel preset)
        {
            if (preset.HasErrors)
            {
                throw new InvalidOperationException("Cannot add a preset with errors.");
            }

            if (PresetExists(preset))
            {
                throw new InvalidOperationException("Cannot add an existing preset.");
            }

            var index = CollectionHelper.BinarySearch(_presets, preset);

            _presets.Insert(~index, preset);
        }
Exemple #14
0
        /// <summary>
        ///  this method creates a new preset state from a set of NodeModels and adds this new state to this presets collection
        /// </summary>
        /// <param name="workspace"></param>
        /// <param name="name">the name of preset state</param>
        /// <param name="description">a description of what the state does</param>
        /// <param name="currentSelection">a set of NodeModels that are to be serialized in this state</param>
        private static PresetModel AddPresetCore(this WorkspaceModel workspace, string name, string description, IEnumerable <NodeModel> currentSelection)
        {
            if (currentSelection == null || currentSelection.Count() < 1)
            {
                throw new ArgumentException("currentSelection is empty or null");
            }
            var inputs = currentSelection;

            var newstate = new PresetModel(name, description, inputs);

            if (workspace.Presets.Any(x => x.GUID == newstate.GUID))
            {
                throw new ArgumentException("duplicate id in collection");
            }

            workspace.presets.Add(newstate);
            return(newstate);
        }
Exemple #15
0
        internal static bool ApplyPreset(this WorkspaceModel workspace, PresetModel state)
        {
            if (state == null)
            {
                return(false);
            }

            //start an undoBeginGroup
            using (var undoGroup = workspace.UndoRecorder.BeginActionGroup())
            {
                //reload each node, and record each each modification in the undogroup
                foreach (var node in state.Nodes)
                {
                    //check that node still exists in this workspace,
                    //otherwise bail on this node, check by GUID instead of nodemodel
                    if (workspace.Nodes.Select(x => x.GUID).Contains(node.GUID))
                    {
                        var originalpos    = node.Position;
                        var serializedNode = state.SerializedNodes.ToList().Find(x => Guid.Parse(x.GetAttribute("guid")) == node.GUID);
                        //overwrite the xy coords of the serialized node with the current position, so the node is not moved
                        serializedNode.SetAttribute("x", originalpos.X.ToString(CultureInfo.InvariantCulture));
                        serializedNode.SetAttribute("y", originalpos.Y.ToString(CultureInfo.InvariantCulture));
                        serializedNode.SetAttribute("isPinned", node.PreviewPinned.ToString());

                        workspace.UndoRecorder.RecordModificationForUndo(node);
                        workspace.ReloadModel(serializedNode);
                    }
                }
                //select all the modified nodes in the UI
                DynamoSelection.Instance.ClearSelection();
                foreach (var node in state.Nodes)
                {
                    DynamoSelection.Instance.Selection.Add(node);
                }
            }

            return(true);
        }
        public PresetViewModel(PresetModel preset, IPresetService presetService, IDialogService dialogService)
        {
            BrowseBiosCommand = new DelegateCommand <Window>(BrowseBiosAction);
            BrowseUefiCommand = new DelegateCommand <Window>(BrowseUefiAction);
            ResetBiosCommand  = new DelegateCommand(ResetBiosAction);
            ResetUefiCommand  = new DelegateCommand(ResetUefiAction);
            SaveCommand       = new DelegateCommand <IClosable>(SaveAction, CanSaveAction);
            CancelCommand     = new DelegateCommand <IClosable>(CancelAction);

            _preset        = preset;
            _presetService = presetService;
            _dialogService = dialogService;

            IsNewPreset    = !_presetService.PresetExists(_preset);
            NameReadOnly   = !IsNewPreset;
            NameBackground = IsNewPreset ? _BackgroundWhite : _BackgroundGray;

            Preset = new PresetModel();
            Preset.PropertyChanged += PresetPropertyChanged;
            Preset.GetValues(_preset);

            WindowTitle = IsNewPreset ? "Add Preset" : "Edit Preset";
        }
        public async Task AddPresetAsync(PresetModel presetModel)
        {
            try
            {
                List <PresetModel> presetModels = await _storageService.LoadAsync <List <PresetModel> >(Constants.PresetsKey);

                if (presetModels == null)
                {
                    presetModels = new List <PresetModel>();
                }
                var res = presetModels.Where(x => x.id == presetModel.id);
                if (!res.Any())
                {
                    presetModels.Add(presetModel);
                    await _storageService.SaveAsync <List <PresetModel> >(Constants.PresetsKey, presetModels);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("AddPresetAsync");
                Debug.WriteLine(ex.Message);
            }
        }
Exemple #18
0
        public override void ExecuteCommand(string userId, string command)
        {
            ServerPresetsStatus vncData = deserialize.Deserialize <ServerPresetsStatus>(command);

            if (vncData == null)
            {
                return;
            }

            List <PresetModel> presetList = new List <PresetModel>();

            foreach (PresetsEntry entry in vncData.UserPresetList)
            {
                List <ApplicationModel> appList = new List <ApplicationModel>();
                foreach (ApplicationEntry appEntry in entry.ApplicationList)
                {
                    ApplicationModel appModel = new ApplicationModel()
                    {
                        AppliationId    = appEntry.Identifier,
                        ApplicationName = appEntry.Name,
                    };
                    appList.Add(appModel);
                }

                PresetModel model = new PresetModel()
                {
                    PresetId        = entry.Identifier,
                    PresetName      = entry.Name,
                    ApplicationList = appList,
                };

                presetList.Add(model);
            }

            client.RefreshPresetList(presetList);
        }
Exemple #19
0
 public void RemovePreset(PresetModel state)
 {
     if (Presets.Contains(state))
     {
         presets.Remove(state);
     }
 }
Exemple #20
0
        /// <summary>
        ///  this method creates a new preset state from a set of NodeModels and adds this new state to this presets collection
        /// </summary>
        /// <param name="name">the name of preset state</param>
        /// <param name="description">a description of what the state does</param>
        /// <param name="currentSelection">a set of NodeModels that are to be serialized in this state</param>
        /// <param name="id">a GUID id for the state, if not supplied, a new GUID will be generated, cannot be a duplicate</param>
        private PresetModel AddPresetCore(string name, string description, IEnumerable<NodeModel> currentSelection)
        {
            if (currentSelection == null || currentSelection.Count() < 1)
            {
                throw new ArgumentException("currentSelection is empty or null");
            }
            var inputs = currentSelection;

            var newstate = new PresetModel(name, description, inputs);
            if (Presets.Any(x => x.GUID == newstate.GUID))
            {
                throw new ArgumentException("duplicate id in collection");
            }

            presets.Add(newstate);
            return newstate;
        }
 public bool PresetExists(PresetModel preset)
 {
     return(_presets.Contains(preset));
 }
Exemple #22
0
        /// <summary>
        /// Creates <see cref="ModelBase"/> object by given xml data and
        /// adds it to corresponding collection of the workspace.
        /// </summary>
        /// <param name="modelData">Xml data to create model</param>
        public void CreateModel(XmlElement modelData)
        {
            var    helper   = new XmlElementHelper(modelData);
            string typeName = helper.ReadString("type", String.Empty);

            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto
                // the name of the XmlElement itself, which is usually the type
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                              string.Format("No type information: {0}", guid));
                }
            }

            if (typeName.Contains("ConnectorModel"))
            {
                var connector = NodeGraph.LoadConnectorFromXml(modelData,
                                                               Nodes.ToDictionary(node => node.GUID));

                // It is possible that in some cases connector can't be created,
                // for example, connector connects to a custom node instance
                // whose input ports have been changed, so connector can't find
                // its end port owner.
                if (connector == null)
                {
                    var guidAttribute = modelData.Attributes["guid"];
                    if (guidAttribute == null)
                    {
                        throw new InvalidOperationException("'guid' field missing from recorded model");
                    }
                }
                else
                {
                    OnConnectorAdded(connector); // Update view-model and view.
                }
            }
            else if (typeName.Contains("NoteModel"))
            {
                var noteModel = NodeGraph.LoadNoteFromXml(modelData);
                AddNote(noteModel);

                //check whether this note belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this note "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == noteModel.GUID))
                    {
                        annotation.AddToSelectedModels(noteModel);
                    }
                }
            }
            else if (typeName.Contains("AnnotationModel"))
            {
                var selectedNodes = this.Nodes == null ? null : this.Nodes.Where(s => s.IsSelected);
                var selectedNotes = this.Notes == null ? null : this.Notes.Where(s => s.IsSelected);

                var annotationModel = new AnnotationModel(selectedNodes, selectedNotes);
                annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
                annotationModel.Disposed           += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
                annotationModel.Deserialize(modelData, SaveContext.Undo);
                AddNewAnnotation(annotationModel);
            }

            else if (typeName.Contains("PresetModel"))
            {
                var preset = new PresetModel(this.Nodes);
                preset.Deserialize(modelData, SaveContext.Undo);
                presets.Add(preset);
                //we raise this property change here so that this event bubbles up through
                //the model and to the DynamoViewModel so that presets show in the UI menu if our undo/redo
                //created the first preset
                RaisePropertyChanged("EnablePresetOptions");
            }
            else // Other node types.
            {
                NodeModel nodeModel = NodeFactory.CreateNodeFromXml(modelData, SaveContext.Undo, ElementResolver);

                AddAndRegisterNode(nodeModel);

                //check whether this node belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this node "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == nodeModel.GUID))
                    {
                        annotation.AddToSelectedModels(nodeModel);
                    }
                }
            }
        }
 public PresetNotExistError(IPresetService svc, PresetModel value, [CallerMemberName] string propertyName = null)
 {
     HasError     = !svc.PresetExists(value);
     ErrorMessage = "This preset does not exist.";
     PropertyName = propertyName;
 }
Exemple #24
0
 private static PresetModel PresetFromXml(XmlElement stateNode, IEnumerable <NodeModel> nodesInNodeGraph, ILogger logger)
 {
     return(PresetModel.LoadFromXml(stateNode, nodesInNodeGraph, logger));
 }
 public PresetViewModel(PresetModel preset) : this(preset, new PresetService(), new DialogService())
 {
 }
Exemple #26
0
        internal void ApplyPreset(PresetModel state)
        {
            if (state == null)
            {
                Log("Attempted to apply a PresetState that was null");
                return;
            }
            //start an undoBeginGroup
            using (var undoGroup = this.undoRecorder.BeginActionGroup())
            {
               //reload each node, and record each each modification in the undogroup
                foreach (var node in state.Nodes)
                {
                    //check that node still exists in this workspace, 
                    //otherwise bail on this node, check by GUID instead of nodemodel
                    if (nodes.Select(x=>x.GUID).Contains(node.GUID))
                    {
                        var originalpos = node.Position;
                        var serializedNode = state.SerializedNodes.ToList().Find(x => Guid.Parse(x.GetAttribute("guid")) == node.GUID);
                        //overwrite the xy coords of the serialized node with the current position, so the node is not moved
                        serializedNode.SetAttribute("x", originalpos.X.ToString(CultureInfo.InvariantCulture));
                        serializedNode.SetAttribute("y", originalpos.Y.ToString(CultureInfo.InvariantCulture));

                        this.undoRecorder.RecordModificationForUndo(node);
                        this.ReloadModel(serializedNode);
                    }
                }
                //select all the modified nodes in the UI
                DynamoSelection.Instance.ClearSelection();
                foreach(var node in state.Nodes)
                {
                    DynamoSelection.Instance.Selection.Add(node);
                }
            }
        }
Exemple #27
0
 public PresetDetailsViewModel(INavigationService navigationService, IAppSettingsManager appSettingsManager) : base(navigationService)
 {
     _appSettingsManager = appSettingsManager;
     _PresetModel        = new PresetModel(0, 0);
 }
Exemple #28
0
        public void CreateModel(XmlElement modelData)
        {
            var helper = new XmlElementHelper(modelData);
            string typeName = helper.ReadString("type", String.Empty);
            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto 
                // the name of the XmlElement itself, which is usually the type 
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                        string.Format("No type information: {0}", guid));
                }
            }

            /*
            if (typeName.Equals("Dynamo.Graph.Nodes.ZeroTouch.DSFunction") ||
                typeName.Equals("Dynamo.Graph.Nodes.ZeroTouch.DSVarArgFunction"))
            {
                // For DSFunction and DSVarArgFunction node types, the type name
                // is actually embedded within "name" attribute (for an example,
                // "UV.ByCoordinates@double,double").
                // 
                typeName = modelData.Attributes["name"].Value;
            }
            */

            if (typeName.Contains("ConnectorModel"))
            {
                var connector = NodeGraph.LoadConnectorFromXml(modelData,
                    Nodes.ToDictionary(node => node.GUID));

                // It is possible that in some cases connector can't be created,
                // for example, connector connects to a custom node instance
                // whose input ports have been changed, so connector can't find
                // its end port owner.
                if (connector == null)
                {
                    var guidAttribute = modelData.Attributes["guid"];
                    if (guidAttribute == null)
                    {
                        throw new InvalidOperationException("'guid' field missing from recorded model");
                    }
                    undoRecorder.RecordModelAsOffTrack(Guid.Parse(guidAttribute.Value)); 
                }
                else 
                {
                    OnConnectorAdded(connector); // Update view-model and view.
                }
            }
            else if (typeName.Contains("NoteModel"))
            {
                var noteModel = NodeGraph.LoadNoteFromXml(modelData);
                AddNote(noteModel);

                //check whether this note belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this note "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == noteModel.GUID))
                    {
                        annotation.AddToSelectedModels(noteModel);
                    }
                }
            }
            else if (typeName.Contains("AnnotationModel"))
            {
                var selectedNodes = this.Nodes == null ? null : this.Nodes.Where(s => s.IsSelected);
                var selectedNotes = this.Notes == null ? null : this.Notes.Where(s => s.IsSelected);

                var annotationModel = new AnnotationModel(selectedNodes, selectedNotes);
                annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
                annotationModel.Disposed += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
                annotationModel.Deserialize(modelData, SaveContext.Undo);
                AddNewAnnotation(annotationModel);
            }

            else if (typeName.Contains("PresetModel"))
            {
                var preset = new PresetModel(this.Nodes);
                preset.Deserialize(modelData, SaveContext.Undo);
                presets.Add(preset);
                //we raise this property change here so that this event bubbles up through
                //the model and to the DynamoViewModel so that presets show in the UI menu if our undo/redo
                //created the first preset
                RaisePropertyChanged("EnablePresetOptions");
               
            }
            else // Other node types.
            {
                NodeModel nodeModel = NodeFactory.CreateNodeFromXml(modelData, SaveContext.Undo, ElementResolver);
                
                AddAndRegisterNode(nodeModel);
                
                //check whether this node belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this node "was" in a group
                    if (annotation.DeletedModelBases.Any(m=>m.GUID == nodeModel.GUID))
                    {
                        annotation.AddToSelectedModels(nodeModel);
                    }
                }
            }
        }
        private IList <ObjectStoreModel> GetAvailableObjectStores(
            [NotNull] IInstancePool instancePool,
            [NotNull] IDataProvider dataProvider)
        {
            if (instancePool == null)
            {
                throw new ArgumentNullException(nameof(instancePool));
            }

            if (dataProvider == null)
            {
                throw new ArgumentNullException(nameof(dataProvider));
            }

            const string profileDirectoryName = "Profiles";

            var profileDirectory = WorkingDirectory.GetChildStore(profileDirectoryName, true);
            var generators       = GetModelGenerators().AsList();
            var objectStores     = new List <ObjectStoreModel>();

            foreach (var generator in generators)
            {
                var profileModel = new PresetModel
                {
                    Key         = generator.Key,
                    DisplayName = generator.DisplayName,
                    Generator   = generator,
                    IconStore   = generator.Icons
                };

                instancePool.Register(profileModel);
                objectStores.Add(profileModel);
            }

            if (WorkingDirectory.HasChildStore(profileDirectoryName))
            {
                var profiles = profileDirectory.GetChildStoreKeys();
                var messages = new List <string>();

                foreach (var storageKey in profiles)
                {
                    var currentProfileDirectory = profileDirectory.GetChildStore(storageKey);
                    if (!currentProfileDirectory.ContainsKey("profile.json"))
                    {
                        continue;
                    }

                    try
                    {
                        const string dataDirectoryName  = "Data";
                        const string iconsDirectoryName = "Icons";

                        var profileModel = dataProvider.Read <ProfileModel>(currentProfileDirectory.Open("profile.json"));
                        if (profileModel == null)
                        {
                            continue;
                        }

                        profileModel.DataStore = currentProfileDirectory.GetChildStore(dataDirectoryName);
                        profileModel.IconStore = currentProfileDirectory.GetChildStore(iconsDirectoryName);

                        instancePool.Register(profileModel);
                        objectStores.Add(profileModel);
                    }
                    catch (Exception exception)
                    {
                        messages.Add($"{storageKey}: {exception.GetOriginalMessage()}");
                    }
                }

                if (messages.Any())
                {
                    Dialog.Error(string.Join("\r\n", messages)).Display();
                }
            }

            return(objectStores);
        }