コード例 #1
0
ファイル: AppConfig.cs プロジェクト: BerndGit/Kamban
        public AppConfig(IMonik m)
        {
            mon = m;

            // C:\Users\myuser\AppData\Roaming (travel with user profile)
            appConfigPath  = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            appConfigPath += @"\Kamban\kamban.config";

            FileInfo file = new FileInfo(appConfigPath);

            file.Directory.Create();

            if (file.Exists)
            {
                string data = File.ReadAllText(appConfigPath);
                appConfig = JsonConvert.DeserializeObject <AppConfigJson>(data);
            }
            else
            {
                appConfig = new AppConfigJson();
            }

            appConfig.StartNumber++;
            SaveConfig();

            recentList = new SourceList <RecentViewModel>();
            recentList.AddRange(appConfig.Feed.Select(x => new RecentViewModel
            {
                Uri = x.Uri, LastAccess = x.LastAccess, Pinned = x.Pinned
            }));

            RecentObservable = recentList.Connect().AutoRefresh();

            publicBoards = new SourceList <PublicBoardJson>();
            publicBoards
            .Connect()
            .Bind(out ReadOnlyObservableCollection <PublicBoardJson> temp)
            .Subscribe();

            PublicBoards = temp;

            GetStarted = this.WhenAnyValue(x => x.GetStartedValue);
            Basement   = this.WhenAnyValue(x => x.BasementValue);
        }
コード例 #2
0
ファイル: AppConfig.cs プロジェクト: malickf/Kamban
        public AppConfig(IShell sh, ILogger l)
        {
            shell = sh;
            log   = l;

            appConfigPath = GetRomaingPath("kamban.config");
            FileInfo file = new FileInfo(appConfigPath);

            if (file.Exists)
            {
                string data = File.ReadAllText(appConfigPath);

                try
                {
                    appConfig = JsonConvert.DeserializeObject <AppConfigJson>(data);
                }
                catch (Exception ex) { }

                if (appConfig == null)
                {
                    appConfig = new AppConfigJson();
                }
                if (string.IsNullOrEmpty(appConfig.AppGuid))
                {
                    appConfig.AppGuid = Guid.NewGuid().ToString();
                }
            }
            else
            {
                appConfig         = new AppConfigJson();
                appConfig.AppGuid = Guid.NewGuid().ToString();
            }

            OpenLatestAtStartupValue = appConfig.OpenLatestAtStartup;
            ShowFileNameInTabValue   = appConfig.ShowFileNameInTab;
            ColorThemeValue          = appConfig.ColorTheme;
            appConfig.StartNumber++;
            SaveConfig();

            recentList = new SourceList <RecentViewModel>();
            recentList.AddRange(appConfig.Feed.Select(x => new RecentViewModel
            {
                Uri = x.Uri, LastAccess = x.LastAccess, Pinned = x.Pinned
            }));

            RecentObservable = recentList.Connect().AutoRefresh();

            publicBoards = new SourceList <PublicBoardJson>();
            publicBoards
            .Connect()
            .Bind(out ReadOnlyObservableCollection <PublicBoardJson> temp)
            .Subscribe();

            PublicBoards = temp;

            GetStarted = this.WhenAnyValue(x => x.GetStartedValue);
            Basement   = this.WhenAnyValue(x => x.BasementValue);
            OpenLatestAtStartupObservable = this.WhenAnyValue(x => x.OpenLatestAtStartupValue);
            ShowFileNameInTabObservable   = this.WhenAnyValue(x => x.ShowFileNameInTabValue);
            ColorThemeObservable          = this.WhenAnyValue(x => x.ColorThemeValue);
            // Manage current opened boards for raise on next startup

            shell.DockingManager.ActiveContentChanged += (s, e) =>
            {
                var view = shell.DockingManager.ActiveContent as BoardView;
                if (view == null)
                {
                    return;
                }
                var vm = view.ViewModel as BoardEditViewModel;
                if (vm.Box == null)
                {
                    return;
                }
                if (!appConfig.LatestOpenedAtStartup.Contains(vm.Box.Uri))
                {
                    appConfig.LatestOpenedAtStartup.Add(vm.Box.Uri);
                }
                SaveConfig();
            };

            shell.DockingManager.DocumentClosed += (s, e) =>
            {
                var view = e.Document.Content as BoardView;
                if (view == null)
                {
                    return;
                }

                var vm = view.ViewModel as BoardEditViewModel;
                appConfig.LatestOpenedAtStartup.Remove(vm.Box.Uri);
                SaveConfig();
            };
        }