public static void CreateEvent(BaseEvent data) { EventLog evt = new EventLog() { Data = data }; BaseProcs.Add(evt).Wait(); }
private static void LoadConfig() { ConfigurationHelper.Init(); RedisConnection.Init(ConfigurationHelper.GetInteger("Redis:Db"), ConfigurationHelper.GetString("Redis:Host"), ConfigurationHelper.GetInteger("Redis:Port"), ConfigurationHelper.GetString("Redis:PassWd")); BsonSerializer.RegisterSerializer(typeof(DateTime), new MyMongoDBDateTimeSerializer()); LogHelper.Init(ConfigurationHelper.GetString("Mongo:ConnectionString"), ConfigurationHelper.GetString("Mongo:DatabaseName"), ConfigurationHelper.GetBoolean("Mongo:IsReplicaSet"), ConfigurationHelper.GetString("Mongo:ReplicaSetName")); BaseProcs.Init(MongoConnect.GetHelper(ConfigurationHelper.GetString("Mongo:ConnectionString"), ConfigurationHelper.GetString("Mongo:DatabaseName"), 10, ConfigurationHelper.GetBoolean("Mongo:IsReplicaSet"), ConfigurationHelper.GetString("Mongo:ReplicaSetName"))).Wait(); DatabaseInit.Init(); //AccountProcs.Init(MongoConnect.GetHelper(ConfigurationHelper.GetString("AccountDb:ConnectionString"), ConfigurationHelper.GetString("AccountDb:DatabaseName"), 10, ConfigurationHelper.GetBoolean("AccountDb:IsReplicaSet"), ConfigurationHelper.GetString("AccountDb:ReplicaSetName"))).Wait(); CultureInfo.CurrentCulture = new CultureInfo("vi-VN"); }
public TestQuery(IHttpContextAccessor httpContext) { FieldAsync <ResponseType <GroupType> >("getAnimal", description: "lấy nội dung animal theo _id truyền vào", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "_id" }), resolve: async contex => { string _id = contex.GetArgument <string>("_id"); var animal = await BaseProcs.Get <Group>(_id); return(Success(animal)); } ); Field <PagingModelType <GroupType> >("listAnimal", description: "Danh sách animal có phân trang", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "page" }, new QueryArgument <IntGraphType> { Name = "pageSize" }, new QueryArgument <ListGraphType <SortedInputType> > { Name = "sorted" }, new QueryArgument <ListGraphType <FilteredInputType> > { Name = "filtered" }), resolve: context => { List <QueryFilter> filters = context.GetArgument("filtered", new List <QueryFilter>()); int page = context.GetArgument("page", 0);//page nay bat dau tu 0 int pageSize = context.GetArgument("pageSize", 10); int skip = (page * pageSize); List <QueryOrder> order = context.GetArgument("sorted", new List <QueryOrder>()); int pages, records; var data = BaseProcs.Search <Group>(filters, skip, pageSize, order, out pages, out records); return(new PagingModel() { Data = data, Pages = pages, Page = page, Records = records }); } ); }
public async Task StoreAsync(PersistedGrant grant) { //_dbRepository.Add<PersistedGrant>(grant); //return Task.FromResult(0); await BaseProcs.Add(grant); }
public static void Init() { BaseProcs.RegisterOption(BaseProcs.UNIQUE_OPTION, BaseProcs.IndexBuilder <AccountGroup>().Ascending(a => a.AccountId).Ascending(a => a.Group)).Wait(); }
public TestMutation(IHttpContextAccessor httpContext) { FieldAsync <ResponseType <GroupType> >("addAnimal", arguments: new QueryArguments(new QueryArgument <GroupInput> { Name = "animal" }), resolve: async context => { Group animal = context.GetArgument <Group>("animal"); await BaseProcs.Add(animal); return(Success(animal)); } ); FieldAsync <ResponseType <GroupType> >("updateAnimal", description: "Cập nhật animal yêu cầu quyền của người đã login", arguments: new QueryArguments(new QueryArgument <GroupInput> { Name = "animal" }), resolve: async context => { var user = LoginSession.Current(httpContext.HttpContext); Group animal = context.GetArgument <Group>("animal"); await BaseProcs.Update(animal); return(Success(animal, $"bạn đã update thành công bằng tài khoản {user.UserName}")); } ).FieldAuthorizeWithName(Policies.BASE_ACCOUNT_POLICY); FieldAsync <ResponseType <LoginSessionType> >("login", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "username" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "password" }), resolve: async context => { string username = context.GetArgument <string>("username"); string password = context.GetArgument <string>("password"); ///giả thiết check database thành công thì lưu vào session để các query sau hiểu là thằng này đã đăng nhập ///module Authentication sẽ tự động check header Authorization của client gửi lên và truy vấn các cache này để quyết định ///1 user có đang login hay không /// RedisConnection cache = new RedisConnection(); LoginSession session = new LoginSession() { FullName = "Register to input this field", AccessToken = Guid.NewGuid().ToString("N"), CreateOn = DateTime.Now, ExpireOn = DateTime.Now.AddHours(2), UserName = username, }; //lưu session=redis (cache = database) await cache.StoreAsync(session, TimeSpan.FromDays(2)); //for test i will let the time long var HttpContext = httpContext.HttpContext; //cache bằng session mặc định của dotnet HttpContext.Session.SetString("token", JsonConvert.SerializeObject(session)); return(Success(session)); } ); }