Exemplo n.º 1
0
        public static bool TryParse(string rawSrcSrv, out HttpSourceServerDescriptor descriptor)
        {
            string currentSection = "";
            int    version        = 0;
            string versionControl = "";
            string target         = "";
            var    sources        = new List <SourceFileDescriptor>();

            foreach (var line in rawSrcSrv.GetLines())
            {
                if (new[] { InitSection, VariablesSection, SourceFilesSection, EndSection }.Contains(line))
                {
                    currentSection = line;
                }
                else
                {
                    switch (currentSection)
                    {
                    case InitSection:
                    case VariablesSection:
                        var groups = VariablesRegex.Match(line).Groups;
                        var key    = groups[1].Value;
                        var value  = groups[2].Value;
                        switch (key)
                        {
                        case VersionKey:
                            version = int.Parse(value);
                            break;

                        case VersionControlKey:
                            versionControl = value;
                            break;

                        case TargetKey:
                            target = value;
                            break;
                        }
                        break;

                    case SourceFilesSection:
                        sources.Add(SourceFileDescriptor.Parse(line));
                        break;
                    }
                }
            }

            descriptor = new[] { "http", "https" }.Contains(versionControl)
                ? new HttpSourceServerDescriptor(version, versionControl, target, sources.ToArray())
                : null;
            return(descriptor != null);
        }
Exemplo n.º 2
0
        public static bool TryParse(string rawSrcSrv, out HttpSourceServerDescriptor descriptor)
        {
            string currentSection = "";
            int version = 0;
            string versionControl = "";
            string target = "";
            var sources = new List<SourceFileDescriptor>();
            
            foreach (var line in rawSrcSrv.GetLines())
            {
                if (new[] { InitSection, VariablesSection, SourceFilesSection, EndSection }.Contains(line))
                {
                    currentSection = line;
                }
                else
                {
                    switch (currentSection)
                    {
                        case InitSection:
                        case VariablesSection:
                            var groups = VariablesRegex.Match(line).Groups;
                            var key = groups[1].Value;
                            var value = groups[2].Value;
                            switch (key)
                            {
                                case VersionKey:
                                    version = int.Parse(value);
                                    break;
                                case VersionControlKey:
                                    versionControl = value;
                                    break;
                                case TargetKey:
                                    target = value;
                                    break;
                            }
                            break;
                        case SourceFilesSection:
                            sources.Add(SourceFileDescriptor.Parse(line));
                            break;
                    }
                }
            }

            descriptor = new[] { "http", "https" }.Contains(versionControl)
                ? new HttpSourceServerDescriptor(version, versionControl, target, sources.ToArray())
                : null;
            return descriptor != null;
        }
        public void Perform()
        {
            var srcsrvValues = _assemblyFiles
                               .Select(PdbPath)
                               .Where(File.Exists)
                               .Select(_pdbStr.Read)
                               .ToArray();
            var descriptors = srcsrvValues.Select(srcsrv =>
            {
                HttpSourceServerDescriptor descriptor;
                return(new
                {
                    Valid = HttpSourceServerDescriptor.TryParse(srcsrv, out descriptor),
                    Descriptor = descriptor
                });
            })
                              .Where(tuple => tuple.Valid)
                              .Select(tuple => tuple.Descriptor)
                              .ToArray();

            _srcSrv = descriptors.Any()
                ? descriptors.First().MergeWith(descriptors.Skip(1)).ToString()
                : srcsrvValues.FirstOrDefault();
        }
 public static IEnumerable<string> GivenSourceServerDataObject_WhenCallingToString_ThenAProperRawValueIGenerated(HttpSourceServerDescriptor descriptor)
 {
     return descriptor.ToString().GetLines();
 }
 public static void GivenAListOfSourceServerDescriptor_WhenMergingThem_ThenItShouldBeProperlyMerged(
     int expectedVersion,
     string expectedVersionControl,
     string expectedTarget,
     IDictionary<string, string> expectedSourceFiles,
     HttpSourceServerDescriptor primary,
     IEnumerable<HttpSourceServerDescriptor> other)
 {
     var merged = primary.MergeWith(other);
     Assert.That(merged.Version, Is.EqualTo(expectedVersion));
     Assert.That(merged.VersionControl, Is.EqualTo(expectedVersionControl));
     Assert.That(merged.Target, Is.EqualTo(expectedTarget));
     CollectionAssert.AreEquivalent(
         expectedSourceFiles,
         merged.SourceFiles.Select(file => file.Variables)
             .ToDictionary(vars => vars.ElementAt(0), vars => vars.ElementAt(1)));
 }