Пример #1
0
        static void EnsureDefaultBranches(YamlMapping firstMapping)
        {
            YamlElement branches = firstMapping["branches"];

            if (branches == null)
            {
                firstMapping["branches"] = SetSequence(new YamlMapping(), "only", new YamlValue("master"), new YamlValue("develop"));
            }
        }
Пример #2
0
        public Value(YamlElement node, ElementFactory fac, DataMap def = null)
            : base(node, fac, def)
        {
            string str = "";

            switch (node.Type)
            {
            case YamlElement.Types.Scalar:
                str = node.Val();
                break;

            case YamlElement.Types.Map:
                str = node.Key("value", "").Str();
                if (node.Has("substring"))
                {
                    int pos;
                    var subs = node.Key("substring");
                    if (subs.Type == YamlElement.Types.Map)
                    {
                        if (subs.Has("length") && int.TryParse(subs.Get("length"), out pos))
                        {
                            data.length = pos;
                        }
                        if (subs.Has("start") && int.TryParse(subs.Get("start"), out pos))
                        {
                            data.start = pos;
                        }
                    }
                    else if (subs.Type == YamlElement.Types.Sequence)
                    {
                        var arr = subs.List().Select(i => i.Str()).ToList();
                        if (arr.Count > 1 && int.TryParse(arr[1], out pos))
                        {
                            data.length = pos;
                        }
                        if (arr.Count > 0 && int.TryParse(arr[0], out pos))
                        {
                            data.start = pos;
                        }
                    }
                    else if (subs.Type == YamlElement.Types.Scalar)
                    {
                        var arr = subs.Val().Split(',');
                        if (arr.Length > 1 && int.TryParse(arr[1], out pos))
                        {
                            data.length = pos;
                        }
                        if (arr.Length > 0 && int.TryParse(arr[0], out pos))
                        {
                            data.start = pos;
                        }
                    }
                }
                break;
            }
            data.value = str.Replace("[ [ ", "[[").Replace(" ] ]", "]]");
        }
Пример #3
0
        void EnsureDefaultBranches(YamlMapping firstMapping)
        {
            YamlElement branches = firstMapping["branches"];

            if (branches == null)
            {
                firstMapping["branches"] = branches = new YamlMapping();
            }
            if (branches is YamlMapping m)
            {
                SetSequence(m, "only", new YamlValue(GitFolder.World.MasterBranchName), new YamlValue(GitFolder.World.DevelopBranchName));
            }
        }
Пример #4
0
        public Form1()
        {
            InitializeComponent();
            //读取配置
            YamlElement y = ConfigManager.ReadConfig();

            if (y != null)
            {
                APPID.Text          = y.AppId;
                SecrateTxt.Text     = y.SecretKey;
                APIAddress.Text     = y.Url;
                gapTime.Text        = y.Gaptime.ToString();
                TranslateTimes.Text = y.Times.ToString();
            }
        }
Пример #5
0
        /// <summary>
        /// 保存配置信息
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="secretKey"></param>
        /// <param name="url"></param>
        /// <param name="times"></param>
        /// <param name="gaptime"></param>
        static public void SaveConfig(string appId, string secretKey, string url, int times, int gaptime)
        {
            //Console.WriteLine(appId + secretKey + url);
            YamlElement element = new YamlElement(appId, secretKey, url, times, gaptime);

            //序列器
            Serializer serializer = new Serializer();
            //将保存对象序列化到strWriter
            string strWriter = serializer.Serialize(element);

            //Console.WriteLine(strWriter);
            using (TextWriter writer = File.CreateText("config.yml"))
            {
                writer.Write(strWriter);
            }
        }
Пример #6
0
        protected YamlMapping FindOrCreateYamlElement(IActivityMonitor m, YamlMapping mapping, string elementName)  ///Too similar with AppveyorFile.FindOrCreateEnvironement. We should mutualise these.
        {
            YamlMapping jobMapping;
            YamlElement job = mapping[elementName];

            if (job != null)
            {
                jobMapping = job as YamlMapping;
                if (jobMapping == null)
                {
                    m.Error($"Unable to parse Yaml file. Expecting job mapping but found '{job.GetType()}'.");
                }
            }
            else
            {
                mapping[elementName] = jobMapping = new YamlMapping();
            }

            return(jobMapping);
        }
Пример #7
0
        public Base Detect(YamlElement node)
        {
            if (node.Type == YamlElement.Types.Scalar)
            {
                return(new Text(node, this));
            }
            else if (node.Type == YamlElement.Types.Sequence)
            {
                return(new Box(node, this));
            }

            var type = node.Get("type", "");

            switch (type)
            {
            case "text": return(new Text(node, this));

            case "image": return(new Graphic(node, this));

            case "qr": return(new QR(node, this));

            case "flow": return(new FlowBox(node, this, style.ContainsKey(type) ? style[type] : null));

            case "space":
            case "directed":
            {
                var elem = new FlowBox(node, this, style.ContainsKey(type) ? style[type] : null);
                elem.factor = 0;
                return(elem);
            }

            case "stack":
            {
                var elem = new FlowBox(node, this, style.ContainsKey(type) ? style[type] : null);
                elem.factor = 1;
                return(elem);
            }

            default: return(new Box(node, this));
            }
        }
Пример #8
0
 public DataMap(YamlElement node)
 {
     data = node.ToData();
 }
Пример #9
0
 public Text(YamlElement node, ElementFactory fac, DataMap def = null)
     : base(node, fac, def ?? (fac.style.ContainsKey("text") ? fac.style["text"] : null))
 {
 }
Пример #10
0
        public Box(YamlElement node, ElementFactory fac, DataMap def = null)
            : base(node, fac, def ?? (fac.style.ContainsKey("box") ? fac.style["box"] : null))
        {
            switch (node.Type)
            {
            case YamlElement.Types.Sequence:
                nodes = node.List().Select(i => fac.Detect(i)).ToList();
                break;

            case YamlElement.Types.Map:
                if (node.Has("elements"))
                {
                    var elem = node.Key("elements");
                    if (elem.Type == YamlElement.Types.Sequence)
                    {
                        var cfac = new ElementFactory(fac);
                        foreach (var pair in node.Keys())
                        {
                            if (pair.Value.Type != YamlElement.Types.Map)
                            {
                                continue;
                            }
                            DataMap dat = null;
                            if (!cfac.style.ContainsKey(pair.Key))
                            {
                                cfac.style[pair.Key] = dat = new DataMap();
                            }
                            else
                            {
                                cfac.style[pair.Key] = dat = cfac.style[pair.Key].Copy();
                            }
                            dat.Join(pair.Value.ToData());
                        }
                        nodes = elem.List().Select(i => cfac.Detect(i)).ToList();
                    }
                }
                if (node.Has("contentalign"))
                {
                    var    align = node.Key("contentalign");
                    string x = null, y = null;
                    if (align.Type == YamlElement.Types.Map)
                    {
                        x = align.Get("h", null);
                        y = align.Get("v", null);
                    }
                    else if (align.Type == YamlElement.Types.Sequence)
                    {
                        var arr = align.List().Select(i => i.ToString()).ToList();
                        if (arr.Count == 1)
                        {
                            x = y = arr[0];
                        }
                        else if (arr.Count > 1)
                        {
                            x = arr[0]; y = arr[1];
                        }
                    }
                    else if (align.Type == YamlElement.Types.Scalar)
                    {
                        var arr = align.Val().Split(',');
                        if (arr.Length == 1)
                        {
                            x = y = arr[0];
                        }
                        else if (arr.Length > 1)
                        {
                            x = arr[0]; y = arr[1];
                        }
                    }

                    Alignment align_en;
                    if (Enum.TryParse(x, true, out align_en))
                    {
                        contentX = align_en;
                    }
                    if (Enum.TryParse(y, true, out align_en))
                    {
                        contentY = align_en;
                    }
                }
                break;
            }
        }
Пример #11
0
 public FlowBox(YamlElement node, ElementFactory fac, DataMap def = null)
     : base(node, fac, def ?? (fac.style.ContainsKey("flowbox") ? fac.style["flowbox"] : null))
 {
 }
Пример #12
0
 public Graphic(YamlElement node, ElementFactory fac, DataMap def = null)
     : base(node, fac, def ?? (fac.style.ContainsKey("graphic") ? fac.style["graphic"] : null))
 {
 }
Пример #13
0
        public Base(YamlElement node, ElementFactory fac, DataMap def = null)
        {
            if (def != null)
            {
                Configure(def, fac);
            }
            if (node.Type != YamlElement.Types.Map)
            {
                return;
            }

            Configure(node.ToData(), fac);

            // position
            if (node.Has("pos"))
            {
                var pos = node.Key("pos");
                if (pos.Type == YamlElement.Types.Map)
                {
                    rect.Up    = fac.unit.Detect(pos.Get("top", null));
                    rect.Down  = fac.unit.Detect(pos.Get("bottom", null));
                    rect.Left  = fac.unit.Detect(pos.Get("left", null));
                    rect.Right = fac.unit.Detect(pos.Get("right", null));
                }
                else if (pos.Type == YamlElement.Types.Sequence)
                {
                    var arr = pos.List().Select(i => (Unit)fac.unit.Detect(i.Val(null)));
                    rect = new Dimension(arr.ToArray());
                }
                else if (pos.Type == YamlElement.Types.Scalar)
                {
                    var arr = pos.Val().Split(',').Select(i => fac.unit.Detect(i));
                    rect = new Dimension(arr.ToArray());
                }
            }

            // size
            if (node.Has("size"))
            {
                var size = node.Key("size");
                if (size.Type == YamlElement.Types.Map)
                {
                    rect.Width  = fac.unit.Detect(size.Get("width", null));
                    rect.Height = fac.unit.Detect(size.Get("height", null));
                }
                else if (size.Type == YamlElement.Types.Sequence)
                {
                    var arr = size.List().Select(i => fac.unit.Detect(i.Val(null)));
                    rect.Size = new Vector(arr.ToArray());
                }
                else if (size.Type == YamlElement.Types.Scalar)
                {
                    var arr = size.Val().Split(',').Select(i => fac.unit.Detect(i));
                    rect.Size = new Vector(arr.ToArray());
                }
            }

            // align
            if (node.Has("align"))
            {
                var    align = node.Key("align");
                string x = null, y = null;
                if (align.Type == YamlElement.Types.Map)
                {
                    x = align.Get("h", null);
                    y = align.Get("v", null);
                }
                else if (align.Type == YamlElement.Types.Sequence)
                {
                    var arr = align.List().Select(i => i.ToString()).ToList();
                    if (arr.Count == 1)
                    {
                        x = y = arr[0];
                    }
                    else if (arr.Count > 1)
                    {
                        x = arr[0]; y = arr[1];
                    }
                }
                else if (align.Type == YamlElement.Types.Scalar)
                {
                    var arr = align.Val().Split(',');
                    if (arr.Length == 1)
                    {
                        x = y = arr[0];
                    }
                    else if (arr.Length > 1)
                    {
                        x = arr[0]; y = arr[1];
                    }
                }

                Alignment align_en;
                if (Enum.TryParse(x, true, out align_en))
                {
                    alignX = align_en;
                }
                if (Enum.TryParse(y, true, out align_en))
                {
                    alignY = align_en;
                }
            }
        }