コード例 #1
0
        internal RoundRobinPool(int size, string projectId)
        {
            ICredential credential = GoogleCredential.GetApplicationDefault();

            _pool = Enumerable
                    .Range(0, size)
                    .Select(_ => CreateFirestoreDb())
                    .ToArray();

            FirestoreDb CreateFirestoreDb()
            {
                // This code forces each channel to really use a different network connection.
                // Without this, different .NET Channel objects can end up using the same underlying
                // connection due to pooling in the C-core layer of gRPC.
                // Note: it would be nice to have a simpler way of doing this.
                var channel = new Channel(
                    FirestoreClient.DefaultEndpoint.ToString(),
                    credential.ToChannelCredentials(),
                    new ChannelOption[] { new ChannelOption("grpc_gcp.client_channel.id", Guid.NewGuid().ToString()) });
                var client = new FirestoreClientBuilder {
                    CallInvoker = channel.CreateCallInvoker()
                }.Build();

                return(FirestoreDb.Create(projectId, client));
            }
        }
コード例 #2
0
        public ChefDataAccessLayer()
        {
            FirestoreClientBuilder firestoreClientBuilder = new FirestoreClientBuilder();

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

            fireStoreDB = FirestoreDb.Create("akshaysdemo", firestoreClient);
        }
コード例 #3
0
        /// <inheritdoc />
        public override async Task <FirestoreDb> BuildAsync(CancellationToken cancellationToken = default)
        {
            var projectId     = ProjectId ?? (await Platform.InstanceAsync().ConfigureAwait(false)).ProjectId;
            var clientBuilder = FirestoreClientBuilder.FromOtherBuilder(this);

            clientBuilder.Settings = Settings;
            var client = await clientBuilder.BuildAsync(cancellationToken).ConfigureAwait(false);

            return(BuildFromClient(projectId, client));
        }
コード例 #4
0
        /// <inheritdoc />
        public override FirestoreDb Build()
        {
            var projectId     = ProjectId ?? Platform.Instance().ProjectId;
            var clientBuilder = FirestoreClientBuilder.FromOtherBuilder(this);

            clientBuilder.Settings = Settings;
            var client = clientBuilder.Build();

            return(BuildFromClient(projectId, client));
        }
コード例 #5
0
        private static async Task <FirestoreDb> InitializeDb(string credentials)
        {
            var builder = new FirestoreClientBuilder
            {
                JsonCredentials = Encoding.UTF8.GetString(Convert.FromBase64String(credentials))
            };

            var client = await builder.BuildAsync();

            return(await FirestoreDb.CreateAsync(ProjectId, client));
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Yogesh-34/PharmaGoProject
        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();
        }
コード例 #7
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);
     }
 }
コード例 #8
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);
        }
コード例 #9
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>();
        }
コード例 #10
0
        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();
        }