public void CompareSavedQueryMetaPxsq()
        {
            var fileRepo = new FileCompareRepo();
            var savedQueryMetaCompareResultModel = new List <SavedQueryMetaCompareResultModel>();
            var compareResultFile = _appSettingsHandler.ReadSetting("CompareSavedQueryResultFile");

            var pxsqFolder1 = _appSettingsHandler.ReadSetting("SQFileFormat1");
            var pxsqFolder2 = _appSettingsHandler.ReadSetting("SQFileFormat2");

            var resultFolder1 = _appSettingsHandler.ReadSetting("ResultFolder1");
            var resultFolder2 = _appSettingsHandler.ReadSetting("ResultFolder2");


            var directory     = new DirectoryInfo(pxsqFolder1);
            var masks         = new[] { "*.pxsq" };
            var savedQueryIds = masks.SelectMany(directory.EnumerateFiles);

            fileRepo.DeleteAllFilesInFolder($"{_appSettingsHandler.ReadSetting("ResultFolder1")}/SavedQueryMeta/");
            fileRepo.DeleteAllFilesInFolder($"{_appSettingsHandler.ReadSetting("ResultFolder2")}/SavedQueryMeta/");

            foreach (var savedQueryId in savedQueryIds)
            {
                var sqId = savedQueryId.Name.Substring(0, savedQueryId.Name.LastIndexOf("."));

                var sq1 = fileRepo.ReadFromFileJson($"{pxsqFolder1}\\{savedQueryId.Name}");
                var sq2 = fileRepo.ReadFromFileJson($"{pxsqFolder2}\\{savedQueryId.Name}");

                if (sq1 != null && sq2 != null)
                {
                    var sq1ResultString = SavedQueryString(sq1);
                    var sq2ResultString = SavedQueryString(sq2);

                    _savedQueryService.SaveToFile(sq1ResultString, sqId, "SavedQueryMeta",
                                                  $"{resultFolder1}\\SavedQueryMeta\\{sqId}\\");
                    _savedQueryService.SaveToFile(sq2ResultString, sqId, "SavedQueryMeta",
                                                  $"{resultFolder2}\\SavedQueryMeta\\{sqId}\\");

                    var result = CompareSavedQueryResults(
                        $@"{resultFolder1}\SavedQueryMeta\{sqId}\{sqId}_SavedQueryMeta.txt",
                        $@"{resultFolder2}\SavedQueryMeta\{sqId}\{sqId}_SavedQueryMeta.txt");
                    savedQueryMetaCompareResultModel.Add(new SavedQueryMetaCompareResultModel()
                    {
                        Id = sqId, Result = result
                    });
                }
                else
                {
                    savedQueryMetaCompareResultModel.Add(new SavedQueryMetaCompareResultModel()
                    {
                        Id = sqId, Result = null
                    });
                }
            }

            fileRepo.DeleteFile(compareResultFile);
            fileRepo.SaveToFile(savedQueryMetaCompareResultModel, compareResultFile);
        }
        public void CompareSavedQueryMetaDatabase()
        {
            var fileRepo = new FileCompareRepo();
            var compareResultModelList           = new List <CompareResultModel>();
            var savedQueryMetaCompareResultModel = new List <SavedQueryMetaCompareResultModel>();
            var connstring1 = _appSettingsHandler.ReadSetting("SavedQueryConnectionString1");
            var connstring2 = _appSettingsHandler.ReadSetting("SavedQueryConnectionString2");

            var compareResultFile = _appSettingsHandler.ReadSetting("CompareSavedQueryResultFile");

            var resultFolder1 = _appSettingsHandler.ReadSetting("ResultFolder1") + "/SavedQueryMeta/";
            var resultFolder2 = _appSettingsHandler.ReadSetting("ResultFolder2") + "/SavedQueryMeta/";

            ;

            fileRepo.DeleteAllFilesInFolder($"{resultFolder1}");
            fileRepo.DeleteAllFilesInFolder($"{resultFolder2}");

            var repo = new DatabaseRepo();

            var savedQueries = repo.GetSavedQueries(connstring1, 10);

            foreach (var savedQuery in savedQueries)
            {
                var savedQueryResult1 = repo.GetSavedQueryById(savedQuery, connstring1);
                var savedQueryResult2 = repo.GetSavedQueryById(savedQuery, connstring2);

                if (savedQueryResult1 != string.Empty && savedQueryResult2 != string.Empty)
                {
                    _savedQueryService.SaveToFile(savedQueryResult1, savedQuery, "SavedQueryMeta",
                                                  $"{resultFolder1}\\{savedQuery}\\");
                    _savedQueryService.SaveToFile(savedQueryResult2, savedQuery, "SavedQueryMeta",
                                                  $"{resultFolder2}\\{savedQuery}\\");

                    var result = CompareSavedQueryResults(
                        $@"{resultFolder1}\{savedQuery}\{savedQuery}_SavedQueryMeta.txt",
                        $@"{resultFolder2}\{savedQuery}\{savedQuery}_SavedQueryMeta.txt");

                    savedQueryMetaCompareResultModel.Add(new SavedQueryMetaCompareResultModel()
                    {
                        Id = savedQuery, Result = result
                    });
                }
                else
                {
                    savedQueryMetaCompareResultModel.Add(new SavedQueryMetaCompareResultModel()
                    {
                        Id = savedQuery, Result = null
                    });
                }
            }

            fileRepo.DeleteFile(compareResultFile);
            fileRepo.SaveToFile(savedQueryMetaCompareResultModel, compareResultFile);
        }
        public void CompareApi(string language, string database)
        {
            // get url for api site 1
            var serverAddress1 = _appSettingsHandler.ReadSetting("WebApiAddress1");
            // get url for api site 2
            var serverAddress2 = _appSettingsHandler.ReadSetting("WebApiAddress2");

            var queryTextListPath = _appSettingsHandler.ReadSetting("queryTextListPath");

            var resultFolder1          = _appSettingsHandler.ReadSetting("ResultFolder1") + "/Api/";
            var resultFolder2          = _appSettingsHandler.ReadSetting("ResultFolder2") + "/Api/";
            var compareResultFile      = _appSettingsHandler.ReadSetting("CompareApiResultFile");
            var fileRepo               = new FileCompareRepo();
            var compareResultModelList = new List <CompareResultApiModel>();


            fileRepo.DeleteAllFilesInFolder(resultFolder1);
            fileRepo.DeleteAllFilesInFolder(resultFolder2);

            string qStringGlobal = string.Empty;

            qStringGlobal = _appSettingsHandler.ReadSetting("WebApiRootPrefix");

            qStringGlobal += language;

            qStringGlobal += $"/{database}";

            var menuItems =
                JsonConvert.DeserializeObject <IEnumerable <MenuItem> >(
                    _savedQueryService.GetService(serverAddress1 + qStringGlobal));

            if (!menuItems.Any())
            {
                return;
            }

            menuItems = GetReduceList <MenuItem>(menuItems.ToList());

            // menuItems = menuItems.Where(x => x.Id == "UF");

            foreach (var menuItem in menuItems)
            {
                string qString = string.Empty;

                qString = _appSettingsHandler.ReadSetting("WebApiRootPrefix");

                qString += language;

                qString += $"/{database}";

                qString += $"/{menuItem.Id}";
                var level1Items =
                    JsonConvert.DeserializeObject <IEnumerable <MenuItem> >(
                        _savedQueryService.GetService(serverAddress1 + qString));
                level1Items = GetReduceList <MenuItem>(level1Items.ToList());
                foreach (var level1Item in level1Items)
                {
                    var level1qString = qString + $"/{level1Item.Id}";
                    var level2Items   =
                        JsonConvert.DeserializeObject <IEnumerable <MenuItem> >(
                            _savedQueryService.GetService(serverAddress1 + level1qString));
                    level2Items = GetReduceList <MenuItem>(level2Items.ToList());
                    foreach (var level2Item in level2Items)
                    {
                        var level2qString = level1qString + $"/{level2Item.Id}";

                        var level2Result = _savedQueryService.GetService(serverAddress1 + level2qString);

                        try
                        {
                            var level3Items = JsonConvert.DeserializeObject <IEnumerable <MenuItem> >(level2Result);
                            level3Items = GetReduceList <MenuItem>(level3Items.ToList());
                            CompareApi(level3Items, level2qString, compareResultModelList);
                        }
                        catch (JsonSerializationException)
                        {
                            CompareApi(level2Items, level1qString, compareResultModelList);
                        }
                    }
                }
            }

            fileRepo.DeleteFile(compareResultFile);
            fileRepo.SaveToFile(compareResultModelList, compareResultFile);

            var resultFile = fileRepo.ReadFromFile <CompareResultApiModel>(compareResultFile);
        }
        public void Compare()
        {
            // get url for api site 1
            var serverAddress1 = _appSettingsHandler.ReadSetting("WebApiAddress1") + $"sq/";
            // get url for api site 2
            var serverAddress2 = _appSettingsHandler.ReadSetting("WebApiAddress2") + $"sq/";

            var queryTextListPath = _appSettingsHandler.ReadSetting("queryTextListPath");

            var resultFolder1          = _appSettingsHandler.ReadSetting("ResultFolder1") + "/SavedQuery/";
            var resultFolder2          = _appSettingsHandler.ReadSetting("ResultFolder2") + "/SavedQuery/";
            var compareResultFile      = _appSettingsHandler.ReadSetting("CompareResultFile");
            var fileRepo               = new FileCompareRepo();
            var compareResultModelList = new List <CompareResultModel>();

            var queryList = _repo.GetSavedQueryFileFormat(queryTextListPath);

            fileRepo.DeleteAllFilesInFolder(resultFolder1);
            fileRepo.DeleteAllFilesInFolder(resultFolder2);
            {
                foreach (var query in queryList)
                {
                    var compareResultModel = new CompareResultModel {
                        SavedQuery = query
                    };

                    var outputFormats = Enum.GetValues(typeof(OutputFormat)).Cast <OutputFormat>();

                    // Check if you can run the saved query at all on reference site
                    var res = _savedQueryService.GetService($"{serverAddress1}{query}");

                    if (res == null)
                    {
                        foreach (var outputFormat in outputFormats)
                        {
                            compareResultModel.UpdateModel(outputFormat, null);
                        }
                    }
                    else
                    {
                        foreach (var outputFormat in outputFormats)
                        {
                            bool saveQuery1;
                            bool saveQuery2;
                            bool?result;

                            if (outputFormat == OutputFormat.xlsx || outputFormat == OutputFormat.xlsx_doublecolumn)
                            {
                                saveQuery1 = _savedQueryService.GetAndSaveAsFile($"{serverAddress1}{query}.{outputFormat}",
                                                                                 $"{query}_{outputFormat}",
                                                                                 "xlsx", $"{resultFolder1}\\{query}\\");

                                saveQuery2 = _savedQueryService.GetAndSaveAsFile($"{serverAddress1}{query}.{outputFormat}",
                                                                                 $"{query}_{outputFormat}",
                                                                                 "xlsx", $"{resultFolder2}\\{query}\\");

                                Thread.Sleep(100);

                                if (saveQuery1 && saveQuery2)
                                {
                                    var resultList1 =
                                        _excelComparer.ReadExcelFile(
                                            $@"{resultFolder1}\{query}\{query}_{outputFormat}.xlsx");
                                    var resultList2 =
                                        _excelComparer.ReadExcelFile(
                                            $@"{resultFolder2}\{query}\{query}_{outputFormat}.xlsx");
                                    result = CompareArrayLists(resultList1, resultList2);
                                }
                                else
                                {
                                    result = null;
                                }
                            }
                            else
                            {
                                var res1 = _savedQueryService.GetService($"{serverAddress1}{query}.{outputFormat}");

                                var res2 = _savedQueryService.GetService($"{serverAddress2}{query}.{outputFormat}");

                                Thread.Sleep(100);

                                if (res1 != null && res2 != null)
                                {
                                    _savedQueryService.SaveToFile(res1, query, outputFormat.ToString(),
                                                                  $"{resultFolder1}\\{query}\\");
                                    _savedQueryService.SaveToFile(res2, query, outputFormat.ToString(),
                                                                  $"{resultFolder2}\\{query}\\");

                                    if (outputFormat == OutputFormat.html5_table)
                                    {
                                        fileRepo.DeleteFirstRowInFile($@"{resultFolder1}\{query}\{query}_{outputFormat}.txt");
                                        fileRepo.DeleteFirstRowInFile($@"{resultFolder2}\{query}\{query}_{outputFormat}.txt");
                                    }

                                    result = CompareSavedQueryResults(
                                        $@"{resultFolder1}\{query}\{query}_{outputFormat}.txt",
                                        $@"{resultFolder2}\{query}\{query}_{outputFormat}.txt");
                                }
                                else
                                {
                                    result = null;
                                }
                            }

                            compareResultModel.UpdateModel(outputFormat, result);
                        }
                    }
                    compareResultModelList.Add(compareResultModel);
                }

                fileRepo.DeleteFile(compareResultFile);
                fileRepo.SaveToFile(compareResultModelList, compareResultFile);
                var resultFile = fileRepo.ReadFromFile <CompareResultModel>(compareResultFile);
            }
        }