예제 #1
0
        public async void PushAsync()
        {
            _firebaseRequestManagerMock.Setup(
                firebaseRequestManager => firebaseRequestManager.RequestAsync(HttpMethod.Post, "todos", _expected))
            .Returns(Task.FromResult(_expectedResponse));

            var response = await _firebaseClient.PushAsync("todos", _expected);

            Assert.NotNull(response);
            Assert.AreEqual(response.Body, _expected.ToJson());
        }
        public async Task <IHttpActionResult> Put()
        {
            try
            {
                IFirebaseConfig config = new FirebaseConfig
                {
                    AuthSecret = "XQsDE173GieFhbMUUs2t2OD5eUwZFjjrEsAYbq6B",
                    BasePath   = "https://flickering-fire-4088.firebaseio.com/"
                };
                IFirebaseClient _client = new FirebaseClient(config);
                var             todo    = new
                {
                    name     = "Execute PUSH",
                    priority = 2
                };
                PushResponse response = await _client.PushAsync("todos/push", todo);

                string a = response.Result.Name;//The result will contain the child name of the new data that was added
                return(StatusCode(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #3
0
        private static async void EventStreaming()
        {
            await _client.DeleteAsync("chat");

            await _client.OnAsync("chat",
                                  added : async(sender, args) =>
            {
                System.Console.WriteLine(args.Data + "-> 1\n");
                await _client.PushAsync("chat/", new
                {
                    name = "someone",
                    text = "Console 1:" + DateTime.Now.ToString("f")
                });
            },
                                  changed : (sender, args) => { System.Console.WriteLine(args.Data); },
                                  removed : (sender, args) => { System.Console.WriteLine(args.Path); });

            EventStreamResponse response = await _client.OnAsync("chat",
                                                                 added : (sender, args) => { System.Console.WriteLine(args.Data + " -> 2\n"); },
                                                                 changed : (sender, args) => { System.Console.WriteLine(args.Data); },
                                                                 removed : (sender, args) => { System.Console.WriteLine(args.Path); });

            //Call dispose to stop listening for events
            //response.Dispose();
        }
예제 #4
0
        public async Task SendData(string name_, string age_)
        {
            try
            {
                IFirebaseConfig config = new FirebaseConfig
                {
                    AuthSecret = "a9UxW4ZVfdJRGHHQ8NusZmTZ0c3NRZgSlrakVXXM",
                    BasePath   = "https://myxamarintest.firebaseio.com/"
                };
                IFirebaseClient client = new FirebaseClient(config);

                //List<MyClass> myclass_list = new List<MyClass>();

                /*myclass_list.Add(new MyClass()
                 * {
                 *  age = int.Parse(age_),
                 *  name = name_
                 * });*/

                Chat mc = new Chat()
                {
                    Llave                 = "",
                    NombreChat            = "Nombre : " + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString(),
                    MensajeChat           = "Este es el mensaje del chat: " + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString(),
                    TipoChat              = "Chat",
                    FechaModificacionChat = DateTime.Now
                };

                await client.PushAsync("mensajes", mc);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
예제 #5
0
 public async void Button_Click(object sender, RoutedEventArgs e)
 {
     PushResponse response = await _client.PushAsync("chat/", new ChatMessage
     {
         name = "Win8",
         text = TextBoxMessage.Text + DateTime.Now.ToString("f")
     });
 }
예제 #6
0
        public async Task Push(cls_notifi notifi, string path)
        {
            IFirebaseClient client    = new FirebaseClient(config);
            var             my_notifi = notifi;
            PushResponse    response  = await client.PushAsync(path, my_notifi);

            var xcv = response.Result.name; //The result will contain the child name of the new data that was added
        }
예제 #7
0
        public async Task <IHttpActionResult> Push_for_room(object thingToPush, string path)
        {
            IFirebaseClient client   = new FirebaseClient(config);
            var             my_thing = thingToPush;
            PushResponse    response = await client.PushAsync(path, my_thing);

            var xcv = response.Result.name; //The result will contain the child name of the new data that was added

            return(Ok());
        }
예제 #8
0
        public async Task <IHttpActionResult> addRoom(cls_chat_room room)
        {
            var file = HttpContext.Current.Request.Files.Count > 0 ?
                       HttpContext.Current.Request.Files[0] : null;

            if (file != null && file.ContentLength > 0)
            {
                //var fileName = Path.GetFileName(file.FileName);
                string filename  = Path.GetFileNameWithoutExtension(file.FileName);
                string extention = Path.GetExtension(file.FileName);
                filename = filename + DateTime.Now.ToString("yymmddssfff") + extention;
                var path = Path.Combine(
                    HttpContext.Current.Server.MapPath("~/uploads/images/"),
                    filename
                    );
                room.photo = "~/uploads/images/" + filename;
                file.SaveAs(path);
            }



            IFirebaseClient client   = new FirebaseClient(config);
            var             new_room = room;

            PushResponse response = await client.PushAsync("chat/rooms/", new_room);

            var xcv      = response.Result.name;
            var firstMem = new
            {
                mem_id   = db.AspNetUsers.FirstOrDefault(x => x.UserName == room.adminName).Id,
                mem_name = room.adminName
            };

            await Push(firstMem, "chat/members/" + xcv);

            /////////////////////////////
            var new_room2 = new
            {
                RoomId        = xcv,
                RoomName      = room.name,
                about         = room.about,
                AddedOn       = DateTime.UtcNow,
                RoomType      = "ordinary-room",
                RelatedTypeId = 0
            };

            await Push(new_room2, "chat/memberRooms/" + db.AspNetUsers.FirstOrDefault(x => x.UserName == room.adminName).Id);

            return(Ok(room));
        }
예제 #9
0
        public List <ProductModel> GetFilteredProducts(string link, bool useCache, bool notify)
        {
            const string cacheKey  = "getFilteredProducts";
            var          cachedObj = _cache.Get(cacheKey);

            if (cachedObj != null && useCache)
            {
                return((List <ProductModel>)cachedObj);
            }

            IFirebaseClient client = new FirebaseClient(config);

            client.Delete("Products");             //Deletes all old items, otherwise they will popup

            const string cacheKeyOldProducts = "getFilteredProductsOldList";
            var          cachedObjOldList    = (List <ProductModel>)_cache.Get(cacheKeyOldProducts);

            var products = ScanProducts(link);

            var filteredProducts = new List <ProductModel>();

            foreach (var product in products.Where(a => a.PriceDrop < -49))
            {
                product.IsNew = false;
                var availableProduct = IsProductInStock(product);

                if (cachedObjOldList != null)
                {
                    var existsInOldList = cachedObjOldList.Any(a => a.Id == product.Id);
                    if (availableProduct != null && !existsInOldList)
                    {
                        product.IsNew = true;
                        if (notify)
                        {
                            client.PushAsync("Products", product);
                        }
                    }
                }

                if (availableProduct != null)
                {
                    filteredProducts.Add(product);
                }
            }
            _cache.Put(cacheKey, filteredProducts, new TimeSpan(0, 5, 0));
            _cache.Put(cacheKeyOldProducts, filteredProducts, new TimeSpan(0, 6, 0));

            return(filteredProducts);
        }
예제 #10
0
    public static async Task Main(String[] args)
    {
        var config = new FirebaseConfig
        {
            AuthSecret = "zDKG1ERNA4OQIPXDXocGz8sCIZzteIDdJpojB1Dt",
            BasePath   = "https://flexi-d8617.firebaseio.com",
        };

        var client = new FirebaseClient(config);
        var data   = new
        {
            id     = 1234,
            status = "Hello, world"
        };

        var response = await client.PushAsync("datas", data);
    }
예제 #11
0
        public static async void AddMyLogAsync(String key, String log)
        {
            try
            {
                IFirebaseConfig config = new FirebaseConfig
                {
                    AuthSecret = FIREBASE_KEY,
                    BasePath   = FIREBASE_URL
                };
                IFirebaseClient client = new FirebaseClient(config);

                PushResponse response = await client.PushAsync("dota/" + key, log);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #12
0
        private async void label1_Click(object sender, EventArgs e)
        {
            label1.Text = (InternetUtility.InternetConnected()) ? "Connected" : "Not Connected";

            IFirebaseConfig config = new FirebaseConfig()
            {
                AuthSecret = "hzTI7r7vll3gXZyQg78GKTgKGEo32aQ8sSK1zImB",
                BasePath   = "https://current-c.firebaseio.com/"
            };

            IFirebaseClient client = new FirebaseClient(config);

            var todo = new Models.User("Andy", new DateTime(1996, 2, 16));

            PushResponse response = await client.PushAsync("todos/set", todo);

            string tes1t = response.Result.name;
        }
예제 #13
0
        public async Task <bool> Upload(FileDataUploadRequestModel fileDataUploadRequestModel)
        {
            var auth = new FirebaseAuthProvider(new FirebaseConfig(ApiKey));

            Client = new FirebaseClient(Config);

            fileDataUploadRequestModel.SharingUser   = HttpContext.Current.GetOwinContext().Authentication.User.Claims.First().Value;
            fileDataUploadRequestModel.FileExtension = Path.GetExtension(fileDataUploadRequestModel.FilePath);
            var fileDataUploadResponseModel = fileDataUploadRequestModel.Convert();

            SetFileType(fileDataUploadResponseModel);

            Console.WriteLine(fileDataUploadRequestModel.HidingMethod);
            Console.WriteLine(fileDataUploadRequestModel.EncryptionMethod);
            switch (fileDataUploadResponseModel.FileType)
            {
            case FileType.Image:

                fileDataUploadResponseModel.File = EncryptAndHideInPicture(fileDataUploadRequestModel);
                break;

            case FileType.Video:
                fileDataUploadResponseModel.File = EncryptAndHideInVideo(fileDataUploadRequestModel);
                break;

            case FileType.Audio:
                fileDataUploadResponseModel.File = EncryptAndHideInAudio(fileDataUploadRequestModel);
                break;

            case FileType.Executable:
                fileDataUploadResponseModel.File = EncryptAndHideInBatchFile(fileDataUploadRequestModel);
                break;
            }


            var response = await Client.PushAsync("Files/", fileDataUploadResponseModel);

            fileDataUploadResponseModel.Id = response.Result.name;
            var setResult = await Client.SetAsync("Files/" + fileDataUploadResponseModel.Id, fileDataUploadResponseModel);

            return(setResult.StatusCode == HttpStatusCode.OK);
        }
예제 #14
0
        static async Task Test()
        {
            IFirebaseConfig config = new FirebaseConfig
            {
                AuthSecret = "XUCrsUoS3lxsQlYMcsBuIhGI21OH1N5iYM3sJCUD",
                BasePath   = "https://mynotes-87fd2.firebaseio.com/"
            };

            IFirebaseClient client   = new FirebaseClient(config);
            var             testNote = new Note()
            {
                Id   = Guid.NewGuid().ToString(),
                Date = DateTime.Now,
                Tags = new List <string>()
                {
                    "gulp", "front", "sass", "minify"
                },
                Text = "Set up gulp task in javascript projects to improve quality in front end architechture"
            };

            await client.PushAsync <Note>($"notes/{testNote.Id}", testNote);
        }
예제 #15
0
        private static async void EventStreaming()
        {
            await _client.DeleteAsync("chat");

            await _client.OnAsync("chat",
                                  added : async(sender, args) =>
            {
                System.Console.WriteLine(args.Data + "-> 1\n");
                await _client.PushAsync("chat/", new
                {
                    name = "someone",
                    text = "Console 1:" + DateTime.Now.ToString("f")
                });
            },
                                  changed : (sender, args) => { System.Console.WriteLine(args.Data); },
                                  removed : (sender, args) => { System.Console.WriteLine(args.Path); });

            await _client.OnAsync("chat",
                                  added : (sender, args) => { System.Console.WriteLine(args.Data + " -> 2\n"); },
                                  changed : (sender, args) => { System.Console.WriteLine(args.Data); },
                                  removed : (sender, args) => { System.Console.WriteLine(args.Path); });
        }
예제 #16
0
        public async Task <IActionResult> Post([FromBody] ProdutoEntidade value)
        {
            var clientProduto = await client.GetAsync("Produto");

            var result = clientProduto.ResultAs <dynamic>();

            if (result != null)
            {
                List <ProdutoEntidade> listProdutos = ConvertJsonToList <ProdutoEntidade>(result);
                var maxId = listProdutos?.Where(c => c != null)?.Max(c => c.Id);
                value.Id = maxId == null ? 1 : (int)maxId + 1;
            }
            else
            {
                value.Id = 1;
            }

            var response = await client.PushAsync("Produto/", value);

            var setresult = response.ResultAs <ProdutoEntidade>();

            return(Json(setresult));
        }
예제 #17
0
        public void AddProduct(ProductModel product)
        {
            IFirebaseClient client = new FirebaseClient(config);

            client.PushAsync("Products", product);
        }
예제 #18
0
        public async Task <IHttpActionResult> Postwork_group(work_group work_group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            /////// Add Chat Room for the Course ///////////////////////////////////////////////////////////



            IFirebaseClient client   = new FirebaseClient(config);
            cls_room        new_room = new cls_room {
                name = work_group.name, about = "Chat Room for " + work_group.name + " Group", admin = work_group.admin, photo = ""
            };

            PushResponse response = await client.PushAsync("chat/rooms/", new_room);

            var xcv      = response.Result.name;
            var firstMem = new
            {
                mem_id   = work_group.admin,                                                     //db.AspNetUsers.FirstOrDefault(x => x.UserName == room.adminName).Id,
                mem_name = db.AspNetUsers.FirstOrDefault(x => x.Id == work_group.admin).UserName //room.adminName
            };

            await PushChat(firstMem, "chat/members/" + xcv);

            /////////////////////////////
            var new_room2 = new
            {
                RoomId        = xcv,
                RoomName      = new_room.name,
                about         = "Chat room for " + work_group.name + " group",
                AddedOn       = DateTime.UtcNow,
                RoomType      = "group",
                RelatedTypeId = db.work_group.OrderByDescending(x => x.id).FirstOrDefault().id
            };

            await PushChat(new_room2, "chat/memberRooms/" + work_group.admin);

            work_group.room_id = xcv;
            db.work_group.Add(work_group);
            db.SaveChanges();

            Work_group_members wg = new Work_group_members();

            wg.Member_id     = work_group.admin;
            wg.Work_group_id = db.work_group.OrderByDescending(x => x.id).FirstOrDefault().id;
            wg.AddingDate    = System.DateTime.Now;
            db.Work_group_members.Add(wg);
            db.SaveChanges();



            //////////////////////////////////////////////////////////////////////////////////////////////
            //send notification to all friends
            var friends  = db.friends.Where(x => x.UserId == work_group.admin && x.Confirmed == true).Select(x => x.friendId);
            var friends2 = db.friends.Where(x => x.friendId == work_group.admin && x.Confirmed == true).Select(x => x.UserId);

            friends.Concat(friends2);
            //
            var new_notifi = new cls_notifi
            {
                source_name  = "group",
                source_id    = db.work_group.OrderByDescending(x => x.id).FirstOrDefault().id.ToString(),
                image        = "no image",
                body_English = "Work group " + work_group.name + " is available now by your friend " + db.AspNetUsers.FirstOrDefault(x => x.Id == work_group.admin).UserName,
                body_Arabic  = "تمت اتاحة مجموعة " + work_group.name + " من قبل صديقك " + db.AspNetUsers.FirstOrDefault(x => x.Id == work_group.admin).UserName,
                timestamp    = DateTime.UtcNow,
                readed       = false
            };

            foreach (var item in friends)
            {
                await Push(new_notifi, "notifications/" + item + "/" + DateTime.UtcNow.ToString("dd-MM-yyyy"));

                PushNotifi(db.AspNetUsers.FirstOrDefault(x => x.Id == item).DeviceToken, "New Workgroup", new_notifi.body_English, "group", db.work_group.OrderByDescending(x => x.id).FirstOrDefault().id.ToString());
            }



            return(CreatedAtRoute("DefaultApi", new { id = work_group.id }, work_group));
        }
예제 #19
0
        public async Task <IHttpActionResult> Postcourse(course course)
        {
            // course.instructor=
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Course_Members cm = new Course_Members();
            course_tags    ct = new course_tags();

            ct.course_id = course.id;
            //ct.tag_id=
            cm.Course_id  = course.id;
            cm.Member_id  = course.instructor;
            cm.AddingDate = course.creating_date;


            //send notification to all friends
            var friends  = db.friends.Where(x => x.UserId == course.instructor && x.Confirmed == true).Select(x => x.friendId);
            var friends2 = db.friends.Where(x => x.friendId == course.instructor && x.Confirmed == true).Select(x => x.UserId);

            friends.Concat(friends2);
            //
            var new_notifi = new cls_notifi
            {
                source_name  = "course",
                source_id    = db.courses.OrderByDescending(x => x.id).FirstOrDefault().id.ToString(),
                image        = "no image",
                body_English = "Course " + course.name + " is available now by your friend " + db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName,
                body_Arabic  = "تمت اتاحة كورس " + course.name + " من قبل صديقك  " + db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName,
                timestamp    = DateTime.UtcNow,
                readed       = false
            };

            foreach (var item in friends)
            {
                await Push(new_notifi, "notifications/" + item + "/" + DateTime.UtcNow.ToString("dd-MM-yyyy"));

                PushNotifi(db.AspNetUsers.FirstOrDefault(x => x.Id == item).DeviceToken, "New Course", new_notifi.body_English, "course", db.courses.OrderByDescending(x => x.id).FirstOrDefault().id.ToString());
            }


            /////// Add Chat Room for the Course ///////////////////////////////////////////////////////////



            IFirebaseClient client   = new FirebaseClient(config);
            cls_room        new_room = new cls_room {
                name = course.name, about = "Chat Room for " + course.name + " Course", admin = course.instructor, photo = ""
            };

            PushResponse response = await client.PushAsync("chat/rooms/", new_room);

            var xcv      = response.Result.name;
            var firstMem = new
            {
                mem_id   = course.instructor,                                                     //db.AspNetUsers.FirstOrDefault(x => x.UserName == room.adminName).Id,
                mem_name = db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName //room.adminName
            };

            await PushChat(firstMem, "chat/members/" + xcv);

            /////////////////////////////
            var new_room2 = new
            {
                RoomId        = xcv,
                RoomName      = new_room.name,
                about         = "Chat room for " + course.name + " course",
                AddedOn       = DateTime.UtcNow,
                RoomType      = "course",
                RelatedTypeId = db.courses.OrderByDescending(x => x.id).FirstOrDefault().id
            };

            await PushChat(new_room2, "chat/memberRooms/" + course.instructor);



            course.room_id = xcv;
            db.courses.Add(course);
            db.Course_Members.Add(cm);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = course.id }, course));
        }
        public async Task <PushResponse> SaveObjectToDatabaseAsync(string path, Object obj)
        {
            var response = await client.PushAsync(path, obj);

            return(response);
        }
예제 #21
0
        private async void button1_Click_1(object sender, EventArgs e)
        {
            if (NametextBox.Text == string.Empty)
            {
                MessageBox.Show("Please Enter all Information", caption: "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (RegistrationtextBox.Text == string.Empty)
            {
                MessageBox.Show("Please Enter all Information", caption: "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (MobileNotextBox4.Text == string.Empty)
            {
                MessageBox.Show("Please Enter all Information", caption: "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else
            {
                Student student = new Student();
                student.name           = NametextBox.Text;
                student.registrationNO = RegistrationtextBox.Text;
                student.mobileNo       = MobileNotextBox4.Text;
                student.departmentName = DepartmenttextBox5.Text;
                student.address        = AddresstextBox3.Text;
                student.Id             = Idlabel.Text;


                IFirebaseConfig firebaseConfig = new FirebaseConfig()
                {
                    AuthSecret = "0q034wxR0p8grjvFHJtPzXLmMhlTNH3yrgrqlAEf",
                    BasePath   = "https://crudforms.firebaseio.com/"
                };
                IFirebaseClient client = new FirebaseClient(firebaseConfig);
                if (InternetCheck.isInternet())
                {
                    if (Save.Text == @"Save")
                    {
                        PushResponse message = await client.PushAsync("StudentList", student);

                        if (message != null)
                        {
                            MessageBox.Show("Student Saved Successfully.", caption: "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Reset();
                            GetAllStudent();
                        }
                        else
                        {
                            MessageBox.Show("Student doesn't saved.", caption: "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    if (Save.Text == @"Update")
                    {
                        var message = await client.UpdateAsync("StudentList/" + student.Id, student);

                        if (message != null)
                        {
                            MessageBox.Show("Student Updated Successfully.", caption: "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Reset();
                            GetAllStudent();
                            Save.Text = "Save";
                        }
                        else
                        {
                            MessageBox.Show("Student doesn't Updated.", caption: "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please check your Internet connection !!!", caption: "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.Close();
                }
            }
        }
예제 #22
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            PushResponse response = await client.PushAsync("kinieapp/", this.MessageText.Text);

            this.MessageText.Text = string.Empty;
        }
예제 #23
0
        public async Task <bool> CreateUser(User Cuenta)
        {
            PushResponse response = await _Client.PushAsync("Users", Cuenta);

            return(response.StatusCode == HttpStatusCode.OK ? true : false);
        }
예제 #24
0
 public Task Add(Pet pet) =>
 _client.PushAsync(GetRegistryPath(pet), pet);