Esempio n. 1
0
        /// <summary>
        /// Find Stroke from Guid
        /// </summary>
        /// The original version was much too slow for the archive replay scenario.
        /// <param name="scribble"></param>
        /// <param name="guid"></param>
        /// <param name="stroke"></param>
        /// <param name="guidTag"></param>
        /// <returns></returns>
        private bool FastFindStrokeFromGuid(InkScribble scribble, Guid guid, out Ink.Stroke stroke, Guid guidTag)
        {
            Ink.Ink ink = scribble.Ink;

            if (this.myGuidReverseTable.Contains(guid))
            {
                if (((ScribbleIntPair)this.myGuidReverseTable[guid]).scribble == scribble)
                {
                    ScribbleIntPair pair = (ScribbleIntPair)this.myGuidReverseTable[guid];

                    /// The count can be zero right after a clear slide or clear deck operation
                    /// if count is zero, CreateStrokes will except.
                    if (pair.scribble.Count == 0)
                    {
                        stroke = null;
                        return(false);
                    }

                    Ink.Strokes targetStrokes = null;
                    try
                    {
                        targetStrokes = ink.CreateStrokes(new int[] { pair.id });
                    }
                    catch (Exception e)
                    {                     //not clear when this would happen?
                        stroke = null;
                        Trace.WriteLine("FastFindStrokeFromGuid: Exception during CreateStrokes: " + e.ToString());
                        return(false);
                    }

                    if (targetStrokes.Count < 1)                     //not clear when this would happen?
                    {
                        stroke = null;
                        Trace.WriteLine("FastFindStrokeFromGuid: Found target with zero stroke count.");
                        return(false);
                    }

                    // Found it.
                    stroke = targetStrokes[0];
                    return(true);
                }
                else
                {                   //This happens when we revisit slides we've been on previously
                    this.myGuidReverseTable.Remove(guid);
                    stroke = null;
                    return(false);
                }
            }
            else
            {
                stroke = null;
                return(false);
            }
        }
Esempio n. 2
0
        private bool FindStrokeFromGuid(InkScribble scribble, Guid guid, out Ink.Stroke stroke, Guid guidTag)
        {
            Ink.Ink ink = scribble.Ink;

            // Check if the guid tables are out of date. This might be indicated by either:
            // * The guid is not in the reverse table.
            // * The reverse table entry's scribble does not match the given scribble.
            // If the tables are out of date, update the entries for this scribble object.
            if (!this.myGuidReverseTable.Contains(guid) ||
                ((ScribbleIntPair)this.myGuidReverseTable[guid]).scribble != scribble)
            {
                // Ensure that, at the least, the stale entry is removed.
                this.myGuidReverseTable.Remove(guid);

                // Refresh entries for all strokes in this scribble.
                foreach (Ink.Stroke s in ink.Strokes)
                {
                    try
                    {
                        if (s.ExtendedProperties.DoesPropertyExist(guidTag))
                        {
                            Guid strokeGuid = new Guid((string)s.ExtendedProperties[guidTag].Data);
                            this.myGuidReverseTable[strokeGuid] = new ScribbleIntPair(scribble, s.Id);
                            this.myGuidTable[new ScribbleIntPair(scribble, s.Id)] = strokeGuid;
                        }
                    }
                    catch
                    {
                        //this try/catch because I once saw an exception thrown here.  Not sure if it was a bug
                        // in the data, the TPC SDK, or in my code..  Anyway it seemed safe to ignore.
                    }
                }
            }

            // If the guid is still not in the table, it is not found.
            if (!this.myGuidReverseTable.Contains(guid))
            {
                stroke = null;
                return(false);
            }

            // Can we find the specific id sought?
            ScribbleIntPair pair = (ScribbleIntPair)this.myGuidReverseTable[guid];

            //This try/catch is a hack to deal with multiple-play (archive) scenario.
            //I believe the real fix is to catch WMP stop and postion change events and
            //to rebuild guid tables and InkScribble appropriately for the new media position.
            Ink.Strokes targetStrokes = null;
            try
            {
                targetStrokes = ink.CreateStrokes(new int[] { pair.id });
            }
            catch
            {
                stroke = null;
                return(false);
            }

            if (targetStrokes.Count < 1)
            {
                stroke = null;
                return(false);
            }

            // Found it.
            stroke = targetStrokes[0];
            return(true);
        }