Exemple #1
0
        public object Deserialize(StructuredText storage)
        {
            RenderProfile prof = new RenderProfile();

            prof.FontName    = storage.Get("font-name", "Courier New");
            prof.CJKFontName = storage.Get("cjk-font-name",
                                           storage.Get("japanese-font-name",
                                                       storage.Get("chinese-font-name", "Courier New")));
            prof.FontSize                = ParseUtil.ParseFloat(storage.Get("font-size"), 10.0f);
            prof.LineSpacing             = ParseUtil.ParseInt(storage.Get("line-spacing"), 0);
            prof.UseClearType            = ParseUtil.ParseBool(storage.Get("clear-type"), false);
            prof.EnableBoldStyle         = ParseUtil.ParseBool(storage.Get("enable-bold-style"), true);
            prof.ForceBoldStyle          = ParseUtil.ParseBool(storage.Get("force-bold-style"), false);
            prof.ForeColor               = ParseUtil.ParseColor(storage.Get("text-color"), Color.FromKnownColor(KnownColor.WindowText));
            prof.BackColor               = ParseUtil.ParseColor(storage.Get("back-color"), Color.FromKnownColor(KnownColor.Window));
            prof.ImageStyle              = ParseUtil.ParseEnum <ImageStyle>(storage.Get("back-style"), ImageStyle.Center);
            prof.BackgroundImageFileName = storage.Get("back-image", "");

            prof.ESColorSet = new EscapesequenceColorSet();
            string escolor = storage.Get("escape-sequence-color");

            if (escolor != null)
            {
                prof.ESColorSet.Load(escolor);
            }
            prof.DarkenEsColorForBackground = ParseUtil.ParseBool(storage.Get("darken-escolor-for-background"), true);

            return(prof);
        }
        public object Deserialize(StructuredText node)
        {
            TerminalSettings ts = new TerminalSettings();

            ts.BeginUpdate();

            ts.Encoding     = ParseEncodingType(node.Get("encoding", ""), EncodingType.ISO8859_1);
            ts.TerminalType = ParseUtil.ParseEnum <TerminalType>(node.Get("terminal-type"), TerminalType.XTerm);
            ts.LocalEcho    = ParseUtil.ParseBool(node.Get("localecho"), false);
            ts.LineFeedRule = ParseUtil.ParseEnum <LineFeedRule>(node.Get("linefeedrule"), LineFeedRule.Normal);
            ts.TransmitNL   = ParseUtil.ParseEnum <NewLine>(node.Get("transmit-nl"), NewLine.CR);
            ts.EnabledCharTriggerIntelliSense = ParseUtil.ParseBool(node.Get("char-trigger-intellisense"), false);
            string shellscheme = node.Get("shellscheme", ShellSchemeCollection.DEFAULT_SCHEME_NAME);

            if (shellscheme.Length > 0)
            {
                ts.SetShellSchemeName(shellscheme);
            }
            ts.Caption = node.Get("caption", "");
#if !UNITTEST
            //現在テストではRenderProfileは対象外
            StructuredText rp = node.FindChild(typeof(RenderProfile).FullName);
            if (rp != null)
            {
                ts.RenderProfile = _serializeService.Deserialize(rp) as RenderProfile;
            }
#endif
            ts.EndUpdate();
            return(ts);
        }
Exemple #3
0
        /// <summary>
        /// Creates an argument of a specific type by parsing the string
        /// </summary>
        /// <returns>The parsed object.</returns>
        /// <param name="value">The string to parse.</param>
        /// <param name="targettype">The type to parse to.</param>
        public static object ArgumentFromString(string value, Type targettype)
        {
            if (targettype.IsEnum)
            {
                var entries = ExpandEnvironmentVariables(value ?? "")
                              .Split('|')
                              .Select(x => Enum.Parse(targettype, x, true))
                              .ToArray();
                if (entries.Length == 1)
                {
                    return(entries.First());
                }
                else
                {
                    return(Enum.ToObject(
                               targettype,
                               entries.Select(x => (int)Convert.ChangeType(x, typeof(int))).Sum()
                               ));
                }
            }

            if (targettype.IsArray)
            {
                // TODO: Handle embedded comma values in strings?
                var args =
                    (value ?? "")
                    .Split(',')
                    .Select(x => ArgumentFromString((x ?? string.Empty).Trim(), targettype.GetElementType()))
                    .ToArray();

                // Manually convert to the right type
                var res = Array.CreateInstance(targettype.GetElementType(), args.Length);
                Array.Copy(args, res, args.Length);
                return(res);
            }

            if ((targettype.IsArray || targettype == typeof(string)) && string.Equals(value, "null", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            if (targettype == typeof(TimeSpan))
            {
                return(ParseUtil.ParseDuration(ExpandEnvironmentVariables(value)));
            }
            if (targettype == typeof(int) || targettype == typeof(uint) || targettype == typeof(long) || targettype == typeof(ulong))
            {
                return(Convert.ChangeType(ParseUtil.ParseSize(ExpandEnvironmentVariables(value)), targettype));
            }
            if (targettype == typeof(bool))
            {
                return(ParseUtil.ParseBool(ExpandEnvironmentVariables(value)));
            }

            return(Convert.ChangeType(ExpandEnvironmentVariables(value), targettype));
        }
        //旧バージョンフォーマットの読み込み
        private static ShortcutFileContent ParseOldFormat(XmlElement root)
        {
            if (root.GetAttribute("type") != "tcp")
            {
                throw new FormatException("Unknown File Format");
            }

            //accountの有無でTelnet/SSHを切り替え
            ITerminalParameter param;
            ISSHLoginParameter ssh     = null;
            ITCPParameter      tcp     = null;
            string             account = root.GetAttribute("account");

            if (account.Length > 0)
            {
                ssh         = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultSSHParameter();
                ssh.Account = account;
                tcp         = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));
            }
            else
            {
                tcp = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();
            }

            param = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));
            ITerminalSettings settings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings("", null);

            settings.BeginUpdate();
            //アトリビュート舐めて設定
            foreach (XmlAttribute attr in root.Attributes)
            {
                switch (attr.Name)
                {
                case "auth":
                    if (ssh != null)
                    {
                        ssh.AuthenticationType = ParseUtil.ParseEnum <AuthenticationType>(attr.Value, AuthenticationType.Password);
                    }
                    break;

                case "keyfile":
                    if (ssh != null)
                    {
                        ssh.IdentityFileName = attr.Value;
                    }
                    break;

                case "encoding":
                    settings.Encoding = (EncodingType)EnumDescAttribute.For(typeof(EncodingType)).FromDescription(attr.Value, EncodingType.ISO8859_1);
                    break;

                case "terminal-type":
                    settings.TerminalType = ParseUtil.ParseEnum <TerminalType>(attr.Value, TerminalType.XTerm);
                    param.SetTerminalName(attr.Value);
                    break;

                case "localecho":
                    settings.LocalEcho = ParseUtil.ParseBool(attr.Value, false);
                    break;

                case "caption":
                    settings.Caption = attr.Value;
                    break;

                case "transmit-nl":
                    settings.TransmitNL = ParseUtil.ParseEnum <NewLine>(attr.Value, NewLine.CR);
                    break;

                case "host":
                    tcp.Destination = attr.Value;
                    break;

                case "port":
                    tcp.Port = ParseUtil.ParseInt(attr.Value, ssh != null? 22 : 23);
                    break;

                case "method":
                    if (ssh != null)
                    {
                        ssh.Method = attr.Value == "SSH1"? SSHProtocol.SSH1 : SSHProtocol.SSH2;
                    }
                    break;
                }
            }
            //ts.LineFeedRule = ParseUtil.ParseEnum<LineFeedRule>(node.Get("linefeedrule"), LineFeedRule.Normal);
            settings.EndUpdate();

            return(new ShortcutFileContent(settings, param));
        }