/// <summary> Serialize the return object, according to the protocol requested </summary> /// <param name="ReturnValue"> Return object to serialize </param> /// <param name="Response"> HTTP Response to write result to </param> /// <param name="Protocol"> Requested protocol type </param> /// <param name="CallbackJsonP"> Callback function for JSON-P </param> protected void Serialize(object ReturnValue, HttpResponse Response, Microservice_Endpoint_Protocol_Enum Protocol, string CallbackJsonP) { if (ReturnValue == null) return; switch (Protocol) { case Microservice_Endpoint_Protocol_Enum.JSON: JSON.Serialize(ReturnValue, Response.Output, Options.ISO8601ExcludeNulls); break; case Microservice_Endpoint_Protocol_Enum.PROTOBUF: Serializer.Serialize(Response.OutputStream, ReturnValue); break; case Microservice_Endpoint_Protocol_Enum.JSON_P: Response.Output.Write(CallbackJsonP + "("); JSON.Serialize(ReturnValue, Response.Output, Options.ISO8601ExcludeNullsJSONP); Response.Output.Write(");"); break; case Microservice_Endpoint_Protocol_Enum.XML: XmlSerializer x = new XmlSerializer(ReturnValue.GetType()); x.Serialize(Response.Output, ReturnValue); break; case Microservice_Endpoint_Protocol_Enum.BINARY: IFormatter binary = new BinaryFormatter(); binary.Serialize(Response.OutputStream, ReturnValue); break; } }
/// <summary> Constructor for a new instance of the Engine_VerbMapping class </summary> /// <param name="Method"> Method within the class specified by the component that should be called to fulfil the request </param> /// <param name="Enabled"> Flag indicates if this endpoint is enabled or disabled </param> /// <param name="Protocol"> Protocol which this endpoint utilizes ( JSON or Protocol Buffer ) </param> /// <param name="RequestType"> Request type expected for this endpoint ( either a GET or a POST ) </param> public Engine_VerbMapping(string Method, bool Enabled, Microservice_Endpoint_Protocol_Enum Protocol, Microservice_Endpoint_RequestType_Enum RequestType) { this.Method = Method; this.Enabled = Enabled; this.Protocol = Protocol; this.RequestType = RequestType; }
/// <summary> Constructor for a new instance of the Engine_VerbMapping class </summary> /// <param name="Method"> Method within the class specified by the component that should be called to fulfil the request </param> /// <param name="Enabled"> Flag indicates if this endpoint is enabled or disabled </param> /// <param name="Protocol"> Protocol which this endpoint utilizes ( JSON or Protocol Buffer ) </param> /// <param name="RequestType"> Request type expected for this endpoint ( either a GET or a POST ) </param> public Engine_VerbMapping(string Method, bool Enabled, Microservice_Endpoint_Protocol_Enum Protocol, Microservice_Endpoint_RequestType_Enum RequestType, string ComponentId, string RestrictionRangeId ) { this.Method = Method; this.Enabled = Enabled; this.Protocol = Protocol; this.RequestType = RequestType; this.ComponentId = ComponentId; this.RestrictionRangeSetId = RestrictionRangeId; }
/// <summary> Gets the administrative setting values, which includes display information /// along with the current value and key </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetAdminSettings(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); try { tracer.Add_Trace("AdministrativeServices.GetAdminSettings", "Pulling dataset from the database"); // Get the complete aggregation DataSet adminSet = Engine_Database.Get_Settings_Complete(true, tracer); // If the returned value from the database was NULL, there was an error if ((adminSet == null) || (adminSet.Tables.Count == 0) || ( adminSet.Tables[0].Rows.Count == 0)) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); if (IsDebug) { Response.Output.WriteLine("DataSet returned from the database was either NULL or empty"); if (Engine_Database.Last_Exception != null) { Response.Output.WriteLine(); Response.Output.WriteLine(Engine_Database.Last_Exception.Message); Response.Output.WriteLine(); Response.Output.WriteLine(Engine_Database.Last_Exception.StackTrace); } Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } Response.StatusCode = 500; return; } tracer.Add_Trace("AdministrativeServices.GetAdminSettings", "Build the list of return objects"); Admin_Setting_Collection returnValue = new Admin_Setting_Collection(); try { DataColumn keyColumn = adminSet.Tables[0].Columns["Setting_Key"]; DataColumn valueColumn = adminSet.Tables[0].Columns["Setting_Value"]; DataColumn tabPageColumn = adminSet.Tables[0].Columns["TabPage"]; DataColumn headingColumn = adminSet.Tables[0].Columns["Heading"]; DataColumn hiddenColumn = adminSet.Tables[0].Columns["Hidden"]; DataColumn reservedColumn = adminSet.Tables[0].Columns["Reserved"]; DataColumn helpColumn = adminSet.Tables[0].Columns["Help"]; DataColumn optionsColumn = adminSet.Tables[0].Columns["Options"]; DataColumn idColumn = adminSet.Tables[0].Columns["SettingID"]; DataColumn dimensionsColumn = adminSet.Tables[0].Columns["Dimensions"]; //Setting_Key, Setting_Value, TabPage, Heading, Hidden, Reserved, Help, Options // Build the return values foreach (DataRow thisRow in adminSet.Tables[0].Rows) { // Build the value object Admin_Setting_Value thisValue = new Admin_Setting_Value { Key = thisRow[keyColumn].ToString(), Value = thisRow[valueColumn] == DBNull.Value ? null : thisRow[valueColumn].ToString(), TabPage = thisRow[tabPageColumn] == DBNull.Value ? null : thisRow[tabPageColumn].ToString(), Heading = thisRow[headingColumn] == DBNull.Value ? null : thisRow[headingColumn].ToString(), Hidden = bool.Parse(thisRow[hiddenColumn].ToString()), Reserved = short.Parse(thisRow[reservedColumn].ToString()), Help = thisRow[helpColumn] == DBNull.Value ? null : thisRow[helpColumn].ToString(), SettingID = short.Parse(thisRow[idColumn].ToString()) }; // Get dimensions, if some were provided if (thisRow[dimensionsColumn] != DBNull.Value) { string dimensions = thisRow[dimensionsColumn].ToString(); if (!String.IsNullOrWhiteSpace(dimensions)) { short testWidth; short testHeight; // Does this include width AND height? if (dimensions.IndexOf("|") >= 0) { string[] splitter = dimensions.Split("|".ToCharArray()); if ((splitter[0].Length > 0) && ( short.TryParse(splitter[0], out testWidth ))) { thisValue.Width = testWidth; if ((splitter[1].Length > 0) && (short.TryParse(splitter[1], out testHeight))) { thisValue.Height = testHeight; } } } else { if (short.TryParse(dimensions, out testWidth)) { thisValue.Width = testWidth; } } } } // Get the options if (thisRow[optionsColumn] != DBNull.Value) { string[] options = thisRow[optionsColumn].ToString().Split("|".ToCharArray()); foreach( string thisOption in options ) thisValue.Add_Option(thisOption.Trim()); } // Add to the return value returnValue.Settings.Add(thisValue); } } catch (Exception ex) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); if (IsDebug) { Response.Output.WriteLine("Error creating the Builder_Settings object from the database tables"); Response.Output.WriteLine(); Response.Output.WriteLine(ex.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ex.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } Response.StatusCode = 500; return; } // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseAdminSettings"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } }
/// <summary> Resolve the URL to a Navigation_Object </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void ResolveUrl(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug ) { Custom_Tracer tracer = new Custom_Tracer(); tracer.Add_Trace("NavigationServices.ResolveUrl", "Parse request and return navigation object"); try { // Pull out the http request tracer.Add_Trace("NavigationServices.ResolveUrl", "Get the current request HttpRequest object"); HttpRequest request = HttpContext.Current.Request; // Get the base url string base_url = request.Url.AbsoluteUri.ToLower().Replace("sobekcm.aspx", "").Replace("sobekcm.svc", ""); if (base_url.IndexOf("?") > 0) base_url = base_url.Substring(0, base_url.IndexOf("?")); tracer.Add_Trace("NavigationServices.ResolveUrl", "Get the navigation object"); Navigation_Object returnValue = get_navigation_object(QueryString, base_url, request.UserLanguages, tracer); tracer.Add_Trace("NavigationServices.ResolveUrl", "Set base url and browser type (may not be useful)"); returnValue.Base_URL = base_url; returnValue.Browser_Type = request.Browser.Type.ToUpper(); tracer.Add_Trace("NavigationServices.ResolveUrl", "Determine if the user host address was a robot request"); returnValue.Set_Robot_Flag(request.UserAgent, request.UserHostAddress); // If this was debug mode, then just write the tracer if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseUrlResolver"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); } catch (Exception ee) { if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } }
/// <summary> Get just the search statistics information for a search or browse </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void Get_Search_Results_Page(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug ) { Custom_Tracer tracer = new Custom_Tracer(); tracer.Add_Trace("ResultsServices.Get_Search_Results_Set", "Parse request to determine search requested"); // Get all the searh field necessary from the query string Results_Arguments args = new Results_Arguments(QueryString); // Was a collection indicated? if (UrlSegments.Count > 0) args.Aggregation = UrlSegments[0]; // Get the aggregation object (we need to know which facets to use, etc.. ) tracer.Add_Trace("ResultsServices.Get_Search_Results_Set", "Get the '" + args.Aggregation + "' item aggregation (for facets, etc..)"); Complete_Item_Aggregation aggr = AggregationServices.get_complete_aggregation(args.Aggregation, true, tracer); // If no aggregation was returned, that is an error if (aggr == null) { tracer.Add_Trace("ResultsServices.Get_Search_Results_Set", "Returned aggregation was NULL... aggregation code may not be valid"); if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error occurred or aggregation '" + args.Aggregation + "' not valid"); Response.StatusCode = 500; return; } // Perform the search tracer.Add_Trace("ResultsServices.Get_Search_Results_Set", "Perform the search"); Search_Results_Statistics resultsStats; List<iSearch_Title_Result> resultsPage; ResultsEndpointErrorEnum error = Get_Search_Results(args, aggr, tracer, out resultsStats, out resultsPage); // Map to the results object title / item tracer.Add_Trace("ResultsServices.Get_Search_Results_Set", "Map to the results object title / item"); List<ResultTitleInfo> results = new List<ResultTitleInfo>(); foreach (iSearch_Title_Result thisResult in resultsPage) { // Create the new rest title object ResultTitleInfo restTitle = new ResultTitleInfo { BibID = thisResult.BibID, MainThumbnail = thisResult.GroupThumbnail, Title = thisResult.GroupTitle }; // add each descriptive field over int field_index = 0; foreach (string metadataTerm in resultsStats.Metadata_Labels) { if ( !String.IsNullOrWhiteSpace(thisResult.Metadata_Display_Values[field_index])) { string termString = thisResult.Metadata_Display_Values[field_index]; ResultTitle_DescriptiveTerm termObj = new ResultTitle_DescriptiveTerm(metadataTerm); if (termString.IndexOf("|") > 0) { string[] splitter = termString.Split("|".ToCharArray()); foreach (string thisSplit in splitter) { if ( !String.IsNullOrWhiteSpace(thisSplit)) termObj.Add_Value(thisSplit.Trim()); } } else { termObj.Add_Value(termString.Trim()); } restTitle.Description.Add(termObj); } field_index++; } // Add each item for (int i = 0; i < thisResult.Item_Count; i++) { iSearch_Item_Result itemResults = thisResult.Get_Item(i); ResultItemInfo newItem = new ResultItemInfo { VID = itemResults.VID, Title = itemResults.Title, Link = itemResults.Link, MainThumbnail = itemResults.MainThumbnail }; restTitle.Items.Add(newItem); } // Add to the array results.Add(restTitle); } // Was this in debug mode? // If this was debug mode, then just write the tracer if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // If an error occurred, return the error switch (error) { case ResultsEndpointErrorEnum.Database_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Database_Timeout_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database timeout"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Solr_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Solr exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Unknown: Response.ContentType = "text/plain"; Response.Output.WriteLine("Unknown error"); Response.StatusCode = 500; return; } // Get the JSON-P callback function string json_callback = "parseResultsSet"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Create the return object ResultSetPage wrappedObject = new ResultSetPage(); wrappedObject.Results = results; wrappedObject.Page = args.Page; // Use the base class to serialize the object according to request protocol Serialize(wrappedObject, Response, Protocol, json_callback); }
/// <summary> Gets the language-specific web skin, by web skin code and language code </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetWebSkin(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug ) { if (UrlSegments.Count > 1) { Custom_Tracer tracer = new Custom_Tracer(); Web_Skin_Object returnValue; try { // Get the code and language from the URL string skinCode = UrlSegments[0]; tracer.Add_Trace("WebSkinServices.GetWebSkin", "Getting skin for '" + skinCode + "'"); string language = UrlSegments[1]; Web_Language_Enum languageEnum = Web_Language_Enum_Converter.Code_To_Enum(language); tracer.Add_Trace("WebSkinServices.GetWebSkin", "Getting skin for language '" + Web_Language_Enum_Converter.Enum_To_Name(languageEnum) + "'"); returnValue = get_web_skin(skinCode, languageEnum, Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language, tracer); // If this was debug mode, then just write the tracer if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } } catch ( Exception ee ) { if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; return; } // Get the JSON-P callback function string json_callback = "parseWebSkin"; if (( Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && ( !String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); } }
/// <summary> Constructor for a new instance of the MicroservicesClient_Endpoint class </summary> /// <param name="URL"> Complete URL for this microservices endpoint </param> /// <param name="Protocol"> Protocol to use when connecting to this endpoint, via the URL </param> public MicroservicesClient_Endpoint(string URL, string Protocol) { this.URL = URL; this.Protocol = String.Compare(Protocol, "protobuf", StringComparison.InvariantCultureIgnoreCase ) == 0 ? Microservice_Endpoint_Protocol_Enum.PROTOBUF : Microservice_Endpoint_Protocol_Enum.JSON; }
/// <summary> Gets the builder-specific settings, including all the builder modules and incoming folders </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetBuilderSettings(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); // Should descriptions be suppressed? bool includeDescriptions = !((!String.IsNullOrEmpty(QueryString["IncludeDescs"])) && (QueryString["IncludeDescs"].ToUpper() == "FALSE")); try { tracer.Add_Trace("BuilderServices.GetBuilderSettings", "Pulling dataset from the database"); // Get the dataset with all the builder settings DataSet builderSet = Engine_Database.Get_Builder_Settings(true, tracer); // If the returned value from the database was NULL, there was an error if ((builderSet == null) || ( builderSet.Tables.Count == 0 )) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); if (IsDebug) { Response.Output.WriteLine("DataSet returned from the database was either NULL or empty"); if (Engine_Database.Last_Exception != null) { Response.Output.WriteLine(); Response.Output.WriteLine(Engine_Database.Last_Exception.Message); Response.Output.WriteLine(); Response.Output.WriteLine(Engine_Database.Last_Exception.StackTrace); } Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } Response.StatusCode = 500; return; } tracer.Add_Trace("BuilderServices.GetBuilderSettings", "Build the builder-specific settings object"); Builder_Settings returnValue = new Builder_Settings(); if (!Builder_Settings_Builder.Refresh(returnValue, builderSet, includeDescriptions, 0)) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); if (IsDebug) { Response.Output.WriteLine("Error creating the Builder_Settings object from the database tables"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } Response.StatusCode = 500; return; } // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseBuilderSettings"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } }
/// <summary> Gets the information about a single digital resource, using the STANDARD mapping set </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetItemBriefStandard(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { brief_item_response("standard", Response, UrlSegments, QueryString, Protocol, IsDebug ); }
/// <summary> Serve the small DESCRIBE html used for adding tags to an item </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void Describe_HTML_Snippet(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); tracer.Add_Trace("ItemServices.Describe_HTML_Snippet", "Serve the small DESCRIBE html for adding tags to an item"); // Determine the number of columns for text areas, depending on browser int actual_cols = 50; //if ((!String.IsNullOrEmpty(CurrentMode.Browser_Type)) && (CurrentMode.Browser_Type.ToUpper().IndexOf("FIREFOX") >= 0)) // actual_cols = 45; // Build the response StringBuilder responseBuilder = new StringBuilder(); responseBuilder.AppendLine("<!-- Add descriptive tage form -->"); responseBuilder.AppendLine("<div class=\"describe_popup_div\" id=\"describe_item_form\" style=\"display:none;\">"); responseBuilder.AppendLine(" <div class=\"popup_title\"><table width=\"100%\"><tr><td align=\"left\">A<span class=\"smaller\">DD </span> I<span class=\"smaller\">TEM </span> D<span class=\"smaller\">ESCRIPTION</span></td><td align=\"right\"> <a href=\"#template\" alt=\"CLOSE\" onclick=\"describe_item_form_close()\">X</a> </td></tr></table></div>"); responseBuilder.AppendLine(" <br />"); responseBuilder.AppendLine(" <fieldset><legend>Enter a description or notes to add to this item </legend>"); responseBuilder.AppendLine(" <br />"); responseBuilder.AppendLine(" <table class=\"popup_table\">"); // Add comments area responseBuilder.Append(" <tr align=\"left\" valign=\"top\"><td><br /><label for=\"add_notes\">Notes:</label></td>"); responseBuilder.AppendLine("<td><textarea rows=\"10\" cols=\"" + actual_cols + "\" name=\"add_tag\" id=\"add_tag\" class=\"add_notes_textarea\" onfocus=\"javascript:textbox_enter('add_tag','add_notes_textarea_focused')\" onblur=\"javascript:textbox_leave('add_tag','add_notes_textarea')\"></textarea></td></tr>"); responseBuilder.AppendLine(" </table>"); responseBuilder.AppendLine(" <br />"); responseBuilder.AppendLine(" </fieldset><br />"); responseBuilder.AppendLine(" <div style=\"text-align:center; font-size:1.3em;\">"); responseBuilder.AppendLine(" <button title=\"Cancel\" class=\"roundbutton\" onclick=\"return describe_item_form_close();\"> CANCEL </button> "); responseBuilder.AppendLine(" <button title=\"Send\" class=\"roundbutton\" type=\"submit\"> SAVE </button>"); responseBuilder.AppendLine(" </div><br />"); responseBuilder.AppendLine("</div>"); responseBuilder.AppendLine(); // Get the return string them string returnValue = responseBuilder.ToString(); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseDescribeHtmlSnippet"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); }
/// <summary> Writes the small snippet of HTML to pop-up when the user selects the SHARE button </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void Share_HTTP_Snippet(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { if (UrlSegments.Count > 1) { Custom_Tracer tracer = new Custom_Tracer(); // Get the BibID and VID string bibid = UrlSegments[0]; string vid = (UrlSegments.Count > 1) ? UrlSegments[1] : "00001"; tracer.Add_Trace("ItemServices.Share_HTTP_Snippet", "Get the full SobekCM_Item object for " + bibid + ":" + vid ); SobekCM_Item sobekItem = getSobekItem(bibid, vid, tracer); // If this item was NULL, there was an error if (sobekItem == null) { tracer.Add_Trace("ItemServices.Share_HTTP_Snippet", "Unable to retrieve the indicated digital resource ( " + bibid + ":" + vid + " )"); Response.ContentType = "text/plain"; Response.StatusCode = 500; Response.Output.WriteLine("Unable to retrieve the indicated digital resource ( " + bibid + ":" + vid + " )"); Response.Output.WriteLine(); // If this was debug mode, then just write the tracer if (IsDebug) { Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } tracer.Add_Trace("ItemServices.Share_HTTP_Snippet", "Building the HTML response"); // Build the response StringBuilder responseBuilder = new StringBuilder(); // Calculate the title and url string title = HttpUtility.HtmlEncode(sobekItem.Bib_Info.Main_Title.Title); string share_url = Engine_ApplicationCache_Gateway.Settings.Servers.Base_URL + "/" + bibid + "/" + vid; responseBuilder.AppendLine("<!-- Share form -->"); responseBuilder.AppendLine("<div id=\"shareform_content\">"); responseBuilder.AppendLine("<a href=\"http://www.facebook.com/share.php?u=" + share_url + "&t=" + title + "\" target=\"FACEBOOK_WINDOW\" onmouseover=\"facebook_share.src='" + Static_Resources_Gateway.Facebook_Share_H_Gif + "'\" onfocus=\"facebook_share.src='" + Static_Resources_Gateway.Facebook_Share_H_Gif + "'\" onmouseout=\"facebook_share.src='" + Static_Resources_Gateway.Facebook_Share_Gif + "'\" onblur=\"facebook_share.src='" + Static_Resources_Gateway.Facebook_Share_Gif + "'\" onclick=\"\"><img class=\"ResultSavePrintButtons\" border=\"0px\" id=\"facebook_share\" name=\"facebook_share\" src=\"" + Static_Resources_Gateway.Facebook_Share_Gif + "\" alt=\"FACEBOOK\" /></a>"); responseBuilder.AppendLine("<a href=\"http://buzz.yahoo.com/buzz?targetUrl=" + share_url + "&headline=" + title + "\" target=\"YAHOOBUZZ_WINDOW\" onmouseover=\"yahoobuzz_share.src='" + Static_Resources_Gateway.Yahoobuzz_Share_H_Gif + "'\" onfocus=\"yahoobuzz_share.src='" + Static_Resources_Gateway.Yahoobuzz_Share_H_Gif + "'\" onmouseout=\"yahoobuzz_share.src='" + Static_Resources_Gateway.Yahoobuzz_Share_Gif + "'\" onblur=\"yahoobuzz_share.src='" + Static_Resources_Gateway.Yahoobuzz_Share_Gif + "'\" onclick=\"\"><img class=\"ResultSavePrintButtons\" border=\"0px\" id=\"yahoobuzz_share\" name=\"yahoobuzz_share\" src=\"" + Static_Resources_Gateway.Yahoobuzz_Share_Gif + "\" alt=\"YAHOO BUZZ\" /></a>"); responseBuilder.AppendLine("<br />"); responseBuilder.AppendLine("<a href=\"http://twitter.com/home?status=Currently reading " + share_url + "\" target=\"TWITTER_WINDOW\" onmouseover=\"twitter_share.src='" + Static_Resources_Gateway.Twitter_Share_H_Gif + "'\" onfocus=\"twitter_share.src='" + Static_Resources_Gateway.Twitter_Share_H_Gif + "'\" onmouseout=\"twitter_share.src='" + Static_Resources_Gateway.Twitter_Share_Gif + "'\" onblur=\"twitter_share.src='" + Static_Resources_Gateway.Twitter_Share_Gif + "'\" onclick=\"\"><img class=\"ResultSavePrintButtons\" border=\"0px\" id=\"twitter_share\" name=\"twitter_share\" src=\"" + Static_Resources_Gateway.Twitter_Share_Gif + "\" alt=\"TWITTER\" /></a>"); responseBuilder.AppendLine("<a href=\"http://www.google.com/bookmarks/mark?op=add&bkmk=" + share_url + "&title=" + title + "\" target=\"GOOGLE_WINDOW\" onmouseover=\"google_share.src='" + Static_Resources_Gateway.Google_Share_H_Gif + "'\" onfocus=\"google_share.src='" + Static_Resources_Gateway.Google_Share_H_Gif + "'\" onmouseout=\"google_share.src='" + Static_Resources_Gateway.Google_Share_Gif + "'\" onblur=\"google_share.src='" + Static_Resources_Gateway.Google_Share_Gif + "'\" onclick=\"\"><img class=\"ResultSavePrintButtons\" border=\"0px\" id=\"google_share\" name=\"google_share\" src=\"" + Static_Resources_Gateway.Google_Share_Gif + "\" alt=\"GOOGLE SHARE\" /></a>"); responseBuilder.AppendLine("<br />"); responseBuilder.AppendLine("<a href=\"http://www.stumbleupon.com/submit?url=" + share_url + "&title=" + title + "\" target=\"STUMBLEUPON_WINDOW\" onmouseover=\"stumbleupon_share.src='" + Static_Resources_Gateway.Stumbleupon_Share_H_Gif + "'\" onfocus=\"stumbleupon_share.src='" + Static_Resources_Gateway.Stumbleupon_Share_H_Gif + "'\" onmouseout=\"stumbleupon_share.src='" + Static_Resources_Gateway.Stumbleupon_Share_Gif + "'\" onblur=\"stumbleupon_share.src='" + Static_Resources_Gateway.Stumbleupon_Share_Gif + "'\" onclick=\"\"><img class=\"ResultSavePrintButtons\" border=\"0px\" id=\"stumbleupon_share\" name=\"stumbleupon_share\" src=\"" + Static_Resources_Gateway.Stumbleupon_Share_Gif + "\" alt=\"STUMBLEUPON\" /></a>"); responseBuilder.AppendLine("<a href=\"http://myweb.yahoo.com/myresults/bookmarklet?t=" + title + "&u=" + share_url + "\" target=\"YAHOO_WINDOW\" onmouseover=\"yahoo_share.src='" + Static_Resources_Gateway.Yahoo_Share_H_Gif + "'\" onfocus=\"yahoo_share.src='" + Static_Resources_Gateway.Yahoo_Share_H_Gif + "'\" onmouseout=\"yahoo_share.src='" + Static_Resources_Gateway.Yahoo_Share_Gif + "'\" onblur=\"yahoo_share.src='" + Static_Resources_Gateway.Yahoo_Share_Gif + "'\" onclick=\"\"><img class=\"ResultSavePrintButtons\" border=\"0px\" id=\"yahoo_share\" name=\"yahoo_share\" src=\"" + Static_Resources_Gateway.Yahoo_Share_Gif + "\" alt=\"YAHOO SHARE\" /></a>"); responseBuilder.AppendLine("<br />"); responseBuilder.AppendLine("<a href=\"http://digg.com/submit?phase=2&url=" + share_url + "&title=" + title + "\" target=\"DIGG_WINDOW\" onmouseover=\"digg_share.src='" + Static_Resources_Gateway.Digg_Share_H_Gif + "'\" onfocus=\"digg_share.src='" + Static_Resources_Gateway.Digg_Share_H_Gif + "'\" onmouseout=\"digg_share.src='" + Static_Resources_Gateway.Digg_Share_Gif + "'\" onblur=\"digg_share.src='" + Static_Resources_Gateway.Digg_Share_Gif + "'\" nclick=\"\"><img class=\"ResultSavePrintButtons\" border=\"0px\" id=\"digg_share\" name=\"digg_share\" src=\"" + Static_Resources_Gateway.Digg_Share_Gif + "\" alt=\"DIGG\" /></a>"); responseBuilder.AppendLine("<a onmouseover=\"favorites_share.src='" + Static_Resources_Gateway.Facebook_Share_H_Gif + "'\" onfocus=\"favorites_share.src='" + Static_Resources_Gateway.Facebook_Share_H_Gif + "'\" onmouseout=\"favorites_share.src='" + Static_Resources_Gateway.Facebook_Share_Gif + "'\" onblur=\"favorites_share.src='" + Static_Resources_Gateway.Facebook_Share_Gif + "'\" onclick=\"javascript:add_to_favorites();\"><img class=\"ResultSavePrintButtons\" border=\"0px\" id=\"favorites_share\" name=\"favorites_share\" src=\"" + Static_Resources_Gateway.Facebook_Share_Gif + "\" alt=\"MY FAVORITES\" /></a>"); responseBuilder.AppendLine("<br />"); responseBuilder.AppendLine("</div>"); responseBuilder.AppendLine(); // Get the return string them string returnValue = responseBuilder.ToString(); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseShareHtmlSnippet"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); return; } // Add the error Response.ContentType = "text/plain"; Response.StatusCode = 400; Response.Output.WriteLine("BibID and VID are required parameters"); Response.Output.WriteLine(); }
/// <summary> Gets the authentication configuration object </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetConfigurationAuthentication(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Get the JSON-P callback function string json_callback = "parseAuthenticationConfig"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(Engine_ApplicationCache_Gateway.Configuration.Authentication, Response, Protocol, json_callback); }
/// <summary> Gets the log from reading all of the configuration files </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetConfigurationLog(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { if (Protocol == Microservice_Endpoint_Protocol_Enum.TEXT) { Response.ContentType = "text/plain"; foreach (string thisLine in Engine_ApplicationCache_Gateway.Configuration.Source.ReadingLog) Response.Output.WriteLine(thisLine); return; } // Get the JSON-P callback function string json_callback = "parseConfigLog"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(Engine_ApplicationCache_Gateway.Configuration.Source.ReadingLog, Response, Protocol, json_callback); }
/// <summary> Gets the citation information for a digital resource </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetItemCitation(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Must at least have one URL segment for the BibID if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); try { // Get the BibID and VID string bibid = UrlSegments[0]; string vid = (UrlSegments.Count > 1) ? UrlSegments[1] : "00001"; tracer.Add_Trace("ItemServices.GetItemCitation", "Requested citation for " + bibid + ":" + vid); if ((vid.Length > 0) && (vid != "00000")) { // Get the brief item tracer.Add_Trace("ItemServices.GetItemCitation", "Build full brief item"); BriefItemInfo returnValue = GetBriefItem(bibid, vid, null, tracer); // Was the item null? if (returnValue == null) { // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("ItemServices.GetItemCitation", "NULL value returned from getBriefItem method"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Create the wrapper to return only basic citation-type information tracer.Add_Trace("ItemServices.GetItemCitation", "Create wrapper class to return only the citation info"); BriefItem_CitationResponse responder = new BriefItem_CitationResponse(returnValue); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseItemCitation"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(responder, Response, Protocol, json_callback); } else { tracer.Add_Trace("ItemServices.GetItemCitation", "Requested VID 00000 - will pull the item group / title"); // Get the brief item tracer.Add_Trace("ItemServices.GetItemCitation", "Build full brief item"); BriefItemInfo returnValue = GetBriefTitle(bibid, null, tracer); // Was the item null? if (returnValue == null) { // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("ItemServices.GetItemCitation", "NULL value returned from getBriefItem method"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Create the wrapper to return only basic citation-type information tracer.Add_Trace("ItemServices.GetItemCitation", "Create wrapper class to return only the citation info"); BriefItem_CitationResponse responder = new BriefItem_CitationResponse(returnValue); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseItemGroupCitation"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(responder, Response, Protocol, json_callback); } } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } } }
/// <summary> Get just the search statistics information for a search or browse </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void NewEndpoint_Results_JSON(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); tracer.Add_Trace("NewEndpointServices.NewEndpoint_Results_JSON", "Parse request to determine search requested"); // Get all the searh field necessary from the query string Results_Arguments args = new Results_Arguments(QueryString); // Additional results arguments // limit number of results int artificial_result_limitation = -1; Boolean isNumeric = false; if (!String.IsNullOrEmpty(QueryString["limit_results"])) { isNumeric = Int32.TryParse(QueryString["limit_results"], out artificial_result_limitation); if (!isNumeric) { artificial_result_limitation = -1; } else if (artificial_result_limitation < 1) { artificial_result_limitation = -1; } } int pagenum = 1; if (!String.IsNullOrEmpty(QueryString["page"])) { isNumeric = Int32.TryParse(QueryString["page"], out pagenum); if (!isNumeric) { pagenum = 1; } else if (pagenum < 1) { pagenum = 1; } else if (pagenum > 1) { artificial_result_limitation = -1; } } // limit title length, in words int artificial_title_length_limitation = -1; if (!String.IsNullOrEmpty(QueryString["title_length"])) { isNumeric = Int32.TryParse(QueryString["title_length"], out artificial_title_length_limitation); if (!isNumeric) { artificial_title_length_limitation = -1; } else if (artificial_title_length_limitation < 1) { artificial_title_length_limitation = -1; } } Boolean include_metadata = false; if (!String.IsNullOrEmpty(QueryString["metadata"])) { include_metadata = true; } // Was a collection indicated? if (UrlSegments.Count > 0) { args.Aggregation = UrlSegments[0]; } // Get the aggregation object (we need to know which facets to use, etc.. ) tracer.Add_Trace("NewEndpointServices.NewEndpoint_Results_JSON", "Get the '" + args.Aggregation + "' item aggregation (for facets, etc..)"); Complete_Item_Aggregation aggr = AggregationServices.get_complete_aggregation(args.Aggregation, true, tracer); // If no aggregation was returned, that is an error if (aggr == null) { tracer.Add_Trace("NewEndpointServices.NewEndpoint_Results_JSON", "Returned aggregation was NULL... aggregation code may not be valid"); if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error occurred or aggregation '" + args.Aggregation + "' not valid"); Response.StatusCode = 500; return; } // Perform the search tracer.Add_Trace("NewEndpointServices.NewEndpoint_Results_JSON", "Perform the search"); Search_Results_Statistics resultsStats; List <iSearch_Title_Result> resultsPage; ResultsEndpointErrorEnum error = Get_Search_Results(args, aggr, false, tracer, out resultsStats, out resultsPage); // Was this in debug mode? // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.Output.WriteLine("{\"stats\":{\"total_items\":\"" + resultsStats.Total_Items + "\",\"total_titles\":\"" + resultsStats.Total_Titles + "\"},"); Response.Output.WriteLine(" \"results\":["); // Map to the results object title / item tracer.Add_Trace("ResultsServices.NewEndpoint_Results_JSON", "Map to the results object title / item"); int items_counter = 0; int resultnum = 0; if (resultsPage != null) { foreach (iSearch_Title_Result thisResult in resultsPage) { // Every results should have an item if (thisResult.Item_Count == 0) { continue; } else { resultnum++; } if (artificial_result_limitation != -1 && resultnum > artificial_result_limitation) { tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Reached limit [" + artificial_result_limitation + "]."); break; } // Was this NOT the first item? if (items_counter > 0) { Response.Output.WriteLine(","); } Response.Output.Write(" "); items_counter++; // add each descriptive field over iSearch_Item_Result itemResult = thisResult.Get_Item(0); string bibid = thisResult.BibID; string title = thisResult.GroupTitle; string vid = itemResult.VID; string thumbnail = itemResult.MainThumbnail; title = Process_Title(title, artificial_title_length_limitation); // {"bibid":"1212", "vid":"00001", "title":"sdsd", "subjects":["subj1", "subj2", "subj3"] }, Response.Output.Write("{ \"bibid\":\"" + bibid + "\", \"vid\":\"" + vid + "\", "); Response.Output.Write("\"title\":\"" + HttpUtility.HtmlEncode(title) + "\","); Response.Output.Write("\"url_item\":\"" + Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_URL + bibid + "/" + vid + "/\","); Response.Output.Write("\"url_thumbnail\":\"" + Engine_ApplicationCache_Gateway.Settings.Servers.Image_URL + SobekFileSystem.AssociFilePath(bibid, vid).Replace("\\", "/") + thumbnail + "\""); int field_index = 0; if (resultsStats.Metadata_Labels.Count > 0 && include_metadata) { foreach (string metadataTerm in resultsStats.Metadata_Labels) { if (!String.IsNullOrWhiteSpace(thisResult.Metadata_Display_Values[field_index])) { // how to display this metadata field? string metadataTermDisplay = metadataTerm.ToLower(); string termString = thisResult.Metadata_Display_Values[field_index]; Response.Output.Write(",\"" + metadataTermDisplay + "\":["); int individual_term_counter = 0; if (termString.IndexOf("|") > 0) { string[] splitter = termString.Split("|".ToCharArray()); foreach (string thisSplit in splitter) { if (!String.IsNullOrWhiteSpace(thisSplit)) { if (individual_term_counter > 0) { Response.Output.Write(", \"" + HttpUtility.HtmlEncode(thisSplit.Trim()) + "\""); } else { Response.Output.Write("\"" + HttpUtility.HtmlEncode(thisSplit.Trim()) + "\""); } individual_term_counter++; } } } else { Response.Output.Write("\"" + HttpUtility.HtmlEncode(termString.Trim()) + "\""); } Response.Output.Write("]"); } field_index++; } } Response.Output.Write("}"); } } Response.Output.WriteLine(); Response.Output.WriteLine(" ]"); Response.Output.WriteLine("} "); // If an error occurred, return the error switch (error) { case ResultsEndpointErrorEnum.Database_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Database_Timeout_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database timeout"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Solr_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Solr exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Unknown: Response.ContentType = "text/plain"; Response.Output.WriteLine("Unknown error"); Response.StatusCode = 500; return; } }
/// <summary> Gets any EAD information related to an item </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetItemEAD(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Must at least have one URL segment for the BibID if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); try { // Get the BibID and VID string bibid = UrlSegments[0]; string vid = (UrlSegments.Count > 1) ? UrlSegments[1] : "00001"; tracer.Add_Trace("ItemServices.GetItemEAD", "Requested ead info for " + bibid + ":" + vid); // Is it a valid BibID/VID, at least in appearance? if ((vid.Length > 0) && (vid != "00000")) { // Get the JSON-P callback function string json_callback = "parseItemEAD"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Just look in the cache for the EAD information EAD_Transfer_Object eadTransferInfo = CachedDataManager.Items.Retrieve_EAD_Info(bibid, vid, tracer); if (eadTransferInfo != null) { tracer.Add_Trace("ItemServices.GetItemEAD", "Found pre-built EAD transfer object in the cache"); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Use the base class to serialize the object according to request protocol Serialize(eadTransferInfo, Response, Protocol, json_callback); } // Get the full SOobekCM_Item object for the provided BibID / VID tracer.Add_Trace("ItemServices.GetItemEAD", "Get the full SobekCM_Item object for this BibID / VID"); SobekCM_Item currentItem = getSobekItem(bibid, vid, tracer); if (currentItem == null) { // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("ItemServices.GetItemEAD", "Could not retrieve the full SobekCM_Item object"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Create the wrapper to return only basic citation-type information tracer.Add_Trace("ItemServices.GetItemEAD", "Create wrapper class to return only the ead info"); EAD_Transfer_Object responder = new EAD_Transfer_Object(); // Transfer all the data over to the EAD transfer object EAD_Info eadInfo = currentItem.Get_Metadata_Module(GlobalVar.PALMM_RIGHTSMD_METADATA_MODULE_KEY) as EAD_Info; if (eadInfo != null) { tracer.Add_Trace("ItemServices.GetItemEAD", "Copy all the source EAD information into the transfer EAD object"); // Copy over the full description responder.Full_Description = eadInfo.Full_Description; // Add all the ead TOC sections if (eadInfo.TOC_Included_Sections != null) { foreach (EAD_TOC_Included_Section tocSection in eadInfo.TOC_Included_Sections) { responder.Add_TOC_Included_Section(tocSection.Internal_Link_Name, tocSection.Section_Title); } } // Copy over all the container portions as well if (eadInfo.Container_Hierarchy != null) { responder.Container_Hierarchy.Type = eadInfo.Container_Hierarchy.Type; responder.Container_Hierarchy.Head = eadInfo.Container_Hierarchy.Head; responder.Container_Hierarchy.Did = ead_copy_did_to_transfer(eadInfo.Container_Hierarchy.Did); if (eadInfo.Container_Hierarchy.Containers != null) { foreach (Container_Info containerInfo in eadInfo.Container_Hierarchy.Containers) { responder.Container_Hierarchy.Containers.Add(ead_copy_container_to_transfer(containerInfo)); } } } } else { tracer.Add_Trace("ItemServices.GetItemEAD", "This existing digital resource has no special EAD information"); } // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Cache this as well, since it appears to be valid CachedDataManager.Items.Store_EAD_Info(bibid, vid, responder, tracer); // Use the base class to serialize the object according to request protocol Serialize(responder, Response, Protocol, json_callback); } else { tracer.Add_Trace("ItemServices.GetItemEAD", "Requested VID 0000 - Invalid"); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } } } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } } }
/// <summary> Get the list of all the recent updates for consumption by the jQuery DataTable.net plug-in </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void Get_Builder_Logs_JDataTable(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); // Get ready to pull the informaiton from the query string which the // jquery datatables library pass in int displayStart; int displayLength; // Get the display start and length from the DataTables generated data URL if (!Int32.TryParse(HttpContext.Current.Request.QueryString["iDisplayStart"], out displayStart)) displayStart = 0; if (!Int32.TryParse(HttpContext.Current.Request.QueryString["iDisplayLength"], out displayLength)) displayLength = 50; // Get the echo value string sEcho = HttpContext.Current.Request.QueryString["sEcho"]; // Look for specific arguments in the URL DateTime? startDate = null; DateTime? endDate = null; string filter = null; bool include_no_work = false; // Check for start date if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["date1"])) { DateTime temp; if (DateTime.TryParse(HttpContext.Current.Request.QueryString["date1"], out temp)) { startDate = new DateTime(temp.Year, temp.Month, temp.Day, 0, 0, 0); } } // Check for end date if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["date2"])) { DateTime temp; if (DateTime.TryParse(HttpContext.Current.Request.QueryString["date2"], out temp)) { endDate = new DateTime(temp.Year, temp.Month, temp.Day, 23, 59, 59); } } // Check for filter if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["filter"])) { filter = HttpContext.Current.Request.QueryString["filter"]; } // Check for flag if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["includeNoWork"])) { bool temp; if (bool.TryParse(HttpContext.Current.Request.QueryString["includeNoWork"], out temp)) { include_no_work = temp; } } // Get the dataset of logs DataSet logs = get_recent_builder_logs(startDate, endDate, filter, include_no_work, tracer); // If null was returned, an error occurred if (logs == null) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Unable to pull builder log from the database"); Response.StatusCode = 500; // If this was debug mode, then just write the tracer if (IsDebug) { Response.Output.WriteLine(); Response.Output.WriteLine(); Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Get the count of results DataTable logTable = logs.Tables[0]; int total_results = logTable.Rows.Count; // If this was set to show ALL results, set some page/length information if (displayLength == -1) { displayStart = 0; displayLength = total_results; } // Start the JSON response Response.Output.WriteLine("{"); Response.Output.WriteLine("\"sEcho\": " + sEcho + ","); Response.Output.WriteLine("\"iTotalRecords\": \"" + total_results + "\","); Response.Output.WriteLine("\"iTotalDisplayRecords\": \"" + total_results + "\","); Response.Output.WriteLine("\"aaData\": ["); // Get the columns DataColumn dateColumn = logTable.Columns["LogDate"]; DataColumn bibVidColumn = logTable.Columns["BibID_VID"]; DataColumn typeColumn = logTable.Columns["LogType"]; DataColumn messageColumn = logTable.Columns["LogMessage"]; // Add the data for the rows to show for (int i = displayStart; (i < displayStart + displayLength) && (i < total_results); i++) { // Start the JSON response for this row DataRow thisRow = logTable.Rows[i]; Response.Output.Write("[\"" + thisRow[dateColumn].ToString().Replace("\"", "'") + "\", "); Response.Output.Write("\"" + thisRow[bibVidColumn].ToString().Replace("\"", "'") + "\", "); Response.Output.Write("\"" + thisRow[typeColumn].ToString().Replace("\"","'") + "\", "); Response.Output.Write("\"" + thisRow[messageColumn].ToString().Replace("\"", "'").Replace(@"\", @"\\").Replace("\n", "\\n").Replace("\r", "") + "\" "); // Finish this row if ((i < displayStart + displayLength - 1) && (i < total_results - 1)) Response.Output.WriteLine("],"); else Response.Output.WriteLine("]"); } Response.Output.WriteLine("]"); Response.Output.WriteLine("}"); }
/// <summary> Writes the small snippet of HTML to pop-up when the user selects the ADD TO BOOKSHELF button </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void Bookshelf_HTTP_Snippet(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); // Try to get the user id int userid; if (!Int32.TryParse(UrlSegments[0], out userid)) { tracer.Add_Trace("ItemServices.Bookshelf_HTTP_Snippet", "UserID is not a valid integer"); Response.ContentType = "text/plain"; Response.StatusCode = 400; Response.Output.WriteLine("UserID is not a valid integer"); Response.Output.WriteLine(); // If this was debug mode, then just write the tracer if (IsDebug) { Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Try to get the user information tracer.Add_Trace("ItemServices.Bookshelf_HTTP_Snippet", "Requested bookshelf HTML snippet for userid " + userid ); User_Object thisUser = Engine_Database.Get_User(userid, tracer); // If null, respond if (thisUser == null) { tracer.Add_Trace("ItemServices.Bookshelf_HTTP_Snippet", "User object returned was NULL.. Invalid UserID"); Response.ContentType = "text/plain"; Response.StatusCode = 400; Response.Output.WriteLine("User object returned was NULL.. Invalid UserID"); Response.Output.WriteLine(); // If this was debug mode, then just write the tracer if (IsDebug) { Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } tracer.Add_Trace("ItemServices.Bookshelf_HTTP_Snippet", "Building the HTML response"); // Build the response StringBuilder responseBuilder = new StringBuilder(); // Determine the number of columns for text areas, depending on browser int actual_cols = 50; //if ((!String.IsNullOrEmpty(CurrentMode.Browser_Type)) && (CurrentMode.Browser_Type.ToUpper().IndexOf("FIREFOX") >= 0)) // actual_cols = 45; responseBuilder.AppendLine("<!-- Add to bookshelf form -->"); responseBuilder.AppendLine("<div id=\"addform_content\" class=\"sbk_PopupForm\" style=\"width:530px;\">"); responseBuilder.AppendLine(" <div class=\"sbk_PopupTitle\"><table style=\"width:100%\"><tr><td style=\"text-align:left;\">Add this item to your Bookshelf</td><td style=\"text-align:right\"> <a href=\"#template\" alt=\"CLOSE\" onclick=\"add_item_form_close()\">X</a> </td></tr></table></div>"); responseBuilder.AppendLine(" <br />"); responseBuilder.AppendLine(" <fieldset><legend>Enter notes for this item in your bookshelf </legend>"); responseBuilder.AppendLine(" <br />"); responseBuilder.AppendLine(" <table class=\"sbk_PopupTable\">"); // Add bookshelf choices responseBuilder.Append(" <tr><td style=\"width:80px\"><label for=\"add_bookshelf\">Bookshelf:</label></td>"); responseBuilder.Append("<td><select class=\"email_bookshelf_input\" name=\"add_bookshelf\" id=\"add_bookshelf\">"); foreach (User_Folder folder in thisUser.All_Folders) { if (folder.Folder_Name.Length > 80) { responseBuilder.Append("<option value=\"" + HttpUtility.HtmlEncode(folder.Folder_Name) + "\">" + HttpUtility.HtmlEncode(folder.Folder_Name.Substring(0, 75)) + "...</option>"); } else { if (folder.Folder_Name != "Submitted Items") { if (folder.Folder_Name == "My Bookshelf") responseBuilder.Append("<option value=\"" + HttpUtility.HtmlEncode(folder.Folder_Name) + "\" selected=\"selected\" >" + HttpUtility.HtmlEncode(folder.Folder_Name) + "</option>"); else responseBuilder.Append("<option value=\"" + HttpUtility.HtmlEncode(folder.Folder_Name) + "\">" + HttpUtility.HtmlEncode(folder.Folder_Name) + "</option>"); } } } responseBuilder.AppendLine("</select></td></tr>"); // Add comments area responseBuilder.Append(" <tr style=\"vertical-align:top\"><td><br /><label for=\"add_notes\">Notes:</label></td>"); responseBuilder.AppendLine("<td><textarea rows=\"6\" cols=\"" + actual_cols + "\" name=\"add_notes\" id=\"add_notes\" class=\"add_notes_textarea\" onfocus=\"javascript:textbox_enter('add_notes','add_notes_textarea_focused')\" onblur=\"javascript:textbox_leave('add_notes','add_notes_textarea')\"></textarea></td></tr>"); responseBuilder.AppendLine(" <tr style=\"vertical-align:top\"><td> </td><td><input type=\"checkbox\" id=\"open_bookshelf\" name=\"open_bookshelf\" value=\"open\" /> <label for=\"open_bookshelf\">Open bookshelf in new window</label></td></tr>"); responseBuilder.AppendLine(" </table>"); responseBuilder.AppendLine(" <br />"); responseBuilder.AppendLine(" </fieldset><br />"); responseBuilder.AppendLine(" <div style=\"text-align:center; font-size:1.3em;\">"); responseBuilder.AppendLine(" <button title=\"Cancel\" class=\"roundbutton\" onclick=\"return add_item_form_close();\"> CANCEL </button> "); responseBuilder.AppendLine(" <button title=\"Send\" class=\"roundbutton\" type=\"submit\"> SAVE </button>"); responseBuilder.AppendLine(" </div><br />"); responseBuilder.AppendLine("</div>"); responseBuilder.AppendLine(); // Get the return string them string returnValue = responseBuilder.ToString(); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseBookshelfHtmlSnippet"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); return; } // Add the error Response.ContentType = "text/plain"; Response.StatusCode = 400; Response.Output.WriteLine("UserID is a required parameter"); Response.Output.WriteLine(); }
/// <summary> Gets the complete (language agnostic) web skin, by web skin code </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetCompleteWebSkin(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug ) { if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); try { string skinCode = UrlSegments[0]; tracer.Add_Trace("WebSkinServices.GetCompleteWebSkin", "Getting skin for '" + skinCode + "'"); Complete_Web_Skin_Object returnValue = get_complete_web_skin(skinCode, tracer); // If this was debug mode, then just write the tracer if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseCompleteSkin"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); } catch (Exception ee) { if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } } }
/// <summary> Gets the list of all files related to an item </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetItemFiles(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Must at least have one URL segment for the BibID if (UrlSegments.Count > 1) { Custom_Tracer tracer = new Custom_Tracer(); try { // Get the BibID and VID string bibid = UrlSegments[0]; string vid = UrlSegments[1]; tracer.Add_Trace("ItemServices.GetItemFiles", "Requested file list for " + bibid + ":" + vid); // Build the brief item tracer.Add_Trace("ItemServices.GetItemFiles", "Building the brief item"); BriefItemInfo briefItem = GetBriefItem(bibid, vid, null, tracer); // Was the item null? if (briefItem == null) { // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("ItemServices.GetItemFiles", "NULL value returned from getBriefItem method"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Look in the cache tracer.Add_Trace("ItemServices.GetItemFiles", "Requesting files from SobekFileSystem"); List<SobekFileSystem_FileInfo> files = SobekFileSystem.GetFiles(briefItem); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseItemFiles"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(files, Response, Protocol, json_callback); } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } } }
/// <summary> [PUBLIC] Get the list of uploaded images for a particular web skin </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> /// <remarks> This REST API should be publicly available for users that are performing administrative work </remarks> public void GetWebSkinUploadedImages(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug ) { if (UrlSegments.Count > 0) { string webSkin = UrlSegments[0]; // Ensure a valid aggregation Complete_Web_Skin_Object skinObject = get_complete_web_skin(webSkin, null); if (skinObject != null) { List<UploadedFileFolderInfo> serverFiles = new List<UploadedFileFolderInfo>(); string design_folder = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + "skins\\" + webSkin + "\\uploads"; if (Directory.Exists(design_folder)) { string foldername = webSkin; string[] files = Directory.GetFiles(design_folder); foreach (string thisFile in files) { string filename = Path.GetFileName(thisFile); string extension = Path.GetExtension(thisFile); // Exclude some files if ((!String.IsNullOrEmpty(extension)) && (extension.ToLower().IndexOf(".db") < 0) && (extension.ToLower().IndexOf("bridge") < 0) && (extension.ToLower().IndexOf("cache") < 0)) { string url = Engine_ApplicationCache_Gateway.Settings.Servers.System_Base_URL + "design/skins/" + webSkin + "/uploads/" + filename; serverFiles.Add(new UploadedFileFolderInfo(url, foldername)); } } } JSON.Serialize(serverFiles, Response.Output, Options.ISO8601ExcludeNulls); } } }
/// <summary> Gets the item's marc record in object format for serialization/deserialization </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetItemMarcRecord(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); string bibid = UrlSegments[0]; string vid = "00001"; if (UrlSegments.Count > 1) vid = UrlSegments[1]; tracer.Add_Trace("ItemServices.GetItemMarcRecord", "Requested MARC record for " + bibid + ":" + vid); // Get the current item first SobekCM_Item sobekItem = getSobekItem(bibid, vid, tracer); // If null, return if (sobekItem == null) { tracer.Add_Trace("ItemServices.GetItemMarcRecord", "Unable to retrieve the indicated digital resource ( " + bibid + ":" + vid + " )"); Response.ContentType = "text/plain"; Response.StatusCode = 500; Response.Output.WriteLine("Unable to retrieve the indicated digital resource ( " + bibid + ":" + vid + " )"); Response.Output.WriteLine(); // If this was debug mode, then just write the tracer if (IsDebug) { Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Create the options dictionary used when saving information to the database, or writing MarcXML string cataloging_source_code = String.Empty; string location_code = String.Empty; string reproduction_agency = String.Empty; string reproduction_place = String.Empty; string system_name = String.Empty; string system_abbreviation = String.Empty; // Pull any settings that exist if (Engine_ApplicationCache_Gateway.Settings.MarcGeneration != null) { if (!String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code)) cataloging_source_code = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code; if (!String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code)) location_code = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code; if (!String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency)) reproduction_agency = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency; if (!String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place)) reproduction_place = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place; } if (!String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.System.System_Name)) system_name = Engine_ApplicationCache_Gateway.Settings.System.System_Name; if (!String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.System.System_Abbreviation)) system_abbreviation = Engine_ApplicationCache_Gateway.Settings.System.System_Abbreviation; // Get the base URL for the thumbnails string thumbnail_base = Engine_ApplicationCache_Gateway.Settings.Servers.Base_URL; // Get all the standard tags tracer.Add_Trace("ItemServices.GetItemMarcRecord", "Creating marc record from valid sobekcm item"); MARC_Record tags = sobekItem.To_MARC_Record(cataloging_source_code, location_code, reproduction_agency, reproduction_place, system_name, system_abbreviation, thumbnail_base); // Now, convert the MARC record from the resource library over to the transfer objects MARC_Transfer_Record transferRecord = new MARC_Transfer_Record(); if (tags != null) { tracer.Add_Trace("ItemServices.GetItemMarcRecord", "Mapping from marc record to transfer marc record"); // Copy over the basic stuff transferRecord.Control_Number = tags.Control_Number; transferRecord.Leader = tags.Leader; // Copy over the fields List<MARC_Field> fields = tags.Sorted_MARC_Tag_List; foreach (MARC_Field thisField in fields) { MARC_Transfer_Field transferField = new MARC_Transfer_Field { Tag = thisField.Tag, Indicator1 = thisField.Indicator1, Indicator2 = thisField.Indicator2 }; if (!String.IsNullOrEmpty(thisField.Control_Field_Value)) transferField.Control_Field_Value = thisField.Control_Field_Value; if (thisField.Subfield_Count > 0) { ReadOnlyCollection<MARC_Subfield> subfields = thisField.Subfields; foreach (MARC_Subfield thisSubfield in subfields) { transferField.Add_Subfield(thisSubfield.Subfield_Code, thisSubfield.Data); } } // Add this transfer field to the transfer record transferRecord.Add_Field(transferField); } } else { tracer.Add_Trace("ItemServices.GetItemMarcRecord", "MARC record returned was NULL"); } // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseMarcRecord"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(transferRecord, Response, Protocol, json_callback); } }
/// <summary> Get just the search statistics information for a search or browse </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void Get_Search_Statistics(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug ) { Custom_Tracer tracer = new Custom_Tracer(); tracer.Add_Trace("ResultsServices.Get_Search_Statistics", "Parse request to determine search requested"); // Get all the searh field necessary from the query string Results_Arguments args = new Results_Arguments(QueryString); // Was a collection indicated? if (UrlSegments.Count > 0) args.Aggregation = UrlSegments[0]; // Get the aggregation object (we need to know which facets to use, etc.. ) tracer.Add_Trace("ResultsServices.Get_Search_Statistics", "Get the '" + args.Aggregation + "' item aggregation (for facets, etc..)"); Complete_Item_Aggregation aggr = AggregationServices.get_complete_aggregation(args.Aggregation, true, tracer); // If no aggregation was returned, that is an error if (aggr == null) { tracer.Add_Trace("ResultsServices.Get_Search_Statistics", "Returned aggregation was NULL... aggregation code may not be valid"); if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error occurred or aggregation '" + args.Aggregation + "' not valid"); Response.StatusCode = 500; return; } // Perform the search tracer.Add_Trace("ResultsServices.Get_Search_Statistics", "Perform the search"); Search_Results_Statistics resultsStats; List<iSearch_Title_Result> resultsPage; ResultsEndpointErrorEnum error = Get_Search_Results(args, aggr, tracer, out resultsStats, out resultsPage); // Was this in debug mode? // If this was debug mode, then just write the tracer if ( IsDebug ) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // If an error occurred, return the error switch (error) { case ResultsEndpointErrorEnum.Database_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Database_Timeout_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database timeout"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Solr_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Solr exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Unknown: Response.ContentType = "text/plain"; Response.Output.WriteLine("Unknown error"); Response.StatusCode = 500; return; } // Get the JSON-P callback function string json_callback = "parseResultsStats"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(resultsStats, Response, Protocol, json_callback); }
/// <summary> Gets the complete (language agnostic) web skin, by web skin code </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetItemRdf(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { if (Protocol == Microservice_Endpoint_Protocol_Enum.XML) { if (UrlSegments.Count > 1) { Custom_Tracer tracer = new Custom_Tracer(); string bibid = UrlSegments[1]; string vid = "00001"; if (UrlSegments.Count > 2) vid = UrlSegments[2]; // Get the current item first SobekCM_Item sobekItem = getSobekItem(bibid, vid, tracer); // If null, return if (sobekItem == null) return; string errorMessage; Dictionary<string, object> options_rdf = new Dictionary<string, object>(); options_rdf["DC_File_ReaderWriter:RDF_Style"] = true; DC_File_ReaderWriter rdfWriter = new DC_File_ReaderWriter(); rdfWriter.Write_Metadata(Response.Output, sobekItem, options_rdf, out errorMessage); } } }
// <summary> Register a user for the conference </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="Protocol"></param> /// <param name="RequestForm"></param> /// <param name="IsDebug"></param> public void Register_User(HttpResponse Response, List<string> UrlSegments, Microservice_Endpoint_Protocol_Enum Protocol, NameValueCollection RequestForm, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); // Add a trace tracer.Add_Trace("CustomServices.Register_User"); // collect the values string eventName = null; string lastName = null; string firstName = null; string email = null; // Collect all the errors StringBuilder requiredValues = new StringBuilder(); // Get and validate the required EVENT posted request string if (String.IsNullOrEmpty(RequestForm["event"])) { requiredValues.Append("\n\tEvent"); } else { eventName = RequestForm["event"]; } // Get and validate the required LAST NAME posted request string if (String.IsNullOrEmpty(RequestForm["lastName"])) { requiredValues.Append("\n\tLast Name"); } else { lastName = RequestForm["lastName"]; } // Get and validate the required FIRST NAME posted request string if (String.IsNullOrEmpty(RequestForm["firstName"])) { requiredValues.Append("\n\tFirst Name"); } else { firstName = RequestForm["firstName"]; } // Get and validate the required EMAIL posted request string if (String.IsNullOrEmpty(RequestForm["email"])) { requiredValues.Append("\n\tEmail"); } else { email = RequestForm["email"]; } // If we are missing some required fields, return a comprehensive error if (requiredValues.Length > 0) { Response.Output.Write("The following fields are required: \n" + requiredValues + "\n\nPlease enter the missing data and select REGISTER again."); Response.StatusCode = 400; return; } // Ensure the email address appears to be valid const string VALID_EMAIL_PATTERN = @"^\s*[\w\-\+_']+(\.[\w\-\+_']+)*\@[A-Za-z0-9]([\w\.-]*[A-Za-z0-9])?\.[A-Za-z][A-Za-z\.]*[A-Za-z]$"; Regex emailCheck = new Regex(VALID_EMAIL_PATTERN, RegexOptions.IgnoreCase); if (( email != null ) && (!emailCheck.IsMatch(email))) { Response.Output.Write("Provided email address is not in the correct format.\n\nPlease correct the email address and select REGISTER again."); Response.StatusCode = 400; return; } // Get the optional values string phone = RequestForm["phone"] ?? String.Empty; string topics = RequestForm["topics"] ?? String.Empty; // Create the SQL connection using (SqlConnection sqlConnect = new SqlConnection("data source=SOB-SQL01\\SOBEK2;initial catalog=sobekrepository;integrated security=Yes;")) { try { sqlConnect.Open(); } catch { Response.Output.Write("Unable to open connection to the database."); Response.StatusCode = 500; return; } // Create the SQL command SqlCommand sqlCommand = new SqlCommand("LOCAL_AddEventRegistration", sqlConnect) { CommandType = CommandType.StoredProcedure }; // Add the parameters sqlCommand.Parameters.AddWithValue("EventID", eventName); sqlCommand.Parameters.AddWithValue("FirstName", firstName); sqlCommand.Parameters.AddWithValue("LastName", lastName); sqlCommand.Parameters.AddWithValue("EmailAddress", email); sqlCommand.Parameters.AddWithValue("Phone", phone); sqlCommand.Parameters.AddWithValue("Notes", String.Empty); sqlCommand.Parameters.AddWithValue("Topics", topics); // Run the command itself try { sqlCommand.ExecuteNonQuery(); } catch { Response.Output.Write("Error executing procedure to add your registration."); Response.StatusCode = 500; return; } // Close the connection (not technical necessary since we put the connection in the // scope of the using brackets.. it would dispose itself anyway) try { sqlConnect.Close(); } catch { Response.Output.Write("Unable to close connection to the database."); Response.StatusCode = 500; return; } } Response.Output.Write("{\"message\":\"You have been registered\",\"success\":true}"); Response.StatusCode = 200; }
/// <summary> Gets the work history related to an item </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetItemTrackingWorkHistory(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Must at least have one URL segment for the BibID if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); try { // Get the BibID and VID string bibid = UrlSegments[0]; string vid = (UrlSegments.Count > 1) ? UrlSegments[1] : "00001"; tracer.Add_Trace("ItemServices.GetItemTrackingWorkHistory", "Requested work history for " + bibid + ":" + vid); // Look in the cache tracer.Add_Trace("ItemServices.GetItemTrackingWorkHistory", "Looking in the cache"); Item_Tracking_Details returnValue = CachedDataManager.Items.Retrieve_Item_Tracking(bibid, vid, tracer); if (returnValue != null) { tracer.Add_Trace("ItemServices.GetItemTrackingWorkHistory", "Found the work history in the cache"); } else { // Return the built list of items tracer.Add_Trace("ItemServices.GetItemTrackingWorkHistory", "Pull the data from the database"); returnValue = Engine_Database.Get_Item_Tracking_Work_History(bibid, vid, tracer); // Was the item null? if (returnValue == null) { // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("ItemServices.GetItemTrackingWorkHistory", "NULL value returned from Get_Item_Tracking_Work_History method"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Store in the cache tracer.Add_Trace("ItemServices.GetItemTrackingWorkHistory", "Storing in the cache"); CachedDataManager.Items.Store_Item_Tracking(bibid, vid, returnValue, tracer); } // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseItemTracking"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(returnValue, Response, Protocol, json_callback); } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } } }
/// <summary> Constructor for a new instance of the MicroservicesClient_Endpoint class </summary> /// <param name="URL"> Complete URL for this microservices endpoint </param> /// <param name="Protocol"> Protocol to use when connecting to this endpoint, via the URL </param> /// <param name="Key"> Lookup key associated with this endpoint </param> public MicroservicesClient_Endpoint(string URL, Microservice_Endpoint_Protocol_Enum Protocol, string Key) { this.URL = URL; this.Protocol = Protocol; this.Key = Key; }
/// <summary> Gets the latest update on the builder status, including the relevant builder /// setting values and updates on the scheduled tasks </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetBuilderStatus(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); try { tracer.Add_Trace("BuilderServices.GetBuilderStatus", "Pulling builder status from the database"); // Get the status Builder_Status builderStatus = Engine_Database.Builder_Get_Recent_Updates(tracer); // If the returned value from the database was NULL, there was an error if (builderStatus == null) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); if (IsDebug) { Response.Output.WriteLine("Builder status object returned from the database was either NULL or empty"); if (Engine_Database.Last_Exception != null) { Response.Output.WriteLine(); Response.Output.WriteLine(Engine_Database.Last_Exception.Message); Response.Output.WriteLine(); Response.Output.WriteLine(Engine_Database.Last_Exception.StackTrace); } Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } Response.StatusCode = 500; return; } tracer.Add_Trace("BuilderServices.GetBuilderStatus", "Successfully built builder status"); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseBuilderStatus"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(builderStatus, Response, Protocol, json_callback); } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } }
/// <summary> Disable an existing plug-in </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void DisablePlugin(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Must at least have one URL segment for the Plugin ID if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); // Get the plugin to enable/disable string plugin_code = UrlSegments[0]; // Create the message to return EnableExtensionMessage responder = new EnableExtensionMessage { Success = true, Message = "Disable request received by the engine" }; // Get this extension from the list of installed plugins ExtensionInfo thisExtension = Engine_ApplicationCache_Gateway.Configuration.Extensions.Get_Extension(plugin_code); // If this was NULL, do nothing else if (thisExtension == null) { responder.Message = "Unable to find the extension indicated."; responder.Success = false; } else { // Set the new flag in the database and get the return message responder.Message = Engine_Database.Plugin_Set_Enabled_Flag(plugin_code, false, tracer); if (responder.Message.IndexOf("error", StringComparison.OrdinalIgnoreCase) >= 0) responder.Success = false; else { // Repull all the configuration information Engine_ApplicationCache_Gateway.RefreshAll(); } } // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parsePluginEnable"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(responder, Response, Protocol, json_callback); } else { Response.ContentType = "text/plain"; Response.Output.WriteLine("The unique plug-in code to enable must be provided"); } }
/// <summary> Gets the information about a single incoming builder folder </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetSingleFolder(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); // Must at least have one URL segment for the BibID if (UrlSegments.Count > 0) { int folderid; if (!Int32.TryParse(UrlSegments[0], out folderid)) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Invalid request - folder id must be an integer"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Invalid request - folder id must be an integer"); Response.StatusCode = 400; return; } try { tracer.Add_Trace("BuilderServices.GetSingleFolder", "Pulling builder folder information by id " + folderid); // Get the status Builder_Source_Folder builderFolder = Engine_Database.Builder_Get_Incoming_Folder(folderid, tracer); // If the returned value from the database was NULL, there was an error if (builderFolder == null) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); if (IsDebug) { Response.Output.WriteLine("Builder folder object returned from the database was either NULL or empty"); if (Engine_Database.Last_Exception != null) { Response.Output.WriteLine(); Response.Output.WriteLine(Engine_Database.Last_Exception.Message); Response.Output.WriteLine(); Response.Output.WriteLine(Engine_Database.Last_Exception.StackTrace); } Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } Response.StatusCode = 500; return; } tracer.Add_Trace("BuilderServices.GetSingleFolder", "Successfully built builder folder"); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Get the JSON-P callback function string json_callback = "parseBuilderFolder"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(builderFolder, Response, Protocol, json_callback); } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } } else { Response.ContentType = "text/plain"; Response.Output.WriteLine("Invalid request - folder id must be included"); Response.StatusCode = 400; } }
/// <summary> Gets the administrative setting values, which includes display information /// along with the current value and key </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetSettings(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Get the JSON-P callback function string json_callback = "parseSettings"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Use the base class to serialize the object according to request protocol Serialize(Engine_ApplicationCache_Gateway.Settings, Response, Protocol, json_callback); }
/// <summary> Get just the search statistics information for a search or browse </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void NewEndpoint_Results_XML(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Parse request to determine search requested"); // Get all the searh field necessary from the query string Results_Arguments args = new Results_Arguments(QueryString); // Additional results arguments // limit number of results int artificial_result_limitation = -1; Boolean isNumeric = false; if (!String.IsNullOrEmpty(QueryString["limit_results"])) { isNumeric = Int32.TryParse(QueryString["limit_results"], out artificial_result_limitation); if (!isNumeric) { artificial_result_limitation = -1; } else if (artificial_result_limitation < 1) { artificial_result_limitation = -1; } } int pagenum = 1; if (!String.IsNullOrEmpty(QueryString["page"])) { isNumeric = Int32.TryParse(QueryString["page"], out pagenum); if (!isNumeric) { pagenum = 1; } else if (pagenum < 1) { pagenum = 1; } else if (pagenum > 1) { artificial_result_limitation = -1; } } // limit title length, in words //int artificial_title_length_limitation = -1; ///if (!String.IsNullOrEmpty(QueryString["title_length"])) //{ // isNumeric = Int32.TryParse(QueryString["title_length"], out artificial_title_length_limitation); // if (!isNumeric) // { // artificial_title_length_limitation = -1; // } /// else if (artificial_title_length_limitation < 1) /// { /// artificial_title_length_limitation = -1; /// } ///} Boolean include_metadata = false; //if (!String.IsNullOrEmpty(QueryString["metadata"])) //{ include_metadata = true; //} // Was a collection indicated? if (UrlSegments.Count > 0) { args.Aggregation = UrlSegments[0]; } // Get the aggregation object (we need to know which facets to use, etc.. ) tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Get the '" + args.Aggregation + "' item aggregation (for facets, etc..)"); Complete_Item_Aggregation aggr = AggregationServices.get_complete_aggregation(args.Aggregation, true, tracer); // If no aggregation was returned, that is an error if (aggr == null) { tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Returned aggregation was NULL... aggregation code may not be valid"); if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error occurred or aggregation '" + args.Aggregation + "' not valid"); Response.StatusCode = 500; return; } // Perform the search tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Perform the search"); Search_Results_Statistics resultsStats; List <iSearch_Title_Result> resultsPage; ResultsEndpointErrorEnum error = Get_Search_Results(args, aggr, false, tracer, out resultsStats, out resultsPage); // Was this in debug mode? // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Debug mode detected"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } try { tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Begin writing the XML result to the response"); Response.Output.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"); int count_pages = (int)Math.Floor((double)resultsStats.Total_Items / 20); if (count_pages == 0) { count_pages = 1; } if (pagenum > count_pages) { pagenum = count_pages; } Response.Output.WriteLine("<results total_items=\"" + resultsStats.Total_Items + "\" total_titles=\"" + resultsStats.Total_Titles + "\" page_count=\"" + count_pages + "\" max_results_per_page=\"20\""); if (artificial_result_limitation != -1) { Response.Output.WriteLine("limit_results=\"" + artificial_result_limitation + "\""); } ///if (artificial_title_length_limitation != -1) ///{ /// Response.Output.WriteLine("title_length=\"" + artificial_title_length_limitation + "\""); ///} Response.Output.WriteLine(">"); // Map to the results object title / item tracer.Add_Trace("ResultsServices.Get_Search_Results_Set", "Map to the results object title / item"); // resultnum int resultnum = 0; if (pagenum > 1) { resultnum = ((pagenum - 1) * 20); } if (resultsPage != null) { foreach (iSearch_Title_Result thisResult in resultsPage) { // Every results should have an item if (thisResult.Item_Count == 0) { continue; } else { resultnum++; } if (artificial_result_limitation != -1 && resultnum > artificial_result_limitation) { tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Reached limit [" + artificial_result_limitation + "]."); break; } // add each descriptive field over iSearch_Item_Result itemResult = thisResult.Get_Item(0); string bibid = thisResult.BibID; string title = thisResult.GroupTitle; string vid = itemResult.VID; string thumbnail = itemResult.MainThumbnail; //title = Process_Title(title, artificial_title_length_limitation); Response.Output.WriteLine(" <result resultnum=\"" + resultnum + "\" bibid=\"" + bibid + "\" vid=\"" + vid + "\">"); Response.Output.WriteLine(" <title>" + HttpUtility.HtmlEncode(title) + "</title>"); Response.Output.WriteLine(" <url_item>" + Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_URL + bibid + "/" + vid + "/</url_item>"); if (!String.IsNullOrEmpty(thumbnail)) { try { Response.Output.WriteLine(" <url_thumbnail>" + Engine_ApplicationCache_Gateway.Settings.Servers.Image_URL + SobekFileSystem.AssociFilePath(bibid, vid).Replace("\\", "/") + thumbnail.Trim() + "</url_thumbnail>"); } catch (Exception ee) { Response.Output.WriteLine("ERROR WRITING THUMBNAIL"); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(ee.StackTrace); } } int field_index = 0; if (resultsStats.Metadata_Labels.Count > 0 && include_metadata) { Response.Output.WriteLine("<metadata>"); foreach (string metadataTerm in resultsStats.Metadata_Labels) { if (!String.IsNullOrWhiteSpace(thisResult.Metadata_Display_Values[field_index])) { // how to display this metadata field? string metadataTermDisplay = metadataTerm.ToLower(); string termString = thisResult.Metadata_Display_Values[field_index]; if (termString.IndexOf("|") > 0) { string[] splitter = termString.Split("|".ToCharArray()); foreach (string thisSplit in splitter) { if (!String.IsNullOrWhiteSpace(thisSplit)) { Response.Output.WriteLine(" <" + metadataTermDisplay + ">" + HttpUtility.HtmlEncode(thisSplit.Trim()) + "</" + metadataTermDisplay + ">"); } } } else { Response.Output.WriteLine(" <" + metadataTermDisplay + ">" + HttpUtility.HtmlEncode(termString.Trim()) + "</" + metadataTermDisplay + ">"); } } field_index++; } Response.Output.WriteLine("</metadata>"); } Response.Output.WriteLine(" </result>"); } } Response.Output.WriteLine("</results>"); tracer.Add_Trace("NewEndpointServices.Get_Search_Results_Set", "Done writing the XML result to the response"); } catch (Exception ee) { Response.Output.Write(ee.Message); Response.Output.Write(ee.StackTrace); } // If an error occurred, return the error switch (error) { case ResultsEndpointErrorEnum.Database_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Database_Timeout_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database timeout"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Solr_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Solr exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Unknown: Response.ContentType = "text/plain"; Response.Output.WriteLine("Unknown error"); Response.StatusCode = 500; return; } }