private void ApplyAssignPatch(ILogMessageSink logger, IPolicyPatch policyPatch, List <JObject> patchPolicies, JArray policySet)
        {
            foreach (JObject patchPolicy in patchPolicies)
            {
                JObject patchTarget = FindPatchTarget(policyPatch, policySet);

                string sourceTerm = CreateSourceTerm(patchPolicy, policyPatch.PatchSourcePath, "Assign");

                if (patchTarget == null)
                {
                    logger.Warning(
                        $"Patch {sourceTerm} was not applied because a matching base patch was not found.");
                    continue;
                }

                if (policyPatch.PatchTargetQuery != null)
                {
                    patchTarget = (JObject)patchTarget.SelectToken(policyPatch.PatchTargetQuery);

                    if (patchTarget == null)
                    {
                        logger.Warning(
                            $"Patch {sourceTerm} was not applied because a matching base patch target {policyPatch.PatchTargetQuery} was not found.");
                        continue;
                    }
                }

                foreach (JProperty patchProperty in patchPolicy.Properties())
                {
                    if (patchProperty.Name.StartsWith("ยง"))
                    {
                        continue;
                    }

                    patchTarget[patchProperty.Name] = patchProperty.Value;
                }

                AppendPatchSource(patchTarget, sourceTerm);

                logger.Message($"{sourceTerm}\n\twhere {JsonConvert.SerializeObject(policyPatch.Conditions)}");
            }
        }
        private bool DetermineResult(Stopwatch sw)
        {
            if (!_logMessageSink.HasErrors && !_logMessageSink.HasWarnings)
            {
                _logMessageSink.Message($"Generation was done successfully({sw.Elapsed.Seconds}s)...");
                return(true);
            }

            if (_logMessageSink.HasErrors)
            {
                _logMessageSink.Error($"Generation was finished with errors({sw.Elapsed.Seconds}s)...");
                return(false);
            }

            if (_logMessageSink.HasWarnings)
            {
                _logMessageSink.Warning($"Generation was finished with warnings({sw.Elapsed.Seconds}s)...");
            }

            return(true);
        }
        public void Flush()
        {
            List <LogMessage> messages = this.messages;

            this.messages = new List <LogMessage>();
            messages.ForEach(l =>
            {
                if (l is ErrorMessage)
                {
                    _logMessageSink.Error(l.Message);
                    return;
                }

                if (l is WarningMessage)
                {
                    _logMessageSink.Warning(l.Message);
                    return;
                }

                _logMessageSink.Message(l.Message);
            });
            messages.Clear();
        }
        private void ApplyReplacePatch(ILogMessageSink logger, IPolicyPatch policyPatch, List <JObject> patchPolicies, JArray policySet)
        {
            foreach (JObject patchPolicy in patchPolicies)
            {
                JObject originalObject = FindPatchTarget(policyPatch, policySet);

                string sourceTerm = CreateSourceTerm(patchPolicy, policyPatch.PatchSourcePath, "Replace");

                if (originalObject == null)
                {
                    logger.Warning(
                        $"Patch {sourceTerm} was not applied because a matching base patch was not found.");
                    continue;
                }

                int index = policySet.IndexOf(originalObject);

                policySet.RemoveAt(index);

                policySet.Insert(index, patchPolicy);

                logger.Message($"{sourceTerm}\n\twhere {JsonConvert.SerializeObject(policyPatch.Conditions)}");
            }
        }