/// <summary>
        /// Formats the search result.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <returns>
        /// The <see cref="ISearchResult"/>.
        /// </returns>
        public ISearchResult FormatResult(SearchCommandResult result)
        {
            if (result == null)
                throw new ArgumentNullException("result");

            var formattedResult = new PublicSearchResult
                                      {
                                          ProcessDisplayName = result.ProcessDisplayName,
                                          TotalRowCount = result.TotalRowCount,
                                          CurrentPage = result.PageNumber,
                                          FilterParametersRequired = result.FilterParametersRequired,
                                      };

            if (result.Items != null)
            {
                formattedResult.Items = result.Items.Select(item => GetFieldValues(item, result.ResultColumns.Select(c => c.SystemName))).ToArray();
            }

            formattedResult.Filters = result.Filters;
            formattedResult.Layouts = result.Layouts;
            formattedResult.RelatedProcesses = result.RelatedProcesses;
            formattedResult.AppliedFilter = result.AppliedFilter;
            formattedResult.AppliedLayout = result.AppliedLayout;
            formattedResult.Metrics = result.Metrics;
            formattedResult.KpiGadget = result.KpiGadget;
            formattedResult.KpiGadgetData = result.KpiGadgetData;

            return formattedResult;
        }
        public void FormatResult_Returns_InternalSearchResult()
        {
            // Arrange.
            const string ProcessDisplayName = "Test Process";
            const int TotalRowCount = 123;
            const int PageNumber = 3;

            var items = new InfoList<IInfoClass>
                            {
                                new InfoItem { Field1 = "Value 1.1", Field2 = "Value 1.2", Field3 = "Value 1.3" },
                                new InfoItem { Field1 = "Value 2.1", Field2 = "Value 2.2", Field3 = "Value 2.3" }
                            };
            items.TotalRowCount = TotalRowCount;
            items.PageNumber = PageNumber;

            var filters = new List<Filter> { new Filter(), new Filter() };
            var layouts = new List<LayoutMetadata> { new LayoutMetadata(), new LayoutMetadata() };
            var relatedProcesses = new List<ProcessMetadata> { new ProcessMetadata(), new ProcessMetadata() };
            var appliedFilter = new Filter();
            var appliedLayout = new LayoutMetadata();

            var searchResult = new SearchCommandResult
                                   {
                                       ProcessDisplayName = ProcessDisplayName,
                                       AppliedFilter = appliedFilter,
                                       FilterParametersRequired = false,
                                       AppliedLayout = appliedLayout,
                                       Items = items,
                                       ResultColumns = { CreateColumnMetadata("Field1"), CreateColumnMetadata("Field3") },
                                       Filters = filters,
                                       Layouts = layouts,
                                       RelatedProcesses = relatedProcesses
                                   };

            var formatter = new InternalSearchResultFormatter(_colorTranslator);

            // Act.
            var result = formatter.FormatResult(searchResult);

            // Assert.
            Assert.IsNotNull(result);
            Assert.AreEqual(ProcessDisplayName, result.ProcessDisplayName);
            Assert.AreSame(appliedFilter, result.AppliedFilter);
            Assert.IsFalse(result.FilterParametersRequired);
            Assert.AreSame(appliedLayout, result.AppliedLayout);
            Assert.AreEqual(PageNumber, result.CurrentPage);
            Assert.AreEqual(TotalRowCount, result.TotalRowCount);
            Assert.IsTrue(result.Filters.SequenceEqual(filters));
            Assert.IsTrue(result.Layouts.SequenceEqual(layouts));
            Assert.IsTrue(result.RelatedProcesses.SequenceEqual(relatedProcesses));

            Assert.IsNotNull(result.Items);
            Assert.AreEqual(2, result.Items.Count);
            Assert.IsTrue(result.Items[0].Values.SequenceEqual(new[] { "Value 1.1", "Value 1.3" }));
            Assert.IsTrue(result.Items[1].Values.SequenceEqual(new[] { "Value 2.1", "Value 2.3" }));
        }
        public void WhenItemsIsNull_FormatResult_ReturnsValidResult()
        {
            // Arrange.
            const string ProcessDisplayName = "Test Process";

            var filters = new List<Filter> { new Filter(), new Filter() };
            var layouts = new List<LayoutMetadata> { new LayoutMetadata(), new LayoutMetadata() };
            var relatedProcesses = new List<ProcessMetadata> { new ProcessMetadata(), new ProcessMetadata() };
            var appliedFilter = new Filter();
            var appliedLayout = new LayoutMetadata();

            var searchResult = new SearchCommandResult
                                   {
                                       ProcessDisplayName = ProcessDisplayName,
                                       AppliedFilter = appliedFilter,
                                       FilterParametersRequired = true,
                                       AppliedLayout = appliedLayout,
                                       Items = null,
                                       ResultColumns = { CreateColumnMetadata("Field1"), CreateColumnMetadata("Field3") },
                                       Filters = filters,
                                       Layouts = layouts,
                                       RelatedProcesses = relatedProcesses
                                   };

            var formatter = new PublicSearchResultFormatter();

            // Act.
            var result = formatter.FormatResult(searchResult) as PublicSearchResult;

            // Assert.
            Assert.IsNotNull(result);
            Assert.AreEqual(ProcessDisplayName, result.ProcessDisplayName);
            Assert.AreSame(appliedFilter, result.AppliedFilter);
            Assert.IsTrue(result.FilterParametersRequired);
            Assert.AreSame(appliedLayout, result.AppliedLayout);
            Assert.AreEqual(-1, result.CurrentPage);
            Assert.AreEqual(0, result.TotalRowCount);
            Assert.IsTrue(result.Filters.SequenceEqual(filters));
            Assert.IsTrue(result.Layouts.SequenceEqual(layouts));
            Assert.IsTrue(result.RelatedProcesses.SequenceEqual(relatedProcesses));
            Assert.IsNull(result.Items);
        }
        public void FormatResult_CanFormat_ApprovalColumns()
        {
            // Arrange.
            var item1 = new InfoItem();
            var item2 = new InfoItem { Approval = ApprovalStates.ReadyForApproval.ToString() };
            var searchResult = new SearchCommandResult
                                   {
                                       Items = new InfoList<IInfoClass> { item1, item2 },
                                       ResultColumns = { CreateColumnMetadata("Approval", ColumnTypes.Approval) }
                                   };

            var formatter = CreateFormatter();

            // Act.
            var result = formatter.FormatResult(searchResult);

            // Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Items);
            Assert.AreEqual(2, result.Items.Count);
            Assert.IsTrue(result.Items[0].Values.SequenceEqual(new object[] { ApprovalStates.NotReadyForApproval.GetDisplayName() }));
            Assert.IsTrue(result.Items[1].Values.SequenceEqual(new object[] { ApprovalStates.ReadyForApproval.GetDisplayName() }));
        }
        public void FormatResult_CanFormat_BackcolorColumns()
        {
            // Arrange.
            var item1 = new InfoItem { Field1_BC = 0 };
            var item2 = new InfoItem { Field1_BC = 0xFF123456 };
            var searchResult = new SearchCommandResult
                                   {
                                       Items = new InfoList<IInfoClass> { item1, item2 },
                                       ResultColumns = { CreateColumnMetadata("Field1_BC", ColumnTypes.FieldBackcolor) }
                                   };

            var formatter = CreateFormatter();

            // Act.
            var result = formatter.FormatResult(searchResult);

            // Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Items);
            Assert.AreEqual(2, result.Items.Count);
            Assert.IsTrue(result.Items[0].Values.SequenceEqual(new object[] { null }));
            Assert.IsTrue(result.Items[1].Values.SequenceEqual(new object[] { "#123456" }));
        }
        public void FormattedResult_Includes_BlockedColumns()
        {
            // Arrange.
            var item = new InfoItem { Field1 = "Value 1", Field2 = "Value 2", Field3 = "Value 3", BlockedFields = { "Field2" } };
            var searchResult = new SearchCommandResult
                                   {
                                       Items = new InfoList<IInfoClass> { item },
                                       ResultColumns =
                                           {
                                               CreateColumnMetadata("Field1"),
                                               CreateColumnMetadata("Field2"),
                                               CreateColumnMetadata("Field3")
                                           }
                                   };

            var formatter = new InternalSearchResultFormatter(_colorTranslator);

            // Act.
            var result = formatter.FormatResult(searchResult);

            // Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Items);
            Assert.AreEqual(1, result.Items.Count);
            Assert.IsTrue(result.Items[0].BlockedColumns.SequenceEqual(new[] { 1 }));
        }
        public void GetProcesses_Returns_FormattedResult()
        {
            // Arrange.
            const int PageNumber = 2;
            const int PageSize = 20;
            const string SearchText = "Search text";

            var searchResult = new SearchCommandResult();

            var searchCommand = Mock.Create<ISearchCommand>(Behavior.Loose);
            Mock.Arrange(() => searchCommand.FilterParameters).Returns(new Collection<object>());
            Mock.Arrange(() => searchCommand.SortDescriptors).Returns(new Collection<ISortDescriptor>());
            Mock.Arrange(() => searchCommand.ExecuteAsync()).Returns(Task.FromResult(searchResult));
            Mock.Arrange(() => _searchCommandFactory.CreateSearchCommand(ProcessName)).Returns(searchCommand);

            var formattedResult = Mock.Create<ISearchResult>(Behavior.Loose);
            Mock.Arrange(() => _searchResultFormatter.FormatResult(searchResult)).Returns(formattedResult);

            var controller = CreateProcessController();
            var searchParameters = new SearchParameters(ProcessName)
                                       {
                                           IncludeProcessMetadata = true,
                                           IncludeLayoutMetadata = true,
                                           PageNumber = PageNumber,
                                           PageSize = PageSize,
                                           SearchText = SearchText,
                                           LayoutId = LayoutId,
                                           FilterId = FilterId,
                                           ApplyDefaultFilter = false,
                                           FilterParameters = { "abc" },
                                           SortDescriptors = { new SortDescriptor("Date", SortDirection.Descending) },
                                           ApplyLayoutSortDescriptors = false
                                       };

            // Act.
            var result = controller.GetProcesses(searchParameters).Result as OkNegotiatedContentResult<ISearchResult>;

            // Assert.
            Assert.IsNotNull(result);
            Assert.AreSame(formattedResult, result.Content);

            Assert.IsTrue(searchCommand.IncludeProcessMetadata);
            Assert.IsTrue(searchCommand.IncludeLayoutMetadata);
            Assert.AreEqual(PageNumber, searchCommand.PageNumber);
            Assert.AreEqual(PageSize, searchCommand.PageSize);
            Assert.AreEqual(SearchText, searchCommand.SearchText);
            Assert.AreEqual(LayoutId, searchCommand.LayoutId);

            Assert.AreEqual(FilterId, searchCommand.FilterId);
            Assert.IsFalse(searchCommand.ApplyDefaultFilter);
            Assert.AreEqual(1, searchCommand.FilterParameters.Count);
            Assert.AreEqual("abc", searchCommand.FilterParameters[0]);

            Assert.AreEqual(1, searchCommand.SortDescriptors.Count);
            Assert.AreEqual("Date", searchCommand.SortDescriptors[0].ColumnName);
            Assert.AreEqual(SortDirection.Descending, searchCommand.SortDescriptors[0].Direction);
            Assert.IsFalse(searchCommand.ApplyLayoutSortDescriptors);
        }
示例#8
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>
        /// The <see cref="ISearchResult"/>.
        /// </returns>
        public SearchCommandResult Execute()
        {
            var result = new SearchCommandResult();

            if (IncludeProcessMetadata)
            {
                result.ProcessDisplayName = Process.DisplayName;
                result.Filters = GetFilters();
                result.Layouts = !IncludeMetricsMetadata ? GetLayouts() : null;
                result.RelatedProcesses = GetRelatedProcesses();
            }

            var appliedFilter = GetAppliedFilter();
            if (appliedFilter != null && IncludeLayoutMetadata)
            {
                result.AppliedFilter = appliedFilter;
            }

            var layout = GetAppliedLayout(appliedFilter);
            var layoutMetadata = SearchUtils.CreateLayoutMetadata(layout, true);

            if (IncludeLayoutMetadata)
            {
                result.AppliedLayout = layoutMetadata;
            }

            result.ResultColumns.AddRange(layoutMetadata.Columns);

            var filterDescriptors = new FilterList();
            if (appliedFilter != null && !appliedFilter.IsEmpty())
            {
                var filterDescriptor = FilterDescriptorFactory.CreateFilterFromJSON(appliedFilter.FilterDefinition);

                if (filterDescriptor.ReplaceUdpValues(FilterParameters))
                {
                    filterDescriptors.Add(filterDescriptor);
                }
                else
                {
                    result.FilterParametersRequired = true;
                    return result;
                }
            }

            filterDescriptors.AddRange(GetMandatoryFilters());

            foreach (var filterDescriptor in filterDescriptors)
            {
                filterDescriptor.ReplacePredefinedValues(null);
            }

            if (IncludeMetricsMetadata)
            {
                result.Metrics = MetricsManager.GetMetrics(ProcessName);
            }

            if (MetricParameters != null)
            {
                result.MetricsData = MetricsManager.GetMetricData(ProcessName, MetricParameters, FilterDescriptorFactory.GetFilterDefinition(filterDescriptors));
                return result;
            }

            if (IncludeKpiMetadata)
            {
                result.KpiGadget = KpiManager.GetKpiGaugeList(ProcessName);
            }

            if (KpiParameters != null && KpiParameters.Any())
            {
                result.KpiGadgetData = KpiManager.GetKpiGadgetData(ProcessName, KpiParameters);
                return result;
            }

            if (FilterId == -1)
            {
                foreach(JObject filt in FilterParameters)
                {
                    var filter = filt.ToObject<KeyValuePair<string, string>>();

                    var filterByKey = new FilterDescriptor(filter.Key, FilterOperator.IsEqualTo, filter.Value);
                    filterByKey.MemberType = layoutMetadata.Columns.FirstOrDefault(x => x.SystemName == filter.Key).ColumnType.GetCSharpType();
                    filterDescriptors.Add(filterByKey);
                }
            }

            var criteria = new PagedCriteria
                               {
                                   ProcessName = ProcessName,
                                   PageNumber = PageNumber,
                                   PageSize = PageSize,
                                   Filter = SearchText,
                                   GroupColumn = GroupColumn,
                                   FilterDefinition = FilterDescriptorFactory.GetFilterDefinition(filterDescriptors),
                                   LimitResultColumns = true,
                                   ResultColumns = new MobileList<string>(layoutMetadata.Columns.Select(c => c.SystemName)),
                                   SortColumns = GetSortDescriptors(layoutMetadata),
                                   NotCalculateAccessDeniedList = true
                               };

            result.Items = DynamicTypeManager.GetInfoList<IInfoClass>(criteria);

            return result;
        }
 /// <summary>
 /// Formats the search result.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 /// <returns>
 /// The <see cref="ISearchResult"/>.
 /// </returns>
 ISearchResult ISearchResultFormatter.FormatResult(SearchCommandResult result)
 {
     return FormatResult(result);
 }