protected override void Load(ContainerBuilder builder) { var settings = this.configuration.GetSettings <GeneralSettings>().InjectEnvVariables(); Console.WriteLine("Connection string: " + settings.ConnectionString); Console.WriteLine("Application Type: " + settings.ApplicationType.ToString()); Console.WriteLine("DB Name: " + settings.BUC_DB_Name); if (string.IsNullOrWhiteSpace(environment.WebRootPath)) { environment.WebRootPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } settings.FileRootPath = environment.WebRootPath; builder.RegisterInstance(settings) .SingleInstance(); //var contextConfig = new ContextConfig() { DbName = Settings.DB_SQLServer_NAME, Application = ApplicationType.SqlServerMigrations, DbPassword= "******", DbUser="******" }; var contextConfig = new ContextConfig() { DbName = settings.BUC_DB_Name, Application = settings.ApplicationType, ConnectionString = settings.ConnectionString }; builder.RegisterInstance(contextConfig).As <IContextConfig>(); var logManager = new NLogManager(); builder.RegisterInstance(logManager).As <ILogManager>().SingleInstance(); builder.RegisterInstance(logManager.GetLog()).As <ILogger>(); }
public static T TryInvoke <T>(this ContextConfig config, IExecutionContext context) { object value = config(context); T result; return(context.TryConvert(value, out result) ? result : default(T)); }
private static void RegisterService(IServiceCollection services, IConfiguration configuration) { NativeInjectorBootstrapp.RegisterServices(services); ContextConfig context = new ContextConfig(configuration); context.RegisterContext(services); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); ContextConfig.RegisterContext(Configuration); }
public TEntity Add(TEntity entity) { var user = _Context.Set <TEntity>().Add(entity); ContextConfig.SaveChanges(); return(user); }
static void Main(string[] args) { var consoleLogger = new ConsoleLogger(); var logger = new Logger(consoleLogger, consoleLogger); string executablePath = null; // if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // executablePath = Path.GetFullPath("../../../../../bin/CastXML/bin/castxml.exe"); var castXml = new CastXml(logger, new IncludeDirectoryResolver(logger), executablePath); var cppParser = new CppParser(logger, castXml); var config = new ContextConfig() { Id = Path.GetFullPath("test.c"), Process = new string[] { Path.GetFullPath("test.c"), // Path.GetFullPath("test.h"), }.ToList(), Include = new string[] { Path.GetFullPath("test.h"), }.ToList(), Macros = new Dictionary <string, string>() { { "ARRSIZE", "42 * 3" } } }; cppParser.Initialize(config); var module = cppParser.Run(new CppModel.CppModule()); foreach (var inc in module.Includes) { Console.WriteLine(inc.Name); foreach (var struct_ in inc.Structs) { Console.WriteLine(" " + struct_.Name + " " + struct_.Size); foreach (var field in struct_.Fields) { Console.WriteLine(" " + field.Name + " " + field.Offset); } } } Console.WriteLine(JsonConvert.SerializeObject(module, Formatting.Indented, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects, TypeNameHandling = TypeNameHandling.All })); foreach (var f in typeof(CastXml).Assembly.GetManifestResourceNames()) { Console.WriteLine(f); } Console.WriteLine(module); Environment.Exit(module is null ? 1 : 0); }
static void Main(string[] args) { DataLoad load = new DataLoad(); ContextConfig config = new ContextConfig(); if (!args.Contains("-c") || !args.Contains("-db") || !args.Contains("-f")) { Console.WriteLine("Command invalid : -c [mongodb connectionstring] -db [databasename] -f [Json file full path]"); Console.ReadKey(); } else { config.ConnectionString = args[Array.IndexOf(args, "-c") + 1]; try { config.DataBaseName = args[Array.IndexOf(args, "-db") + 1]; load.LoadData(config, args[Array.IndexOf(args, "-f") + 1]); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadKey(); } } }
public ActionResult Login(FormCollection fc) { string account = fc["account"].ToString(); string password = fc["password"].ToString(); P_User user = SugarFactory.GetInstance().Queryable <P_User>().Where(it => it.User_Accounts == account).AddJoinInfo("P_SystemRoles", "s2", "User_Roles_Code=Role_Code").Select("P_User.*,s2.Role_Name").Single(); string pass = Encryption.GetMd5(password); if (user != null) { if (user.User_Pwd.Equals(Encryption.GetMd5(password))) { ContextConfig.SetUser(user); return(Content("toastr.success('登陆成功!');", "application/x-javascript")); } else { return(Content("toastr.success('密码错误!');", "application/x-javascript")); } } else { return(Content("toastr.success('用户不存在!');", "application/x-javascript")); } }
private static IModuleList GetModules(ContextConfig condition, Pipeline pipeline) => new ModuleList { { Condition, new If(condition, pipeline.ToArray()) } };
private IDocument GenerateFeed(FeedType feedType, Feed feed, ContextConfig path, IExecutionContext context) { // Get the output path FilePath outputPath = path?.Invoke <FilePath>(context, "while getting output path"); if (outputPath == null) { return(null); } if (!outputPath.IsRelative) { throw new ArgumentException("The feed output path must be relative"); } // Generate the feed and document MemoryStream stream = new MemoryStream(); FeedSerializer.SerializeXml(feedType, feed, stream); stream.Position = 0; return(context.GetDocument(stream, new MetadataItems { new MetadataItem(Keys.RelativeFilePath, outputPath), new MetadataItem(Keys.WritePath, outputPath) })); }
/// <summary> /// Uses a function to determine a text template which is processed and added as metadata for /// each document. This allows you to specify different metadata for each document depending on the context. /// </summary> /// <param name="key">The metadata key for the generated text.</param> /// <param name="template">A delegate that returns the template to use.</param> public GenerateMeta(string key, ContextConfig template) : base(template) { if (key == null) { throw new ArgumentNullException(nameof(key)); } _key = key; }
// This will get documents based on the context - the delegate will only be called once, regardless of the number of input documents // The delegate should return a IEnumerable<IDocument> public Documents(ContextConfig documents) { if (documents == null) { throw new ArgumentNullException(nameof(documents)); } _contextDocuments = documents; }
/// <summary> /// Uses a function to determine a text template which is processed and added as metadata for /// each document. This allows you to specify different metadata for each document depending on the context. /// </summary> /// <param name="key">The metadata key for the generated text.</param> /// <param name="template">A delegate that returns the template to use.</param> public GenerateMeta(string key, ContextConfig template) : base(template) { if (key == null) { throw new ArgumentNullException(nameof(key)); } _key = key; }
/// <summary> /// Specifies a delegate that should be invoked once for all input documents. /// This will return the input documents. /// </summary> /// <param name="execute">A delegate to invoke that should return a <see cref="IEnumerable{IDocument}"/>.</param> public Execute(Action<IExecutionContext> execute) { _executeContext = ctx => { execute(ctx); return null; }; }
public async Task getPDV(ContextConfig config) { var context = new MongoDBDataContext(config); var pdv = new PDVRespository(context); var ret = await pdv.FindById(1); }
/// <summary> /// Specifies a delegate that should be invoked once for all input documents. /// This will return the input documents. /// </summary> /// <param name="execute">A delegate to invoke that should return a <see cref="IEnumerable{IDocument}"/>.</param> public Execute(Action <IExecutionContext> execute) { _executeContext = ctx => { execute(ctx); return(null); }; }
private static void InitAuthentication() { if (HttpContext.Current == null) { return; } ContextConfig.InitAuthentication(); }
/// <summary> /// This will get documents based on the context so you can perform custom document /// fetching behavior. The delegate will only be called once, /// regardless of the number of input documents. The return value /// is expected to be a <c>IEnumerable<IDocument></c>. /// </summary> /// <param name="documents">A delegate that should return /// a <c>IEnumerable<IDocument></c> containing the documents to output.</param> public Documents(ContextConfig documents) { if (documents == null) { throw new ArgumentNullException(nameof(documents)); } _contextDocuments = documents; }
private static IModuleList GetModules(ContextConfig condition, Pipeline pipeline) => new ModuleList { { Condition, new If(condition, pipeline.ToArray()) .WithoutUnmatchedDocuments() } };
/// <summary> /// Uses a function to determine an object to be added as metadata for each document. /// This allows you to specify different metadata for each document depending on the context. /// </summary> /// <param name="key">The metadata key to set.</param> /// <param name="metadata">A delegate that returns the object to add as metadata.</param> public Meta(string key, ContextConfig metadata) { if (key == null) { throw new ArgumentNullException(nameof(key)); } _key = key; _metadata = new ConfigHelper<object>(metadata); }
/// <summary> /// This sets the title of all input documents to a value from the delegate. /// </summary> /// <param name="title">A delegate that must return a string.</param> public Title(ContextConfig title) { if (title == null) { throw new ArgumentNullException(nameof(title)); } _title = (doc, ctx) => title(ctx); }
/// <summary> /// Reads all files that match the specified globbing patterns and/or absolute paths. This allows you to /// specify different patterns and/or paths depending on the context. /// </summary> /// <param name="patterns">A delegate that returns one or more globbing patterns and/or absolute paths.</param> public ReadFiles(ContextConfig patterns) { if (patterns == null) { throw new ArgumentNullException(nameof(patterns)); } _contextPatterns = patterns; }
/// <summary> /// Uses a function to determine an object to be added as metadata for each document. /// This allows you to specify different metadata for each document depending on the context. /// </summary> /// <param name="key">The metadata key to set.</param> /// <param name="metadata">A delegate that returns the object to add as metadata.</param> public Meta(string key, ContextConfig metadata) { if (key == null) { throw new ArgumentNullException(nameof(key)); } _key = key; _metadata = new ConfigHelper <object>(metadata); }
/// <summary> /// Controls the output path of the result document. If this is specified, the resulting <see cref="FilePath"/> /// will be used to set a <c>WritePath</c> metadata value. /// </summary> /// <param name="path">A delegate that should return a <see cref="FilePath"/> to the output file.</param> /// <returns>The current module instance.</returns> public SearchIndex WithPath(ContextConfig path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } _path = path; return(this); }
public void Initialize(ContextConfig configRoot) { _config = configRoot ?? throw new ArgumentNullException(nameof(configRoot)); OutputPath = Path.Combine(Path.GetTempPath(), "castxml-" + _config.Id.GetHashCode()); if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); } }
/// <summary> /// 登陆超时查询,如果超时则退回到登陆界面 /// </summary> /// <param name="filterContext"></param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { P_User user = ContextConfig.GetUser(); if (ContextConfig.GetUser() == null) { filterContext.Result = RedirectToRoute("Default", new { Controller = "Login", Action = "RedirectTo" }); } base.OnActionExecuting(filterContext); }
public static T Invoke <T>(this ContextConfig config, IExecutionContext context) { object value = config(context); T result; if (!context.TryConvert(value, out result)) { throw new InvalidOperationException( string.Format("Could not convert from type {0} to type {1}", value?.GetType().Name ?? "null", typeof(T).Name)); } return(result); }
private static string GetGlobbingPattern(IExecutionContext context, ContextConfig pagesPattern, ContextConfig ignorePaths, string extension) { List <string> segments = new List <string>(); IEnumerable <string> ignorePatterns = ignorePaths?.Invoke <IEnumerable <string> >(context).Select(x => "!" + x); if (ignorePatterns != null) { segments.AddRange(ignorePatterns); } segments.Add($"{(pagesPattern == null ? string.Empty : pagesPattern.Invoke(context) + "/")}**/{{!.git,}}/**/{{!_,}}*.{extension}"); return(segments.Count == 1 ? segments[0] : $"{{{string.Join(",", segments)}}}"); }
// Generates count number of new documents public Documents(int count) { _contextDocuments = ctx => { List<IDocument> documents = new List<IDocument>(); for (int c = 0; c < count; c++) { documents.Add(ctx.GetNewDocument()); } return documents; }; }
public void LoadData(ContextConfig config, string sourcefile) { var context = new MongoDBDataContext(config); var fileJson = File.ReadAllText(sourcefile); var data = JsonConvert.DeserializeObject <Data>(fileJson); data.pdvs.ForEach(p => { p.document = p.document.CnpJOnlyNumbers(); }); context.Database.GetCollection <PDVEntity>("pdvs").InsertMany(data.pdvs); Console.WriteLine($"{data.pdvs.Count} itens included in the collection pdvs"); }
/// <summary> /// Generates a specified number of new empty documents. /// </summary> /// <param name="count">The number of new documents to output.</param> public Documents(int count) { _contextDocuments = ctx => { List <IDocument> documents = new List <IDocument>(); for (int c = 0; c < count; c++) { documents.Add(ctx.GetDocument()); } return(documents); }; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); ContextConfig.InitAuthentication(); IocConfig.Run(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); }
/// <summary> /// Reads all files that match the specified globbing patterns and/or absolute paths. /// </summary> /// <param name="patterns">The globbing patterns and/or absolute paths to read.</param> public ReadFiles(params string[] patterns) { if (patterns == null) { throw new ArgumentNullException(nameof(patterns)); } if (patterns.Any(x => x == null)) { throw new ArgumentNullException(nameof(patterns)); } _contextPatterns = _ => patterns; }
/// <summary> /// Invokes the delegate with additional information in the exception message if the conversion fails. /// </summary> /// <typeparam name="T">The desired result type.</typeparam> /// <param name="config">The delegate.</param> /// <param name="context">The execution context.</param> /// <param name="errorDetails">A string to add to the exception message should the conversion fail.</param> /// <returns>A typed result from invoking the delegate.</returns> public static T Invoke <T>(this ContextConfig config, IExecutionContext context, string errorDetails) { object value = config(context); T result; if (!context.TryConvert(value, out result)) { errorDetails = GetErrorDetails(errorDetails); throw new InvalidOperationException( $"Could not convert from type {value?.GetType().Name ?? "null"} to type {typeof(T).Name}{errorDetails}"); } return(result); }
public Context CreateDbContext(string[] args) { var contextConfig = new ContextConfig() { DbName = Settings.DB_SQLite_NAME, Application = ApplicationType.SQLiteMigrations, ConnectionString = "Filename=" }; var connectionString = contextConfig.ConnectionString; DbContextOptionsBuilder <Context> optionsBuilder = new DbContextOptionsBuilder <Context>() .UseSqlite(connectionString, options => options.MigrationsAssembly("BudgetUnderControl.Migrations.SQLite")); return(new Context(optionsBuilder.Options, contextConfig)); }
/// <summary> /// Sets the feed identifier. The default value is a link to the site. /// </summary> /// <param name="feedId">A delegate that should return a <c>Uri</c> with /// the feed identifier.</param> public GenerateFeeds WithFeedId(ContextConfig feedId) { _feedId = feedId; return this; }
// Generates new documents with the defined content public Documents(params string[] content) { _contextDocuments = ctx => content.Select(x => ctx.GetNewDocument().Clone(x)); }
/// <summary> /// Sets the path to the generated RSS file. The default behavior is to generate a RSS feed with /// a path of "feed.rss". /// </summary> /// <param name="rssPath">A delegate that should return a <see cref="FilePath"/> for the RSS path. /// If the delegate is <c>null</c> or returns <c>null</c>, no RSS file will be generated.</param> public GenerateFeeds WithRssPath(ContextConfig rssPath) { _rssPath = rssPath; return this; }
protected ContentModule(ContextConfig content) { _content = new ConfigHelper<object>(content); }
/// <summary> /// Sets the feed updated time. The default value is the current UTC time. /// </summary> /// <param name="feedUpdated">A delegate that should return a <c>DateTime</c> with /// the feed updated time.</param> public GenerateFeeds WithFeedUpdated(ContextConfig feedUpdated) { _feedUpdated = feedUpdated; return this; }
public Replace(string search, ContextConfig content) : base(content) { _search = search; }
/// <summary> /// Appends the string value of the returned object to to content of each document. This /// allows you to specify different content to append depending on the execution context. /// </summary> /// <param name="content">A delegate that returns the content to append.</param> public Append(ContextConfig content) : base(content) { }
/// <summary> /// Specifies a delegate that should be invoked once for all input documents. /// </summary> /// <param name="execute">A delegate to invoke that should return a IEnumerable%lt;IDocument>.</param> public Execute(ContextConfig execute) { _executeContext = execute; }
/// <summary> /// Sets the feed copyright. The default value is the value for the "Copyright" key /// in the global metadata. /// </summary> /// <param name="feedCopyright">A delegate that should return a <c>string</c> with /// the feed copyright.</param> public GenerateFeeds WithFeedCopyright(ContextConfig feedCopyright) { _feedCopyright = feedCopyright; return this; }
/// <summary> /// Prepends the string value of the returned object to to content of each document. This /// allows you to specify different content to prepend depending on the execution context. /// </summary> /// <param name="content">A delegate that returns the content to prepend.</param> public Prepend(ContextConfig content) : base(content) { }
/// <summary> /// Sets the path to the generated RDF file. The default behavior is not to generate a RDF feed. /// </summary> /// <param name="rdfPath">A delegate that should return a <see cref="FilePath"/> for the RDF path. /// If the delegate is <c>null</c> or returns <c>null</c>, no RDF file will be generated.</param> public GenerateFeeds WithRdfPath(ContextConfig rdfPath) { _rdfPath = rdfPath; return this; }
// Generates new documents with the defined metadata public Documents(params IEnumerable<KeyValuePair<string, object>>[] metadata) { _contextDocuments = ctx => metadata.Select(ctx.GetNewDocument); }
/// <summary> /// Outputs the string value of the returned object to trace. This allows /// you to trace different content depending on the execution context. /// </summary> /// <param name="content">A delegate that returns the content to trace.</param> public Trace(ContextConfig content) : base(content) { }
// Generates new documents with the defined content and metadata public Documents(params Tuple<string, IEnumerable<KeyValuePair<string, object>>>[] contentAndMetadata) { _contextDocuments = ctx => contentAndMetadata.Select(x => ctx.GetNewDocument(x.Item2).Clone(x.Item1)); }
/// <summary> /// Uses the string value of the returned object as the new content for each document. /// This allows you to specify different content depending on the execution context. /// </summary> /// <param name="content">A delegate that gets the new content to use.</param> public Content(ContextConfig content) : base(content) { }
/// <summary> /// Sets the feed description. The default value is the value for the "Description" key /// in the global metadata. /// </summary> /// <param name="feedDescription">A delegate that should return a <c>string</c> with /// the feed description.</param> public GenerateFeeds WithFeedDescription(ContextConfig feedDescription) { _feedDescription = feedDescription; return this; }
/// <summary> /// Sets the feed title. The default value is the value for the "Title" key /// in the global metadata. /// </summary> /// <param name="feedTitle">A delegate that should return a <c>string</c> with /// the feed title.</param> public GenerateFeeds WithFeedTitle(ContextConfig feedTitle) { _feedTitle = feedTitle; return this; }
private IDocument GenerateFeed(FeedType feedType, Feed feed, ContextConfig path, IExecutionContext context) { // Get the output path FilePath outputPath = path?.Invoke<FilePath>(context); if (outputPath == null) { return null; } if (!outputPath.IsRelative) { throw new ArgumentException("The feed output path must be relative"); } // Generate the feed and document MemoryStream stream = new MemoryStream(); FeedSerializer.SerializeXml(feedType, feed, stream); stream.Position = 0; return context.GetDocument(stream, new MetadataItems { new MetadataItem(Keys.RelativeFilePath, outputPath), new MetadataItem(Keys.WritePath, outputPath) }); }
/// <summary> /// The object returned by the specified delegate is converted to JSON, which then either /// replaces the content of each input document or is stored in the specified metadata key. /// </summary> /// <param name="data">A delegate that returns the object to convert to JSON.</param> /// <param name="destinationKey">The metadata key where the JSON should be stored (or <c>null</c> /// to replace the content of each input document).</param> public GenerateJson(ContextConfig data, string destinationKey = null) { _data = (doc, ctx) => data(ctx); }
protected RantModule(ContextConfig template) : base(template) { SetEngine(); }
/// <summary> /// Sets the feed author. The default value is the value for the "Author" key /// in the global metadata. /// </summary> /// <param name="feedAuthor">A delegate that should return a <c>string</c> with /// the feed author.</param> public GenerateFeeds WithFeedAuthor(ContextConfig feedAuthor) { _feedAuthor = feedAuthor; return this; }
/// <summary> /// Sets the feed image link. The default value is the value for the "Image" key /// in the global metadata. /// </summary> /// <param name="feedImageLink">A delegate that should return a <c>Uri</c> with /// the feed image link.</param> public GenerateFeeds WithFeedImageLink(ContextConfig feedImageLink) { _feedImageLink = feedImageLink; return this; }
/// <summary> /// Uses a function to determine a text template which is processed and added as content /// for each document. This allows you to specify different content for each document depending on the context. /// </summary> /// <param name="template">A delegate that returns the template to use.</param> public GenerateContent(ContextConfig template) : base(template) { }
/// <summary> /// Sets the path to the generated Atom file. The default behavior is to generate a RSS feed with /// a path of "feed.atom". /// </summary> /// <param name="atomPath">A delegate that should return a <see cref="FilePath"/> for the Atom path. /// If the delegate is <c>null</c> or returns <c>null</c>, no Atom file will be generated.</param> public GenerateFeeds WithAtomPath(ContextConfig atomPath) { _atomPath = atomPath; return this; }