当前位置: 首页>>代码示例>>C#>>正文


C# QueryBuilder.SelectFrom方法代码示例

本文整理汇总了C#中ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder.SelectFrom方法的典型用法代码示例。如果您正苦于以下问题:C# QueryBuilder.SelectFrom方法的具体用法?C# QueryBuilder.SelectFrom怎么用?C# QueryBuilder.SelectFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder.SelectFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOutgoingLinks

        /// <summary>
        /// Gets the outgoing links of a page.
        /// </summary>
        /// <param name="page">The full name of the page.</param>
        /// <returns>The outgoing links.</returns>
        /// <exception cref="ArgumentNullException">If <b>page</b> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <b>page</b> is empty.</exception>
        public string[] GetOutgoingLinks(string page)
        {
            if(page == null) throw new ArgumentNullException("page");
            if(page.Length == 0) throw new ArgumentException("Page cannot be empty", "page");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("OutgoingLink", new string[] { "Destination" });
            query = queryBuilder.Where(query, "Source", WhereOperator.Equals, "Source");
            query = queryBuilder.OrderBy(query, new[] { "Destination" }, new[] { Ordering.Asc });

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Source", page));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<string> result = new List<string>(20);

                while(reader.Read()) {
                    result.Add(reader["Destination"] as string);
                }

                CloseReader(command, reader);

                return result.ToArray();
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:39,代码来源:SqlSettingsStorageProviderBase.cs

示例2: GetPageAttachmentDetails

        /// <summary>
        /// Gets the details of a page attachment.
        /// </summary>
        /// <param name="pageInfo">The page that owns the attachment.</param>
        /// <param name="name">The name of the attachment, for example "myfile.jpg".</param>
        /// <returns>The details of the attachment, or <c>null</c> if the attachment does not exist.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="pageInfo"/> or <paramref name="name"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception>
        public FileDetails GetPageAttachmentDetails(PageInfo pageInfo, string name)
        {
            if(pageInfo == null) throw new ArgumentNullException("pageInfo");
            if(name == null) throw new ArgumentNullException("name");
            if(name.Length == 0) throw new ArgumentException("Name cannot be empty");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("Attachment", new string[] { "Size", "Downloads", "LastModified" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");
            query = queryBuilder.AndWhere(query, "Page", WhereOperator.Equals, "Page");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Name", name));
            parameters.Add(new Parameter(ParameterType.String, "Page", pageInfo.FullName));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                FileDetails details = null;

                if(reader.Read()) {
                    details = new FileDetails((long)reader["Size"],
                        (DateTime)reader["LastModified"], (int)reader["Downloads"]);
                }

                CloseReader(command, reader);

                return details;
            }
            else return null;
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:43,代码来源:SqlFilesStorageProviderBase.cs

示例3: ListFiles

        /// <summary>
        /// Lists the Files in the specified Directory.
        /// </summary>
        /// <param name="directory">The full directory name, for example "/my/directory". Null, empty or "/" for the root directory.</param>
        /// <returns>The list of Files in the directory.</returns>
        /// <exception cref="ArgumentException">If <paramref name="directory"/> does not exist.</exception>
        public string[] ListFiles(string directory)
        {
            directory = PrepareDirectory(directory);

            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);

            if(!DirectoryExists(connection, directory)) {
                CloseConnection(connection);
                throw new ArgumentException("Directory does not exist", "directory");
            }

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("File", new string[] { "Name" });
            query = queryBuilder.Where(query, "Directory", WhereOperator.Equals, "Directory");
            query = queryBuilder.OrderBy(query, new [] { "Name" }, new[] { Ordering.Asc });

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Directory", directory));

            DbCommand command = builder.GetCommand(connection, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<string> result = new List<string>(20);

                while(reader.Read()) {
                    result.Add(directory + reader["Name"] as string);
                }

                CloseReader(command, reader);

                return result.ToArray();
            }
            else return null;
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:44,代码来源:SqlFilesStorageProviderBase.cs

示例4: GetNavigationPaths

        /// <summary>
        /// Gets all the Navigation Paths in a Namespace.
        /// </summary>
        /// <param name="nspace">The Namespace.</param>
        /// <returns>All the Navigation Paths, sorted by name.</returns>
        public NavigationPath[] GetNavigationPaths(NamespaceInfo nspace)
        {
            string nspaceName = nspace != null ? nspace.Name : "";

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("NavigationPath", new string[] { "Name", "Namespace", "Page" });
            query = queryBuilder.Where(query, "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.OrderBy(query, new string[] { "Namespace", "Name", "Number" }, new Ordering[] { Ordering.Asc, Ordering.Asc, Ordering.Asc });

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspaceName));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<NavigationPath> result = new List<NavigationPath>(10);

                string prevName = "|||";
                string name;
                string actualNamespace = "";
                List<string> pages = new List<string>(10);

                while(reader.Read()) {
                    name = reader["Name"] as string;

                    if(name != prevName) {
                        actualNamespace = reader["Namespace"] as string;

                        if(prevName != "|||") {
                            result[result.Count - 1].Pages = pages.ToArray();
                            pages.Clear();
                        }

                        result.Add(new NavigationPath(NameTools.GetFullName(actualNamespace, name), this));
                    }

                    prevName = name;
                    pages.Add(NameTools.GetFullName(actualNamespace, reader["Page"] as string));
                }

                if(result.Count > 0) {
                    result[result.Count - 1].Pages = pages.ToArray();
                }

                CloseReader(command, reader);

                return result.ToArray();
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:59,代码来源:SqlPagesStorageProviderBase.cs

示例5: ListPageAttachments

        /// <summary>
        /// Returns the names of the Attachments of a Page.
        /// </summary>
        /// <param name="connection">A database connection.</param>
        /// <param name="pageInfo">The Page Info object that owns the Attachments.</param>
        /// <returns>The names, or an empty list.</returns>
        private string[] ListPageAttachments(DbConnection connection, PageInfo pageInfo)
        {
            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("Attachment", new string[] { "Name" });
            query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Page", pageInfo.FullName));
            query = queryBuilder.OrderBy(query, new[] { "Name" }, new[] { Ordering.Asc });

            DbCommand command = builder.GetCommand(connection, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<string> result = new List<string>(10);

                while(reader.Read()) {
                    result.Add(reader["Name"] as string);
                }

                CloseReader(reader);

                return result.ToArray();
            }
            else return null;
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:35,代码来源:SqlFilesStorageProviderBase.cs

示例6: SaveDataForDocument

        /// <summary>
        /// Saves data for a new document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="content">The content words.</param>
        /// <param name="title">The title words.</param>
        /// <param name="keywords">The keywords.</param>
        /// <param name="state">A state object passed from the index (can be <c>null</c> or a <see cref="T:DbTransaction" />).</param>
        /// <returns>The number of stored occurrences.</returns>
        private int SaveDataForDocument(IDocument document, WordInfo[] content, WordInfo[] title, WordInfo[] keywords, object state)
        {
            // 1. Insert document
            // 2. Insert all new words
            // 3. Load all word IDs
            // 4. Insert mappings

            // On error, return without rolling back if state != null, rollback otherwise
            // On completion, commit if state == null

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            DbTransaction transaction = null;
            if(state != null) transaction = (DbTransaction)state;
            else {
                DbConnection connection = builder.GetConnection(connString);
                transaction = BeginTransaction(connection);
            }

            uint freeDocumentId = GetFreeElementId(IndexElementType.Documents, transaction);
            uint freeWordId = GetFreeElementId(IndexElementType.Words, transaction);

            // Insert the document
            string query = queryBuilder.InsertInto("IndexDocument",
                new string[] { "Id", "Name", "Title", "TypeTag", "DateTime" },
                new string[] { "Id", "Name", "Title", "TypeTag", "DateTime" });

            List<Parameter> parameters = new List<Parameter>(5);
            parameters.Add(new Parameter(ParameterType.Int32, "Id", (int)freeDocumentId));
            parameters.Add(new Parameter(ParameterType.String, "Name", document.Name));
            parameters.Add(new Parameter(ParameterType.String, "Title", document.Title));
            parameters.Add(new Parameter(ParameterType.String, "TypeTag", document.TypeTag));
            parameters.Add(new Parameter(ParameterType.DateTime, "DateTime", document.DateTime));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            if(ExecuteNonQuery(command, false) != 1) {
                if(state == null) RollbackTransaction(transaction);
                return -1;
            }
            document.ID = freeDocumentId;

            List<WordInfo> allWords = new List<WordInfo>(content.Length + title.Length + keywords.Length);
            allWords.AddRange(content);
            allWords.AddRange(title);
            allWords.AddRange(keywords);

            List<WordInfo> existingWords = new List<WordInfo>(allWords.Count / 2);

            Dictionary<string, uint> wordIds = new Dictionary<string, uint>(1024);

            // Try to blindly insert all words (assumed to be lowercase and clean from diacritics)

            query = queryBuilder.InsertInto("IndexWord", new string[] { "Id", "Text" }, new string[] { "Id", "Text" });

            parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.Int32, "Id", 0));
            parameters.Add(new Parameter(ParameterType.String, "Text", ""));

            foreach(WordInfo word in allWords) {
                parameters[0].Value = (int)freeWordId;
                parameters[1].Value = word.Text;

                command = builder.GetCommand(transaction, query, parameters);

                if(ExecuteNonQuery(command, false, false) == 1) {
                    wordIds.Add(word.Text, freeWordId);
                    freeWordId++;
                }
                else {
                    existingWords.Add(word);
                }
            }

            // Load IDs of all existing words
            query = queryBuilder.SelectFrom("IndexWord", new string[] { "Id" });
            query = queryBuilder.Where(query, "Text", WhereOperator.Equals, "Text");

            parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Text", ""));

            foreach(WordInfo word in existingWords) {
                parameters[0].Value = word.Text;

                command = builder.GetCommand(transaction, query, parameters);

                int id = ExecuteScalar<int>(command, -1, false);
                if(id == -1) {
                    if(state == null) RollbackTransaction(transaction);
                    return -1;
//.........这里部分代码省略.........
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:101,代码来源:SqlPagesStorageProviderBase.cs

示例7: GetCategoriesForPage

        /// <summary>
        /// Gets all the categories of a page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <returns>The categories, sorted by name.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="page"/> is <c>null</c>.</exception>
        public CategoryInfo[] GetCategoriesForPage(PageInfo page)
        {
            if(page == null) throw new ArgumentNullException("page");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string nspace, pageName;
            NameTools.ExpandFullName(page.FullName, out nspace, out pageName);
            if(nspace == null) nspace = "";

            string query = queryBuilder.SelectFrom("Category", "CategoryBinding", new string[] { "Name", "Namespace" }, new string[] { "Category", "Namespace" }, Join.LeftJoin,
                new string[] { "Name", "Namespace" }, new string[] { "Page" });
            query = queryBuilder.Where(query, "CategoryBinding", "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.AndWhere(query, "CategoryBinding", "Page", WhereOperator.Equals, "Page");
            query = queryBuilder.OrderBy(query, new[] { "Category_Name" }, new[] { Ordering.Asc });

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
            parameters.Add(new Parameter(ParameterType.String, "Page", pageName));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<CategoryInfo> result = new List<CategoryInfo>(20);
                List<string> pages = new List<string>(50);

                string prevName = "|||";
                string name = null;

                while(reader.Read()) {
                    name = reader["Category_Name"] as string;

                    if(name != prevName) {
                        if(prevName != "|||") {
                            result[result.Count - 1].Pages = pages.ToArray();
                            pages.Clear();
                        }

                        result.Add(new CategoryInfo(NameTools.GetFullName(reader["Category_Namespace"] as string, name), this));
                    }

                    prevName = name;
                    if(!IsDBNull(reader, "CategoryBinding_Page")) {
                        pages.Add(NameTools.GetFullName(reader["Category_Namespace"] as string, reader["CategoryBinding_Page"] as string));
                    }
                }

                CloseReader(command, reader);

                if(result.Count > 0) result[result.Count - 1].Pages = pages.ToArray();

                return result.ToArray();
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:64,代码来源:SqlPagesStorageProviderBase.cs

示例8: AddMessage

        /// <summary>
        /// Adds a new Message to a Page.
        /// </summary>
        /// <param name="page">The Page.</param>
        /// <param name="username">The Username.</param>
        /// <param name="subject">The Subject.</param>
        /// <param name="dateTime">The Date/Time.</param>
        /// <param name="body">The Body.</param>
        /// <param name="parent">The Parent Message ID, or -1.</param>
        /// <returns>True if the Message is added successfully.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="page"/>, <paramref name="username"/>, <paramref name="subject"/> or <paramref name="body"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="username"/> or <paramref name="subject"/> are empty.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="parent"/> is less than -1.</exception>
        public bool AddMessage(PageInfo page, string username, string subject, DateTime dateTime, string body, int parent)
        {
            if(page == null) throw new ArgumentNullException("page");
            if(username == null) throw new ArgumentNullException("username");
            if(username.Length == 0) throw new ArgumentException("Username cannot be empty", "username");
            if(subject == null) throw new ArgumentNullException("subject");
            if(subject.Length == 0) throw new ArgumentException("Subject cannot be empty", "subject");
            if(body == null) throw new ArgumentNullException("body"); // body can be empty
            if(parent < -1) throw new ArgumentOutOfRangeException("parent", "Invalid Parent Message ID");

            string nspace, name;
            NameTools.ExpandFullName(page.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            if(parent != -1 && FindMessage(GetMessages(transaction, page), parent) == null) {
                RollbackTransaction(transaction);
                return false;
            }

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            short freeId = -1;

            string query = queryBuilder.SelectFrom("Message", new string[] { "Id" });
            query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
            query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.OrderBy(query, new string[] { "Id" }, new Ordering[] { Ordering.Desc });

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Page", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            freeId = ExecuteScalar<short>(command, -1, false);

            if(freeId == -1) freeId = 0;
            else freeId++;

            query = queryBuilder.InsertInto("Message", new string[] { "Page", "Namespace", "Id", "Parent", "Username", "Subject", "DateTime", "Body" },
                new string[] { "Page", "Namespace", "Id", "Parent", "Username", "Subject", "DateTime", "Body" });

            parameters = new List<Parameter>(8);
            parameters.Add(new Parameter(ParameterType.String, "Page", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
            parameters.Add(new Parameter(ParameterType.Int16, "Id", freeId));
            if(parent != -1) parameters.Add(new Parameter(ParameterType.Int16, "Parent", parent));
            else parameters.Add(new Parameter(ParameterType.Int16, "Parent", DBNull.Value));
            parameters.Add(new Parameter(ParameterType.String, "Username", username));
            parameters.Add(new Parameter(ParameterType.String, "Subject", subject));
            parameters.Add(new Parameter(ParameterType.DateTime, "DateTime", dateTime));
            parameters.Add(new Parameter(ParameterType.String, "Body", body));

            command = builder.GetCommand(transaction, query, parameters);

            int rows = ExecuteNonQuery(command, false);

            if(rows == 1) {
                IndexMessage(page, freeId, subject, dateTime, body, transaction);

                CommitTransaction(transaction);
                return true;
            }
            else {
                RollbackTransaction(transaction);
                return false;
            }
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:85,代码来源:SqlPagesStorageProviderBase.cs

示例9: DeleteDataForDocument

        /// <summary>
        /// Deletes all data associated to a document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="state">A state object passed from the index (can be <c>null</c> or a <see cref="T:DbTransaction" />).</param>
        private void DeleteDataForDocument(IDocument document, object state)
        {
            // 1. Delete all data related to a document
            // 2. Delete all words that have no more mappings

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.DeleteFrom("IndexDocument");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "DocName");
            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "DocName", document.Name));

            string subQuery = queryBuilder.SelectFrom("IndexWordMapping", new string[] { "Word" });
            subQuery = queryBuilder.GroupBy(subQuery, new string[] { "Word" });
            string query2 = queryBuilder.DeleteFrom("IndexWord");
            query2 = queryBuilder.WhereNotInSubquery(query2, "IndexWord", "Id", subQuery);

            query = queryBuilder.AppendForBatch(query, query2);

            DbCommand command = null;
            if(state != null) command = builder.GetCommand((DbTransaction)state, query, parameters);
            else command = builder.GetCommand(connString, query, parameters);

            // Close only if state is null
            ExecuteNonQuery(command, state == null);
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:32,代码来源:SqlPagesStorageProviderBase.cs

示例10: GetSetting

        /// <summary>
        /// Retrieves the value of a Setting.
        /// </summary>
        /// <param name="name">The name of the Setting.</param>
        /// <returns>The value of the Setting, or null.</returns>
        /// <exception cref="ArgumentNullException">If <b>name</b> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <b>name</b> is empty.</exception>
        public string GetSetting(string name)
        {
            if(name == null) throw new ArgumentNullException("name");
            if(name.Length == 0) throw new ArgumentException("Name cannot be empty", "name");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("Setting");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Name", name));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                string result = null;

                if(reader.Read()) {
                    result = reader["Value"] as string;
                }

                CloseReader(command, reader);

                // HACK: this allows to correctly initialize a fully SQL-based wiki instance without any user intervention
                if(string.IsNullOrEmpty(result)) {
                    if(name == "DefaultUsersProvider") result = DefaultUsersStorageProvider;
                    if(name == "DefaultPagesProvider") result = DefaultPagesStorageProvider;
                    if(name == "DefaultFilesProvider") result = DefaultFilesStorageProvider;
                }

                return result;
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:45,代码来源:SqlSettingsStorageProviderBase.cs

示例11: RetrievePluginAssembly

        /// <summary>
        /// Retrieves a plugin's assembly.
        /// </summary>
        /// <param name="filename">The file name of the assembly.</param>
        /// <returns>The assembly content, or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <b>filename</b> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <b>filename</b> is empty.</exception>
        public byte[] RetrievePluginAssembly(string filename)
        {
            if(filename == null) throw new ArgumentNullException("filename");
            if(filename.Length == 0) throw new ArgumentException("Filename cannot be empty", "filename");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("PluginAssembly", new string[] { "Assembly" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Name", filename));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                byte[] result = null;

                if(reader.Read()) {
                    result = GetBinaryColumn(reader, "Assembly", MaxAssemblySize);
                }

                CloseReader(command, reader);

                return result;
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:38,代码来源:SqlSettingsStorageProviderBase.cs

示例12: GetRecentChanges

        /// <summary>
        /// Gets the recent changes of the Wiki.
        /// </summary>
        /// <returns>The recent Changes, oldest to newest.</returns>
        public RecentChange[] GetRecentChanges()
        {
            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("RecentChange", new string[] { "Page", "Title", "MessageSubject", "DateTime", "User", "Change", "Description" });
            query = queryBuilder.OrderBy(query, new string[] { "DateTime" }, new Ordering[] { Ordering.Asc });

            DbCommand command = builder.GetCommand(connString, query, new List<Parameter>());

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<RecentChange> result = new List<RecentChange>(100);

                while(reader.Read()) {
                    result.Add(new RecentChange(reader["Page"] as string, reader["Title"] as string,
                        GetNullableColumn<string>(reader, "MessageSubject", ""),
                        (DateTime)reader["DateTime"], reader["User"] as string, RecentChangeFromChar(((string)reader["Change"])[0]),
                        GetNullableColumn<string>(reader, "Description", "")));
                }

                CloseReader(command, reader);

                return result.ToArray();
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:32,代码来源:SqlSettingsStorageProviderBase.cs

示例13: GetPluginStatus

        /// <summary>
        /// Gets the status of a plugin.
        /// </summary>
        /// <param name="typeName">The Type name of the plugin.</param>
        /// <returns>The status (<c>false</c> for disabled, <c>true</c> for enabled), or <c>true</c> if no status is found.</returns>
        /// <exception cref="ArgumentNullException">If <b>typeName</b> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <b>typeName</b> is empty.</exception>
        public bool GetPluginStatus(string typeName)
        {
            if(typeName == null) throw new ArgumentNullException("typeName");
            if(typeName.Length == 0) throw new ArgumentException("Type Name cannot be empty", "typeName");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("PluginStatus", new string[] { "Enabled" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Name", typeName));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            bool? enabled = null;

            if(reader != null && reader.Read()) {
                if(!IsDBNull(reader, "Enabled")) enabled = (bool)reader["Enabled"];
            }
            CloseReader(command, reader);

            if(enabled.HasValue) return enabled.Value;
            else {
                if(typeName == "ScrewTurn.Wiki.UsersStorageProvider" ||
                    typeName == "ScrewTurn.Wiki.PagesStorageProvider" ||
                    typeName == "ScrewTurn.Wiki.FilesStorageProvider") return false;
                else return true;
            }
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:40,代码来源:SqlSettingsStorageProviderBase.cs

示例14: GetPluginConfiguration

        /// <summary>
        /// Gets the configuration of a plugin.
        /// </summary>
        /// <param name="typeName">The Type name of the plugin.</param>
        /// <returns>The plugin configuration, or <b>String.Empty</b>.</returns>
        /// <exception cref="ArgumentNullException">If <b>typeName</b> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <b>typeName</b> is empty.</exception>
        public string GetPluginConfiguration(string typeName)
        {
            if(typeName == null) throw new ArgumentNullException("typeName");
            if(typeName.Length == 0) throw new ArgumentException("Type Name cannot be empty", "typeName");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("PluginStatus", new string[] { "Configuration" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Name", typeName));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            string result = ExecuteScalar<string>(command, "");

            return result;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:27,代码来源:SqlSettingsStorageProviderBase.cs

示例15: GetPage

        /// <summary>
        /// Gets a page.
        /// </summary>
        /// <param name="connection">A database connection.</param>
        /// <param name="fullName">The full name of the page.</param>
        /// <returns>The <see cref="T:PageInfo" />, or <c>null</c> if no page is found.</returns>
        private PageInfo GetPage(DbConnection connection, string fullName)
        {
            string nspace, name;
            NameTools.ExpandFullName(fullName, out nspace, out name);
            if(nspace == null) nspace = "";

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("Page");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");
            query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Name", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));

            DbCommand command = builder.GetCommand(connection, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                PageInfo result = null;

                if(reader.Read()) {
                    result = new PageInfo(NameTools.GetFullName(reader["Namespace"] as string, reader["Name"] as string),
                        this, (DateTime)reader["CreationDateTime"]);
                }

                CloseReader(reader);

                return result;
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:41,代码来源:SqlPagesStorageProviderBase.cs


注:本文中的ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder.SelectFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。