/// <summary>
        /// Adds a mail address parameter to the command.
        /// </summary>
        /// <param name="value">The value for the mail address.</param>
        /// <returns>This instance of the <see cref="HouseholdDataCommandBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal HouseholdDataCommandBuilder AddMailAddressParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@mailAddress", value, 128);
            return(this);
        }
        /// <summary>
        /// Adds the parameter for the title.
        /// </summary>
        /// <param name="value">The value for the title.</param>
        /// <returns>Command builder which can build command to the common repository.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="value"/> is null, empty or white space.</exception>
        internal CommonCommandBuilder AddTitleParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@title", value, 50);
            return(this);
        }
        /// <summary>
        /// Adds a household name parameter to the command.
        /// </summary>
        /// <param name="value">The value for the household name.</param>
        /// <returns>This instance of the <see cref="HouseholdDataCommandBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal HouseholdDataCommandBuilder AddHouseholdNameParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@name", value, 64);
            return(this);
        }
        /// <summary>
        /// Adds a payment reference parameter to the command.
        /// </summary>
        /// <param name="value">The value for the payment reference.</param>
        /// <returns>This instance of the <see cref="HouseholdDataCommandBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal HouseholdDataCommandBuilder AddPaymentReferenceParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@paymentReference", value, 128);
            return(this);
        }
        /// <summary>
        /// Adds a translation value parameter to the command.
        /// </summary>
        /// <param name="value">The value for the translation value.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal SystemDataCommandBuilder AddTranslationValueParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@value", value, 4096);
            return(this);
        }
        /// <summary>
        /// Adds a data provider name parameter to the command.
        /// </summary>
        /// <param name="value">The value for the data provider name.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal SystemDataCommandBuilder AddDataProviderNameParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@name", value, 256);
            return(this);
        }
        /// <summary>
        /// Adds a foreign key value parameter to the command.
        /// </summary>
        /// <param name="value">The value for the foreign key value.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal SystemDataCommandBuilder AddForeignKeyValueParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@foreignKeyValue", value, 128);
            return(this);
        }
        /// <summary>
        /// Creates a builder which can build a database command tester.
        /// </summary>
        /// <param name="commandText">The expected command text.</param>
        /// <param name="commandType">The expected command type.</param>
        /// <param name="commandTimeout">The expected command timeout.</param>
        public DbCommandTestBuilder(string commandText, CommandType commandType = CommandType.Text, int commandTimeout = 30)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(commandText, nameof(commandText));

            IDataParameterCollection dataParameterCollection = MockRepository.GenerateMock <IDataParameterCollection>();

            dataParameterCollection.Stub(m => m.Count)
            .WhenCalled(e => e.ReturnValue = _dataParameterCollection.Count)
            .Return(0)
            .Repeat.Any();
            dataParameterCollection.Stub(m => m[Arg <string> .Is.Anything])
            .WhenCalled(e => e.ReturnValue = _dataParameterCollection.SingleOrDefault(m => string.CompareOrdinal((string)e.Arguments.ElementAt(0), m.ParameterName) == 0))
            .Return(null)
            .Repeat.Any();

            _expectedDbCommand = MockRepository.GenerateMock <IDbCommand>();
            _expectedDbCommand.Stub(m => m.CommandText)
            .Return(commandText)
            .Repeat.Any();
            _expectedDbCommand.Stub(m => m.CommandType)
            .Return(commandType)
            .Repeat.Any();
            _expectedDbCommand.Stub(m => m.CommandTimeout)
            .Return(commandTimeout)
            .Repeat.Any();
            _expectedDbCommand.Stub(m => m.Parameters)
            .WhenCalled(e => e.ReturnValue = dataParameterCollection)
            .Return(null)
            .Repeat.Any();
        }
        /// <summary>
        /// Danner et system under OSWEBDB.
        /// </summary>
        /// <param name="nummer">Unik identifikation af systemet.</param>
        /// <param name="titel">Titel på systemet.</param>
        /// <param name="properties">Egenskaber for systemet.</param>
        public System(int nummer, string titel, int properties = 0)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(titel, nameof(titel));

            _nummer     = nummer;
            _titel      = titel;
            _properties = properties;
        }
        /// <summary>
        /// Validates whether a value is a mail address.
        /// </summary>
        /// <param name="value">Value to validate.</param>
        /// <returns>True if the value is a mail address otherwise false.</returns>
        public virtual bool IsMailAddress(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            Regex regularExpression = new Regex(@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", RegexOptions.Compiled);

            return(regularExpression.IsMatch(value));
        }
        /// <summary>
        /// Adds an instance of the <typeparamref name="TDataProxy"/> to the cache.
        /// </summary>
        /// <typeparam name="TDataProxy">Type of the data proxy which should be cached.</typeparam>
        /// <param name="cacheName">Unique name for the cached data.</param>
        /// <param name="dataProxy">The instance of the <typeparamref name="TDataProxy"/> which should be added to the cache.</param>
        /// <param name="dataProxyMatch">The predicate which can match any <typeparamref name="TDataProxy"/>.</param>
        /// <param name="minutesToStore">Number of minute to store cached data.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheName"/> is null, empty or white space or when <paramref name="dataProxy"/> is null or when <paramref name="dataProxyMatch"/> is null.</exception>
        internal static void AddDataProxyCollectionToCache <TDataProxy>(string cacheName, TDataProxy dataProxy, Predicate <TDataProxy> dataProxyMatch, int minutesToStore = 15)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(cacheName, nameof(cacheName))
            .NotNull(dataProxy, nameof(dataProxy))
            .NotNull(dataProxyMatch, nameof(dataProxyMatch));

            AddDataProxyCollectionToCache(cacheName, new List <TDataProxy> {
                dataProxy
            }, dataProxyMatch, minutesToStore);
        }
        /// <summary>
        /// Creates a household.
        /// </summary>
        /// <param name="name">Name for the household.</param>
        /// <param name="description">Description for the household.</param>
        /// <param name="creationTime">Date and time for when the household was created.</param>
        /// <param name="domainObjectValidations">Implementation for common validations used by domain objects in the food waste domain.</param>
        protected Household(string name, string description, DateTime creationTime, IDomainObjectValidations domainObjectValidations = null)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(name, nameof(name));

            _name         = name;
            _description  = description;
            _creationTime = creationTime;

            _domainObjectValidations = domainObjectValidations ?? DomainObjectValidations.Create();
        }
Esempio n. 13
0
        /// <summary>
        /// Creates an instance of the internal builder which can build a MySQL command for SQL statements.
        /// </summary>
        /// <param name="sqlStatement">The SQL statement for the MySQL command.</param>
        /// <param name="timeout">Wait time (in seconds) before terminating the attempt to execute a command and generating an error.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="sqlStatement"/> is null, empty or white space.</exception>
        protected MySqlCommandBuilderBase(string sqlStatement, int timeout = 30)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(sqlStatement, nameof(sqlStatement));

            Command = new MySqlCommand(sqlStatement)
            {
                CommandType    = CommandType.Text,
                CommandTimeout = timeout
            };
        }
        /// <summary>
        /// Gets the cached collection of the <typeparamref name="TDataProxy"/> or an empty collection when no data has been cached.
        /// </summary>
        /// <typeparam name="TDataProxy">Type of the data proxy which should be cached.</typeparam>
        /// <param name="cacheName">Unique name for the cached data.</param>
        /// <returns>Cached collection of the <typeparamref name="TDataProxy"/> or an empty collection when no data has been cached.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheName"/> is null, empty or white space.</exception>
        internal static HashSet <TDataProxy> GetCachedDataProxyCollection <TDataProxy>(string cacheName)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(cacheName, nameof(cacheName));

            lock (SyncRoot)
            {
                MemoryCache          memoryCache = MemoryCache.Default;
                HashSet <TDataProxy> cachedDataProxyCollection = memoryCache.Get(cacheName) as HashSet <TDataProxy>;
                return(cachedDataProxyCollection ?? new HashSet <TDataProxy>());
            }
        }
        /// <summary>
        /// Removes an instance of the <typeparamref name="TDataProxy"/> from the cache.
        /// </summary>
        /// <typeparam name="TDataProxy">Type of the data proxy which should be cached.</typeparam>
        /// <param name="cacheName">Unique name for the cached data.</param>
        /// <param name="dataProxy">The instance of the <typeparamref name="TDataProxy"/> which should be removed from the cache.</param>
        /// <param name="dataProxyMatch">The predicate which can match any <typeparamref name="TDataProxy"/>.</param>
        /// <param name="minutesToStore">Number of minute to store cached data.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheName"/> is null, empty or white space or when <paramref name="dataProxy"/> is null or when <paramref name="dataProxyMatch"/> is null.</exception>
        internal static void RemoveDataProxyCollectionToCache <TDataProxy>(string cacheName, TDataProxy dataProxy, Predicate <TDataProxy> dataProxyMatch, int minutesToStore = 15)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(cacheName, nameof(cacheName))
            .NotNull(dataProxy, nameof(dataProxy))
            .NotNull(dataProxyMatch, nameof(dataProxyMatch));

            lock (SyncRoot)
            {
                HashSet <TDataProxy> cachedDataProxyCollection = GetCachedDataProxyCollection <TDataProxy>(cacheName);
                cachedDataProxyCollection.RemoveWhere(dataProxyMatch);

                MemoryCache memoryCache = MemoryCache.Default;
                memoryCache.Set(cacheName, cachedDataProxyCollection, DateTimeOffset.Now.AddMinutes(minutesToStore));
            }
        }
        /// <summary>
        /// Creates a household member.
        /// </summary>
        /// <param name="mailAddress">Mail address for the household member.</param>
        /// <param name="membership">Membership.</param>
        /// <param name="membershipExpireTime">Date and time for when the membership expires.</param>
        /// <param name="activationCode">Activation code for the household member.</param>
        /// <param name="creationTime">Date and time for when the household member was created.</param>
        /// <param name="domainObjectValidations">Implementation for common validations used by domain objects in the food waste domain.</param>
        protected HouseholdMember(string mailAddress, Membership membership, DateTime?membershipExpireTime, string activationCode, DateTime creationTime, IDomainObjectValidations domainObjectValidations = null)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(mailAddress, nameof(mailAddress))
            .NotNullOrWhiteSpace(activationCode, nameof(activationCode));

            _domainObjectValidations = domainObjectValidations ?? DomainObjectValidations.Create();
            if (_domainObjectValidations.IsMailAddress(mailAddress) == false)
            {
                throw new IntranetSystemException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, mailAddress, "mailAddress"));
            }
            _mailAddress = mailAddress;

            _membership           = membership;
            _membershipExpireTime = membershipExpireTime;
            _activationCode       = activationCode;
            _creationTime         = creationTime;
        }
        /// <summary>
        /// Build a mockup for translation information.
        /// </summary>
        /// <returns>Mockup for translation information.</returns>
        public static ITranslationInfo BuildTranslationInfoMock(string cultureName)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(cultureName, nameof(cultureName));

            ITranslationInfo translationInfoMock = MockRepository.GenerateMock <ITranslationInfo>();

            translationInfoMock.Stub(m => m.Identifier)
            .Return(Guid.NewGuid())
            .Repeat.Any();
            translationInfoMock.Stub(m => m.CultureName)
            .Return(cultureName)
            .Repeat.Any();
            translationInfoMock.Stub(m => m.CultureInfo)
            .Return(new CultureInfo(cultureName))
            .Repeat.Any();
            return(translationInfoMock);
        }
        /// <summary>
        /// Gets a household member by their mail address.
        /// </summary>
        /// <param name="mailAddress">Mail address for the household member to get.</param>
        /// <returns>Household member when exists; otherwise null.</returns>
        public virtual IHouseholdMember HouseholdMemberGetByMailAddress(string mailAddress)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(mailAddress, nameof(mailAddress));

            try
            {
                MySqlCommand command = HouseholdMemberProxy.BuildHouseholdDataCommandForSelecting("WHERE MailAddress=@mailAddress", householdDataCommandBuilder => householdDataCommandBuilder.AddMailAddressParameter(mailAddress));
                return(DataProvider.GetCollection <HouseholdMemberProxy>(command).SingleOrDefault());
            }
            catch (IntranetRepositoryException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, MethodBase.GetCurrentMethod().Name, ex.Message), ex);
            }
        }
        /// <summary>
        /// Adds a data parameter to the data parameter collection.
        /// </summary>
        /// <param name="parameterName">The name of the data parameter.</param>
        /// <param name="value">The value for the data parameter.</param>
        /// <param name="dbType">The database type for the data parameter.</param>
        /// <param name="size">The size for the data parameter.</param>
        /// <param name="isNullable">Indicates whether the data parameter can be null.</param>
        private void AddDataParameter(string parameterName, object value, DbType dbType, int size = 0, bool isNullable = false)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(parameterName, nameof(parameterName));

            IDbDataParameter dataParameter = MockRepository.GenerateMock <IDbDataParameter>();

            dataParameter.Stub(m => m.ParameterName)
            .Return(parameterName)
            .Repeat.Any();
            dataParameter.Stub(m => m.Value)
            .Return(value ?? DBNull.Value)
            .Repeat.Any();
            dataParameter.Stub(m => m.DbType)
            .Return(dbType)
            .Repeat.Any();
            dataParameter.Stub(m => m.Size)
            .Return(size)
            .Repeat.Any();
            dataParameter.Stub(m => m.IsNullable)
            .Return(isNullable)
            .Repeat.Any();

            _dataParameterCollection.Add(dataParameter);
        }