Example #1
0
        internal static string GenerateCode(string[] DocXsds, string DocTypeName, string DocRev, params string[] AdditionalRootNames)
        {
            string cSharpNameSpace = RuntimeTypeNamer.CalcCSharpFullname(DocTypeName, DocRev, AdditionalRootNames);
            string myclasses_cs    = new Xsd().ImportSchemasAsClasses(
                DocXsds,
                cSharpNameSpace,
                CodeGenerationOptions.GenerateOrder | CodeGenerationOptions.GenerateProperties,
                new StringCollection());

            return(CustomizeXsdToCSharpOutput(DocTypeName, myclasses_cs));
        }
Example #2
0
        public Xsd Procesar(XmlDocument documento)
        {
            var xsdModel = new Xsd
            {
                Nodos = new List <Xsd.Nodo>()
            };

            foreach (XmlElement nodoElemento in documento.DocumentElement.ChildNodes)
            {
                if (nodoElemento.LocalName == "element")
                {
                    var readXsd = new ReadXsd();
                    xsdModel.Nodos.Add(readXsd.Nodo(nodoElemento, documento));
                }
            }

            return(xsdModel);
        }
 private IO2Assessment createO2AssessmentFromCodeCrawlerObject(Xsd.DocumentElement codeCrawlerObject, String fileName)
 {
     var o2Assessment = new O2Assessment();
     o2Assessment.name = "CodeCrawler Import of: " + fileName;
     foreach(var threat in codeCrawlerObject.ThreatList)
     {
         var o2Finding = new O2Finding
                             {
                                 vulnName = threat.Threat,
                                 vulnType = threat.Threat,
                                 context = threat.Description,
                                 severity = threat.Level,
                                 confidence = 2,
                                 lineNumber = threat.Line,
                                 file = fileName
                             };
         o2Finding.text.Add(threat.Description);
         o2Assessment.o2Findings.Add(o2Finding);
     }
     return o2Assessment;
 }
Example #4
0
        private bool TryGetLiteral <T>(T obj, out INode literal)
        {
            literal = null;

            var value = obj.ToString();
            Iri dataType;

            if (obj is string)
            {
                literal = new LiteralNode(value);
            }
            else if (Xsd.TryGetDataType(obj.GetType(), out dataType))
            {
                literal = new LiteralNode(value, dataType);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #5
0
 public bool TryGetValue(out object obj)
 {
     return(Xsd.TryGetValueFromString(this.Value, this.DataType, out obj));
 }
        private IO2Assessment createO2AssessmentFromFindBugsObject(Xsd.BugCollection findBugsObject, String fileName)
        {
            var o2Assessment = new O2Assessment();
            o2Assessment.name = "FindBugs Import of: " + fileName;
            foreach (var bug in findBugsObject.BugInstance)
            {
                var o2Finding = new O2Finding
                                    {
                                        vulnName = bug.type,
                                        vulnType = bug.category + "." + bug.abbrev,
                                        severity = bug.priority,
                                        confidence = 2
                                    };
             //   o2Finding.text.Add(threat.Description);

                foreach (var item in bug.Items)
                {
                    var o2Trace = new O2Trace();
                    switch (item.GetType().Name)
                    {
                        case "BugCollectionBugInstanceClass":
                            var clazz = (BugCollectionBugInstanceClass) item;

                            o2Trace.signature = "Class: " + clazz.classname;
                            o2Trace.context = "Class: " + clazz.role;

                            o2Trace.file = tryToResolveFullFilePath(clazz.SourceLine.sourcepath, findBugsObject);
                            o2Trace.lineNumber = 0;
                            break;

                        case "BugCollectionBugInstanceSourceLine":
                            var sourceLine = (BugCollectionBugInstanceSourceLine)item;
                            o2Trace.signature = "SourceLine: " + sourceLine.sourcefile + "  on line " + sourceLine.start;
                            o2Trace.file = tryToResolveFullFilePath(sourceLine.sourcepath , findBugsObject);
                            o2Trace.lineNumber = sourceLine.start;
                            break;

                        case "BugCollectionBugInstanceMethod":
                            var method = (BugCollectionBugInstanceMethod)item;
                            o2Trace.signature = "Method:  + " + method.signature;
                            o2Trace.file = tryToResolveFullFilePath(method.SourceLine.sourcepath, findBugsObject);
                            o2Trace.lineNumber = method.SourceLine.start;
                            break;

                        case "BugCollectionBugInstanceClassSourceLine":
                            o2Trace.signature = "ClassSourceLine";
                            break;
                        case "BugCollectionBugInstanceField":
                            o2Trace.signature = "Field";
                            break;
                        case "BugCollectionBugInstanceFieldSourceLine":
                            o2Trace.signature = "FieldSourceLine";
                            break;
                        case "BugCollectionBugInstanceMethodSourceLine":
                            o2Trace.signature = "MethodSourceLine";
                            break;
                        case "BugCollectionBugInstanceInt":
                            o2Trace.signature = "Int";
                            break;
                        case "BugCollectionBugInstanceLocalVariable":
                            o2Trace.signature = "LocalVariable";
                            break;
                        case "BugCollectionBugInstanceString":
                            o2Trace.signature = "String";
                            break;
                        case "BugCollectionBugInstanceProperty":
                            o2Trace.signature = "Property";
                            break;
                        case "BugCollectionBugInstanceType":
                            o2Trace.signature = "Type";
                            break;
                        case "BugCollectionBugInstanceTypeSourceLine":
                            o2Trace.signature = "TypeSourceLine";
                            break;
                        case "Object":          // ignore it
                            break;
                        default:
                            o2Trace.signature = item.GetType().Name;

                            break;
                    }
                    o2Finding.o2Traces.Add(o2Trace);
                }
                o2Assessment.o2Findings.Add(o2Finding);
            }
            return o2Assessment;
        }
Example #7
0
        /// <summary>
        ///     Scans AppDomain for classes implementing the IDocModel & performs all transformations needed to represent them as
        ///     BaseDoc to be served.
        /// </summary>
        /// <param name="DocTypeName">
        ///     Processes only the given DocTypeName the IDocModel represents. If a IDocModel can not be
        ///     located through out the AppDomain nothing will be processed & no IDocRev will be imported. If no DocTypeName is
        ///     specified all IDocModel located will be processed.
        /// </param>
        public static List <ImporterLightDoc> ReadIDocModelCSharpCode()
        {
            List <ImporterLightDoc> List_ImporterLightDoc = new List <ImporterLightDoc>();

            //TODO:Validate POCO utilizes correct title-case underscore separated labeling practices
            //TODO:add a placeholder file describing what goes in the given DocTypeName's form root directory
            var IDocModelItems = AppDomain
                                 .CurrentDomain
                                 .GetAssemblies()
                                 .SelectMany(a => a.GetTypes())
                                 .Distinct()
                                 .Where(typ => (typ.GetInterfaces().Any(i => i == typeof(IDocModel))))
                                 .Select(type => new
            {
                type,
                DirectoryInfo = new DirectoryInfo(FilesystemTemplateController.GetDocDirectoryPath(type.Name)).mkdir(),
                myschemaXsd   = XsdExporter.ExportSchemas(
                    type.Assembly,
                    new List <string> {
                    type.Name
                },
                    RuntimeTypeNamer.CalcSchemaUri(type.Name)).First()
            });

            foreach (var docTypeDirectoryInfo in IDocModelItems)
            {
                string filepath = string.Format(@"{0}{1}", docTypeDirectoryInfo.DirectoryInfo.FullName, Runtime.MYSCHEMA_XSD_FILE_NAME);

                // always (over)write the xsd as this will always be generated by and for Rudine.Core regardless of the IDocInterpreter that is handling
                // compare the existing xsd on disk with the one generated here (excluding the "rolling" namespace) to see if anything has changed
                if (
                    !File.Exists(filepath)
                    ||
                    RuntimeTypeNamer.VALID_CSHARP_NAMESPACE_PART_MATCH.Replace(docTypeDirectoryInfo.myschemaXsd, string.Empty) != RuntimeTypeNamer.VALID_CSHARP_NAMESPACE_PART_MATCH.Replace(File.ReadAllText(filepath), string.Empty)
                    )
                {
                    File.WriteAllText(string.Format(@"{0}{1}", docTypeDirectoryInfo.DirectoryInfo.FullName, Runtime.MYSCHEMA_XSD_FILE_NAME), docTypeDirectoryInfo.myschemaXsd);
                }

                // create placeholder App_Code\DocTypeName.c_ files for developer to get started with myschema.xsd generation via cSharp file editing & thus auto translating
                string App_Code_Directory_Fullname = RequestPaths.GetPhysicalApplicationPath(Resources.App_Code_DirectoryPath);
                if (Directory.Exists(App_Code_Directory_Fullname))
                {
                    Tasker.StartNewTask(() =>
                    {
                        foreach (string DocTypeName in DocExchange.DocTypeDirectories())
                        {
                            if (!IDocModelItems.Any(m => m.DirectoryInfo.Name.Equals(DocTypeName, StringComparison.CurrentCultureIgnoreCase)))
                            {
                                string cSharpCodeFileName = string.Format(@"{0}\{1}.c_", App_Code_Directory_Fullname, DocTypeName);
                                string xsdFileName        = RequestPaths.GetPhysicalApplicationPath("doc", DocTypeName, Runtime.MYSCHEMA_XSD_FILE_NAME);
                                string xsd          = File.ReadAllText(xsdFileName);
                                string myclasses_cs = new Xsd().ImportSchemasAsClasses(
                                    new[] { xsd },
                                    null,
                                    CodeGenerationOptions.GenerateOrder | CodeGenerationOptions.GenerateProperties,
                                    new StringCollection());

                                if (!File.Exists(cSharpCodeFileName) || File.ReadAllText(cSharpCodeFileName) != myclasses_cs)
                                {
                                    File.WriteAllText(cSharpCodeFileName, myclasses_cs);
                                    File.SetAttributes(cSharpCodeFileName, FileAttributes.Hidden);
                                }
                            }
                        }
                        return(true);
                    });
                }
            }
            return(List_ImporterLightDoc);
        }