Exemplo n.º 1
0
        public ChefDataAccessLayer()
        {
            FirestoreClientBuilder firestoreClientBuilder = new FirestoreClientBuilder();

            firestoreClientBuilder.JsonCredentials = GoogleApisOAuthJsonString;
            FirestoreClient firestoreClient = firestoreClientBuilder.Build();

            fireStoreDB = FirestoreDb.Create("akshaysdemo", firestoreClient);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            //Code for GOOGLE AUTHENTICATION CREDENTIALS part

            var jsonString = File.ReadAllText(keyFilepath);
            var builder    = new FirestoreClientBuilder {
                JsonCredentials = jsonString
            };
            FirestoreDb db = FirestoreDb.Create(projectId, builder.Build());

            //standard project setup
            CreateWebHostBuilder(args).Build().Run();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Connect to Firestore database
 /// </summary>
 /// <param name="Collection"></param>
 /// <param name="Document"></param>
 /// <returns></returns>
 internal static bool Connect(string Collection, string Document)
 {
     CollectionName = Collection;
     DocumentName   = Document;
     try
     {
         string path = FileManager.getCredentialsPath();
         FirestoreClientBuilder builder = new FirestoreClientBuilder();
         builder.CredentialsPath = path;
         var client = builder.Build();
         firestoreDb = FirestoreDb.Create("bimsocket-db", client);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public static IServiceCollection AddApplicationDependencies(this IServiceCollection services, FirestoreAppSettings firestoreSettings)
        {
            services.AddSingleton <IUserService, UserService>();
            services.AddSingleton <IJwtService <User, UserToken>, UserJwtService>();
            services.AddSingleton <ICryptographyService, CryptographSHA512Service>();

            services.AddSingleton <IFirestoreRepository, FirestoreRepository>();

            var builder = new FirestoreClientBuilder();

            builder.JsonCredentials = firestoreSettings.Credentials;

            // Add Firestore singleton
            services.AddSingleton(FirestoreDb.Create(firestoreSettings.ProjectId, builder.Build()).Collection(firestoreSettings.CollectionName));

            services.AddSingleton(AddMappers());

            return(services);
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddOptions();

            var settings = Configuration.GetSection(nameof(FirestoreAdviserNotifierOptions)).Get <FirestoreAdviserNotifierOptions>();

            services.AddSingleton(_ =>
            {
                var builder = new FirestoreClientBuilder
                {
                    JsonCredentials = Encoding.UTF8.GetString(Convert.FromBase64String(settings.FirebaseCredentials))
                };

                var client = builder.Build();

                return(FirestoreDb.Create(settings.ProjectId, client));
            });

            services.Configure <FirestoreAdviserNotifierOptions>(Configuration.GetSection(nameof(FirestoreAdviserNotifierOptions)));
            services.AddScoped <IAdviserNotifier, FirestoreAdviserNotifier>();
        }
        private static void Main(string[] args)
        {
            var jsonString = File.ReadAllText("htlgkr-testet-firebase-adminsdk-s5lca-0cbf2afb33.json");

            var pdfManager     = new PdfManager();
            var storageManager = new StorageManager(jsonString);


            var builder = new FirestoreClientBuilder {
                JsonCredentials = jsonString
            };
            var db = FirestoreDb.Create("htlgkr-testet", builder.Build());


            var coll = db.Collection("Registrations");

            var listener = coll.Listen(snapshot =>
            {
                foreach (var change in snapshot.Changes)
                {
                    try
                    {
                        var doc        = change.Document;
                        var dict       = doc.ToDictionary();
                        dict["doc_id"] = doc.Id;

                        var name = dict["lastname"] as string;
                        var createdRegistration = dict["registrationPdfCreated"] as bool?;
                        var createdResult       = dict["resultPdfCreated"] as bool?;

                        var selectedFacility = (dict["selectedFacility"] as DocumentReference).GetSnapshotAsync()
                                               .Result;

                        dict["screening-station"] = selectedFacility.GetValue <string>("name");

                        dict["station-location"] = selectedFacility.GetValue <string>("city");

                        var now = DateTime.Now;

                        dict["time"] = now.ToShortTimeString();
                        dict["date"] = now.ToShortDateString();

                        if (!(createdRegistration ?? true))
                        {
                            Console.WriteLine("Generating registration-pdf for " + name);

                            storageManager.DownloadFile((dict["barcodelocation"] as string) + ".svg", "Registration-PDF/assets/qr.svg");

                            pdfManager.GeneratePDF(dict, true);
                            storageManager.UploadFile("out.pdf", doc.Id, "registration-pdf");

                            change.Document.Reference.UpdateAsync("registrationPdfCreated", true);
                        }

                        if (!(createdResult ?? true))
                        {
                            Console.WriteLine("Generating result-pdf for " + name);
                            pdfManager.GeneratePDF(dict, false);
                            storageManager.UploadFile("out.pdf", doc.Id, "result-pdf");

                            change.Document.Reference.UpdateAsync("resultPdfCreated", true);
                        }
                    }
                    catch (KeyNotFoundException e)
                    {
                        // Console.WriteLine(e.Message);
                    }
                }
            });

            listener.ListenerTask.Wait();
        }