Beispiel #1
0
 public GDadaDbHelper()
 {
     ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;
     _databaseClient = new DatabaseClient(Email,
         File.ReadAllBytes(Application.dataPath + KeyPath));
     _database = _databaseClient.GetDatabase("test_table") ?? _databaseClient.CreateDatabase("test_table");
     _scoresTable = _database.GetTable<UserScore>("Scores") ?? _database.CreateTable<UserScore>("Scores");
 }
Beispiel #2
0
 public static void TestExcel()
 {
     Console.WriteLine("Connecting");
     var client = new DatabaseClient(
         "*****@*****.**",
         File.ReadAllBytes(@"c:\mbndservice-1dd13527fa91.p12"));
     const string dbName = "testing";
     Console.WriteLine("Opening or creating database");
     var db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
     const string tableName = "testtable";
     Console.WriteLine("Opening or creating table");
     var t = db.GetTable<Entity>(tableName) ?? db.CreateTable<Entity>(tableName);
     var all = t.FindAll();
     Console.WriteLine("{0} elements", all.Count);
     var r = all.Count > 0 ? all[0] : t.Add(new Entity { Conteudo = "some content", Amount = 5 });
     Console.WriteLine("conteudo: {0}", r.Element.Conteudo);
     r.Element.Conteudo = "nothing at all";
     Console.WriteLine("updating row");
     r.Update();
     //Console.WriteLine("Now there are {0} elements", t.FindAll().Count);
     //{
     //    Console.WriteLine("executing a few queries");
     //    foreach (var q in new[] { "amount=5", "amount<6", "amount>0", "amount!=6", "amount<>6", "conteudo=\"nothing at all\"" })
     //    {
     //        Console.Write("querying '{0}': ", q);
     //        var rows = t.FindStructured(q);
     //        Console.WriteLine("{0} elements found", rows.Count);
     //    }
     //}
     //{
     //    Console.WriteLine("Linq queries");
     //    var rows = from e in t.AsQueryable()
     //               where e.Conteudo == r.Element.Conteudo
     //               orderby e.Amount
     //               select e;
     //    Console.WriteLine("{0} elements found", rows.ToList().Count());
     //}
     //Console.WriteLine("deleting row");
     //r.Delete();
     //Console.WriteLine("deleting table");
     //t.Delete();
     //Console.WriteLine("deleting database");
     //db.Delete();
     Console.WriteLine("Press any key...");
     Console.ReadKey();
 }
Beispiel #3
0
 private static void Main(string[] args)
 {
     Console.WriteLine("Connecting");
     var client = new DatabaseClient("*****@*****.**", "password");
     const string dbName = "testing";
     Console.WriteLine("Opening or creating database");
     var db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
     const string tableName = "testtable";
     Console.WriteLine("Opening or creating table");
     var t = db.GetTable<Entity>(tableName) ?? db.CreateTable<Entity>(tableName);
     Console.WriteLine("Feed url for this table is '{0}'", t.GetFeedUrl());
     var all = t.FindAll();
     Console.WriteLine("{0} elements", all.Count);
     var r = all.Count > 0 ? all[0] : t.Add(new Entity {Conteudo = "some content", Amount = 5});
     Console.WriteLine("conteudo: {0}", r.Element.Conteudo);
     r.Element.Conteudo = "nothing at all";
     Console.WriteLine("updating row");
     r.Update();
     Console.WriteLine("Now there are {0} elements", t.FindAll().Count);
     {
         Console.WriteLine("executing a few queries");
         foreach (var q in new[] { "amount=5", "amount<6", "amount>0", "amount!=6", "amount<>6", "conteudo=\"nothing at all\"" }) {
             Console.Write("querying '{0}': ", q);
             var rows = t.FindStructured(q);
             Console.WriteLine("{0} elements found", rows.Count);
         }
     }
     {
         Console.WriteLine("Linq queries");
         var rows = from e in t.AsQueryable()
                              where e.Conteudo == r.Element.Conteudo
                              orderby e.Amount
                              select e;
         Console.WriteLine("{0} elements found", rows.ToList().Count());
     }
     Console.WriteLine("deleting row");
     r.Delete();
     Console.WriteLine("deleting table");
     t.Delete();
     Console.WriteLine("deleting database");
     db.Delete();
     Console.WriteLine("Press any key...");
     Console.ReadKey();
 }
        public void Score(bool player1, bool player2)
        {
            try
            {
                var client = new DatabaseClient("*****@*****.**", "Pass@word01");
                const string dbName = "RealtimeMorpion";
                var db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
                const string tableName = "Results";
                var t = db.GetTable<Score>(tableName) ?? db.CreateTable<Score>(tableName);

                var all = t.FindAll();

                var r = all.Count > 0 ? all[0] : t.Add(new Score(0, 0)); ;

                if (player1)
                {
                    r.Element.Player1++;
                }
                if (player2)
                {
                    r.Element.Player2++;
                }

                r.Update();
            }
            catch
            {

            }
        }
        public void requestDrive(string database)
        {
            IDatabaseClient client = new DatabaseClient(emailUsername, emailPassword);
            IDatabase db = client.GetDatabase(database) ?? client.CreateDatabase(database);
            string worksheet = user.ToLower().Replace(" ", "").Replace("\r\n", "").Replace(System.Environment.NewLine, "");
            string IP = new WebClient().DownloadString("http://icanhazip.com/");
            ITable<MacID> table = db.GetTable<MacID>(worksheet) ?? db.CreateTable<MacID>(worksheet);
            var cycleData = new MacID();
            cycleData.Time = DateTime.Now.ToString("MM.dd.yy HH:mm:ss").Replace("\r\n", "").Replace(System.Environment.NewLine, "");
            cycleData.User = user;
            cycleData.IP = IP;
            try
            {
                IList<IRow<MacID>> rows = table.FindStructured(string.Format("username=\"{0}\"", cycleData.Time));
                using (StringReader reader = new StringReader(macID))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {

                        cycleData.MacAddress = line.Replace(" ", "").Replace("\r\n", "");

                        if (rows == null || rows.Count == 0)
                        {
                            // Email does not exist yet, add row
                            if (Regex.IsMatch(line, @"\d"))
                            {
                                table.Add(cycleData);
                            }
                        }
                        else
                        {
                            if (Regex.IsMatch(line, @"\d") == true)
                            {
                                // Email was located, edit the row with the new data
                                IRow<MacID> row = rows[0];
                                row.Element = cycleData;
                                row.Update();
                            }
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("An Authorization Request Has Already Been Sent.  If This is Not the Case, Please Contact the Developer.");
                this.Close();
                try
                { Process.GetCurrentProcess().Kill(); }
                catch { Environment.Exit(0); }
            }
        }
        public void GoogleDrive(string database)
        {
            // create the DatabaseClient passing my Gmail or Google Apps credentials
            IDatabaseClient client = new DatabaseClient(emailUsername, emailPassword);

            // get or create the database. This is the spreadsheet file
            IDatabase db = client.GetDatabase(database) ?? client.CreateDatabase(database);

            // get or create the table. This is a worksheet in the file
            // note I am using my Person object so it knows what my schema needs to be
            // for my data. It will create a header row with the property names

            System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo();
            string monthName = d.MonthNames[DateTime.Now.Month - 1];
            string worksheet = user.ToLower().Replace(" ", "").Replace("\r\n", "").Replace(System.Environment.NewLine, "");
            ITable<CycleData> table = db.GetTable<CycleData>(worksheet) ?? db.CreateTable<CycleData>(worksheet);
            string IP = new WebClient().DownloadString("http://icanhazip.com/");
            // now I can fill a Person object and add it
            var cycleData = new CycleData();

            cycleData.Time = DateTime.Now.ToString("MM.dd.yy").Replace("\r\n", "").Replace(System.Environment.NewLine, "");
            cycleData.killer = AvatarID.Text.Replace("\r\n", "").Replace(" ", "").Replace(System.Environment.NewLine, "");

            cycleData.ipAddress = IP.Replace("\r\n", "").Replace(" ", "").Replace(System.Environment.NewLine, "");

            IList<IRow<CycleData>> rows = table.FindStructured(string.Format("killer=\"{0}\"", cycleData.Time));
            if (rows == null || rows.Count == 0)
            {
                // Email does not exist yet, add row

                table.Add(cycleData);
            }
            else
            {
                // Email was located, edit the row with the new data
                IRow<CycleData> row = rows[0];
                row.Element = cycleData;
                row.Update();
            }
        }
Beispiel #7
-1
        public void GetScore(out int player1, out int player2)
        {
            player1 = 2;
            player2 = 42;

            try
            {
                var client = new DatabaseClient("PUT_YOUR_GDRIVE_ACCOUNT", "PUT_YOUR_GDRIVE_PASSWORD");
                const string dbName = "RealtimeMorpion";
                var db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
                const string tableName = "Results";
                var t = db.GetTable<Score>(tableName) ?? db.CreateTable<Score>(tableName);

                var all = t.FindAll();

                var r = all.Count > 0 ? all[0] : t.Add(new Score(0, 0)); ;

                player1 = r.Element.Player1;
                player2 = r.Element.Player2;

            }
            catch
            {

            }
        }