コード例 #1
0
        public SourcesViewModel(ISourceManager sourceManager) : base("sources")
        {
            DisplayName = "Sources";

            Metadata = MappingCollection.Create(sourceManager.Metadata, source => new MetadataSourceViewModel(source));
            Content  = MappingCollection.Create(sourceManager.Content, source => new ContentSourceViewModel(source));
        }
コード例 #2
0
        public void ClassWithProtectedProperties_ProtectedAccessorsShouldNotBeAvailable()
        {
            // Arrange:
            // const string altogetherProtectedProperty = "ImAltogetherProtected"; // Not expected to be available either as a source or destination property.
            const string propertyWithProtectedGetter  = "MyGetterIsProtected";
            var          propertyWithProtectedSetter  = MemberExpressions.GetMemberInfo <ClassWithProtectedProperties>(c => c.MySetterIsProtected).Name;
            var          altogetherAccessibleProperty = MemberExpressions.GetMemberInfo <ClassWithProtectedProperties>(c => c.ImAltogetherAccessible).Name;

            var expectedSourcePropertyNames     = new[] { propertyWithProtectedSetter, altogetherAccessibleProperty };
            var expectedDestinationProperyNames = new[] { propertyWithProtectedGetter, altogetherAccessibleProperty };

            // Act:
            var mappingCollection                 = new MappingCollection <ClassWithProtectedProperties, ClassWithProtectedProperties, object>(null);
            var availableSourcePropertyNames      = mappingCollection.Unmapped.Source.Select(sourceMember => sourceMember.Name).ToArray();
            var availableDestinationPropertyNames = mappingCollection.Unmapped.Destination.Select(destMember => destMember.Name).ToArray();

            // Assert:
            Array.Sort(expectedSourcePropertyNames);
            Array.Sort(availableSourcePropertyNames);
            Assert.AreEqual(expectedSourcePropertyNames, availableSourcePropertyNames);

            Array.Sort(expectedDestinationProperyNames);
            Array.Sort(availableDestinationPropertyNames);
            Assert.AreEqual(expectedDestinationProperyNames, availableDestinationPropertyNames);
        }
コード例 #3
0
    public MappingCollection <T> GetRange(int index, int count)
    {
        if (index < 0)
        {
            ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
        }

        if (count < 0)
        {
            ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
        }

        if (_size - index < count)
        {
            ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
        }
        Contract.Ensures(Contract.Result <MappingCollection <T> >() != null);
        Contract.EndContractBlock();

        MappingCollection <T> list = new MappingCollection <T>(count);

        Array.Copy(_items, index, list._items, 0, count);
        list._size = count;
        return(list);
    }
コード例 #4
0
    public virtual MappingCollection <TOutput> ConvertAll <TOutput>(Converter <T, TOutput> converter)
    {
        if (converter == null)
        {
            ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter);
        }
        Contract.EndContractBlock();
        Type OutputType = GetType().GetGenericTypeDefinition().MakeGenericType(typeof(TOutput));
        MappingCollection <TOutput> output = (MappingCollection <TOutput>)Activator.CreateInstance(OutputType);

        if (output._items.Length < _size)
        {
            TOutput[] newItems = new TOutput[_size];
            if (output._items.Length > 0)
            {
                Array.Copy(output._items, newItems, output._items.Length);
            }
            output._items = newItems;
        }

        for (int i = 0; i < _size; i++)
        {
            output._items[i] = converter(_items[i]);
        }
        output._size = _size;
        return(output);
    }
コード例 #5
0
        public SearchResult <TEntityType> DoSearch <TEntityType>(
            IQueryable <TEntityType> query,
            FilterSet filter,
            MappingCollection <TEntityType> mappings
            ) where TEntityType : class
        {
            if (filter.PageNumber < 1)
            {
                filter.PageNumber = 1;
            }

            if (filter.HasFilters())
            {
                query = query.AsExpandable().Where(
                    SearchHelper.CreateSearchPredicate(filter, mappings)
                    );
            }

            query = ApplySort(query, filter, mappings);

            var resIdx = (filter.PageSize * filter.PageNumber) - filter.PageSize;

            return(new SearchResult <TEntityType>
            {
                TotalResults = query.Count(),
                Results = query.Skip(resIdx)
                          .Take(filter.PageSize)
                          .ToList()
            });
        }
コード例 #6
0
ファイル: AutoMapperImpl.cs プロジェクト: osafak/ErtisAuth
        /// <summary>
        /// Constructor
        /// </summary>
        public AutoMapperImpl(MappingCollection typeMap) : base(typeMap)
        {
            var profile             = new AutoMapperProfile(typeMap);
            var mapperConfiguration = new AutoMapper.MapperConfiguration(cfg => cfg.AddProfile(profile));

            this.Mapper = mapperConfiguration.CreateMapper();
        }
コード例 #7
0
 internal Enumerator(MappingCollection <T> list)
 {
     this.list = list;
     index     = 0;
     version   = list._version;
     current   = default(T);
 }
コード例 #8
0
        /// <summary>
        /// Searches the type and child types for a field that matches the given column name.
        /// </summary>
        /// <param name="type">The type to search.</param>
        /// <param name="columnName">The column to search for.</param>
        /// <param name="mappingCollection">The mapping collection containing the configuration for this context.</param>
        /// <returns>The name of the field or null if there is no match.</returns>
        internal static string SearchForMatchingField(Type type, string columnName, MappingCollection mappingCollection)
        {
            var queue = new Queue <Tuple <Type, string> >();

            queue.Enqueue(Tuple.Create(type, String.Empty));

            var searched = new HashSet <Type>();

            while (queue.Any())
            {
                var tuple  = queue.Dequeue();
                var t      = tuple.Item1;
                var prefix = tuple.Item2;
                searched.Add(t);

                var prop = GetMemberByColumnName(t, columnName);
                if (prop != null)
                {
                    return(prefix + prop.Name);
                }

                if (mappingCollection.CanBindChild(t))
                {
                    foreach (var p in ClassPropInfo.GetMembersForType(t).Where(m => !TypeHelper.IsAtomicType(m.MemberType)))
                    {
                        if (!searched.Contains(p.MemberType))
                        {
                            queue.Enqueue(Tuple.Create(p.MemberType, prefix + p.Name + MemberSeparator));
                        }
                    }
                }
            }

            return(null);
        }
コード例 #9
0
        public void Overlay_Root_To_Expression()
        {
            var collection = new MappingCollection <ResourceClassNested, DomainClassSimple, CloneableTestContext>(_mapper.Object);

            collection.Overlay(to => to, from => from.Child);
            Assert.AreEqual(1, collection.Setters.Count());
        }
コード例 #10
0
        public void Overlay_Expression_To_Expression()
        {
            var collection = new MappingCollection <MultiSrc, MultiNestedDest, CloneableTestContext>(_mapper.Object);

            collection.Overlay(to => to.Dest, from => from.Src1);

            Assert.AreEqual(new[] { "Dest", "Dest.Property1" }, ToDestinationStrings(collection.Setters));
        }
コード例 #11
0
        public void Overlay_Root_To_Expression_MultipleSources()
        {
            var collection = new MappingCollection <MultiSrc, MultiDest, CloneableTestContext>(_mapper.Object);

            collection.Overlay(to => to, from => from.Src1);
            collection.Overlay(to => to, from => from.Src2);

            Assert.AreEqual(new[] { "Property1", "Property2" }, ToDestinationStrings(collection.Setters));
        }
コード例 #12
0
ファイル: AutoMapperImpl.cs プロジェクト: osafak/ErtisAuth
 public AutoMapperProfile(MappingCollection typeMap)
 {
     foreach (var typePair in typeMap.Mappings)
     {
         var sourceType      = typePair.Key;
         var destinationType = typePair.Value;
         this.CreateMap(sourceType, destinationType);
     }
 }
コード例 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="typeMap"></param>
 public TinyMapperImpl(MappingCollection typeMap) : base(typeMap)
 {
     foreach (var typePair in typeMap.Mappings)
     {
         var sourceType      = typePair.Key;
         var destinationType = typePair.Value;
         TinyMapper.Bind(sourceType, destinationType);
     }
 }
コード例 #14
0
        public SearchResult <TEntityType> DoSearch <TEntityType>(
            IQueryable <TEntityType> query,
            FilterSet filter,
            List <IMapAFilter <TEntityType> > mappings
            ) where TEntityType : class
        {
            var mappingDef = new MappingCollection <TEntityType>(mappings);

            return(DoSearch(query, filter, mappingDef));
        }
コード例 #15
0
        private static Expression <Func <T, bool> > GetExpression <T>(
            MappingCollection <T> mappings,
            FilterGroup filterGroup
            ) where T : class
        {
            var predicate     = PredicateBuilder.New <T>(filterGroup.Operator == FilterOperator.And);
            var filterApplied = false;

            foreach (var filter in filterGroup.Filters.Where(f => !string.IsNullOrWhiteSpace(f.Value)))
            {
                var mapping = mappings.GetMapping(filter.Field);

                var expression = mapping.GetFilterLambda(filter.Value, filter.Action);

                if (expression == null)
                {
                    continue;
                }

                filterApplied = true;

                if (filterGroup.Operator == FilterOperator.And)
                {
                    predicate = predicate.And(expression);
                }
                else
                {
                    predicate = predicate.Or(expression);
                }
            }

            // if an or filter doesnt actually do any filtering, we return true.
            // this allows us to ignore empty predicates
            if (!filterApplied && filterGroup.Operator == FilterOperator.Or)
            {
                predicate = PredicateBuilder.New <T>(true);
            }

            if (filterGroup.FilterGroups != null)
            {
                foreach (var group in filterGroup.FilterGroups)
                {
                    if (filterGroup.Operator == FilterOperator.And)
                    {
                        predicate = predicate.And(GetExpression <T>(mappings, group));
                    }
                    else
                    {
                        predicate = predicate.Or(GetExpression <T>(mappings, group));
                    }
                }
            }

            return(predicate);
        }
コード例 #16
0
        public void OverrideChildContext_ValueType_ReturnsNewValue()
        {
            var collection = new MappingCollection <object, object, bool>(null);

            collection.SetChildContext((from, to, context) =>
            {
                Assert.IsTrue(context);
                return(false);
            });
            Assert.IsFalse(collection.ContextUpdater(null, null, true));
        }
コード例 #17
0
        public bool MoveNext()
        {
            MappingCollection <T> localList = list;

            if (version == localList._version && ((uint)index < (uint)localList._size))
            {
                current = localList._items[index];
                index++;
                return(true);
            }
            return(MoveNextRare());
        }
コード例 #18
0
 public void SetUp()
 {
     _builder = new Builder();
     _mapper  = new Mock <IResourceMapper <CloneableTestContext> >();
     _mapper.Setup(m => m.MemberConsumers).Returns(new PriorityList <IMemberConsumer> {
         new DefaultMemberConsumer()
     });
     _mapper.Setup(m => m.MemberResolvers).Returns(new PriorityList <IMemberResolver> {
         new IgnoreCaseNameMatcher()
     });
     _collection = new MappingCollection <ClassWithSeveralPropertiesSrcNullable, ClassWithSeveralPropertiesDest, CloneableTestContext>(_mapper.Object);
 }
コード例 #19
0
 private Type FindType(string url)
 {
     url = ResolveUrl(url);
     if (!string.IsNullOrEmpty(url))
     {
         Type result;
         MappingCollection mappings = this.Mappings;
         if (mappings.TryGetValue(url, out result))
         {
             return(result);
         }
     }
     return(null);
 }
コード例 #20
0
        public void SetItemTest()
        {
            PrivateObject param0 = CreateIniElement();
            MappingCollection_Accessor target = new MappingCollection_Accessor(param0); // TODO: Initialize to an appropriate value
            int     index = 0;
            Mapping item  = target.CreateMapping();

            item.Assembly = "or.dll";
            target.SetItem(index, item);

            MappingCollection tar = (MappingCollection)target.Target;

            Assert.AreEqual("or.dll", tar[index].Assembly);
        }
コード例 #21
0
        public void CreateMappingTest()
        {
            XNamespace name = "urn:nhibernate-configuration-2.2";
            XElement   sessionFactoryEelement =
                new XElement(name + "sessionFactory",
                             new XElement(name + "property", new XAttribute("name", "name"), new XText("values")),
                             new XElement(name + "mapping", new XAttribute("assembly", "name"), new XText("orname.core.dll"))
                             );

            MappingCollection target = new MappingCollection(sessionFactoryEelement);
            var actual = target.CreateMapping();

            Assert.AreEqual(name, actual.Element.Name.Namespace);
        }
コード例 #22
0
        public void ClearItemsTest()
        {
            PrivateObject param0 = CreateIniElement();
            MappingCollection_Accessor target = new MappingCollection_Accessor(param0);

            MappingCollection tar = (MappingCollection)target.Target;

            tar.Clear();

            IEnumerable <XElement> elements = from mappingNode in target.sessionFactoryEelement.Elements(xNamespace + "mapping")
                                              select mappingNode;

            XElement[] mappings = elements.ToArray <XElement>();
            Assert.AreEqual(0, mappings.Length);
            Assert.AreEqual(0, tar.Count);
        }
コード例 #23
0
 public void Initialize()
 {
     if (!Initialized)
     {
         var mappingCollection = new MappingCollection <TFrom, TTo, TContext>(_mapper);
         foreach (var @override in _override)
         {
             @override(mappingCollection);
         }
         _override.Clear();
         mappingCollection.DoAutomapping();
         mappingCollection.VerifyMap();
         _mapStatement = _mapper.Builder.BuildAction(mappingCollection);
         Initialized   = true;
     }
 }
コード例 #24
0
        private IQueryable <TEntityType> ApplySort <TEntityType>(
            IQueryable <TEntityType> query,
            FilterSet filter,
            MappingCollection <TEntityType> mappings
            ) where TEntityType : class
        {
            if (!string.IsNullOrWhiteSpace(filter.SortBy))
            {
                var mapping = mappings.GetMapping(filter.SortBy);

                return(mapping.ApplySort(query, filter.SortDir ?? mappings.DefaultSort.SortOrder));
            }

            var defaultSort = mappings.DefaultSort;

            return(defaultSort.Mapping.ApplySort(query, filter.SortDir ?? mappings.DefaultSort.SortOrder));
        }
コード例 #25
0
        public void RemoveItemTest()
        {
            PrivateObject param0 = CreateIniElement();
            MappingCollection_Accessor target = new MappingCollection_Accessor(param0); // TODO: Initialize to an appropriate value
            int index = 0;

            target.RemoveItem(index);


            IEnumerable <XElement> elements = from mappingNode in target.sessionFactoryEelement.Elements(xNamespace + "mapping")
                                              select mappingNode;

            XElement[] mappings = elements.ToArray <XElement>();
            Assert.AreEqual(0, mappings.Length);
            MappingCollection tar = (MappingCollection)target.Target;

            Assert.AreEqual(0, tar.Count);
        }
コード例 #26
0
        public virtual void Add(string url, Type type)
        {
            url = ResolveUrl(url);
            if (!string.IsNullOrEmpty(url) && type != null)
            {
                MappingCollection mappings = this.Mappings;

                if (mappings != null)
                {
                    Type newType = null;
                    mappings.TryGetValue(url, out newType);
                    if (newType != type)
                    {
                        lock (mappings)
                        {
                            mappings[url] = type;
                        }
                    }
                }
            }
        }
コード例 #27
0
        private IQueryable <TEntityType> ApplySort <TEntityType>(
            IQueryable <TEntityType> query,
            FilterSet filter,
            MappingCollection <TEntityType> mappings
            ) where TEntityType : class
        {
            var isDescending = filter.SortDir == "desc";
            var isAscending  = filter.SortDir == "asc";

            bool?selectedSort = isDescending ? true : (isAscending ? false : (bool?)null);

            if (!string.IsNullOrWhiteSpace(filter.SortBy))
            {
                var mapping = mappings.GetMapping(filter.SortBy);

                return(mapping.ApplySort(query, selectedSort ?? mappings.DefaultSort.Descending));
            }

            var defaultSort = mappings.DefaultSort;

            return(defaultSort.Mapping.ApplySort(query, selectedSort ?? mappings.DefaultSort.Descending));
        }
コード例 #28
0
        public void InsertItemTest_index0()
        {
            PrivateObject param0 = CreateIniElement();
            MappingCollection_Accessor target = new MappingCollection_Accessor(param0);

            //Insert 第一位
            int     index = 0;
            Mapping item  = target.CreateMapping();

            item.Assembly = "ol.dll";
            target.InsertItem(index, item);

            MappingCollection tar = (MappingCollection)target.Target;

            Assert.AreEqual <Int32>(2, tar.Count);


            Assert.AreEqual("ol.dll", tar[0].Assembly);


            //Insert 最后一位
            item          = target.CreateMapping();
            item.Assembly = "ol1.dll";
            index         = tar.Count;
            target.InsertItem(index, item);

            Assert.AreEqual("ol1.dll", tar[2].Assembly);

            //insert 中间位置
            index         = 1;
            item          = target.CreateMapping();
            item.Assembly = "middle.dll";
            target.InsertItem(index, item);

            Assert.AreEqual("middle.dll", tar[index].Assembly);
        }
コード例 #29
0
        private static void EnsureManagedProperties(SPSite site, IEnumerable <ManagedPropertyDefinition> definitions)
        {
            SearchServiceApplication searchApplication = GetSearchServiceApplication(site);

            if (searchApplication != null)
            {
                Schema schema = new Schema(searchApplication);
                IEnumerable <CrawledProperty> allCrawledProperties = schema.AllCategories["SharePoint"].GetAllCrawledProperties().OfType <CrawledProperty>();

                foreach (ManagedPropertyDefinition definition in definitions)
                {
                    int             variantType = VariantTypeDictionary[definition.DataType];
                    CrawledProperty rawProperty = allCrawledProperties.FirstOrDefault(v => v.Name == definition.CrawledPropertyName);
                    if (rawProperty == null || rawProperty.GetMappedManagedProperties().GetEnumerator().MoveNext())
                    {
                        continue;
                    }

                    ManagedProperty property;
                    try {
                        property = schema.AllManagedProperties[definition.MappedPropertyName];
                    } catch (KeyNotFoundException) {
                        property = schema.AllManagedProperties.Create(definition.MappedPropertyName, definition.DataType);
                    }
                    MappingCollection mappings = property.GetMappings();
                    Mapping           mapping  = new Mapping();
                    mapping.CrawledPropset      = rawProperty.Propset;
                    mapping.CrawledPropertyName = rawProperty.Name;
                    mapping.ManagedPid          = property.PID;
                    mappings.Add(mapping);
                    property.SetMappings(mappings);
                    property.Update();
                }
                FlushCache(site);
            }
        }
コード例 #30
0
ファイル: EFContact.cs プロジェクト: MrAntix/Poci
 public EFContact()
 {
     Emails = new MappingCollection<IEmail, EFEmail>();
     Phones = new MappingCollection<IPhone, EFPhone>();
     Addresses = new MappingCollection<IAddress, EFAddress>();
 }
コード例 #31
0
 CreateSearchPredicate <T>(FilterSet filterSet,
                           MappingCollection <T> mappings
                           ) where T : class
 {
     return(GetExpression <T>(mappings, filterSet.Filter));
 }
コード例 #32
0
        public void CreateMappingTest()
        {
            XNamespace name = "urn:nhibernate-configuration-2.2";
            XElement sessionFactoryEelement =
               new XElement(name + "sessionFactory",
                            new XElement(name + "property", new XAttribute("name", "name"), new XText("values")),
                            new XElement(name + "mapping", new XAttribute("assembly", "name"), new XText("orname.core.dll"))
                   );

            MappingCollection target = new MappingCollection(sessionFactoryEelement);
            var actual = target.CreateMapping();

            Assert.AreEqual(name, actual.Element.Name.Namespace);
        }