예제 #1
0
        public void MaximalConfiguration()
        {
            string warning = null;
            var    builder = new FirestoreDbBuilder
            {
                ProjectId     = "proj",
                DatabaseId    = "db",
                CallInvoker   = new FakeCallInvoker(),
                WarningLogger = text => warning = text,
                Settings      = new FirestoreSettings {
                    Clock = new FakeClock()
                },
                ConverterRegistry = new ConverterRegistry {
                    new SerializationTestData.GuidConverter()
                }
            };
            var db = builder.Build();

            Assert.Equal("proj", db.ProjectId);
            Assert.Equal("db", db.DatabaseId);
            db.LogWarning("Test warning");
            Assert.Equal("Test warning", warning);
            Assert.IsType <FakeClock>(db.Client.Settings.Clock);
            Assert.IsType <CustomConverter <Guid> >(db.SerializationContext.GetConverter(typeof(Guid)));
        }
예제 #2
0
        public static FirestoreDb GenerateFireStore(string projectname, string path)
        {
            FirestoreDbBuilder builder = new FirestoreDbBuilder();

            builder.CredentialsPath = path;
            builder.ProjectId       = projectname;

            return(builder.Build());
        }
예제 #3
0
        private FirestoreDb GetDb()
        {
            var dbBuilder = new FirestoreDbBuilder
            {
                CredentialsPath = _configuration.GetValue <string>(CredentialsPath),
                ProjectId       = _configuration.GetValue <string>(ProjectId)
            };

            return(dbBuilder.Build());
        }
예제 #4
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Created Cloud Firestore client with project ID: {0}", db.ProjectId);
            FirestoreDbBuilder temp         = new FirestoreDbBuilder();
            StreamReader       streamReader = new StreamReader("Keys/clientsecrets.txt");

            client_id     = streamReader.ReadLine();
            client_secret = streamReader.ReadLine();
            CreateHostBuilder(args).Build().Run();
        }
예제 #5
0
        public ExamService(string projectId, string jsonCredentials)
        {
            var dbBuilder = new FirestoreDbBuilder
            {
                ProjectId       = projectId,
                JsonCredentials = jsonCredentials
            };

            db = dbBuilder.Build();
        }
 public FirestoreFixture() : base(ProjectEnvironmentVariable)
 {
     // Currently, only the default database is supported... so we create all our collections with a randomly-generated prefix.
     // When multiple databases are supported, we'll create a new one per test run.
     CollectionPrefix = IdGenerator.FromGuid(prefix: "test-");
     FirestoreDb      = new FirestoreDbBuilder {
         ProjectId = ProjectId, EmulatorDetection = EmulatorDetection.EmulatorOrProduction
     }.Build();
     NonQueryCollection             = FirestoreDb.Collection(CollectionPrefix + "-non-query");
     HighScoreCollection            = FirestoreDb.Collection(CollectionPrefix + "-high-scores");
     ArrayQueryCollection           = FirestoreDb.Collection(CollectionPrefix + "-array-query");
     CollectionGroupQueryCollection = FirestoreDb.Collection(CollectionPrefix + "-collection-groups");
     Task.Run(PopulateCollections).Wait();
 }
예제 #7
0
    private void MakeClient()
    {
        var credPath = BotSettings.GoogleCloudCredentialsPath.SanitizeSlash();

        Log.Information("Create Firestore client, cred {CredPath}", credPath);
        var clientBuilder = new FirestoreDbBuilder()
        {
            CredentialsPath = credPath,
            ProjectId       = ProjectId
        };

        var client = clientBuilder.Build();

        Db = client;
    }
예제 #8
0
        protected FirestoreDbContext(FirestoreOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.ProjectId == null)
            {
                throw new ArgumentNullException(nameof(options.ProjectId));
            }

            Database = new FirestoreDbBuilder
            {
                ProjectId = options.ProjectId, EmulatorDetection = EmulatorDetection.EmulatorOrProduction
            }.Build();
        }
        protected BaseRepo(FirestoreConfig firestoreConfig, ILogger logger)
        {
            log    = logger;
            config = firestoreConfig;
            if (config.Emulator)
            {
                if (string.IsNullOrEmpty(config.EmulatorUrl))
                {
                    throw new MissingFieldException(nameof(config.EmulatorUrl));
                }


                var fb = new FirestoreDbBuilder
                {
                    ProjectId = config.ProjectId,
                    //Endpoint = config.EmulatorUrl,
                    EmulatorDetection = EmulatorDetection.EmulatorOnly
                };

                db = fb.Build();
                return;
            }
            db = FirestoreDb.Create(config.ProjectId);
        }