Esempio n. 1
0
 public ItemMatcherTest()
 {
     var channelConfig = new ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(
         ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1, // This stinks somewhat. Not going with generics is probably the alternative?
         ltr => ltr.Id);
     _itemMatcherUnderTest = new ItemMatcher<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(channelConfig);
 }
        public void SetUpTest()
        {
            var type1Config = new TypeConfiguration<LocalTestResource, int>(
                ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1,
                -1);
            LocalEndpoint = new InMemoryCrudDataEndpoint<LocalTestResource, int>(type1Config, TestData.LocalResults);
            var endpoint1Config = new EndpointConfiguration<LocalTestResource, int>(
                type1Config,
                LocalEndpoint);

            var type2Config = new TypeConfiguration<RemoteTestResource, int>(rtr => rtr.Id, 0);
            RemoteEndpoint = new InMemoryCrudDataEndpoint<RemoteTestResource, int>(type2Config, TestData.RemoteResults);
            var endpoint2Config = new EndpointConfiguration<RemoteTestResource, int>(
                type2Config,
                RemoteEndpoint);

            // This clearly requires a configuration API.
            ChannelConfig = new ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(endpoint1Config, endpoint2Config, new TestResourceTranslator());
            var itemsPreprocessor = new ItemMatcher<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(ChannelConfig);

            ChannelConfig.ItemsPreprocessor = itemsPreprocessor.Match;

            var resolvers = new List<ISynchronizationResolver<ItemMatch<LocalTestResource, RemoteTestResource>>>
            {
                new SynchronizationResolver<ItemMatch<LocalTestResource,RemoteTestResource>, ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>>(
                ChannelConfig,
                (item, cfg) => item.Result1 == null,
                (item, cfg) =>
                {
                    var synchItem = item.Result1;
                    cfg.TypeTranslator.TranslateBackward(item.Result2, ref synchItem);

                    // Now the translate decides wether a new item has to be created, but the decision is there anyway because of the Create.
                    cfg.Type1EndpointConfiguration.Endpoint.Create(synchItem);
                    return new SynchronizationResult(true);
                })
            };
            Plumber = new ItemMatchPipelinePlumber<LocalTestResource, RemoteTestResource, int>(ChannelConfig, resolvers, itemsPreprocessor.Match);
            ConstructTestSubject();
        }
        public void SetUpTest()
        {
            var type1Config = new TypeConfiguration<LocalTestResource, int>(ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1);
            _localEndpoint = new InMemoryCrudDataEndpoint<LocalTestResource, int>(type1Config, TestData.LocalResults);
            var endpoint1Config = new EndpointConfiguration<LocalTestResource, int>(
                type1Config,
                _localEndpoint);

            var type2Config = new TypeConfiguration<RemoteTestResource, int>(rtr => rtr.Id);
            _remoteEndpoint = new InMemoryCrudDataEndpoint<RemoteTestResource, int>(type2Config, TestData.RemoteResults);
            var endpoint2Config = new EndpointConfiguration<RemoteTestResource, int>(
                type2Config,
                _remoteEndpoint);

            // This clearly requires a configuration API.
            var channelConfig = new ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(endpoint1Config, endpoint2Config, new TestResourceTranslator());
            var itemsPreprocessor = new ItemMatcher<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(channelConfig);
            channelConfig.ItemsPreprocessor = itemsPreprocessor.Match;
            channelConfig.AddSynchAction(new SynchronizationResolver<ItemMatch<LocalTestResource,RemoteTestResource>, ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>>(
                channelConfig,
                (item, cfg) =>
                {
                    return item.Result1 == null;
                },
                (item, cfg) =>
                {
                    var synchItem = item.Result1;
                    cfg.TypeTranslator.TranslateBackward(item.Result2, ref synchItem);
                    // Now the translate decides wether a new item has to be created, but the decision is there anyway because of the Create.
                    cfg.Type1EndpointConfiguration.Endpoint.Create(synchItem);
                    return new SynchronizationResult(true);
                }
            ));

            //var t2epConfig = new EndpointConfiguration()
            _channelUnderTest = new OneWayPullChannel<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(
                channelConfig,
                () => Task.FromResult(_localEndpoint.ReadAll().AsEnumerable()),
                () => Task.FromResult(_remoteEndpoint.ReadAll().AsEnumerable()));
        }
Esempio n. 4
0
 public ItemMatcherTest()
 {
     _itemMatcherUnderTest = new ItemMatcher<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(
         new TypeConfiguration<LocalTestResource, int>(ltr => ltr.CorrelationId ?? -1, -1)
         , new TypeConfiguration<RemoteTestResource, int>(ltr => ltr.Id, 0));
 }
Esempio n. 5
0
        /// <summary>
        /// 获取联动规则的数据,数据源来自 BizBus
        /// </summary>
        protected void GetLinkageData()
        {
            string targetId           = Request["TargetID"];
            string schemaCode         = Request["SchemaCode"];
            string filterMethod       = Request["FilterMethod"];
            string queryCode          = Request["QueryCode"];
            string queryPropertyName  = Request["QueryPropertyName"];
            string queryPropertyValue = Request["QueryPropertyValue"];
            string textDataField      = Request["TextDataField"];
            string valueDataField     = Request["ValueDataField"];

            // 获取查询对象
            //BizQuery query = OThinker.H3.WorkSheet.AppUtility.Engine.BizBus.GetBizQuery(schemaCode, queryCode);
            DataModel.BizQuery query = AppUtility.Engine.BizObjectManager.GetBizQuery(queryCode);
            // 构造查询条件
            OThinker.H3.BizBus.Filter.Filter filter = new BizBus.Filter.Filter();
            OThinker.H3.BizBus.Filter.And    and    = new And();
            filter.Matcher = and;
            ItemMatcher propertyMatcher = null;

            if (query.QueryItems != null)
            {
                string[] values = queryPropertyValue.Split(new string[] { "," }, StringSplitOptions.None);
                int      i      = 0;
                foreach (DataModel.BizQueryItem queryItem in query.QueryItems)
                { // 增加系统参数条件
                    if (queryItem.FilterType == DataModel.FilterType.SystemParam)
                    {
                        propertyMatcher = new OThinker.H3.BizBus.Filter.ItemMatcher(queryItem.PropertyName,
                                                                                    OThinker.Data.ComparisonOperatorType.Equal,
                                                                                    SheetUtility.GetSystemParamValue(UserValidatorFactory.CurrentUser, queryItem.SelectedValues));
                        and.Add(propertyMatcher);
                        continue;
                    }
                    else if (values.Length > 1)
                    {
                        if (values.Length > i)
                        {
                            propertyMatcher = new OThinker.H3.BizBus.Filter.ItemMatcher(queryItem.PropertyName,
                                                                                        queryItem.FilterType == DataModel.FilterType.Contains ? OThinker.Data.ComparisonOperatorType.Contain : OThinker.Data.ComparisonOperatorType.Equal,
                                                                                        values[i]);
                            and.Add(propertyMatcher);
                        }
                    }
                    else if (queryItem.PropertyName == queryPropertyName)
                    {
                        propertyMatcher = new OThinker.H3.BizBus.Filter.ItemMatcher(queryPropertyName,
                                                                                    queryItem.FilterType == DataModel.FilterType.Contains ? OThinker.Data.ComparisonOperatorType.Contain : OThinker.Data.ComparisonOperatorType.Equal,
                                                                                    queryPropertyValue);
                        and.Add(propertyMatcher);
                    }
                    i++;
                }
            }
            DataModel.BizObjectSchema   schema      = AppUtility.Engine.BizObjectManager.GetPublishedSchema(schemaCode);
            Dictionary <string, string> SelectItems = new Dictionary <string, string>();

            if (schema != null)
            {
                // 调用查询获取数据源
                //OThinker.H3.DataModel.BizObject[] objs = schema.GetList(OThinker.H3.WorkSheet.AppUtility.Engine.BizBus,
                //    this.UserValidator.UserID,
                //    filterMethod,
                //    filter);
                DataModel.BizObject[] objs = schema.GetList(
                    AppUtility.Engine.Organization,
                    AppUtility.Engine.MetadataRepository,
                    AppUtility.Engine.BizObjectManager,
                    UserValidatorFactory.CurrentUser != null ? UserValidatorFactory.CurrentUser.UserID : string.Empty,
                    filterMethod,
                    filter);

                DataTable dtSource = DataModel.BizObjectUtility.ToTable(schema, objs);
                foreach (DataRow row in dtSource.Rows)
                {
                    SelectItems.Add(row[valueDataField] + string.Empty, row[textDataField] + string.Empty);
                }
            }

            Response.Clear();
            Response.Write(JSSerializer.Serialize(SelectItems));
            Response.Buffer = true;
        }
Esempio n. 6
0
 public ItemMatcherTest()
 {
     _itemMatcherUnderTest = new ItemMatcher <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >(
         new TypeConfiguration <LocalTestResource, int>(ltr => ltr.CorrelationId ?? -1, -1)
         , new TypeConfiguration <RemoteTestResource, int>(ltr => ltr.Id, 0));
 }