Пример #1
0
        public bool SaveGesture(string filename, List <TimePointF> points)
        {
            // add the new prototype with the name extracted from the filename.
            string name = Unistroke.ParseName(filename);

            if (_gestures.ContainsKey(name))
            {
                _gestures.Remove(name);
            }
            Unistroke newPrototype = new Unistroke(name, points);

            _gestures.Add(name, newPrototype);

            // do the xml writing
            bool          success = true;
            XmlTextWriter writer  = null;

            try
            {
                // save the prototype as an Xml file
                writer            = new XmlTextWriter(filename, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument(true);
                writer.WriteStartElement("Gesture");
                writer.WriteAttributeString("Name", name);
                writer.WriteAttributeString("NumPts", XmlConvert.ToString(points.Count));
                writer.WriteAttributeString("Millseconds", XmlConvert.ToString(points[points.Count - 1].Time - points[0].Time));
                writer.WriteAttributeString("AppName", Assembly.GetExecutingAssembly().GetName().Name);
                writer.WriteAttributeString("AppVer", Assembly.GetExecutingAssembly().GetName().Version.ToString());
                writer.WriteAttributeString("Date", DateTime.Now.ToLongDateString());
                writer.WriteAttributeString("TimeOfDay", DateTime.Now.ToLongTimeString());

                // write out the raw individual points
                foreach (TimePointF p in points)
                {
                    writer.WriteStartElement("Point");
                    writer.WriteAttributeString("X", XmlConvert.ToString(p.X));
                    writer.WriteAttributeString("Y", XmlConvert.ToString(p.Y));
                    writer.WriteAttributeString("T", XmlConvert.ToString(p.Time));
                    writer.WriteEndElement();                     // <Point />
                }

                writer.WriteEndDocument();                 // </Gesture>
            }
            catch (XmlException xex)
            {
                Console.Write(xex.Message);
                success = false;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                success = false;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
            return(success);            // Xml file successfully written (or not)
        }