public void ISOCode()
        {
            WebLocale locale = GetLocale();

            locale.ISOCode = "Namn";
            Assert.AreEqual(locale.ISOCode, "Namn");
        }
        public void Constructor()
        {
            WebLocale locale;

            locale = new WebLocale();
            Assert.IsNotNull(locale);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a WebServiceContext instance.
        /// This contructor should only be used during login.
        /// </summary>
        /// <param name="userName">User name.</param>
        /// <param name="applicationIdentifier">
        /// Identifier of the application that the user uses.
        /// </param>
        public WebServiceContext(String userName,
                                 String applicationIdentifier)
        {
            // Init object.
            _database    = null;
            _clientToken = new WebClientToken(userName,
                                              applicationIdentifier,
                                              WebServiceData.WebServiceManager.Key);
            _requestId = GetNextRequestId();
            if (_isTracing)
            {
                _traceStart = DateTime.Now;
            }
            _transactionTimeout = Settings.Default.TransactionDefaultTimeout; // Unit is seconds.

            // Check arguments.
            try
            {
                CheckHttpsProtocol();
            }
            catch (Exception exception)
            {
                WebServiceData.LogManager.LogSecurityError(this, exception);
                throw;
            }
            _currentRole = null;

            // This is only a temporary value.
            // Real value is set by UserManager when user has logged in.
            _locale = GetDefaultLocale();
        }
        public void NativeName()
        {
            WebLocale locale = GetLocale();

            locale.NativeName = "Namn";
            Assert.AreEqual(locale.NativeName, "Namn");
        }
        /// <summary>
        /// Get cached locales.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <returns>Cached locales.</returns>
        private static Hashtable GetCachedLocales(WebServiceContext context)
        {
            Hashtable localeTable;
            WebLocale locale;

            // Get cached information.
            localeTable = (Hashtable)context.GetCachedObject(Settings.Default.LocaleCacheKey);

            // Data not in cache - store it in the cache.
            if (localeTable.IsNull())
            {
                // Get information from database.
                using (DataReader dataReader = context.GetUserDatabase().GetLocales())
                {
                    localeTable = new Hashtable();
                    while (dataReader.Read())
                    {
                        locale = new WebLocale();
                        locale.LoadData(dataReader);

                        // Add object to Hashtable.
                        localeTable.Add(locale.Id, locale);
                        localeTable.Add(locale.ISOCode.ToUpper(), locale);
                    }
                    // Add information to cache.
                    context.AddCachedObject(Settings.Default.LocaleCacheKey,
                                            localeTable,
                                            DateTime.Now + new TimeSpan(1, 0, 0, 0),
                                            CacheItemPriority.High);
                }
            }
            return(localeTable);
        }
Esempio n. 6
0
        /// <summary>
        /// Create a WebServiceContext instance.
        /// </summary>
        /// <param name='clientInformation'>Client information.</param>
        public WebServiceContext(WebClientInformation clientInformation)
        {
            // Init context.
            _database    = null;
            _clientToken = new WebClientToken(clientInformation.Token,
                                              WebServiceData.WebServiceManager.Key);
            _locale = clientInformation.Locale;
            if (_locale.IsNull())
            {
                _locale = GetDefaultLocale();
            }
            _currentRole = clientInformation.Role;
            _requestId   = GetNextRequestId();
            if (_isTracing)
            {
                _traceStart = DateTime.Now;
            }
            _transactionTimeout = Settings.Default.TransactionDefaultTimeout; // Unit is seconds.

            // Check arguments.
            try
            {
                clientInformation.CheckNotNull("clientInformation");
                CheckUser();
                CheckClientIpAddress();
                CheckHttpsProtocol();
                CheckWebServiceName();
                CheckCurrentRole();
            }
            catch (Exception exception)
            {
                WebServiceData.LogManager.LogSecurityError(this, exception);
                throw;
            }
        }
        public void Id()
        {
            WebLocale locale = GetLocale();

            locale.Id = 1;
            Assert.AreEqual(locale.Id, 1);
        }
        public void GetPictureMetaDataDescriptionsByIds()
        {
            List <Int32> metaDataIds = new List <int> {
                2, 4
            };
            List <WebPictureMetaDataDescription> pictureMetaDataDescriptions;
            WebLocale            locale            = new WebLocale();
            WebClientInformation clientInformation = GetClientInformation();

            locale.Id = 49; // English
            clientInformation.Locale = locale;
            using (IWebServiceTransaction transaction = new WebServiceTransaction(clientInformation, WebServiceProxy.PictureService))
            {
                pictureMetaDataDescriptions = WebServiceProxy.PictureService.GetPictureMetaDataDescriptionsByIds(clientInformation, metaDataIds);
                Assert.IsTrue(pictureMetaDataDescriptions.IsNotEmpty());
            }

            pictureMetaDataDescriptions = WebServiceProxy.PictureService.GetPictureMetaDataDescriptionsByIds(clientInformation, metaDataIds);
            Assert.IsTrue(pictureMetaDataDescriptions.IsNotEmpty());

            locale.Id = 175; // Swedish
            clientInformation.Locale = locale;
            using (IWebServiceTransaction transaction = new WebServiceTransaction(clientInformation, WebServiceProxy.PictureService))
            {
                pictureMetaDataDescriptions = WebServiceProxy.PictureService.GetPictureMetaDataDescriptionsByIds(clientInformation, metaDataIds);
                Assert.IsTrue(pictureMetaDataDescriptions.IsNotEmpty());
            }

            pictureMetaDataDescriptions = WebServiceProxy.PictureService.GetPictureMetaDataDescriptionsByIds(clientInformation, metaDataIds);
            Assert.IsTrue(pictureMetaDataDescriptions.IsNotEmpty());
        }
 private WebLocale GetLocale(Boolean refresh)
 {
     if (_locale.IsNull() || refresh)
     {
         _locale = new WebLocale();
     }
     return(_locale);
 }
        public void Locale()
        {
            WebLocale locale = new WebLocale();


            GetClientInformation(true).Locale = locale;
            Assert.AreEqual(locale, GetClientInformation().Locale);
        }
 /// <summary>
 /// Get locale from web locale.
 /// </summary>
 /// <param name="webLocale">Web locale.</param>
 /// <returns>Locale.</returns>
 protected ILocale GetLocale(WebLocale webLocale)
 {
     return(new Locale(webLocale.Id,
                       webLocale.ISOCode,
                       webLocale.Name,
                       webLocale.NativeName,
                       new DataContext(GetDataSourceInformation(), null)));
 }
        public void Locale()
        {
            WebLocale locale = new WebLocale();


            GetLoginResponse(true).Locale = locale;
            Assert.AreEqual(locale, GetLoginResponse().Locale);
        }
Esempio n. 13
0
        /// <summary>
        /// Get default locale.
        /// </summary>
        /// <returns>Default locale.</returns>
        public WebLocale GetDefaultLocale()
        {
            WebLocale defaultLocale;

            defaultLocale         = new WebLocale();
            defaultLocale.Id      = Settings.Default.DefaultLocaleId;
            defaultLocale.ISOCode = Settings.Default.DefaultLocaleISOCode;
            return(defaultLocale);
        }
Esempio n. 14
0
        /// <summary>
        /// Gets a WebLocale.
        /// Currently this method returns a swedish WebLocale.
        /// </summary>
        /// <returns>A swedish WebLocale object.</returns>
        protected virtual WebLocale GetWebLocale()
        {
            WebLocale webLocale = new WebLocale();

            webLocale.Id         = (int)LocaleId.sv_SE;
            webLocale.ISOCode    = "sv-SE";
            webLocale.Name       = "Swedish (Sweden)";
            webLocale.NativeName = "svenska (Sverige)";
            return(webLocale);
        }
        /// <summary>
        /// Get web locale from locale.
        /// </summary>
        /// <param name="locale">Locale.</param>
        /// <returns>Web locale.</returns>
        protected WebLocale GetLocale(ILocale locale)
        {
            WebLocale webLocale;

            webLocale            = new WebLocale();
            webLocale.Id         = locale.Id;
            webLocale.ISOCode    = locale.ISOCode;
            webLocale.Name       = locale.Name;
            webLocale.NativeName = locale.NativeName;
            return(webLocale);
        }
Esempio n. 16
0
        /// <summary>
        /// Create a WebServiceContext instance.
        /// </summary>
        /// <param name='clientToken'>Token with information about current user and connection</param>
        /// <param name='checkUser'>Information about if user authority should be checked.
        ///                         It should only be set to false during login.</param>
        /// <param name='traceMethod'>Name of calling method. Used during tracing.</param>
        /// <param name='traceArgument1'>Argument 1 to the calling method. Used during tracing.</param>
        /// <param name='traceArgument2'>Argument 2 to the calling method. Used during tracing.</param>
        /// <param name='traceArgument3'>Argument 3 to the calling method. Used during tracing.</param>
        public WebServiceContext(WebClientToken clientToken,
                                 Boolean checkUser,
                                 String traceMethod,
                                 Object traceArgument1,
                                 Object traceArgument2,
                                 Object traceArgument3)
        {
            // Init context.
            _databases      = new DataServer[Enum.GetNames(typeof(DataServer.DatabaseId)).Length];
            _clientToken    = clientToken;
            _locale         = null;
            _requestId      = GetNextRequestId();
            _traceArgument1 = traceArgument1;
            _traceArgument2 = traceArgument2;
            _traceArgument3 = traceArgument3;
            _traceMethod    = traceMethod;
            if (_isTracing)
            {
                _traceStart = DateTime.Now;
            }
            else
            {
                _traceStart = DateTime.MinValue;
            }
            _transactionTimeout = DEFAULT_TRANSACTION_TIMEOUT;

            // Check arguments.
            try
            {
                clientToken.CheckNotNull("clientToken");
                if (checkUser)
                {
                    clientToken.CheckData();
                    CheckUser();
                }
                CheckClientIPAddress();
                CheckHttpsProtocol();
            }
            catch (Exception exception)
            {
                LogManager.LogSecurityError(this, exception);
                throw exception;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// The process observation.
        /// </summary>
        /// <param name="webData">
        /// The web data.
        /// </param>
        /// <param name="mappings">
        /// The mappings.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The harvestSpeciesObservation.<see cref="HarvestSpeciesObservation"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">If some properties where not found.
        /// </exception>
        public virtual HarvestSpeciesObservation ProcessObservation(WebData webData, List <HarvestMapping> mappings, WebServiceContext context)
        {
            // Create a dictionary object from the WebData object (Not cachable, needs to be done for each row)
            // Can be a problem if same name exists in more than one class...
            Dictionary <string, WebDataField> dictionaryWebData = webData.DataFields.ToDictionary(row => row.Name.ToLower(), row => row);

            WebLocale webLocale = GetWebLocale();

            HarvestSpeciesObservation harvestSpeciesObservation = new HarvestSpeciesObservation();

            harvestSpeciesObservation.Fields = new List <HarvestSpeciesObservationField>();

            if (mappings.IsNotNull())
            {
                // Loop through the mappings + create objects for every field
                foreach (HarvestMapping mapping in mappings)
                {
                    String mapProperty;
                    if (!ReadElement(mapping.Property, out mapProperty))
                    {
                        throw new ArgumentNullException(String.Format("Error in mapping. Element <Property>, {0}, not found.", mapping.Property));
                    }

                    SpeciesObservationPropertyId speciesObservationPropertyId = SpeciesObservationPropertyId.None;

                    // This validation should not be performed on fields of ProjectParameter type
                    if (mapping.GUID == null || !mapping.GUID.Contains("projectparameter"))
                    {
                        if (!Enum.TryParse(mapProperty, true, out speciesObservationPropertyId))
                        {
                            throw new ArgumentNullException(String.Format("Property value: {0} not a valid property.", mapProperty));
                        }
                    }

                    Boolean isMandatory;
                    String  isMandatoryString;
                    if (!ReadElement(mapping.Mandatory.ToString(), out isMandatoryString))
                    {
                        throw new ArgumentNullException(String.Format("Error in mapping. Element <IsMandatoryFromProvider>, {0}, not found.", mapping.IsMandatoryFromProvider));
                    }

                    isMandatory = mapping.Mandatory;

                    String mapClass;
                    if (!ReadElement(mapping.Class, out mapClass))
                    {
                        throw new ArgumentNullException(String.Format("Error in mapping. Element <Class>, {0}, not found.", mapping.Class));
                    }

                    SpeciesObservationClassId speciesObservationClassId;
                    if (!Enum.TryParse(mapClass, true, out speciesObservationClassId))
                    {
                        throw new ArgumentNullException(String.Format("Class value: {0} not a valid class.", mapClass));
                    }

                    String mapType;
                    if (!ReadElement(mapping.Type, out mapType))
                    {
                        throw new ArgumentNullException(String.Format("Error in mapping. Element <Type>, {0}, not found.", mapping.Type));
                    }

                    WebDataType webDataType;
                    if (!Enum.TryParse(mapType, true, out webDataType))
                    {
                        throw new ArgumentNullException(String.Format("Type value: {0} not a valid type.", mapType));
                    }

                    String mapName;
                    if (mapping.IsProjectParameter())
                    {
                        mapName = mapping.PropertyIdentifier;
                    }
                    else
                    {
                        ReadElement(mapping.Name, out mapName);
                    }

                    String mapMethod;
                    ReadElement(mapping.Method, out mapMethod);
                    String mapDefault;
                    ReadElement(mapping.Default, out mapDefault);

                    String fieldValue = String.Empty;
                    String fieldUnit  = null;

                    if (mapName.IsNotEmpty())
                    {
                        try
                        {
                            if (dictionaryWebData.ContainsKey(mapName.ToLower()))
                            {
                                fieldValue = dictionaryWebData[mapName.ToLower()].Value;
                                fieldUnit  = ReplaceInvalidCharacters(dictionaryWebData[mapName.ToLower()].Unit);
                                if (webDataType == WebDataType.String)
                                {
                                    fieldValue = ReplaceInvalidCharacters(fieldValue);
                                }
                            }
                        }
                        catch (KeyNotFoundException)
                        {
                            throw new ArgumentNullException(String.Format("Field:{0} not found.", mapName));
                        }
                    }

                    if (mapMethod.IsNotEmpty())
                    {
                        fieldValue = MethodWrapper(mapMethod, dictionaryWebData, context, mapping);
                    }

                    if (fieldValue.IsNull() || fieldValue.IsEmpty())
                    {
                        // field is empty - set to default value ?
                        if (mapDefault.IsNotEmpty())
                        {
                            fieldValue = mapDefault;
                        }
                    }

                    if (fieldValue.IsNotEmpty() || isMandatory)
                    {
                        HarvestSpeciesObservationField harvestSpeciesObservationField = new HarvestSpeciesObservationField();
                        harvestSpeciesObservationField.Class = new WebSpeciesObservationClass(speciesObservationClassId);

                        // The type SpeciesObservationPropertyId.None indicates the use of the Identifier instead
                        harvestSpeciesObservationField.Property = new WebSpeciesObservationProperty();
                        if (mapping.IsProjectParameter())
                        {
                            harvestSpeciesObservationField.Property.Id         = SpeciesObservationPropertyId.None;
                            harvestSpeciesObservationField.Property.Identifier = mapping.PropertyIdentifier;
                        }
                        else
                        {
                            harvestSpeciesObservationField.Property.Id = speciesObservationPropertyId;
                            if (speciesObservationPropertyId == SpeciesObservationPropertyId.None)
                            {
                                harvestSpeciesObservationField.Property.Identifier = mapping.Name;
                            }
                        }

                        harvestSpeciesObservationField.Type                    = webDataType;
                        harvestSpeciesObservationField.Unit                    = fieldUnit;
                        harvestSpeciesObservationField.Value                   = fieldValue.CheckInjection();
                        harvestSpeciesObservationField.Locale                  = webLocale;
                        harvestSpeciesObservationField.IsDarwinCore            = mapping.IsDarwinCore;
                        harvestSpeciesObservationField.IsSearchable            = mapping.IsSearchable;
                        harvestSpeciesObservationField.IsMandatory             = isMandatory; // måste med till nästa steg
                        harvestSpeciesObservationField.IsMandatoryFromProvider = mapping.IsMandatoryFromProvider;
                        harvestSpeciesObservationField.IsObtainedFromProvider  = mapping.IsObtainedFromProvider;
                        harvestSpeciesObservationField.PersistedInTable        = mapping.PersistedInTable;

                        // add the field to the observation
                        harvestSpeciesObservation.Fields.Add(harvestSpeciesObservationField);
                    }
                }
            }

            // return one observation
            return(harvestSpeciesObservation);
        }
 public WebLocaleTest()
 {
     _locale = null;
 }