public OutputCls CreateUser(string username, string password, string Email) { OutputCls res = new OutputCls() { Result = false, Comment = "Create user failed." }; var db = container.Get<SchemaDb>(); var datas = from c in db.GetAllData<User>() where c.UserName == username select c; if (datas.Count() > 0) { res.Comment = "User is already exists."; return res; } db.InsertData<User>(new User() { UserName = username, Password = password, Email = Email, IsLocked = false, Id = db.GetSequence<User>() }); res.Result = true; res.Comment = "User registered."; return res; }
protected void Page_Load(object sender, EventArgs e) { var hubManager = new DefaultHubManager(GlobalHost.DependencyResolver); _hub = hubManager.ResolveHub("WebHub") as WebHub; string req = Request.QueryString["op"]; Response.Clear(); OutputCls status = new OutputCls(); if (req == "signin") { string username = Request["username"]; string password = Request["password"]; var output = _hub.Login(username, password); Response.ContentType = "application/json; charset=utf-8"; if (output.Result.Value) { FormsAuthentication.SetAuthCookie(username, false); //var test = System.Web.HttpContext.Current.User.Identity.IsAuthenticated; status.Result = true; Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(status)); } else { status.Result = false; Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(status)); } } else { status.Result = false; Response.ContentType = "application/json"; HttpContext.Current.Session.Abandon(); FormsAuthentication.SignOut(); Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(status)); } Response.End(); }
public OutputCls DeleteData(long SchemaId,long KeyId) { OutputCls output = new OutputCls() { Result = false, Comment = "No params provided." }; //get schemaid to determine dbtype var item = getSchemaById(SchemaId); if (item != null) { if (KeyId > 0) { output.Result = Task.Run(async () => await Db[item.SchemaType].DeleteData(KeyId, item.SchemaName)).Result; } else { output.Comment = "KeyId cannot less than 0!"; } } else { output.Comment = "Schema not found!"; } return output; }
public OutputCls InsertData(string ObjInJson, long SchemaId) { OutputCls output = new OutputCls() { Result = false, Comment = "No params provided." }; //get schemaid to determine dbtype var item = getSchemaById(SchemaId); if (item != null) { if (!string.IsNullOrEmpty(ObjInJson)) { dynamic data = SchemaConverter.JsonToExpando(ObjInJson); output.Result = Db[item.SchemaType].InsertData(data, item.SchemaName); } else { output.Comment = "Object cannot be empty!"; } } else { output.Comment = "Schema not found!"; } return output; }
public OutputCls Login(string username, string password) { OutputCls res = new OutputCls() { Result = false, Comment = "Username & password invalid." }; var db = container.Get<SchemaDb>(); var datas = from c in db.GetAllData<User>() where c.UserName == username select c; foreach (var item in datas) { if (item.Password == password) { res.Comment = "Login succeed."; res.Result = true; SetDatabaseName(username); return res; } } return res; // Call the broadcastMessage method to update clients. //Clients.All.displayData(datas); }
public OutputCls SaveLapor(string nama, string url, string keterangan) { OutputCls res = new OutputCls() { Result = false, Comment = "Create user failed." }; var db = container.Get<SchemaDb>(); res.Result = db.InsertData<Laporan>(new Laporan() { nama = nama, url = url, keterangan = keterangan, Id = db.GetSequence<Laporan>() }); res.Comment = "User registered."; return res; }
public async Task<OutputCls> ExportData(long SchemaId,string UserName,string Tipe) { SetDatabaseName(); OutputCls output = new OutputCls() { Result = false, Comment = "export data error." }; try { string SchemaName = string.Empty; SchemaTypes SchemaType = SchemaTypes.StreamData; ISchemaContext ctx = new SchemaDb(); var data = from c in ctx.GetAllData<SchemaEntity>() where c.Id == SchemaId select c; foreach (var item in data) { SchemaName = item.SchemaName; SchemaType = item.SchemaType; } IDataContext dtx = null; dtx = GetDB(SchemaType); string PathToFile = string.Format(string.Format("{0}/{1}/{2}", DownloadPath, UserName, SchemaName)); if (!Directory.Exists(PathToFile)) Directory.CreateDirectory(PathToFile); var temp = await dtx.GetAllData(SchemaName); var FileName = string.Empty; switch (Tipe) { case "csv": string csvstr = SchemaConverter.ExpandoToCsv(temp); FileName = SchemaName + DateTime.Now.ToString("_yyyyMMdd_HHmm") + ".csv"; File.WriteAllText(string.Format("{0}/{1}", PathToFile, FileName), csvstr); break; case "json": string jsonstr = JsonConvert.SerializeObject(temp); FileName = SchemaName + DateTime.Now.ToString("_yyyyMMdd_HHmm") + ".json"; File.WriteAllText(string.Format("{0}/{1}", PathToFile, FileName), jsonstr); break; case "xml": XElement el = SchemaConverter.ExpandoToXML(temp, SchemaName); FileName = SchemaName + DateTime.Now.ToString("_yyyyMMdd_HHmm") + ".xml"; File.WriteAllText(string.Format("{0}/{1}", PathToFile, FileName), el.ToString()); break; } output.Params = new List<dynamic>(); output.Params.Add(string.Format("/downloads/{0}/{1}/{2}", UserName, SchemaName, FileName)); output.Result = true; output.Comment = "ok"; return output; } catch (Exception ex) { output.Comment = ex.Message; return output; } }
public List<SchemaEntity> GetSchemas(string username) { OutputCls res = new OutputCls() { Result = false, Comment = "get schema error." }; var db = container.Get<SchemaDb>(); var datas = from c in db.GetAllData<SchemaEntity>() where c.CreatedBy == username orderby c.GroupName ascending select c; return datas.ToList(); // Call the broadcastMessage method to update clients. //Clients.All.displayData(datas); }
public OutputCls DesignSchema(dynamic Entity,List<dynamic> Rows) { ISchemaContext ctx = new SchemaDb(); var Fields = new List<IDField>(); OutputCls res = new OutputCls() { Result = false, Comment = "Schema invalid." }; foreach(dynamic item in Rows) { var Field = new IDField(); Field.Name = item.field_name; Field.IsMandatory = (bool)item.field_mandatory; Field.FieldType = FieldTypes.SingleField; switch ((string)item.field_type) { case "string": Field.NativeType = typeof(string); break; case "integer": Field.NativeType = typeof(Int64); break; case "double": Field.NativeType = typeof(double); break; case "datetime": Field.NativeType = typeof(DateTime); break; case "boolean": Field.NativeType = typeof(bool); break; case "character": Field.NativeType = typeof(char); break; default: Field.NativeType = typeof(string); break; } Field.RegexValidation = item.field_regex; Field.Desc = item.field_description; Fields.Add(Field); } string SchemaName = Entity.SchemaName; SchemaEntity newEntity = SchemaConverter.DesignToSchema(Fields, SchemaName); newEntity.GroupName = Entity.GroupName; newEntity.SchemaType = (SchemaTypes)Entity.SchemaType; newEntity.Description = Entity.Description; newEntity.AccessType = (AccessTypes)Entity.AccessType; newEntity.CreatedBy = Entity.UserName; newEntity.Id = ctx.GetSequence<SchemaEntity>(); ctx.InsertData<SchemaEntity>(newEntity); res.Result = true; res.Comment = "ok"; //khusus columnar (casandra) if ((SchemaTypes)Entity.SchemaType == SchemaTypes.HistoricalData) { SetDatabaseName(); var dx = container.Get<ColumnarDb>(); dx.SetupKeyspaceAndTable(SchemaName, newEntity.Fields); } return res; }
public async Task<OutputCls> DeleteData(int FID, string SchemaName) { SetDatabaseName(); OutputCls res = new OutputCls() { Result = false, Comment = "Update data failed." }; var username = System.Web.HttpContext.Current.User.Identity.Name; var db = container.Get<SchemaDb>(); var data = (from c in db.GetAllData<SchemaEntity>() where c.SchemaName == SchemaName && c.CreatedBy == username select c).SingleOrDefault(); IDataContext dx = null; dx = GetDB(data.SchemaType); res.Result = await dx.DeleteData(FID, SchemaName); res.Comment = "ok"; return res; }
public async Task<OutputCls> UpdateData(int FID, List<dynamic> Fields, string SchemaName) { SetDatabaseName(); OutputCls res = new OutputCls() { Result = false, Comment = "Update data failed." }; var username = System.Web.HttpContext.Current.User.Identity.Name; var db = container.Get<SchemaDb>(); var data = (from c in db.GetAllData<SchemaEntity>() where c.SchemaName == SchemaName && c.CreatedBy == username select c).SingleOrDefault(); IDataContext dx = null; dx = GetDB(data.SchemaType); dynamic Entity = new ExpandoObject(); foreach (dynamic newObj in Fields) { dynamic obj; if (data.Fields[(string)newObj.fieldname].NativeType == typeof(double)) { obj = Convert.ToDouble(newObj.fieldvalue); } else if (data.Fields[(string)newObj.fieldname].NativeType == typeof(DateTime)) { obj = Convert.ToDateTime(newObj.fieldvalue); } else if (data.Fields[(string)newObj.fieldname].NativeType == typeof(char)) { obj = Convert.ToChar(newObj.fieldvalue); } else if (data.Fields[(string)newObj.fieldname].NativeType == typeof(int)) { obj = Convert.ToInt32(newObj.fieldvalue); } else if (data.Fields[(string)newObj.fieldname].NativeType == typeof(Int64)) { obj = Convert.ToInt64(newObj.fieldvalue); } else { obj = Convert.ToString(newObj.fieldvalue); } (Entity as IDictionary<string, object>).Add((string)newObj.fieldname, obj); } Entity._id = FID; res.Result = await dx.UpdateData(Entity, SchemaName); res.Comment = "ok"; return res; }