示例#1
0
                public static DangerSettings FromYencon(YSection section)
                {
                    bool allow    = section.GetNodeAsBoolean(KeyOfAllowDangerSettings) ?? false;
                    bool show_del = section.GetNodeAsBoolean(KeyOfShowDeleteMenu) ?? false;

                    return(new DangerSettings(allow, show_del));
                }
示例#2
0
        /// <exception cref="System.ArgumentException" />
        public virtual void ReadFrom(YSection section)
        {
            this.Logger.Trace($"executing {nameof(ProjectItem)}.{nameof(this.ReadFrom)} ({this.Name})...");

            var name = section.GetNodeAsString("Name");

            if (name == this.Name)
            {
                var hint = section.GetNodeAsString("Hint");
                if (!string.IsNullOrEmpty(hint))
                {
                    this.HintPath = new PathString(hint);
                }
            }
            else
            {
                throw new ArgumentException(string.Format(
                                                ErrorMessages.ProjectItem_ReadFrom_DoesNotMatch,
                                                this.Name,
                                                name
                                                ), nameof(section));
            }

            this.Logger.Trace($"completed {nameof(ProjectItem)}.{nameof(this.ReadFrom)} ({this.Name})...");
        }
示例#3
0
 public override void WriteTo(YSection section)
 {
     base.WriteTo(section);
     this.Logger.Trace($"executing {nameof(ItemGroup)}.{nameof(this.WriteTo)} ({this.Name})...");
     section.SetNodeAsString("FolderKind", this.Kind.ToString());
     this.Logger.Trace($"completed {nameof(ItemGroup)}.{nameof(this.WriteTo)} ({this.Name})");
 }
示例#4
0
        /// <summary>
        ///  長方形の大きさを表す型'<see cref="System.Drawing.Rectangle"/>'をヱンコンのセクションに変換します。
        /// </summary>
        /// <param name="rect">変換前の長方形です。</param>
        /// <param name="name">変換後のセクションの名前です。</param>
        /// <returns>変換後のヱンコンのセクションを表す新しいインスタンスです。</returns>
        public static YSection ToYSection(this Rectangle rect, string name = "_rect")
        {
            var section = new YSection()
            {
                Name = name
            };

            section.Add(new YNumber()
            {
                Name = "x", SInt64Value = rect.X
            });
            section.Add(new YNumber()
            {
                Name = "y", SInt64Value = rect.Y
            });
            section.Add(new YNumber()
            {
                Name = "w", SInt64Value = rect.Width
            });
            section.Add(new YNumber()
            {
                Name = "h", SInt64Value = rect.Height
            });
            return(section);
        }
示例#5
0
 public static void Adds(YSection section, string name)
 {
     section.Add(new YSection()
     {
         Name = name
     });
 }
示例#6
0
 /// <summary>
 ///  ヱンコンのセクションを長方形の大きさを表す型'<see cref="System.Drawing.Rectangle"/>'に変換します。
 /// </summary>
 /// <param name="section">変換前のセクションです。</param>
 /// <returns>変換後の長方形を表す新しいインスタンスです。</returns>
 /// <exception cref="System.ArgumentNullException">
 ///  <paramref name="section"/>が<see langword="null"/>の場合に発生します。
 /// </exception>
 public static Rectangle ToRectangle(this YSection section)
 {
     section = section ?? throw new ArgumentNullException(nameof(section));
     return(new Rectangle(
                unchecked ((int)((section.GetNode("x") as YNumber)?.SInt64Value)),
                unchecked ((int)((section.GetNode("y") as YNumber)?.SInt64Value)),
                unchecked ((int)((section.GetNode("w") as YNumber)?.SInt64Value)),
                unchecked ((int)((section.GetNode("h") as YNumber)?.SInt64Value))));
 }
示例#7
0
 public void Save()
 {
     if (!this.Metadata.IsRemoved)
     {
         var data = new YSection();
         this.Solution.WriteTo(data);
         _converter.Save(this.Folder.GetSolutionFilePath(), data);
     }
 }
示例#8
0
        /// <exception cref="System.ArgumentException" />
        public override void ReadFrom(YSection section)
        {
            base.ReadFrom(section);
            this.Logger.Trace($"executing {nameof(ItemGroup)}.{nameof(this.ReadFrom)} ({this.Name})...");
            var kind = ((FolderKind)(section.GetNodeAsNumber("FolderKind")));

            _         = kind == FolderKind.Invalid && Enum.TryParse(section.GetNodeAsString("FolderKind"), out kind);
            this.Kind = kind;
            this.Logger.Trace($"completed {nameof(ItemGroup)}.{nameof(this.ReadFrom)} ({this.Name})...");
        }
示例#9
0
        public virtual void WriteTo(YSection section)
        {
            this.Logger.Trace($"executing {nameof(ProjectItem)}.{nameof(this.WriteTo)} ({this.Name})...");

            section.SetNodeAsString("Name", this.Name);
            section.SetNodeAsString("Hint", this.HintPath);
            section.SetNodeAsString("Type", this.GetType().FullName);

            this.Logger.Trace($"completed {nameof(ProjectItem)}.{nameof(this.WriteTo)} ({this.Name})");
        }
示例#10
0
                public YSection ToYencon()
                {
                    var result = new YSection()
                    {
                        Name = KeyOfRiskySettings
                    };

                    result.SetNodeAsBoolean(KeyOfAllowDangerSettings, this.AllowDangerSettings);
                    result.SetNodeAsBoolean(KeyOfShowDeleteMenu, this.ShowDeleteMenu);
                    return(result);
                }
示例#11
0
        /// <summary>
        ///  指定されたセクションに新しい論理値を作成し追加します。
        /// </summary>
        /// <param name="section">新しい論理値の保存先のセクションです。</param>
        /// <param name="name">新しい論理値の名前です。</param>
        /// <param name="value">論理値です。</param>
        /// <returns>
        ///  新しい論理値を表すオブジェクトです。
        ///  <paramref name="name"/>が既に存在するノードと一致した場合、
        ///  またはサポートされない場合は<see langword="null"/>を返します。
        /// </returns>
        /// <exception cref="System.ArgumentNullException"/>
        /// <exception cref="CAP.Yencon.Exceptions.InvalidNodeNameException"/>
        public static YBoolean?CreateBoolean(this YSection section, string name, bool value)
        {
            section.EnsureNotNull(nameof(section));
            var result = section.CreateBoolean(name);

            if (result is not null)
            {
                result.Value = value;
            }
            return(result);
        }
示例#12
0
        /// <summary>
        ///  指定されたセクションに新しい文字列値を作成し追加します。
        /// </summary>
        /// <param name="section">新しい文字列値の保存先のセクションです。</param>
        /// <param name="name">新しい文字列値の名前です。</param>
        /// <param name="value">文字列値です。</param>
        /// <returns>
        ///  新しい文字列値を表すオブジェクトです。
        ///  <paramref name="name"/>が既に存在するノードと一致した場合、
        ///  またはサポートされない場合は<see langword="null"/>を返します。
        /// </returns>
        /// <exception cref="System.ArgumentNullException"/>
        /// <exception cref="CAP.Yencon.Exceptions.InvalidNodeNameException"/>
        public static YString?CreateString(this YSection section, string name, string value)
        {
            section.EnsureNotNull(nameof(section));
            var result = section.CreateString(name);

            if (result is not null)
            {
                result.Value = value;
            }
            return(result);
        }
示例#13
0
        /// <summary>
        ///  指定されたセクションに新しい64ビット符号無し整数値を作成し追加します。
        /// </summary>
        /// <param name="section">新しい64ビット符号無し整数値の保存先のセクションです。</param>
        /// <param name="name">新しい64ビット符号無し整数値の名前です。</param>
        /// <param name="value">64ビット符号無し整数値です。</param>
        /// <returns>
        ///  新しい64ビット符号無し整数値を表すオブジェクトです。
        ///  <paramref name="name"/>が既に存在するノードと一致した場合、
        ///  またはサポートされない場合は<see langword="null"/>を返します。
        /// </returns>
        /// <exception cref="System.ArgumentNullException"/>
        /// <exception cref="CAP.Yencon.Exceptions.InvalidNodeNameException"/>
        public static YNumber?CreateNumber(this YSection section, string name, ulong value)
        {
            section.EnsureNotNull(nameof(section));
            var result = section.CreateNumber(name);

            if (result is not null)
            {
                result.ValueU64 = value;
            }
            return(result);
        }
示例#14
0
        public static void List(YSection section)
        {
            var k = section.SubKeys;

            for (int i = 0; i < k.Length; ++i)
            {
                Console.WriteLine($"{k[i].Name}");
                Console.WriteLine($"\t{k[i].GetType().FullName}");
                Console.WriteLine($"\t{k[i].GetValue()?.ToString()}");
                Console.WriteLine(new string('-', 16));
            }
        }
示例#15
0
        private static T GetKey <T>(YSection inix, YSection cfg, string keyName, Func <T> defaultValueFactory) where T : YNode
        {
            var result = inix.GetNode(keyName) as T ?? cfg.GetNode(keyName) as T;

            if (result == null)
            {
                result      = defaultValueFactory();
                result.Name = keyName;
                cfg.Add(result);
            }
            return(result);
        }
示例#16
0
		public static void SaveTxt(string filename, YSection root)
		{
#if RELEASE
			try {
#endif
				_last_type = YenconType.Text;
				_txt_cnvtr.Save(filename, root);
#if RELEASE
			} catch (Exception e) {
				Program.ShowError(e);
			}
#endif
		}
示例#17
0
        /// <summary>
        ///  <paramref name="section"/>から数値を取得します。
        /// </summary>
        /// <param name="section">取得元の<see cref="Yencon.YSection"/>です。</param>
        /// <param name="keyname">取得する数値キーの名前です。</param>
        /// <returns>
        ///  指定された名前のノードが、
        ///  数値キーの場合はキーが保持している符号付き64ビット数値を返し、
        ///  それ以外の場合は、<c>0</c>を返します。
        /// </returns>
        public static long GetNodeAsNumber(this YSection section, string keyname)
        {
            var node = section.GetNode(keyname);

            if (node is YNumber numKey)
            {
                return(numKey.SInt64Value);
            }
            else
            {
                return(0);
            }
        }
示例#18
0
        /// <summary>
        ///  <paramref name="section"/>から論理値を取得します。
        /// </summary>
        /// <param name="section">取得元の<see cref="Yencon.YSection"/>です。</param>
        /// <param name="keyname">取得する論理値キーの名前です。</param>
        /// <returns>
        ///  指定された名前のノードが、
        ///  論理値キーの場合はキーが保持している論理値を返し、
        ///  それ以外の場合は、<see langword="null"/>を返します。
        /// </returns>
        public static bool?GetNodeAsBoolean(this YSection section, string keyname)
        {
            var node = section.GetNode(keyname);

            if (node is YBoolean flgKey)
            {
                return(flgKey.Flag);
            }
            else
            {
                return(null);
            }
        }
示例#19
0
        /// <summary>
        ///  <paramref name="section"/>から子セクションを取得します。
        /// </summary>
        /// <param name="section">取得元の<see cref="Yencon.YSection"/>です。</param>
        /// <param name="keyname">取得する子セクションの名前です。</param>
        /// <returns>
        ///  指定された名前のノードが、
        ///  子セクションの場合はそのセクションを、
        ///  それ以外の場合は<see langword="null"/>を返します。
        /// </returns>
        public static YSection GetNodeAsSection(this YSection section, string keyname)
        {
            var node = section.GetNode(keyname);

            if (node is YSection secKey)
            {
                return(secKey);
            }
            else
            {
                return(null);
            }
        }
示例#20
0
        /// <summary>
        ///  <paramref name="section"/>から文字列値を取得します。
        /// </summary>
        /// <param name="section">取得元の<see cref="Yencon.YSection"/>です。</param>
        /// <param name="keyname">取得する文字列キーの名前です。</param>
        /// <returns>
        ///  指定された名前のノードが、
        ///  文字列キーの場合はキーが保持している文字列を返し、
        ///  それ以外の場合は、キーの値を文字列に変換して返します。
        /// </returns>
        public static string GetNodeAsString(this YSection section, string keyname)
        {
            var node = section.GetNode(keyname);

            if (node is YString strKey)
            {
                return(strKey.Text);
            }
            else
            {
                return(node?.GetValue()?.ToString() ?? string.Empty);
            }
        }
示例#21
0
        public static void Set(YSection section, string type, string name, string value)
        {
#if RELEASE
            try {
#endif
            switch (type)
            {
            case "str":
                var str = new YString();
                str.Name = name;
                str.Text = value;
                section.Add(str);
                break;

            case "num":
                var num = new YNumber();
                num.Name = name;
                if (ulong.TryParse(value, out var val1))
                {
                    num.UInt64Value = val1;
                }
                section.Add(num);
                break;

            case "flg":
                var flg = new YBoolean();
                flg.Name = name;
                if (value.TryToBoolean(out var val2))
                {
                    flg.Flag = val2;
                }
                section.Add(flg);
                break;

            default:                             // case "nul"
                var nul = new YNullOrEmpty();
                nul.Name = name;
                section.Add(nul);
                break;
            }
#if RELEASE
        }

        catch (Exception e) {
            Program.ShowError(e);
        }
#endif
        }
示例#22
0
        public static void Load()
        {
            if (!_is_initialized)
            {
                throw new ObjectDisposedException(nameof(SettingManager));
            }

            {             // system
                _p_system_inix = SystemPaths.Settings.Bond("system.inix");
                _p_system_cfg  = SystemPaths.DefaultSettings.Bond("system.cfg");
                _y_system_inix = File.Exists(_p_system_inix) ? _txt_cnvtr.Load(_p_system_inix) : new YSection();
                _y_system_cfg  = File.Exists(_p_system_cfg) ? _bin_cnvtr.Load(_p_system_cfg) : new YSection();
                System.EnsureAvailable();
                _logger.Info("loaded the configuration data of \'system\'");
            }             // system
        }
示例#23
0
        public override void ReadFrom(YSection section)
        {
            base.ReadFrom(section);

            var typeName = section.GetNodeAsString("Type");

            try {
                this.Type = Type.GetType(typeName, true);
            } catch (Exception e) {
                throw new ArgumentException(string.Format(
                                                ErrorMessages.ProjectItem_ReadFrom_InvalidType,
                                                this.Name,
                                                typeName
                                                ), nameof(section), e);
            }
        }
示例#24
0
        /// <summary>
        ///  <paramref name="section"/>に文字列値を設定します。
        /// </summary>
        /// <param name="section">設定先の<see cref="Yencon.YSection"/>です。</param>
        /// <param name="keyname">設定する文字列キーの名前です。</param>
        /// <param name="value">設定する文字列です。</param>
        public static void SetNodeAsString(this YSection section, string keyname, string value)
        {
            var node = section.GetNode(keyname);

            if (node is YString strKey)
            {
                strKey.Text = value;
            }
            else
            {
                section.Add(new YString()
                {
                    Name = keyname, Text = value
                });
            }
        }
示例#25
0
        /// <summary>
        ///  <paramref name="section"/>に数値を設定します。
        /// </summary>
        /// <param name="section">設定先の<see cref="Yencon.YSection"/>です。</param>
        /// <param name="keyname">設定する数値キーの名前です。</param>
        /// <param name="value">設定する数値です。</param>
        public static void SetNodeAsNumber(this YSection section, string keyname, long value)
        {
            var node = section.GetNode(keyname);

            if (node is YNumber numKey)
            {
                numKey.SInt64Value = value;
            }
            else
            {
                section.Add(new YNumber()
                {
                    Name = keyname, SInt64Value = value
                });
            }
        }
示例#26
0
        /// <summary>
        ///  <paramref name="section"/>に論理値を設定します。
        /// </summary>
        /// <param name="section">設定先の<see cref="Yencon.YSection"/>です。</param>
        /// <param name="keyname">設定する論理値キーの名前です。</param>
        /// <param name="value">設定する論理値です。</param>
        public static void SetNodeAsBoolean(this YSection section, string keyname, bool value)
        {
            var node = section.GetNode(keyname);

            if (node is YBoolean flgKey)
            {
                flgKey.Flag = value;
            }
            else
            {
                section.Add(new YBoolean()
                {
                    Name = keyname, Flag = value
                });
            }
        }
示例#27
0
		public static void Save(string filename, YSection root)
		{
#if RELEASE
			try {
#endif
				if (_last_type == YenconType.Text) {
					_txt_cnvtr.Save(filename, root);
				} else if (_last_type == YenconType.Binary) {
					_bin_cnvtr.Save(filename, root);
				} else {
					_last_type = YenconType.Text;
					_txt_cnvtr.Save(filename, root);
				}
#if RELEASE
			} catch (Exception e) {
				Program.ShowError(e);
			}
#endif
		}
示例#28
0
 /// <summary>
 ///  指定されたセクションへ指定された名前のリンク文字列を設定します。
 /// </summary>
 /// <remarks>
 ///  同名の値が既に存在する場合は削除されます。
 /// </remarks>
 /// <param name="section">設定先のセクションです。</param>
 /// <param name="name">設定するリンク文字列の名前です。</param>
 /// <param name="value">リンク文字列です。</param>
 /// <returns>設定に成功した場合はリンク文字列を表すオブジェクト、失敗した場合は<see langword="null"/>を返します。</returns>
 /// <exception cref="System.ArgumentNullException"/>
 /// <exception cref="CAP.Yencon.Exceptions.InvalidNodeNameException"/>
 public static YLink?SetLink(this YSection section, string name, string value)
 {
     section.EnsureNotNull(nameof(section));
     section.RemoveNode(name);
     return(section.CreateLink(name, value));
 }
示例#29
0
 /// <summary>
 ///  指定されたセクションへ指定された名前の論理値を設定します。
 /// </summary>
 /// <remarks>
 ///  同名の値が既に存在する場合は削除されます。
 /// </remarks>
 /// <param name="section">設定先のセクションです。</param>
 /// <param name="name">設定する論理値の名前です。</param>
 /// <param name="value">論理値です。</param>
 /// <returns>設定に成功した場合は論理値を表すオブジェクト、失敗した場合は<see langword="null"/>を返します。</returns>
 /// <exception cref="System.ArgumentNullException"/>
 /// <exception cref="CAP.Yencon.Exceptions.InvalidNodeNameException"/>
 public static YBoolean?SetBoolean(this YSection section, string name, bool value)
 {
     section.EnsureNotNull(nameof(section));
     section.RemoveNode(name);
     return(section.CreateBoolean(name, value));
 }
示例#30
0
 /// <summary>
 ///  指定されたセクションへ指定された名前の10進数値を設定します。
 /// </summary>
 /// <remarks>
 ///  同名の値が既に存在する場合は削除されます。
 /// </remarks>
 /// <param name="section">設定先のセクションです。</param>
 /// <param name="name">設定する10進数値の名前です。</param>
 /// <param name="value">10進数値です。</param>
 /// <returns>設定に成功した場合は10進数値を表すオブジェクト、失敗した場合は<see langword="null"/>を返します。</returns>
 /// <exception cref="System.ArgumentNullException"/>
 /// <exception cref="CAP.Yencon.Exceptions.InvalidNodeNameException"/>
 public static YNumber?SetNumber(this YSection section, string name, decimal value)
 {
     section.EnsureNotNull(nameof(section));
     section.RemoveNode(name);
     return(section.CreateNumber(name, value));
 }