public override FilterList GetFilterFields(Type cardType, FullTextSearchResultModel searchModel)
        {
            if (cardType == null || typeof(IEmailMessageFullTextSearchObject) != cardType)
            {
                return(new FilterList());
            }
            var filterList = new FilterList();
            var emailMessageFullTextSearchResultModel = searchModel as EmailMessageFullTextSearchResultModel;

            if (emailMessageFullTextSearchResultModel != null && emailMessageFullTextSearchResultModel.TypeUid != Guid.Empty)
            {
                var classMetadata = MetadataLoader.LoadMetadata(emailMessageFullTextSearchResultModel.TypeUid) as ClassMetadata;
                if (classMetadata != null)
                {
                    var list = (from c in MetadataLoader.GetChildClasses(classMetadata)
                                where c != null
                                select c).ToList();
                    list.Add(classMetadata);
                    var list2 = new List <object>();
                    list2.AddRange(from c in list
                                   select c.Uid.ToString("n"));
                    filterList.Add(new FilterListItem(LinqUtils.NameOf((IEmailMessageFullTextSearchObject d) => d.TypeUid), list2, FilterListItemType.Must, FullTextFieldType.String));
                }
            }

            var emailMessageFullTextSearchResultModel2 = searchModel as EmailMessageFullTextSearchResultModel;

            if (emailMessageFullTextSearchResultModel2?.Contractor != null)
            {
                var contractorId = emailMessageFullTextSearchResultModel2.Contractor.Id;
                filterList.Add(new FilterListItem(LinqUtils.NameOf((IEmailMessageFullTextSearchObject d) => d.Contractors), new List <object>()
                {
                    contractorId
                }, FilterListItemType.Must, FullTextFieldType.Long));
            }
            if (emailMessageFullTextSearchResultModel2?.Contact != null)
            {
                var contactId = emailMessageFullTextSearchResultModel2.Contact.Id;
                filterList.Add(new FilterListItem(LinqUtils.NameOf((IEmailMessageFullTextSearchObject d) => d.Contacts), new List <object>()
                {
                    contactId
                }, FilterListItemType.Must, FullTextFieldType.Long));
            }

            filterList.Add(new FilterListItem(LinqUtils.NameOf((IEmailMessageFullTextSearchObject d) => d.IsDeleted), new List <object>
            {
                "false"
            }, FilterListItemType.Must, FullTextFieldType.String));

            return(filterList);
        }
Example #2
0
 public void LoadFilterData()
 {
     foreach (string filter in Properties.Settings.Default.Filters)
     {
         FilterList.Add(new FilterData(filter));
     }
 }
Example #3
0
        public async Task ApplyRotationFilterAsync(double value)
        {
            RotationFilterModel f = new RotationFilterModel(value);

            IsChanged = true;
            FilterList.Add(f);
            foreach (var item in f.Components)
            {
                _filters.Add(item);
            }

            int h = Math.Max(OriginalBitmap.PixelHeight, OriginalBitmap.PixelWidth);
            int w = Math.Min(OriginalBitmap.PixelHeight, OriginalBitmap.PixelWidth);

            OriginalBitmap = new WriteableBitmap(w, h);

            using (FilterEffect effect = new FilterEffect(ImageSource)
            {
                Filters = _filters
            })
                using (WriteableBitmapRenderer renderer = new WriteableBitmapRenderer(effect, OriginalBitmap))
                {
                    await renderer.RenderAsync();

                    OriginalBitmap.Invalidate();
                }
        }
Example #4
0
        public void AddFilterListItem(string value, DialogClosingEventArgs arg)
        {
            if (!(bool)arg.Parameter || string.IsNullOrEmpty(value) || FilterList.Contains(value))
            {
                return;
            }

            FilterList.Add(value);
        }
Example #5
0
 public void AddFilterModel(FilterModel f)
 {
     IsChanged = true;
     FilterList.Add(f);
     foreach (var item in f.Components)
     {
         _filters.Add(item);
     }
 }
Example #6
0
        /// <summary>
        /// Creates a new filter list from an existing one.
        /// </summary>
        /// <remarks>If the filter is not found in the addin host or
        /// the type hasn't changed, the old filter is copied by reference to the new
        /// filter list. Otherwise, a new instance of the new type is initialized and
        /// added to the new filter list</remarks>
        /// <param name="fl">Current filter list</param>
        /// <param name="h">List of available addins</param>
        /// <returns>The new filter list</returns>
        public FilterList Update(FilterList fl, AddinHost h)
        {
            FilterList fl_new = new FilterList();
              foreach (IFilter f in fl) {
            Type t = f.GetType();
            Type addin = h.FindAddins(
              typeof(IFilter),
              (ai) => { return ai.IsDefaultConstructible() && ai.FullName == t.FullName; }).FirstOrDefault();

            if (addin == null || t == addin) {
              // Just move filter over
              fl_new.Add(f);
            } else {
              // Create a new instance
              fl_new.Add(h.CreateInstance(addin) as IFilter);
            }
              }

              return fl_new;
        }
Example #7
0
        public async Task ApplyFilterModelAsync(FilterModel f)
        {
            IsChanged = true;
            FilterList.Add(f);
            foreach (var item in f.Components)
            {
                _filters.Add(item);
            }

            await ApplyOriginalAsync();
        }
Example #8
0
        public void AddFilter(FilterType fType)
        {
            #region Conditions to collection
            if (lstFilter.SelectedValue != null && ((FilterClass)lstFilter.SelectedValue).ConditionType == FilterType.Collection)
            {
                switch (fType)
                {
                case FilterType.Name:
                case FilterType.Host:
                case FilterType.Description:
                case FilterType.OperatingSystem:
                case FilterType.Folder:
                case FilterType.Protocol:
                case FilterType.Credential:
                case FilterType.Public:
                case FilterType.Port:
                case FilterType.ProtocolSetting:
                case FilterType.Connection:
                case FilterType.Collection:
                    var newFilter = new FilterClass(fType);
                    ((FilterClass)lstFilter.SelectedValue).SubConditions.Add(newFilter);
                    break;
                }
            }
            #endregion
            #region Conditions to root
            else
            {
                switch (fType)
                {
                case FilterType.Name:
                case FilterType.Host:
                case FilterType.Description:
                case FilterType.OperatingSystem:
                case FilterType.Folder:
                case FilterType.Protocol:
                case FilterType.Credential:
                case FilterType.Public:
                case FilterType.Port:
                case FilterType.ProtocolSetting:
                case FilterType.Connection:
                case FilterType.Collection:
                    var newFilter = new FilterClass(fType);
                    FilterList.Add(newFilter);
                    break;
                }
            }

            RaisePropertyChanged("FilterList");
            lstFilter.SelectedIndex = lstFilter.Items.Count - 1;

            #endregion
        }
        private void TestSerialization()
        {
            var rule = new Filter()
            {
                Enabled = true, CanAbortProcessing = false, Label = "Test"
            };

            rule.Actions.Add(new OutlookFilters.Actions.MoveAction()
            {
                DestinationFolder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
            });
            rule.Conditions.Conditions.Add(new OutlookFilters.Conditions.TextMatch()
            {
                SearchText = "Text", MatchMethod = Conditions.TextMatch.TextMatchType.Exact, FieldType = Conditions.TextMatch.TextFieldType.Subject
            });

            _Filters.Add(rule);

            SaveFilters("C:\\filterlist.xml");
            LoadFilters("C:\\filterlist.xml");
        }
        public SpecificationForm()
        {
            InitializeComponent();
              try
              {
            current = Program.StartForm.current;
            if (current == null)
            {
              Functions.CloseApplication();
              return;
            }
            FM = new FlexCellManager(Book);
            FM.InitBook(1, 1, "Tahoma", 8, true);

            StatusSplash.Create(MainStatusStrip);
            StatusSplash.Message("Настройка источника данных...");
            current.Parameters.Add("ConnectionString", 0, "User id=qmmoscow;password=qmmoscow;Data Source=msk-lims-01.corp.tnk-bp.ru;SID=limsmsk;Direct=true;Max Pool Size=30;Connection Lifetime=1200");
            DataConnection.ConnectionString = current.Parameters["ConnectionString"].StringValue;
            DataConnection.Open();

            // фильтры
            StatusSplash.Message("Обновление фильтров...");
            FL = new FilterList(current);
            FL.Add(PlantsCheck, null);
            FL.Add(PlantsCombo, UpdatePlants);
            FL.Add(UNCCheck, null);
            FL.Add(UNCCombo, UpdateUNCProducts);
            FL.Add(ProductsCheck, null);
            FL.Add(ProductsCombo, UpdateProducts);
            FL.Start();

            IntegralCheck_CheckedChanged(this, new EventArgs());
              }
              finally
              {
            StatusSplash.Close();
              }
        }
        public CertTankForm()
        {
            InitializeComponent();
              StatusSplash.Create(MainStatusStrip);
              StatusSplash.Message("�����������...");
              current = Program.StartForm.current;
              if (current == null)
              {
            Functions.CloseApplication();
            return;
              }

              StatusSplash.Message("��������� ��������� ������...");
              current.Parameters.Add("ConnectionString", 0, "User id=qmmoscow;password=qmmoscow;Data Source=msk-lims-01.corp.tnk-bp.ru;SID=limsmsk;Direct=true;Max Pool Size=30;Connection Lifetime=1200");
              DataConnection.ConnectionString = current.Parameters["ConnectionString"].StringValue;
              DataConnection.Open();

              StatusSplash.Message("������...");
              // ������� FlexCell
              FM = new FlexCellManager(Book);
              FM.InitBook(1, 1, "Arial", 8, true);
              FM.EnableCalculateStatistical(StatusLabel);

              // ������������� ����
              Date1.Value = Functions.FirstDateInMonth(DateTime.Now.AddDays(-3));
              Date1.MaxDate = DateTime.Now;
              Date2.Value = Functions.LastDateInMonth(DateTime.Now.AddDays(-3));
              Date2.MaxDate = Date2.Value;

              this.WindowState = FormWindowState.Maximized;

              StatusSplash.Message("��������� ������ �����������...");
              UpdatePlants(); // ��������� ������ ������ �������

              StatusSplash.Message("���������� �������� ������...");
              // ��������� �������� ��������, ������� ������ �� ������� �������� � ��� ��������� �� ���������� �
              // �����������, �� ��������� �������� "�������" ��������
              FL = new FilterList(current);
              FL.Add(new Filter(null, Date1, null));
              FL.Add(new Filter(null, Date2, null));
              FL.Add(PlantCombo, UpdateCertTankPlants);
              FL.Add(ControlTypeCombo, UpdateCertTankControlTypes);
              FL.Add(ProductCombo, UpdateCertTankProducts);
              FL.Start();

              StatusSplash.Close();
        }
 public virtual Differences VisitFilterList(FilterList list1, FilterList list2,
   out FilterList changes, out FilterList deletions, out FilterList insertions){
   changes = list1 == null ? null : list1.Clone();
   deletions = list1 == null ? null : list1.Clone();
   insertions = list1 == null ? new FilterList() : list1.Clone();
   //^ assert insertions != null;
   Differences differences = new Differences();
   for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){
     //^ assert list2 != null;
     Filter nd2 = list2[j];
     if (nd2 == null) continue;
     insertions.Add(null);
   }
   TrivialHashtable savedDifferencesMapFor = this.differencesMapFor;
   this.differencesMapFor = null;
   TrivialHashtable matchedNodes = new TrivialHashtable();
   for (int i = 0, k = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Filter nd1 = list1[i]; 
     if (nd1 == null) continue;
     Differences diff;
     int j;
     Filter nd2 = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out diff, out j);
     if (nd2 == null || diff == null){Debug.Assert(nd2 == null && diff == null); continue;}
     matchedNodes[nd1.UniqueKey] = nd1;
     matchedNodes[nd2.UniqueKey] = nd2;
     changes[i] = diff.Changes as Filter;
     deletions[i] = diff.Deletions as Filter;
     insertions[i] = diff.Insertions as Filter;
     insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
     Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]);
     differences.NumberOfDifferences += diff.NumberOfDifferences;
     differences.NumberOfSimilarities += diff.NumberOfSimilarities;
   }
   //Find deletions
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Filter nd1 = list1[i]; 
     if (nd1 == null) continue;
     if (matchedNodes[nd1.UniqueKey] != null) continue;
     changes[i] = null;
     deletions[i] = nd1;
     insertions[i] = null;
     differences.NumberOfDifferences += 1;
   }
   //Find insertions
   for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){
     //^ assert list2 != null;
     Filter nd2 = list2[j]; 
     if (nd2 == null) continue;
     if (matchedNodes[nd2.UniqueKey] != null) continue;
     insertions[n+j] = nd2;  //Records nd2 as an insertion into list1, along with its position in list2
     differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here?
   }
   if (differences.NumberOfDifferences == 0){
     changes = null;
     deletions = null;
     insertions = null;
   }
   this.differencesMapFor = savedDifferencesMapFor;
   return differences;
 }
Example #13
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;
        }
        private void ExecuteUnlink(IEditableRoot source, IEditableRoot destination)
        {
            var crList = (ICrossRefItemList)destination.GetValueByPropertyName(Property.Name);
            if (crList == null)
            {
                throw new InvalidOperationException("Destination field is null.");
            }

            var filterList = new FilterList();
            if (crList.Count > 0)
            {
                // Include only items that are linked to MCR.
                filterList.Add(CreateLinkedItemsFilter(FilterOperator.In, crList.Cast<ICrossRefItemInfo>().Select(x => x.Id)));
            }

            if (!string.IsNullOrEmpty(SourceDataFilterDefinition))
            {
                filterList.Add(CreateSourceDataFilter(source));
            }

            foreach (var infoItem in GetSourceItems(filterList))
            {
                var ancestor = infoItem.GetAncestorByProcessName(ReferencedProcessName);
                if (ancestor == null)
                    continue;

                crList.Remove(ancestor.Id);
            }
        }
        /// <summary>
        /// Links items to destination field.
        /// </summary>
        /// <param name="source">
        /// The source item.
        /// </param>
        /// <param name="destination">
        /// The destination item.
        /// </param>
        private void ExecuteLink(IEditableRoot source, IEditableRoot destination)
        {
            var crList = (ICrossRefItemList)destination.GetValueByPropertyName(Property.Name);
            if (crList == null)
            {
                throw new InvalidOperationException("Destination field is null.");
            }

            var filterList = new FilterList();
            if (crList.Count > 0)
            {
                // Exclude items that are already linked.
                filterList.Add(CreateLinkedItemsFilter(FilterOperator.NotIn, crList.Cast<ICrossRefItemInfo>().Select(x => x.Id)));
            }

            if (!string.IsNullOrEmpty(SourceDataFilterDefinition))
            {
                filterList.Add(CreateSourceDataFilter(source));
            }

            foreach (var infoItem in GetSourceItems(filterList))
            {
                var ancestor = infoItem.GetAncestorByProcessName(ReferencedProcessName);
                if (ancestor == null || crList.Contains(ancestor.Id))
                    continue;

                crList.Assign(ancestor.Id);

                if (FieldUpdaters.Count == 0)
                    continue;

                var criteria = new DetailCriteria(infoItem.Id) { AllowLazyLoading = true };
                var editItem = DynamicTypeManager.GetEditableRoot<IEditableRoot>(SourceDataProcessName, criteria);
                if (editItem == null || editItem.Id <= 0)
                    continue;

                var sourceData = new DataTriggerSourceData();
                sourceData.SourceItems[DataTriggerFieldMappingExpressionNames.SourceDataProcess] = editItem;

                UpdateFieldValues(sourceData, editItem);

                ((ISavable)editItem).Save();
            }
        }
Example #16
0
 public Filter <T> Add(Expression <Func <T, bool> > filter)
 {
     FilterList.Add(filter);
     return(this);
 }
Example #17
0
        /// <summary>
        /// Schedules the items.
        /// </summary>
        /// <param name="scheduleEdit">The schedule edit.</param>
        /// <param name="finalState">The final state.</param>
        public void ScheduleItems(ISupportScheduling scheduleEdit, Guid finalState)
        {
            using (new BypassPropertyCheckContext())
            {
                if (scheduleEdit == null)
                {
                    return;
                }

                if (scheduleEdit.ProcessingScheduling)
                {
                    return;
                }

                if (!scheduleEdit.ScheduleBasedOnDate.HasValue && !scheduleEdit.ScheduleDisplayDate.HasValue)
                {
                    return;
                }

                if (scheduleEdit.IsScheduleDateChangedForOnlyItem)
                {
                    return;
                }

                var fp = TheDynamicTypeManager.GetEditableRoot<IFrequencyPattern>(Constants.FrequencyPatternProcessName, scheduleEdit.SchedulingFrequencyPatternId);
                if (fp == null)
                {
                    return;
                }

                var supportStateEdit = scheduleEdit as ISupportStates;
                if (supportStateEdit == null)
                {
                    return;
                }

                var isFinalState = finalState == supportStateEdit.CurrentStateGuid;
                if (!isFinalState && !scheduleEdit.IsNew)
                {
                    return;
                }

                if (scheduleEdit.SchedulingEndOption == SchedulingEndOption.EndAfterOccurrences.ToString())
                {
                    if (scheduleEdit.SchedulingEndAfterOccurrencesIndex >= scheduleEdit.SchedulingEndAfterOccurrences)
                    {
                        return;
                    }

                    scheduleEdit.SchedulingEndAfterOccurrencesIndex++;
                }

                DateTime dateOfScheduleEdit = scheduleEdit.ScheduleBasedOnDate ?? scheduleEdit.ScheduleDisplayDate.Value;

                ICalendar calendar = null;
                var userCalendar = scheduleEdit.GetCalendar();

                var tmpCalendar = userCalendar as ICalendar;
                if (tmpCalendar != null)
                {
                    calendar = tmpCalendar;
                }

                if (userCalendar is int)
                {
                    calendar = TheDynamicTypeManager.GetEditableRoot<ICalendar>(Constants.CalendarProcessName, (int)userCalendar);
                }

                if (userCalendar == null)
                {
                    var calendars = TheDynamicTypeManager.GetInfoList<IInfoClass>(Constants.CalendarProcessName, pageSize: 1);
                    if (calendars.Count > 0)
                    {
                        calendar = TheDynamicTypeManager.GetEditableRoot<ICalendar>(Constants.CalendarProcessName, calendars[0].Id);
                    }
                }

                var filter = new FilterList
                                 {
                                     new FilterDescriptor(
                                         LogicalOperators.And,
                                         new MobileObservableCollection<IFilterDescriptor>
                                             {
                                                 new FilterDescriptor(
                                                     Constants.SchedulingSeriesGuid,
                                                     FilterOperator.IsEqualTo,
                                                     scheduleEdit.SchedulingSeriesGuid,
                                                     typeof(string)),
//ELMTDEV-2250
//                                                 new FilterDescriptor(
//                                                     Constants.SchedulingSeriesItemNumber,
//                                                     FilterOperator.IsGreaterThan,
//                                                     scheduleEdit.SchedulingSeriesItemNumber,
//                                                     typeof(int)),
                                                 new FilterDescriptor(
                                                     Constants.IdColumnName,
                                                     FilterOperator.IsNotEqualTo,
                                                     scheduleEdit.Id,
                                                     typeof(int)),
                                                 new FilterDescriptor(
                                                     Constants.CurrentStateIdColumnName,
                                                     FilterOperator.IsNotEqualTo,
                                                     scheduleEdit.ScheduleStartStateId,
                                                     typeof(int))
                                             })
                                 };

                if (!string.IsNullOrEmpty(scheduleEdit.ScheduleFilter))
                {
                    var scheduleFilterList = FilterDescriptor.GetFilterList(scheduleEdit.ScheduleFilter);
                    if (scheduleFilterList != null)
                    {
                        foreach (var filterDescriptor in scheduleFilterList)
                            filter.Add(filterDescriptor);
                    }
                }

                var sortList = new SortList { new SortDescriptor(Constants.SchedulingSeriesItemNumber, SortDirection.Ascending) };

                var infoList = TheDynamicTypeManager.GetInfoList<IInfoClass>(
                    scheduleEdit.ProcessName,
                    pageSize: 100,
                    filterDescriptors: filter,
                    sortDescriptors: sortList);

                var lenght = isFinalState ? scheduleEdit.ScheduledItemsCount : scheduleEdit.ScheduledItemsCount - 1;

                _scheduledList.Clear();
                _scheduledList.Add(dateOfScheduleEdit.Date);
                _previousScheduleDate = dateOfScheduleEdit.Date;
                for (var i = 0; i < lenght; i++)
                {
                    CalculateAndSave(ref dateOfScheduleEdit, infoList.ElementAtOrDefault(i), scheduleEdit, fp, calendar);
                }
             }
        }
        private int? GetValue(DataTriggerSourceData sourceData, IEditableRoot destination)
        {
            if (ValueCalculator != null)
                return SafeTypeConverter.Convert<int?>(ValueCalculator(sourceData, destination));

            var filterList = new FilterList();

            foreach (var childMapping in ChildMappings.Where(m => m.IsKey))
            {
                IFilterDescriptor filter;

                if (!childMapping.TryCreateFilter(sourceData, destination, out filter))
                    return null;

                filterList.Add(filter);
            }

            if (filterList.Count != 0)
            {
                var crItems = DynamicTypeManager.GetList<IInfoList>(ReferencedProcessName, string.Empty, 0, int.MaxValue, null, filterList);
                return crItems != null && crItems.Count > 0 ? (int?)crItems[0].Id : null;
            }

            return null;
        }
Example #19
0
        public async Task<IHttpActionResult> Search(string process, int page, string searchText = null, int? layout = 0, int? userFilter = 0, string udpFilterOptions = null)
        {
            try
            {
                var listType = DynamicTypeManager.GetListType(process);
                if (listType == null || listType.BaseType == null)
                {
                    Exception exception = new Exception("Process " + process + " not found.");
                    Logger.Log(LogSeverity.Error, this.GetType().ToString(), exception);

                    return InternalServerError(exception);
                }

                var itemType = listType.BaseType.GetGenericArguments()[1];

                int pageSize = 20;
                FilterList filters = new FilterList();
                //int? layout = 0;

                var userLayoutFilter = GetLayoutFilter(process);
                var filterList = new FilterList { userLayoutFilter };
                IList<GridColumn> columns = this.GetLayoutColumns(filterList, layout);

                for (int index = columns.Count - 1; index >= 0; index--)
                {
                    var c = columns[index];
                    var prop = GetProperty(c.SystemName, itemType);
                    if (prop == null) // property not found - normal probably has been removed from the base class.
                    {
                        columns.RemoveAt(index);
                        continue;
                    }
                    c.Index = index;

                    var display = (from d in prop.GetCustomAttributes(typeof(DisplayAttribute), false) select d).FirstOrDefault() as DisplayAttribute;
                    c.Header = (display == null) ? c.Header : display.GetName();
                }

                var sortList = new SortList(columns.Where(c => c.SortLevel != null).Select(c => new SortDescriptor(c.SystemName, c.SortDirection)).ToList());
                string filter = null;

                if (userFilter != null && userFilter > 0)
                {
                    FilterDescriptor procFilter = GetFilterFilter(process);
                    FilterList localFilterList = new FilterList { procFilter };
                    IFilterList<IFilterInfo> ll = this.DynamicTypeManager.GetList<IFilterList<IFilterInfo>>(Constants.FilterProcessName, filter, 0, int.MaxValue, null, localFilterList);

                    if (ll != null)
                    {
                        var filterResult = ll.FirstOrDefault(x => x.Id == userFilter);

                        if (filterResult != null)
                        {
                            //filterName += " - " + filterResult.Name;

                            IFilterDescriptor filterDescriptor = FilterDescriptor.FromJSON(filterResult.FilterDefinition);
                            ICollection<IFilterDescriptor> udpFilters = filterDescriptor.GetAllUdpDescriptors();

                            if (udpFilters != null && udpFilters.Count != 0)
                            {
                                string[] tempUdp = JsonConvert.DeserializeObject<string[]>(udpFilterOptions);

                                IList<string> udpUserOptionsList = udpFilterOptions == null ? new List<string>() : tempUdp.ToList();

                                int i = 0;
                                foreach (var filterValue in udpFilters.Select(udpFilter => udpFilter.Value as FilterValue))
                                {
                                    if (filterValue != null)
                                    {
                                        if (filterValue.SystemName == "CurrentStateGuid")
                                        {
                                            if (udpUserOptionsList.Count > i)
                                            {
                                                if (udpUserOptionsList[i] == "null")
                                                {
                                                    filterValue.ProvidedValue = null;
                                                }
                                                else
                                                {
                                                    var editObject = this.DynamicTypeManager.GetEditableRoot<IEditableRoot>(Constants.StateProcessName, SafeTypeConverter.Convert<int>(udpUserOptionsList[i]));
                                                    filterValue.ProvidedValue = editObject.GetPropertyByName("Guid").GetValue(editObject);
                                                }
                                            }
                                            else
                                            {
                                                filterValue.ProvidedValue = filterValue.DefaultValue;
                                            }
                                        }
                                        else
                                        {
                                            filterValue.ProvidedValue = udpUserOptionsList.Count > i ? (udpUserOptionsList[i] == "null" ? null : udpUserOptionsList[i]) : filterValue.DefaultValue;
                                        }
                                    }
                                    i++;
                                }
                            }

                            filters.Add(filterDescriptor);
                            //filters = new FilterList { filterDescriptor };
                        }
                    }
                }

                AddMandatoryFilter(filters, process);

                // TODO: AS: switch to async (when available)
                IInfoList itemsList = this.DynamicTypeManager.GetList<IInfoList>(process, searchText, page, pageSize, sortList, filters);
                if (itemsList == null)
                {
                    SearchResult res = new SearchResult(0, 0);
                    return await Task.FromResult<IHttpActionResult>(Ok(res));
                }

                int totalRowsCount = (int)itemsList.GetType().GetProperty("TotalRowCount").GetValue(itemsList);
                int pageNumber = (int)itemsList.GetType().GetProperty("PageNumber").GetValue(itemsList);

                SearchResult result = new SearchResult(pageNumber, totalRowsCount);
                result.ProcessDisplayName = itemType.GetCustomAttribute<ProcessInfoAttribute>().DisplayName;

                // prepare columns metadata
                int columnIndex = 0;
                foreach (GridColumn gridColumn in columns)
                {
                    ColumnMetadata columnMeta = new ColumnMetadata(gridColumn);
                    columnMeta.Position = columnIndex++;

                    PropertyInfo property = itemType.GetPropertyByName(columnMeta.SystemName);
                    if (property != null)
                    {
                        columnMeta.ColumnType = property.GetFieldType().ToString();
                    }

                    result.Metadata.Columns.Add(columnMeta);

                    // add hidden URL column for File field
                    if (columnMeta.ColumnType == ColumnTypes.File.ToString())
                    {
                        result.Metadata.Columns.Add(new ColumnMetadata { Header = columnMeta.Header + " Url", SystemName = columnMeta.SystemName + Constants.Url, Position = columnIndex++ });
                    }
                }

                // add id column if it is not in Layout columns (we need it at least for referencing items).
                var idColumn = result.Metadata.Columns.FirstOrDefault(c => c.SystemName == Constants.IdColumnName);
                if (idColumn == null)
                {
                    result.Metadata.Columns.Add(new ColumnMetadata { Header = "Id", SystemName = Constants.IdColumnName, Position = columnIndex++ });
                }

                foreach (IInfoClass infoClass in itemsList)
                {
                    Dictionary<string, string> blockedColumns = ((string)infoClass.GetType().GetProperty("AccessDeniedProperties").GetValue(infoClass)).Split('|').ToDictionary(k => k);

                    SearchItem newItem = new SearchItem();
                    newItem.BlockedColumns = result.Metadata.Columns.Where(mc => blockedColumns.Keys.Any(k => mc.SystemName == k)).Select(mc => mc.Position).ToArray();
                    newItem.Values = new string[result.Metadata.Columns.Count];
                    newItem.Id = infoClass.Id;
                    result.Items.Add(newItem);

                    var properties = infoClass.GetAllPropertiesForInstance();

                    for (int colIndex = 0; colIndex < result.Metadata.Columns.Count; colIndex++)
                    {
                        var prop = itemType.GetPropertyByFullName(result.Metadata.Columns[colIndex].SystemName);
                        if (prop == null)
                        {
                            continue;
                        }

                        if (blockedColumns.ContainsKey(prop.Name))
                        {
                            continue;
                        }

                        var itemInfo = properties[prop];

                        var value = prop.GetValue(itemInfo);

                        var colType = result.Metadata.Columns[colIndex].ColumnType;

                        newItem.Values[colIndex] = FieldValueExtractor.GetPropertyStringValue(prop, value, colType);
                    }
                }

                var editableRootType = DynamicTypeManager.GetEditableRootType(process);
                result.CanAdd = BusinessRules.HasPermission(AuthorizationActions.CreateObject, editableRootType);

                return await Task.FromResult<IHttpActionResult>(this.Ok(result));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #20
0
 private void AddFilterItem()
 {
     FilterList.Add(new FilterItem("Blue", "Blue", "#4287f5"));
 }