コード例 #1
0
        /// <summary>
        /// Gets a list of items as described in requestInfo
        /// </summary>
        /// <param name="portalId">
        /// Only items for portalID is returned
        /// </param>
        /// <param name="userId">
        /// User ID. If -1 the user is Annonymous/Guest
        /// </param>
        /// <param name="applicationFullPath">
        /// Full URL path to Appleseed site
        /// </param>
        /// <param name="requestInfo">
        /// a filled ServiceRequestInfo class
        /// </param>
        /// <returns>
        /// ArrayList
        /// </returns>
        public static List<ServiceResponseInfoItem> GetResponseItemList(
            int portalId, Guid userId, string applicationFullPath, ref ServiceRequestInfo requestInfo)
        {
            var colItems = new List<ServiceResponseInfoItem>();
            ServiceResponseInfoItem responseItem;

            var moduleType = requestInfo.ModuleType;

            // JLH!! We really should lookup complete ModuleName in db...
            if (moduleType.ToUpper() == "ALL")
            {
                moduleType = string.Empty;
            }
            else
            {
                moduleType = string.Format("Appleseed.DLL;Appleseed.DesktopModules.{0}", moduleType);
            }

            var select = new StringBuilder(string.Empty, 1000);
            if (requestInfo.IDList.Length != 0)
            {
                if (requestInfo.IDListType == ServiceListType.Tab)
                {
                    select.AppendFormat(" AND tab.PageID IN ({0})", requestInfo.IDList);
                }

                if (requestInfo.IDListType == ServiceListType.Module)
                {
                    select.AppendFormat(" AND mod.ModuleID IN ({0})", requestInfo.IDList);
                }
            }

            // We can not add this code - original search sql not ready for this!
            // if (requestInfo.RootLevelOnly)
            // 	select.Append(" AND tab.ParentPageID IS NULL");
            if (requestInfo.MobileOnly)
            {
                select.Append(" AND mod.ShowMobile=1");
            }

            var dr = SearchHelper.SearchPortal(
                portalId,
                userId,
                moduleType,
                requestInfo.SearchString,
                requestInfo.SearchField,
                requestInfo.SortField,
                requestInfo.SortDirection,
                string.Empty,
                select.ToString());

            var hits = 1;
            try
            {
                while (dr.Read() && hits <= requestInfo.MaxHits)
                {
                    responseItem = new ServiceResponseInfoItem();

                    if (!dr.IsDBNull(0))
                    {
                        responseItem.FriendlyName = dr.GetString(0);
                    }

                    if (!dr.IsDBNull(1))
                    {
                        responseItem.Title = dr.GetString(1);
                    }

                    if (!dr.IsDBNull(2))
                    {
                        HTMLText html = SearchHelper.DeleteBeforeBody(HttpUtility.HtmlDecode(dr.GetString(2)));
                        responseItem.Description = html.InnerText;
                    }

                    if (!dr.IsDBNull(3))
                    {
                        responseItem.ModuleID = dr.GetInt32(3);
                    }

                    if (!dr.IsDBNull(4))
                    {
                        responseItem.ItemID = dr.GetInt32(4);
                        if (requestInfo.ShowID)
                        {
                            responseItem.Title += string.Format(" (ItemID={0})", responseItem.ItemID);
                        }
                    }

                    if (!dr.IsDBNull(5))
                    {
                        responseItem.CreatedByUser = dr.GetString(5);
                    }

                    if (!dr.IsDBNull(6))
                    {
                        try
                        {
                            responseItem.CreatedDate = dr.GetDateTime(6);
                        }
                        catch
                        {
                            // Modules like HtmlModule has not field CreatedDate
                        }
                    }

                    if (!dr.IsDBNull(7))
                    {
                        responseItem.PageID = dr.GetInt32(7);
                        if (requestInfo.ShowID)
                        {
                            responseItem.Description += string.Format(
                                " (PageID={0}, ModuleID={1})", responseItem.PageID, responseItem.ModuleID);
                        }
                    }

                    if (!dr.IsDBNull(8))
                    {
                        responseItem.PageName = dr.GetString(8);
                    }

                    if (!dr.IsDBNull(9))
                    {
                        responseItem.GeneralModDefID = dr.GetGuid(9).ToString().ToUpper();
                    }

                    if (!dr.IsDBNull(10))
                    {
                        responseItem.ModuleTitle = dr.GetString(10);
                    }

                    if (responseItem.GeneralModDefID == "0B113F51-FEA3-499A-98E7-7B83C192FDBB" || // Html Document
                        responseItem.GeneralModDefID == "2B113F51-FEA3-499A-98E7-7B83C192FDBB")
                    {
                        // Html WYSIWYG Edit (V2)
                        // We use the database field [rb.Modules].[ModuleTitle]:
                        responseItem.Title = responseItem.ModuleTitle;
                    }

                    responseItem.Link = string.Format(
                        "{0}/DesktopDefault.aspx?tabID={1}", applicationFullPath, responseItem.PageID);
                    if (requestInfo.PortalAlias.Length != 0)
                    {
                        responseItem.Link += string.Format("&Alias={0}", requestInfo.PortalAlias);
                    }

                    colItems.Add(responseItem);
                    hits++;
                }
            }
            finally
            {
                dr.Close(); // by Manu, fixed bug 807858
            }

            return colItems;
        }
コード例 #2
0
        /// <summary>
        /// Gets a list of tabs as described in requestInfo
        /// </summary>
        /// <param name="portalId">
        /// Only tabs for portalID is returned
        /// </param>
        /// <param name="userId">
        /// User ID. If -1 the user is Anonymous/Guest
        /// </param>
        /// <param name="applicationFullPath">
        /// Full URL path to Appleseed site
        /// </param>
        /// <param name="requestInfo">
        /// a filled ServiceRequestInfo class
        /// </param>
        /// <returns>
        /// ArrayList
        /// </returns>
        public static List<ServiceResponseInfoItem> GetResponseTabList(
            int portalId, Guid userId, string applicationFullPath, ref ServiceRequestInfo requestInfo)
        {
            var colItems = new List<ServiceResponseInfoItem>();
            ServiceResponseInfoItem responseItem = null;

            var select = new StringBuilder(string.Empty, 1000);

            select.Append(" SELECT");
            if (requestInfo.MaxHits > 0)
            {
                select.AppendFormat(" TOP {0}", requestInfo.MaxHits);
            }

            select.Append(" Tab.*");
            select.Append(" ,ISNULL(ParTab.PageName,'') AS ParentTabName");
            select.Append(" ,ParTab.PageID AS ParentPageID");
            select.Append(" ,Mod.ModuleID AS ModuleID");
            select.Append(" ,Mod.ModuleTitle AS ModuleTitle");
            select.Append(
                " FROM rb_Pages Tab, rb_Pages ParTab, rb_Modules Mod, rb_ModuleDefinitions ModDef, rb_GeneralModuleDefinitions GenModDef");
            select.Append(" WHERE");
            select.Append(" Tab.AuthorizedRoles like '%All Users%'");
            select.Append(" AND Tab.ParentPageID *= ParTab.PageID");

            // Jakob: I just luv this outer join! (It's so easy!)
            select.Append(" AND Tab.PageID = Mod.TabID");
            select.Append(" AND Mod.ModuleDefID = ModDef.ModuleDefID");
            select.Append(" AND ModDef.GeneralModDefID = GenModDef.GeneralModDefID");
            select.Append(" AND Mod.AuthorizedViewRoles like '%All Users%'");
            select.AppendFormat(" AND Tab.PortalID = {0}", portalId);
            if (requestInfo.IDList.Length != 0)
            {
                if (requestInfo.IDList.Length != 0)
                {
                    select.AppendFormat(" AND Tab.PageID IN ({0})", requestInfo.IDList);
                }

                if (requestInfo.IDListType == ServiceListType.Module)
                {
                    select.AppendFormat(" AND Mod.ModuleID IN ({0})", requestInfo.IDList);
                }
            }

            if (requestInfo.ModuleType != "All")
            {
                select.AppendFormat(" AND GenModDef.ClassName = 'Appleseed.DesktopModules.{0}'", requestInfo.ModuleType);
            }

            if (requestInfo.RootLevelOnly)
            {
                select.Append(" AND Tab.ParentPageID IS NULL");
            }

            if (requestInfo.MobileOnly)
            {
                select.Append(" AND Tab.ShowMobile=1");
            }

            if (requestInfo.SearchString.Length != 0)
            {
                select.AppendFormat(" AND Tab.PageName like '%{0}%'", requestInfo.SearchString);
            }

            select.AppendFormat(
                " ORDER BY Tab.PageOrder {0}, Tab.ParentPageID, Mod.ModuleOrder ", requestInfo.SortDirection);

            var pageIdPrev = -1;

            var dr = DBHelper.GetDataReader(select.ToString());
            try
            {
                while (dr.Read())
                {
                    var pageId = (int)dr["PageID"];
                    var moduleId = (int)dr["ModuleID"];

                    if (pageId != pageIdPrev)
                    {
                        if (pageIdPrev != -1)
                        {
                            colItems.Add(responseItem);
                        }

                        responseItem = new ServiceResponseInfoItem();

                        if (requestInfo.ShowID)
                        {
                            responseItem.Title = string.Format("{0} (PageID={1})", dr["PageName"], pageId);
                        }
                        else
                        {
                            responseItem.Title = (string)dr["PageName"];
                        }

                        if (requestInfo.ShowID)
                        {
                            responseItem.Description = string.Format("{0} (ModuleID={1})", dr["ModuleTitle"], moduleId);
                        }
                        else
                        {
                            responseItem.Description = (string)dr["ModuleTitle"];
                        }

                        responseItem.Link = string.Format(
                            "{0}/DesktopDefault.aspx?tabID={1}", applicationFullPath, pageId);
                        if (requestInfo.PortalAlias.Length != 0)
                        {
                            responseItem.Link += string.Format("&Alias={0}", requestInfo.PortalAlias);
                        }
                    }
                    else
                    {
                        if (requestInfo.ShowID)
                        {
                            if (responseItem != null)
                            {
                                responseItem.Description += string.Format(
                                    ", {0} (ModuleID={1})", dr["ModuleTitle"], moduleId);
                            }
                        }
                        else
                        {
                            if (responseItem != null)
                            {
                                responseItem.Description += string.Format(", {0}", dr["ModuleTitle"]);
                            }
                        }
                    }

                    pageIdPrev = pageId;
                }
            }
            finally
            {
                dr.Close(); // by Manu, fixed bug 807858
            }

            if (pageIdPrev != -1)
            {
                colItems.Add(responseItem);
            }

            return colItems;
        }
コード例 #3
0
        /// <summary>
        /// Calls an RSS service and returns the service response.
        ///   This method goes crazy with the Regex class to parse the response
        ///   from an RSS service. After testing, I discovered that most
        ///   RSS services do not return a valid XML response. That requires
        ///   parsing through possibly faulty XML (missing end tags, etc.)
        /// </summary>
        /// <param name="requestInfo">
        /// a filled ServiceRequestInfo class
        /// </param>
        /// <returns>
        /// The Service Response Info
        /// </returns>
        private static ServiceResponseInfo CallRssService(ServiceRequestInfo requestInfo)
        {
            var responseInfo = new ServiceResponseInfo();

            // Grab the page
            var rawResponse = GetWebPage(requestInfo.Url);
            if (rawResponse == string.Empty)
            {
                responseInfo.ServiceStatus = "No reply from URL (could be timeout)";
                return responseInfo;
            }

            // Get Channel
            var channel = Regex.Match(rawResponse, @"<channel>(.*?)</channel>", RegexOptions.Singleline);
            if (channel.Success)
            {
                // Get Service title
                var serviceTitle = Regex.Match(
                    channel.Result("$1"), @"<title>(.*?)</title>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (serviceTitle.Success)
                {
                    responseInfo.ServiceTitle = serviceTitle.Result("$1");
                }

                // Get Service Link
                var serviceLink = Regex.Match(
                    channel.Result("$1"), @"<link>(.*?)</link>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (serviceLink.Success)
                {
                    responseInfo.ServiceLink = serviceLink.Result("$1");
                }

                // Get Service Description
                var serviceDescription = Regex.Match(
                    channel.Result("$1"),
                    @"<description>(.*?)</description>",
                    RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (serviceDescription.Success)
                {
                    responseInfo.ServiceDescription = serviceDescription.Result("$1");
                }

                // Get Service Copyright
                var serviceCopyright = Regex.Match(
                    channel.Result("$1"),
                    @"<copyright>(.*?)</copyright>",
                    RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (serviceCopyright.Success)
                {
                    responseInfo.ServiceCopyright = serviceCopyright.Result("$1");
                }
            }

            // Get Image
            var image = Regex.Match(rawResponse, @"<image>(.*?)</image>", RegexOptions.Singleline);
            if (image.Success)
            {
                // Get Image title
                var imageTitle = Regex.Match(
                    image.Result("$1"), @"<title>(.*?)</title>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (imageTitle.Success)
                {
                    responseInfo.ServiceImageTitle = imageTitle.Result("$1");
                }

                // Get Image Url
                var imageUrl = Regex.Match(
                    image.Result("$1"), @"<url>(.*?)</url>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (imageUrl.Success)
                {
                    responseInfo.ServiceImageUrl = imageUrl.Result("$1");
                }

                // Get Image Link
                var imageLink = Regex.Match(
                    image.Result("$1"), @"<link>(.*?)</link>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (imageLink.Success)
                {
                    responseInfo.ServiceImageLink = imageLink.Result("$1");
                }
            }

            // Get Items
            var items = Regex.Matches(rawResponse, @"<item>(.*?)</item>", RegexOptions.Singleline);
            var counter = 0;
            foreach (Match item in items)
            {
                counter++;
                if (counter > requestInfo.MaxHits)
                {
                    break;
                }

                var responseInfoItem = new ServiceResponseInfoItem();

                // Get Item title
                var itemTitle = Regex.Match(
                    item.Result("$1"), @"<title>(.*?)</title>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (itemTitle.Success)
                {
                    responseInfoItem.Title = itemTitle.Result("$1");
                }

                // Get Item Link
                var itemLink = Regex.Match(
                    item.Result("$1"), @"<link>(.*?)</link>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (itemLink.Success)
                {
                    responseInfoItem.Link = itemLink.Result("$1");
                }

                // Get Item Description
                var itemDescription = Regex.Match(
                    item.Result("$1"),
                    @"<description>(.*?)</description>",
                    RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (itemDescription.Success)
                {
                    responseInfoItem.Description = itemDescription.Result("$1");
                }

                // Add new item to Response Info
                responseInfo.Items.Add(responseInfoItem);
            }

            return responseInfo;
        }
コード例 #4
0
        /// <summary>
        /// Gets a list of modules as described in requestInfo
        /// </summary>
        /// <param name="portalId">
        /// Only modules for portalID is returned
        /// </param>
        /// <param name="userId">
        /// User ID. If -1 the user is Anonymous/Guest
        /// </param>
        /// <param name="applicationFullPath">
        /// Full URL path to Appleseed site
        /// </param>
        /// <param name="requestInfo">
        /// a filled ServiceRequestInfo class
        /// </param>
        /// <returns>
        /// ArrayList
        /// </returns>
        public static List<ServiceResponseInfoItem> GetResponseModuleList(
            int portalId, Guid userId, string applicationFullPath, ref ServiceRequestInfo requestInfo)
        {
            var colItems = new List<ServiceResponseInfoItem>();
            ServiceResponseInfoItem responseItem = null;

            var select = new StringBuilder(string.Empty, 1000);

            select.Append(" SELECT");
            if (requestInfo.MaxHits > 0)
            {
                select.AppendFormat(" TOP {0}", requestInfo.MaxHits);
            }

            select.Append(" Mod.ModuleID, Mod.ModuleTitle, Mod.ModuleDefID, Mod.ShowMobile, Mod.WorkflowState");
            select.Append(" ,Tab.PageID AS PageID");
            select.Append(" ,Tab.PageName AS TabName");
            select.Append(" ,Tab.ParentPageID AS ParentPageID");
            select.Append(" ,GenModDef.GeneralModDefID AS GeneralModDefID");
            select.Append(" ,GenModDef.FriendlyName AS FriendlyName");
            select.Append(
                " FROM rb_Modules Mod, rb_Pages Tab, rb_ModuleDefinitions ModDef, rb_GeneralModuleDefinitions GenModDef");
            select.Append(" WHERE");
            select.Append(" Tab.AuthorizedRoles like '%All Users%'");
            select.Append(" AND Tab.PageID = Mod.PageID");
            select.Append(" AND Mod.ModuleDefID = ModDef.ModuleDefID");
            select.Append(" AND ModDef.GeneralModDefID = GenModDef.GeneralModDefID");
            select.Append(" AND Mod.AuthorizedViewRoles like '%All Users%'");
            select.Append(" AND ModDef.PortalID = Tab.PortalID");
            select.AppendFormat(" AND Tab.PortalID = {0}", portalId);
            if (requestInfo.IDList.Length != 0)
            {
                if (requestInfo.IDListType == ServiceListType.Tab)
                {
                    select.AppendFormat(" AND Tab.PageID IN ({0})", requestInfo.IDList);
                }

                if (requestInfo.IDListType == ServiceListType.Module)
                {
                    select.AppendFormat(" AND Mod.ModuleID IN ({0})", requestInfo.IDList);
                }
            }

            if (requestInfo.ModuleType != "All")
            {
                select.AppendFormat(" AND GenModDef.ClassName = 'Appleseed.DesktopModules.{0}'", requestInfo.ModuleType);
            }

            if (requestInfo.RootLevelOnly)
            {
                select.Append(" AND Tab.ParentPageID IS NULL");
            }

            if (requestInfo.MobileOnly)
            {
                select.Append(" AND Mod.ShowMobile=1");
            }

            if (requestInfo.SearchString.Length != 0)
            {
                select.AppendFormat(" AND Mod.ModuleTitle like '%{0}%'", requestInfo.SearchString);
            }

            var sortField = "GenModDef.FriendlyName";
            if (requestInfo.SortField == "TITLE")
            {
                sortField = "Mod.ModuleTitle";
            }

            select.AppendFormat(" ORDER BY {0}", sortField);
            select.Append(" ");
            select.Append(requestInfo.SortDirection);

            var dr = DBHelper.GetDataReader(select.ToString());
            try
            {
                while (dr.Read())
                {
                    responseItem = new ServiceResponseInfoItem();
                    var pageId = (int)dr["PageID"];
                    var moduleId = (int)dr["ModuleID"];

                    if (requestInfo.ShowID)
                    {
                        responseItem.Title = string.Format("{0} (ModuleID={1})", dr["ModuleTitle"], moduleId);
                        responseItem.Description = string.Format(
                            "Type: {0}, Page: {1} (PageID={2})", dr["FriendlyName"], dr["PageName"], pageId);
                    }
                    else
                    {
                        responseItem.Title = string.Format("{0} (ModuleID={1})", dr["ModuleTitle"], moduleId);
                        responseItem.Description = string.Format(
                            "Type: {0}, Page: {1}", dr["FriendlyName"], dr["PageName"]);
                    }

                    responseItem.Link = string.Format("{0}/DesktopDefault.aspx?tabID={1}", applicationFullPath, pageId);
                    if (requestInfo.PortalAlias.Length != 0)
                    {
                        responseItem.Link += string.Format("&Alias={0}", requestInfo.PortalAlias);
                    }

                    colItems.Add(responseItem);
                }
            }
            finally
            {
                dr.Close(); // by Manu, fixed bug 807858
            }

            return colItems;
        }