public bool Load(string loadFileName = null) { bool success = true; string filename = loadFileName ?? _storeSettings.StoreFileName; ResumeStoreContext resumeContext = null; if (!File.Exists(filename)) { success = false; } else { try { resumeContext = filename.GetObjectFromJsonFile <ResumeStoreContext>(_storeSettings.JsonSerializerSettings); } catch { success = false; } } if (!success || resumeContext.ContainerContextCollection.Count == 0) { resumeContext = InitDefaultStoreContext(); } var loadedContainers = InitMdiContainers(resumeContext); _windowsManager.LoadContainers(loadedContainers); return(success); }
private ResumeStoreContext InitContext(IEnumerable <IMdiContainerViewModel> containers) { ResumeStoreContext context = new ResumeStoreContext("admin"); foreach (var container in containers) { var containerContext = (container as IStorable <ContainersStoreContext>).InitStoreContext(); var storableWindows = container.WindowsCollection .Where(w => w is IStorable <WindowsStoreContext>) .Select(w => (IStorable <WindowsStoreContext>)w); foreach (var window in storableWindows) { var windowsStoreContext = window.InitStoreContext(); containerContext.WindowsContextCollection.Add(windowsStoreContext); } context.ContainerContextCollection.Add(containerContext); } return(context); }
private IList <IMdiContainerViewModel> InitMdiContainers(ResumeStoreContext resumeContext) { List <IMdiContainerViewModel> loadedContainers = new List <IMdiContainerViewModel>(); foreach (ContainersStoreContext containerContext in resumeContext.ContainerContextCollection) { var container = (MdiContainerViewModelBase)_windowsFactory.CreateContainer(containerContext.ViewModelType); container.LoadFromStoreContext(containerContext); foreach (var windowContext in containerContext.WindowsContextCollection) { var window = (IMdiWindowViewModel)_windowsFactory.CreateWindow(windowContext.ViewModelType); window.Container = container; container.WindowsCollection.Add(window); (window as IStorable <WindowsStoreContext>).LoadFromStoreContext(windowContext); } loadedContainers.Add(container); } return(loadedContainers); }
private ResumeStoreContext InitDefaultStoreContext() { ResumeStoreContext context = new ResumeStoreContext("admin"); Type continerType = Assembly.GetEntryAssembly().FindDerivedTypes <MdiContainerViewModelBase>().First(); if (continerType == null) { throw new ArgumentNullException("Didn't find type inheriting MdiContainerViewModelBase"); } for (int i = 1; i <= 3; i++) { ContainersStoreContext containersStoreContext = new ContainersStoreContext() { Guid = Guid.NewGuid(), ViewModelType = continerType, IsSelected = i == 1 ? true : false, Title = $"DefaultTab {i}" }; context.ContainerContextCollection.Add(containersStoreContext); } return(context); }