コード例 #1
0
        /// <summary>
        /// This method verifies that all of the required inputs exist for each Resource object.
        /// </summary>
        /// <param name="vaultList">The KeyVault information obtained from MasterConfig.json file</param>
        /// <param name="configVaults">The Json object formed from parsing the MasterConfig.json file</param>
        public void checkMissingResourceFields(JsonInput vaultList, JObject configVaults)
        {
            JEnumerable <JToken> resourceList = configVaults.SelectToken($".Resources").Children();

            int i = 0;

            foreach (Resource res in vaultList.Resources)
            {
                JToken jres = resourceList.ElementAt(i);

                if (res.SubscriptionId != null && res.ResourceGroups.Count() == 0 && jres.Children().Count() > 1)
                {
                    throw new Exception($"Invalid fields for Resource with SubscriptionId '{res.SubscriptionId}' were defined. Valid fields are 'SubscriptionId' and 'ResourceGroups'.");
                }
                else if (res.SubscriptionId == null && jres.Children().Count() > 0)
                {
                    throw new Exception($"Missing 'SubscriptionId' for Resource. Invalid fields were defined; valid fields are 'SubscriptionId' and 'ResourceGroups'.");
                }
                else if (res.SubscriptionId != null && res.ResourceGroups.Count() != 0)
                {
                    if (jres.Children().Count() > 2)
                    {
                        throw new Exception($"Invalid fields other than 'SubscriptionId' and 'ResourceGroups' were defined for Resource with SubscriptionId '{res.SubscriptionId}'.");
                    }

                    int j = 0;
                    foreach (ResourceGroup resGroup in res.ResourceGroups)
                    {
                        JEnumerable <JToken> groupList = jres.SelectToken($".ResourceGroups").Children();
                        JToken jresGroup = groupList.ElementAt(j);

                        if (resGroup.ResourceGroupName != null && resGroup.KeyVaults.Count() == 0 && jresGroup.Children().Count() > 1)
                        {
                            throw new Exception($"Invalid fields for ResourceGroup with ResourceGroupName '{resGroup.ResourceGroupName}' were defined. " +
                                                $"Valid fields are 'ResourceGroupName' and 'KeyVaults'.");
                        }
                        else if (resGroup.ResourceGroupName == null && jresGroup.Children().Count() > 0)
                        {
                            throw new Exception("Missing 'ResourceGroupName' for ResourceGroup. Invalid fields were defined; valid fields are 'ResourceGroupName' and 'KeyVaults'.");
                        }
                        else if (resGroup.ResourceGroupName != null && resGroup.KeyVaults.Count() != 0 && jresGroup.Children().Count() > 2)
                        {
                            throw new Exception($"Invalid fields other than 'ResourceGroupName' and 'KeyVaults' were defined for ResourceGroup " +
                                                $"with ResourceGroupName '{resGroup.ResourceGroupName}'.");
                        }
                        ++j;
                    }
                }
                ++i;
            }
        }
コード例 #2
0
        private static Difference CompareItems(JArray actual, JArray expected, JPath path)
        {
            JEnumerable <JToken> actualChildren   = actual.Children();
            JEnumerable <JToken> expectedChildren = expected.Children();

            if (actualChildren.Count() != expectedChildren.Count())
            {
                return(new Difference(DifferenceKind.DifferentLength, path));
            }

            for (int i = 0; i < actualChildren.Count(); i++)
            {
                Difference firstDifference = FindFirstDifference(actualChildren.ElementAt(i), expectedChildren.ElementAt(i),
                                                                 path.AddIndex(i));

                if (firstDifference != null)
                {
                    return(firstDifference);
                }
            }

            return(null);
        }
コード例 #3
0
        public override bool Execute()
        {
            string inputFile  = InputDepsFilePath.ItemSpec;
            string outputFile = OutputDepsFilePath.ItemSpec;

            string[] keptAssemblies    = KeptAssemblies.Select(a => a.ItemSpec).ToArray();
            string[] allAssemblies     = ManagedPublishAssemblies.Select(a => a.ItemSpec).ToArray();
            string[] removedAssemblies = allAssemblies.Except(keptAssemblies).ToArray();

            var removedAssembliesSet = new HashSet <string> (removedAssemblies, StringComparer.InvariantCultureIgnoreCase);

            JObject o = JObject.Parse(File.ReadAllText(inputFile));

            JObject targets = (JObject)o["targets"];

            // Remove targets
            foreach (JProperty target in targets.Children())
            {
                JEnumerable <JToken> children = target.Value.Children();
                for (int i = 0; i < children.Count(); ++i)
                {
                    //foreach (JProperty subtarget in target.Value.Children()) {
                    var    subtarget = (JProperty)children.ElementAt(i);
                    string name      = subtarget.Name.Substring(0, subtarget.Name.IndexOf('/'));
                    if (removedAssembliesSet.Contains(name + ".dll"))
                    {
                        subtarget.Remove();
                        i--;
                        continue;
                    }

                    // Remove dependencies
                    var dependencies = subtarget.Value["dependencies"];
                    if (dependencies != null)
                    {
                        for (int j = 0; j < dependencies.Count(); ++j)
                        {
                            var dependency = ((JProperty)dependencies.ElementAt(j));

                            if (removedAssembliesSet.Contains(dependency.Name + ".dll"))
                            {
                                dependency.Remove();
                                j--;
                                continue;
                            }
                        }
                    }

                    // Remove runtimes
                    var runtimes = subtarget.Value["runtime"];
                    if (runtimes != null)
                    {
                        for (int j = 0; j < runtimes.Count(); ++j)
                        {
                            var    runtime         = ((JProperty)runtimes.ElementAt(j));
                            string runtimeFileName = runtime.Name.Substring(runtime.Name.LastIndexOf('/') + 1);

                            if (removedAssembliesSet.Contains(runtimeFileName))
                            {
                                runtime.Remove();
                                j--;
                                continue;
                            }
                        }
                    }
                }
            }

            // Remove libraries
            JObject libraries = (JObject)o["libraries"];

            JEnumerable <JToken> libraryChildren = libraries.Children();

            for (int i = 0; i < libraryChildren.Count(); ++i)
            {
                var    library = (JProperty)libraryChildren.ElementAt(i);
                string name    = library.Name.Substring(0, library.Name.IndexOf('/'));
                if (removedAssembliesSet.Contains(name + ".dll"))
                {
                    library.Remove();
                    i--;
                    continue;
                }
            }

            File.WriteAllText(outputFile, o.ToString());

            return(true);
        }