This object contains properties of the document. Most of them are for the viewing operation.

These will be used in the various opening/conversion processes on the server that support client-side viewing.

        private void getList(HttpContext context, ViewingSessionProperties viewingSessionProperties, string documentMarkupId)
        {
            //string path= string.Empty;
            var list = new List <Dictionary <string, object> >();

            try
            {
                // generate a list of all of the layerRecord files
                if (Directory.Exists(resourcePath))
                {
                    string[] fileList = Directory.GetFiles(resourcePath);

                    foreach (string filePath in fileList)
                    {
                        var summary = getLayerRecordSummary(filePath, viewingSessionProperties, documentMarkupId);

                        if (summary != null)
                        {
                            list.Add(summary);
                        }
                    }
                }

                list = cleanList(context, list);

                sendResponse(context, (int)HttpStatusCode.OK, list);
            }
            catch (Exception e)
            {
                var error = createJSONError("ServerError2", "", e.Message);
                sendResponse(context, 580, error);
            }
        }
        private Dictionary <string, object> getLayerRecordSummary(String path, ViewingSessionProperties viewingSessionProperties, string documentMarkupId)
        {
            if (File.Exists(path))
            {
                string layerRecordId = "";
                string fileRecord    = Path.GetFileNameWithoutExtension(path);
                if (fileRecord.Contains(documentMarkupId + "_" + viewingSessionProperties.attachmentIndex))
                {
                    layerRecordId = fileRecord.Replace(documentMarkupId + "_" + viewingSessionProperties.attachmentIndex + "_", "");

                    try
                    {
                        string text    = File.ReadAllText(path);
                        var    jsonObj = new Dictionary <string, object>();

                        jsonObj = parseJSON(text);

                        string name = "";
                        if (jsonObj.ContainsKey("name"))
                        {
                            name = (string)jsonObj["name"];
                        }

                        string originalXmlName = "";
                        if (jsonObj.ContainsKey("originalXmlName"))
                        {
                            originalXmlName = (string)jsonObj["originalXmlName"];
                        }

                        var json = new Dictionary <string, object>();
                        json.Add("name", name);
                        json.Add("layerRecordId", layerRecordId);
                        json.Add("originalXmlName", originalXmlName);

                        return(json);
                    }
                    catch (Exception e)
                    {
                        // if there is an error parsing the JSON, we will assume
                        // that this is not a valid JSON file
                        return(null);
                    }
                }
                return(null);
            }

            // the file does not contain a valid layerRecord
            return(null);
        }
        private void getList(HttpContext context, ViewingSessionProperties viewingSessionProperties, string documentMarkupId)
        {
            //string path= string.Empty;
            var list = new List<Dictionary<string, object>>();

            try
            {
                // generate a list of all of the layerRecord files
                if (Directory.Exists(resourcePath))
                {
                    string[] fileList = Directory.GetFiles(resourcePath);

                    foreach (string filePath in fileList)
                    {
                        var summary = getLayerRecordSummary(filePath, viewingSessionProperties, documentMarkupId);

                        if (summary != null)
                        {
                            list.Add(summary);
                        }
                    }
                }

                list = cleanList(context, list);

                sendResponse(context, (int)HttpStatusCode.OK, list);
            }
            catch (Exception e)
            {
                var error = createJSONError("ServerError2", "", e.Message);
                sendResponse(context, 580, error);
            }
        }
        private Dictionary<string, object> getLayerRecordSummary(String path, ViewingSessionProperties viewingSessionProperties, string documentMarkupId)
        {
            if (File.Exists(path))
            {
                string layerRecordId = "";
                string fileRecord = Path.GetFileNameWithoutExtension(path);
                if (fileRecord.Contains(documentMarkupId + "_" + viewingSessionProperties.attachmentIndex))
                {
                    layerRecordId = fileRecord.Replace(documentMarkupId + "_" + viewingSessionProperties.attachmentIndex + "_", "");

                    try
                    {
                        string text = File.ReadAllText(path);
                        var jsonObj = new Dictionary<string, object>();

                        jsonObj = parseJSON(text);

                        string name = "";
                        if (jsonObj.ContainsKey("name"))
                        {
                            name = (string)jsonObj["name"];
                        }

                        string originalXmlName = "";
                        if (jsonObj.ContainsKey("originalXmlName"))
                        {
                            originalXmlName = (string)jsonObj["originalXmlName"];
                        }

                        var json = new Dictionary<string, object>();
                        json.Add("name", name);
                        json.Add("layerRecordId", layerRecordId);
                        json.Add("originalXmlName", originalXmlName);

                        return json;
                    }
                    catch (Exception e)
                    {
                        // if there is an error parsing the JSON, we will assume
                        // that this is not a valid JSON file
                        return null;
                    }
                }
                return null;
            }

            // the file does not contain a valid layerRecord
            return null;
        }
        public List <Dictionary <string, object> > getLayers(string viewingSessionId)
        {
            var    list = new List <Dictionary <string, object> >();
            string path = resourcePath;

            // Perform an HTTP GET request to retrieve properties about the viewing session from PCCIS.
            // The properties will include an identifier of the source document that will be used below
            // to construct the name of file where markups are stored.
            string         uriString = PccConfig.prizmServiceAddress + "/ViewingSession/u" + viewingSessionId;
            HttpWebRequest request   = (HttpWebRequest)WebRequest.Create(uriString);

            request.Method = "GET";
            string responseBody = null;

            request.Headers.Add("acs-api-key", PccConfig.acsApiKey);
            try
            {
                // Send request to PCCIS and get response
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                {
                    responseBody = sr.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                return(null);
            }

            ViewingSessionProperties viewingSessionProperties = serializer.Deserialize <ViewingSessionProperties>(responseBody);

            string documentMarkupId = string.Empty;

            viewingSessionProperties.origin.TryGetValue("documentMarkupId", out documentMarkupId);

            try
            {
                // generate a list of all of the layerRecord files
                if (Directory.Exists(path))
                {
                    string[] fileList = Directory.GetFiles(path);

                    foreach (string filePath in fileList)
                    {
                        // Each summary
                        var summary = getLayerRecordSummary(filePath, viewingSessionProperties, documentMarkupId);

                        if (summary != null)
                        {
                            list.Add(summary);
                        }
                    }
                }

                return(list);
            }
            catch (Exception e)
            {
                // If there was an error getting a list of annotation files for this document
                // Assume there are no valid annotation files for this document
                return(null);
            }
        }
        public void ProcessRequest(HttpContext context, Match match)
        {
            // Environmental Setup
            //PccConfig.LoadConfig("viewer-webtier/pcc.config");

            // Check if this folder exsts, and if it does not, create it
            if (!Directory.Exists(resourcePath))
            {
                Directory.CreateDirectory(resourcePath);
            }

            // find the request method
            string method       = context.Request.RequestType.ToLower();
            string methodHeader = context.Request.Headers["X-HTTP-Method-Override"];

            if (!String.IsNullOrEmpty(methodHeader))
            {
                method = methodHeader.ToLower();
            }

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            string viewingSessionId = match.Groups["ViewingSessionId"].Value;
            // get the annotationsLayer (it could be undefined)
            string layerRecordId = match.Groups["LayerRecordId"].Value;

            // Perform an HTTP GET request to retrieve properties about the viewing session from PCCIS.
            // The properties will include an identifier of the source document that will be used below
            // to construct the name of file where markups are stored.
            string         uriString = PccConfig.prizmServiceAddress + "/ViewingSession/" + viewingSessionId;
            HttpWebRequest request   = (HttpWebRequest)WebRequest.Create(uriString);

            request.Method = "GET";
            string responseBody = null;

            request.Headers.Add("acs-api-key", PccConfig.acsApiKey);
            try
            {
                // Send request to PCCIS and get response
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                {
                    responseBody = sr.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                var json = createJSONError("ServerError1", layerRecordId, e.Message);
                sendResponse(context, (int)HttpStatusCode.NotFound, json);
                return;
            }

            ViewingSessionProperties viewingSessionProperties = serializer.Deserialize <ViewingSessionProperties>(responseBody);

            string documentMarkupId = string.Empty;

            viewingSessionProperties.origin.TryGetValue("documentMarkupId", out documentMarkupId);
            string recordNamePrefix = resourcePath + documentMarkupId + "_" + viewingSessionProperties.attachmentIndex + "_";

            if (String.IsNullOrEmpty(recordNamePrefix))
            {
                //BadGateway = 502
                var json = createJSONError("UnknownRequest", layerRecordId);
                sendResponse(context, (int)HttpStatusCode.BadGateway, json);
                return;
            }


            // add the file extension
            string resourceName = null;

            if (!String.IsNullOrEmpty(layerRecordId))
            {
                resourceName = recordNamePrefix + layerRecordId + ".json";
            }

            string fullPath = resourceName;

            // route to the correct method
            if (String.IsNullOrEmpty(layerRecordId) && method == "get")
            {
                getList(context, viewingSessionProperties, documentMarkupId);
                return;
            }
            else if (String.IsNullOrEmpty(layerRecordId) && method == "post")
            {
                // we are creating a new record, so generate a new layerRecordId
                layerRecordId = generateId();
                fullPath      = recordNamePrefix + layerRecordId + ".json";

                createResource(context, fullPath, layerRecordId);
                return;
            }

            else if (!String.IsNullOrEmpty(layerRecordId) && method == "get")
            {
                getResource(context, resourceName, layerRecordId);
                return;
            }
            else if (!String.IsNullOrEmpty(layerRecordId) && (method == "post" || method == "put"))
            {
                updateResource(context, resourceName, layerRecordId);
                return;
            }
            else if (!String.IsNullOrEmpty(layerRecordId) && method == "delete")
            {
                deleteResource(context, resourceName, layerRecordId);
                return;
            }

            var json1 = createJSONError("UnknownRequest", layerRecordId);

            sendResponse(context, (int)HttpStatusCode.BadRequest, json1);
        }
Пример #7
0
        public override void ProcessRequest(HttpContext context, Match match)
        {
            // Environmental Setup
            //PccConfig.LoadConfig("viewer-webtier/pcc.config");

            // find the request method
            string method       = context.Request.RequestType.ToLower();
            string methodHeader = context.Request.Headers["X-HTTP-Method-Override"];

            if (!String.IsNullOrEmpty(methodHeader))
            {
                method = methodHeader.ToLower();
            }

            if (!(method == "get" || method == "post"))
            {
                // Request is not a get or a post
                sendResponse(context, (int)HttpStatusCode.MethodNotAllowed);
                return;
            }

            string viewingSessionId = GetStringFromUrl(context, match, "DocumentID");
            string userName         = string.Empty;

            // We can check for status of our user's identification in multiple places
            if (context.Request.Headers["username"] != null)
            {
                userName = context.Request.Headers["username"];
            }
            else if (context.Request.QueryString["username"] != null)
            {
                userName = context.Request.QueryString["username"];
            }
            else if (context.Request.Params["username"] != null)
            {
                userName = context.Request.Params["username"];
            }
            else
            {
                sendResponse(context, (int)HttpStatusCode.BadRequest, "No username defined. 1");
                return;
            }

            // Final check to make sure we have a useable user name.
            if (userName == string.Empty)
            {
                sendResponse(context, (int)HttpStatusCode.BadRequest, "No username defined. 2");
                return;
            }

            // Perform an HTTP GET request to retrieve properties about the viewing session from PCCIS.
            // The properties will include an identifier of the source document that will be used below
            // to construct the name of file where markups are stored.
            string         uriString = PccConfig.WebServiceAddress + "/ViewingSession/" + viewingSessionId;
            HttpWebRequest request   = (HttpWebRequest)WebRequest.Create(uriString);

            request.Method = "GET";
            string responseBody = null;

            request.Headers.Add("acs-api-key", PccConfig.ApiKey);
            try
            {
                // Send request to PCCIS and get response
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                {
                    responseBody = sr.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                sendResponse(context, (int)HttpStatusCode.BadGateway, "Bad or expired Viewing Session");
                return;
            }

            ViewingSessionProperties viewingSessionProperties = serializer.Deserialize <ViewingSessionProperties>(responseBody);
            string documentMarkupId = string.Empty;

            viewingSessionProperties.origin.TryGetValue("documentMarkupId", out documentMarkupId);

            if (!String.IsNullOrEmpty(documentMarkupId))
            {
                if (method == "post")
                {
                    // Post is used to update an existin annotation or insert a new one.
                    upsertAnnotation(context, documentMarkupId, userName);
                }
                else if (method == "get")
                {
                    // Get is used to retrieve an annotation
                    selectAnnotaion(context, documentMarkupId, userName);
                }
            }
            else
            {
                // Return an error if the documentMarkupId is not present
                // This means that there was a problem with the response from PCCIS
                sendResponse(context, (int)HttpStatusCode.BadGateway, "Bad Gateway");
                return;
            }
        }