Ejemplo n.º 1
0
 public override string getPeopleListMetadata()
 {
     try
     {
         XmlNode node       = searchData.SelectSingleNode("rdf:RDF/rdf:Description/prns:numberOfConnections", namespaceManager);
         Int32   resultSize = Convert.ToInt32(node.InnerText);
         if (resultSize == 1)
         {
             return("" + resultSize + " profile");
         }
         else if (resultSize <= searchLimit)
         {
             return("" + resultSize + " profiles");
         }
         else
         {
             return("top " + searchLimit + " profiles");
         }
     }
     catch (Exception e)
     {
         DebugLogging.Log(e.Message);
     }
     return("Error reading results");
 }
Ejemplo n.º 2
0
        public void PutSocket(CustomSocket socket)
        {
            DebugLogging.Log("Put Socket -> Pool size: " + availableSockets.Count.ToString());
            lock (availableSockets)
            {
                TimeSpan socketLifeTime = DateTime.Now.Subtract(socket.TimeCreated);
                if (availableSockets.Count < POOL_MAX_SIZE && socketLifeTime.Seconds < EXPIRE_SECONDS)
                {
                    if (socket != null)
                    {
                        if (socket.Connected)
                        {
                            availableSockets.Enqueue(socket);

                            DebugLogging.Log("Socket Queued -> Pool size: " + availableSockets.Count.ToString());
                        }
                        else
                        {
                            socket.Close();
                        }
                    }
                }
                else
                {
                    socket.Close();
                    DebugLogging.Log("PutSocket - Socket is forced " +
                                     "to closed -> Pool size: " +
                                     availableSockets.Count.ToString());
                }
            }
        }
Ejemplo n.º 3
0
        public CustomSocket GetSocket()
        {
            DebugLogging.Log("Get Socket -> Pool size: " + availableSockets.Count.ToString());
            if (availableSockets.Count > 0)
            {
                lock (availableSockets)
                {
                    CustomSocket socket = null;
                    while (availableSockets.Count > 0)
                    {
                        socket = availableSockets.Dequeue();

                        if (socket.Connected)
                        {
                            DebugLogging.Log("Socket Dequeued -> Pool size: " +
                                             availableSockets.Count.ToString());

                            return(socket);
                        }
                        else
                        {
                            socket.Close();
                            System.Threading.Interlocked.Decrement(ref SocketCounter);
                            DebugLogging.Log("GetSocket -- Close -- Count: " +
                                             SocketCounter.ToString());
                        }
                    }
                }
            }
            return(ConnectSocket());
        }
Ejemplo n.º 4
0
            public override string getCallbackResponse()
            {
                try
                {
                    searchRequest.SelectSingleNode("/SearchOptions/OutputOptions/Offset").InnerText = "0";
                    searchRequest.SelectSingleNode("/SearchOptions/OutputOptions/Limit").InnerText  = "500";
                    XmlDocument searchData = new Profiles.Search.Utilities.DataIO().Search(searchRequest, false, false);

                    DebugLogging.Log("SeachCallbackResponse :" + searchRequest.ToString());

                    List <string> peopleURIs = new List <string>();
                    XmlNodeList   people     = searchData.GetElementsByTagName("rdf:object");
                    for (int i = 0; i < people.Count; i++)
                    {
                        peopleURIs.Add(people[i].Attributes["rdf:resource"].Value);
                    }
                    if (peopleURIs.Count > 0)
                    {
                        return(BuildJSONPersonIds(peopleURIs, "" + peopleURIs.Count + " people found"));
                    }
                }
                catch (Exception e)
                {
                    DebugLogging.Log(e.Message);
                }

                return(null);
            }
Ejemplo n.º 5
0
        public static void LoadProfile(string profile)
        {
            if (IsCurrentProfile(profile))
            {
                return;
            }

            string sProfilePath = string.Empty;

            if (profile.Contains("Loader"))
            {
                sProfilePath = XmlLoaderProfile;
            }
            else
            {
                sProfilePath = DataPath + @"\" + profile;
            }

            if (sProfilePath == null || profile == null)
            {
                DebugLogging.Log("[LoadProfile] Failed to Load Profile, file: " + sProfilePath);
                return;
            }

            try
            {
                DebugLogging.Log("[LoadProfile] Load Profile, file: " + sProfilePath);
                ProfileManager.Load(sProfilePath);
            }
            catch { }
        }
        public object Search(queryrequest xml)
        {
            SemWeb.Query.Query query = null;

            string q = string.Empty;

            try
            {
                query = new SparqlEngine(new StringReader(xml.query));
            }
            catch (QueryFormatException ex)
            {
                var malformed = new malformedquery();

                malformed.faultdetails = ex.Message;

                return(malformed);
            }

            // Load the data from sql server
            SemWeb.Stores.SQLStore store;

            string connstr = ConfigurationManager.ConnectionStrings["SemWebDB"].ConnectionString;

            DebugLogging.Log(connstr);

            store = (SemWeb.Stores.SQLStore)SemWeb.Store.CreateForInput(connstr);

            //Create a Sink for the results to be writen once the query is run.
            MemoryStream    ms     = new MemoryStream();
            XmlTextWriter   writer = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
            QueryResultSink sink   = new SparqlXmlQuerySink(writer);

            try
            {
                // Run the query.
                query.Run(store, sink);
            }
            catch (Exception ex)
            {
                // Run the query.
                query.Run(store, sink);
                DebugLogging.Log("Run the query a second time");
                DebugLogging.Log(ex.Message);
            }
            //flush the writer then  load the memory stream
            writer.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            //Write the memory stream out to the response.
            ASCIIEncoding ascii = new ASCIIEncoding();

            DebugLogging.Log(ascii.GetString(ms.ToArray()).Replace("???", ""));
            writer.Close();

            DebugLogging.Log("End of Processing");

            return(SerializeXML.DeserializeObject(ascii.GetString(ms.ToArray()).Replace("???", ""), typeof(sparql)) as sparql);
        }
Ejemplo n.º 7
0
 public bool IsVisible()
 {
     // always have turned on for Profile/Display.aspx because we want to generate the "profile was viewed" in Javascript (bot proof) 
     // regardless of any gadgets being visible, and we need this to be True for the shindig javascript libraries to load
     bool retval = shindigURL != null && (GetVisibleGadgets().Count > 0);
     DebugLogging.Log("OpenSocialIsVisible = " + retval);
     return retval;
 }
        private string BuildJSONPersonIds(string uri)
        {
            DebugLogging.Log("BuildJSONPersonIds " + uri);
            List <string> personIds = new List <string>();

            personIds.Add(uri);
            return(BuildJSONPersonIds(personIds));
        }
Ejemplo n.º 9
0
        public static string BuildJSONPersonIds(string uri, string message)
        {
            DebugLogging.Log("BuildJSONPersonIds " + uri + " : " + message);
            List <string> personIds = new List <string>();

            personIds.Add(uri);
            return(BuildJSONPersonIds(personIds, message));
        }
Ejemplo n.º 10
0
        private static string SocketSendReceive(string viewer, string owner, string gadget)
        {
            //  These keys need to match what you see in edu.ucsf.profiles.shindig.service.SecureTokenGeneratorService in Shindig
            string request = "c=default" + (viewer != null ? "&v=" + HttpUtility.UrlEncode(viewer) : "") +
                             (owner != null ? "&o=" + HttpUtility.UrlEncode(owner) : "") + "&u=" + HttpUtility.UrlEncode(gadget) + "\r\n";

            Byte[] bytesSent     = System.Text.Encoding.ASCII.GetBytes(request);
            Byte[] bytesReceived = new Byte[256];

            // Create a socket connection with the specified server and port.
            //Socket s = ConnectSocket(tokenService[0], Int32.Parse(tokenService[1]));

            // during startup we might fail a few times, so be will to retry
            string page = "";

            for (int i = 0; i < 3 && page.Length == 0; i++)
            {
                CustomSocket s = null;
                try
                {
                    s = sockets.GetSocket();

                    if (s == null)
                    {
                        return("Connection failed");
                    }

                    // Send request to the server.
                    DebugLogging.Log("Sending Bytes");
                    s.Send(bytesSent, bytesSent.Length, 0);

                    // Receive the server home page content.
                    int bytes = 0;

                    // The following will block until te page is transmitted.
                    do
                    {
                        DebugLogging.Log("Receiving Bytes");
                        bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
                        page  = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
                        DebugLogging.Log("Socket Page=" + page + "|");
                    }while (page.Length == page.TrimEnd().Length&& bytes > 0);
                }
                catch (Exception ex)
                {
                    DebugLogging.Log("Socket Error :" + ex.Message);
                    page = "";
                }
                finally
                {
                    if (sockets != null)
                    {
                        sockets.PutSocket(s);
                    }
                }
            }
            return(page.TrimEnd());
        }
Ejemplo n.º 11
0
        public static string CallORNGRPC(string guid, string channel, string opt_params)
        {
            DebugLogging.Log("CallORNGRPC " + guid + ":" + channel);
            ORNGRPCService responder = ORNGRPCService.GetRPCService(new Guid(guid), channel);
            string         retval    = responder != null?responder.call(channel, opt_params) : null;

            DebugLogging.Log("CallORNGRPC " + (responder == null ? "ORNGRPCService not found! guid =" : guid));
            return(retval != null ? retval : "");
        }
Ejemplo n.º 12
0
        public static string CallORNGResponder(string guid, string request)
        {
            DebugLogging.Log("OpenSocialManager CallORNGResponder " + guid + ":" + request);
            ORNGCallbackResponder responder = ORNGCallbackResponder.GetORNGCallbackResponder(new Guid(guid), request);
            string retval = responder != null?responder.getCallbackResponse() : null;

            DebugLogging.Log("OpenSocialManager CallORNGResponder " + (responder == null ? "CallbackReponder not found! " : retval));
            return(retval);
        }
Ejemplo n.º 13
0
        public static string CallORNGRPC(string guid, string request)
        {
            DebugLogging.Log("CallORNGRPC " + guid + ":" + request);
            ORNGRPCService responder = ORNGRPCService.GetRPCService(new Guid(guid));
            string         retval    = responder != null?responder.call(request) : null;

            DebugLogging.Log("CallORNGRPC " + (responder == null ? "ORNGRPCService not found! guid =" : guid));
            return(retval != null ? retval : "");
        }
Ejemplo n.º 14
0
 public ORNGRPCService(string uri, Page page, bool editMode, string[] chnls)
 {
     this.om = OpenSocialManager.GetOpenSocialManager(uri, page, false);
     this.channels.AddRange(chnls);
     // Add to Session so that it does not get prematurely garbage collected
     HttpContext.Current.Session[KEY_PREFIX + ":" + om.GetGuid().ToString()] = this;
     managers.Add(new WeakReference(this));
     DebugLogging.Log("ORNGRPCService created :" + om.GetGuid().ToString() + " channels " + this.channels.ToString());
 }
Ejemplo n.º 15
0
        public static void LeaveGame()
        {
            DebugLogging.Log("LeaveGame");

            LoadProfile("UberBotLeaveGame.xml");

            MyUsedProfiles.Clear();
            UberBot.MyRunInfos.GameCount++;
            UberBot.MyRunInfos.LastProfile = 0;
        }
Ejemplo n.º 16
0
 internal string GetSecurityToken(String gadgetURL)
 {
     if (Convert.ToBoolean(ConfigurationSettings.AppSettings["DEBUG"]) == true)
     {
         Stopwatch sw = new Stopwatch();
         sw.Start();
         string retval = SocketSendReceive(GetViewerURI(), GetOwnerURI(), gadgetURL);
         sw.Stop();
         socketTime += sw.Elapsed.TotalSeconds;
         DebugLogging.Log("Average socket = " + (socketTime / socketCounter++) + ", Elapsed = " + sw.Elapsed);
         return retval;
     }
     else
     {
         return SocketSendReceive(GetViewerURI(), GetOwnerURI(), gadgetURL);
     }
 }
Ejemplo n.º 17
0
        public void LoadAssets()
        {
            // Only do this once per page, and do it only for the last request!
            // should synchronize
            int currentCount = (int)page.Items[OPENSOCIAL_PAGE_REQUESTS];

            page.Items[OPENSOCIAL_PAGE_REQUESTS] = --currentCount;

            DebugLogging.Log("OpenSocialCurrentCount = " + currentCount);
            if (!IsVisible() || currentCount > 0)
            {
                return;
            }

            // trigger the javascript to render gadgets
            HtmlGenericControl body = (HtmlGenericControl)page.Master.FindControl("bodyMaster");

            body.Attributes.Add("onload", "my.init();");

            HtmlLink gadgetscss = new HtmlLink();

            gadgetscss.Href = Root.Domain + "/ORNG/CSS/gadgets.css";
            gadgetscss.Attributes["rel"]   = "stylesheet";
            gadgetscss.Attributes["type"]  = "text/css";
            gadgetscss.Attributes["media"] = "all";
            page.Header.Controls.Add(gadgetscss);

            HtmlGenericControl containerjs = new HtmlGenericControl("script");

            containerjs.Attributes.Add("type", "text/javascript");
            containerjs.Attributes.Add("src", GetContainerJavascriptSrc());
            page.Header.Controls.Add(containerjs);

            HtmlGenericControl gadgetjs = new HtmlGenericControl("script");

            gadgetjs.Attributes.Add("type", "text/javascript");
            gadgetjs.InnerHtml = GetGadgetJavascipt();
            page.Header.Controls.Add(gadgetjs);

            HtmlGenericControl shindigjs = new HtmlGenericControl("script");

            shindigjs.Attributes.Add("type", "text/javascript");
            shindigjs.Attributes.Add("src", Root.Domain + "/ORNG/JavaScript/orng.js");
            page.Header.Controls.Add(shindigjs);
        }
Ejemplo n.º 18
0
        public static ORNGRPCService GetRPCService(Guid guid)
        {
            DebugLogging.Log("ORNGRPCService guid :" + guid);
            ORNGRPCService retval = null;

            foreach (WeakReference wr in managers.ToArray <WeakReference>())
            {
                if (wr.Target == null)
                {
                    DebugLogging.Log("ORNGRPCService removing WeakReference :" + wr);
                    managers.Remove(wr);
                }
                else if (guid.Equals(((ORNGRPCService)wr.Target).om.GetGuid()))
                {
                    retval = wr.Target as ORNGRPCService;
                }
            }
            return(retval);
        }
Ejemplo n.º 19
0
        public static ORNGCallbackResponder GetORNGCallbackResponder(Guid guid, string request)
        {
            DebugLogging.Log("GetORNGCallbackResponder guid :" + guid + ":" + request);
            ORNGCallbackResponder retval = null;

            foreach (WeakReference wr in managers.ToArray <WeakReference>())
            {
                if (wr.Target == null)
                {
                    DebugLogging.Log("GetORNGCallbackResponder removing WeakReference :" + wr);
                    managers.Remove(wr);
                }
                else if (request.Equals(((ORNGCallbackResponder)wr.Target).requestToRespondTo) && guid.Equals(((ORNGCallbackResponder)wr.Target).om.GetGuid()))
                {
                    retval = wr.Target as ORNGCallbackResponder;
                }
            }
            return(retval);
        }
Ejemplo n.º 20
0
        private List <GadgetSpec> GetGadgetSpecifications()
        {
            DebugLogging.Log("OpenSocialManager GetAllDBGadgets " + !noCache);
            Dictionary <string, GadgetSpec> allDBGadgets = GetAllDBGadgets(!noCache);
            List <GadgetSpec> gadgetSpecs = new List <GadgetSpec>();

            // if someone used the sandbox to log in, grab those gadgets, and only those gadget.
            // if a gadget with the same file name is in the DB, merge it in so that we can inherit it's configuruation
            if (page.Session != null && (string)page.Session[ORNG_GADGETS] != null)
            {
                // Add sandbox gadgets if there are any
                // Note that this block of code only gets executed after someone logs in with GadgetSandbox.aspx!
                String   openSocialGadgetURLS = (string)page.Session[ORNG_GADGETS];
                String[] urls = openSocialGadgetURLS.Split(Environment.NewLine.ToCharArray());
                for (int i = 0; i < urls.Length; i++)
                {
                    String openSocialGadgetURL = urls[i];
                    if (openSocialGadgetURL.Length == 0)
                    {
                        continue;
                    }
                    GadgetSpec sandboxGadget = new GadgetSpec(openSocialGadgetURL);
                    // see if we have a gadget with the same file name in the DB, if so use its configuration
                    if (allDBGadgets.ContainsKey(sandboxGadget.GetFileName()))
                    {
                        GadgetSpec gadget = allDBGadgets[sandboxGadget.GetFileName()];
                        gadget.MergeWithUnrecognizedGadget(sandboxGadget);
                        gadgetSpecs.Add(gadget);
                    }
                    else
                    {
                        gadgetSpecs.Add(sandboxGadget);
                    }
                }
            }
            else
            {
                // the normal use case
                // just add in the db gadgets
                gadgetSpecs.AddRange(allDBGadgets.Values);
            }
            return(gadgetSpecs);
        }
Ejemplo n.º 21
0
        public SocketConnectionPool(string server, int port, int minConnections, int maxConnections, int expire, int timeout)
        {
            this.POOL_MAX_SIZE    = maxConnections;
            this.POOL_MIN_SIZE    = minConnections;
            this.EXPIRE_SECONDS   = expire;
            this.RECIEVE_TIMEOUT  = timeout;
            this.server           = server;
            this.port             = port;
            this.availableSockets = new Queue <CustomSocket>();
            for (int i = 0; i < minConnections; i++)
            {
                CustomSocket cachedSocket = ConnectSocket();
                PutSocket(cachedSocket);
            }

            DebugLogging.Log("Connection Pool is initialized" +
                             " with Max Number of " +
                             POOL_MAX_SIZE.ToString() + " And Min number of " +
                             availableSockets.Count.ToString());
        }
Ejemplo n.º 22
0
        private static void LegendaryCheck()
        {
            if (IsLegendaryOnFloor)
            {
                if (!LegendaryDropped)
                {
                    LegendaryDropped = true;

                    Logging.Log("Legendary dropped !");
                    DebugLogging.Log("[LegendaryCheck] " + ItemState(LegendaryObject));
                }

                if (OrganObject != null && OrganObject.Position != BlankVector)
                {
                    Navigator.MoveTo(OrganObject.Position, ItemState(LegendaryObject));
                }
            }
            else if (LegendaryDropped)
            {
                Logging.Log("Legendary acquired !");
                LegendaryDropped = false;
            }
        }
Ejemplo n.º 23
0
        private static void OrganCheck()
        {
            if (IsOrganOnFloor)
            {
                if (!OrganDropped)
                {
                    OrganDropped = true;

                    Logging.Log("Uber Organ dropped !");
                    DebugLogging.Log("[OrganCheck] " + ItemState(OrganObject));
                }

                if (OrganObject != null && OrganObject.Position != BlankVector)
                {
                    Navigator.MoveTo(OrganObject.Position, ItemState(OrganObject));
                }
            }
            else if (OrganDropped)
            {
                Logging.Log("Uber Organ acquired !");
                OrganDropped = false;
            }
        }
Ejemplo n.º 24
0
            public override List <string> getPeople()
            {
                try
                {
                    List <string> peopleURIs    = new List <string>();
                    int           offSet        = 0;
                    Boolean       hasMorePeople = true;
                    while (peopleURIs.Count < searchLimit && hasMorePeople)
                    {
                        searchRequest.SelectSingleNode("/SearchOptions/OutputOptions/Offset").InnerText = "" + offSet;
                        searchRequest.SelectSingleNode("/SearchOptions/OutputOptions/Limit").InnerText  = "" + searchLimit;
                        XmlDocument searchData = new Profiles.Search.Utilities.DataIO().Search(searchRequest, false, false);

                        DebugLogging.Log("SeachCallbackResponse :" + searchRequest.ToString());

                        XmlNodeList people = searchData.GetElementsByTagName("rdf:object");
                        for (int i = 0; i < people.Count; i++)
                        {
                            peopleURIs.Add(people[i].Attributes["rdf:resource"].Value);
                        }
                        // increase offset by amount found
                        XmlNode node = searchData.SelectSingleNode("rdf:RDF/rdf:Description/prns:numberOfConnections", namespaceManager);
                        offSet       += people.Count;
                        hasMorePeople = Convert.ToInt32(node.InnerText) > peopleURIs.Count;
                    }
                    if (peopleURIs.Count > 0)
                    {
                        return(peopleURIs);
                    }
                }
                catch (Exception e)
                {
                    DebugLogging.Log(e.Message);
                }

                return(null);
            }
Ejemplo n.º 25
0
        private OpenSocialManager(string ownerUri, Page page, bool editMode)
        {
            this.guid     = Guid.NewGuid();
            this.isDebug  = page.Session != null && page.Session[ORNG_DEBUG] != null && (bool)page.Session[ORNG_DEBUG];
            this.noCache  = page.Session != null && page.Session[ORNG_NOCACHE] != null && (bool)page.Session[ORNG_NOCACHE];
            this.page     = page;
            this.pageName = page.AppRelativeVirtualPath.Substring(2).ToLower();

            DebugLogging.Log("Creating OpenSocialManager for " + ownerUri + ", " + pageName);
            if (shindigURL == null)
            {
                // do nothing
                return;
            }

            this.ownerUri = ownerUri;
            // in editMode we need to set the viewer to be the same as the owner
            // otherwise, the gadget will not be able to save appData correctly
            if (editMode)
            {
                viewerUri = ownerUri;
            }
            else
            {
                Profiles.Framework.Utilities.SessionManagement sm = new Profiles.Framework.Utilities.SessionManagement();
                // if they have a Profile, use the Profile URI otherwise use the User URI.  This allows admins and other folks without profile pages to use gadgets
                if (sm.Session().PersonURI != null && sm.Session().PersonURI.Trim().Length > 0)
                {
                    viewerUri = sm.Session().PersonURI;
                }
                else
                {
                    viewerUri = sm.Session().UserURI;
                }
                if (viewerUri != null && viewerUri.Trim().Length == 0)
                {
                    viewerUri = null;
                }
            }

            string requestAppId = page.Request.QueryString["appId"];

            foreach (GadgetSpec gadgetSpec in GetGadgetSpecifications())
            {
                // only add ones that are visible in this context!
                if (((requestAppId == null && gadgetSpec.IsEnabled()) || gadgetSpec.GetAppId() == Convert.ToInt32(requestAppId)) && gadgetSpec.Show(viewerUri, ownerUri, GetPageName()))
                {
                    gadgets.Add(new PreparedGadget(gadgetSpec, this));
                }
            }

            // if we are in edit mode, clear the cache
            if (editMode)
            {
                ClearOwnerCache();
            }

            // sort the gadgets
            DebugLogging.Log("Visible Gadget Count : " + gadgets.Count);
            gadgets.Sort();
        }
Ejemplo n.º 26
0
        private void DrawProfilesModule()
        {
            XsltArgumentList args               = new XsltArgumentList();
            long             offset             = 0;
            long             perpage            = 0;
            long             totalcount         = 0;
            long             totalpageremainder = 0;
            long             totalpages         = 0;
            long             startrecord        = 0;
            long             page               = 0;
            string           searchfor          = "";
            string           classgroupuri      = "";
            string           classuri           = "";

            string      fname         = "";
            string      lname         = "";
            string      institution   = "";
            string      department    = "";
            string      division      = "";
            string      sort          = "";
            string      sortdirection = "";
            string      searchrequest = "";
            XmlDocument xmlsearchrequest;

            xmlsearchrequest = new XmlDocument();

            Int16 showcolumns = 0;

            string otherfilters         = "";
            string institutionallexcept = string.Empty;
            string departmentallexcept  = string.Empty;
            string divisionallexcept    = string.Empty;
            string exactphrase          = "false"; // UCSF default value to allow old Mini Search to work


            string searchtype = "";

            Search.Utilities.DataIO data = new Profiles.Search.Utilities.DataIO();

            if (String.IsNullOrEmpty(Request.QueryString["searchrequest"]) == false)
            {
                searchrequest = data.DecryptRequest(Request.QueryString["searchrequest"]);
                xmlsearchrequest.LoadXml(searchrequest);
            }
            else if (Session["searchrequest"] != null)
            {
                searchrequest = Session["searchrequest"].ToString();
                xmlsearchrequest.LoadXml(searchrequest);
            }
            else if (string.IsNullOrEmpty(base.MasterPage.SearchRequest) == false)
            {
                searchrequest = data.DecryptRequest(base.MasterPage.SearchRequest);
                xmlsearchrequest.LoadXml(searchrequest);
            }


            if (String.IsNullOrEmpty(Request.QueryString["searchtype"]) == false)
            {
                searchtype = Request.QueryString["searchtype"];
            }
            else if (String.IsNullOrEmpty(Request.Form["searchtype"]) == false)
            {
                searchtype = Request.Form["searchtype"];
            }


            if (String.IsNullOrEmpty(Request.QueryString["searchfor"]) == false)
            {
                searchfor = Request.QueryString["searchfor"];
                //exactphrase = Request.QueryString["exactphrase"];  This is causing a bug. We test and set this if present later in this block anyway
            }
            else if (String.IsNullOrEmpty(Request.Form["txtSearchFor"]) == false)
            {
                searchfor = Request.Form["txtSearchFor"];
            }
            else if (xmlsearchrequest.ChildNodes.Count > 0)
            {
                try
                {
                    searchfor = xmlsearchrequest.SelectSingleNode("SearchOptions/MatchOptions/SearchString").InnerText;
                }
                catch (Exception)
                {
                    // Do nothing, leave searchfor = null
                }
            }



            if (searchfor == null)
            {
                searchfor = string.Empty;
            }

            if (String.IsNullOrEmpty(Request.QueryString["lname"]) == false)
            {
                lname = Request.QueryString["lname"];
            }
            else
            {
                lname = Request.Form["txtLname"];
            }

            if (lname == null)
            {
                lname = string.Empty;
            }

            if (String.IsNullOrEmpty(Request.QueryString["fname"]) == false)
            {
                fname = Request.QueryString["fname"];
            }
            else
            {
                fname = Request.Form["txtFname"];
            }

            if (fname == null)
            {
                fname = string.Empty;
            }

            if (String.IsNullOrEmpty(Request.QueryString["institution"]) == false)
            {
                institution = Request.QueryString["institution"];
            }

            if (String.IsNullOrEmpty(Request.QueryString["department"]) == false)
            {
                department = Request.QueryString["department"];
            }

            if (String.IsNullOrEmpty(Request.QueryString["division"]) == false)
            {
                division = Request.QueryString["division"];
            }

            if (String.IsNullOrEmpty(Request.QueryString["perpage"]) == false)
            {
                perpage = Convert.ToInt64(Request.QueryString["perpage"]);
                if (!(perpage > 0))
                {
                    perpage = 15;
                }

                //if (String.IsNullOrEmpty(Request.QueryString["perpage"])==false)
                //    perpage = Convert.ToInt64(Request.QueryString["perpage"]);
                //else
                //    perpage = 15;
            }
            else
            {
                perpage = 15; //default
            }

            if (String.IsNullOrEmpty(Request.QueryString["offset"]) == false)
            {
                offset = Convert.ToInt64(Request.QueryString["offset"]);
                //if (Request.QueryString["offset"] != string.Empty)
                //    offset = Convert.ToInt64(Request.QueryString["offset"]);
                //else
                //    offset = 0;
            }
            else
            {
                offset = 0;
            }

            if (String.IsNullOrEmpty(Request.QueryString["page"]) == false)
            {
                page = Convert.ToInt64(Request.QueryString["page"]);
                if (!(page > 0))
                {
                    page = 1;
                }
                //if (Request.QueryString["page"] != string.Empty)
                //    page = Convert.ToInt64(Request.QueryString["page"]);
                //else
                //    page = 1;
            }
            else
            {
                page = 1;
            }


            if (String.IsNullOrEmpty(Request.QueryString["classgroupuri"]) == false)
            {
                classgroupuri = HttpUtility.UrlDecode(Request.QueryString["classgroupuri"]);
            }
            else
            {
                classgroupuri = HttpUtility.UrlDecode(Request.Form["classgroupuri"]);
            }

            if (classgroupuri != null)
            {
                if (classgroupuri.Contains("!"))
                {
                    classgroupuri = classgroupuri.Replace('!', '#');
                }
            }
            else
            {
                classgroupuri = string.Empty;
            }

            if (String.IsNullOrEmpty(Request.QueryString["classuri"]) == false)
            {
                classuri = HttpUtility.UrlDecode(Request.QueryString["classuri"]);
            }
            else
            {
                classuri = HttpUtility.UrlDecode(Request.Form["classuri"]);
            }

            if (classuri != null)
            {
                if (classuri.Contains("!"))
                {
                    classuri = classuri.Replace('!', '#');
                }
            }
            else
            {
                classuri = string.Empty;
            }


            if (String.IsNullOrEmpty(Request.QueryString["sortby"]) == false)
            {
                sort = Request.QueryString["sortby"];
            }

            if (String.IsNullOrEmpty(Request.QueryString["sortdirection"]) == false)
            {
                sortdirection = Request.QueryString["sortdirection"];
            }


            if (String.IsNullOrEmpty(Request.QueryString["showcolumns"]) == false)
            {
                showcolumns = Convert.ToInt16(Request.QueryString["showcolumns"]);
            }
            else
            {
                showcolumns = 1;
            }


            if (String.IsNullOrEmpty(Request.QueryString["otherfilters"]) == false)
            {
                otherfilters = Request.QueryString["otherfilters"];
            }



            if (String.IsNullOrEmpty(Request.QueryString["institutionallexcept"]) == false)
            {
                institutionallexcept = Request.QueryString["institutionallexcept"];
            }


            if (String.IsNullOrEmpty(Request.QueryString["departmentallexcept"]) == false)
            {
                departmentallexcept = Request.QueryString["departmentallexcept"];
            }

            if (String.IsNullOrEmpty(Request.QueryString["divisionallexcept"]) == false)
            {
                divisionallexcept = Request.QueryString["divisionallexcept"];
            }

            if (String.IsNullOrEmpty(Request.QueryString["exactphrase"]) == false)
            {
                exactphrase = Request.QueryString["exactphrase"];
            }


            try
            {
                totalcount = data.GetTotalSearchConnections(this.SearchData, base.Namespaces);

                if (page < 0)
                {
                    page = 1;
                }


                totalpages = Math.DivRem(totalcount, Convert.ToInt64(perpage), out totalpageremainder);

                if (totalpageremainder > 0)
                {
                    totalpages = totalpages + 1;
                }

                if (page > totalpages)
                {
                    page = totalpages;
                }

                startrecord = ((Convert.ToInt32(page) * Convert.ToInt32(perpage)) + 1) - Convert.ToInt32(perpage);

                if (startrecord < 0)
                {
                    startrecord = 1;
                }

                if (searchrequest.Trim() != string.Empty)
                {
                    searchrequest = data.EncryptRequest(searchrequest);
                }

                List <GenericListItem> g = new List <GenericListItem>();
                g = data.GetListOfFilters();

                if (otherfilters.IsNullOrEmpty() && base.BaseData.SelectSingleNode("rdf:RDF/rdf:Description/vivo:overview/SearchOptions/MatchOptions/SearchFiltersList/SearchFilter[@Property='http://profiles.catalyst.harvard.edu/ontology/prns#hasPersonFilter']", base.Namespaces) != null)
                {
                    string s = string.Empty;

                    foreach (XmlNode x in base.BaseData.SelectSingleNode("rdf:RDF/rdf:Description/vivo:overview/SearchOptions/MatchOptions/SearchFiltersList/SearchFilter[@Property='http://profiles.catalyst.harvard.edu/ontology/prns#hasPersonFilter']", base.Namespaces))
                    {
                        s             = data.GetConvertedURIListItem(g, x.InnerText);
                        otherfilters += "," + s;
                    }
                }

                switch (searchtype.ToLower())
                {
                case "everything":
                    xmlsearchrequest = data.SearchRequest(searchfor, exactphrase, classgroupuri, classuri, perpage.ToString(), (startrecord - 1).ToString());
                    break;

                default:
                    xmlsearchrequest = data.SearchRequest(searchfor, exactphrase, fname, lname, institution, institutionallexcept, department, departmentallexcept, division, divisionallexcept, "http://xmlns.com/foaf/0.1/Person", perpage.ToString(), (startrecord - 1).ToString(), sort, sortdirection, otherfilters, "", true, ref searchrequest);
                    HttpContext.Current.Session["PERSON-SEARCH-ADD"] = "true";
                    break;
                }

                this.SearchData               = data.Search(xmlsearchrequest, false);
                this.SearchRequest            = data.EncryptRequest(xmlsearchrequest.OuterXml);
                base.MasterPage.SearchRequest = this.SearchRequest;
                base.MasterPage.RDFData       = this.SearchData;
                base.MasterPage.RDFNamespaces = this.Namespaces;

                // only shows these if we are not doing an everything search, or we are looking at people in the everything search
                if (!"everything".Equals(searchtype.ToLower()) || "http://profiles.catalyst.harvard.edu/ontology/prns#ClassGroupPeople".Equals(classgroupuri))
                {
                    new ORNGSearchRPCService(Page, this.SearchData, xmlsearchrequest, this.Namespaces);
                }
            }
            catch (DisallowedSearchException se)
            {
                litEverythingResults.Text = se.Message;
                return;
            }
            catch (Exception ex)
            {
                ex = ex;
                DebugLogging.Log("ERROR" + ex.Message);
                //for now just flip it back to the defaults. This is if someone keys some funky divide by zero stuff in the URL
                // to try and break the system.
                startrecord = 1;
                perpage     = 15;
            }

            args.AddParam("root", "", Root.Domain);
            args.AddParam("perpage", "", perpage);
            args.AddParam("offset", "", offset);
            args.AddParam("totalpages", "", totalpages);
            args.AddParam("page", "", page);
            args.AddParam("searchfor", "", searchfor);
            args.AddParam("exactphrase", "", exactphrase);
            args.AddParam("classGrpURIpassedin", "", classgroupuri);
            args.AddParam("classURIpassedin", "", classuri);
            args.AddParam("searchrequest", "", this.SearchRequest);

            switch (searchtype.ToLower())
            {
            case "everything":
                litEverythingResults.Text = XslHelper.TransformInMemory(Server.MapPath("~/Search/Modules/SearchResults/EverythingResults.xslt"), args, this.SearchData.OuterXml);
                break;

            case "people":

                args.AddParam("showcolumns", "", showcolumns.ToString());

                if ((showcolumns & 1) == 1)
                {
                    args.AddParam("institution", "", "true");
                }
                else
                {
                    args.AddParam("institution", "", "false");
                }

                if ((showcolumns & 2) == 2)
                {
                    args.AddParam("department", "", "true");
                }
                else
                {
                    args.AddParam("department", "", "false");
                }



                if ((showcolumns & 8) == 8)
                {
                    args.AddParam("facrank", "", "true");
                }
                else
                {
                    args.AddParam("facrank", "", "false");
                }



                //Profiles.Search.Utilities.DataIO dropdowns = new Profiles.Search.Utilities.DataIO();
                if (Convert.ToBoolean(ConfigurationSettings.AppSettings["ShowInstitutions"]) == true)
                {
                    args.AddParam("ShowInstitutions", "", "true");
                }
                else
                {
                    args.AddParam("ShowInstitutions", "", "false");
                }


                if (Convert.ToBoolean(ConfigurationSettings.AppSettings["ShowDepartments"]) == true)
                {
                    args.AddParam("ShowDepartments", "", "true");
                }
                else
                {
                    args.AddParam("ShowDepartments", "", "false");
                }

                //Faculty Rank always shows
                args.AddParam("ShowFacRank", "", "true");

                args.AddParam("currentsort", "", sort);
                args.AddParam("currentsortdirection", "", sortdirection);

                if (base.BaseData.SelectNodes("rdf:RDF/rdf:Description/vivo:overview/SearchDetails/SearchPhraseList", base.Namespaces).Count > 0)
                {
                    args.AddParam("why", "", true);
                }
                else
                {
                    args.AddParam("why", "", false);
                }

                litEverythingResults.Text = HttpUtility.HtmlDecode(XslHelper.TransformInMemory(Server.MapPath("~/Search/Modules/SearchResults/PeopleResults.xslt"), args, this.SearchData.OuterXml));
                break;
            }
        }
        private void DrawProfilesModule()
        {
            XsltArgumentList args               = new XsltArgumentList();
            long             offset             = 0;
            long             perpage            = 0;
            long             totalcount         = 0;
            long             totalpageremainder = 0;
            long             totalpages         = 0;
            long             startrecord        = 0;
            long             page               = 0;
            string           searchfor          = "";
            string           classgroupuri      = "";
            string           classuri           = "";

            string      fname         = "";
            string      lname         = "";
            string      institution   = "";
            string      department    = "";
            string      division      = "";
            string      searchrequest = "";
            XmlDocument xmlsearchrequest;

            xmlsearchrequest = new XmlDocument();


            string otherfilters         = "";
            string institutionallexcept = string.Empty;
            string departmentallexcept  = "0";
            string divisionallexcept    = string.Empty;
            string exactphrase          = "false"; // UCSF default value to allow old Mini Search to work


            string country = (Request.QueryString["country"].IsNullOrEmpty() ? "(All)" : Request.QueryString["country"]);

            department = country;
            string keywordOrPerson = "keyword";



            string searchtype = "";

            Search.Utilities.DataIO data = new Profiles.Search.Utilities.DataIO();


            if (String.IsNullOrEmpty(Request.QueryString["searchtype"]) == false)
            {
                searchtype = Request.QueryString["searchtype"];
            }
            else if (String.IsNullOrEmpty(Request.Form["searchtype"]) == false)
            {
                searchtype = Request.Form["searchtype"];
            }


            if (String.IsNullOrEmpty(Request.QueryString["searchfor"]) == false)
            {
                searchfor = Request.QueryString["searchfor"];
                //exactphrase = Request.QueryString["exactphrase"];  This is causing a bug. We test and set this if present later in this block anyway
            }
            else if (String.IsNullOrEmpty(Request.Form["txtSearchFor"]) == false)
            {
                searchfor = Request.Form["txtSearchFor"];
            }


            if (searchfor == null)
            {
                searchfor = string.Empty;
            }

            if (String.IsNullOrEmpty(Request.QueryString["lname"]) == false)
            {
                lname = Request.QueryString["lname"];
            }
            else
            {
                lname = Request.Form["txtLname"];
            }

            if (lname == null)
            {
                lname = string.Empty;
            }

            if (String.IsNullOrEmpty(Request.QueryString["fname"]) == false)
            {
                fname = Request.QueryString["fname"];
            }
            else
            {
                fname = Request.Form["txtFname"];
            }

            if (fname == null)
            {
                fname = string.Empty;
            }



            if (String.IsNullOrEmpty(Request.QueryString["perpage"]) == false)
            {
                perpage = Convert.ToInt64(Request.QueryString["perpage"]);
                if (!(perpage > 0))
                {
                    perpage = 15;
                }
            }
            else
            {
                perpage = 15; //default
            }

            if (String.IsNullOrEmpty(Request.QueryString["offset"]) == false)
            {
                offset = Convert.ToInt64(Request.QueryString["offset"]);
            }
            else
            {
                offset = 0;
            }

            if (String.IsNullOrEmpty(Request.QueryString["page"]) == false)
            {
                page = Convert.ToInt64(Request.QueryString["page"]);
                if (!(page > 0))
                {
                    page = 1;
                }
            }
            else
            {
                page = 1;
            }


            if (String.IsNullOrEmpty(Request.QueryString["classgroupuri"]) == false)
            {
                classgroupuri = HttpUtility.UrlDecode(Request.QueryString["classgroupuri"]);
            }
            else
            {
                classgroupuri = HttpUtility.UrlDecode(Request.Form["classgroupuri"]);
            }

            if (classgroupuri != null)
            {
                if (classgroupuri.Contains("!"))
                {
                    classgroupuri = classgroupuri.Replace('!', '#');
                }
            }
            else
            {
                classgroupuri = string.Empty;
            }

            if (String.IsNullOrEmpty(Request.QueryString["classuri"]) == false)
            {
                classuri = HttpUtility.UrlDecode(Request.QueryString["classuri"]);
            }
            else
            {
                classuri = HttpUtility.UrlDecode(Request.Form["classuri"]);
            }

            if (classuri != null)
            {
                if (classuri.Contains("!"))
                {
                    classuri = classuri.Replace('!', '#');
                }
            }
            else
            {
                classuri = string.Empty;
            }


            if (String.IsNullOrEmpty(Request.QueryString["otherfilters"]) == false)
            {
                otherfilters = Request.QueryString["otherfilters"];
            }


            try
            {
                totalcount = data.GetTotalSearchConnections(this.SearchData, base.Namespaces);

                if (page < 0)
                {
                    page = 1;
                }


                totalpages = Math.DivRem(totalcount, Convert.ToInt64(perpage), out totalpageremainder);

                if (totalpageremainder > 0)
                {
                    totalpages = totalpages + 1;
                }

                if (page > totalpages)
                {
                    page = totalpages;
                }

                startrecord = ((Convert.ToInt32(page) * Convert.ToInt32(perpage)) + 1) - Convert.ToInt32(perpage);

                if (startrecord < 0)
                {
                    startrecord = 1;
                }

                List <GenericListItem> g = new List <GenericListItem>();
                g = data.GetListOfFilters();

                if (otherfilters.IsNullOrEmpty() && base.BaseData.SelectSingleNode("rdf:RDF/rdf:Description/vivo:overview/SearchOptions/MatchOptions/SearchFiltersList/SearchFilter[@Property='http://profiles.catalyst.harvard.edu/ontology/prns#hasPersonFilter']", base.Namespaces) != null)
                {
                    string s = string.Empty;

                    foreach (XmlNode x in base.BaseData.SelectSingleNode("rdf:RDF/rdf:Description/vivo:overview/SearchOptions/MatchOptions/SearchFiltersList/SearchFilter[@Property='http://profiles.catalyst.harvard.edu/ontology/prns#hasPersonFilter']", base.Namespaces))
                    {
                        s             = data.GetConvertedURIListItem(g, x.InnerText);
                        otherfilters += "," + s;
                    }
                }



                //added this test for search type so we could split the person keyword search into a split to remove the why col for person
                keywordOrPerson = data.SearchType(searchfor);


                if (keywordOrPerson == "person")
                {
                    xmlsearchrequest = data.CovidPersonSearchRequest(searchfor, (startrecord - 1).ToString(), perpage.ToString(), country);
                }
                else
                {
                    xmlsearchrequest = data.SearchRequest(searchfor, exactphrase, fname, lname, institution, institutionallexcept, department, departmentallexcept, division, divisionallexcept, "http://xmlns.com/foaf/0.1/Person", perpage.ToString(), (startrecord - 1).ToString(), otherfilters, "", true, ref searchrequest);
                    HttpContext.Current.Session["PERSON-SEARCH-ADD"] = "true";
                }

                this.SearchData               = data.Search(xmlsearchrequest, false, false);
                this.SearchRequest            = xmlsearchrequest.OuterXml;
                base.MasterPage.SearchRequest = this.SearchRequest;
                base.MasterPage.RDFData       = this.SearchData;
                base.MasterPage.RDFNamespaces = this.Namespaces;
            }
            catch (DisallowedSearchException se)
            {
                litEverythingResults.Text = se.Message;
                return;
            }
            catch (Exception ex)
            {
                ex = ex;
                DebugLogging.Log("ERROR " + ex.Message);
                //for now just flip it back to the defaults. This is if someone keys some funky divide by zero stuff in the URL
                // to try and break the system.
                startrecord = 1;
                perpage     = 15;
            }

            args.AddParam("root", "", Root.Domain);
            args.AddParam("perpage", "", perpage);
            args.AddParam("offset", "", offset);
            args.AddParam("totalpages", "", totalpages);
            args.AddParam("page", "", page);
            args.AddParam("searchfor", "", searchfor);
            args.AddParam("exactphrase", "", exactphrase);
            args.AddParam("classGrpURIpassedin", "", classgroupuri);
            args.AddParam("classURIpassedin", "", classuri);

            switch (searchtype.ToLower())
            {
            case "everything":
                litEverythingResults.Text = XslHelper.TransformInMemory(Server.MapPath("~/Search/Modules/SearchResults/EverythingResults.xslt"), args, this.SearchData.OuterXml);
                break;

            case "people":


                args.AddParam("country", "", country);


                if (keywordOrPerson == "keyword")
                {
                    args.AddParam("why", "", true);
                }
                else
                {
                    args.AddParam("why", "", false);
                }

                litEverythingResults.Text = HttpUtility.HtmlDecode(XslHelper.TransformInMemory(Server.MapPath("~/Search/Modules/SearchResults/PeopleResults.xslt"), args, this.SearchData.OuterXml));
                break;
            }
        }
Ejemplo n.º 28
0
        private OpenSocialManager(string ownerUri, Page page, bool editMode)
        {
            this.guid     = Guid.NewGuid();
            this.isDebug  = page.Session != null && page.Session[OPENSOCIAL_DEBUG] != null && (bool)page.Session[OPENSOCIAL_DEBUG];
            this.noCache  = page.Session != null && page.Session[OPENSOCIAL_NOCACHE] != null && (bool)page.Session[OPENSOCIAL_NOCACHE];
            this.page     = page;
            this.pageName = page.AppRelativeVirtualPath.Substring(2).ToLower();

            DebugLogging.Log("Creating OpenSocialManager for " + ownerUri + ", " + pageName);
            if (shindigURL == null)
            {
                // do nothing
                return;
            }

            this.ownerUri = ownerUri;
            // in editMode we need to set the viewer to be the same as the owner
            // otherwise, the gadget will not be able to save appData correctly
            if (editMode)
            {
                viewerUri = ownerUri;
            }
            else
            {
                Profiles.Framework.Utilities.SessionManagement sm = new Profiles.Framework.Utilities.SessionManagement();
                viewerUri = sm.Session().PersonURI;
                if (viewerUri != null && viewerUri.Trim().Length == 0)
                {
                    viewerUri = null;
                }
            }

            string requestAppId = page.Request.QueryString["appId"];

            DebugLogging.Log("OpenSocialManager GetAllDBGadgets " + !noCache);
            Dictionary <string, GadgetSpec> allDBGadgets = GetAllDBGadgets(!noCache);

            // if someone used the sandbox to log in, grab those gadgets refreshed from the DB
            if (page.Session != null && (string)page.Session[OPENSOCIAL_GADGETS] != null)
            {
                gadgets = GetSandboxGadgets(allDBGadgets, requestAppId);
            }
            else
            {
                DebugLogging.Log("OpenSocialManager GetSecurityToken " + !noCache);
                foreach (GadgetSpec gadgetSpec in allDBGadgets.Values)
                {
                    // only add ones that are visible in this context!
                    int moduleId = 0;
                    if (((requestAppId == null && gadgetSpec.IsEnabled()) || gadgetSpec.GetAppId() == Convert.ToInt32(requestAppId)) && gadgetSpec.Show(viewerUri, ownerUri, GetPageName()))
                    {
                        String securityToken = SocketSendReceive(viewerUri, ownerUri, gadgetSpec.GetGadgetURL());
                        gadgets.Add(new PreparedGadget(gadgetSpec, this, moduleId++, securityToken));
                    }
                }
            }
            // if we are in edit mode, clear the cache
            if (editMode)
            {
                ClearOwnerCache();
            }

            // sort the gadgets
            DebugLogging.Log("Visible Gadget Count : " + gadgets.Count);
            gadgets.Sort();
        }