Esempio n. 1
0
        private void saveQueryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QueryReport report = new QueryReport();

            report.conditions       = AssembleConditions();
            report.queries          = new List <string>(listQuery.Items.Cast <string>().ToList());
            report.selectedFields   = new List <string>(userSelectedFields.Items.Cast <string>().ToList());
            report.unusedFields     = new List <string>(allFieldNames.Items.Cast <string>().ToList());
            report.useExclusionList = cbExclusionList.Checked;
            report.useAllShips      = cbAllShips.Checked;

            Settings settings = Commons.GetSettings();
            string   def      = settings.SaveLocation;

            SaveFileDialog saveDlg = new SaveFileDialog();

            saveDlg.InitialDirectory = def;
            saveDlg.DefaultExt       = "rpt";
            saveDlg.FileName         = "report.rpt";
            saveDlg.Filter           = "Randomizer Query Report (*.rpt)|*.rpt";
            if (saveDlg.ShowDialog() == DialogResult.OK)
            {
                string file = saveDlg.FileName;
                if (!file.EndsWith(".rpt"))
                {
                    file += ".rpt";
                }
                BinarySerialize.WriteToBinaryFile(file, report);
            }
        }
Esempio n. 2
0
 private void OnQueryProgressChanged(QueryReport report)
 {
     _statisticBox.Lines = new[]
     {
         string.Format(ALL_REQUESTS_PATTERN, report.AllQueriesCount),
         string.Format(GOOD_REQUESTS_PATTERN, report.SuccessQueriesCount),
         string.Format(BAD_REQUESTS_PATTERN, report.FailedQueriesCount)
     };
 }
        public QueryReport ExecuteSearchFight(List <string> args)
        {
            var queryReport = new QueryReport();

            queryReport.QueryResults = _searchFightService.SearchQueries(args);
            queryReport.QueryWinners = _searchFightService.QueryWinnersBySearchEngine(queryReport.QueryResults);
            queryReport.TotalWinner  = _searchFightService.GetTotalWinner(queryReport.QueryResults);
            return(queryReport);
        }
Esempio n. 4
0
 private void QueryReportBtn_Click(object sender, RoutedEventArgs e)
 {
     QueryReport.ShowWindow();
 }
 public void BuildConsoleResponse(QueryReport queryReport)
 {
     BuildResults(queryReport.QueryResults);
     BuildWinners(queryReport.QueryWinners);
     BuildTotalWinner(queryReport.TotalWinner);
 }
Esempio n. 6
0
        private void loadQueryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Settings settings = Commons.GetSettings();

            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter           = "Randomizer Query Report (*.rpt)|*.rpt";
            openFile.DefaultExt       = "rpt";
            openFile.InitialDirectory = settings.SaveLocation;

            string fileName = "";

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                fileName = openFile.FileName;
            }
            else
            {
                return;
            }

            QueryReport report = BinarySerialize.ReadFromBinaryFile <QueryReport>(fileName);

            UnselectAllCheckboxes();
            allFieldNames.Items.Clear();
            userSelectedFields.Items.Clear();
            listQuery.Items.Clear();

            if (report.useAllShips == false)
            {
                cbAllShips.Checked = false; cbPersonalShips.Checked = true; cbExclusionList.Enabled = true;
            }
            if (report.useExclusionList)
            {
                cbExclusionList.Checked = true;
            }
            else
            {
                cbExclusionList.Checked = false;
            }

            foreach (string itm in report.unusedFields)
            {
                allFieldNames.Items.Add(itm);
            }
            foreach (string itm in report.selectedFields)
            {
                userSelectedFields.Items.Add(itm);
            }
            foreach (string itm in report.queries)
            {
                listQuery.Items.Add(itm);
            }

            foreach (string itm in report.conditions)
            {
                if (itm.Equals("PS:" + cbTechTree.Tag.ToString()))
                {
                    cbTechTree.Checked = true;
                }
                else if (itm.Equals("PS:" + cbPremium.Tag.ToString()))
                {
                    cbPremium.Checked = true;
                }
                else if (itm.Equals(CONDITION_ALLNATIONS) || itm.Equals(CONDITION_ALLSHIPS) || itm.Equals(CONDITION_ALLTIERS))
                {
                }
                else
                {
                    SelectCheckboxByConditionName(itm);
                }
            }

            if (cbPremium.Checked && cbTechTree.Checked)
            {
                cbTechTree.Checked = false;
                cbPremium.Checked  = false;
            }

            btnShow_Click(new object(), new EventArgs());
        }
Esempio n. 7
0
        //TODO:refactor it.
        public void GenerateReport(string project, Action <string> descriptionText)
        {
            var popup = new QueryReport {
                Project = project
            };
            Project currProject = tfsManager.GetProject(project);
            var     qm          = new QueryManager(currProject, popup.QueriesTree, tfsManager.ItemsStore);
            List <FieldDefinition> allFields = tfsManager.GetAllAvailableWorkItemFieldsForProject(project);
            string        queryName          = string.Empty;
            Query         query            = null;
            List <string> displayFieldList = null;

            qm.Query += qDef =>
            {
                if (qDef != null)
                {
                    tfsManager.ItemsStore.RefreshCache();
                    query            = new Query(tfsManager.ItemsStore, qDef.QueryText);
                    displayFieldList = query.DisplayFieldList.Cast <FieldDefinition>().Select(f => f.Name).ToList();
                    popup.QueryDef   = qDef;

                    // clear controls
                    popup.PropertiesList.SelectionMode = SelectionMode.Multiple;
                    popup.tbxHeader.Clear();
                    popup.PropertiesList.Items.Clear();
                    popup.PropertiesListBody.Items.Clear();
                    queryName = qDef.Name;
                    if (displayFieldList != null)
                    {
                        popup.PopulateQueryFields(allFields, displayFieldList);
                        popup.InsertButton.IsEnabled = true;
                    }
                }
                else
                {
                    popup.InsertButton.IsEnabled = false;
                }
            };



            switch (tfsManager.tfsVersion)
            {
            case TfsVersion.Tfs2011:
                popup.ManageQueriesLink.NavigateUri = new Uri(string.Format("{0}/{1}/_workitems", tfsManager.ItemsStore.TeamProjectCollection.Uri, project));
                break;

            case TfsVersion.Tfs2010:
                popup.ManageQueriesLink.NavigateUri = new Uri(string.Format("{0}/web/UI/Pages/WorkItems/QueryExplorer.aspx?pguid={1}", tfsManager.GetTfsUrl(), tfsManager.GetProject(project).Guid));
                break;
            }
            popup.Create(null, Icons.Report);

            //Generate Report from WI list
            if (popup.byWIIDsTabItem.IsSelected && !popup.IsCanceled)
            {
                tfsManager.ItemsStore.RefreshCache();
                query     = new Query(tfsManager.ItemsStore, popup.queryDef.QueryText);
                queryName = popup.queryDef.Name;
            }

            revisionDate = popup.onDate.SelectedDate;
            if (!popup.IsCanceled)
            {
                List <string> metaDataSelectedItems = GetSelectedItemsFromCheckListBox(popup.PropertiesList);
                List <string> bodySelectedItems     = GetSelectedItemsFromCheckListBox(popup.PropertiesListBody);
                bool          includeAttachments    = popup.IncludeAttachmentsCheckBox.IsChecked.Value;

                var pd = new ProgressDialog();

                string uiCulture = Thread.CurrentThread.CurrentUICulture.ToString();

                pd.Execute(ts =>
                {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(uiCulture);
                    pd.UpdateProgress(0, ResourceHelper.GetResourceString("MSG_RETRIEVING_WORK_ITEMS"), true);
                    SetProjectTextWithUrl(project, string.Format("{0}: {1}", ResourceHelper.GetResourceString("MSG_REPORT_TITLE"), queryName));

                    if (query.IsLinkQuery)
                    {
                        WorkItemLinkInfo[] queryResults = query.RunLinkQuery();

                        // Dictionary<Id,HierarchyLevel>
                        var hierarchy      = new Dictionary <int, int>();
                        int hierarchyLevel = 1;
                        int itemsCount     = queryResults.Count();
                        for (int i = 0; i < itemsCount; i++)
                        {
                            try
                            {
                                if (!ts.IsCancellationRequested)
                                {
                                    WorkItemLinkInfo item = queryResults[i];
                                    WorkItem workItem     = tfsManager.ItemsStore.GetWorkItem(item.TargetId);
                                    DateTime date         = DateTime.MaxValue;

                                    popup.Dispatcher.Invoke((Action)(() =>
                                    {
                                        date = popup.onDate.SelectedDate.GetValueOrDefault(date);
                                    }));

                                    if (date != DateTime.MaxValue)
                                    {
                                        Revision onDateItem = GetLastRevision(workItem, date);

                                        if (onDateItem != null)
                                        {
                                            pd.UpdateProgress(Convert.ToInt32(i / (decimal)itemsCount * 100), string.Format(ResourceHelper.GetResourceString("REPORT_PROGRESS"), i + 1, itemsCount, onDateItem.WorkItem.Title), false);
                                            AddHierarchy(hierarchy, ref hierarchyLevel, ref item);

                                            // TODO:Move to separate Method
                                            WriteReport(descriptionText, metaDataSelectedItems, bodySelectedItems, includeAttachments, onDateItem, hierarchyLevel);
                                            //WriteReport(descriptionText, metaDataSelectedItems, bodySelectedItems, includeAttachments, workItem, hierarchyLevel);
                                        }
                                    }
                                    else
                                    {
                                        pd.UpdateProgress(Convert.ToInt32(i / (decimal)itemsCount * 100), string.Format(ResourceHelper.GetResourceString("REPORT_PROGRESS"), i + 1, itemsCount, workItem.Title), false);
                                        AddHierarchy(hierarchy, ref hierarchyLevel, ref item);
                                        WriteReport(descriptionText, metaDataSelectedItems, bodySelectedItems, includeAttachments, workItem, hierarchyLevel);
                                    }
                                }
                            }
                            //catch (DeniedOrNotExistException)
                            //{
                            //}
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, ResourceHelper.GetResourceString("ERROR_TEXT"), MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }
                    else
                    {
                        WorkItemCollection queryResults = query.RunQuery();
                        int counter = 0;
                        foreach (WorkItem item in queryResults)
                        {
                            DateTime date = DateTime.MaxValue;
                            popup.Dispatcher.Invoke((Action)(() =>
                            {
                                date = popup.onDate.SelectedDate.GetValueOrDefault(date);
                            }));

                            if (date != DateTime.MaxValue)
                            {
                                Revision onDateItem = GetLastRevision(item, date);
                                if (onDateItem != null)
                                {
                                    if (!ts.IsCancellationRequested)
                                    {
                                        counter++;

                                        pd.UpdateProgress(Convert.ToInt32(counter / (decimal)queryResults.Count * 100), string.Format(ResourceHelper.GetResourceString("REPORT_PROGRESS"), counter, queryResults.Count, onDateItem.WorkItem.Title), false);

                                        //TODO:Move to separate Method
                                        WriteReport(descriptionText, metaDataSelectedItems, bodySelectedItems, includeAttachments, onDateItem);
                                        //WriteReport(descriptionText, metaDataSelectedItems, bodySelectedItems, includeAttachments, item);
                                    }
                                }
                            }
                            else
                            {
                                if (!ts.IsCancellationRequested)
                                {
                                    counter++;

                                    pd.UpdateProgress(Convert.ToInt32(counter / (decimal)queryResults.Count * 100), string.Format(ResourceHelper.GetResourceString("REPORT_PROGRESS"), counter, queryResults.Count, item.Title), false);

                                    WriteReport(descriptionText, metaDataSelectedItems, bodySelectedItems, includeAttachments, item);
                                    // TODO:Move to separate Method
                                }
                            }
                        }
                    }
                });
                pd.Create(string.Format("{0} {1}", project, ResourceHelper.GetResourceString("MSG_REPORT_TITLE")), Icons.Report);
            }
        }
Esempio n. 8
0
    static ErrorCode Main_Internal(string[] args)
    {
        try
        {
            if ((args.Length == 0) ||
                Parser.IsOption(args[0], _helpOptions) ||
                _helpActions.ContainsIgnoreCase(args[0]))
            {   // Print help
                PrintUsage();
                return((int)ErrorCode.Success);
            }

            if ((args.Length == 1) && args[0].StartsWith("@"))
            {
                args = System.IO.File.ReadLines(args[0].Substring(1)).ToArray();
            }

            // Parse first 'action' argument
            string        actionArg = args[0];
            ActionCommand action    = 0;
            {
                bool isValidActionArg = false;
                foreach (ActionCommand actionCommand in Enum.GetValues(typeof(ActionCommand)))
                {
                    if (actionArg.Equals(actionCommand.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        action           = actionCommand;
                        isValidActionArg = true;
                        break;
                    }
                }
                if (!isValidActionArg)
                {
                    ReportError($"Error: unrecognized action '{actionArg}' - command line argument #1");
                    return(ErrorCode.InvalidCommand);
                }
            }

            Parser optionsParser = new Parser(
                args.Skip(1).ToArray(),
                PrintUsage);

            switch (action)
            {
            case ActionCommand.cache:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _prefixOption },
                        new Option[] { _authenticationTokenOption, _commentsPrefixOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                string filePrefix = _prefixOption.GetValue(optionsParser);
                // Optional args
                string authenticationToken = _authenticationTokenOption.GetValue(optionsParser);
                string commentsFilePrefix  = _commentsPrefixOption.GetValue(optionsParser);

                return(CacheGitHubIssues(configFiles, filePrefix, commentsFilePrefix, authenticationToken));
            }

            case ActionCommand.cacheRange:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _prefixOption, _startIndexOption, _endIndexOption },
                        new Option[] { _authenticationTokenOption, _commentsPrefixOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                string filePrefix = _prefixOption.GetValue(optionsParser);
                int    startIndex = Int32.Parse(_startIndexOption.GetValue(optionsParser));
                int    endIndex   = Int32.Parse(_endIndexOption.GetValue(optionsParser));
                // Optional args
                string authenticationToken = _authenticationTokenOption.GetValue(optionsParser);

                if (startIndex <= 0)
                {
                    optionsParser.ReportError($"Option /startIndex has to be positive number.");
                    return(ErrorCode.InvalidCommand);
                }
                if (endIndex < startIndex)
                {
                    optionsParser.ReportError($"Option /endIndex has to larger than /startIndex.");
                    return(ErrorCode.InvalidCommand);
                }

                return(CacheGitHubIssuesRange(
                           configFiles,
                           filePrefix,
                           startIndex,
                           endIndex,
                           authenticationToken));
            }

            case ActionCommand.query:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _endOption, _outputOption },
                        new Option[] { _beginOption, _outputJsonOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> beginFiles  = _beginOption.GetValues(optionsParser);
                IEnumerable <string> endFiles    = _endOption.GetValues(optionsParser);
                string outputJsonFile            = _outputJsonOption.GetValue(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                Config      config = new Config(configFiles);
                QueryReport report = new QueryReport(config, beginFiles, endFiles);
                report.Write(outputFile, outputJsonFile);
                return(ErrorCode.Success);
            }

            case ActionCommand.report:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _endOption },
                        new Option[] { _beginOption, _middleOption, _outputOption, _outputCsvOption, _nameOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> beginFiles  = _beginOption.GetValues(optionsParser);
                IEnumerable <string> middleFiles = _middleOption.GetValues(optionsParser);
                IEnumerable <string> endFiles    = _endOption.GetValues(optionsParser);

                string outputFile        = _outputOption.GetValue(optionsParser);
                string csvFileNamePrefix = _outputCsvOption.GetValue(optionsParser);
                string reportName        = _nameOption.GetValue(optionsParser);

                if ((outputFile == null) && (csvFileNamePrefix == null))
                {
                    optionsParser.ReportError("Required at least one option: '/out' or '/out_csv'.");
                    return(ErrorCode.InvalidCommand);
                }
                if ((csvFileNamePrefix != null) &&
                    csvFileNamePrefix.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
                {
                    optionsParser.ReportError($"Option '/out_csv' takes file name prefix, not file name {csvFileNamePrefix}.");
                    return(ErrorCode.InvalidCommand);
                }

                TableReport report = new TableReport(configFiles, beginFiles, middleFiles, endFiles);
                if (outputFile != null)
                {
                    HtmlTableReport.Write(report, outputFile, reportName);
                }
                // Note we can have both options
                if (csvFileNamePrefix != null)
                {
                    CsvTableReport.Write(report, csvFileNamePrefix, reportName);
                }
                return(ErrorCode.Success);
            }

            case ActionCommand.contributions:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _inputOption },
                        new Option[] { _outputOption, _outputCsvOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> inputFiles  = _inputOption.GetValues(optionsParser);

                string outputFileHtml = _outputOption.GetValue(optionsParser);
                string outputFileCsv  = _outputCsvOption.GetValue(optionsParser);

                if ((outputFileHtml == null) && (outputFileCsv == null))
                {
                    optionsParser.ReportError("Required at least one option: '/out' or '/out_csv'.");
                    return(ErrorCode.InvalidCommand);
                }

                ContributionsReport report = new ContributionsReport(configFiles, inputFiles);
                if (outputFileHtml != null)
                {
                    HtmlContributionsReport.Write(report, outputFileHtml);
                }
                // Note we can have both options
                if (outputFileCsv != null)
                {
                    //CsvContributionsReport.Write(report, outputFileCsv);
                }
                return(ErrorCode.Success);
            }

            case ActionCommand.alerts:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _beginOption, _endOption, _templateOption },
                        new Option[] { _filterOption, _skipEmailOption, _outputOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> beginFiles  = _beginOption.GetValues(optionsParser);
                IEnumerable <string> endFiles    = _endOption.GetValues(optionsParser);
                string templateFile = _templateOption.GetValue(optionsParser);
                // Optional args
                IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser);
                bool   skipEmail  = _skipEmailOption.IsDefined(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                Config config = new Config(configFiles);
                IEnumerable <DataModelIssue> beginIssues = IssueCollection.LoadIssues(
                    beginFiles,
                    config,
                    IssueKindFlags.Issue | IssueKindFlags.PullRequest)
                                                           .DistinctFirst_ByIssueNumber()
                                                           .ToArray();
                IEnumerable <DataModelIssue> endIssues = IssueCollection.LoadIssues(
                    endFiles,
                    config,
                    IssueKindFlags.Issue | IssueKindFlags.PullRequest)
                                                         .DistinctLast_ByIssueNumber()
                                                         .ToArray();

                if (AlertReport_Diff.DetectLargeChanges(beginIssues, endIssues, config))
                {
                    return(ErrorCode.EmailSendFailure);
                }

                return(GetSendEmailErrorCode(AlertReport_Diff.SendEmails(
                                                 config,
                                                 templateFile,
                                                 skipEmail,
                                                 outputFile,
                                                 alertFilters,
                                                 beginIssues,
                                                 endIssues)));
            }

            case ActionCommand.history:
            {
                if (!optionsParser.Parse(
                        new Option[] { _inputOption, _outputOption },
                        Option.EmptyList))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> inputFiles = _inputOption.GetValues(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                HistoryReport.Create(inputFiles, outputFile);
                return(ErrorCode.Success);
            }

            case ActionCommand.untriaged:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _inputOption, _templateOption },
                        new Option[] { _filterOption, _skipEmailOption, _outputOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> inputFiles  = _inputOption.GetValues(optionsParser);
                string templateFile = _templateOption.GetValue(optionsParser);
                // Optional args
                IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser);
                bool   skipEmail  = _skipEmailOption.IsDefined(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                Config config = new Config(configFiles);

                return(GetSendEmailErrorCode(AlertReport_Untriaged.SendEmails(
                                                 config,
                                                 templateFile,
                                                 skipEmail,
                                                 outputFile,
                                                 alertFilters,
                                                 inputFiles)));
            }

            case ActionCommand.needsResponse:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _inputOption, _commentsOption, _templateOption },
                        new Option[] { _filterOption, _skipEmailOption, _outputOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles   = _configOption.GetValues(optionsParser);
                IEnumerable <string> inputFiles    = _inputOption.GetValues(optionsParser);
                IEnumerable <string> commentsFiles = _commentsOption.GetValues(optionsParser);
                string templateFile = _templateOption.GetValue(optionsParser);
                // Optional args
                IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser);
                bool   skipEmail  = _skipEmailOption.IsDefined(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                Config config = new Config(configFiles);
                IEnumerable <DataModelIssue> issues = IssueCollection.LoadIssues(
                    inputFiles,
                    config,
                    IssueKindFlags.Issue);
                IEnumerable <DataModelIssue> comments = IssueCollection.LoadIssues(
                    commentsFiles,
                    config,
                    IssueKindFlags.Comment);

                return(GetSendEmailErrorCode(AlertReport_NeedsResponse.SendEmails(
                                                 config,
                                                 templateFile,
                                                 skipEmail,
                                                 outputFile,
                                                 alertFilters,
                                                 issues,
                                                 comments)));
            }

            default:
                Debug.Assert(false);
                return(ErrorCode.CatastrophicFailure);
            }
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine();
            Console.Error.WriteLine();
            Console.Error.WriteLine();
            Console.Error.WriteLine("Catastrophic failure:");
            Console.Error.WriteLine(ex);
            return(ErrorCode.CatastrophicFailure);
        }
    }