Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="selectedIndex">Index of the configuration item to edit (if -1, new creattion)</param>
        public SandboxConfigEditorViewModel(int selectedIndex = -1)
        {
            model = (App.Current as App)?.Model;
            if (model == null)
            {
                throw new Exception($"Failed to get reference of model instance on the {GetType()} class.");
            }
            this.selectedIndex = selectedIndex;
            IsNew = selectedIndex <= -1;
            if (IsNew)
            {
                EditingItem = new WSBConfigManagerModel {
                    Name = resourceLoader.GetString("NewSandboxName")
                };
            }
            else
            {
                EditingItem = new WSBConfigManagerModel(model.WSBConfigCollection[selectedIndex]);
                foreach (var mf in EditingItem.MappedFolders)
                {
                    EditingMappedFolders.Add(mf);
                }
            }

            model.PropertyChanged += (sender, e) => PropertyChanged?.Invoke(sender, e);
        }
 public void Execute(object parameter)
 {
     viewModel.ImportSandboxConfingAction?.Invoke(
         async(file, exportErrorCallback) => {
         try {
             using (var s = await file.OpenStreamForReadAsync())
                 using (var sr = new StreamReader(s)) {
                     var importModel = WSBConfigManagerModel.Import(sr);
                     if (string.IsNullOrEmpty(importModel.Name))
                     {
                         importModel.Name = Path.GetFileNameWithoutExtension(file.Name);
                     }
                     viewModel.model.WSBConfigCollection.Add(importModel);
                 }
         }
         catch (Exception) {
             exportErrorCallback?.Invoke();
         }
     }
         );
 }