Пример #1
0
        public void NamingPositive1()
        {
            string          teststring      = "F1unny.Onion";
            NamespaceString namespaceString = new NamespaceString(teststring);

            namespaceString.ToString().ShouldBe(teststring);
        }
Пример #2
0
 private CSharp(CodeGenerator codeGenerator, NamespaceString startNameSpace)
 {
     _applicationRoot   = codeGenerator.ApplicationRoot;
     _startNameSpace    = startNameSpace;
     _registeredSchemas = codeGenerator.RegisteredJsonSchemas;
     _codeGenerator     = codeGenerator;
 }
Пример #3
0
        public void ToFilePathTest()
        {
            //Works only on windows as Environment.NewLine is \
            NamespaceString namespaceString = new NamespaceString("Funny.Onion");

            string[] stringParts = namespaceString.ToFilePath.Split(Path.DirectorySeparatorChar);
            stringParts.Length.ShouldBe(2);
            if (stringParts.Length == 2)
            {
                stringParts[0].ShouldBe("Funny");
                stringParts[1].ShouldBe("Onion");
            }
        }
Пример #4
0
        private void DoReferenceResolution(IJSBPart jsonSchemaBuilderPart, NamespaceString module)
        {
            switch (jsonSchemaBuilderPart.PartType)
            {
            case JSBPartType.IriReference:
                JSBRef jsonSchemaBuilderIriReference = jsonSchemaBuilderPart as JSBRef;
                if (!jsonSchemaBuilderIriReference.IsFragmentOnly)
                {
                    string relativeLocalFileWithExpandedDot = jsonSchemaBuilderIriReference.RelativeLocalFile;
                    if (relativeLocalFileWithExpandedDot.StartsWith("./") || relativeLocalFileWithExpandedDot.StartsWith(".\\"))
                    {
                        relativeLocalFileWithExpandedDot = Path.Combine(module.ToFilePath, relativeLocalFileWithExpandedDot.Remove(0, 2));
                    }

                    string localFile = Path.Combine(JsonSchemaApplicationRoot, TransformToCamelCase(relativeLocalFileWithExpandedDot));
                    string uriWithoutFragmentString = jsonSchemaBuilderIriReference.IriReference.OriginalString;
                    if (!string.IsNullOrWhiteSpace(jsonSchemaBuilderIriReference.Fragment))
                    {
                        uriWithoutFragmentString = uriWithoutFragmentString.Replace("#" + jsonSchemaBuilderIriReference.Fragment, "");
                    }
                    if (Uri.TryCreate(uriWithoutFragmentString, UriKind.RelativeOrAbsolute, out Uri uriWithoutFragment))
                    {
                        if (!File.Exists(localFile))
                        {
                            if (jsonSchemaBuilderIriReference.IriReference.IsAbsoluteUri && !jsonSchemaBuilderIriReference.IriReference.IsLoopback)
                            {
                                try
                                {
                                    FileInfo fileInfo  = new FileInfo(localFile);
                                    string   directory = fileInfo.Directory.FullName;
                                    if (!Directory.Exists(directory))
                                    {
                                        Directory.CreateDirectory(directory);
                                    }
                                    using (WebClient myWebClient = new WebClient())
                                    {
                                        // Download the Web resource and save it into the current filesystem folder.
                                        myWebClient.DownloadFile(uriWithoutFragment, localFile);
                                        //TODO generate builderparts from schema and register in _registeredJsonSchemas
                                    }
                                }
                                catch (Exception ex)
                                {
                                    throw new CodeGenerationException($"Resource at {uriWithoutFragment} could not be downloaded", ex);
                                }
                            }
                            else
                            {
                                throw new CodeGenerationException($"Iri reference {uriWithoutFragment} was not found locally at {localFile}");
                            }
                        }
                    }
                }
                break;

            case JSBPartType.Schema:
                JSBSchema jsonSchemaBuilderSchema = jsonSchemaBuilderPart as JSBSchema;
                foreach (IJSBPart definition in jsonSchemaBuilderSchema.Definitions.Values)
                {
                    DoReferenceResolution(definition, module);
                }
                if (jsonSchemaBuilderSchema.TopPart != null)
                {
                    DoReferenceResolution(jsonSchemaBuilderSchema.TopPart, module);
                }
                break;

            case JSBPartType.Array:
                JSBArray jsonSchemaBuilderArray = jsonSchemaBuilderPart as JSBArray;
                foreach (IJSBPart part in jsonSchemaBuilderArray.Items)
                {
                    DoReferenceResolution(part, module);
                }
                break;

            case JSBPartType.Object:
                JSBObject jsonSchemaBuilderObject = jsonSchemaBuilderPart as JSBObject;
                foreach (IJSBPart property in jsonSchemaBuilderObject.Properties.Values)
                {
                    DoReferenceResolution(property, module);
                }
                break;

            default:
                break;
            }
        }