/// <summary>
        /// Compiles all files in the namespace *.customizations*.json into one large json file in bin\Release|Debug\customizations folder
        /// </summary>
        /// <param name="modelsPath">The path the to customization models to be compiled</param>
        public static void CompileServiceCustomizations(string modelsPath)
        {
            Console.WriteLine("Compiling service customizations from {0}", modelsPath);

            if (Directory.Exists("customizations"))
            {
                Console.WriteLine("...cleaning previous compilation output");

                // Cleanup any previous run customization.
                foreach (var file in Directory.GetFiles("customizations"))
                {
                    File.Delete(file);
                }
            }
            else
            {
                Directory.CreateDirectory("customizations");
            }

            var fileServices = Directory.GetFiles(modelsPath, "*.customizations*.json");

            foreach (var file in fileServices)
            {
                // The name before the .customizations extension
                // Used to get all files for that service
                var baseName = file.Substring(file.IndexOf("ServiceModels\\", StringComparison.OrdinalIgnoreCase)
                                    + "ServiceModels\\".Length, file.IndexOf(".customizations", StringComparison.OrdinalIgnoreCase)
                                    - Convert.ToInt32(file.IndexOf("ServiceModels\\", StringComparison.OrdinalIgnoreCase) 
                                    + "ServiceModels\\".Length));

                var filePath = Path.Combine("customizations", baseName + ".customizations.json");
                var fileEntries = Directory.GetFiles(modelsPath, baseName + "*.customizations*.json");

                var jsonWriter = new JsonWriter {PrettyPrint = true};
                jsonWriter.WriteObjectStart();

                foreach (var entry in fileEntries)
                {
                    var customJson = JsonMapper.ToObject(new StreamReader(entry));
                    foreach (var property in customJson.PropertyNames)
                    {
                        jsonWriter.WritePropertyName(property);
                        jsonWriter.Write(customJson[property].ToJson());
                    }
                }

                jsonWriter.WriteObjectEnd();
                
                // Fixes json being placed into the json mapper
                var output = jsonWriter.ToString().Replace("\\\"", "\"").Replace("\"{", "{").Replace("}\"", "}").Replace("\"[", "[").Replace("]\"", "]");
                
                // Empty json file
                if (jsonWriter.ToString().Length < 10)
                    continue;

                File.WriteAllText(filePath, output);
                Console.WriteLine("...updated {0}", Path.GetFullPath(filePath));
            }
        }
        /// <summary>
        /// Compiles all files in the namespace *.customizations*.json into one large json file in bin\Release|Debug\customizations folder
        /// </summary>
        /// <param name="modelsPath">The path the to customization models to be compiled</param>
        public static void CompileServiceCustomizations(string modelsPath)
        {
            string[] fileServices = Directory.GetFiles(modelsPath, "*.customizations*.json");

            foreach (var file in fileServices)
            {
                // The name before the .customizations extension
                // Used to get all files for that service
                var baseName = file.Substring(file.IndexOf("ServiceModels\\") + "ServiceModels\\".Length, file.IndexOf(".customizations") - Convert.ToInt32(file.IndexOf("ServiceModels\\") + "ServiceModels\\".Length));

                string[] fileEntries = Directory.GetFiles(modelsPath, baseName + "*.customizations*.json");

                var jsonWriter = new JsonWriter();
                jsonWriter.PrettyPrint = true;
                jsonWriter.WriteObjectStart();

                foreach (var entry in fileEntries)
                {
                    var customJson = JsonMapper.ToObject(new StreamReader(entry));
                    foreach (var property in customJson.PropertyNames)
                    {
                        jsonWriter.WritePropertyName(property);
                        jsonWriter.Write(customJson[property].ToJson());
                    }
                }

                jsonWriter.WriteObjectEnd();

                // Fixes json being placed into the json mapper
                var output = jsonWriter.ToString().Replace("\\\"", "\"").Replace("\"{", "{").Replace("}\"", "}").Replace("\"[", "[").Replace("]\"", "]");

                // Empty json file
                if (jsonWriter.ToString().Length < 10)
                    continue;

                Directory.CreateDirectory("customizations");

                var filePath = "customizations\\" + baseName + ".customizations.json";
                if (File.Exists(filePath))
                {
                    var existingContent = File.ReadAllText(filePath);
                    if (string.Equals(existingContent, output))
                        continue;
                }

                File.WriteAllText(filePath, output);
                Console.WriteLine("\tUpdated {0}", baseName + ".customizations.json");
            }
        }
Beispiel #3
0
        void WriteNamespaceToc(JsonWriter writer, string ns)
        {
            var assemblyWrapper = _generatedNamespaces[ns];
            var tocId = ns.Replace(".", "_");

            var nsFilePath = Path.Combine("./" + Options.ContentSubFolderName,
                                          GenerationManifest.OutputSubFolderFromNamespace(ns),
                                          FilenameGenerator.GenerateNamespaceFilename(ns)).Replace('\\', '/');

            writer.WritePropertyName(ns);
            writer.WriteObjectStart();

            writer.WritePropertyName("id");
            writer.Write(tocId);

            writer.WritePropertyName("href");
            writer.Write(nsFilePath);

            writer.WritePropertyName("nodes");
            writer.WriteObjectStart();

            foreach (var type in assemblyWrapper.GetTypesForNamespace(ns).OrderBy(x => x.Name))
            {
                var filePath = Path.Combine("./" + Options.ContentSubFolderName,
                                            GenerationManifest.OutputSubFolderFromNamespace(type.Namespace),
                                            FilenameGenerator.GenerateFilename(type)).Replace('\\', '/');

                writer.WritePropertyName(type.GetDisplayName(false));
                writer.WriteObjectStart();
                writer.WritePropertyName("id");
                writer.Write(type.GetDisplayName(true).Replace(".", "_"));

                writer.WritePropertyName("href");
                writer.Write(filePath);
                writer.WriteObjectEnd();
            }

            writer.WriteObjectEnd();

            writer.WriteObjectEnd();
        }
Beispiel #4
0
        /// <summary>
        /// Constructs the per-root-namespace json files for the services that were generated.
        /// These will be added to the _namespaceTocs collection, either extending it or
        /// overwriting an existing entry if we're updating a service.
        /// </summary>
        /// <example>
        /// An partial and annotated example of what one data file looks like for the 
        /// 'Amazon' namespace:
        /// {
        ///     "Amazon" :                              // this is used as the display name of the root for the entries
        ///     {
        ///         "id" : "Amazon",                    // the unique id assigned to the li element
        ///         "href" : "./items/Amazon/N_.html",  // the target of the link
        ///         "nodes": {                          // collection of child nodes for the namespace
        ///             "AWSConfigs" : {                                // display name for child node
        ///                 "id" : "Amazon_AWSConfigs",                 // the unique li id
        ///                 "href" : "./items/Amazon/TAWSConfigs.html"  // the target of the link
        ///             },
        ///             "LoggingOptions" : {
        ///                 "id" : "Amazon_LoggingOptions",
        ///                 "href" : "./items/Amazon\TLoggingOptions.html"
        ///             },
        ///             ...
        ///         }
        ///     }
        /// }
        /// </example>
        void UpdateNamespaceTocs()
        {
            foreach (var ns in _generatedNamespaces.Keys)
            {
                var sb = new StringBuilder();
                var jsonWriter = new JsonWriter(sb);

                jsonWriter.WriteObjectStart();
                WriteNamespaceToc(jsonWriter, ns);
                jsonWriter.WriteObjectEnd();

                var nsTocContents = sb.ToString();
                if (_namespaceTocs.ContainsKey(ns))
                    _namespaceTocs[ns] = nsTocContents;
                else
                    _namespaceTocs.Add(ns, nsTocContents);
            }
        }