Example #1
0
        /// <summary>
        /// Add a coverage annotation to the store, or remove it if it already exists (toggle).
        /// </summary>
        /// <param name="annotation">The annotation to add</param>
        /// <returns>true if an annotation has been added, false otherwise</returns>
        public static async Task<bool> AddAnnotation(CoverageAnnotation annotation, string ID)
        {
            bool result;
            //This is a repeat, just toggle it
            if (Exists(annotation))
            {
                data.RemoveAll(a => a.GetType() == typeof(CoverageAnnotation) && MatchString(a.target.selector.exact, annotation.target.selector.exact));
                result = false;
            }
            //This is new
            else
            {
                data.RemoveAll(a => a.GetType() == typeof(CoverageAnnotation) && MatchString(a.target.selector.exact, annotation.target.selector.exact));
                data.Add(annotation);
                result = true;
            }


            if (!SampleData.DEMO)
            {
                var localFolder = ApplicationData.Current.LocalFolder;
                StorageFile sampleFile = await localFolder.GetFileAsync(ID + COVERAGEFILENAME);
                var serialized = await JsonConvert.SerializeObjectAsync(new AnnotationPackage(data).coverageannotations);
                await FileIO.WriteTextAsync(sampleFile, serialized);
            }

            return result;
        }
Example #2
0
        /// <summary>
        /// This is necessary because some of the work that needs to be done when the 
        /// user adds a coverage annotation requires asynchrony, which is not allowed
        /// in event listeners.
        /// </summary>
        /// <param name="coverage">The type of coverage annotation to apply</param>
        private async void CoverageAnnotationButtonClickWork(string coverage)
        {
            if (IsTextSelected())
            {
                var coverageannotation = new CoverageAnnotation(
                    new CoverageBody(coverage),
                    new Target("oa:SpecificResource", "",
                    new Selector(SpecHighlitText.Substring(0, Math.Min(50, SpecHighlitText.Length)), SpecHighlitXpath)));

                var oldannotation = (CoverageAnnotation) AnnotationData.data.Where(an => an.GetType() == typeof(CoverageAnnotation) && SpecHighlitText.Contains(an.target.selector.exact)).FirstOrDefault();
                string oldcoverage = null;
                if(oldannotation != null)
                {
                    oldcoverage = oldannotation.body.value;
                }

                //This is a new annotation
                if (await AnnotationData.AddAnnotation(coverageannotation, GetSpecID()))
                {
                    UpdateStatusBar(coverageannotation.body.value, oldcoverage);
                    Annotate(coverageannotation);
                }
                //This is a toggle
                else
                {
                    UpdateStatusBar(oldcoverage: oldcoverage);
                    coverageannotation.body.value = "";
                    Annotate(coverageannotation);
                }

                FindAnnotationsFor(SpecHighlitText);

                _UnsavedChanges = true;
            }
        }