/// <summary>
        /// Convert an IFactorField instance
        /// to a WebFactorField instance.
        /// </summary>
        /// <param name="factorField">An IFactorField instance.</param>
        /// <returns>A WebFactorField instance.</returns>
        private WebFactorField GetFactorField(IFactorField factorField)
        {
            WebFactorField webFactorField;

            webFactorField = new WebFactorField();
            webFactorField.DatabaseFieldName = factorField.DatabaseFieldName;
            webFactorField.FactorDataTypeId  = factorField.FactorDataType.Id;
            if (factorField.Enum.IsNull())
            {
                webFactorField.EnumId = -1;
            }
            else
            {
                webFactorField.EnumId = factorField.Enum.Id;
            }

            webFactorField.Id            = factorField.Id;
            webFactorField.Information   = factorField.Information;
            webFactorField.IsEnumField   = factorField.Enum.IsNotNull();
            webFactorField.IsMain        = factorField.IsMain;
            webFactorField.IsSubstantial = factorField.IsSubstantial;
            webFactorField.Label         = factorField.Label;
            webFactorField.Size          = factorField.Size;
            webFactorField.TypeId        = factorField.Type.Id;
            webFactorField.Unit          = factorField.Unit;

            return(webFactorField);
        }
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        public WebFactorField GetFactorField()
        {
            if (_factorField.IsNull())
            {
                _factorField = FactorManagerTest.GetOneFactorField(GetContext());
            }
            return(_factorField);
        }
        /// <summary>
        /// Convert a WebFactorField into an IFactorField instance.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="factorDataType">Factor data type that this factor field belongs to.</param>
        /// <param name="webFactorField">A WebFactorField instance.</param>
        /// <param name="factorFieldEnums">List of factor field enumerations.</param>
        /// <returns>An IFactorField instance.</returns>
        private IFactorField GetFactorField(IUserContext userContext,
                                            IFactorDataType factorDataType,
                                            WebFactorField webFactorField,
                                            FactorFieldEnumList factorFieldEnums)
        {
            Int32 factorFieldIndex;

            switch (webFactorField.DatabaseFieldName)
            {
            case "tal1":
                factorFieldIndex = 0;
                break;

            case "tal2":
                factorFieldIndex = 1;
                break;

            case "tal3":
                factorFieldIndex = 2;
                break;

            case "text1":
                factorFieldIndex = 3;
                break;

            case "text2":
                factorFieldIndex = 4;
                break;

            default:
                throw new ApplicationException("Unknown database field name = " + webFactorField.DatabaseFieldName);
            }

            IFactorField factorField = new FactorField
            {
                DataContext       = GetDataContext(userContext),
                DatabaseFieldName = webFactorField.DatabaseFieldName,
                FactorDataType    = factorDataType,
                Id            = webFactorField.Id,
                Index         = factorFieldIndex,
                Information   = webFactorField.Information,
                IsMain        = webFactorField.IsMain,
                IsSubstantial = webFactorField.IsSubstantial,
                Label         = webFactorField.Label,
                Size          = webFactorField.Size,
                Type          = CoreData.FactorManager.GetFactorFieldType(userContext, webFactorField.TypeId),
                Unit          = webFactorField.Unit
            };

            if (webFactorField.IsEnumField)
            {
                factorField.Enum = factorFieldEnums.Get(webFactorField.EnumId);
            }

            return(factorField);
        }
Exemple #4
0
 /// <summary>
 /// Load data into the WebFactorField instance.
 /// </summary>
 /// <param name="factorField">The factor field instance.</param>
 /// <param name='dataReader'>An open data reader.</param>
 public static void LoadData(this WebFactorField factorField, DataReader dataReader)
 {
     factorField.DatabaseFieldName = dataReader.GetString(FactorFieldData.DATABASE_FIELD_NAME);
     factorField.FactorDataTypeId  = dataReader.GetInt32(FactorFieldData.FACTOR_DATA_TYPE_ID);
     factorField.EnumId            = dataReader.GetInt32(FactorFieldData.FACTOR_FIELD_ENUM_ID, -1);
     factorField.Id            = dataReader.GetInt32(FactorFieldData.ID);
     factorField.Information   = dataReader.GetString(FactorFieldData.INFORMATION);
     factorField.IsEnumField   = dataReader.IsNotDbNull(FactorFieldData.FACTOR_FIELD_ENUM_ID);
     factorField.IsMain        = dataReader.GetBoolean(FactorFieldData.IS_MAIN);
     factorField.IsSubstantial = dataReader.GetBoolean(FactorFieldData.IS_SUBSTANTIAL);
     factorField.Label         = dataReader.GetString(FactorFieldData.LABEL);
     factorField.Size          = dataReader.GetInt32(FactorFieldData.SIZE, -1);
     factorField.TypeId        = dataReader.GetInt32(FactorFieldData.FACTOR_FIELD_TYPE_ID);
     factorField.Unit          = dataReader.GetString(FactorFieldData.UNIT);
 }
        public static WebFactorField GetOneFactorFieldString(WebServiceContext context)
        {
            List <WebFactorDataType> factorDataTypes;
            WebFactorDataType        factorDataType = null;
            WebFactorField           factorField    = null;

            factorDataTypes = FactorManager.GetFactorDataTypes(context);
            foreach (WebFactorDataType tempFactorDataType in factorDataTypes)
            {
                if (tempFactorDataType.Id == 15)
                {
                    factorDataType = tempFactorDataType;
                }
            }
            foreach (WebFactorField tempFactorField in factorDataType.Fields)
            {
                if (tempFactorField.DatabaseFieldName == "text1")
                {
                    factorField = tempFactorField;
                }
            }
            return(factorField);
        }
Exemple #6
0
        /// <summary>
        /// Get all factor data types.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <returns>Factor data types.</returns>
        public static List <WebFactorDataType> GetFactorDataTypes(WebServiceContext context)
        {
            Int32 factorDataTypeId;
            List <WebFactorDataType> factorDataTypes;
            String            cacheKey;
            WebFactorDataType factorDataType;
            WebFactorField    factorField;

            // Get cached information.
            factorDataTypes = null;
            cacheKey        = Settings.Default.FactorDataTypeCacheKey;
            if (!context.IsInTransaction())
            {
                factorDataTypes = (List <WebFactorDataType>)context.GetCachedObject(cacheKey);
            }

            if (factorDataTypes.IsNull())
            {
                // Get information from database.
                factorDataTypes = new List <WebFactorDataType>();
                using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetFactorFields())
                {
                    while (dataReader.Read())
                    {
                        // Get factor data type.
                        factorDataType   = null;
                        factorDataTypeId = dataReader.GetInt32(FactorFieldData.FACTOR_DATA_TYPE_ID);
                        foreach (WebFactorDataType tempFactorDataType in factorDataTypes)
                        {
                            if (factorDataTypeId == tempFactorDataType.Id)
                            {
                                factorDataType = tempFactorDataType;
                            }
                        }

                        if (factorDataType.IsNull())
                        {
                            dataReader.ColumnNamePrefix = FactorDataTypeData.COLUMN_NAME_PREFIX;
                            factorDataType = new WebFactorDataType();
                            factorDataType.LoadData(dataReader);
                            factorDataTypes.Add(factorDataType);
                            dataReader.ColumnNamePrefix = null;
                        }

                        // Add field.
                        factorField = new WebFactorField();
                        factorField.LoadData(dataReader);

                        // ReSharper disable once PossibleNullReferenceException
                        factorDataType.Fields.Add(factorField);
                    }

                    if (!context.IsInTransaction())
                    {
                        // Add information to cache.
                        context.AddCachedObject(cacheKey, factorDataTypes, DateTime.Now + new TimeSpan(12, 0, 0), CacheItemPriority.AboveNormal);
                    }
                }
            }

            return(factorDataTypes);
        }
 public WebFactorFieldTest()
 {
     _factorField = null;
 }