コード例 #1
0
        private static void AddPackageElement(string target, Package package, PackageElement element, ReleaseFlags flags)
        {
            //Filter by framework.
            if (element.Flags.HasFlag(PackageElementFlags.FrameworkNET40) || element.Flags.HasFlag(PackageElementFlags.FrameworkNET461))
            {
                if (flags.HasFlag(ReleaseFlags.FrameworkNET40) && !element.Flags.HasFlag(PackageElementFlags.FrameworkNET40))
                {
                    return;
                }
                if (flags.HasFlag(ReleaseFlags.FrameworkNET461) && !element.Flags.HasFlag(PackageElementFlags.FrameworkNET461))
                {
                    return;
                }
            }

            //Filter by platform.
            if (element.Flags.HasFlag(PackageElementFlags.PlatformX86) || element.Flags.HasFlag(PackageElementFlags.PlatformX64))
            {
                if (flags.HasFlag(ReleaseFlags.PlatformX86) && !element.Flags.HasFlag(PackageElementFlags.PlatformX86))
                {
                    return;
                }
                if (flags.HasFlag(ReleaseFlags.PlatformX64) && !element.Flags.HasFlag(PackageElementFlags.PlatformX64))
                {
                    return;
                }
            }

            var source      = GetSource(target, package, element, flags);
            var destination = GetDestination(target, package, element, flags);

            CopyFile(source, destination, flags);
        }
コード例 #2
0
        private static string GetSource(string target, Package package, PackageElement element, ReleaseFlags flags)
        {
            var parts = new List <string>()
            {
                "..",
                DISTRIBUTION
            };

            if (flags.HasFlag(ReleaseFlags.PlatformX86))
            {
                parts.Add(X86);
            }
            if (flags.HasFlag(ReleaseFlags.PlatformX64))
            {
                parts.Add(X64);
            }
            if (flags.HasFlag(ReleaseFlags.FrameworkNET40))
            {
                parts.Add(NET40);
            }
            if (flags.HasFlag(ReleaseFlags.FrameworkNET461))
            {
                parts.Add(NET461);
            }
            parts.Add(element.FileName);
            return(Path.Combine(parts.ToArray()));
        }
コード例 #3
0
        public ProjectElement Parse(String[] inputfiles)
        {
            ProjectElement project = new ProjectElement();

            // Open file
            using (CoverageInfo info = JoinCoverageFiles(inputfiles))
            {
                CoverageDS dataSet = info.BuildDataSet();

                Dictionary <String, PackageElement> packages = new Dictionary <String, PackageElement>();
                Dictionary <uint, string>           files    = new Dictionary <uint, string>();

                // Namespaces
                DataTable namespacesTable = dataSet.Tables["NameSpaceTable"];
                DataTable classesTable    = dataSet.Tables["Class"];
                DataTable filesTable      = dataSet.Tables["SourceFileNames"];

                CreateIndexPackages(project, namespacesTable, packages);
                CreateIndexFiles(filesTable, files);

                foreach (DataRow iclass in classesTable.Rows)
                {
                    string       className = System.Security.SecurityElement.Escape((string)iclass["ClassName"]);
                    ClassElement ce        = new ClassElement(className);

                    DataRow[] methodRows = iclass.GetChildRows("Class_Method");

                    foreach (DataRow imethod in methodRows)
                    {
                        // Get First Line in class
                        DataRow[] lineRows    = imethod.GetChildRows("Method_Lines");
                        bool      includeFile = lineRows.Length < 1 ? false : files.ContainsKey(lineRows[0].Field <uint>("SourceFileID"));

                        if (includeFile)
                        {
                            string        methodName = (string)imethod["MethodName"]; // System.Security.SecurityElement.Escape((string)imethod["MethodName"]);
                            MethodElement me         = new MethodElement(methodName);

                            uint coveredBlocks = (uint)imethod["BlocksCovered"];
                            uint totalBlocks   = coveredBlocks + (uint)imethod["BlocksNotCovered"];
                            uint coveredLines  = (uint)imethod["LinesCovered"];
                            uint totalLines    = coveredLines + (uint)imethod["LinesNotCovered"] + (uint)imethod["LinesPartiallyCovered"];
                            me.Metrics = new MethodMetrics(totalBlocks, coveredBlocks, totalLines, coveredLines);

                            ce.AddMethod(me);
                        }
                    }

                    if (packages.ContainsKey((string)iclass["NamespaceKeyName"]))
                    {
                        PackageElement pe = packages[(string)iclass["NamespaceKeyName"]];
                        pe.AddClass(ce);
                    }
                }
            }

            return(project);
        }
コード例 #4
0
        private static string GetDestination(string target, Package package, PackageElement element, ReleaseFlags flags)
        {
            var parts = new List <string>()
            {
                target
            };

            if (!string.IsNullOrEmpty(package.Name))
            {
                parts.Add(package.Name);
            }
            parts.Add(element.FileName);
            return(Path.Combine(parts.ToArray()));
        }
コード例 #5
0
        /// <summary>
        /// Получить текст ссылки на метод в новом пакете
        /// </summary>
        /// <param name="element"></param>
        /// <param name="repositoryPackage"></param>
        /// <returns></returns>
        private string[] GetLink(PackageElement element, RepositoryPackage repositoryPackage)
        {
            Func <int, string> GetSpaces = (n) => string.Join(string.Empty, Enumerable.Range(0, n).Select(x => " "));

            // Получаем текст метода до ключевого слова IS/AS
            var position = element.Position[ePackageElementDefinitionType.BodyDeclaration];
            var text     = DBRep.Instance().GetTextOfFile(repositoryPackage.BodyRepFullPath, position.LineBeg, position.LineEnd, position.ColumnEnd);

            // Считаем количество пробелов до начала метода (до слова function/procedure)
            var SpaceBeforeTextBegin = 0;
            var ch = text[SpaceBeforeTextBegin];

            while (ch == ' ')
            {
                ch = text[++SpaceBeforeTextBegin];
            }
            var beginIndent = GetSpaces(SpaceBeforeTextBegin);

            // Текст ссылки на метод в новом пакете
            var NewPackageCallText = $"{Config.Instanse().NewPackageName.ToLower()}.{element.Name}";

            // Добавляем схему если новая схема отличается от текущей
            if (repositoryPackage.Owner.ToUpper() != Config.Instanse().NewPackageOwner.ToUpper())
            {
                NewPackageCallText = $"{Config.Instanse().NewPackageOwner.ToLower()}.{NewPackageCallText}";
            }
            // Добавляем слово return для функции
            if (element.ElementType == ePackageElementType.Function)
            {
                NewPackageCallText = $"return {NewPackageCallText}";
            }
            // Отступ длинною в текст ссылки (необходим для отступов параметров)
            var IndentName = GetSpaces(NewPackageCallText.Count());

            // Добавляем параметры
            string parametersText = string.Empty;

            if (element.Parametres.Any())
            {
                parametersText += "(";
                for (int i = 0; i < element.Parametres.Count; i++)
                {
                    var paramName = element.Parametres[i].Name;
                    // Первый параметр без отступов, остальные с отступами
                    parametersText += $"{(i == 0 ? string.Empty : $"{beginIndent}  {IndentName} ")}{paramName} => {paramName},\r\n";
コード例 #6
0
        public virtual Stream <CompilationMessage> ValidateName(ExecutableElement method)
        {
            Optional <string> customName = _customNameExtractor.apply(method.getAnnotation(_annotationType));

            if (customName.Present)
            {
                if (IsInRootNamespace(customName.get()))
                {
                    return(Stream.of(RootNamespaceError(method, customName.get())));
                }
                return(Stream.empty());
            }

            PackageElement @namespace = _elements.getPackageOf(method);

            if (@namespace == null)
            {
                return(Stream.of(RootNamespaceError(method)));
            }
            return(Stream.empty());
        }
コード例 #7
0
        private String GenerateFilePath(String filePattern, PackageElement package, String packageDirectoryPath)
        {
            String fileName;

            if (package.PackageType != null)
            {
                fileName = String.Format(filePattern, package.PackageType);
            }
            else
            {
                fileName = String.Format(filePattern, package.PackageName);
            }

            String filePath = Path.Combine(packageDirectoryPath, fileName);

            if (!Path.IsPathRooted(filePath))
            {
                filePath = Path.GetFullPath(Path.Combine(Project.BaseDirectory, filePath));
            }
            return(filePath);
        }
コード例 #8
0
        private void CreateIndexPackages(ProjectElement project, DataTable origin, Dictionary <String, PackageElement> dest)
        {
            foreach (DataRow row in origin.Rows)
            {
                bool include = false;
                // If there is no include... include all (.*)
                if (__includeNamespaces.Count < 1)
                {
                    __includeNamespaces.Add(".*");
                }
                // Check if the namespace is included

                String nsname = (string)row.ItemArray[5];
                foreach (string entry in __includeNamespaces)
                {
                    if (TestRegex(nsname, entry))
                    {
                        include = true;
                        break;
                    }
                }
                // Check if the namespace is excluded
                foreach (string entry in __excludeNamespaces)
                {
                    if (TestRegex(nsname, entry))
                    {
                        include = false;
                        break;
                    }
                }
                // If the namespace passed all the filters, then we must
                // add it to the project
                if (include)
                {
                    PackageElement pe = new PackageElement(nsname);
                    dest.Add((string)row["NamespaceKeyName"], pe);
                    project.AddPackage(pe);
                }
            }
        }
コード例 #9
0
        public ProjectElement Parse(String[] inputfiles)
        {
            ProjectElement PROJECT = new ProjectElement("new_project", 123323230);

            // Open file
            using (CoverageInfo info = JoinCoverageFiles(inputfiles))
            {
                CoverageDS dataSet = info.BuildDataSet();

                Dictionary <String, PackageElement> packages = new Dictionary <String, PackageElement>();
                Dictionary <uint, FileElement>      files    = new Dictionary <uint, FileElement>();

                // Namespaces
                DataTable namespacesTable = dataSet.Tables["NameSpaceTable"];
                DataTable classesTable    = dataSet.Tables["Class"];
                DataTable filesTable      = dataSet.Tables["SourceFileNames"];

                CreateIndexPackages(PROJECT, namespacesTable, packages);
                CreateIndexFiles(filesTable, files);

                foreach (DataRow iclass in classesTable.Rows)
                {
                    DataRow[] childRows = iclass.GetChildRows("Class_Method");

                    // Since it's one class per file (at least) declare
                    // file here and add it to the class.
                    uint fileid = 0;
                    // uint classlocs = 0;
                    uint        covered_methods = 0;
                    FileElement fe = null;

                    foreach (DataRow imethod in childRows)
                    {
                        // Method starting line
                        uint linenum = 0;
                        // Get First Line in class
                        DataRow[] childRows2 = imethod.GetChildRows("Method_Lines");
                        //if(childRows2.Length > 0)
                        foreach (DataRow iline in childRows2)
                        {
                            LineElement le       = null;
                            uint        coverage = iline.Field <uint>("Coverage");
                            if (linenum == 0)
                            {
                                fileid = iline.Field <uint>("SourceFileID");
                                string methodname = System.Security.SecurityElement.Escape((string)imethod["MethodName"]);
                                linenum = iline.Field <uint>("LnStart");
                                le      = new LineElement(linenum, "method", methodname, coverage);
                            }
                            else
                            {
                                linenum = iline.Field <uint>("LnStart");
                                le      = new LineElement(linenum, "stmt", "", coverage);
                            }

                            // If the file doesn't exists in our report, we'll
                            // just ignore this information
                            if (files.ContainsKey(fileid))
                            {
                                fe = files[fileid];
                                fe.AddLine(le);
                            }
                        }

                        // Count how many methods covered we have
                        if ((uint)imethod["LinesCovered"] > 0)
                        {
                            covered_methods++;
                        }
                    }

                    uint totallines           = (uint)iclass["LinesCovered"] + (uint)iclass["LinesNotCovered"] + (uint)iclass["LinesPartiallyCovered"];
                    uint complexity           = 1;
                    uint methods              = (uint)childRows.Length;
                    uint statements           = totallines - methods;
                    uint covered_statements   = (uint)iclass["LinesCovered"] - covered_methods;
                    uint conditionals         = 0;
                    uint covered_conditionals = 0;

                    ClassElement ce = new ClassElement(System.Security.SecurityElement.Escape((string)iclass["ClassName"]));
                    ce.Metrics = new ClassMetrics(complexity, statements, covered_statements, conditionals, covered_conditionals, methods, covered_methods);

                    if (fe != null)
                    {
                        if (!fe.GetClasses().Contains(ce))
                        {
                            fe.AddClass(ce);
                        }

                        if (packages.ContainsKey((string)iclass["NamespaceKeyName"]))
                        {
                            PackageElement pe = packages[(string)iclass["NamespaceKeyName"]];
                            if (!pe.GetFiles().Contains(fe))
                            {
                                pe.AddFile(fe);
                            }
                        }
                    }
                }
            }
            return(PROJECT);
        }
コード例 #10
0
 public virtual void Visit(PackageElement packageElement)
 {
     packageElement.AcceptAlternative(this);
 }
コード例 #11
0
ファイル: AtomItem.cs プロジェクト: piscisaureus/coapp
 protected override bool TryParseElement(System.Xml.XmlReader reader, string version)
 {
     var extension = _xmlSerializer.Deserialize(reader);
     packageElement = extension as PackageElement;
     return packageElement != null;
 }