Exemple #1
0
        /// <summary>
        /// Initialize instance for DBContext and scaffold this to typescript
        /// </summary>
        /// <param name="rootPath">root path for created types folder. Should be in client app source folder and included in client app and including it into bundling toolchain</param>
        /// <param name="storageName">IndexedDB database name </param>
        public void Initialize(string rootPath, string storageName, IAutoControllerOptions options)
        {
            _rootPath    = Path.Combine(rootPath, Utils.NormalizedName(typeof(T).ToString()));
            _storageName = storageName;
            _options     = options;
            GetEntityKeys();
            GetIndexes();
            EnsurePathExists(rootPath);
            if (!Directory.Exists(_rootPath))
            {
                CreateFolder(_rootPath);
            }
            else
            {
                ClearRootFolder(_rootPath);
                CreateFolder(_rootPath);
            }
            CreateFolder(Path.Combine(_rootPath, "types"));
            CreateFolder(Path.Combine(_rootPath, "enums"));
            foreach (var q in _entityKeys)
            {
                string s = ScaffoldTypeToTypescript(q.Key);
                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(Path.Combine(_rootPath, "types", Utils.NormalizedName(q.Key.ToString()) + ".ts"), true))
                {
                    file.Write(s);
                }
            }
            foreach (var q in _importDirectives.Where(v => v.Key.IsEnum))
            {
                string s = ScaffoldEnums(q.Key);
                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(Path.Combine(_rootPath, "enums", Utils.NormalizedName(q.Key.ToString()) + ".ts"), true))
                {
                    file.Write(s);
                }
            }
            string indexTS = ScaffoldIndexTS();

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(Path.Combine(_rootPath, "index.ts"), true))
            {
                file.Write(indexTS);
            }

            string a = ScaffoldDatabase();

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(Path.Combine(_rootPath, "database.ts"), true))
            {
                file.Write(a);
            }
            ClearInternalData();
        }
Exemple #2
0
        /// <summary>
        /// Adds IndexedDB projection of current DBContext.
        /// </summary>
        /// <typeparam name="T">The DBContext derived type</typeparam>
        /// <param name="appBuilder">The instance of ApplicationBuilder</param>
        /// <param name="indexedDBname">The name of IndexedDB</param>
        /// <param name="path">path</param>
        /// <param name="options">Autocontroller options</param>
        public static void UseIDBEmitter <T>(
            this IApplicationBuilder appBuilder,
            string indexedDBname,
            string path,
            IAutoControllerOptions options
            ) where T : DbContext
        {
            if (appBuilder == null)
            {
                throw new ArgumentNullException(nameof(appBuilder));
            }
            var logger = GetOrCreateLogger(appBuilder, LogCategoryName);
            // This is not nessesary register it as service
            // because it should run once
            DBEmitService <T> emitter = new DBEmitService <T>();

            emitter.Initialize(path, indexedDBname, options);
            //emitter.Dispose();
        }
 /// <summary>
 /// Adds autocontroller for DBContext.
 ///
 /// </summary>
 /// <typeparam name="T">The DBContext derived type</typeparam>
 /// <param name="appBuilder">The ApplicationBuilder instance</param>
 /// <param name="options">Options for autocontroller</param>
 public static void UseAutoController <T>(
     this IApplicationBuilder appBuilder,
     IAutoControllerOptions options) where T : DbContext
 {
     UseAutoController <T>(appBuilder,
                           options.RoutePrefix,
                           options.LogInformation,
                           options.InteractingType,
                           options.AuthentificationPath,
                           options.AccessDeniedPath,
                           options.JsonSerializerOptions,
                           options.DefaultGetAction,
                           options.DefaultGetCountAction,
                           options.DefaultPostAction,
                           options.DefaultDeleteAction,
                           options.DefaultFilterParameter,
                           options.DefaultSortParameter,
                           options.DefaultSortDirectionParameter,
                           options.DefaultPageParameter,
                           options.DefaultItemsPerPageParameter,
                           options.DefaultUpdateAction);
 }