/// <summary>
        /// Create a sequence node.
        /// </summary>
        /// <param name="nodes">Child nodes.</param>
        /// <param name="tag">Tag for the seuqnce.</param>
        /// <returns>Created sequence node.</returns>
        protected static YamlSequence seq_tag(string tag, params YamlNode[] nodes)
        {
            var result = new YamlSequence(nodes);

            result.Tag = tag;
            return(result);
        }
Exemplo n.º 2
0
 public static IEnumerable <T> Convert <T>(this YamlSequence sequence)
 {
     foreach (YamlMapping mapping in sequence)
     {
         yield return(Convert <T>(mapping));
     }
 }
Exemplo n.º 3
0
        public Method ParseMethod(string containingTypeName, YamlSequence sequence)
        {
            switch (((YamlValue)sequence[0]).Value)
            {
            case "virtual" when sequence.Count != 5:
                throw new ArgumentException("Virtual method definitions must have 5 elements");

            case "virtual":
            {
                var(_, returnType, name, arguments, index) = sequence.ToObjectX <(Modifier modifier, string returnType, string name, string[] arguments, uint index)>();
                return(new VirtualMethod(_typeCache, containingTypeName, returnType, name, arguments, index));
            }

            case "partial" when sequence.Count != 5:
                throw new ArgumentException("Partial method definitions must have 5 elements");

            case "partial":
            {
                var(_, returnType, name, arguments, offset) = sequence.ToObjectX <(Modifier modifier, string returnType, string name, string[] arguments, uint offset)>();
                return(new PartialMethod(_typeCache, containingTypeName, returnType, name, arguments, offset));
            }

            default:
            {
                if (sequence.Count != 4)
                {
                    throw new ArgumentException("Method definitions must be either 4 elements or 5 elements with a valid modifier (virtual/partial)");
                }

                var(returnType, name, arguments, offset) = sequence.ToObjectX <(string returnType, string name, string[] arguments, uint offset)>();
                return(new InstanceMethod(_typeCache, containingTypeName, returnType, name, arguments, offset));
            }
            }
        }
Exemplo n.º 4
0
        private void FlowSequenceToYaml(YamlSequence node, string pres, Context c)
        {
            var tag = TagToYaml(node, "!!seq");

            if (column > 80)
            {
                WriteLine();
                Write(pres);
            }
            if (tag != "" && tag != "!!seq")
            {
                Write(tag + " ");
            }
            Write("[");
            foreach (var item in node)
            {
                if (item != node.First())
                {
                    Write(", ");
                }
                if (column > 100)
                {
                    WriteLine();
                    Write(pres);
                }
                NodeToYaml(item, pres, Context.NoBreak);
            }
            Write("]");
            if (c != Context.NoBreak)
            {
                WriteLine();
            }
        }
Exemplo n.º 5
0
 protected static YamlMapping EnsureSequence(YamlMapping m, string key)
 {
     if (m[key] == null)
     {
         m[key] = new YamlSequence();
     }
     return(m);
 }
Exemplo n.º 6
0
        protected static YamlMapping SetSequence(YamlMapping m, string key, params YamlElement[] values)
        {
            var seq = new YamlSequence();

            seq.AddRange(values);
            m[key] = seq;
            return(m);
        }
Exemplo n.º 7
0
        public static YamlSequence ToYamlSequence(this IEnumerable enumerable)
        {
            YamlSequence seq = new YamlSequence();

            foreach (object obj in enumerable)
            {
                seq.Add(obj.ToYamlNode());
            }
            return(seq);
        }
Exemplo n.º 8
0
        public void TestChangingMappingKey()
        {
            var key = (YamlScalar)"def";
            var map = new YamlMapping(key, 3);

            key.Value = "ghi";
            Assert.IsTrue(map.ContainsKey(key));
            Assert.IsTrue(map.Remove(key));

            map[map] = 4;
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            var map2 = new YamlMapping(key, 3);

            map2[map2] = 2;
            map2[map]  = 4;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            map[map2] = 2;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            map.Tag = YamlNode.DefaultTagPrefix + "map";
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);

            var seq = new YamlSequence(map);

            map.Add(seq, 4);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
            seq.Add(map);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
        }
Exemplo n.º 9
0
 private void SequenceToYaml(YamlSequence node, string pres, Context c)
 {
     if (node.Count == 0 || GetPropertyOrNull(node, "Compact") != null)
     {
         FlowSequenceToYaml(node, pres, c);
     }
     else
     {
         BlockSequenceToYaml(node, pres, c);
     }
 }
Exemplo n.º 10
0
 private static void GetLengthes(YamlSequence seq, int i, int[] lengthes)
 {
     lengthes[i] = Math.Max(lengthes[i], seq.Count);
     if (i < lengthes.Length - 1)
     {
         for (int j = 0; j < seq.Count; j++)
         {
             GetLengthes((YamlSequence)seq[j], i + 1, lengthes);
         }
     }
 }
Exemplo n.º 11
0
        public void TrackerAssignmentTest()
        {
            var tracker = new YamlNodeTracker();
            var stream  = new YamlStream(tracker);

            var document = new YamlDocument();
            var sequence = new YamlSequence();

            document.Contents = sequence;

            var mapping = new YamlMapping();

            sequence.Add(mapping);

            var key   = new YamlValue("key");
            var value = new YamlValue("value");

            var eventList = new List <TrackerEventArgs>();

            tracker.TrackerEvent += (sender, args) => eventList.Add(args);

            mapping[key] = value;

            Assert.IsNull(document.Tracker);
            Assert.IsNull(sequence.Tracker);
            Assert.IsNull(mapping.Tracker);
            Assert.IsNull(key.Tracker);
            Assert.IsNull(value.Tracker);

            stream.Add(document);

            Assert.AreEqual(tracker, document.Tracker);
            Assert.AreEqual(tracker, sequence.Tracker);
            Assert.AreEqual(tracker, mapping.Tracker);
            Assert.AreEqual(tracker, key.Tracker);
            Assert.AreEqual(tracker, value.Tracker);

            Assert.AreEqual(4, eventList.Count);
            Assert.IsTrue(eventList[0] is MappingPairAdded);
            Assert.IsTrue(eventList[1] is SequenceElementAdded);
            Assert.IsTrue(eventList[2] is DocumentContentsChanged);
            Assert.IsTrue(eventList[3] is StreamDocumentAdded);

            eventList.Clear();

            var key2   = new YamlValue("key2");
            var value2 = new YamlValue("value2");

            mapping[key2] = value2;

            Assert.AreEqual(1, eventList.Count);
            Assert.IsTrue(eventList[0] is MappingPairAdded);
        }
Exemplo n.º 12
0
        public static YamlNode ToYamlNode(this object val)
        {
            Type                type       = val.GetType();
            YamlMapping         node       = new YamlMapping();
            List <PropertyInfo> properties = new List <PropertyInfo>(type.GetProperties());

            properties.Sort((l, r) => l.MetadataToken.CompareTo(r.MetadataToken));
            foreach (PropertyInfo property in properties)
            {
                object propVal = property.GetValue(val);
                if (propVal != null)
                {
                    if (property.IsEnumerable())
                    {
                        YamlSequence yamlSequence = new YamlSequence();
                        node.Add(property.Name, yamlSequence);
                        foreach (object v in ((IEnumerable)propVal))
                        {
                            yamlSequence.Add(v.ToYamlNode());
                        }
                    }
                    else
                    {
                        if (property.PropertyType == typeof(bool) ||
                            property.PropertyType == typeof(bool?) ||
                            property.PropertyType == typeof(int) ||
                            property.PropertyType == typeof(int?) ||
                            property.PropertyType == typeof(long) ||
                            property.PropertyType == typeof(long?) ||
                            property.PropertyType == typeof(decimal) ||
                            property.PropertyType == typeof(decimal?) ||
                            property.PropertyType == typeof(double) ||
                            property.PropertyType == typeof(double?) ||
                            property.PropertyType == typeof(string) ||
                            property.PropertyType == typeof(byte[]) ||
                            property.PropertyType == typeof(DateTime) ||
                            property.PropertyType == typeof(DateTime?))
                        {
                            node.Add(property.Name, new YamlScalar(propVal.ToString()));
                        }
                        else
                        {
                            node.Add(property.Name, propVal.ToYamlNode());
                        }
                    }
                }
            }
            return(node);
        }
Exemplo n.º 13
0
 void SetArrayElements(Array array, YamlSequence seq, int i, int[] indices, Type elementType, Dictionary <YamlNode, object> appeared)
 {
     if (i < indices.Length - 1)
     {
         for (indices[i] = 0; indices[i] < seq.Count; indices[i]++)
         {
             SetArrayElements(array, (YamlSequence)seq[indices[i]], i + 1, indices, elementType, appeared);
         }
     }
     else
     {
         for (indices[i] = 0; indices[i] < seq.Count; indices[i]++)
         {
             array.SetValue(NodeToObjectInternal(seq[indices[i]], elementType, appeared), indices);
         }
     }
 }
Exemplo n.º 14
0
        private void SaveConfig()
        {
            var sec = new YamlSequence();

            foreach (var rf in RecentFiles)
            {
                sec.Add(new YamlScalar(rf));
            }

            YamlNode pnode =
                new YamlMapping(
                    "recentfiles", sec
                    );

            var path = Path.Combine(GetExecPath(), "cache.yml");

            pnode.ToYamlFile(path);
        }
Exemplo n.º 15
0
        public object ReadYaml(ref ObjectContext objectContext)
        {
            if (objectContext.Descriptor.Type == typeof(YamlNode))
            {
                if (objectContext.Reader.Accept <MappingStart>())
                {
                    return(YamlMapping.Load(objectContext.Reader, new YamlNodeTracker()));
                }
                if (objectContext.Reader.Accept <SequenceStart>())
                {
                    return(YamlSequence.Load(objectContext.Reader, new YamlNodeTracker()));
                }
                if (objectContext.Reader.Accept <Scalar>())
                {
                    return(YamlValue.Load(objectContext.Reader, new YamlNodeTracker()));
                }
            }
            if (objectContext.Descriptor.Type == typeof(YamlMapping))
            {
                if (objectContext.Reader.Accept <MappingStart>())
                {
                    return(YamlMapping.Load(objectContext.Reader, new YamlNodeTracker()));
                }
                throw new YamlException($"Expected {nameof(MappingStart)} but did not find it");
            }
            if (objectContext.Descriptor.Type == typeof(YamlSequence))
            {
                if (objectContext.Reader.Accept <SequenceStart>())
                {
                    return(YamlSequence.Load(objectContext.Reader, new YamlNodeTracker()));
                }
                throw new YamlException($"Expected {nameof(SequenceStart)} but did not find it");
            }
            if (objectContext.Descriptor.Type == typeof(YamlValue))
            {
                if (objectContext.Reader.Accept <Scalar>())
                {
                    return(YamlValue.Load(objectContext.Reader, new YamlNodeTracker()));
                }
                throw new YamlException($"Expected {nameof(Scalar)} but did not find it");
            }

            throw new YamlException($"{objectContext.Descriptor.Type} is not a supported {nameof(YamlNode)} type");
        }
Exemplo n.º 16
0
        private void BlockSequenceToYaml(YamlSequence node, string pres, Context c)
        {
            var tag = TagToYaml(node, "!!seq");

            if (tag != "" || c == Context.Map)
            {
                WriteLine(tag);
                c = Context.Normal;
            }
            string press = pres + "  ";

            foreach (var item in node)
            {
                if (c == Context.Normal)
                {
                    Write(pres);
                }
                Write("- ");
                NodeToYaml(item, press, Context.List);
                c = Context.Normal;
            }
        }
Exemplo n.º 17
0
        object SequenceToObject(YamlSequence seq, Type type, Dictionary <YamlNode, object> appeared)
        {
            if (type == null)
            {
                type = typeof(object[]);
            }

            if (type.IsArray)
            {
                var lengthes = new int[type.GetArrayRank()];
                GetLengthes(seq, 0, lengthes);
                var array = (Array)type.GetConstructor(lengthes.Select(l => typeof(int) /* l.GetType() */).ToArray())
                            .Invoke(lengthes.Cast <object>().ToArray());
                appeared.Add(seq, array);
                var indices = new int[type.GetArrayRank()];
                SetArrayElements(array, seq, 0, indices, type.GetElementType(), appeared);
                return(array);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Create a sequence node. 
 /// </summary>
 /// <param name="nodes">Child nodes.</param>
 /// <param name="tag">Tag for the seuqnce.</param>
 /// <returns>Created sequence node.</returns>
 protected static YamlSequence seq_tag(string tag, params YamlNode[] nodes)
 {
     var result= new YamlSequence(nodes);
     result.Tag= tag;
     return result;
 }
Exemplo n.º 19
0
        object SequenceToObject(YamlSequence seq, Type type, object obj, Dictionary<YamlNode, object> appeared)
        {
            if ( type == null )
                type = typeof(object[]);

            // 1) Give a chance to deserialize through a IYamlSerializable interface
            var serializable = config.Serializable.FindSerializable(context, null, type);
            if (serializable != null)
            {
                return serializable.Deserialize(context, seq, type);
            }

            // 3) Give a chance to config.Activator
            if (obj == null)
            {
                obj = config.Activator.Activate(type);
                appeared.Add(seq, obj);
            }
            else
            {
                if (appeared.ContainsKey(seq))
                    throw new InvalidOperationException("This member is not writeable: {0}".DoFormat(obj.ToString()));
            }

            if (type.IsArray)
            {
                var lengthes= new int[type.GetArrayRank()];
                GetLengthes(seq, 0, lengthes);
                var array = (Array)type.GetConstructor(lengthes.Select(l => typeof(int) /* l.GetType() */).ToArray())
                               .Invoke(lengthes.Cast<object>().ToArray());
                appeared.Add(seq, array);
                var indices = new int[type.GetArrayRank()];
                SetArrayElements(array, seq, 0, indices, type.GetElementType(), appeared);
                return array;
            }


            var collection = obj as ICollection;
            if (collection != null)
            {
                var access = ObjectMemberAccessor.FindFor(type);

                // If this is a pure list
                if (access.CollectionAdd == null)
                    throw new FormatException("{0} is not a collection type.".DoFormat(type.FullName));
                access.CollectionClear(obj);
                foreach (var item in seq)
                    access.CollectionAdd(obj, NodeToObjectInternal(item, access.ValueType, appeared));

                return obj;
            }

            // TODO Add support for lists
            throw new FormatException("Unsupported type [{0}] for sequence [{1}]".DoFormat(type.Name, seq));
        }
Exemplo n.º 20
0
 void SetArrayElements(Array array, YamlSequence seq, int i, int[] indices, Type elementType, Dictionary<YamlNode, object> appeared)
 {
     if ( i < indices.Length - 1 ) {
         for ( indices[i] = 0; indices[i] < seq.Count; indices[i]++ )
             SetArrayElements(array, (YamlSequence)seq[indices[i]], i + 1, indices, elementType, appeared);
     } else {
         for ( indices[i] = 0; indices[i] < seq.Count; indices[i]++ )
             array.SetValue(NodeToObjectInternal(seq[indices[i]], elementType, appeared), indices);
     }
 }
Exemplo n.º 21
0
 private static void GetLengthes(YamlSequence seq, int i, int[] lengthes)
 {
     lengthes[i] = Math.Max(lengthes[i], seq.Count);
     if ( i < lengthes.Length - 1 )
         for ( int j = 0; j < seq.Count; j++ )
             GetLengthes((YamlSequence)seq[j], i + 1, lengthes);
 }
Exemplo n.º 22
0
        public void TestChangingMappingKey()
        {
            var key = (YamlScalar)"def";
            var map = new YamlMapping(key, 3);
            key.Value = "ghi";
            Assert.IsTrue(map.ContainsKey(key));
            Assert.IsTrue(map.Remove(key));

            map[map] = 4;
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            var map2 = new YamlMapping(key, 3);
            map2[map2] = 2;
            map2[map] = 4;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            map[map2] = 2;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            map.Tag = YamlNode.DefaultTagPrefix + "map";
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);

            var seq = new YamlSequence(map);
            map.Add(seq, 4);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
            seq.Add(map);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
        }
Exemplo n.º 23
0
 protected static YamlSequence EnsureSequenceContent(YamlSequence s)
 {
     //s.Add(new YamlElement() )
     return(s);
 }
Exemplo n.º 24
0
        // c_keyを使ってpinコードで認証する
        public void Authorize()
        {
            // get auth url
            var requestToken = service.GetRequestToken();
            var url = service.GetAuthenticationUrl(requestToken).ToString();

            // input
            string pin = inputer(url);

            Debug.WriteLine(pin);
            if (pin == null) { return; }

            // get & set access token
            access = service.GetAccessToken(requestToken, pin);

            // check & save
            if(auth())
            {
                var y = new YamlSequence(access.Token, access.TokenSecret);
                y.ToYamlFile(tokenFile);
            }
        }
Exemplo n.º 25
0
        public void ApplySettings(IActivityMonitor m)
        {
            if (!this.CheckCurrentBranch(m))
            {
                return;
            }
            YamlMapping firstMapping = GetFirstMapping(m, true);

            if (firstMapping == null)
            {
                return;
            }
            var solution = _driver.GetSolution(m, allowInvalidSolution: true);

            if (solution == null)
            {
                return;
            }

            // We don't use AppVeyor for private repositories.
            if (!GitFolder.IsPublic)
            {
                if (TextContent != null)
                {
                    m.Log(LogLevel.Info, "The project is private, so we don't use Appveyor and the Appveyor.yml is not needed.");
                    Delete(m);
                }
                return;
            }
            // We currently always use AppVeyor when the repository is public.
            YamlMapping env = FindOrCreateYamlElement(m, firstMapping, "environment");

            if (env == null)
            {
                return;
            }

            var passphrase = _keyStore.GetSecretKey(m, SolutionDriver.CODECAKEBUILDER_SECRET_KEY, false);

            if (passphrase != null)
            {
                var central = KeyVault.DecryptValues(_sharedState.CICDKeyVault, passphrase);
                if (central.TryGetValue(APPVEYOR_ENCRYPTED_CODECAKEBUILDER_SECRET_KEY, out var appveyorSecure))
                {
                    env[SolutionDriver.CODECAKEBUILDER_SECRET_KEY] = CreateKeyValue("secure", appveyorSecure);
                }
                else
                {
                    m.Warn($"Update of {SolutionDriver.CODECAKEBUILDER_SECRET_KEY} encrypted secure key has been skipped: {APPVEYOR_ENCRYPTED_CODECAKEBUILDER_SECRET_KEY} key should be defined in CICDKeyVault.");
                }
            }
            else
            {
                m.Info($"Update of {SolutionDriver.CODECAKEBUILDER_SECRET_KEY} encrypted secure skipped.");
            }
            // Remove obsolete environment variables definitions.
            env.Remove("NUGET_API_KEY");
            env.Remove("MYGET_RELEASE_API_KEY");
            env.Remove("MYGET_PREVIEW_API_KEY");
            env.Remove("MYGET_CI_API_KEY");
            env.Remove("CK_DB_TEST_MASTER_CONNECTION_STRING");
            env.Remove("AZURE_FEED_SIGNATURE_OPENSOURCE_PAT");
            env.Remove("AZURE_FEED_PAT");
            env.Remove("VSS_NUGET_EXTERNAL_FEED_ENDPOINTS");
            if (_solutionSpec.SqlServer != null)
            {
                env["SqlServer/MasterConnectionString"] = new YamlValue($"Server=(local)\\SQL{_solutionSpec.SqlServer.ToUpperInvariant()};Database=master;User ID=sa;Password=Password12!");
            }
            //
            firstMapping.Remove(new YamlValue("init"));
            if (_solutionSpec.SqlServer != null)
            {
                firstMapping["services"] = new YamlValue("mssql" + _solutionSpec.SqlServer.ToLowerInvariant());
            }
            var install = new YamlSequence();

            // Temporary: installs the 6.9.0 of npm.
            if (solution.GeneratedArtifacts.Any(g => g.Artifact.Type.Name == "NPM"))
            {
                install.Add(CreateKeyValue("cmd", "npm install -g [email protected]"));
                install.Add(CreateKeyValue("ps", "Install-Product node 12"));
            }
            firstMapping["install"] = install;

            firstMapping["version"]      = new YamlValue("build{build}");
            firstMapping["image"]        = new YamlValue("Visual Studio 2019");
            firstMapping["clone_folder"] = new YamlValue("C:\\CKli-World\\" + GitFolder.SubPath.Path.Replace('/', '\\'));
            EnsureDefaultBranches(firstMapping);
            SetSequence(firstMapping, "build_script", new YamlValue("dotnet run --project CodeCakeBuilder -nointeraction"));
            firstMapping["test"]      = new YamlValue("off");
            firstMapping["artifacts"] = new YamlSequence()
            {
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\*.log'"),
                    ["name"] = new YamlValue("Log file")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\*.trx'"),
                    ["name"] = new YamlValue("Visual studio test results file")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\Tests\**\TestResult*.xml'"),
                    ["name"] = new YamlValue("NUnit tests result files")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**Tests\**\Logs\**\*'"),
                    ["name"] = new YamlValue("Log files")
                }
            };
            CreateOrUpdate(m, YamlMappingToString(m));
        }
Exemplo n.º 26
0
        object SequenceToObject(YamlSequence seq, Type type, object obj, Dictionary <YamlNode, object> appeared)
        {
            if (type == null)
            {
                type = typeof(object[]);
            }

            // 1) Give a chance to deserialize through a IYamlSerializable interface
            var serializable = config.Serializable.FindSerializable(context, null, type);

            if (serializable != null)
            {
                return(serializable.Deserialize(context, seq, type));
            }

            // 3) Give a chance to config.Activator
            if (obj == null)
            {
                obj = config.Activator.Activate(type);
                appeared.Add(seq, obj);
            }
            else
            {
                if (appeared.ContainsKey(seq))
                {
                    throw new InvalidOperationException("This member is not writeable: {0}".DoFormat(obj.ToString()));
                }
            }

            if (type.IsArray)
            {
                var lengthes = new int[type.GetArrayRank()];
                GetLengthes(seq, 0, lengthes);
                var array = (Array)type.GetConstructor(lengthes.Select(l => typeof(int) /* l.GetType() */).ToArray())
                            .Invoke(lengthes.Cast <object>().ToArray());
                appeared.Add(seq, array);
                var indices = new int[type.GetArrayRank()];
                SetArrayElements(array, seq, 0, indices, type.GetElementType(), appeared);
                return(array);
            }


            var collection = obj as ICollection;

            if (collection != null)
            {
                var access = ObjectMemberAccessor.FindFor(type);

                // If this is a pure list
                if (access.CollectionAdd == null)
                {
                    throw new FormatException("{0} is not a collection type.".DoFormat(type.FullName));
                }
                access.CollectionClear(obj);
                foreach (var item in seq)
                {
                    access.CollectionAdd(obj, NodeToObjectInternal(item, access.ValueType, appeared));
                }

                return(obj);
            }

            // TODO Add support for lists
            throw new FormatException("Unsupported type [{0}] for sequence [{1}]".DoFormat(type.Name, seq));
        }