/// <summary> parse and save incoming message </summary> /// <param name="SendData"> message from page </param> public static void SaveContent(String SendData) { try { //get rid of excess string SendData = SendData.Replace("{\"sendData\": \"", "").Replace("{\"sendData\":\"", ""); //validate if (SendData.Length == 0) return; //ensure we have a geo-spatial module in the digital resource GeoSpatial_Information resourceGeoInfo = currentItem.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information; //if there was no geo-spatial module if (resourceGeoInfo == null) { //create new geo-spatial module, if we do not already have one resourceGeoInfo = new GeoSpatial_Information(); currentItem.Add_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY, resourceGeoInfo); } //get the pages List<abstract_TreeNode> pages = currentItem.Divisions.Physical_Tree.Pages_PreOrder; //create a new list of all the polygons for a resource item Dictionary<string, Page_TreeNode> pageLookup = new Dictionary<string, Page_TreeNode>(); int page_index = 1; foreach (var abstractTreeNode in pages) { var pageNode = (Page_TreeNode) abstractTreeNode; if (pageNode.Label.Length == 0) pageLookup["Page " + page_index] = pageNode; else pageLookup[pageNode.Label] = pageNode; page_index++; } //get the length of incoming message int index1 = SendData.LastIndexOf("~", StringComparison.Ordinal); //split into each save message string[] allSaves = SendData.Substring(0, index1).Split('~'); //hold save type handle string saveTypeHandle; //go through each item to save and check for ovelrays and item only not pois (ORDER does matter because these will be saved to db before pois are saved) foreach (string t in allSaves) { //get the length of save message int index2 = t.LastIndexOf("|", StringComparison.Ordinal); //split into save elements string[] ar = t.Substring(0, index2).Split('|'); //determine the save type handle (position 0 in array) saveTypeHandle = ar[0]; //determine the save type (position 1 in array) string saveType = ar[1]; //based on saveType, parse into objects if (saveTypeHandle == "save") { //handle save based on type switch (saveType) { #region item case "item": //prep incoming lat/long string[] temp1 = ar[2].Split(','); double temp1Lat = Convert.ToDouble(temp1[0].Replace("(", "")); double temp1Long = Convert.ToDouble(temp1[1].Replace(")", "")); ////clear specific geo obj //resourceGeoInfo.Clear_Specific(Convert.ToString(ar[3])); //clear all the previous mains featureTypes (this will work for an item because there is only ever one item) resourceGeoInfo.Clear_NonPOIs(); //add the point obj Coordinate_Point newPoint = new Coordinate_Point(temp1Lat, temp1Long, currentItem.METS_Header.ObjectID, "main"); //add the new point resourceGeoInfo.Add_Point(newPoint); //save to db SobekCM_Database.Save_Digital_Resource(currentItem, options); break; #endregion #region overlay case "overlay": //parse the array id of the page int arrayId = (Convert.ToInt32(ar[2]) - 1); //is this always true (minus one of the human page id)? //add the label to page obj pages[arrayId].Label = ar[3]; //get the geocoordinate object for that pageId GeoSpatial_Information pageGeo = pages[arrayId].Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information; //if there isnt any already there if (pageGeo == null) { //create new pageGeo = new GeoSpatial_Information(); //create a polygon Coordinate_Polygon pagePolygon = new Coordinate_Polygon(); //prep incoming bounds string[] temp2 = ar[4].Split(','); pagePolygon.Clear_Edge_Points(); pagePolygon.Add_Edge_Point(Convert.ToDouble(temp2[0].Replace("(", "")), Convert.ToDouble(temp2[1].Replace(")", ""))); pagePolygon.Add_Edge_Point(Convert.ToDouble(temp2[2].Replace("(", "")), Convert.ToDouble(temp2[3].Replace(")", ""))); pagePolygon.Recalculate_Bounding_Box(); //add the rotation double result; pagePolygon.Rotation = Double.TryParse(ar[6], out result) ? result : 0; //add the featureType (explicitly add to make sure it is there) pagePolygon.FeatureType = "main"; //add the label pagePolygon.Label = ar[3]; //add the polygon type pagePolygon.PolygonType = "rectangle"; //add polygon to pagegeo pageGeo.Add_Polygon(pagePolygon); } else { try { //get current polygon info Coordinate_Polygon pagePolygon = pageGeo.Polygons[0]; //prep incoming bounds string[] temp2 = ar[4].Split(','); pagePolygon.Clear_Edge_Points(); pagePolygon.Add_Edge_Point(Convert.ToDouble(temp2[0].Replace("(", "")), Convert.ToDouble(temp2[1].Replace(")", ""))); pagePolygon.Add_Edge_Point(Convert.ToDouble(temp2[2].Replace("(", "")), Convert.ToDouble(temp2[3].Replace(")", ""))); pagePolygon.Recalculate_Bounding_Box(); //add the rotation double result; pagePolygon.Rotation = Double.TryParse(ar[6], out result) ? result : 0; //add the featureType (explicitly add to make sure it is there) pagePolygon.FeatureType = "main"; //add the label pagePolygon.Label = ar[3]; //add the polygon type pagePolygon.PolygonType = "rectangle"; //clear all previous nonPOIs for this page (NOTE: this will only work if there is only one main page item) pageGeo.Clear_NonPOIs(); //add polygon to pagegeo pageGeo.Add_Polygon(pagePolygon); } catch (Exception) { //there were no polygons try { //make a polygon Coordinate_Polygon pagePolygon = new Coordinate_Polygon(); //prep incoming bounds string[] temp2 = ar[4].Split(','); pagePolygon.Clear_Edge_Points(); pagePolygon.Add_Edge_Point(Convert.ToDouble(temp2[0].Replace("(", "")), Convert.ToDouble(temp2[1].Replace(")", ""))); pagePolygon.Add_Edge_Point(Convert.ToDouble(temp2[2].Replace("(", "")), Convert.ToDouble(temp2[3].Replace(")", ""))); pagePolygon.Recalculate_Bounding_Box(); //add the rotation double result; pagePolygon.Rotation = Double.TryParse(ar[6], out result) ? result : 0; //add the featureType (explicitly add to make sure it is there) pagePolygon.FeatureType = "main"; //add the label pagePolygon.Label = ar[3]; //add the polygon type pagePolygon.PolygonType = "rectangle"; //clear all previous nonPOIs for this page (NOTE: this will only work if there is only one main page item) pageGeo.Clear_NonPOIs(); //add polygon to pagegeo pageGeo.Add_Polygon(pagePolygon); } catch (Exception) { //welp... } } } //add the pagegeo obj pages[arrayId].Add_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY, pageGeo); //save to db SobekCM_Database.Save_Digital_Resource(currentItem, options); break; #endregion } } else { if (saveTypeHandle == "delete") { switch (saveType) { #region item case "item": //clear nonpoipoints resourceGeoInfo.Clear_NonPOIPoints(); //save to db SobekCM_Database.Save_Digital_Resource(currentItem, options); break; #endregion #region overlay case "overlay": try { //parse the array id of the page int arrayId = (Convert.ToInt32(ar[2]) - 1); //is this always true (minus one of the human page id)? //get the geocoordinate object for that pageId GeoSpatial_Information pageGeo = pages[arrayId].Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information; if (pageGeo != null) { Coordinate_Polygon pagePolygon = pageGeo.Polygons[0]; //reset edgepoints pagePolygon.Clear_Edge_Points(); //reset rotation pagePolygon.Rotation = 0; //add the featureType (explicitly add to make sure it is there) pagePolygon.FeatureType = "hidden"; //add the polygon type pagePolygon.PolygonType = "hidden"; //clear all previous nonPOIs for this page (NOTE: this will only work if there is only one main page item) pageGeo.Clear_NonPOIs(); //add polygon to pagegeo pageGeo.Add_Polygon(pagePolygon); } ////if there isnt any already there //if (pageGeo != null) // pageGeo.Remove_Polygon(pageGeo.Polygons[0]); //add the pagegeo obj pages[arrayId].Add_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY, pageGeo); //save to db SobekCM_Database.Save_Digital_Resource(currentItem, options); } catch (Exception) { // } break; #endregion } } } } //check to see if save poi clear has already been fired... bool firedOnce = true; //go through each item to save and check for pois only foreach (string t in allSaves) { //get the length of save message int index2 = t.LastIndexOf("|", StringComparison.Ordinal); //split into save elements string[] ar = t.Substring(0, index2).Split('|'); //determine the save type handle (position 0 in array) saveTypeHandle = ar[0]; //determine the save type (position 1 in array) string saveType = ar[1]; //based on saveType, parse into objects if (saveTypeHandle == "save") { //handle save based on type switch (saveType) { #region poi case "poi": //fixes bug if (firedOnce) { //clear previous poi points resourceGeoInfo.Clear_POIs(); firedOnce = false; } //get specific geometry (KML Standard) switch (ar[2]) { case "marker": //prep incoming lat/long string[] temp2 = ar[4].Split(','); double temp2Lat = Convert.ToDouble(temp2[0].Replace("(", "")); double temp2Long = Convert.ToDouble(temp2[1].Replace(")", "")); //add the new point resourceGeoInfo.Add_Point(temp2Lat, temp2Long, ar[3], "poi"); break; case "circle": //create new circle Coordinate_Circle poiCircle = new Coordinate_Circle {Label = ar[3], Radius = Convert.ToDouble(ar[5]), FeatureType = "poi"}; //add the incoming lat/long string[] temp3 = ar[4].Split(','); poiCircle.Latitude = Convert.ToDouble(temp3[0].Replace("(", "")); poiCircle.Longitude = Convert.ToDouble(temp3[1].Replace(")", "")); //add to the resource obj resourceGeoInfo.Add_Circle(poiCircle); break; case "rectangle": //create new polygon Coordinate_Polygon poiRectangle = new Coordinate_Polygon {Label = ar[3], FeatureType = "poi", PolygonType = "rectangle"}; //add the incoming bounds string[] temp4 = ar[4].Split(','); poiRectangle.Add_Edge_Point(Convert.ToDouble(temp4[0].Replace("(", "")), Convert.ToDouble(temp4[1].Replace(")", ""))); poiRectangle.Add_Edge_Point(Convert.ToDouble(temp4[2].Replace("(", "")), Convert.ToDouble(temp4[3].Replace(")", ""))); poiRectangle.Recalculate_Bounding_Box(); //add to resource obj resourceGeoInfo.Add_Polygon(poiRectangle); break; case "polygon": //create new polygon Coordinate_Polygon poiPolygon = new Coordinate_Polygon {Label = ar[3], FeatureType = "poi"}; //add the edge points for (int i2 = 5; i2 < ar.Length; i2++) { string[] temp5 = ar[i2].Split(','); poiPolygon.Add_Edge_Point(Convert.ToDouble(temp5[0].Replace("(", "")), Convert.ToDouble(temp5[1].Replace(")", ""))); } //add the polygon resourceGeoInfo.Add_Polygon(poiPolygon); break; case "polyline": //create new line Coordinate_Line poiLine = new Coordinate_Line {Label = ar[3], FeatureType = "poi"}; //add the edge points for (int i2 = 5; i2 < ar.Length; i2++) { string[] temp5 = ar[i2].Split(','); poiLine.Add_Point(Convert.ToDouble(temp5[0].Replace("(", "")), Convert.ToDouble(temp5[1].Replace(")", "")), ""); } //add the line resourceGeoInfo.Add_Line(poiLine); break; } break; #endregion } } } #region prep saving dir //create inprocessing directory string userInProcessDirectory = UI_ApplicationCache_Gateway.Settings.User_InProcess_Directory( currentUser, "mapwork"); string backupDirectory = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + currentItem.Web.AssocFilePath + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name; //ensure the user's process directory exists if (!Directory.Exists(userInProcessDirectory)) Directory.CreateDirectory(userInProcessDirectory); //ensure the backup directory exists if (!Directory.Exists(backupDirectory)) Directory.CreateDirectory(backupDirectory); string resource_directory = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + currentItem.Web.AssocFilePath; string current_mets = resource_directory + currentItem.METS_Header.ObjectID + ".mets.xml"; string backup_mets = backupDirectory + "\\" + currentItem.METS_Header.ObjectID + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".mets.xml.BAK"; string metsInProcessFile = userInProcessDirectory + "\\" + currentItem.BibID + "_" + currentItem.VID + ".mets.xml"; #endregion #region Save mets and db //save the item to the temporary location currentItem.Save_METS(userInProcessDirectory + "\\" + currentItem.BibID + "_" + currentItem.VID + ".mets.xml"); //move temp mets to prod File.Copy(metsInProcessFile, current_mets, true); //delete in process mets file File.Delete(metsInProcessFile); //create a backup mets file File.Copy(current_mets, backup_mets, true); #endregion } catch (Exception) { //Custom_Tracer.Add_Trace("MapEdit Save Error"); throw new ApplicationException("MapEdit Save Error"); //throw; } }