示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }