Esempio n. 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");
 }
Esempio n. 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();
 }
Esempio n. 3
0
    void Start()
    {
        Debug.Log("Connecting");

        const string account = "*****@*****.**";
        const string password = "******";
        var client = new DatabaseClient(account, password);

        const string dbName = "spreadsheet-test";
        var db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);

        const string tableName = "test_table";
        var t = db.GetTable<Entity>(tableName) ?? db.CreateTable<Entity>(tableName);

        Debug.Log("Feed url for this table is : " + t.GetFeedUrl());

        var all = t.FindAll();

        var r = all.Count > 0 ? all[0] : t.Add(new Entity {Conteudo = "some content", Amount = 5});
        r.Element.Conteudo = "nothing at all";
        r.Update();

        Debug.Log("Now there are " + t.FindAll().Count + "elements");
        {
            Debug.Log("executing a few queries");
            foreach (var q in new[] { "amount=5", "amount<6", "amount>0", "amount!=6", "amount<>6", "conteudo=\"nothing at all\"" }) {
                Debug.Log("querying: " + q);
                var rows = t.FindStructured(q);
                Debug.Log("elements found: " + rows.Count);
            }
        }
        {
            Debug.Log("Linq queries");
            var rows = from e in t.AsQueryable()
                                 where e.Conteudo == r.Element.Conteudo
                                 orderby e.Amount
                                 select e;
            Debug.Log("elements found : " + rows.ToList().Count());
        }

        //r.Delete();
        //t.Delete();
        //db.Delete();
    }
Esempio n. 4
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();
 }
    /// <summary>
    /// Connect to google-spreadsheet with the specified account and password then query cells and
    /// call the given callback.
    /// </summary>
    private void DoCellQuery(OnEachCell onCell)
    {
        // first we need to connect to the google-spreadsheet to get all the first row of the cells
        // which are used for the properties of data class.
        var client = new DatabaseClient("", "");

        if (string.IsNullOrEmpty(machine.SpreadSheetName))
            return;
        if (string.IsNullOrEmpty(machine.WorkSheetName))
            return;

        var db = client.GetDatabase(machine.SpreadSheetName);
        if (db == null) {
            Debug.LogError("The given spreadsheet does not exist.");
            return;
        }

        // retrieves all cells
        var worksheet = ((Database)db).GetWorksheetEntry(machine.WorkSheetName);

        // Fetch the cell feed of the worksheet.
        CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
        var cellFeed = client.SpreadsheetService.Query(cellQuery);

        // Iterate through each cell, printing its value.
        foreach (CellEntry cell in cellFeed.Entries) {
            if (onCell != null)
                onCell(cell);
        }
    }
Esempio n. 6
0
        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
            {

            }
        }
Esempio n. 7
0
        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); }
            }
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
-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
            {

            }
        }