コード例 #1
0
ファイル: HibernateUtils.cs プロジェクト: ghy/SMS
 static HibernateUtils()
 {
     try
     {
         _configuration = new Configuration();
         var mapping = new MappingFactory().CreateMapping();
         _configuration.AddDeserializedMapping(mapping, null);
         var a = _configuration.Configure();
         _sessionFactory = a.BuildSessionFactory();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #2
0
        private static Expression GetEnumerablePopulation(
            DictionarySourceMember sourceMember,
            Expression variable,
            IEnumerable <string> potentialNames,
            IChildMemberMappingData childMappingData)
        {
            var sourceList = Expression.Variable(typeof(List <>).MakeGenericType(sourceMember.EntryType), "sourceList");
            var counter    = Expression.Variable(typeof(int), "i");

            var potentialNameConstants = GetPotentialItemNames(potentialNames, counter, childMappingData.MapperData);

            var tryGetValueCall       = GetTryGetValueCall(variable, potentialNameConstants, childMappingData.MapperData);
            var loopBreak             = Expression.Break(Expression.Label());
            var ifNotTryGetValueBreak = Expression.IfThen(Expression.Not(tryGetValueCall), loopBreak);

            var sourceListAddCall = Expression.Call(sourceList, "Add", Constants.NoTypeArguments, variable);
            var incrementCounter  = Expression.PreIncrementAssign(counter);

            var loopBody = Expression.Block(
                ifNotTryGetValueBreak,
                sourceListAddCall,
                incrementCounter);

            var populationLoop = Expression.Loop(loopBody, loopBreak.Target);

            var entrySourceMember = sourceMember.WithType(sourceList.Type);

            var mapping = MappingFactory.GetChildMapping(
                entrySourceMember,
                sourceList,
                0,
                childMappingData);

            var enumerablePopulation = Expression.Block(
                new[] { sourceList, counter },
                Expression.Assign(sourceList, sourceList.Type.GetEmptyInstanceCreation()),
                Expression.Assign(counter, Expression.Constant(0)),
                populationLoop,
                mapping);

            return(enumerablePopulation);
        }
コード例 #3
0
        public void Will_ReturnBflagMapping_When_Requested()
        {
            ValueMapping mapping = MappingFactory.GetMapping(MappingTypes.BFLAG);

            Assert.IsNotNull(mapping);
            Assert.AreEqual(MappingTypes.BFLAG, mapping.MappingType);
            Assert.AreEqual(typeof(int), mapping.ValueType);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(1));
            Assert.AreEqual("Address(A)", mapping.PossibleValues[1]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(2));
            Assert.AreEqual("Memory/cache(M)", mapping.PossibleValues[2]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(4));
            Assert.AreEqual("Workflow(W)", mapping.PossibleValues[4]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(8));
            Assert.AreEqual("Master file(MF)", mapping.PossibleValues[8]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(16));
            Assert.AreEqual("Dates on relations", mapping.PossibleValues[16]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(32));
            Assert.AreEqual("Form", mapping.PossibleValues[32]);
        }
コード例 #4
0
        public CompanyModel GetCompanyModel(int companyId)
        {
            if (companyId == 0)
            {
                return(GetNewCompanyModel());
            }

            using (var context = _contextFactory.CreateContext())
            {
                return(context.Companies
                       .AsNoTracking()
                       .Include(c => c.Addresses)
                       .Include(c => c.Contacts)
                       .Include(c => c.CompanyTypesLink).ThenInclude(l => l.CompanyType)
                       .Where(c => c.CompanyId == companyId)
                       //.ProjectBetween<Company, CompanyModel>()
                       .Select(c => MappingFactory.MapTo <CompanyModel>(c))
                       .FirstOrDefault());
            }
        }
コード例 #5
0
        private void CheckVersions()
        {
            if (LastValidationMemo != null && LastValidationMemo.Errors.Any(a => a.Message.Contains("This service will only execute when the server is online.")))
            {
                RemoveErrors(
                    LastValidationMemo.Errors.Where(
                        a => a.Message.Contains("This service will only execute when the server is online.")).ToList());
                UpdateWorstError();
            }
            var webAct     = ActivityFactory.CreateWebActivity(NewModel, NewModel, ServiceName);
            var newMapping = MappingFactory.CreateModel(webAct, OnMappingCollectionChanged);

            if (newMapping.GetInputString(DataMappingViewModel.Inputs) != DataMappingViewModel.GetInputString(DataMappingViewModel.Inputs) ||
                newMapping.GetOutputString(DataMappingViewModel.Outputs) != DataMappingViewModel.GetOutputString(DataMappingViewModel.Outputs))
            {
                UpdateLastValidationMemoWithVersionChanged();
                _resourcesUpdated  = true;
                _versionsDifferent = true;
            }
        }
コード例 #6
0
        private IDataReader GetRelatedTableReader(string table_name)
        {
            var metadata = (TMappingInfo)MappingFactory.GetMapping(typeof(TMappingInfo));
            var item     = metadata.Associations.Where(x => x.Name == table_name).FirstOrDefault();

            if (item == null)
            {
                return(null);
            }

            var omapping = MappingFactory.GetMapping(item.OtherMappingType);

            var qry = (new SelectStatement())
                      .Column(omapping.Columns.Where(x => x.Name == item.OtherKeys[0]).Single().ColumnName)
                      .From(omapping.TableName);

            var lblCount = item.OtherLabels.Count;

            if (lblCount == 0)
            {
                return(null);
            }
            else
            {
                if (lblCount == 1)
                {
                    qry.Column(omapping.Columns.Where(x => x.Name == item.OtherLabels[0]).Single().ColumnName);
                }
                else
                {
                    var lblConcat = new ConcatFunction(" | ");
                    foreach (var lbl in item.OtherLabels)
                    {
                        lblConcat.Append(new SqlColumnName(omapping.Columns.Where(x => x.Name == lbl).Single().ColumnName));
                    }
                    qry.Column(lblConcat);
                }
            }

            return(qry.ExecuteReader());
        }
コード例 #7
0
ファイル: Adapter.cs プロジェクト: MingLu8/Nemo
        private static void DefineProperties(Type objectType, TypeBuilder typeBuilder, FieldInfo field, Type interfaceType, DynamicProxyType proxyType)
        {
            var entityMap = MappingFactory.GetEntityMap(interfaceType);

            foreach (var property in Reflector.GetAllProperties(interfaceType))
            {
                // check if we can support the wrapping.
                var propertyName   = MappingFactory.GetPropertyOrColumnName(property, false, entityMap, false);
                var objectProperty = objectType?.GetProperty(propertyName);

                if (objectProperty != null && ((property.CanRead && !objectProperty.CanRead) || (property.CanWrite && !objectProperty.CanWrite)))
                {
                    throw new InvalidCastException("Can't cast because the property is missing or does not have the required implementation.");
                }

                // check the property types.
                if (objectProperty != null && objectProperty.PropertyType != property.PropertyType)
                {
                    throw new InvalidCastException("Can't cast because property types do not match.");
                }

                // define the property.
                if (proxyType == DynamicProxyType.FullIndexer || (proxyType == DynamicProxyType.SimpleIndexer && IsWrappable(property, entityMap)))
                {
                    DefineIndexerProperty(property, typeBuilder, field, objectType, entityMap);
                }
                else if (proxyType == DynamicProxyType.Guard)
                {
                    DefineGuardedProperty(property, typeBuilder, field, objectType, entityMap);
                }
                else if (objectProperty != null)
                {
                    DefineProperty(property, typeBuilder, field, objectType, objectProperty);
                }
                else
                {
                    DefineDefaultProperty(property, typeBuilder);
                }
            }
        }
コード例 #8
0
        public void BuildSchemaTableFromMapping()
        {
            var entityMapping = MappingFactory.CreateEntityMappingFromAnnonations <NotNullEntity>();
            var schemaTable   = DataSourceBuilder.BuildSchemaTableFromEntityMapping(entityMapping);

            AssertSchemaTable(schemaTable, new[]
            {
                new SchemaMappingColumn("FID", typeof(int), false),
                new SchemaMappingColumn("FIntProp", typeof(int), false),
                new SchemaMappingColumn("FShortProp", typeof(short), false),
                new SchemaMappingColumn("FLongProp", typeof(long), false),
                new SchemaMappingColumn("FFloatProp", typeof(float), false),
                new SchemaMappingColumn("FDoubleProp", typeof(double), false),
                new SchemaMappingColumn("FDecimalProp", typeof(decimal), false),
                new SchemaMappingColumn("FBoolProp", typeof(bool), false),
                new SchemaMappingColumn("FStringProp", typeof(string), true),
                new SchemaMappingColumn("FDateTimeProp", typeof(DateTime), false),
                new SchemaMappingColumn("FBinaryProp", typeof(byte[]), true),
                new SchemaMappingColumn("FGuidProp", typeof(Guid), false),
                new SchemaMappingColumn("FEnumProp", typeof(int), false),
            });
        }
コード例 #9
0
        protected void AddDetailsDataTables(TMappingInfo mapping_info)
        {
            // Add details data tables

            var items = mapping_info.Associations;

            foreach (var item in items)
            {
                var mapping         = MappingFactory.GetMapping(item.OtherMappingType);
                var tableName       = mapping.TableName;
                var tableAlias      = item.Name;
                var associationName = item.GetType().Name;

                AddDataTable(tableName, tableAlias, mapping);

                var thisColumns  = new DataColumn[item.ThisKeys.Count];
                var otherColumns = new DataColumn[item.OtherKeys.Count];

                for (int z = 0; z < item.ThisKeys.Count; z++)
                {
                    thisColumns[z] = this.Tables[0].Columns[item.ThisKeys[z]];
                }

                for (int z = 0; z < item.OtherKeys.Count; z++)
                {
                    var key  = item.OtherKeys[z];
                    var ccol = this.Tables[tableAlias].Columns[item.OtherKeys[z]];

                    otherColumns[z] = ccol;
                }

                if (associationName.Contains("Has"))
                {
                    this.Tables[tableAlias].ExtendedProperties["IsChild"] = true;
                    this.Relations.Add(new DataRelation(tableAlias, thisColumns, otherColumns));
                }
            }
        }
コード例 #10
0
        public void OnRequestMassTerminateControllerIsNotNull()
        {
            //Mock the repository
            var repository =
                new Mock <IStagingRepository <MassTerminationModelSerialized> >(MockBehavior.Strict);


            //Mock data factory
            var dataFactory =
                new Mock <IDataFactory>(MockBehavior.Strict);

            dataFactory.Setup(d => d.GetMassTerminateRepository()).Returns(repository.Object);

            //Mapping factory
            IMappingFactory mapFactory = new MappingFactory();

            //Mock Auth
            var authorization = new Mock <IAuthorizationProvider>(MockBehavior.Strict);

            authorization.Setup(m => m.IsAuthorized(It.IsAny <string>())).Returns(true);

            repository.Setup(x => x.SetDataAsync(It.IsAny <UserContext>(),
                                                 It.IsAny <List <MassTerminationModelSerialized> >()))
            .ReturnsAsync(new List <DataloadBatch>()
            {
                new DataloadBatch {
                    BatchID = Guid.NewGuid(), JobID = Guid.NewGuid()
                }
            });

            //Create Controller
            var controller =
                new MassTerminateController(dataFactory.Object, authorization.Object, mapFactory);

            Assert.IsNotNull(controller);
        }
コード例 #11
0
ファイル: DbFactory.cs プロジェクト: MingLu8/Nemo
        private static string GetDefaultConnectionName(Type objectType)
        {
            string connectionName = null;

            if (Reflector.IsEmitted(objectType))
            {
                objectType = Reflector.GetInterface(objectType);
            }

            var map = MappingFactory.GetEntityMap(objectType);

            if (map != null)
            {
                connectionName = map.ConnectionStringName;
            }

            if (connectionName == null)
            {
                var attr = Reflector.GetAttribute <ConnectionAttribute>(objectType, false, true);
                if (attr != null)
                {
                    connectionName = attr.Name;
                }
            }

            if (connectionName == null)
            {
                var attr = Reflector.GetAttribute <ConnectionAttribute>(objectType, true);
                if (attr != null)
                {
                    connectionName = attr.Name;
                }
            }

            return(connectionName ?? ConfigurationFactory.Get(objectType).DefaultConnectionName);
        }
コード例 #12
0
        public void SetDataAsyncWithoutSaveFromRepositoryReturnsNotFoundResult()
        {
            //Mock the repository
            var repository =
                new Mock <IStagingRepository <MassTerminationModelSerialized> >(MockBehavior.Strict);
            var qRepo = new Mock <IQueueRepository>(MockBehavior.Strict);

            repository.Setup(r => r.SetDataAsync(It.IsAny <UserContext>(),
                                                 It.IsAny <List <MassTerminationModelSerialized> >()))
            .ReturnsAsync(new List <DataloadBatch>());

            //Mock data factory
            var dataFactory =
                new Mock <IDataFactory>(MockBehavior.Strict);

            dataFactory.Setup(d => d.GetMassTerminateRepository()).Returns(repository.Object);
            dataFactory.Setup(d => d.GetQueueRepository()).Returns(qRepo.Object);

            //Mapping factory
            IMappingFactory mapFactory = new MappingFactory();

            //Mock Auth
            var authorization = new Mock <IAuthorizationProvider>(MockBehavior.Strict);

            authorization.Setup(s => s.IsAuthorized(It.IsIn <string>(new List <string>()
            {
                "426"
            }))).Returns(true);

            var controller = new MassTerminateController(dataFactory.Object, authorization.Object, mapFactory);


            Task <IHttpActionResult> actionResult = controller.SetDataAsync("426", models);

            Assert.IsInstanceOfType(actionResult.Result, typeof(NotFoundResult));
        }
コード例 #13
0
        public void NoVersionColumnName()
        {
            var document = GetMappingDocument("Version.NoVersionColumnName.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #14
0
        public void WrongDiscriminatorColumnType()
        {
            var document = GetMappingDocument("Discriminator.WrongDiscriminatorColumnType.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #15
0
        public void NoProperties()
        {
            var document = GetMappingDocument("Class.NoProperties.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #16
0
        public void NoDiscriminatorColumnName()
        {
            var document = GetMappingDocument("Discriminator.NoDiscriminatorColumnName.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #17
0
        public void NoSequenceGeneratorName()
        {
            var document = GetMappingDocument("Property.NoSequenceGeneratorName.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #18
0
        public void WrongSubclassDiscriminatorValueType()
        {
            var document = GetMappingDocument("Subclass.WrongDiscriminatorValueType.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #19
0
        public void NoSubclassName()
        {
            var document = GetMappingDocument("Subclass.NoSubclassName.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #20
0
        public void CheckVersionStaticPropertyReference()
        {
            var document = GetMappingDocument("Version.CheckVersionStaticPropertyReference.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #21
0
ファイル: PocoData.cs プロジェクト: manishkungwani/frapid
 public PocoData()
 {
     _mappingFactory = new MappingFactory(this);
 }
コード例 #22
0
        public void NoTableName()
        {
            var document = GetMappingDocument("Class.NoTableName.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #23
0
        public void CheckVersionWrongConverter()
        {
            var document = GetMappingDocument("Version.CheckVersionWrongConverter.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #24
0
        public void CheckSubclassNoJoinTable()
        {
            var document = GetMappingDocument("Subclass.CheckNoJoinTable.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #25
0
        public void WrongPrimaryKeyName()
        {
            var document = GetMappingDocument("PrimaryKey.WrongPrimaryKeyName.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #26
0
        public void CheckPropertyStaticFieldReference()
        {
            var document = GetMappingDocument("Property.CheckPropertyStaticFieldReference.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #27
0
        public void ClassSubclassDiscriminatorValueWithoutColumn()
        {
            var document = GetMappingDocument("Subclass.DiscriminatorValueWithoutColumn.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #28
0
        public void CheckPropertyPseudoConverter()
        {
            var document = GetMappingDocument("Property.CheckPropertyPseudoConverter.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #29
0
        public void CheckSubclassEmptyJoin()
        {
            var document = GetMappingDocument("Subclass.CheckEmptyJoin.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #30
0
        public void CheckPropertyUnknownConverter()
        {
            var document = GetMappingDocument("Property.CheckPropertyWrongConverter.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #31
0
        public void CheckJoinNoColumnJoinColumn()
        {
            var document = GetMappingDocument("Subclass.CheckJoinNoColumnJoinColumn.xml");

            MappingFactory.CreateMapping(document);
        }
コード例 #32
0
        public void CheckPropertyWrongGenerator()
        {
            var document = GetMappingDocument("Property.CheckPropertyWrongGenerator.xml");

            MappingFactory.CreateMapping(document);
        }