Ejemplo n.º 1
0
        /// <summary>
        /// Old Paper Todos Code.
        /// </summary>
        /// <param name="category"></param>
        /// <param name="data"></param>
        void saveRequestFile(string category, object data, StreamWriter log)
        {
            // make the pen request from the PGC data
            PenRequest req = new PenRequest();

            req.Initialize(data);


            // put request information in an xml file (one per request)
            requestXMLFilePath = penRequestDir + @"XML\" + nowString + "_" + req.PenId + ".xml";

            // xml writer
            XmlTextWriter xml = new XmlTextWriter(requestXMLFilePath, null);


            // start the xml document
            xml.WriteStartDocument();
            xml.WriteStartElement("penRequest");
            xml.WriteStartElement("requestInformation");



            xml.WriteStartElement("universalTime");
            xml.WriteStartAttribute("time");
            xml.WriteValue(universalTimeString);
            xml.WriteEndElement();


            xml.WriteStartElement("localTime");
            xml.WriteStartAttribute("time");
            xml.WriteValue(DateTime.Now.ToString());
            xml.WriteEndElement();



            log.WriteLine();
            log.WriteLine("////////// Request at " + nowString);
            log.WriteLine("UniversalTime: " + universalTimeString);

            // more user feedback
            form.appendLine("Pen Synched on: " + DateTime.Now.ToString());


            // Save the data to a pgc file by using Anoto.Util
            // writePGCFile(data, todosPath, nowString);


            log.WriteLine("PenID: " + req.PenId);
            log.WriteLine("NumPages: " + req.Pages.Count);

            // more user feedback
            form.appendLine("Number of Pages in this Session: " + req.Pages.Count);

            xml.WriteStartElement("penID");
            xml.WriteStartAttribute("id");
            xml.WriteValue(req.PenId);
            xml.WriteEndElement(); // end penID

            xml.WriteStartElement("numPages");
            xml.WriteStartAttribute("num");
            xml.WriteValue(req.Pages.Count);
            xml.WriteEndElement(); // end penID

            xml.WriteEndElement(); // end requestInformation

            // get the pages
            RequestPages pages = req.Pages;

            // process page addresses
            Anoto.Util.PageAddress pageAddressUtil = new Anoto.Util.PageAddress();

            // go through all the pages
            IEnumerator pagesEnum = pages.GetEnumerator();
            int         pageCount = 0;

            while (pagesEnum.MoveNext())
            {
                xml.WriteStartElement("page");
                log.WriteLine("Page Object " + pageCount + ": ");
                Page page = (Page)pagesEnum.Current;
                log.WriteLine("\t" + page.PageAddress);

                // more user feedback
                form.appendLine("Processing Page with Address: " + page.PageAddress);

                // break down the page address
                int segment  = pageAddressUtil.GetSegment(page.PageAddress);
                int shelf    = pageAddressUtil.GetShelf(page.PageAddress);
                int book     = pageAddressUtil.GetBook(page.PageAddress);
                int pageNum  = pageAddressUtil.GetPage(page.PageAddress);
                int instance = pageAddressUtil.GetInstance(page.PageAddress);

                log.WriteLine("\t  Segment: " + segment);
                log.WriteLine("\t  Shelf: " + shelf);
                log.WriteLine("\t  Book: " + book);
                log.WriteLine("\t  Page: " + pageNum);

                xml.WriteStartAttribute("address");
                xml.WriteValue(segment + "." + shelf + "." + book + "." + pageNum);
                xml.WriteEndAttribute();
                xml.WriteStartAttribute("addressWithInstance");
                xml.WriteValue(page.PageAddress);
                xml.WriteEndAttribute();
                xml.WriteStartAttribute("segment");
                xml.WriteValue(segment + "");
                xml.WriteEndAttribute();
                xml.WriteStartAttribute("shelf");
                xml.WriteValue(shelf + "");
                xml.WriteEndAttribute();
                xml.WriteStartAttribute("book");
                xml.WriteValue(book + "");
                xml.WriteEndAttribute();
                xml.WriteStartAttribute("page");
                xml.WriteValue(pageNum);
                xml.WriteEndAttribute();

                // the instance N of the page in the request formatted as X.X.X.X#N
                if (instance < 0)
                {
                    log.WriteLine("\t  Instance: NONE");
                }
                else
                {
                    log.WriteLine("\t  Instance: " + instance);
                }

                PenStrokes strokes = page.PenStrokes;
                log.WriteLine("\tPen Strokes Count: " + strokes.Count);
                Bounds b = strokes.Bounds;
                log.WriteLine("\t  Bounds Size: " + b.Width + " x " + b.Height);
                log.WriteLine("\t  Bounds[ltrb]: " + b.Left + " " + b.Top + " " + b.Right + " " + b.Bottom);

                xml.WriteStartAttribute("minX");
                xml.WriteValue(b.Left);
                xml.WriteStartAttribute("minY");
                xml.WriteValue(b.Top);
                xml.WriteStartAttribute("maxX");
                xml.WriteValue(b.Right);
                xml.WriteStartAttribute("maxY");
                xml.WriteValue(b.Bottom);

                // deal with all of the strokes
                processStrokes(strokes, log, xml);

                // next page
                pageCount++;

                xml.WriteEndElement();
            }


            // finish the xml document, Flush & Close
            xml.WriteEndDocument();
            xml.Flush();
            xml.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Puts the stroke data into the XML file.
        /// </summary>
        private static void processStrokes(PenStrokes strokes, StreamWriter log, XmlTextWriter xml)
        {
            IEnumerator strokesEnum = strokes.GetEnumerator();

            // more user feedback
            form.appendLine("");

            while (strokesEnum.MoveNext()) {
                PenStroke stroke = (PenStroke)strokesEnum.Current;

                // more user feedback
                form.appendText(".");

                //log.WriteLine("\tPen Stroke");
                //log.WriteLine("\t  Duration: " + stroke.Duration);

                long strokeTimeMillis = ((long)stroke.StartSecond * 1000) + (long)stroke.StartMillisecond;
                long strokeTimeSystemMillis = ((long)stroke.SystemSecond * 1000) + (long)stroke.SystemMillisecond;

                xml.WriteStartElement("stroke");
                xml.WriteStartAttribute("begin");
                xml.WriteValue(strokeTimeMillis);
                xml.WriteStartAttribute("beginSystemTime");
                xml.WriteValue(strokeTimeSystemMillis);
                xml.WriteStartAttribute("duration");
                xml.WriteValue(stroke.Duration);
                xml.WriteStartAttribute("end");
                xml.WriteValue(strokeTimeMillis + stroke.Duration);
                xml.WriteStartAttribute("colorRGB");
                xml.WriteValue(getRGBString(stroke.Color));

                xml.WriteStartAttribute("minStrokeX");
                xml.WriteValue(stroke.Bounds.Left);
                xml.WriteStartAttribute("minStrokeY");
                xml.WriteValue(stroke.Bounds.Top);
                xml.WriteStartAttribute("maxStrokeX");
                xml.WriteValue(stroke.Bounds.Right);
                xml.WriteStartAttribute("maxStrokeY");
                xml.WriteValue(stroke.Bounds.Bottom);

                int numSamples = stroke.X.Length;
                float[] x = stroke.X;
                float[] y = stroke.Y;
                byte[] f = stroke.Force;
                int[] deltaMillis = stroke.DeltaTime;

                long startTimeMillis = strokeTimeMillis;

                for (int j = 0; j < numSamples; j++) {
                    xml.WriteStartElement("p");
                    // x
                    xml.WriteStartAttribute("x");
                    xml.WriteValue(x[j]);
                    // y
                    xml.WriteStartAttribute("y");
                    xml.WriteValue(y[j]);
                    // f
                    xml.WriteStartAttribute("f");
                    xml.WriteValue(f[j]);
                    // t
                    // move the time counter by delta
                    startTimeMillis += deltaMillis[j];
                    xml.WriteStartAttribute("t");
                    xml.WriteValue(startTimeMillis);

                    xml.WriteEndElement();
                }
                xml.WriteEndElement();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Puts the stroke data into the XML file.
        /// </summary>
        private static void processStrokes(PenStrokes strokes, StreamWriter log, XmlTextWriter xml)
        {
            IEnumerator strokesEnum = strokes.GetEnumerator();

            // more user feedback
            form.appendLine("");

            while (strokesEnum.MoveNext())
            {
                PenStroke stroke = (PenStroke)strokesEnum.Current;

                // more user feedback
                form.appendText(".");

                //log.WriteLine("\tPen Stroke");
                //log.WriteLine("\t  Duration: " + stroke.Duration);

                long strokeTimeMillis       = ((long)stroke.StartSecond * 1000) + (long)stroke.StartMillisecond;
                long strokeTimeSystemMillis = ((long)stroke.SystemSecond * 1000) + (long)stroke.SystemMillisecond;

                xml.WriteStartElement("stroke");
                xml.WriteStartAttribute("begin");
                xml.WriteValue(strokeTimeMillis);
                xml.WriteStartAttribute("beginSystemTime");
                xml.WriteValue(strokeTimeSystemMillis);
                xml.WriteStartAttribute("duration");
                xml.WriteValue(stroke.Duration);
                xml.WriteStartAttribute("end");
                xml.WriteValue(strokeTimeMillis + stroke.Duration);
                xml.WriteStartAttribute("colorRGB");
                xml.WriteValue(getRGBString(stroke.Color));


                xml.WriteStartAttribute("minStrokeX");
                xml.WriteValue(stroke.Bounds.Left);
                xml.WriteStartAttribute("minStrokeY");
                xml.WriteValue(stroke.Bounds.Top);
                xml.WriteStartAttribute("maxStrokeX");
                xml.WriteValue(stroke.Bounds.Right);
                xml.WriteStartAttribute("maxStrokeY");
                xml.WriteValue(stroke.Bounds.Bottom);


                int     numSamples  = stroke.X.Length;
                float[] x           = stroke.X;
                float[] y           = stroke.Y;
                byte[]  f           = stroke.Force;
                int[]   deltaMillis = stroke.DeltaTime;

                long startTimeMillis = strokeTimeMillis;

                for (int j = 0; j < numSamples; j++)
                {
                    xml.WriteStartElement("p");
                    // x
                    xml.WriteStartAttribute("x");
                    xml.WriteValue(x[j]);
                    // y
                    xml.WriteStartAttribute("y");
                    xml.WriteValue(y[j]);
                    // f
                    xml.WriteStartAttribute("f");
                    xml.WriteValue(f[j]);
                    // t
                    // move the time counter by delta
                    startTimeMillis += deltaMillis[j];
                    xml.WriteStartAttribute("t");
                    xml.WriteValue(startTimeMillis);

                    xml.WriteEndElement();
                }
                xml.WriteEndElement();
            }
        }