Example #1
0
        public MainViewModel(IDataService dataService)
        {
            InitializeCommands();

            MainWindowTitle = "EventLook" + (ProcessHelper.IsElevated ? " (Administrator)" : "");
            DataService     = dataService;
            Events          = new ObservableCollection <EventItem>();

            logSourceMgr      = new LogSourceMgr();
            SelectedLogSource = LogSources.FirstOrDefault();

            rangeMgr      = new RangeMgr();
            SelectedRange = Ranges.FirstOrDefault(r => r.DaysFromNow == 3);

            sourceFilter = new Model.SourceFilter();
            levelFilter  = new LevelFilter();
            MsgFilter    = new MessageFilter();
            IdFilter     = new IdFilter();

            filters = new List <FilterBase> {
                sourceFilter, levelFilter, MsgFilter, IdFilter
            };

            progress  = new Progress <ProgressInfo>(ProgressCallback); // Needs to instantiate in UI thread
            stopwatch = new Stopwatch();

            Messenger.Default.Register <ViewCollectionViewSourceMessageToken>(this, Handle_ViewCollectionViewSourceMessageToken);
            Messenger.Default.Register <FileToBeProcessedMessageToken>(this, Handle_FileToBeProcessedMessageToken);
            Messenger.Default.Register <DetailWindowMessageToken>(this, Handle_DetailWindowMessageToken);
        }
Example #2
0
        public void IdFilter_ConstructWithSingleId()
        {
            var filter = new IdFilter(dummyFixture.Id);

            Assert.False(filter.IsEmpty);
            Assert.That(filter.Match(dummyFixture));
            Assert.False(filter.Match(anotherFixture));
        }
Example #3
0
        private static TestFilter FromXml(TNode node)
        {
            switch (node.Name)
            {
            case "filter":
            case "and":
                var andFilter = new AndFilter();
                foreach (var childNode in node.ChildNodes)
                {
                    andFilter.Add(FromXml(childNode));
                }
                return(andFilter);

            case "or":
                var orFilter = new OrFilter();
                foreach (var childNode in node.ChildNodes)
                {
                    orFilter.Add(FromXml(childNode));
                }
                return(orFilter);

            case "not":
                return(new NotFilter(FromXml(node.FirstChild)));

            case "id":
                var idFilter = new IdFilter();
                if (node.Value != null)
                {
                    foreach (string id in node.Value.Split(COMMA))
                    {
                        idFilter.Add(id);
                    }
                }
                return(idFilter);

            case "tests":
                var testFilter = new SimpleNameFilter();
                foreach (var childNode in node.SelectNodes("test"))
                {
                    testFilter.Add(childNode.Value);
                }
                return(testFilter);

            case "cat":
                var catFilter = new CategoryFilter();
                if (node.Value != null)
                {
                    foreach (string cat in node.Value.Split(COMMA))
                    {
                        catFilter.AddCategory(cat);
                    }
                }
                return(catFilter);

            default:
                throw new ArgumentException("Invalid filter element: " + node.Name, "xmlNode");
            }
        }
Example #4
0
        public void IdFilter_ConstructWithMultipleIds()
        {
            var filter = new IdFilter(new string[] { dummyFixture.Id, anotherFixture.Id });

            Assert.False(filter.IsEmpty);
            Assert.That(filter.Match(dummyFixture));
            Assert.That(filter.Match(anotherFixture));
            Assert.False(filter.Match(yetAnotherFixture));
        }
Example #5
0
        public void TopLevelIdMatch()
        {
            IdFilter filter = CreateIdFilter(_suite);

            Assert.IsTrue(filter.Pass(_mock1), "Filter did not pass MockTest1");
            Assert.IsTrue(filter.Pass(_mock2), "Filter did not pass MockTest2");
            Assert.IsTrue(filter.Pass(_mock3), "Filter did not pass MockTest3");
            Assert.IsFalse(filter.Pass(_explicitTest), "Filter should not have passed ExplicitlyRunTest");
            Assert.IsTrue(filter.Pass(_fixture), "Filter did not pass MockTestFixture");
            Assert.IsTrue(filter.Pass(_suite), "Filter did not pass TopLevelSuite");
        }
Example #6
0
        public async Task <List <Item> > ListItem(ItemFilter ItemFilter, IdFilter OrderCategoryId, IdFilter OrderId)
        {
            if (OrderCategoryId == null || OrderCategoryId.Equal.HasValue == false)
            {
                return(new List <Item>());
            }
            if (OrderId.HasValue == false || OrderId.Equal.HasValue == false)
            {
                return(new List <Item>());
            }

            if (OrderCategoryId.Equal == OrderCategoryEnum.ORDER_CUSTOMER.Id)
            {
                var CustomerSalesOrder = await UOW.CustomerSalesOrderRepository.Get(OrderId.Equal.Value);

                if (CustomerSalesOrder == null || (CustomerSalesOrder.CustomerSalesOrderContents == null && CustomerSalesOrder.CustomerSalesOrderPromotions == null))
                {
                    return(new List <Item>());
                }
                var ItemIds = new List <long>();
                var Ids1    = CustomerSalesOrder.CustomerSalesOrderContents?.Select(x => x.ItemId).ToList();
                var Ids2    = CustomerSalesOrder.CustomerSalesOrderPromotions?.Select(x => x.ItemId).ToList();
                ItemIds.AddRange(Ids1);
                ItemIds.AddRange(Ids2);
                ItemIds = ItemIds.Distinct().ToList();

                ItemFilter.Id = new IdFilter {
                    In = ItemIds
                };
                return(await UOW.ItemRepository.List(ItemFilter));
            }
            if (OrderCategoryId.Equal == OrderCategoryEnum.ORDER_DIRECT.Id)
            {
                var DirectSalesOrder = await UOW.DirectSalesOrderRepository.Get(OrderId.Equal.Value);

                if (DirectSalesOrder == null || (DirectSalesOrder.DirectSalesOrderContents == null && DirectSalesOrder.DirectSalesOrderPromotions == null))
                {
                    return(new List <Item>());
                }
                var ItemIds = new List <long>();
                var Ids1    = DirectSalesOrder.DirectSalesOrderContents?.Select(x => x.ItemId).ToList();
                var Ids2    = DirectSalesOrder.DirectSalesOrderPromotions?.Select(x => x.ItemId).ToList();
                ItemIds.AddRange(Ids1);
                ItemIds.AddRange(Ids2);
                ItemIds = ItemIds.Distinct().ToList();

                ItemFilter.Id = new IdFilter {
                    In = ItemIds
                };
                return(await UOW.ItemRepository.List(ItemFilter));
            }
            return(new List <Item>());
        }
Example #7
0
        public void IdFilter_AddIds()
        {
            var filter = new IdFilter();

            filter.Add(dummyFixture.Id);
            filter.Add(anotherFixture.Id);

            Assert.False(filter.IsEmpty);
            Assert.That(filter.Match(dummyFixture));
            Assert.That(filter.Match(anotherFixture));
            Assert.False(filter.Match(yetAnotherFixture));
        }
Example #8
0
        private static TestFilter FromXml(XmlNode xmlNode)
        {
            switch (xmlNode.Name)
            {
            case "filter":
            case "and":
                var andFilter = new AndFilter();
                foreach (XmlNode childNode in xmlNode.ChildNodes)
                {
                    andFilter.Add(FromXml(childNode));
                }
                return(andFilter);

            case "or":
                var orFilter = new OrFilter();
                foreach (System.Xml.XmlNode childNode in xmlNode.ChildNodes)
                {
                    orFilter.Add(FromXml(childNode));
                }
                return(orFilter);

            case "not":
                return(new NotFilter(FromXml(xmlNode.FirstChild)));

            case "id":
                var idFilter = new IdFilter();
                foreach (string id in xmlNode.InnerText.Split(COMMA))
                {
                    idFilter.Add(int.Parse(id));
                }
                return(idFilter);

            case "tests":
                var testFilter = new SimpleNameFilter();
                foreach (XmlNode childNode in xmlNode.SelectNodes("test"))
                {
                    testFilter.Add(childNode.InnerText);
                }
                return(testFilter);

            case "cat":
                var catFilter = new CategoryFilter();
                foreach (string cat in xmlNode.InnerText.Split(COMMA))
                {
                    catFilter.AddCategory(cat);
                }
                return(catFilter);

            default:
                throw new ArgumentException("Invalid filter element: " + xmlNode.Name, "xmlNode");
            }
        }
Example #9
0
        protected List <long> FilterOrganization(List <Organization> Organizations, IdFilter IdFilter)
        {
            List <long> In    = null;
            List <long> NotIn = null;

            if (IdFilter.Equal != null)
            {
                if (In == null)
                {
                    In = new List <long>();
                }
                In.Add(IdFilter.Equal.Value);
            }
            if (IdFilter.In != null)
            {
                if (In == null)
                {
                    In = new List <long>();
                }
                In.AddRange(IdFilter.In);
            }

            if (IdFilter.NotEqual != null)
            {
                if (NotIn == null)
                {
                    NotIn = new List <long>();
                }
                NotIn.Add(IdFilter.NotEqual.Value);
            }
            if (IdFilter.NotIn != null)
            {
                if (NotIn == null)
                {
                    NotIn = new List <long>();
                }
                NotIn.AddRange(IdFilter.NotIn);
            }
            if (In != null)
            {
                List <string> InPaths = Organizations.Where(o => In.Count == 0 || In.Contains(o.Id)).Select(o => o.Path).ToList();
                Organizations = Organizations.Where(o => InPaths.Any(p => o.Path.StartsWith(p))).ToList();
            }
            if (NotIn != null)
            {
                List <string> NotInPaths = Organizations.Where(o => NotIn.Count == 0 || NotIn.Contains(o.Id)).Select(o => o.Path).ToList();
                Organizations = Organizations.Where(o => !NotInPaths.Any(p => o.Path.StartsWith(p))).ToList();
            }
            return(Organizations.Select(o => o.Id).ToList());
        }
Example #10
0
        public async Task <int> CountAppUser(AppUserFilter AppUserFilter, IdFilter KpiYearId, IdFilter KpiPeriodId)
        {
            try
            {
                KpiItemFilter KpiItemFilter = new KpiItemFilter
                {
                    Skip        = 0,
                    Take        = int.MaxValue,
                    KpiYearId   = KpiYearId,
                    KpiPeriodId = KpiPeriodId,
                    Selects     = KpiItemSelect.Id | KpiItemSelect.Employee
                };

                var KpiItems = await UOW.KpiItemRepository.List(KpiItemFilter);

                var AppUserIds = KpiItems.Select(x => x.EmployeeId).ToList();

                if (AppUserFilter.Id == null)
                {
                    AppUserFilter.Id = new IdFilter();
                }
                AppUserFilter.Id.NotIn = AppUserIds;

                var count = await UOW.AppUserRepository.Count(AppUserFilter);

                return(count);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(KpiItemService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(KpiItemService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
Example #11
0
        public async Task <List <AppUser> > ListAppUser(AppUserFilter AppUserFilter, IdFilter KpiYearId)
        {
            try
            {
                KpiGeneralFilter KpiGeneralFilter = new KpiGeneralFilter
                {
                    Skip      = 0,
                    Take      = int.MaxValue,
                    KpiYearId = KpiYearId,
                    Selects   = KpiGeneralSelect.Id | KpiGeneralSelect.Employee
                };

                var KpiGenerals = await UOW.KpiGeneralRepository.List(KpiGeneralFilter);

                var AppUserIds = KpiGenerals.Select(x => x.EmployeeId).ToList();
                if (AppUserFilter.Id == null)
                {
                    AppUserFilter.Id = new IdFilter();
                }
                AppUserFilter.Id.NotIn = AppUserIds;
                AppUserFilter.Selects  = AppUserSelect.Id | AppUserSelect.Username | AppUserSelect.DisplayName | AppUserSelect.Phone | AppUserSelect.Email;

                var AppUsers = await UOW.AppUserRepository.List(AppUserFilter);

                return(AppUsers);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(KpiGeneralService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(KpiGeneralService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="OrganizationId"></param>
        /// <param name="AppUserService"></param>
        /// <param name="OrganizationService"></param>
        /// <param name="CurrentContext"></param>
        /// <param name="DataContext"></param>
        /// <returns> AppUserIds, OrganizationIds </returns>
        protected async Task <(List <long>, List <long>)> FilterOrganizationAndUser(IdFilter OrganizationId, IAppUserService AppUserService, IOrganizationService OrganizationService, ICurrentContext CurrentContext, DataContext DataContext)
        {
            List <long> OrganizationIds = await FilterOrganization(OrganizationService, CurrentContext);

            List <OrganizationDAO> OrganizationDAOs = await DataContext.Organization.Where(o => o.DeletedAt == null && (OrganizationIds.Count == 0 || OrganizationIds.Contains(o.Id))).ToListAsync();

            OrganizationDAO OrganizationDAO = null;

            if (OrganizationId?.Equal != null)
            {
                OrganizationDAO = await DataContext.Organization.Where(o => o.Id == OrganizationId.Equal.Value).FirstOrDefaultAsync();

                OrganizationDAOs = OrganizationDAOs.Where(o => o.Path.StartsWith(OrganizationDAO.Path)).ToList();
            }
            OrganizationIds = OrganizationDAOs.Select(o => o.Id).ToList();
            List <long> AppUserIds = await FilterAppUser(AppUserService, OrganizationService, CurrentContext);

            return(AppUserIds, OrganizationIds);
        }
Example #13
0
        private void ApplyFilters()
        {
            var idFilter = IdFilter?.FirstOrDefault(x => x.IsEnabled);

            foreach (var item in ItemsSource)
            {
                item.IsVisible = true;
            }

            if (idFilter != null)
            {
                Filter(idFilter.Filter);
            }

            if (ShowMegaEvolution.Value is false)
            {
                Filter(x => !Filters.IsMegashinka(x));
            }
            if (ShowBanLegend.Value is false)
            {
                Filter(x => !Filters.IsBanLegend(x));
            }
            Messenger.Raise(new InteractionMessage("RaiseFilter"));
        }
Example #14
0
 public void ToStringTest(string id)
 {
     Filter<ITestDescriptor> filter = new IdFilter<ITestDescriptor>(new EqualityFilter<string>(id));
     Assert.AreEqual("Id(Equality('" + id + "'))", filter.ToString());
 }
Example #15
0
        protected async Task <List <long> > FilterAppUser(IAppUserService AppUserService, IOrganizationService OrganizationService, ICurrentContext CurrentContext)
        {
            List <long> organizationIds = await FilterOrganization(OrganizationService, CurrentContext);

            List <long> In            = null;
            List <long> NotIn         = null;
            IdFilter    CurrentUserId = new IdFilter();
            //foreach (var currentFilter in CurrentContext.Filters)
            //{
            //    List<FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
            //    foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
            //    {
            //        if (FilterPermissionDefinition.Name == "AppUserId")
            //        {
            //            if (FilterPermissionDefinition.IdFilter.Equal != null)
            //            {
            //                if (In == null) In = new List<long>();
            //                In.Add(FilterPermissionDefinition.IdFilter.Equal.Value);
            //            }
            //            if (FilterPermissionDefinition.IdFilter.In != null)
            //            {
            //                if (In == null) In = new List<long>();
            //                In.AddRange(FilterPermissionDefinition.IdFilter.In);
            //            }

            //            if (FilterPermissionDefinition.IdFilter.NotEqual != null)
            //            {
            //                if (NotIn == null) NotIn = new List<long>();
            //                NotIn.Add(FilterPermissionDefinition.IdFilter.NotEqual.Value);
            //            }
            //            if (FilterPermissionDefinition.IdFilter.NotIn != null)
            //            {
            //                if (NotIn == null) NotIn = new List<long>();
            //                NotIn.AddRange(FilterPermissionDefinition.IdFilter.NotIn);
            //            }
            //        }
            //        if (FilterPermissionDefinition.Name == nameof(CurrentContext.UserId) && FilterPermissionDefinition.IdFilter != null)
            //        {
            //            if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.IS.Id)
            //            {
            //                CurrentUserId.Equal = CurrentContext.UserId;
            //            }
            //            if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.ISNT.Id)
            //            {
            //                CurrentUserId.NotEqual = CurrentContext.UserId;
            //            }
            //        }
            //    }
            //}


            AppUserFilter AppUserFilter = new AppUserFilter
            {
                Id = new IdFilter {
                    In = In, NotIn = NotIn, Equal = CurrentUserId.Equal, NotEqual = CurrentUserId.NotEqual
                },
                OrganizationId = new IdFilter {
                    In = organizationIds
                },
                Skip      = 0,
                Take      = int.MaxValue,
                Selects   = AppUserSelect.Id,
                OrderBy   = AppUserOrder.DisplayName,
                OrderType = OrderType.ASC,
            };

            List <AppUser> AppUsers = await AppUserService.List(AppUserFilter);

            List <long> AppUserIds = AppUsers.Select(a => a.Id).ToList();

            return(AppUserIds);
        }
Example #16
0
        public void ToStringTest(string id)
        {
            Filter <ITestDescriptor> filter = new IdFilter <ITestDescriptor>(new EqualityFilter <string>(id));

            Assert.AreEqual("Id(Equality('" + id + "'))", filter.ToString());
        }
Example #17
0
        public async Task <DirectSalesOrderFilter> ToFilter(DirectSalesOrderFilter filter)
        {
            if (filter.OrFilter == null)
            {
                filter.OrFilter = new List <DirectSalesOrderFilter>();
            }
            if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
            {
                return(filter);
            }

            List <Organization> Organizations = await OrganizationService.List(new OrganizationFilter
            {
                Skip      = 0,
                Take      = int.MaxValue,
                Selects   = OrganizationSelect.ALL,
                OrderBy   = OrganizationOrder.Id,
                OrderType = OrderType.ASC
            });

            foreach (var currentFilter in CurrentContext.Filters)
            {
                DirectSalesOrderFilter subFilter = new DirectSalesOrderFilter();
                filter.OrFilter.Add(subFilter);
                List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
                foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
                {
                    if (FilterPermissionDefinition.Name == nameof(subFilter.AppUserId))
                    {
                        subFilter.AppUserId = FilterBuilder.Merge(subFilter.AppUserId, FilterPermissionDefinition.IdFilter);
                    }
                    if (FilterPermissionDefinition.Name == nameof(subFilter.OrganizationId))
                    {
                        var      organizationIds = FilterOrganization(Organizations, FilterPermissionDefinition.IdFilter);
                        IdFilter IdFilter        = new IdFilter {
                            In = organizationIds
                        };
                        subFilter.OrganizationId = FilterBuilder.Merge(subFilter.OrganizationId, IdFilter);
                    }
                    if (FilterPermissionDefinition.Name == nameof(CurrentContext.UserId) && FilterPermissionDefinition.IdFilter != null)
                    {
                        if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.IS.Id)
                        {
                            if (subFilter.UserId == null)
                            {
                                subFilter.UserId = new IdFilter {
                                }
                            }
                            ;
                            subFilter.UserId.Equal = CurrentContext.UserId;
                        }
                        if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.ISNT.Id)
                        {
                            if (subFilter.UserId == null)
                            {
                                subFilter.UserId = new IdFilter {
                                }
                            }
                            ;
                            subFilter.UserId.NotEqual = CurrentContext.UserId;
                        }
                    }
                }
            }
            return(filter);
        }
    }
}