示例#1
0
        private Settings SelectAll()
        {
            if (SettingCache == null)
            {
                SettingCache = new Settings();
            }

            using (var statement = this.conn.Prepare(DML_SETTINGS_READ))
            {
                while (statement.Step() == SQLitePCL.SQLiteResult.ROW)
                {
                    SettingCache.Add(new Setting()
                    {
                        Code  = statement.GetText("CODE"),
                        Value = statement["VALUE"],
                        Type  = statement.GetText("TYPE"),
                        Attr1 = statement["ATTR1"] != null ? statement.GetText("ATTR1") : null,
                        Attr2 = statement["ATTR2"] != null ? statement.GetText("ATTR2") : null,
                    });
                }
            }

            var general   = new Settings.GeneralSetting(SettingCache);
            var playback  = new Settings.PlaybackSetting(SettingCache);
            var subtitle  = new Settings.ClosedCaptionSetting(SettingCache);
            var privacy   = new Settings.PrivacySetting(SettingCache);
            var server    = new Settings.ServerSetting(SettingCache);
            var thumbnail = new Settings.ThumbnailSetting(SettingCache);

            if (SettingCache.Count == 0)
            {
                //최초 상태이면 fal 초기화
                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Clear();

                //디폴트 값 등록
                //일반
                general.ResetDefaultValue();
                //재생
                playback.ResetDefaultValue();
                //자막
                subtitle.ResetDefaultvalue();
                //개인설정
                privacy.ResetDefaultValue();
                //서버
                server.ResetDefaultValue();
                //썸네일
                thumbnail.ResetDefaultValue();

                try
                {
                    using (var stmt = this.conn.Prepare(TCL_BEGIN)) { stmt.Step(); }
                    using (var custstmt = this.conn.Prepare(DML_SETTINGS_CREATE))
                    {
                        foreach (var setting in SettingCache)
                        {
                            //if (setting.Code == "ForegroundColor")
                            //    System.Diagnostics.Debugger.Break();
                            //System.Diagnostics.Debug.WriteLine(setting.Code + " " + setting.Value + " " + setting.Type + " " + setting.Attr1 + " " + setting.Attr2);
                            custstmt.Bind("@CODE", setting.Code);
                            custstmt.Bind("@VALUE", setting.Value);
                            custstmt.Bind("@TYPE", setting.Type);
                            custstmt.Bind("@ATTR1", setting.Attr1);
                            custstmt.Bind("@ATTR2", setting.Attr2);

                            var result = custstmt.Step();
                            if (result != SQLitePCL.SQLiteResult.DONE)
                            {
                                throw new Exception();
                            }

                            // Resets the statement, to that it can be used again (with different parameters).
                            custstmt.Reset();
                            custstmt.ClearBindings();
                        }
                    }
                    using (var stmt = this.conn.Prepare(TCL_COMMIT)) { stmt.Step(); }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write("Settings 데이터의 DB 저장이 실패함!!!! : " + ex.Message);
                    using (var stmt = this.conn.Prepare(TCL_ROLLBACK)) { stmt.Step(); }
                }
            }

            return(SettingCache);
        }
示例#2
0
        public Settings SelectAll()
        {
            if (SettingCache == null)
            {
                SettingCache = new Settings();
            }

            using (var statement = this.conn.Prepare(DML_SETTINGS_READ))
            {
                while (statement.Step() == SQLitePCL.SQLiteResult.ROW)
                {
                    SettingCache.Add(new Setting()
                    {
                        Code  = statement.GetText("CODE"),
                        Value = statement["VALUE"],
                        Type  = statement.GetText("TYPE"),
                        Attr1 = statement["ATTR1"] != null ? statement.GetText("ATTR1") : null,
                        Attr2 = statement["ATTR2"] != null ? statement.GetText("ATTR2") : null,
                    });
                }
            }

            var general  = new Settings.GeneralSetting(SettingCache);
            var playback = new Settings.PlaybackSetting(SettingCache);
            var subtitle = new Settings.SubtitleSetting(SettingCache);

            if (SettingCache.Count == 0)
            {
                //최초 상태이면 fal 초기화
                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Clear();

                //디폴트 값 등록
                //일반
                general.ResetDefaultValue();
                //재생
                playback.ResetDefaultValue();
                //자막
                subtitle.ResetDefaultvalue();

                try
                {
                    using (var stmt = this.conn.Prepare(TCL_BEGIN)) { stmt.Step(); }
                    using (var custstmt = this.conn.Prepare(DML_SETTINGS_CREATE))
                    {
                        foreach (var setting in SettingCache)
                        {
                            custstmt.Bind("@CODE", setting.Code);
                            custstmt.Bind("@VALUE", setting.Value);
                            custstmt.Bind("@TYPE", setting.Type);
                            custstmt.Bind("@ATTR1", setting.Attr1);
                            custstmt.Bind("@ATTR2", setting.Attr2);
                            if (custstmt.Step() != SQLitePCL.SQLiteResult.DONE)
                            {
                                throw new Exception();
                            }

                            // Resets the statement, to that it can be used again (with different parameters).
                            custstmt.Reset();
                            custstmt.ClearBindings();
                        }
                    }
                    using (var stmt = this.conn.Prepare(TCL_COMMIT)) { stmt.Step(); }
                }
                catch (Exception)
                {
                    using (var stmt = this.conn.Prepare(TCL_ROLLBACK)) { stmt.Step(); }
                }
            }

            return(SettingCache);
        }