예제 #1
0
        public static void Main(string[] args)
        {
            // Your Google Cloud Platform project ID
            string projectId = "YOUR-PROJECT-ID";

            // Instantiates a client
            DatastoreDb db = DatastoreDb.Create(projectId);

            // The kind for the new entity
            string kind = "Task";
            // The name/ID for the new entity
            string name = "sampletask1";
            KeyFactory keyFactory = db.CreateKeyFactory(kind);
            // The Cloud Datastore key for the new entity
            Key key = keyFactory.CreateKey(name);

            var task = new Entity
            {
                Key = key,
                ["description"] = "Buy milk"
            };
            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                // Saves the task
                transaction.Upsert(task);
                transaction.Commit();

                Console.WriteLine($"Saved {task.Key.Path[0].Name}: {(string)task["description"]}");
            }
        }
        public static void CreateUser(string username, string uid, string passhash, string email, byte[] salt)
        {
            KeyFactory keyFactory = db.CreateKeyFactory("IcyWind");
            Key        key        = keyFactory.CreateKey(username);

            var task = new Entity
            {
                Key              = key,
                ["data"]         = string.Empty,
                ["salt"]         = ByteArrayToString(salt),
                ["passhash"]     = passhash,
                ["uid"]          = uid,
                ["email"]        = email,
                ["IsAdmin"]      = false,
                ["IsDonator"]    = false,
                ["Banned"]       = false,
                ["DonateAmount"] = 0
            };

            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                // Saves the task
                transaction.Upsert(task);
                transaction.Commit();
            }
        }
예제 #3
0
 public void Upsert(Entity entity)
 {
     using  (DatastoreTransaction transaction = _db.BeginTransaction())
     {
         transaction.Upsert(entity);
         transaction.Commit();
     }
 }
예제 #4
0
 public void StoreEntity(Entity e)
 {
     e.Key.PartitionId = new PartitionId(projectId, namespaceId);
     using (DatastoreTransaction transaction = db.BeginTransaction())
     {
         transaction.Upsert(e);
         transaction.Commit();
     }
 }
        private void upsert(DatastoreDb db, Entity entity)
        {
            GrpcEnvironment.SetLogger(new ConsoleLogger());

            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                transaction.Upsert(entity);
                transaction.Commit();
            }
        }
        public void Upsert(ApiKey apiKey)
        {
            var entity = apiKey.ToEntity();

            using (DatastoreTransaction transaction = _db.BeginTransaction())
            {
                entity.Key = _db.CreateKeyFactory("ApiKey").CreateKey(apiKey.Id);
                transaction.Upsert(entity);
                transaction.Commit();
            }
        }
예제 #7
0
        public void InsertBD(string InsertTweet, string[] tweetScore, DateTime fecha, Tweetinvi.Models.IPlace lugar)
        {
            #region db access
            ///////////////////////////////////////////// db access ///////////////////////////////////
            string credential_path = @"C:\Users\Javier\Downloads\IMAPBD-Misc\Sentiment analisis\imapbd\IMAPBD\IMAPBD\OAuth\IMAPBD - Load-db-access.json";
            System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);

            string projectID = "imapbd-load";

            DatastoreDb db   = DatastoreDb.Create(projectID, "");
            string      kind = "Lugar_Tweet";

            KeyFactory keyFactory = db.CreateKeyFactory(kind);
            Key        key        = keyFactory.CreateIncompleteKey();

            Entity task = new Entity();
            task.Key = key;
            task.Properties.Add("tweet", InsertTweet);

            task.Properties.Add("tedioso", Convert.ToDouble(tweetScore[0]));
            task.Properties.Add("malo", Convert.ToDouble(tweetScore[1]));
            task.Properties.Add("bueno", Convert.ToDouble(tweetScore[2]));
            task.Properties.Add("regular", Convert.ToDouble(tweetScore[3]));

            task.Properties.Add("dia", fecha.DayOfWeek.ToString());
            task.Properties.Add("mes", fecha.Month);
            task.Properties.Add("anio", fecha.Year);
            if (string.IsNullOrEmpty(lugar.Name))
            {
                task.Properties.Add("lugar", "");
            }
            else
            {
                task.Properties.Add("lugar", lugar.Name);
            }

            task.Properties.Add("lugar", lugar.Name);
            task.Properties.Add("pais", lugar.Country);


            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                transaction.Upsert(task);
                transaction.Commit();
            }
            ///////////////////////////////////////////// db access ///////////////////////////////////
            #endregion
        }
예제 #8
0
        public static void Main(string[] args)
        {
            // Your Google Cloud Platform project ID
            string projectId = "czreadbook";

            // Instantiates a client
            DatastoreDb db = DatastoreDb.Create(projectId);

            // The kind for the new entity
            string kind = "book_shengxu";
            // The name/ID for the new entity
            string     article_id = "6290265";
            KeyFactory keyFactory = db.CreateKeyFactory(kind);
            // The Cloud Datastore key for the new entity
            Key key = keyFactory.CreateKey(article_id);

            var contenttmp = @"这才多长时间过去,当年那个都不曾被他们注意、没有放在眼中的小土著,竟在短短的一年内从圣者层次突破到神级领域,位列神将之巅,震撼人心。

他们惶恐了,这种进化速度就是在阳间也吓死人,除非古代那几个特殊时期,不然的话怎能出现?

在阴间宇宙中,法则不全,天地残缺,此外还有“天花板”,最高不过映照级,他居然能走到这一步,逆天了吗?

噗!

楚风的剑翼扇动,如同一个十二羽翼的神王,呼啸天地间,再次将一位神祇的头颅斩落,根本就没有人能挡住他。";
            var task       = new Entity
            {
                Key                 = key,
                ["url"]             = "https://www.piaotian.com/html/8/8253/6290265.html",
                ["content"]         = contenttmp,
                ["create_date"]     = DateTimeOffset.Now,
                ["last_upate_date"] = DateTimeOffset.Now,
            };

            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                // Saves the task
                transaction.Upsert(task);
                transaction.Commit();

                Console.WriteLine($"Saved {task.Key.Path[0].Name}: {(string)task["url"]}");
            }
        }
예제 #9
0
        public void Upsert()
        {
            string projectId   = _fixture.ProjectId;
            string namespaceId = _fixture.NamespaceId;

            // Snippet: Upsert(Entity[])
            DatastoreDb db         = DatastoreDb.Create(projectId, namespaceId);
            KeyFactory  keyFactory = db.CreateKeyFactory("book");
            Entity      book1      = new Entity
            {
                Key                  = keyFactory.CreateIncompleteKey(),
                ["author"]           = "Harper Lee",
                ["title"]            = "Tequila Mockingbird",
                ["publication_date"] = new DateTime(1960, 7, 11, 0, 0, 0, DateTimeKind.Utc),
                ["genres"]           = new[] { "Southern drama", "Courtroom drama", "Bildungsroman" }
            };

            db.Insert(book1);

            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                // Correct the typo in memory
                book1["title"] = "To Kill a Mockingbird";

                Entity book2 = new Entity
                {
                    Key                  = keyFactory.CreateIncompleteKey(),
                    ["author"]           = "Charlotte Brontë",
                    ["title"]            = "Jane Eyre",
                    ["publication_date"] = new DateTime(1847, 10, 16, 0, 0, 0, DateTimeKind.Utc),
                    ["genres"]           = new[] { "Gothic", "Romance", "Bildungsroman" }
                };

                // This adds the entities to a collection of mutations in memory: nothing
                // is sent to the server.
                transaction.Upsert(book1, book2);
                // Without the Commit call, the transaction will automatically
                // be rolled back. The Commit call performs all the mutations
                // within the transaction.
                transaction.Commit();
            }
            // End snippet
        }
예제 #10
0
        private void UpsertLocation(DatastoreTransaction transaction, Location location)
        {
            Entity dbLocation = null;

            if (location.Id > 0)
            {
                dbLocation = transaction.Lookup(_keyFactory.CreateKey(location.Id));
            }

            if (dbLocation == null)
            {
                dbLocation = new Entity
                {
                    Key = _keyFactory.CreateIncompleteKey()
                };
            }

            location.Update(dbLocation);
            transaction.Upsert(dbLocation);
        }
예제 #11
0
        public ActionResult <object> Register([FromBody] User user)
        {
            Environment.SetEnvironmentVariable(
                "GOOGLE_APPLICATION_CREDENTIALS",
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "fsndigital-cred.json"));

            DatastoreDb db = DatastoreDb.Create("fsndigital", "Users", DatastoreClient.Create());

            string kind = "user";

            KeyFactory keyFactory = db.CreateKeyFactory(kind);
            Key        key        = keyFactory.CreateKey(user.Email);

            var task = new Entity
            {
                Key          = key,
                ["TypeId"]   = user.TypeId,
                ["UserName"] = user.UserName,
                ["Email"]    = user.Email,
                ["Password"] = user.Password,
            };

            Entity check = db.Lookup(task.Key);

            if (check != null)
            {
                return(Ok(new { succeeded = false, message = "An account with that email already exists." }));
            }



            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                transaction.Upsert(task);
                transaction.Commit();
            }

            return(Ok(new { succeeded = true }));
        }
예제 #12
0
        public void Save(T obj)
        {
            DatastoreDb db = DatastoreDb.Create("fantasyfootball-204922", "default");

            KeyFactory keyFactory = db.CreateKeyFactory(obj.Kind);
            Entity     entity     = new Entity
            {
                Key         = keyFactory.CreateKey(obj.id),
                ["updated"] = DateTime.UtcNow,
                ["text"]    = JsonConvert.SerializeObject(obj),
                ["tags"]    = obj.Tags.ToArray()
            };

            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                transaction.Upsert(entity);
                CommitResponse commitResponse = transaction.Commit();
                Key            insertedKey    = commitResponse.MutationResults[0].Key;
                Console.WriteLine($"Inserted key: {insertedKey}");
                // The key is also propagated to the entity
                Console.WriteLine($"Entity key: {entity.Key}");
            }
        }
예제 #13
0
        public void Firebase_Connection()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + @"safe-zone-child-firebase-adminsdk-mq2cq-8ea2101a36.json";

            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);

            // Your Google Cloud Platform project ID.
            string projectId = "safe-zone-child";

            // Instantiates a client
            DatastoreDb db = DatastoreDb.Create(projectId);


            // The kind for the new entity
            string kind = "Task";
            // The name/ID for the new entity
            string     name       = "sampletask1";
            KeyFactory keyFactory = db.CreateKeyFactory(kind);
            // The Cloud Datastore key for the new entity
            Key key = keyFactory.CreateKey(name);

            var task = new Entity
            {
                Key             = key,
                ["description"] = "8888Buy milk"
            };

            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                // Saves the task
                transaction.Upsert(task);
                transaction.Commit();

                Console.WriteLine($"Saved {task.Key.Path[0].Name}: {(string)task["description"]}");
            }
        }