Ejemplo n.º 1
0
 /// <summary> Add a single, completely built Cirlce associated with this digital resource </summary>
 /// <param name="Circle"> Coordinate Circle object associated with this digital resource </param>
 public void Add_Circle(Coordinate_Circle Circle)
 {
     circles.Add(Circle);
 }
 /// <summary> Add a single, completely built Cirlce associated with this digital resource </summary>
 /// <param name="Circle"> Coordinate Circle object associated with this digital resource </param>
 public void Add_Circle(Coordinate_Circle Circle)
 {
     circles.Add(Circle);
 }
        private bool Read_Metadata_Section(XmlReader Input_XmlReader, GeoSpatial_Information geoInfo, Dictionary<string, object> Options)
        {
            do // Loop through reading each XML node
            {
                // get the right division information based on node type
                if (Input_XmlReader.NodeType == XmlNodeType.Element) //if it is an element
                {
                    switch (Input_XmlReader.Name) //get name of
                    {
                        case "gml:Point": //is a point
                            //read the featureType
                            string pointFeatureType = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("featureType"))
                                pointFeatureType = Input_XmlReader.Value;
                            //read the label
                            string pointLabel = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("label"))
                                pointLabel = Input_XmlReader.Value;
                            //get the rest of the information
                            do
                            {
                                //check to see if end of element
                                if (Input_XmlReader.NodeType == XmlNodeType.EndElement && Input_XmlReader.Name == "gml:Point")
                                    break;
                                //if it is an element
                                if (Input_XmlReader.NodeType == XmlNodeType.Element)
                                {
                                    //determine the name of that element
                                    switch (Input_XmlReader.Name)
                                    {
                                        //if it is the coordinates
                                        case "gml:Coordinates":
                                            Input_XmlReader.Read();
                                            if ((Input_XmlReader.NodeType == XmlNodeType.Text) && (Input_XmlReader.Value.Trim().Length > 0))
                                            {
                                                //get coordinates
                                                string result = Convert.ToString(Input_XmlReader.Value);
                                                var items = result.Split(',');
                                                double latitude = double.Parse(items[0]);
                                                double longitude = double.Parse(items[1]);
                                                //add point to geo obj
                                                geoInfo.Add_Point(latitude, longitude, pointLabel, pointFeatureType);
                                            }
                                            break;
                                    }
                                }
                            } while (Input_XmlReader.Read());
                            break;
                        case "gml:Line": //is a line
                            //read the featureType
                            string lineFeatureType = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("featureType"))
                                lineFeatureType = Input_XmlReader.Value;
                            //read the label
                            string lineLabel = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("label"))
                                lineLabel = Input_XmlReader.Value;
                            //get the rest
                            do
                            {
                                //check to see if end of element
                                if (Input_XmlReader.NodeType == XmlNodeType.EndElement && Input_XmlReader.Name == "gml:Line")
                                    break;
                                //if it is an element
                                if (Input_XmlReader.NodeType == XmlNodeType.Element)
                                {
                                    //determine the name of that element
                                    switch (Input_XmlReader.Name)
                                    {
                                        //if it is the coordinates
                                        case "gml:Coordinates":
                                            Input_XmlReader.Read();
                                            if ((Input_XmlReader.NodeType == XmlNodeType.Text) && (Input_XmlReader.Value.Trim().Length > 0))
                                            {
                                                // Parse the string into a collection of doubles, which represents lats AND longs
                                                List<double> latLongs = new List<double>();
                                                string rValue = Input_XmlReader.Value + ' ';
                                                StringBuilder coordinatePointBuilder = new StringBuilder();
                                                for (int iterator = 0; iterator < rValue.Length; iterator++)
                                                {
                                                    char rValueChar = rValue[iterator];
                                                    if ((Char.IsNumber(rValueChar)) || (rValueChar == '.') || (rValueChar == '-'))
                                                    {
                                                        coordinatePointBuilder.Append(rValueChar);
                                                    }
                                                    else
                                                    {
                                                        if (coordinatePointBuilder.Length > 0)
                                                        {
                                                            latLongs.Add(double.Parse(coordinatePointBuilder.ToString()));
                                                            coordinatePointBuilder.Remove(0, coordinatePointBuilder.Length);
                                                        }
                                                    }
                                                }
                                                //create newline obj
                                                Coordinate_Line newline = new Coordinate_Line();
                                                //add points, In pairs, assign new points to the line and add the line to the coordinate/item
                                                int i = 0;
                                                while ((i + 2) <= latLongs.Count)
                                                {
                                                    string lineName = "line";
                                                    lineName += i;
                                                    newline.Add_Point(latLongs[i], latLongs[i + 1], lineName);
                                                    i += 2;
                                                }
                                                //add featureType
                                                newline.FeatureType = lineFeatureType;
                                                //add label
                                                newline.Label = lineLabel;
                                                //add line to geo obj
                                                geoInfo.Add_Line(newline);
                                            }
                                            break;
                                    }
                                }
                            } while (Input_XmlReader.Read());
                            break;

                        case "gml:Polygon": //is polygon
                            //read the featuretype
                            string polygonFeatureType = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("featureType"))
                                polygonFeatureType = Input_XmlReader.Value;
                            //read the polygonType
                            string polygonPolygonType = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("polygonType"))
                                polygonPolygonType = Input_XmlReader.Value;
                            //read the label
                            string polygonLabel = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("label"))
                                polygonLabel = Input_XmlReader.Value;
                            //read the rotation
                            double polygonRotation = 0;
                            if (Input_XmlReader.MoveToAttribute("rotation"))
                                polygonRotation = Convert.ToDouble(Input_XmlReader.Value);
                            //get the rest
                            do
                            {
                                //check to see if end of element
                                if (Input_XmlReader.NodeType == XmlNodeType.EndElement && Input_XmlReader.Name == "gml:Polygon")
                                    break;
                                //if it is an element
                                if (Input_XmlReader.NodeType == XmlNodeType.Element)
                                {
                                    //determine the name of that element
                                    switch (Input_XmlReader.Name)
                                    {
                                        //if it is the coordinates
                                        case "gml:Coordinates":
                                            Input_XmlReader.Read();
                                            if ((Input_XmlReader.NodeType == XmlNodeType.Text) && (Input_XmlReader.Value.Trim().Length > 0))
                                            {
                                                // Parse the string into a collection of doubles, which represents lats AND longs
                                                List<double> latLongs = new List<double>();
                                                string rValue = Input_XmlReader.Value + ' ';
                                                StringBuilder coordinatePointBuilder = new StringBuilder();
                                                for (int iterator = 0; iterator < rValue.Length; iterator++)
                                                {
                                                    char rValueChar = rValue[iterator];
                                                    if ((Char.IsNumber(rValueChar)) || (rValueChar == '.') || (rValueChar == '-'))
                                                    {
                                                        coordinatePointBuilder.Append(rValueChar);
                                                    }
                                                    else
                                                    {
                                                        if (coordinatePointBuilder.Length > 0)
                                                        {
                                                            latLongs.Add(double.Parse(coordinatePointBuilder.ToString()));
                                                            coordinatePointBuilder.Remove(0, coordinatePointBuilder.Length);
                                                        }
                                                    }
                                                }
                                                //create a newpoly obj
                                                Coordinate_Polygon newPoly = new Coordinate_Polygon();
                                                //add the edgepoints, In pairs, assign new points to the polygon and add the polygon to the coordinate/item
                                                int i = 0;
                                                while ((i + 2) <= latLongs.Count)
                                                {
                                                    newPoly.Add_Edge_Point(latLongs[i], latLongs[i + 1]);
                                                    i += 2;
                                                }
                                                //add the featuretype
                                                newPoly.FeatureType = polygonFeatureType;
                                                //add the polygontype
                                                newPoly.PolygonType = polygonPolygonType;
                                                //add the label
                                                newPoly.Label = polygonLabel;
                                                //add the rotation
                                                newPoly.Rotation = polygonRotation;
                                                //add poly to geo obj
                                                geoInfo.Add_Polygon(newPoly);
                                            }
                                            break;
                                    }
                                }
                            } while (Input_XmlReader.Read());
                            break;

                        case "gml:Circle": //is a circle
                            //read the featureType
                            string circleFeatureType = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("featureType"))
                                circleFeatureType = Input_XmlReader.Value;
                            //read the label
                            string circleLabel = String.Empty;
                            if (Input_XmlReader.MoveToAttribute("label"))
                                circleLabel = Input_XmlReader.Value;
                            //read the radius
                            double circleRadius = 0;
                            if (Input_XmlReader.MoveToAttribute("radius"))
                                circleRadius = Convert.ToDouble(Input_XmlReader.Value);
                            //get the rest
                            do
                            {
                                //check to see if end of element
                                if (Input_XmlReader.NodeType == XmlNodeType.EndElement && Input_XmlReader.Name == "gml:Circle")
                                    break;
                                //if it is an element
                                if (Input_XmlReader.NodeType == XmlNodeType.Element)
                                {
                                    //determine the name of that element
                                    switch (Input_XmlReader.Name)
                                    {
                                        //if it is the coordinates
                                        case "gml:Coordinates":
                                            Input_XmlReader.Read();
                                            if ((Input_XmlReader.NodeType == XmlNodeType.Text) && (Input_XmlReader.Value.Trim().Length > 0))
                                            {
                                                string result = Convert.ToString(Input_XmlReader.Value);
                                                var items = result.Split(',');
                                                double latitude = double.Parse(items[0]);
                                                double longitude = double.Parse(items[1]);
                                                //create the circle
                                                Coordinate_Circle newCircle = new Coordinate_Circle(latitude, longitude, circleRadius, circleLabel, circleFeatureType);
                                                //add to object
                                                geoInfo.Add_Circle(newCircle);
                                            }
                                            break;
                                    }
                                }
                            } while (Input_XmlReader.Read());
                            break;

                    }
                }
            } while (Input_XmlReader.Read());

            return true;
        }
        /// <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;
            }
        }