Exemple #1
0
 /// <summary>
 /// Constructor for the <c>FieldScanner</c> object. This is
 /// used to perform a scan on the specified class in order to find
 /// all fields that are labeled with an XML annotation.
 /// </summary>
 /// <param name="type">
 /// this is the schema class that is to be scanned
 /// </param>
 /// <param name="access">
 /// this is the access type for the class
 /// </param>
 public FieldScanner(Class type, DefaultType access) {
    this.factory = new AnnotationFactory();
    this.hierarchy = new Hierarchy(type);
    this.done = new ContactMap();
    this.access = access;
    this.Scan(type);
 }
        public List <Annotation> GetAnnotations(AnnotationType annotationType, List <Guid> selectedTagIds, bool includeNoTags)
        {
            List <Annotation> annotationsFilteredByAnnotationType = new List <Annotation>();

            if (annotationType == AnnotationType.All)
            {
                annotationsFilteredByAnnotationType = GetAnnotations();
            }
            else
            {
                var annotations = annotationAccess.GetAnnotationsByType(GlobalAccess.Instance.Email, GlobalAccess.Instance.ServiceCode, annotationType);
                var dlBooks     = publicationAccess.GetAllDlBooks(GlobalAccess.Instance.UserCredential);
                annotationsFilteredByAnnotationType = AnnotationFactory.CreateAnnotations(annotations, this.tagDomainService.Tags, dlBooks);
            }
            if (annotationsFilteredByAnnotationType != null)
            {
                List <Annotation> noTags = null;
                if (includeNoTags)
                {
                    noTags = annotationsFilteredByAnnotationType.FindAll(o => o.CategoryTagIDs.Count == 0);
                }

                if (selectedTagIds != null && selectedTagIds.Count > 0)
                {
                    annotationsFilteredByAnnotationType = annotationsFilteredByAnnotationType.FindAll(o => selectedTagIds.Intersect(o.CategoryTagIDs).Count() > 0);
                }

                if (noTags != null)
                {
                    annotationsFilteredByAnnotationType.AddRange(noTags);
                }
            }
            return(annotationsFilteredByAnnotationType);
        }
        /// <summary>
        /// get All Annotations
        /// </summary>
        /// <returns></returns>
        public List <Annotation> GetAnnotations()
        {
            var dlBooks = publicationAccess.GetAllDlBooks(GlobalAccess.Instance.UserCredential);

            var annotations = annotationAccess.GetAnnotations(GlobalAccess.Instance.Email, GlobalAccess.Instance.ServiceCode);

            return(AnnotationFactory.CreateAnnotations(annotations, this.tagDomainService.Tags, dlBooks));
        }
Exemple #4
0
 /// <summary>
 /// Constructor for the <c>FieldScanner</c> object. This is
 /// used to perform a scan on the specified class in order to find
 /// all fields that are labeled with an XML annotation.
 /// </summary>
 /// <param name="type">
 /// this is the schema class that is to be scanned
 /// </param>
 /// <param name="access">
 /// this is the access type for the class
 /// </param>
 public FieldScanner(Class type, DefaultType access)
 {
     this.factory   = new AnnotationFactory();
     this.hierarchy = new Hierarchy(type);
     this.done      = new ContactMap();
     this.access    = access;
     this.Scan(type);
 }
        /// <summary>
        /// get Annotations By special BookId
        /// </summary>
        /// <param name="bookId"></param>
        /// <returns></returns>
        public List <Annotation> GetAnnotationsByBookId(int bookId)
        {
            var annotations = annotationAccess.GetAnnotations(GlobalAccess.Instance.Email, GlobalAccess.Instance.ServiceCode, bookId);
            var dlBook      = publicationAccess.GetDlBookByBookId(bookId, GlobalAccess.Instance.UserCredential);

            return(AnnotationFactory.CreateAnnotations(annotations, this.tagDomainService.Tags, new List <DlBook> {
                dlBook
            }));
        }
        private AnnotationShaderGroup UpdateVariables(SyntaxTree tree, ShaderType header)
        {
            // Probably should use a combined approach of the compiled shader with the source for annotations to get this info.
            //
            // because now it will also show unused buffers/variables
            // Also when you register buffers to the same slot and use only one, the shader will compile and work, but I don't have
            // any idea about which buffer I need to bind to the pipeline, so current solution show errorbox
            AnnotationFactory.Start(header);
            IList <SyntaxNodeBase> nodes     = tree.Root.ChildNodes;
            List <string>          registers = new List <string>();

            foreach (SyntaxNodeBase node in nodes)
            {
                if (node is ConstantBufferSyntax)
                {
                    ConstantBufferSyntax structType = (ConstantBufferSyntax)node;
                    string register = structType.Register.Register.ValueText;

                    AnnotationFactory.BeginGroup();
                    if (registers.Contains(register))
                    {
                        MessageBox.Show($"Register: {register}\nDefined multiple times, ShaderBox can not decides which one needs to be binded.\n\nWill be resolved in a future release.", "Unsupported operation", MessageBoxButton.OK, MessageBoxImage.Error);
                        AnnotationFactory.DestroyGroup();
                        return(null);
                    }
                    registers.Add(register);
                    AnnotationFactory.SetRegister(register);
                    foreach (VariableDeclarationStatementSyntax syntax in structType.Declarations)
                    {
                        if (!ParseVariableDeclarationStatementSyntax(syntax, registers))
                        {
                            return(null);
                        }
                    }
                    AnnotationFactory.EndGroup();
                }

                if (node is VariableDeclarationStatementSyntax)
                {
                    AnnotationFactory.BeginGroup();
                    if (!ParseVariableDeclarationStatementSyntax((VariableDeclarationStatementSyntax)node, registers))
                    {
                        return(null);
                    }
                    AnnotationFactory.EndGroup();
                }
            }

            return(AnnotationFactory.End());
        }
        /// <summary>
        /// only for search annotationlist
        /// </summary>
        /// <returns></returns>
        public List <Annotation> SearchAnnotations(string searchText, AnnotationType annotationType)
        {
            var dlBooks     = publicationAccess.GetDlBooksOffline(GlobalAccess.Instance.UserCredential);
            var annotations = annotationAccess.SearchAnnotations(searchText, GlobalAccess.Instance.Email, GlobalAccess.Instance.ServiceCode, annotationType);

            if (annotations == null)
            {
                return(null);
            }

            var q = from anno in annotations
                    select AnnotationFactory.CreateAnnotation(anno.AnnotationContent, this.tagDomainService.Tags, dlBooks);

            return(q.ToList());
        }
 public Task Handle(TagDeletedEvent evt)
 {
     return(Task.Run(() =>
     {
         var annotations = annotationAccess.GetAnnotations(evt.Email, evt.ServiceCode);
         if (annotations.Count > 0)
         {
             var ConvertedAnnotations = AnnotationFactory.CreateAnnotations(annotations);
             foreach (var annotation in ConvertedAnnotations)
             {
                 if (annotation.CategoryTagIDs.Remove(evt.TagId))
                 {
                     annotationAccess.UpdateAnnotation(annotation.DocId, annotation.Type, AnnotationStatusEnum.Updated, annotation.ToXmlString(), DateTime.Now, false, annotation.AnnotationCode);
                 }
             }
         }
     }));
 }
        private void InitialNoteHighlightText(string email, string serviceCode)
        {
            if (!isAnnotationInitialized)
            {
                foreach (Annotations element in base.GetEntityList <Annotations>(base.MainDbPath, queryAllAnnotationsSql, (int)AnnotationStatusEnum.Deleted, email, serviceCode))
                {
                    Annotation annotation = AnnotationFactory.CreateAnnotation(element.AnnotationContent);
                    if (String.IsNullOrEmpty(element.NoteText) && !String.IsNullOrEmpty(annotation.NoteText))
                    {
                        base.Execute(base.MainDbPath, initialNoteText, annotation.NoteText, element.AnnotationCode);
                    }

                    if (String.IsNullOrEmpty(element.HighlightText) && !String.IsNullOrEmpty(annotation.HighlightText))
                    {
                        base.Execute(base.MainDbPath, initialHighLightText, annotation.HighlightText, element.AnnotationCode);
                    }
                }

                isAnnotationInitialized = true;
            }
        }
Exemple #10
0
        private static void ProcessMethod(CCCheckOutputAssemblyMethod method, List <BaseAnnotation> annotations)
        {
            if (method.Name.EndsWith("..cctor"))
            {
                Output.WriteLine("Ignoring suggestions for {0} as it is a static constructor", method.Name);
                return;
            }

            if (method.Suggestion == null)
            {
#if DEBUG_PRINT
                Output.WriteLine("No suggestions for method {0}", method.Name);
#endif
                return;
            }

            foreach (var suggestion in method.Suggestion)
            {
                Contract.Assume(suggestion != null);

                string                 path, whyFailed = null;
                Squiggle               squiggle;
                BaseAnnotation         ann;
                ClousotSuggestion.Kind suggestionKind;

                if (Enum.TryParse(suggestion.SuggestionKind, out suggestionKind) &&
                    TryGetPath(suggestion.SourceLocation, out path, out squiggle, out whyFailed) &&
                    AnnotationFactory.TryMakeAnnotation(method, suggestion, suggestionKind, path, squiggle, out ann, out whyFailed))
                {
                    annotations.Add(ann);
                }
                else
                {
                    Output.WriteError("Failed to parse suggestion for {0}. Reason {1}", method.Name, whyFailed);
                }
            }
        }
Exemple #11
0
        public void ParseArgs(string[] args)
        {
            if (InvokeRequired)
            {
                ParseArgsCallback d = new ParseArgsCallback(ParseArgs);
                Invoke(d, new object[] { args });
                return;
            }

            try
            {
                if (args.Any(o => Regex.Match(o, "(-{1,2}|/)(help|\\?)").Success))
                {
                    Console.WriteLine("TODO");
                    Close();
                    return;
                }

                BringToFront();
                Focus();
                Activate();
                Show();
                Application.DoEvents();

                string      datasource          = null;
                IAnnotation annotation          = null;
                var         idOrIndexList       = new List <object>();
                var         idOrIndexListByFile = new Dictionary <string, List <object> >();
                var         annotationByFile    = new Dictionary <string, IAnnotation>();

                for (int i = 0; i < args.Length; ++i)
                {
                    string arg = args[i];
                    // does the arg specify a data source?
                    if (arg.StartsWith("--index"))
                    {
                        idOrIndexList.Add(Convert.ToInt32(args[i + 1]));
                        ++i;
                    }
                    else if (arg.StartsWith("--id"))
                    {
                        idOrIndexList.Add(args[i + 1]);
                        ++i;
                    }
                    else if (arg.StartsWith("--annotation"))
                    {
                        annotation = AnnotationFactory.ParseArgument(args[i + 1]);
                        ++i;
                    }
                    else
                    {
                        if (datasource != null)
                        {
                            idOrIndexListByFile[datasource].AddRange(idOrIndexList);
                            annotationByFile[datasource] = annotation;

                            idOrIndexList.Clear();
                            annotation = null;
                        }

                        datasource = arg;
                        if (!idOrIndexListByFile.ContainsKey(datasource))
                        {
                            idOrIndexListByFile[datasource] = new List <object>();
                        }
                    }
                }

                if (datasource != null)
                {
                    idOrIndexListByFile[datasource].AddRange(idOrIndexList);
                    annotationByFile[datasource] = annotation;

                    idOrIndexList.Clear();
                    annotation = null;
                }

                foreach (var fileListPair in idOrIndexListByFile)
                {
                    if (fileListPair.Value.Count > 0)
                    {
                        Manager.OpenFile(fileListPair.Key, fileListPair.Value, annotationByFile[fileListPair.Key]);
                    }
                    else
                    {
                        Manager.OpenFile(fileListPair.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += "\n\nAdditional information: " + ex.InnerException.Message;
                }
                MessageBox.Show(message,
                                "Error parsing command line arguments",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }
Exemple #12
0
        public void ParseArgs(string[] args)
        {
            if (InvokeRequired)
            {
                ParseArgsCallback d = new ParseArgsCallback(ParseArgs);
                Invoke(d, new object[] { args });
                return;
            }

            try
            {
                if (args.Any(o => Regex.Match(o, "(-{1,2}|/)(help|\\?)").Success))
                {
                    Console.WriteLine("TODO");
                    Close();
                    return;
                }

                BringToFront();
                Focus();
                Activate();
                Show();
                Application.DoEvents();

                string      datasource          = null;
                IAnnotation annotation          = null;
                var         idOrIndexList       = new List <object>();
                var         idOrIndexListByFile = new Dictionary <string, List <object> >();
                var         annotationByFile    = new Dictionary <string, IAnnotation>();
                bool        testMode            = false;

                for (int i = 0; i < args.Length; ++i)
                {
                    string arg = args[i];
                    // does the arg specify a data source?
                    if (arg.StartsWith("--index"))
                    {
                        idOrIndexList.Add(Convert.ToInt32(args[i + 1]));
                        ++i;
                    }
                    else if (arg.StartsWith("--id"))
                    {
                        idOrIndexList.Add(args[i + 1]);
                        ++i;
                    }
                    else if (arg.StartsWith("--annotation"))
                    {
                        annotation = AnnotationFactory.ParseArgument(args[i + 1]);
                        ++i;
                    }
                    else if (arg == "--test")
                    {
                        testMode = true;
                    }
                    else
                    {
                        if (datasource != null)
                        {
                            idOrIndexListByFile[datasource].AddRange(idOrIndexList);
                            annotationByFile[datasource] = annotation;

                            idOrIndexList.Clear();
                            annotation = null;
                        }

                        datasource = arg;
                        if (!idOrIndexListByFile.ContainsKey(datasource))
                        {
                            idOrIndexListByFile[datasource] = new List <object>();
                        }
                    }
                }

                if (datasource != null)
                {
                    idOrIndexListByFile[datasource].AddRange(idOrIndexList);
                    annotationByFile[datasource] = annotation;

                    idOrIndexList.Clear();
                    annotation = null;
                }

                bool success = true;
                foreach (var fileListPair in idOrIndexListByFile)
                {
                    if (fileListPair.Value.Count > 0)
                    {
                        success &= Manager.OpenFile(fileListPair.Key, fileListPair.Value, annotationByFile[fileListPair.Key]);
                    }
                    else
                    {
                        success &= Manager.OpenFile(fileListPair.Key);
                    }
                }

                if (testMode)
                {
                    Environment.ExitCode = success ? 0 : 1;
                    Close();
                }
            }
            catch (Exception ex)
            {
                Program.HandleException("Error parsing command line arguments", ex);
            }
        }
Exemple #13
0
        public void ParseArgs(string[] args)
        {
            if (InvokeRequired)
            {
                ParseArgsCallback d = new ParseArgsCallback(ParseArgs);
                Invoke(d, new object[] { args });
                return;
            }

            try
            {
                Arguments argParser = new Arguments(args);

                if (argParser["help"] != null ||
                    argParser["h"] != null ||
                    argParser["?"] != null)
                {
                    Console.WriteLine("TODO");
                    Close();
                    return;
                }

                BringToFront();
                Focus();
                Activate();
                Show();
                Application.DoEvents();

                string datasource = null;
                foreach (string arg in args)
                {
                    if (!arg.StartsWith("--index") && !arg.StartsWith("id") && !arg.StartsWith("annotation"))
                    {
                        datasource = arg;
                        break;
                    }
                }

                IAnnotation annotation = null;
                if (argParser["annotation"] != null)
                {
                    annotation = AnnotationFactory.ParseArgument(argParser["annotation"]);
                }

                if (datasource != null)
                {
                    if (argParser["index"] != null)
                    {
                        Manager.OpenFile(datasource, Convert.ToInt32(argParser["index"]), annotation);
                    }
                    else if (argParser["id"] != null)
                    {
                        Manager.OpenFile(datasource, argParser["id"], annotation);
                    }
                    else
                    {
                        Manager.OpenFile(datasource);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += "\n\nAdditional information: " + ex.InnerException.Message;
                }
                MessageBox.Show(message,
                                "Error parsing command line arguments",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }
Exemple #14
0
        private static async Task MergeAnnotation(AnnotationTaskContext context, string strFileName, int bookID)
        {
            XDocument xDocument = null;

            using (var stream = await GlobalAccess.DirectoryService.OpenFile(strFileName, BusinessModel.FileModeEnum.Open))
            {
                xDocument = XDocument.Load(stream);
            }

            if (xDocument != null)
            {
                var annotationCode   = Guid.Parse(xDocument.Root.Attribute(Constants.SId).Value);
                var localAnnotations = context.AnnotationAccess.getAnnotation(annotationCode);
                if (localAnnotations != null)
                {
                    var annotation     = AnnotationFactory.CreateAnnotation(localAnnotations.AnnotationContent);
                    var localDateTime  = annotation.UpdatedTime;
                    var serverDateTime = DateTime.Parse(xDocument.Root.Attribute(XName.Get(Constants.SUpdatedOn)).Value);

                    var dateDiff = DateTime.Compare(localDateTime, serverDateTime);
                    if (dateDiff > 0) //local version is newer than the server version
                    {
                        return;
                    }
                    localAnnotations.AnnotationContent = xDocument.Root.ToString();
                    localAnnotations.IsSynced          = true;
                    localAnnotations.AnnotationType    = int.Parse(xDocument.Root.Attribute(Constants.SType).Value);
                    localAnnotations.LastSyncDate      = DateTime.Now;
                    var statusString = xDocument.Root.Attribute(Constants.Status).Value;
                    AnnotationStatusEnum annoStatus = (AnnotationStatusEnum)Enum.Parse(typeof(AnnotationStatusEnum), statusString[0].ToString().ToUpper() + statusString.Substring(1));

                    localAnnotations.Status     = (int)annoStatus;
                    localAnnotations.DocumentID = xDocument.Root.Attribute(Constants.DocId).Value;

                    context.AnnotationAccess.UpdateAnnotation(localAnnotations);
                }
                else
                {
                    Annotations annotations = new Annotations
                    {
                        Email            = context.AnnotationSyncTask.Email,
                        ServiceCode      = context.AnnotationSyncTask.ServiceCode,
                        AnnotationCode   = annotationCode,
                        BookID           = bookID,
                        IsSynced         = true,
                        CreatedDate      = DateTime.Now,
                        LastModifiedDate = DateTime.Now,
                        LastSyncDate     = DateTime.Now
                    };
                    annotations.DocumentID     = xDocument.Root.Attribute(Constants.DocId).Value;
                    annotations.AnnotationType = int.Parse(xDocument.Root.Attribute(Constants.SType).Value);

                    var statusString = xDocument.Root.Attribute(Constants.Status).Value;
                    AnnotationStatusEnum annoStatus = (AnnotationStatusEnum)Enum.Parse(typeof(AnnotationStatusEnum), statusString[0].ToString().ToUpper() + statusString.Substring(1));

                    annotations.Status            = (int)annoStatus;
                    annotations.AnnotationContent = xDocument.Root.ToString();
                    context.AnnotationAccess.AddAnnotation(annotations);
                }
            }
        }
 public static void FixtureSetUp()
 {
     _factory = new AnnotationFactory();
 }
        private bool ParseVariableDeclarationStatementSyntax(VariableDeclarationStatementSyntax syntax, List <string> registers)
        {
            VariableDeclarationSyntax varDeclaration = syntax.Declaration;

            TypeSyntax type = varDeclaration.Type;

            foreach (VariableDeclaratorSyntax var in varDeclaration.Variables)
            {
                AnnotationFactory.BeginVar();
                AnnotationFactory.SetModifiers(varDeclaration.Modifiers);

                if (AnnotationFactory.IsGroupOpen())
                {
                    AnnotationFactory.SetType(type);
                    AnnotationFactory.SetAnnotations(var.Annotations?.Annotations ?? null);
                    InitializerSyntax initializer = var.Initializer;
                    if (varDeclaration.Variables[0].ArrayRankSpecifiers.Count > 0)
                    {
                        LiteralExpressionSyntax litExpressionSyntax = varDeclaration.Variables[0].ArrayRankSpecifiers[0].Dimension as LiteralExpressionSyntax;
                        AnnotationFactory.SetDimension((int)litExpressionSyntax.Token.Value);
                    }
                    if (initializer != null && initializer is EqualsValueClauseSyntax)
                    {
                        EqualsValueClauseSyntax evcSyntax = (EqualsValueClauseSyntax)initializer;
                        if (evcSyntax.Value is NumericConstructorInvocationExpressionSyntax)
                        {
                            NumericConstructorInvocationExpressionSyntax ncieSyntax = (NumericConstructorInvocationExpressionSyntax)evcSyntax.Value;
                            SeparatedSyntaxList <ExpressionSyntax>       arguments  = ncieSyntax.ArgumentList.Arguments;
                        }
                        else if (evcSyntax.Value is LiteralExpressionSyntax)
                        {
                        }
                    }

                    SyntaxToken name = var.Identifier;
                    AnnotationFactory.SetName(name.ValueText);
                    foreach (var qualifier in var.Qualifiers)
                    {
                        if (qualifier is RegisterLocation)
                        {
                            string register = ((RegisterLocation)qualifier).Register.ValueText;
                            if (registers.Contains(register))
                            {
                                MessageBox.Show($"Register: {register}\nDefined multiple times, ShaderBox can not decides which one needs to be binded.\n\nWill be resolved in a future release.", "Unsupported operation", MessageBoxButton.OK, MessageBoxImage.Error);
                                AnnotationFactory.DestroyGroup();
                                return(false);
                            }
                            AnnotationFactory.SetRegister(register);
                        }
                    }
                    if (string.IsNullOrWhiteSpace(AnnotationFactory.GetRegister()))
                    {
                        AnnotationFactory.DestroyGroup();
                    }
                    else
                    {
                        AnnotationFactory.EndVar();
                    }
                }
            }

            return(true);
        }