private bool RunValidationQueries(NightWatchmanSettings settings, CommonExtractionContext context)
        {
            foreach (var query in settings.Queries)
            {
                if (!string.IsNullOrEmpty(query.ValidationQuery))
                {
                    var validationParameters = new[]
                    {
                        new SqlParameter("@startdate", SqlDbType.DateTime)
                        {
                            Value = context.StartDate
                        },
                        new SqlParameter("@enddate", SqlDbType.DateTime)
                        {
                            Value = context.EndtDate
                        }
                    };

                    var validationData = queryExecutor.ExecuteQuery(
                        query.ValidationQuery, "Validate_" + query.Name, validationParameters);
                    if (!ValidateQueryResult(query, validationData))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public override void ExtractData(string outputDirectory, CommonExtractionContext context, Dictionary <string, object> pluginSettings)
        {
            GlobalContext.Properties[Name] = Name + " Plugin";

            var settings = new NightWatchmanSettings(Path.Combine(context.PluginsDirectory, "SavingsAnalysis.Plugin.NightWatchman.xml"));

            if (!RunValidationQueries(settings, context))
            {
                return;
            }

            SqlQueryResultSerializer resultSerializer = new SqlQueryResultSerializer(queryExecutor, context.SccmConnection, outputDirectory);

            foreach (var query in settings.Queries)
            {
                var queryParameters = new[]
                {
                    new SqlParameter("@startdate", SqlDbType.DateTime)
                    {
                        Value = context.StartDate
                    },
                    new SqlParameter("@enddate", SqlDbType.DateTime)
                    {
                        Value = context.EndtDate
                    }
                };

                resultSerializer.SerializeQueryResult(query.SelectionQuery, query.Name, queryParameters, (msg) => NotifyProgress(
                                                          new ExtractionEventArgs()
                {
                    Status  = ExtractionStatus.Succeeded,
                    Message = msg
                }));

                Log.Info("Successfully extracted data for " + query.Name);
            }

            if (settings.Queries.Count > 0)
            {
                NotifyProgress(
                    new ExtractionEventArgs()
                {
                    Status = ExtractionStatus.Succeeded, Message = "All query results collected successfully."
                });
            }
        }
        public override void ExtractData(string outputDirectory, CommonExtractionContext context, Dictionary<string, object> pluginSettings)
        {
            GlobalContext.Properties[Name] = Name + " Plugin";

            var settings = new NightWatchmanSettings(Path.Combine(context.PluginsDirectory, "SavingsAnalysis.Plugin.NightWatchman.xml"));
            if (!RunValidationQueries(settings, context))
            {
                return;
            }

            SqlQueryResultSerializer resultSerializer = new SqlQueryResultSerializer(queryExecutor, context.SccmConnection, outputDirectory);
            foreach (var query in settings.Queries)
            {
                var queryParameters = new[]
                        {
                            new SqlParameter("@startdate", SqlDbType.DateTime) { Value = context.StartDate },
                            new SqlParameter("@enddate", SqlDbType.DateTime) { Value = context.EndtDate }
                        };

                resultSerializer.SerializeQueryResult(query.SelectionQuery, query.Name, queryParameters, (msg) => NotifyProgress(
                            new ExtractionEventArgs()
                            {
                               Status = ExtractionStatus.Succeeded,
                               Message = msg
                            }));

                Log.Info("Successfully extracted data for " + query.Name);
            }

            if (settings.Queries.Count > 0)
            {
                NotifyProgress(
                    new ExtractionEventArgs()
                        {
                            Status = ExtractionStatus.Succeeded, Message = "All query results collected successfully." 
                        });
            }
        }
        private bool RunValidationQueries(NightWatchmanSettings settings, CommonExtractionContext context)
        {
            foreach (var query in settings.Queries)
            {
                if (!string.IsNullOrEmpty(query.ValidationQuery))
                {
                    var validationParameters = new[]
                        {
                            new SqlParameter("@startdate", SqlDbType.DateTime) { Value = context.StartDate },
                            new SqlParameter("@enddate", SqlDbType.DateTime) { Value = context.EndtDate }
                        };

                    var validationData = queryExecutor.ExecuteQuery(
                        query.ValidationQuery, "Validate_" + query.Name, validationParameters);
                    if (!ValidateQueryResult(query, validationData))
                    {
                        return false;
                    }
                }
            }

            return true;
        }