Example #1
0
        private Way Convertv6XmlWay(way xml_way)
        {
            Way way = new Way();

            way.Id = new long?(xml_way.id);
            if (xml_way.tag != null)
            {
                way.Tags = (TagsCollectionBase) new TagsCollection();
                foreach (tag tag in xml_way.tag)
                {
                    way.Tags.Add(tag.k, tag.v);
                }
            }
            if (xml_way.nd != null)
            {
                way.Nodes = new List <long>();
                foreach (nd nd in xml_way.nd)
                {
                    way.Nodes.Add(nd.@ref);
                }
            }
            way.ChangeSetId = new long?(xml_way.changeset);
            way.TimeStamp   = new DateTime?(xml_way.timestamp);
            way.UserName    = xml_way.user;
            way.UserId      = new long?(xml_way.uid);
            way.Version     = new ulong?(xml_way.version);
            way.Visible     = new bool?(xml_way.visible);
            return(way);
        }
Example #2
0
        public Way WayCreate(Way way)
        {
            if (this._current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }
            way way1 = way.ConvertTo();

            way1.changeset          = this._current_changeset.id;
            way1.changesetSpecified = true;
            osm osm1 = new osm();

            osm1.way    = new way[1];
            osm1.way[0] = way1;
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(osm));
            MemoryStream  memoryStream  = new MemoryStream();
            Stream        stream1       = (Stream)memoryStream;
            Stream        stream2       = stream1;
            osm           osm2          = osm1;

            xmlSerializer.Serialize(stream2, (object)osm2);
            stream1.Flush();
            memoryStream.Flush();
            string s = this.DoApiCall(true, "api/0.6/way/create", APIConnection.Method.PUT, memoryStream.ToArray());
            long   result;

            if (!long.TryParse(s, out result))
            {
                throw new APIException(string.Format("Invalid response when creating a new way: {0}", (object)s));
            }
            way.Id = new long?(result);
            return(way);
        }
Example #3
0
        /// <summary>
        /// Converts an API v6 xml node to a SimpleWay object.
        /// </summary>
        /// <param name="xml_way"></param>
        /// <returns></returns>
        private Way Convertv6XmlWay(way xml_way)
        {
            Way way = new Way();

            way.Id = xml_way.id;

            if (xml_way.tag != null)
            {
                way.Tags = new TagsCollection();
                foreach (Osm.Xml.v0_6.tag xml_tag in xml_way.tag)
                {
                    way.Tags.Add(xml_tag.k, xml_tag.v);
                }
            }

            if (xml_way.nd != null)
            {
                way.Nodes = new List <long>();
                foreach (Osm.Xml.v0_6.nd xml_nd in xml_way.nd)
                {
                    way.Nodes.Add(xml_nd.@ref);
                }
            }

            way.ChangeSetId = xml_way.changeset;
            way.TimeStamp   = xml_way.timestamp;
            way.UserName    = xml_way.user;
            way.UserId      = xml_way.uid;
            way.Version     = xml_way.version;
            way.Visible     = xml_way.visible;

            return(way);
        }
Example #4
0
        public void WayDelete(Way way)
        {
            if (this._current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }
            if (!way.Id.HasValue)
            {
                throw new ArgumentOutOfRangeException("Cannot update an object without an id!");
            }
            way way1 = way.ConvertTo();

            way1.changeset          = this._current_changeset.id;
            way1.changesetSpecified = true;
            osm osm1 = new osm();

            osm1.way    = new way[1];
            osm1.way[0] = way1;
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(osm));
            MemoryStream  memoryStream  = new MemoryStream();
            Stream        stream1       = (Stream)memoryStream;
            Stream        stream2       = stream1;
            osm           osm2          = osm1;

            xmlSerializer.Serialize(stream2, (object)osm2);
            stream1.Flush();
            memoryStream.Flush();
            byte[] array = memoryStream.ToArray();
            this.DoApiCall(1 != 0, string.Format("api/0.6/way/{0}", (object)way.Id.Value), APIConnection.Method.DELETE, array);
        }
Example #5
0
        void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <node> selectedWayNodes = ((KeyValuePair <way, List <node> >)comboBox1.SelectedItem).Value;
            way         selectedWay      = ((KeyValuePair <way, List <node> >)comboBox1.SelectedItem).Key;

            Console.WriteLine("Nicely Done You Imported Way Number {0} Data", selectedWay.id);
            this.graphRoad(selectedWay);
        }
Example #6
0
        public IActionResult AddWay(AddWay model)
        {
            way way = new way()
            {
                cost        = model.cost,
                end_point   = model.end_point,
                start_point = model.start_point,
                lenght      = model.lenght,
                name        = model.name,
                time_in_way = model.time_in_way
            };

            _context.ways.Add(way);
            _context.SaveChanges();
            return(RedirectToAction("AddWayToAvto", "AddSome", new { id = model.Avto_Key }));
        }
Example #7
0
        public IActionResult EditWay(AddWay model)
        {
            way way = new way()
            {
                Ways_Key    = model.Avto_Key,
                cost        = model.cost,
                end_point   = model.end_point,
                start_point = model.start_point,
                lenght      = model.lenght,
                name        = model.name,
                time_in_way = model.time_in_way
            };

            _context.ways.Update(way);
            _context.SaveChanges();
            return(RedirectToAction("ShowsWay", "Shows"));
        }
Example #8
0
        internal static Way ConvertToSimple(way wa)
        {
            Way way = new Way();

            if (wa.idSpecified)
            {
                way.Id = new long?(wa.id);
            }
            if (wa.changesetSpecified)
            {
                way.ChangeSetId = new long?(wa.changeset);
            }
            if (wa.visibleSpecified)
            {
                way.Visible = new bool?(wa.visible);
            }
            else
            {
                way.Visible = new bool?(true);
            }
            if (wa.timestampSpecified)
            {
                way.TimeStamp = new DateTime?(wa.timestamp);
            }
            if (wa.uidSpecified)
            {
                way.UserId = new long?(wa.uid);
            }
            if (wa.versionSpecified)
            {
                way.Version = new ulong?(wa.version);
            }
            way.UserName = wa.user;
            way.Tags     = XmlSimpleConverter.ConvertToTags(wa.tag);
            if (wa.nd != null && wa.nd.Length != 0)
            {
                way.Nodes = new List <long>();
                for (int index = 0; index < wa.nd.Length; ++index)
                {
                    way.Nodes.Add(wa.nd[index].@ref);
                }
            }
            return(way);
        }
Example #9
0
        /// <summary>
        /// Creates a new way by adding it to the current changeset.
        /// </summary>
        /// <param name="way"></param>
        public Way WayCreate(Way way)
        {
            if (_current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }

            // build a new node.
            way xml_way = way.ConvertTo();

            xml_way.changeset          = _current_changeset.id;
            xml_way.changesetSpecified = true;

            // encapsulate into an osm object.
            OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm();
            osm.way    = new Osm.Xml.v0_6.way[1];
            osm.way[0] = xml_way;

            // serialize the changeset.
            XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm));
            MemoryStream  mem_stream = new MemoryStream();
            Stream        stream     = mem_stream;

            serializer.Serialize(stream, osm);
            stream.Flush();
            mem_stream.Flush();
            byte[] put_data = mem_stream.ToArray();

            // do the api call.
            string response_string = this.DoApiCall(true, "api/0.6/way/create",
                                                    Method.PUT, put_data);

            // get the id-response.
            long id;

            if (!long.TryParse(response_string, out id))
            { // invalid response!
                throw new APIException(string.Format("Invalid response when creating a new way: {0}", response_string));
            }
            way.Id = id;
            return(way);
        }
Example #10
0
        public void graphRoad(way road)
        {
            //populate dataset with some demo data..
            DataSet   dataSet = new DataSet();
            DataTable dt      = new DataTable();

            dt.Columns.Add("x", typeof(double));
            dt.Columns.Add("y", typeof(double));

            double xMax = MercatorProjection.lonToX(converterHandler.maxLon);
            double yMax = MercatorProjection.latToY(converterHandler.maxLat);
            double xMin = MercatorProjection.lonToX(converterHandler.minLon);
            double yMin = MercatorProjection.latToY(converterHandler.minLat);

            double scale_x = (xMax - xMin) / 200;
            double scale_y = (yMax - yMin) / 200;

            double scale = Math.Max(scale_x, scale_y);

            foreach (node roadNodes in this.waysNodesDict[road])
            {
                DataRow r1 = dt.NewRow();

                double xRoadNode = scale * MercatorProjection.lonToX(roadNodes.lon - originPoint.Item1);
                double yRoadNode = scale * MercatorProjection.latToY(roadNodes.lat - originPoint.Item2);

                r1[0] = xRoadNode;
                r1[1] = yRoadNode;
                dt.Rows.Add(r1);
            }
            dataSet.Tables.Add(dt);


            //prepare chart control...
            Chart chart = this.chart1;

            chart.DataSource = dataSet.Tables[0];
            chart.Width      = 1300;
            chart.Height     = 800;
            chart.DataBind();
        }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        if (now == way.up)
        {
            direction = Vector3.up * Time.deltaTime;
        }
        else if (now == way.down)
        {
            direction = Vector3.down * Time.deltaTime;
        }

        transform.Translate(direction * speed);
        if ((transform.localPosition.y > (startPos.y + maxHeight) || (transform.localPosition.y < (startPos.y))) && now != way.stop)
        {
            if (now == way.up)
            {
                now = way.down;
            }
            else if (now == way.down)
            {
                now = way.up;
            }
        }
    }
Example #12
0
        /// <summary>
        /// Updates the given way.
        /// </summary>
        /// <param name="way"></param>
        public void WayDelete(Way way)
        {
            if (_current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }
            if (!way.Id.HasValue)
            {
                throw new ArgumentOutOfRangeException("Cannot update an object without an id!");
            }

            // build a new node.
            way xml_way = way.ConvertTo();

            xml_way.changeset          = _current_changeset.id;
            xml_way.changesetSpecified = true;

            // encapsulate into an osm object.
            OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm();
            osm.way    = new Osm.Xml.v0_6.way[1];
            osm.way[0] = xml_way;

            // serialize the changeset.
            XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm));
            MemoryStream  mem_stream = new MemoryStream();
            Stream        stream     = mem_stream;

            serializer.Serialize(stream, osm);
            stream.Flush();
            mem_stream.Flush();
            byte[] put_data = mem_stream.ToArray();

            // do the api call.
            this.DoApiCall(true, string.Format("api/0.6/way/{0}", way.Id.Value),
                           Method.DELETE, put_data);
        }
        private way ConvertFeatureToOSMWay(IFeature currentFeature, IWorkspace featureWorkspace, IFeatureClass pointFeatureClass, int osmIDPointFieldIndex, int tagsFieldIndex, int osmIDFieldIndex, int changesetIDFieldIndex, int osmVersionFieldIndex, int userIDFieldIndex, int userNameFieldIndex, int timeStampFieldIndex, int visibleFieldIndex, int extensionVersion)
        {

            if (currentFeature == null)
                throw new ArgumentNullException("currentFeature");

            way osmWay = new way();
            object featureValue = DBNull.Value;

            List<nd> vertexIDs = new List<nd>();

            if (currentFeature.Shape.IsEmpty == false)
            {
                IPointCollection pointCollection = currentFeature.Shape as IPointCollection;

                if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    for (int pointIndex = 0; pointIndex < pointCollection.PointCount - 1; pointIndex++)
                    {
                        nd vertex = new nd();
                        vertex.@ref = OSMToolHelper.retrieveNodeID(pointFeatureClass, osmIDPointFieldIndex, extensionVersion, pointCollection.get_Point(pointIndex));
                        vertexIDs.Add(vertex);
                    }

                    // the last node is the first one again even though it doesn't have an internal ID
                    nd lastVertex = new nd();
                    lastVertex.@ref = OSMToolHelper.retrieveNodeID(pointFeatureClass, osmIDPointFieldIndex, extensionVersion, pointCollection.get_Point(0));
                    vertexIDs.Add(lastVertex);

                }
                else
                {
                    for (int pointIndex = 0; pointIndex < pointCollection.PointCount; pointIndex++)
                    {
                        nd vertex = new nd();
                        vertex.@ref = OSMToolHelper.retrieveNodeID(pointFeatureClass, osmIDPointFieldIndex, extensionVersion, pointCollection.get_Point(pointIndex));
                        vertexIDs.Add(vertex);
                    }
                }

                osmWay.nd = vertexIDs.ToArray();
            }

            if (osmIDFieldIndex != -1)
            {
                osmWay.id = Convert.ToString(currentFeature.get_Value(osmIDFieldIndex));
            }

            if (changesetIDFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(changesetIDFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.changeset = Convert.ToString(currentFeature.get_Value(changesetIDFieldIndex));
                }
            }

            if (osmVersionFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(osmVersionFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.version = Convert.ToString(featureValue);
                }
            }

            if (userIDFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(userIDFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.uid = Convert.ToString(featureValue);
                }
            }

            if (userNameFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(userNameFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.user = Convert.ToString(featureValue);
                }
            }

            if (timeStampFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(timeStampFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.timestamp = Convert.ToDateTime(featureValue).ToUniversalTime().ToString("u");
                }
            }

            if (visibleFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(visibleFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    try
                    {
                        osmWay.visible = (wayVisible)Enum.Parse(typeof(wayVisible), Convert.ToString(featureValue));
                    }
                    catch
                    {
                        osmWay.visible = wayVisible.@true;
                    }
                }
            }

            if (tagsFieldIndex > -1)
            {
                tag[] tags = null;
                tags = _osmUtility.retrieveOSMTags((IRow)currentFeature, tagsFieldIndex, featureWorkspace);

                if (tags.Length != 0)
                {
                    osmWay.tag = tags;
                }
            }

            return osmWay;
        }
Example #14
0
        public override void AddWay(Way simpleWay)
        {
            way way1 = new way();

            way1.idSpecified = false;
            long?nullable;

            if (simpleWay.Id.HasValue)
            {
                way1.idSpecified = true;
                way way2 = way1;
                nullable = simpleWay.Id;
                long num = nullable.Value;
                way2.id = num;
            }
            way1.changesetSpecified = false;
            nullable = simpleWay.ChangeSetId;
            if (nullable.HasValue)
            {
                way way2 = way1;
                nullable = simpleWay.ChangeSetId;
                long num = nullable.Value;
                way2.changeset          = num;
                way1.changesetSpecified = true;
            }
            way1.visibleSpecified = false;
            if (simpleWay.Visible.HasValue)
            {
                way1.visible          = simpleWay.Visible.Value;
                way1.visibleSpecified = true;
            }
            way1.timestampSpecified = false;
            if (simpleWay.TimeStamp.HasValue)
            {
                way1.timestamp          = simpleWay.TimeStamp.Value;
                way1.timestampSpecified = true;
            }
            way1.uidSpecified = false;
            nullable          = simpleWay.UserId;
            if (nullable.HasValue)
            {
                way way2 = way1;
                nullable = simpleWay.UserId;
                long num = nullable.Value;
                way2.uid          = num;
                way1.uidSpecified = true;
            }
            way1.user = simpleWay.UserName;
            way1.tag  = this.ConvertToXmlTags(simpleWay.Tags);
            if (simpleWay.Nodes != null)
            {
                way1.nd = new nd[simpleWay.Nodes.Count];
                for (int index = 0; index < simpleWay.Nodes.Count; ++index)
                {
                    way1.nd[index] = new nd()
                    {
                        refSpecified = true,
                        @ref         = simpleWay.Nodes[index]
                    }
                }
                ;
            }
            if (simpleWay.Version.HasValue)
            {
                way1.version          = simpleWay.Version.Value;
                way1.versionSpecified = true;
            }
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add(string.Empty, string.Empty);
            MemoryStream      memoryStream = new MemoryStream();
            XmlWriterSettings settings     = this._settings;
            XmlWriter         xmlWriter    = XmlWriter.Create((Stream)memoryStream, settings);

            new XmlSerializer(typeof(way), string.Empty).Serialize(xmlWriter, (object)way1, namespaces);
            Stream stream = this._stream;

            memoryStream.WriteTo(stream);
            this._stream.Flush();
            this._streamWriter.WriteLine();
            this._streamWriter.Flush();
        }
Example #15
0
        public static double getInnerFloat(this string s, string after = "", way w = way.straight)
        {
            if (!s.Contains(after))
            {
                return(0);
            }
            int    z      = 1;
            string arg    = String.Empty;
            string exp    = "0";
            bool   key    = false;
            int    sx     = (after != "") ? ((w == way.straight) ? s.IndexOf(after) : s.LastIndexOf(after)) : ((w == way.straight) ? 0 : s.Length - 1);
            int    d      = (w == way.straight) ? 1 : -1;
            int    start  = (w == way.straight) ? sx + after.Length : sx;
            int    finish = (w == way.straight) ? s.Length : -1;

            for (int i = start; i != finish; i += d)
            {
                if ((Char.IsDigit(s[i])) || (s[i] == '.'))
                {
                    key = true;
                    if (w == way.straight && i > start && s[i - 1] == '-')
                    {
                        arg = "-" + arg;
                    }
                    arg = (w == way.straight) ? arg + s[i] : s[i] + arg;
                }
                else if (s[i] == '-' && w == way.reverse)
                {
                    if (arg != String.Empty)
                    {
                        arg = "-" + arg;
                    }
                }
                else if (s[i] == 'E' && w == way.reverse)
                {
                    exp = arg;
                    arg = String.Empty;
                }
                else if (s[i] == 'E')
                {
                    exp = "";
                    int k = 0;
                    if (s[i + 1] == '-')
                    {
                        z = -1;
                        k = 1;
                    }
                    for (int j = i + 1 + k; j < s.Length; j++)
                    {
                        if (Char.IsDigit(s[j]))
                        {
                            exp += s[j];
                        }
                        else
                        {
                            break;
                        }
                    }
                    break;
                }
                else if (key)
                {
                    break;
                }
            }
            if (arg == String.Empty)
            {
                arg = "0";
            }
            return(Convert.ToDouble(arg.Replace('.', ',')) * Math.Pow(10, Convert.ToInt32(exp) * z));
        }
Example #16
0
 The array that will apear on your Object as Positions / Rotations / Alphas have 5 parameter that works this way :
     Total Time : How long this action will take.
Example #17
0
 movement(right, left, down, up, ref endlunchTime, foodexitTime, ref reverseend, ref sleepTime, ref way, NumbersCreater, problems, snakeobjects, ref food);
Example #18
0
 // Use this for initialization
 void Start()
 {
     now      = way.up;
     startPos = transform.position;
 }
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {
            try
            {
                IGPUtilities3 execute_Utilities = new GPUtilitiesClass();

                if (TrackCancel == null)
                {
                    TrackCancel = new CancelTrackerClass();
                }

                IGPParameter inputFeatureDatasetParameter = paramvalues.get_Element(in_featureDatasetParameterNumber) as IGPParameter;
                IGPValue inputFeatureDatasetGPValue = execute_Utilities.UnpackGPValue(inputFeatureDatasetParameter);
                IGPValue outputOSMFileGPValue = execute_Utilities.UnpackGPValue(paramvalues.get_Element(out_osmFileLocationParameterNumber));

                // get the name of the feature dataset
                int fdDemlimiterPosition = inputFeatureDatasetGPValue.GetAsText().LastIndexOf("\\");

                string nameOfFeatureDataset = inputFeatureDatasetGPValue.GetAsText().Substring(fdDemlimiterPosition + 1);


                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;

                System.Xml.XmlWriter xmlWriter = null;

                try
                {
                    xmlWriter = XmlWriter.Create(outputOSMFileGPValue.GetAsText(), settings);
                }
                catch (Exception ex)
                {
                    message.AddError(120021, ex.Message);
                    return;
                }

                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("osm"); // start the osm root node
                xmlWriter.WriteAttributeString("version", "0.6"); // add the version attribute
                xmlWriter.WriteAttributeString("generator", "ArcGIS Editor for OpenStreetMap"); // add the generator attribute

                // write all the nodes
                // use a feature search cursor to loop through all the known points and write them out as osm node

                IFeatureClassContainer osmFeatureClasses = execute_Utilities.OpenDataset(inputFeatureDatasetGPValue) as IFeatureClassContainer;

                if (osmFeatureClasses == null)
                {
                    message.AddError(120022, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), inputFeatureDatasetParameter.Name));
                    return;
                }

                IFeatureClass osmPointFeatureClass = osmFeatureClasses.get_ClassByName(nameOfFeatureDataset + "_osm_pt");

                if (osmPointFeatureClass == null)
                {
                    message.AddError(120023, string.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_no_pointfeatureclass"), nameOfFeatureDataset + "_osm_pt"));
                    return;
                }

                // check the extension of the point feature class to determine its version
                int internalOSMExtensionVersion = osmPointFeatureClass.OSMExtensionVersion();

                IFeatureCursor searchCursor = null;

                System.Xml.Serialization.XmlSerializerNamespaces xmlnsEmpty = new System.Xml.Serialization.XmlSerializerNamespaces();
                xmlnsEmpty.Add("", "");

                message.AddMessage(resourceManager.GetString("GPTools_OSMGPExport2OSM_exporting_pts_msg"));
                int pointCounter = 0;

                string nodesExportedMessage = String.Empty;

                // collect the indices for the point feature class once
                int pointOSMIDFieldIndex = osmPointFeatureClass.Fields.FindField("OSMID");
                int pointChangesetFieldIndex = osmPointFeatureClass.Fields.FindField("osmchangeset");
                int pointVersionFieldIndex = osmPointFeatureClass.Fields.FindField("osmversion");
                int pointUIDFieldIndex = osmPointFeatureClass.Fields.FindField("osmuid");
                int pointUserFieldIndex = osmPointFeatureClass.Fields.FindField("osmuser");
                int pointTimeStampFieldIndex = osmPointFeatureClass.Fields.FindField("osmtimestamp");
                int pointVisibleFieldIndex = osmPointFeatureClass.Fields.FindField("osmvisible");
                int pointTagsFieldIndex = osmPointFeatureClass.Fields.FindField("osmTags");

                using (ComReleaser comReleaser = new ComReleaser())
                {
                    searchCursor = osmPointFeatureClass.Search(null, false);
                    comReleaser.ManageLifetime(searchCursor);

                    System.Xml.Serialization.XmlSerializer pointSerializer = new System.Xml.Serialization.XmlSerializer(typeof(node));

                    IFeature currentFeature = searchCursor.NextFeature();

                    IWorkspace pointWorkspace = ((IDataset)osmPointFeatureClass).Workspace;

                    while (currentFeature != null)
                    {
                        if (TrackCancel.Continue() == true)
                        {
                            // convert the found point feature into a osm node representation to store into the OSM XML file
                            node osmNode = ConvertPointFeatureToOSMNode(currentFeature, pointWorkspace, pointTagsFieldIndex, pointOSMIDFieldIndex, pointChangesetFieldIndex, pointVersionFieldIndex, pointUIDFieldIndex, pointUserFieldIndex, pointTimeStampFieldIndex, pointVisibleFieldIndex, internalOSMExtensionVersion);

                            pointSerializer.Serialize(xmlWriter, osmNode, xmlnsEmpty);

                            // increase the point counter to later status report
                            pointCounter++;

                            currentFeature = searchCursor.NextFeature();
                        }
                        else
                        {
                            // properly close the document
                            xmlWriter.WriteEndElement(); // closing the osm root element
                            xmlWriter.WriteEndDocument(); // finishing the document

                            xmlWriter.Close(); // closing the document

                            // report the number of elements loader so far
                            nodesExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_pts_exported_msg"), pointCounter);
                            message.AddMessage(nodesExportedMessage);

                            return;
                        }
                    }
                }

                nodesExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_pts_exported_msg"), pointCounter);
                message.AddMessage(nodesExportedMessage);

                // next loop through the line and polygon feature classes to export those features as ways
                // in case we encounter a multi-part geometry, store it in a relation collection that will be serialized when exporting the relations table
                IFeatureClass osmLineFeatureClass = osmFeatureClasses.get_ClassByName(nameOfFeatureDataset + "_osm_ln");

                if (osmLineFeatureClass == null)
                {
                    message.AddError(120023, string.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_no_linefeatureclass"), nameOfFeatureDataset + "_osm_ln"));
                    return;
                }

                message.AddMessage(resourceManager.GetString("GPTools_OSMGPExport2OSM_exporting_ways_msg"));

                // as we are looping through the line and polygon feature classes let's collect the multi-part features separately 
                // as they are considered relations in the OSM world
                List<relation> multiPartElements = new List<relation>();

                System.Xml.Serialization.XmlSerializer waySerializer = new System.Xml.Serialization.XmlSerializer(typeof(way));
                int lineCounter = 0;
                int relationCounter = 0;
                string waysExportedMessage = String.Empty;

                using (ComReleaser comReleaser = new ComReleaser())
                {
                    searchCursor = osmLineFeatureClass.Search(null, false);
                    comReleaser.ManageLifetime(searchCursor);

                    IFeature currentFeature = searchCursor.NextFeature();

                    // collect the indices for the point feature class once
                    int lineOSMIDFieldIndex = osmLineFeatureClass.Fields.FindField("OSMID");
                    int lineChangesetFieldIndex = osmLineFeatureClass.Fields.FindField("osmchangeset");
                    int lineVersionFieldIndex = osmLineFeatureClass.Fields.FindField("osmversion");
                    int lineUIDFieldIndex = osmLineFeatureClass.Fields.FindField("osmuid");
                    int lineUserFieldIndex = osmLineFeatureClass.Fields.FindField("osmuser");
                    int lineTimeStampFieldIndex = osmLineFeatureClass.Fields.FindField("osmtimestamp");
                    int lineVisibleFieldIndex = osmLineFeatureClass.Fields.FindField("osmvisible");
                    int lineTagsFieldIndex = osmLineFeatureClass.Fields.FindField("osmTags");
                    int lineMembersFieldIndex = osmLineFeatureClass.Fields.FindField("osmMembers");

                    IWorkspace lineWorkspace = ((IDataset)osmLineFeatureClass).Workspace;

                    while (currentFeature != null)
                    {
                        if (TrackCancel.Continue() == false)
                        {
                            // properly close the document
                            xmlWriter.WriteEndElement(); // closing the osm root element
                            xmlWriter.WriteEndDocument(); // finishing the document

                            xmlWriter.Close(); // closing the document

                            // report the number of elements loaded so far
                            waysExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_ways_exported_msg"), lineCounter);
                            message.AddMessage(waysExportedMessage);

                            return;
                        }

                        //test if the feature geometry has multiple parts
                        IGeometryCollection geometryCollection = currentFeature.Shape as IGeometryCollection;

                        if (geometryCollection != null)
                        {
                            if (geometryCollection.GeometryCount == 1)
                            {
                                // convert the found polyline feature into a osm way representation to store into the OSM XML file
                                way osmWay = ConvertFeatureToOSMWay(currentFeature, lineWorkspace, osmPointFeatureClass, pointOSMIDFieldIndex, lineTagsFieldIndex, lineOSMIDFieldIndex, lineChangesetFieldIndex, lineVersionFieldIndex, lineUIDFieldIndex, lineUserFieldIndex, lineTimeStampFieldIndex, lineVisibleFieldIndex, internalOSMExtensionVersion);
                                waySerializer.Serialize(xmlWriter, osmWay, xmlnsEmpty);

                                // increase the line counter for later status report
                                lineCounter++;
                            }
                            else
                            {
                                relation osmRelation = ConvertRowToOSMRelation((IRow)currentFeature, lineWorkspace, lineTagsFieldIndex, lineOSMIDFieldIndex, lineChangesetFieldIndex, lineVersionFieldIndex, lineUIDFieldIndex, lineUserFieldIndex, lineTimeStampFieldIndex, lineVisibleFieldIndex, lineMembersFieldIndex, internalOSMExtensionVersion);
                                multiPartElements.Add(osmRelation);

                                // increase the line counter for later status report
                                relationCounter++;
                            }
                        }

                        currentFeature = searchCursor.NextFeature();
                    }
                }


                IFeatureClass osmPolygonFeatureClass = osmFeatureClasses.get_ClassByName(nameOfFeatureDataset + "_osm_ply");
                IFeatureWorkspace commonWorkspace = ((IDataset)osmPolygonFeatureClass).Workspace as IFeatureWorkspace;

                if (osmPolygonFeatureClass == null)
                {
                    message.AddError(120024, string.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_no_polygonfeatureclass"), nameOfFeatureDataset + "_osm_ply"));
                    return;
                }

                using (ComReleaser comReleaser = new ComReleaser())
                {
                    searchCursor = osmPolygonFeatureClass.Search(null, false);
                    comReleaser.ManageLifetime(searchCursor);

                    IFeature currentFeature = searchCursor.NextFeature();

                    // collect the indices for the point feature class once
                    int polygonOSMIDFieldIndex = osmPolygonFeatureClass.Fields.FindField("OSMID");
                    int polygonChangesetFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmchangeset");
                    int polygonVersionFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmversion");
                    int polygonUIDFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmuid");
                    int polygonUserFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmuser");
                    int polygonTimeStampFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmtimestamp");
                    int polygonVisibleFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmvisible");
                    int polygonTagsFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmTags");
                    int polygonMembersFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmMembers");

                    IWorkspace polygonWorkspace = ((IDataset)osmPolygonFeatureClass).Workspace;

                    while (currentFeature != null)
                    {
                        if (TrackCancel.Continue() == false)
                        {
                            // properly close the document
                            xmlWriter.WriteEndElement(); // closing the osm root element
                            xmlWriter.WriteEndDocument(); // finishing the document

                            xmlWriter.Close(); // closing the document

                            // report the number of elements loaded so far
                            waysExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_ways_exported_msg"), lineCounter);
                            message.AddMessage(waysExportedMessage);

                            message.AddAbort(resourceManager.GetString("GPTools_toolabort"));
                            return;
                        }

                        //test if the feature geometry has multiple parts
                        IGeometryCollection geometryCollection = currentFeature.Shape as IGeometryCollection;

                        if (geometryCollection != null)
                        {
                            if (geometryCollection.GeometryCount == 1)
                            {
                                // convert the found polyline feature into a osm way representation to store into the OSM XML file
                                way osmWay = ConvertFeatureToOSMWay(currentFeature, polygonWorkspace, osmPointFeatureClass, pointOSMIDFieldIndex, polygonTagsFieldIndex, polygonOSMIDFieldIndex, polygonChangesetFieldIndex, polygonVersionFieldIndex, polygonUIDFieldIndex, polygonUserFieldIndex, polygonTimeStampFieldIndex, polygonVisibleFieldIndex, internalOSMExtensionVersion);
                                waySerializer.Serialize(xmlWriter, osmWay, xmlnsEmpty);

                                // increase the line counter for later status report
                                lineCounter++;
                            }
                            else
                            {
                                relation osmRelation = ConvertRowToOSMRelation((IRow)currentFeature, polygonWorkspace, polygonTagsFieldIndex, polygonOSMIDFieldIndex, polygonChangesetFieldIndex, polygonVersionFieldIndex, polygonUIDFieldIndex, polygonUserFieldIndex, polygonTimeStampFieldIndex, polygonVisibleFieldIndex, polygonMembersFieldIndex, internalOSMExtensionVersion);
                                multiPartElements.Add(osmRelation);

                                // increase the line counter for later status report
                                relationCounter++;
                            }
                        }

                        currentFeature = searchCursor.NextFeature();
                    }
                }

                waysExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_ways_exported_msg"), lineCounter);
                message.AddMessage(waysExportedMessage);


                // now let's go through the relation table 
                message.AddMessage(resourceManager.GetString("GPTools_OSMGPExport2OSM_exporting_relations_msg"));
                ITable relationTable = commonWorkspace.OpenTable(nameOfFeatureDataset + "_osm_relation");

                if (relationTable == null)
                {
                    message.AddError(120025, String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_no_relationTable"), nameOfFeatureDataset + "_osm_relation"));
                    return;
                }


                System.Xml.Serialization.XmlSerializer relationSerializer = new System.Xml.Serialization.XmlSerializer(typeof(relation));
                string relationsExportedMessage = String.Empty;

                using (ComReleaser comReleaser = new ComReleaser())
                {
                    ICursor rowCursor = relationTable.Search(null, false);
                    comReleaser.ManageLifetime(rowCursor);

                    IRow currentRow = rowCursor.NextRow();

                    // collect the indices for the relation table once
                    int relationOSMIDFieldIndex = relationTable.Fields.FindField("OSMID");
                    int relationChangesetFieldIndex = relationTable.Fields.FindField("osmchangeset");
                    int relationVersionFieldIndex = relationTable.Fields.FindField("osmversion");
                    int relationUIDFieldIndex = relationTable.Fields.FindField("osmuid");
                    int relationUserFieldIndex = relationTable.Fields.FindField("osmuser");
                    int relationTimeStampFieldIndex = relationTable.Fields.FindField("osmtimestamp");
                    int relationVisibleFieldIndex = relationTable.Fields.FindField("osmvisible");
                    int relationTagsFieldIndex = relationTable.Fields.FindField("osmTags");
                    int relationMembersFieldIndex = relationTable.Fields.FindField("osmMembers");

                    IWorkspace polygonWorkspace = ((IDataset)osmPolygonFeatureClass).Workspace;


                    while (currentRow != null)
                    {
                        if (TrackCancel.Continue() == false)
                        {
                            // properly close the document
                            xmlWriter.WriteEndElement(); // closing the osm root element
                            xmlWriter.WriteEndDocument(); // finishing the document

                            xmlWriter.Close(); // closing the document

                            // report the number of elements loaded so far
                            relationsExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_relations_exported_msg"), relationCounter);
                            message.AddMessage(relationsExportedMessage);

                            message.AddAbort(resourceManager.GetString("GPTools_toolabort"));
                            return;
                        }

                        relation osmRelation = ConvertRowToOSMRelation(currentRow, (IWorkspace)commonWorkspace, relationTagsFieldIndex, relationOSMIDFieldIndex, relationChangesetFieldIndex, relationVersionFieldIndex, relationUIDFieldIndex, relationUserFieldIndex, relationTimeStampFieldIndex, relationVisibleFieldIndex, relationMembersFieldIndex, internalOSMExtensionVersion);
                        relationSerializer.Serialize(xmlWriter, osmRelation, xmlnsEmpty);

                        // increase the line counter for later status report
                        relationCounter++;

                        currentRow = rowCursor.NextRow();
                    }
                }

                // lastly let's serialize the collected multipart-geometries back into relation elements
                foreach (relation currentRelation in multiPartElements)
                {
                    if (TrackCancel.Continue() == false)
                    {
                        // properly close the document
                        xmlWriter.WriteEndElement(); // closing the osm root element
                        xmlWriter.WriteEndDocument(); // finishing the document

                        xmlWriter.Close(); // closing the document

                        // report the number of elements loaded so far
                        relationsExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_relations_exported_msg"), relationCounter);
                        message.AddMessage(relationsExportedMessage);

                        return;
                    }

                    relationSerializer.Serialize(xmlWriter, currentRelation, xmlnsEmpty);
                    relationCounter++;
                }

                relationsExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_relations_exported_msg"), relationCounter);
                message.AddMessage(relationsExportedMessage);


                xmlWriter.WriteEndElement(); // closing the osm root element
                xmlWriter.WriteEndDocument(); // finishing the document

                xmlWriter.Close(); // closing the document
            }
            catch (Exception ex)
            {
                message.AddError(11111, ex.StackTrace);
                message.AddError(120026, ex.Message);
            }
        }
Using scope this way allows you to control when a destructor is called for an object. In this case, that allows us to time a block of code.