Esempio n. 1
0
        /// <summary>
        /// The rollback.
        /// </summary>
        /// <param name="dbFunctionSession">
        /// The db function session.
        /// </param>
        public static void Rollback([NotNull] this IDbFunctionSession dbFunctionSession)
        {
            CodeContracts.ArgumentNotNull(dbFunctionSession, "dbFunctionSession");

            if (dbFunctionSession.DbTransaction != null)
            {
                dbFunctionSession.DbTransaction.Rollback();
            }
        }
Esempio n. 2
0
        private static IEnumerable <Control> ControlListNoParents([NotNull] this Control sourceControl, [NotNull] Func <Control, bool> isControl)
        {
            CodeContracts.ArgumentNotNull(sourceControl, "sourceControl");
            CodeContracts.ArgumentNotNull(isControl, "isControl");

            return((from c in sourceControl.Controls.Cast <Control>().AsQueryable()
                    where !c.HasControls()
                    select c).Where(isControl).ToList());
        }
Esempio n. 3
0
        /// <summary>
        /// The count.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="topicId">
        /// The topic id.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public static int Count(this IRepository <FavoriteTopic> repository, int topicId)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            return
                (repository.DbAccess.Execute(
                     cmd =>
                     cmd.GetScalar <int>("SELECT COUNT(*) FROM " + repository.DbAccess.GetTableName <FavoriteTopic>() + "  WHERE topicId = {0}", topicId)));
        }
Esempio n. 4
0
        /// <summary>
        /// The get as bool.
        /// </summary>
        /// <param name="readValue">
        /// The read value.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="defaultValue">
        /// The default value.
        /// </param>
        /// <returns>
        /// The get as bool.
        /// </returns>
        public static bool GetAsBool([NotNull] this IReadValue <string> readValue, [NotNull] string key, bool defaultValue)
        {
            CodeContracts.ArgumentNotNull(readValue, "readValue");
            CodeContracts.ArgumentNotNull(key, "key");

            var value = readValue.Get(key);

            return(Equals(value, null) ? defaultValue : Convert.ToBoolean(value.ToLower()));
        }
Esempio n. 5
0
        /// <summary>
        /// Gets a value with a default value...
        /// </summary>
        /// <param name="readValue">
        /// </param>
        /// <param name="key">
        /// </param>
        /// <param name="defaultValue"></param>
        /// <typeparam name="T">
        /// </typeparam>
        /// <returns>
        /// </returns>
        public static T Get <T>([NotNull] this IReadValue <T> readValue, [NotNull] string key, [CanBeNull] T defaultValue)
        {
            CodeContracts.ArgumentNotNull(readValue, "readValue");
            CodeContracts.ArgumentNotNull(key, "key");

            var value = readValue.Get(key);

            return(Equals(value, default(T)) ? defaultValue : value);
        }
Esempio n. 6
0
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="userID">
        /// The user id.
        /// </param>
        /// <param name="hash">
        /// The hash.
        /// </param>
        /// <param name="email">
        /// The email.
        /// </param>
        public static void Save(this IRepository <CheckEmail> repository, int?userID, [NotNull] string hash, [NotNull] string email)
        {
            CodeContracts.ArgumentNotNull(hash, "hash");
            CodeContracts.ArgumentNotNull(email, "email");
            CodeContracts.ArgumentNotNull(repository, "repository");

            repository.DbFunction.Query.checkemail_save(UserID: userID, Hash: hash, Email: email.ToLower(), UTCTIMESTAMP: DateTime.UtcNow);
            repository.FireNew();
        }
        /// <summary>
        /// The start.
        /// </summary>
        /// <param name="taskModuleManager">
        /// The task module manager.
        /// </param>
        /// <param name="createTask">
        /// The create task.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        /// <returns>
        /// The start.
        /// </returns>
        public static bool Start <T>([NotNull] this ITaskModuleManager taskModuleManager, [NotNull] Func <T> createTask) where T : IBackgroundTask
        {
            CodeContracts.ArgumentNotNull(taskModuleManager, "taskModuleManager");
            CodeContracts.ArgumentNotNull(createTask, "createTask");

            string taskName = typeof(T).ToString();

            return(taskModuleManager.StartTask(taskName, () => createTask()));
        }
        /// <summary>
        /// The remote all.
        /// </summary>
        /// <param name="objectStore">
        /// The object store.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        public static void RemoveOf <T>([NotNull] this IObjectStore objectStore)
        {
            CodeContracts.ArgumentNotNull(objectStore, "objectStore");

            foreach (var i in objectStore.GetAll <T>().ToList())
            {
                objectStore.Remove(i.Key);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// The list typed.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="bBCodeID">
        /// The b b code id.
        /// </param>
        /// <param name="boardId">
        /// The board id.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        public static IList <BBCode> ListTyped(this IRepository <BBCode> repository, int?bBCodeID = null, int?boardId = null)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            using (var session = repository.DbFunction.CreateSession())
            {
                return(session.GetTyped <BBCode>(r => r.bbcode_list(BoardID: boardId ?? repository.BoardID, BBCodeID: bBCodeID)));
            }
        }
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="haveLocator">
        /// The have locator.
        /// </param>
        /// <param name="named">
        /// The named.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The <see cref="TService"/>.
        /// </returns>
        public static TService Get <TService>(
            [NotNull] this IHaveServiceLocator haveLocator, [NotNull] string named, [NotNull] IEnumerable <IServiceLocationParameter> parameters)
        {
            CodeContracts.ArgumentNotNull(haveLocator, "haveLocator");
            CodeContracts.ArgumentNotNull(named, "named");
            CodeContracts.ArgumentNotNull(parameters, "parameters");

            return(haveLocator.ServiceLocator.Get <TService>(named, parameters));
        }
Esempio n. 11
0
        public static IScriptStatementContext Add(
            [NotNull] this IScriptStatementContext scriptStatement, [NotNull] string js)
        {
            CodeContracts.ArgumentNotNull(scriptStatement, "scriptStatement");
            CodeContracts.ArgumentNotNull(js, "js");

            scriptStatement.ScriptStatement.Add(js);
            return(scriptStatement);
        }
Esempio n. 12
0
        /// <summary>
        /// Uses the pager to convert the list into a properly skipped and paged list.
        /// </summary>
        /// <param name="list">
        /// The enumerable.
        /// </param>
        /// <param name="pager">
        /// The pager.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        /// <returns>
        /// The <see cref="IEnumerable{T}"/>.
        /// </returns>
        public static IList <T> GetPaged <T>([NotNull] this IList <T> list, [NotNull] IPager pager)
        {
            CodeContracts.ArgumentNotNull(list, "list");
            CodeContracts.ArgumentNotNull(pager, "pager");

            pager.Count = list.Count;

            return(list.Skip(pager.SkipIndex()).Take(pager.PageSize).ToList());
        }
Esempio n. 13
0
        public static IScriptStatementContext AddSelectorFormat(
            [NotNull] this IScriptStatementContext scriptStatement, [NotNull] string selector, [NotNull] params object[] args)
        {
            CodeContracts.ArgumentNotNull(scriptStatement, "scriptStatement");
            CodeContracts.ArgumentNotNull(selector, "selector");
            CodeContracts.ArgumentNotNull(args, "args");

            return(scriptStatement.AddFormat(@"$$$({0})", selector.FormatWith(args)));
        }
Esempio n. 14
0
        /// <summary>
        /// The list typed.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="email">
        /// The email.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        public static IList <CheckEmail> ListTyped(this IRepository <CheckEmail> repository, string email = null)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            using (var session = repository.DbFunction.CreateSession())
            {
                return(session.GetTyped <CheckEmail>(r => r.repository.DbFunction.GetData.checkemail_list(Email: email)));
            }
        }
        public static IList <WatchTopic> ListTyped(this IRepository <WatchTopic> repository, int userID)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            using (var session = repository.DbFunction.CreateSession())
            {
                return(session.GetTyped <WatchTopic>(r => r.watchtopic_list(UserID: userID)));
            }
        }
Esempio n. 16
0
        /// <summary>
        /// The list typed.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="extension">
        /// The extension.
        /// </param>
        /// <param name="boardId">
        /// The board id.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        public static IList <FileExtension> ListTyped(this IRepository <FileExtension> repository, string extension = null, int?boardId = null)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            using (var functionSession = repository.DbFunction.CreateSession())
            {
                return(functionSession.GetTyped <FileExtension>(r => r.extension_list(BoardID: boardId ?? repository.BoardID, Extension: extension)));
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Gets the mapped theme file.
        /// </summary>
        /// <param name="themeFile">The theme file.</param>
        /// <returns>
        /// The get mapped theme file.
        /// </returns>
        private static string GetMappedThemeFile([NotNull] string themeFile)
        {
            CodeContracts.ArgumentNotNull(themeFile, "themeFile");

            return
                (HttpContext.Current.Server.MapPath(
                     string.Concat(
                         YafForumInfo.ForumServerFileRoot, YafBoardFolders.Current.Themes, "/", themeFile.Trim())));
        }
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="serviceLocator">
        /// The service locator.
        /// </param>
        /// <param name="named">
        /// The named.
        /// </param>
        /// <param name="parameters">
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The <see cref="TService"/>.
        /// </returns>
        public static TService Get <TService>(
            [NotNull] this IServiceLocator serviceLocator, [NotNull] string named, [NotNull] IEnumerable <IServiceLocationParameter> parameters)
        {
            CodeContracts.ArgumentNotNull(serviceLocator, "serviceLocator");
            CodeContracts.ArgumentNotNull(named, "named");
            CodeContracts.ArgumentNotNull(parameters, "parameters");

            return((TService)serviceLocator.Get(typeof(TService), named, parameters));
        }
Esempio n. 19
0
        /// <summary>
        /// Gets a text localization using the page and tag name.
        /// </summary>
        /// <param name="haveLocalization">
        /// The have localization.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="tag">
        /// The tag.
        /// </param>
        /// <returns>
        /// The get text.
        /// </returns>
        public static string GetText(
            [NotNull] this IHaveLocalization haveLocalization, [NotNull] string page, [NotNull] string tag)
        {
            CodeContracts.ArgumentNotNull(haveLocalization, "haveLocalization");
            CodeContracts.ArgumentNotNull(page, "page");
            CodeContracts.ArgumentNotNull(tag, "tag");

            return(haveLocalization.Localization.GetText(page, tag));
        }
Esempio n. 20
0
        protected IEnumerable <SearchCondition> BuildWhoConditions(
            [NotNull] string toSearchFromWho, SearchWhatFlags searchFromWhoMethod, bool searchDisplayName)
        {
            CodeContracts.ArgumentNotNull(toSearchFromWho, "toSearchFromWho");

            toSearchFromWho = toSearchFromWho.Replace("'", "''").Trim();

            var    conditions   = new List <SearchCondition>();
            string conditionSql = string.Empty;

            SearchConditionType conditionType = SearchConditionType.AND;

            if (searchFromWhoMethod == SearchWhatFlags.AnyWords)
            {
                conditionType = SearchConditionType.OR;
            }

            var wordList = new List <string> {
                toSearchFromWho
            };

            if (searchFromWhoMethod == SearchWhatFlags.AllWords || searchFromWhoMethod == SearchWhatFlags.AnyWords)
            {
                wordList =
                    toSearchFromWho.Replace(@"""", string.Empty).Split(' ').Where(x => x.IsSet()).Select(x => x.Trim()).ToList();
            }

            foreach (string word in wordList)
            {
                int userId;

                if (int.TryParse(word, out userId))
                {
                    conditionSql = "c.UserID IN ({0})".FormatWith(userId);
                }
                else
                {
                    if (searchFromWhoMethod == SearchWhatFlags.ExactMatch)
                    {
                        conditionSql = "(c.Username IS NULL AND b.{1} = N'{0}') OR (c.Username = N'{0}')".FormatWith(
                            word, searchDisplayName ? "DisplayName" : "Name");
                    }
                    else
                    {
                        conditionSql = "(c.Username IS NULL AND b.{1} LIKE N'%{0}%') OR (c.Username LIKE N'%{0}%')".FormatWith(
                            word, searchDisplayName ? "DisplayName" : "Name");
                    }
                }

                conditions.Add(new SearchCondition {
                    Condition = conditionSql, ConditionType = conditionType
                });
            }

            return(conditions);
        }
Esempio n. 21
0
        /// <summary>
        /// The load.
        /// </summary>
        /// <param name="builder">
        /// The builder.
        /// </param>
        protected void Load([NotNull] ContainerBuilder builder)
        {
            CodeContracts.ArgumentNotNull(builder, "builder");

            if (!this.IsRegistered <ILoggerProvider>())
            {
                builder.RegisterType <YafDbLoggerProvider>().As <ILoggerProvider>().SingleInstance();
                builder.Register(c => c.Resolve <ILoggerProvider>().Create(null)).SingleInstance();
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Extension method for adding in a bunch of parameters
        /// </summary>
        /// <param name="cmd">
        /// The cmd.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        public static void AddParams([NotNull] this DbCommand cmd, [NotNull] params object[] args)
        {
            CodeContracts.ArgumentNotNull(cmd, "cmd");
            CodeContracts.ArgumentNotNull(args, "args");

            foreach (var item in args)
            {
                AddParam(cmd, item);
            }
        }
Esempio n. 23
0
        public static DataTable GetMessages(
            this IRepository <ShoutboxMessage> repository, int numberOfMessages, bool styledNicks, int?boardId = null)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            return(repository.DbFunction.GetData.shoutbox_getmessages(
                       BoardId: boardId ?? repository.BoardID,
                       NumberOfMessages: numberOfMessages,
                       StyledNicks: styledNicks));
        }
        /// <summary>
        /// Save Updated Mail
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="mailMessage">The mail message.</param>
        public static void Save(
            this IRepository <Mail> repository, Mail mailMessage)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            repository.DbFunction.Scalar.mail_save(
                MailID: mailMessage.ID, SendTries: mailMessage.SendTries, SendAttempt: DateTime.UtcNow);

            repository.FireUpdated(mailMessage.ID);
        }
        /// <summary>
        /// The list typed.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="processID">
        /// The process id.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        public static IList <Mail> ListTyped(this IRepository <Mail> repository, int?processID)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            using (var session = repository.DbFunction.CreateSession())
            {
                return(session.GetTyped <Mail>(
                           r => r.mail_list(ProcessID: processID, UTCTIMESTAMP: DateTime.UtcNow)));
            }
        }
Esempio n. 26
0
        public static IEnumerable <T> GetDataTyped <T>(
            [NotNull] this IDbFunction dbFunction,
            [NotNull] Func <object, object> function,
            [CanBeNull] IEqualityComparer <string> comparer = null) where T : IDataLoadable, new()
        {
            CodeContracts.ArgumentNotNull(dbFunction, "dbFunction");
            CodeContracts.ArgumentNotNull(function, "function");

            return(dbFunction.GetData(function).Typed <T>(comparer));
        }
Esempio n. 27
0
        /// <summary>
        /// The list typed.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="boardID">
        /// The board id.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        public static IList <Board> ListTyped(this IRepository <Board> repository, int?boardID = null)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            return(boardID.HasValue
                ? new List <Board> {
                repository.GetByID(boardID.Value)
            }
                : repository.DbAccess.Execute(cmd => cmd.Select <Board>()));
        }
Esempio n. 28
0
        public static DbConnection CreateConnection([NotNull] this IDbAccessV2 dbAccess)
        {
            CodeContracts.ArgumentNotNull(dbAccess, "dbAccess");

            var connection = dbAccess.DbProviderFactory.CreateConnection();

            connection.ConnectionString = dbAccess.ConnectionString;

            return(connection);
        }
Esempio n. 29
0
        /// <summary>
        /// Does an action for each character in the input string. Kind of useless, but in a
        ///   useful way. ;)
        /// </summary>
        /// <param name="input">
        /// </param>
        /// <param name="forEachAction">
        /// </param>
        public static void ForEachChar([NotNull] this string input, [NotNull] Action <char> forEachAction)
        {
            CodeContracts.ArgumentNotNull(input, "input");
            CodeContracts.ArgumentNotNull(forEachAction, "forEachAction");

            foreach (char c in input)
            {
                forEachAction(c);
            }
        }
        /// <summary>
        /// A list of Medals.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="medalID">
        /// The medal id.
        /// </param>
        /// <param name="category">
        /// The category.
        /// </param>
        /// <param name="boardId">
        /// The board id.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        public static IList <Medal> ListTyped(this IRepository <Medal> repository, int?medalID = null, string category = null, int?boardId = null)
        {
            CodeContracts.ArgumentNotNull(repository, "repository");

            using (var functionSession = repository.DbFunction.CreateSession())
            {
                return(functionSession.GetTyped <Medal>(
                           r => r.medal_list(BoardID: boardId ?? repository.BoardID, MedalID: medalID, Category: category)));
            }
        }