public string PushFireBaseData(string AuthSecret, string BasePath, string item) { IFirebaseConfig config = new FirebaseConfig { AuthSecret = AuthSecret, BasePath = BasePath }; IFirebaseClient client = new FirebaseClient(config); var todo = new { name = "Execute PUSH", priority = 2 }; PushResponse response = client.Push(item, todo); string retorno = JsonConvert.SerializeObject(response).ToString(); return retorno; }
public ActionResult Create(Student student) { IFirebaseClient client = new FirebaseClient(config); PushResponse response = client.Push("Students/", student); return(View()); /* * try * { * AddStudentToFirebase(student); * ModelState.AddModelError(string.Empty, "Add Successfully"); * } * catch(Exception ex) * { * ModelState.AddModelError(string.Empty, "Not Successfully"+ex.Message); * } * AddStudentToFirebase(student); * return View(); * } * * private void AddStudentToFirebase(Student student) * { * * * client = new FireSharp.FirebaseClient(config); * var data = student; * PushResponse response = client.Push("Students/", data); * * data.student_id = response.Result.name; * SetResponse setResponse = client.Set("Students/" + data.student_id, data); * }*/ }
public string postTransaction(Transaction transaction) { try { if (transaction.accountId == null) { return("Account id can`t be null. Transference failed"); } IFirebaseClient client = new FirebaseClient(config); transaction.account = getAccountById(transaction.accountId); if (transaction.account == null) { return("Account not found. Transference failed"); } PushResponse response = client.Push("transactions", transaction); Transaction result = response.ResultAs <Transaction>(); return("Transaction successfully recorded."); } catch (Exception ex) { throw ex; } }
static void Main(string[] args) { IFirebaseConfig config = new FirebaseConfig { BasePath = "https://simplephonenotify.firebaseio.com/" }; IFirebaseClient client = new FirebaseClient(config); Random ran = new Random(); string input = ""; while (!input.Equals("quit")) { Console.Write("Enter input: "); input = Console.ReadLine(); Console.WriteLine(input); var item = new Item { Name = input, Amount = ran.Next(1, 30) }; client.Push("items", item); Console.WriteLine(item); } Console.WriteLine("Finished"); Console.WriteLine(input); }
public string save(Note note) { IFirebaseClient client = new FirebaseClient(config); try { PushResponse response = client.Push("notes", note); return(response.Result.name); } catch { return("ko"); } }
public ActionResult Create(User user) { IFirebaseClient client = new FirebaseClient(config); var data = user; PushResponse response = client.Push("Users/", user); data.user_id = response.Result.name; SetResponse setResponse = client.Set("Users/" + data.user_id, data); return RedirectToAction("Index"); }
public ActionResult Create(Staff staff) { IFirebaseClient client = new FirebaseClient(config); var data = staff; PushResponse response = client.Push("Staffs/", data); data.staff_id = response.Result.name; SetResponse setResponse = client.Set("Staffs/" + data.staff_id, data); return(RedirectToAction("Index")); }
public string postAccount(Account account) { try { IFirebaseClient client = new FirebaseClient(config); PushResponse response = client.Push("accounts", account); Account result = response.ResultAs <Account>(); //The response will contain the data written return("Account successfully recorded."); } catch (Exception ex) { throw ex; } }
public static void Main(string[] args) { IFirebaseConfig config = new FirebaseConfig { AuthSecret = "", BasePath = "https://hip-voyager-241415.firebaseio.com" }; var people = new People { Name = "Tom", Designation = "TechLead", Age = 25 }; IFirebaseClient client = new FirebaseClient(config); _ = client.Push("People/", people); }
private void Acquire(string resource, TimeSpan timeout) { System.Diagnostics.Stopwatch acquireStart = new System.Diagnostics.Stopwatch(); acquireStart.Start(); while (true) { FirebaseResponse response = client.Get("locks"); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Dictionary <string, Lock> locks = response.ResultAs <Dictionary <string, Lock> >(); string reference = locks?.Where(l => l.Value.Resource == resource).Select(l => l.Key).FirstOrDefault(); if (string.IsNullOrEmpty(reference)) { response = client.Push("locks", new Lock { Resource = resource, ExpireOn = DateTime.UtcNow.Add(timeout) }); if (response.StatusCode == System.Net.HttpStatusCode.OK) { reference = ((PushResponse)response).Result.name; if (!string.IsNullOrEmpty(reference)) { lockReference = reference; break; } } } } // check the timeout if (acquireStart.ElapsedMilliseconds > timeout.TotalMilliseconds) { throw new FirebaseDistributedLockException($"Could not place a lock on the resource '{resource}': Lock timeout."); } // sleep for 500 millisecond System.Threading.Thread.Sleep(500); } }
public IActionResult Create(Reportdonet reportdonet) { Reportdonet r = reportdonet; DateTime aDate = DateTime.Now; string day = aDate.ToString("dd"); string month = aDate.ToString("MM"); string year = aDate.ToString("yyyy"); r.date = day + " " + month + " " + year; Random rnd = new Random(); int no = rnd.Next(1000, 10000); r.no = no.ToString(); IFirebaseClient client = new FirebaseClient(config); var data = r; PushResponse response = client.Push("Reportdonets/", r); data.reportdonet_id = response.Result.name; SetResponse setResponse = client.Set("Reportdonets/" + data.reportdonet_id, data); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(Project project, IFormFile file, IFormFile file2, IFormFile file3) { FileStream fs = null; FileStream fs2 = null; FileStream fs3 = null; var fileupload = file; var fileupload2 = file2; var fileupload3 = file3; if (fileupload == null) { IFirebaseClient client = new FirebaseClient(config); var data = project; PushResponse response = client.Push("Projects/", project); data.project_id = response.Result.name; SetResponse setResponse = client.Set("Projects/" + data.project_id, data); } else { if (fileupload.Length > 0) { if (fileupload2 == null && fileupload3 == null) { try { if (!Directory.Exists(_environment.WebRootPath + "\\imageproject\\")) { Directory.CreateDirectory(_environment.WebRootPath + "\\imageproject\\"); } //ReName Image Guid guid = Guid.NewGuid(); string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = guid + extension; string img = "/imageproject/" + fileName; // string path2 = Path.Combine(_environment.WebRootPath, $"imageproject"); if (Directory.Exists(path2)) { using (fs = new FileStream(Path.Combine(path2, fileupload.FileName), FileMode.Create)) { await fileupload.CopyToAsync(fs); } fs = new FileStream(Path.Combine(path2, fileupload.FileName), FileMode.Open); } else { } // // var auth = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)); // var a = await auth.SignInWithEmailAndPasswordAsync(AuthEmail, AuthPassword); // var cancellation = new CancellationTokenSource(); var upload = new FirebaseStorage( Bucket, new FirebaseStorageOptions { // AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken), ThrowOnCancel = true }) .Child("imagesproject") .Child(fileName) .PutAsync(fs, cancellation.Token); try { string link = await upload; project.image = link; IFirebaseClient client = new FirebaseClient(config); var data = project; PushResponse response = client.Push("Projects/", project); data.project_id = response.Result.name; SetResponse setResponse = client.Set("Projects/" + data.project_id, data); return(RedirectToAction("Index")); } catch (Exception ex) { Debug.WriteLine($"*******************{ex}************************"); throw; } } catch (Exception e) { Console.WriteLine(e); } } else if (fileupload2.Length > 0 && fileupload3 == null) { try { if (!Directory.Exists(_environment.WebRootPath + "\\imageproject\\") && !Directory.Exists(_environment.WebRootPath + "\\imageproject2\\")) { Directory.CreateDirectory(_environment.WebRootPath + "\\imageproject\\"); Directory.CreateDirectory(_environment.WebRootPath + "\\imageproject2\\"); } //ReName Image Guid guid = Guid.NewGuid(); Guid guid2 = Guid.NewGuid(); string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = guid + extension; string fileName2 = Path.GetFileNameWithoutExtension(file2.FileName); string extension2 = Path.GetExtension(file2.FileName); fileName2 = "image2" + extension2; // string path2 = Path.Combine(_environment.WebRootPath, $"imageproject"); string path3 = Path.Combine(_environment.WebRootPath, $"imageproject2"); if (Directory.Exists(path2) && Directory.Exists(path3)) { using (fs = new FileStream(Path.Combine(path2, fileupload.FileName), FileMode.Create)) { await fileupload.CopyToAsync(fs); } fs = new FileStream(Path.Combine(path2, fileupload.FileName), FileMode.Open); using (fs2 = new FileStream(Path.Combine(path3, fileupload2.FileName), FileMode.Create)) { await fileupload2.CopyToAsync(fs2); } fs2 = new FileStream(Path.Combine(path3, fileupload2.FileName), FileMode.Open); } // // var auth = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)); // var a = await auth.SignInWithEmailAndPasswordAsync(AuthEmail, AuthPassword); // var cancellation = new CancellationTokenSource(); var cancellation2 = new CancellationTokenSource(); var upload = new FirebaseStorage( Bucket, new FirebaseStorageOptions { // AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken), ThrowOnCancel = true }) .Child("imagesproject") .Child(fileName) .PutAsync(fs, cancellation.Token); var upload2 = new FirebaseStorage( Bucket, new FirebaseStorageOptions { // AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken), ThrowOnCancel = true }) .Child("imagesproject") .Child(fileName2) .PutAsync(fs2, cancellation2.Token); try { string link = await upload; string link2 = await upload2; project.image = link; project.image2 = link2; IFirebaseClient client = new FirebaseClient(config); var data = project; PushResponse response = client.Push("Projects/", project); data.project_id = response.Result.name; SetResponse setResponse = client.Set("Projects/" + data.project_id, data); return(RedirectToAction("Index")); } catch (Exception ex) { Debug.WriteLine($"*******************{ex}************************"); throw; } } catch (Exception e) { Console.WriteLine(e); } } else if (fileupload.Length > 0 && fileupload2.Length > 0 && fileupload3.Length > 0) { try { if (!Directory.Exists(_environment.WebRootPath + "\\imageproject\\")) { Directory.CreateDirectory(_environment.WebRootPath + "\\imageproject\\"); } //ReName Image Guid guid = Guid.NewGuid(); Guid guid2 = Guid.NewGuid(); Guid guid3 = Guid.NewGuid(); string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = guid + extension; string fileName2 = Path.GetFileNameWithoutExtension(file2.FileName); string extension2 = Path.GetExtension(file2.FileName); fileName2 = guid2 + extension2; string fileName3 = Path.GetFileNameWithoutExtension(file3.FileName); string extension3 = Path.GetExtension(file3.FileName); fileName3 = guid3 + extension3; // string path2 = Path.Combine(_environment.WebRootPath, $"imageproject"); if (Directory.Exists(path2)) { using (fs = new FileStream(Path.Combine(path2, fileupload.FileName), FileMode.Create)) { await fileupload.CopyToAsync(fs); } fs = new FileStream(Path.Combine(path2, fileupload.FileName), FileMode.Open); using (fs2 = new FileStream(Path.Combine(path2, fileupload2.FileName), FileMode.Create)) { await fileupload3.CopyToAsync(fs2); } fs2 = new FileStream(Path.Combine(path2, fileupload2.FileName), FileMode.Open); using (fs3 = new FileStream(Path.Combine(path2, fileupload3.FileName), FileMode.Create)) { await fileupload3.CopyToAsync(fs3); } fs3 = new FileStream(Path.Combine(path2, fileupload3.FileName), FileMode.Open); } else { } // // var auth = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)); // var a = await auth.SignInWithEmailAndPasswordAsync(AuthEmail, AuthPassword); // var cancellation = new CancellationTokenSource(); var cancellation2 = new CancellationTokenSource(); var cancellation3 = new CancellationTokenSource(); var upload = new FirebaseStorage( Bucket, new FirebaseStorageOptions { // AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken), ThrowOnCancel = true }) .Child("imagesproject") .Child(fileName) .PutAsync(fs, cancellation.Token); var upload2 = new FirebaseStorage( Bucket, new FirebaseStorageOptions { // AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken), ThrowOnCancel = true }) .Child("imagesproject") .Child(fileName2) .PutAsync(fs2, cancellation2.Token); var upload3 = new FirebaseStorage( Bucket, new FirebaseStorageOptions { // AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken), ThrowOnCancel = true }) .Child("imagesproject") .Child(fileName3) .PutAsync(fs3, cancellation3.Token); try { string link = await upload; string link2 = await upload2; string link3 = await upload3; project.image = link; project.image2 = link2; project.image3 = link3; IFirebaseClient client = new FirebaseClient(config); var data = project; PushResponse response = client.Push("Projects/", project); data.project_id = response.Result.name; SetResponse setResponse = client.Set("Projects/" + data.project_id, data); return(RedirectToAction("Index")); } catch (Exception ex) { Debug.WriteLine($"*******************{ex}************************"); throw; } } catch (Exception e) { Console.WriteLine(e); } } } } return(RedirectToAction("Index")); }
public PushResponse SaveObjectToDatabase(string path, Object obj) { var response = client.Push(path, obj); return(response); }
public Payload SendNotification(Payload payload) { PushResponse response = _firebaseClient.Push("/users/" + payload.ToUserId, payload); return(response.ResultAs <Payload>()); }