Exemplo n.º 1
0
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="serviceLocator">
        /// The service locator.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The <see cref="TService"/>.
        /// </returns>
        public static TService Get <TService>([NotNull] this IServiceLocator serviceLocator)
        {
            CodeContracts.VerifyNotNull(serviceLocator, "serviceLocator");

            return((TService)serviceLocator.Get(typeof(TService)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether [is valid theme] [the specified theme].
        /// </summary>
        /// <param name="theme">The theme.</param>
        /// <returns>
        ///   <c>true</c> if [is valid theme] [the specified theme]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsValidTheme([NotNull] string theme)
        {
            CodeContracts.VerifyNotNull(theme, "theme");

            return(!theme.IsNotSet() && Directory.Exists(GetMappedThemeFile(theme)));
        }
        /// <summary>
        /// Gets the user signature.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="userId">The user identifier.</param>
        /// <returns>Returns the user points</returns>
        public static string GetSignature(this IRepository <User> repository, int userId)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.GetById(userId).Signature);
        }
Exemplo n.º 4
0
        public static DataTable SimpleListAsDataTable(this IRepository <Message> repository, [CanBeNull] int startId = 0, [CanBeNull] int limit = 500)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.message_simplelist(StartID: startId, Limit: limit));
        }
Exemplo n.º 5
0
        public static long CountAlbumImages([NotNull] this IRepository<UserAlbumImage> repository, [NotNull] int albumId)
        {
            CodeContracts.VerifyNotNull(repository);

            return repository.Count(albumImage => albumImage.AlbumID == albumId);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checks if source is in the list provided.
        /// </summary>
        /// <typeparam name="T">
        /// </typeparam>
        /// <param name="source">
        /// </param>
        /// <param name="list">
        /// </param>
        /// <returns>
        /// The is in.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source"/>
        ///     is
        ///     <c>null</c>
        ///     .
        /// </exception>
        public static bool IsIn <T>(this T source, [NotNull] params T[] list)
        {
            CodeContracts.VerifyNotNull(list, "list");

            return(list.Contains(source));
        }
Exemplo n.º 7
0
        public static ILookup <string, string> ToLookup([NotNull] this NameValueCollection collection, IEqualityComparer <string> comparer = null)
        {
            CodeContracts.VerifyNotNull(collection, "collection");

            return(collection.Cast <string>().ToLookup(key => key, key => collection[key], comparer ?? StringComparer.OrdinalIgnoreCase));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get an instance of a module (based on it's id).
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <returns>
        /// Instance of TModule or null if not found.
        /// </returns>
        public TModule GetBy([NotNull] string id)
        {
            CodeContracts.VerifyNotNull(id, "id");

            return(this._modules.SingleOrDefault(e => e.ModuleId.Equals(id)));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardModuleManager{TModule}"/> class.
        /// </summary>
        /// <param name="modules">
        /// The modules.
        /// </param>
        public StandardModuleManager([NotNull] IEnumerable <TModule> modules)
        {
            CodeContracts.VerifyNotNull(modules, "modules");

            this._modules = modules.ToList();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets the Localized Text
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <returns>
        /// The get text.
        /// </returns>
        public string GetText([NotNull] string text)
        {
            CodeContracts.VerifyNotNull(text, "text");

            return(this.GetText(this.TransPage, text));
        }
Exemplo n.º 11
0
        /// <summary>
        /// The load translation.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="CultureInfo"/>.
        /// </returns>
        public CultureInfo LoadTranslation(string fileName, HttpContext context)
        {
            CodeContracts.VerifyNotNull(fileName, "fileName");

            if (this.localizer != null)
            {
                return(this.localizer.CurrentCulture);
            }

#if !DEBUG
            if (this.localizer == null && context.Cache[$"Localizer.{fileName}"] != null)
            {
                this.localizer = (Localizer)context.Cache[
                    $"Localizer.{fileName}"];
            }
#endif
            if (this.localizer == null)
            {
                this.localizer =
                    new Localizer(
                        context.Server.MapPath($"{BoardInfo.ForumServerFileRoot}languages/{fileName}"));

#if !DEBUG
                context.Cache[$"Localizer.{fileName}"] = this.localizer;
#endif
            }

            // If not using default language load that too
            if (fileName.ToLower() != "english.xml")
            {
#if !DEBUG
                if (this.defaultLocale == null && context.Cache["DefaultLocale"] != null)
                {
                    this.defaultLocale = (Localizer)context.Cache["DefaultLocale"];
                }
#endif

                if (this.defaultLocale == null)
                {
                    this.defaultLocale =
                        new Localizer(
                            context.Server.MapPath(
                                $"{BoardInfo.ForumServerFileRoot}languages/english.xml"));
#if !DEBUG
                    context.Cache["DefaultLocale"] = this.defaultLocale;
#endif
                }
            }

            try
            {
                // try to load culture info defined in localization file
                this.culture = this.localizer.CurrentCulture;
            }
            catch
            {
                // if it's wrong, fall back to current culture
                this.culture = CultureInfo.CurrentCulture;
            }

            this.LanguageFileName = fileName.ToLower();

            return(this.culture);
        }
Exemplo n.º 12
0
        /// <summary>
        /// The listforum.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="forumID">
        /// The forum id.
        /// </param>
        /// <param name="styledNicks">
        /// The styled nicks.
        /// </param>
        /// <returns>
        /// The <see cref="DataTable"/> .
        /// </returns>
        public static DataTable ListForum(this IRepository <Active> repository, int forumID, bool styledNicks)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.active_listforum(ForumID: forumID, StyledNicks: styledNicks));
        }
Exemplo n.º 13
0
        /// <summary>
        /// The updatemaxstats.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="boardId">
        /// The board Id.
        /// </param>
        /// <returns>
        /// The <see cref="DataTable"/> .
        /// </returns>
        public static DataTable UpdateMaxStats(this IRepository <Active> repository, int?boardId = null)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.active_updatemaxstats(BoardID: boardId ?? repository.BoardID, UTCTIMESTAMP: DateTime.UtcNow));
        }
Exemplo n.º 14
0
        /// <summary>
        /// The stats.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="boardId">
        /// The board Id.
        /// </param>
        /// <returns>
        /// The <see cref="DataTable"/> .
        /// </returns>
        public static DataRow Stats(this IRepository <Active> repository, int?boardId = null)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(((DataTable)repository.DbFunction.GetData.active_stats(BoardID: boardId ?? repository.BoardID)).Rows[0]);
        }
        public static DataTable RankStyle(this IRepository <Group> repository, int?boardId = null)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.group_rank_style(BoardID: boardId ?? repository.BoardID));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the topic image.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="imgTitle">The image title.</param>
        /// <returns>
        /// Returns the Topic Image
        /// </returns>
        protected string GetTopicImage([NotNull] DataRowView row, [NotNull] ref string imgTitle)
        {
            CodeContracts.VerifyNotNull(row, "row");
            CodeContracts.VerifyNotNull(imgTitle, "imgTitle");

            DateTime lastPosted = row["LastPosted"] != DBNull.Value
                                      ? (DateTime)row["LastPosted"]
                                      : DateTimeHelper.SqlDbMinTime();

            var topicFlags = new TopicFlags(row["TopicFlags"]);
            var forumFlags = new ForumFlags(row["ForumFlags"]);

            var isHot = this.IsPopularTopic(lastPosted, row);
            var theme = this.Get <ITheme>();

            if (row["TopicMovedID"].ToString().Length > 0)
            {
                imgTitle = this.GetText("MOVED");
                return(theme.GetItem("ICONS", "TOPIC_MOVED"));
            }

            DateTime lastRead = this.Get <IReadTrackCurrentUser>()
                                .GetForumTopicRead(
                row["ForumID"].ToType <int>(),
                row["TopicID"].ToType <int>(),
                row["LastForumAccess"].IsNullOrEmptyDBField()
                        ? DateTimeHelper.SqlDbMinTime()
                        : row["LastForumAccess"].ToType <DateTime?>(),
                row["LastTopicAccess"].IsNullOrEmptyDBField()
                        ? DateTimeHelper.SqlDbMinTime()
                        : row["LastForumAccess"].ToType <DateTime?>());

            if (lastPosted > lastRead)
            {
                this.Get <IYafSession>().UnreadTopics++;

                if (row["PollID"] != DBNull.Value)
                {
                    imgTitle = this.GetText("POLL_NEW");
                    return(theme.GetItem("ICONS", "TOPIC_POLL_NEW"));
                }

                switch (row["Priority"].ToString())
                {
                case "1":
                    imgTitle = this.GetText("STICKY_NEW");
                    return(theme.GetItem("ICONS", "TOPIC_STICKY_NEW"));

                case "2":
                    imgTitle = this.GetText("ANNOUNCEMENT");
                    return(theme.GetItem("ICONS", "TOPIC_ANNOUNCEMENT_NEW"));

                default:
                    if (topicFlags.IsLocked || forumFlags.IsLocked)
                    {
                        imgTitle = this.GetText("NEW_POSTS_LOCKED");
                        return(theme.GetItem("ICONS", "TOPIC_NEW_LOCKED"));
                    }

                    if (isHot)
                    {
                        imgTitle = this.GetText("ICONLEGEND", "HOT_NEW_POSTS");
                        return(theme.GetItem("ICONS", "TOPIC_HOT_NEW", theme.GetItem("ICONS", "TOPIC_NEW")));
                    }

                    imgTitle = this.GetText("ICONLEGEND", "NEW_POSTS");
                    return(theme.GetItem("ICONS", "TOPIC_NEW"));
                }
            }

            if (row["PollID"] != DBNull.Value)
            {
                imgTitle = this.GetText("POLL");
                return(theme.GetItem("ICONS", "TOPIC_POLL"));
            }

            switch (row["Priority"].ToString())
            {
            case "1":
                imgTitle = this.GetText("STICKY");
                return(theme.GetItem("ICONS", "TOPIC_STICKY"));

            case "2":
                imgTitle = this.GetText("ANNOUNCEMENT");
                return(theme.GetItem("ICONS", "TOPIC_ANNOUNCEMENT"));

            default:
                if (topicFlags.IsLocked || forumFlags.IsLocked)
                {
                    imgTitle = this.GetText("NO_NEW_POSTS_LOCKED");
                    return(theme.GetItem("ICONS", "TOPIC_LOCKED"));
                }

                if (isHot)
                {
                    imgTitle = this.GetText("HOT_NO_NEW_POSTS");
                    return(theme.GetItem("ICONS", "TOPIC_HOT", theme.GetItem("ICONS", "TOPIC")));
                }

                imgTitle = this.GetText("NO_NEW_POSTS");
                return(theme.GetItem("ICONS", "TOPIC"));
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// The get attribute.
        /// </summary>
        /// <typeparam name="TAttribute">The type of the attribute.</typeparam>
        /// <param name="objectType">The object type.</param>
        /// <returns>
        /// The <see cref="TAttribute" />.
        /// </returns>
        public static TAttribute GetAttribute <TAttribute>([NotNull] this Type objectType) where TAttribute : Attribute
        {
            CodeContracts.VerifyNotNull(objectType, "objectType");

            return(objectType.GetCustomAttributes(typeof(TAttribute), false).OfType <TAttribute>().FirstOrDefault());
        }
        /// <summary>
        /// Fast index of.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="pattern">The pattern.</param>
        /// <returns>
        /// The fast index of.
        /// </returns>
        public static int FastIndexOf([NotNull] this string source, [NotNull] string pattern)
        {
            CodeContracts.VerifyNotNull(source, "source");
            CodeContracts.VerifyNotNull(pattern, "pattern");

            if (pattern.Length == 0)
            {
                return(0);
            }

            if (pattern.Length == 1)
            {
                return(source.IndexOf(pattern[0]));
            }

            int limit = source.Length - pattern.Length + 1;

            if (limit < 1)
            {
                return(-1);
            }

            // Store the first 2 characters of "pattern"
            char c0 = pattern[0];
            char c1 = pattern[1];

            // Find the first occurrence of the first character
            int first = source.IndexOf(c0, 0, limit);

            while (first != -1)
            {
                // Check if the following character is the same like
                // the 2nd character of "pattern"
                if (source[first + 1] != c1)
                {
                    first = source.IndexOf(c0, ++first, limit - first);
                    continue;
                }

                // Check the rest of "pattern" (starting with the 3rd character)
                bool found = true;
                for (int j = 2; j < pattern.Length; j++)
                {
                    if (source[first + j] == pattern[j])
                    {
                        continue;
                    }

                    found = false;
                    break;
                }

                // If the whole word was found, return its index, otherwise try again
                if (found)
                {
                    return(first);
                }

                first = source.IndexOf(c0, ++first, limit - first);
            }

            return(-1);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Turns any object into a Dictionary
        /// </summary>
        /// <param name="thingy">
        /// The thingy.
        /// </param>
        /// <returns>
        /// The <see cref="IDictionary"/>.
        /// </returns>
        public static IDictionary <string, object> AnyToDictionary([NotNull] this object thingy)
        {
            CodeContracts.VerifyNotNull(thingy, "thingy");

            return((IDictionary <string, object>)thingy.ToExpando());
        }
        public static List <string> GetNewNoEmptyStrings([NotNull] this IEnumerable <string> inputList)
        {
            CodeContracts.VerifyNotNull(inputList, "inputList");

            return(inputList.Where(x => x.IsSet()).ToList());
        }
Exemplo n.º 21
0
        /// <summary>
        /// Approves the message.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="messageId">The message identifier.</param>
        public static void ApproveMessage(this IRepository <Message> repository, int messageId)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            repository.DbFunction.Query.message_approve(MessageID: messageId);
        }
        public static List <string> GetNewNoSmallStrings([NotNull] this IEnumerable <string> inputList, int minSize)
        {
            CodeContracts.VerifyNotNull(inputList, "inputList");

            return(inputList.Where(x => x.Length >= minSize).ToList());
        }
Exemplo n.º 23
0
        /// <summary>
        /// Increments the image's download times.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="imageId">The image identifier.</param>
        public static void IncrementDownload(this IRepository<UserAlbumImage> repository, [NotNull] int imageId)
        {
            CodeContracts.VerifyNotNull(repository);

            repository.UpdateAdd(() => new UserAlbumImage { Downloads = 1 }, u => u.ID == imageId);
        }
        public static long CountUserAlbum([NotNull] this IRepository <UserAlbum> repository, [NotNull] int userId)
        {
            CodeContracts.VerifyNotNull(repository);

            return(repository.Count(album => album.UserID == userId));
        }
Exemplo n.º 25
0
        /// <summary>
        /// The list.
        /// </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="DataTable"/> .
        /// </returns>
        public static DataTable List(this IRepository <BBCode> repository, int?bBCodeID = null, int?boardId = null)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.bbcode_list(BoardID: boardId ?? repository.BoardID, BBCodeID: bBCodeID));
        }
        public static DataTable List(this IRepository <Group> repository, int?groupID = null, int?boardId = null)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.group_list(BoardID: boardId ?? repository.BoardID, GroupID: groupID));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Gets full path to the given theme file.
        /// </summary>
        /// <param name="filename">
        /// Short name of theme file.
        /// </param>
        /// <returns>
        /// The build theme path.
        /// </returns>
        public string BuildThemePath([NotNull] string filename)
        {
            CodeContracts.VerifyNotNull(filename, "filename");

            return(YafForumInfo.GetURLToContentThemes(Path.Combine(this.Theme, filename)));
        }
        public static DataTable Member(this IRepository <Group> repository, int userID, int?boardId = null)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.group_member(BoardID: boardId ?? repository.BoardID, UserID: userID));
        }
        /// <summary>
        /// Gets the user points.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="userId">The user identifier.</param>
        /// <returns>Returns the user points</returns>
        public static int GetPoints(this IRepository <User> repository, int userId)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.GetById(userId).Points);
        }
Exemplo n.º 30
0
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="haveLocator">
        /// The have locator.
        /// </param>
        /// <param name="instance">
        /// The instance.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The try get.
        /// </returns>
        public static bool TryGet <TService>([NotNull] this IHaveServiceLocator haveLocator, out TService instance)
        {
            CodeContracts.VerifyNotNull(haveLocator, "haveLocator");

            return(haveLocator.ServiceLocator.TryGet(out instance));
        }