public void ProcessRequest(HttpContext context)
        {
            // Set up the response settings
            context.Response.ContentType = "image/jpeg";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;

            if (!string.IsNullOrEmpty(context.Request.QueryString["NodeID"]))
            {

                // get the id for the image
                Int64 nodeid = Convert.ToInt32(context.Request.QueryString["NodeID"]);
                bool harvarddefault = false;

                if (context.Request.QueryString["HarvardDefault"] != null)
                {
                    harvarddefault = true;
                }

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

                Framework.Utilities.RDFTriple request = new Profiles.Framework.Utilities.RDFTriple(nodeid);

                request.Expand = true;
                Framework.Utilities.Namespace xmlnamespace = new Profiles.Framework.Utilities.Namespace();
                XmlDocument person ;

                person = data.GetRDFData(request);
                XmlNamespaceManager namespaces =  xmlnamespace.LoadNamespaces(person);

                if (person.SelectSingleNode("rdf:RDF/rdf:Description[1]/prns:mainImage/@rdf:resource", namespaces) != null)
                {

                    //Set up the response settings
                    context.Response.ContentType = "image/jpeg";
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.BufferOutput = false;

                    Stream stream = data.GetUserPhotoList(nodeid,harvarddefault);

                    const int buffersize = 1024 * 16;
                    byte[] buffer2 = new byte[buffersize];
                    int count = stream.Read(buffer2, 0, buffersize);
                    while (count > 0)
                    {
                        context.Response.OutputStream.Write(buffer2, 0, count);
                        count = stream.Read(buffer2, 0, buffersize);
                    }

                }
                else
                {

                    context.Response.Write("No Image Found");
                }
            }
        }
示例#2
0
        public void ProcessRequest(HttpContext context)
        {
            // Set up the response settings
            context.Response.ContentType = "image/jpeg";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;

            if (!string.IsNullOrEmpty(context.Request.QueryString["NodeID"]))
            {
                // get the id for the image
                Int64 nodeid         = Convert.ToInt32(context.Request.QueryString["NodeID"]);
                bool  harvarddefault = false;

                if (context.Request.QueryString["HarvardDefault"] != null)
                {
                    harvarddefault = true;
                }

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

                Framework.Utilities.RDFTriple request = new Profiles.Framework.Utilities.RDFTriple(nodeid);

                request.Expand = true;
                Framework.Utilities.Namespace xmlnamespace = new Profiles.Framework.Utilities.Namespace();
                XmlDocument person;

                person = data.GetRDFData(request);
                XmlNamespaceManager namespaces = xmlnamespace.LoadNamespaces(person);

                if (person.SelectSingleNode("rdf:RDF/rdf:Description[1]/prns:mainImage/@rdf:resource", namespaces) != null)
                {
                    //Set up the response settings
                    context.Response.ContentType = "image/jpeg";
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.BufferOutput = false;

                    Stream stream = data.GetUserPhotoList(nodeid, harvarddefault);

                    const int buffersize = 1024 * 16;
                    byte[]    buffer2    = new byte[buffersize];
                    int       count      = stream.Read(buffer2, 0, buffersize);
                    while (count > 0)
                    {
                        context.Response.OutputStream.Write(buffer2, 0, count);
                        count = stream.Read(buffer2, 0, buffersize);
                    }
                }
                else
                {
                    context.Response.Write("No Image Found");
                }
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            Utilities.DataIO data = new Profiles.Profile.Utilities.DataIO();
            // Set up the response settings
            context.Response.ContentType = "image/jpeg";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;

            Int64 nodeid = -1;

            if (!string.IsNullOrEmpty(context.Request.QueryString["NodeID"]))
            {

                // get the id for the image
                nodeid = Convert.ToInt32(context.Request.QueryString["NodeID"]);
            }
            if (nodeid > 0)
            {
                bool thumbnail = false;
                int width = 150;
                int height = 300;
                if (context.Request.QueryString["Thumbnail"] != null)
                {
                    thumbnail = true;
                }
                if (context.Request.QueryString["Width"] != null)
                {
                    width = Convert.ToInt32(context.Request.QueryString["Width"]);
                    height = 2 * width;
                }
                if (context.Request.QueryString["Height"] != null)
                {
                    height = Convert.ToInt32(context.Request.QueryString["Height"]);
                }

                byte[] image = (byte[])Framework.Utilities.Cache.FetchObject(GetCacheKey(nodeid, width, height));

                if (image == null)
                {
                    // stuff below this and if statement is what makes it slow
                    Framework.Utilities.RDFTriple request = new Profiles.Framework.Utilities.RDFTriple(nodeid);

                    request.Expand = true;
                    request.ShowDetails = true;
                    request.ExpandRDFList = "<ExpandRDF Class=\"http://xmlns.com/foaf/0.1/Person\" Property=\"http://vivoweb.org/ontology/core#authorInAuthorship\" Limit=\"1\" />";
                    Framework.Utilities.Namespace xmlnamespace = new Profiles.Framework.Utilities.Namespace();
                    XmlDocument person;

                    person = data.GetRDFData(request);
                    XmlNamespaceManager namespaces = xmlnamespace.LoadNamespaces(person);

                    byte[] rawimage = null;
                    if (person.SelectSingleNode("rdf:RDF/rdf:Description[1]/prns:mainImage/@rdf:resource", namespaces) != null)
                    {
                        rawimage = data.GetUserPhotoList(nodeid);
                    }
                    else if (thumbnail)
                    {
                        rawimage = silhouetteImage;
                    }
                    if (rawimage != null)
                    {
                        Edit.Utilities.DataIO resize = new Profiles.Edit.Utilities.DataIO();
                        image = resize.ResizeImageFile(rawimage, width, height);
                        // we are caching silhouettes many times, but that is OK
                        Framework.Utilities.Cache.Set(GetCacheKey(nodeid, width, height), image, nodeid, request.Session.SessionID);
                    }
                }

                if (image != null)
                {
                    Stream stream = new System.IO.MemoryStream(image);

                    // Set up the response settings
                    context.Response.ContentType = "image/jpeg";
                    context.Response.Cache.SetExpires(DateTime.Now.AddDays(7));
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetValidUntilExpires(true);
                    context.Response.BufferOutput = false;
                    context.Response.AddHeader("Content-Length", stream.Length.ToString());

                    const int buffersize = 1024 * 16;
                    byte[] buffer2 = new byte[buffersize];
                    int count = stream.Read(buffer2, 0, buffersize);
                    while (count > 0)
                    {
                        context.Response.OutputStream.Write(buffer2, 0, count);
                        count = stream.Read(buffer2, 0, buffersize);
                    }
                }
                else
                {
                    context.Response.Write("No Image Found");
                }

            }
        }
示例#4
0
        public void ProcessRequest(HttpContext context)
        {
            Utilities.DataIO data = new Profiles.Profile.Utilities.DataIO();
            // Set up the response settings
            context.Response.ContentType = "image/jpeg";
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.BufferOutput = false;

            Int64 nodeid = -1;

            if (!string.IsNullOrEmpty(context.Request.QueryString["NodeID"]))
            {
                // get the id for the image
                nodeid = Convert.ToInt32(context.Request.QueryString["NodeID"]);
            }
            if (nodeid > 0)
            {
                bool thumbnail = false;
                int  width     = 150;
                int  height    = 300;
                if (context.Request.QueryString["Thumbnail"] != null)
                {
                    thumbnail = true;
                }
                if (context.Request.QueryString["Width"] != null)
                {
                    width  = Convert.ToInt32(context.Request.QueryString["Width"]);
                    height = 2 * width;
                }
                if (context.Request.QueryString["Height"] != null)
                {
                    height = Convert.ToInt32(context.Request.QueryString["Height"]);
                }

                byte[] image = (byte[])Framework.Utilities.Cache.FetchObject(GetCacheKey(nodeid, width, height));

                if (image == null)
                {
                    // stuff below this and if statement is what makes it slow
                    Framework.Utilities.RDFTriple request = new Profiles.Framework.Utilities.RDFTriple(nodeid);

                    byte[] rawimage = null;
                    rawimage = data.GetUserPhotoList(nodeid, request.Session.SessionID);

                    if (thumbnail && rawimage == null)
                    {
                        rawimage = silhouetteImage;
                    }
                    if (rawimage != null)
                    {
                        Edit.Utilities.DataIO resize = new Profiles.Edit.Utilities.DataIO();
                        image = resize.ResizeImageFile(rawimage, width, height);
                        // we are caching silhouettes many times, but that is OK
                        Framework.Utilities.Cache.Set(GetCacheKey(nodeid, width, height), image, nodeid, request.Session.SessionID);
                    }
                }

                if (image != null)
                {
                    Stream stream = new System.IO.MemoryStream(image);

                    // Set up the response settings
                    context.Response.ContentType = "image/jpeg";
                    context.Response.Cache.SetExpires(DateTime.Now.AddDays(7));
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetValidUntilExpires(true);
                    context.Response.BufferOutput = false;
                    context.Response.AddHeader("Content-Length", stream.Length.ToString());

                    const int buffersize = 1024 * 16;
                    byte[]    buffer2    = new byte[buffersize];
                    int       count      = stream.Read(buffer2, 0, buffersize);
                    while (count > 0)
                    {
                        context.Response.OutputStream.Write(buffer2, 0, count);
                        count = stream.Read(buffer2, 0, buffersize);
                    }
                }
                else
                {
                    context.Response.Write("No Image Found");
                }
            }
        }
示例#5
0
        public void ProcessRequest(HttpContext context)
        {
            Utilities.DataIO data = new Profiles.Profile.Utilities.DataIO();
            // Set up the response settings
            context.Response.ContentType = "image/jpeg";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;

            Int64 nodeid = -1;

            if (!string.IsNullOrEmpty(context.Request.QueryString["NodeID"]))
            {
                // get the id for the image
                nodeid = Convert.ToInt32(context.Request.QueryString["NodeID"]);
            }
            if (nodeid > 0)
            {
                bool thumbnail = false;
                int  width     = 150;
                int  height    = 300;
                if (context.Request.QueryString["Thumbnail"] != null)
                {
                    thumbnail = true;
                }
                if (context.Request.QueryString["Width"] != null)
                {
                    width  = Convert.ToInt32(context.Request.QueryString["Width"]);
                    height = 2 * width;
                }
                if (context.Request.QueryString["Height"] != null)
                {
                    height = Convert.ToInt32(context.Request.QueryString["Height"]);
                }

                byte[] image = (byte[])Framework.Utilities.Cache.FetchObject(GetCacheKey(nodeid, width, height));

                if (image == null)
                {
                    // stuff below this and if statement is what makes it slow
                    Framework.Utilities.RDFTriple request = new Profiles.Framework.Utilities.RDFTriple(nodeid);

                    request.Expand        = true;
                    request.ShowDetails   = true;
                    request.ExpandRDFList = "<ExpandRDF Class=\"http://xmlns.com/foaf/0.1/Person\" Property=\"http://vivoweb.org/ontology/core#authorInAuthorship\" Limit=\"1\" />";
                    Framework.Utilities.Namespace xmlnamespace = new Profiles.Framework.Utilities.Namespace();
                    XmlDocument person;

                    person = data.GetRDFData(request);
                    XmlNamespaceManager namespaces = xmlnamespace.LoadNamespaces(person);

                    byte[] rawimage = null;
                    if (person.SelectSingleNode("rdf:RDF/rdf:Description[1]/prns:mainImage/@rdf:resource", namespaces) != null)
                    {
                        rawimage = data.GetUserPhotoList(nodeid);
                    }
                    else if (thumbnail)
                    {
                        rawimage = silhouetteImage;
                    }
                    if (rawimage != null)
                    {
                        Edit.Utilities.DataIO resize = new Profiles.Edit.Utilities.DataIO();
                        image = resize.ResizeImageFile(rawimage, width, height);
                        // we are caching silhouettes many times, but that is OK
                        Framework.Utilities.Cache.Set(GetCacheKey(nodeid, width, height), image, nodeid, request.Session.SessionID);
                    }
                }

                if (image != null)
                {
                    Stream stream = new System.IO.MemoryStream(image);

                    // Set up the response settings
                    context.Response.ContentType = "image/jpeg";
                    context.Response.Cache.SetExpires(DateTime.Now.AddDays(7));
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetValidUntilExpires(true);
                    context.Response.BufferOutput = false;
                    context.Response.AddHeader("Content-Length", stream.Length.ToString());

                    const int buffersize = 1024 * 16;
                    byte[]    buffer2    = new byte[buffersize];
                    int       count      = stream.Read(buffer2, 0, buffersize);
                    while (count > 0)
                    {
                        context.Response.OutputStream.Write(buffer2, 0, count);
                        count = stream.Read(buffer2, 0, buffersize);
                    }
                }
                else
                {
                    context.Response.Write("No Image Found");
                }
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            // Set up the response settings
            context.Response.ContentType = "image/jpeg";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;

            Utilities.DataIO data = new Profiles.Profile.Utilities.DataIO();
            Int64 nodeid = -1;
            if (!string.IsNullOrEmpty(context.Request.QueryString["NodeID"]))
            {
                // get the id for the image
                nodeid = Convert.ToInt32(context.Request.QueryString["NodeID"]);
            }
            else if (!string.IsNullOrEmpty(context.Request.QueryString["person"]))
            {
                // UCSF.  Allow old id to work
                nodeid = data.GetNodeID(Convert.ToInt32(context.Request.QueryString["person"].ToString()));
            }

            if (nodeid > 0)
            {
                //Set up the response settings
                context.Response.ContentType = "image/jpeg";
                context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.BufferOutput = false;

                Stream stream = data.GetUserPhotoList(nodeid);

                // UCSF show silhouette if we have no image and this is in the URL
                // note that if the length is 4 then it is going to be the word "null".
                if (stream.Length == 4 && "True".Equals(context.Request.QueryString["ShowSilhouetteAsDefault"]))
                {
                    // It's OK that this isn't synchronized even though it would be cleaner if it were
                    if (silhouetteImage == null)
                    {
                        // this method is limited to 2^32 byte files (4.2 GB)
                        FileStream fs = File.OpenRead(AppDomain.CurrentDomain.BaseDirectory + "/Profile/Images/default_img.png");
                        try
                        {
                            silhouetteImage = new byte[fs.Length];
                            fs.Read(silhouetteImage, 0, Convert.ToInt32(fs.Length));
                        }
                        finally
                        {
                            fs.Close();
                        }
                    }
                    // added by UCSF
                    stream = new System.IO.MemoryStream(silhouetteImage);
                }

                // added by UCSF
                context.Response.AddHeader("Content-Length", stream.Length.ToString());

                const int buffersize = 1024 * 16;
                byte[] buffer2 = new byte[buffersize];
                int count = stream.Read(buffer2, 0, buffersize);
                while (count > 0)
                {
                    context.Response.OutputStream.Write(buffer2, 0, count);
                    count = stream.Read(buffer2, 0, buffersize);
                }

            }
        }