示例#1
0
        public static string  submit_Via_REST(this API_Firebase firebase, API_Firebase.SubmitData submitData)
        {
            var result = "";

            if (submitData.notNull())
            {
                try
                {
                    switch (submitData.Type)
                    {
                    case API_Firebase.Submit_Type.GET:
                        result = firebase.GET();
                        break;

                    case API_Firebase.Submit_Type.ADD:
                        result = firebase.POST(submitData.Data);
                        break;

                    case API_Firebase.Submit_Type.SET:
                        result = firebase.PUT(submitData.Data);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    ex.log("[API_Firebase] [submit_Via_REST] for: {0}".format(submitData));
                }
                if (result.notValid())                          // this could happen in the cases where the SSL failed to connect
                {
                    firebase.offlineQueue().add(submitData);
                }
            }
            return(result);
        }
示例#2
0
 public static BlockingCollection <API_Firebase.SubmitData> offlineQueue(this API_Firebase firebase)
 {
     if (firebase.notNull())
     {
         return(firebase.OfflineQueue);
     }
     return(null);
 }
示例#3
0
 public static Uri  site_Uri(this API_Firebase firebase, string area)
 {
     return("https://{0}.firebaseio.com/{1}/{2}.json?auth={3}".format(
                firebase.firebase_Site(),
                firebase.firebase_RootArea(),
                area,
                firebase.firebase_AuthToken()).uri());
 }
示例#4
0
 public static API_Firebase            add(this API_Firebase firebase, API_Firebase.SubmitData submitData)
 {
     if (firebase.notNull() && submitData.notNull())
     {
         firebase.submitThread_Start();           // start a new SubmitThread (if there isn't one alive already)
         firebase.SubmitQueue.add(submitData);    // queues the request for submition
     }
     return(firebase);
 }
 public void setup()
 {
     firebase = new API_Firebase
         {
                 SubmitThread = null,
                 QueueMaxWait = 1,
                 Offline      = false
         };
 }
 public void API_Firebase_Ctor()
 {
     firebase = new API_Firebase();
     Assert.IsNotNull(firebase);
     Assert.IsNotNull(firebase.Area);
     Assert.IsNotNull(firebase.MessageFormat);
     Assert.IsNotNull(firebase.SubmitQueue);
     Assert.IsNotNull(firebase.OfflineQueue);
     Assert.AreEqual (firebase.QueueMaxWait, TMConsts.FIREBASE_SUBMIT_QUEUE_MAX_WAIT);
 }
示例#7
0
        public static bool firebase_ForceOffline(this API_Firebase firebase)
        {
            var userData = TM_UserData.Current;

            if (userData.notNull() && userData.SecretData.notNull())
            {
                return(userData.SecretData.FirebaseConfig.Force_Offline);
            }
            return(false);
        }
示例#8
0
        public static bool firebase_DisableSslCertCheck(this API_Firebase firebase)
        {
            var userData = TM_UserData.Current;

            if (userData.notNull() && userData.SecretData.notNull())
            {
                return(userData.SecretData.FirebaseConfig.DisableSslCertCheck);
            }
            return(false);
        }
示例#9
0
        public static string firebase_RootArea(this API_Firebase firebase)
        {
            var userData = TM_UserData.Current;

            if (userData.notNull() && userData.SecretData.notNull())
            {
                return(userData.SecretData.FirebaseConfig.RootArea);
            }
            return(null);
        }
示例#10
0
 public static bool site_Online(this API_Firebase firebase)
 {
     if (firebase.site_Configured())
     {
         var randomAreaUri = firebase.site_Uri(10.randomLetters());   // sets a random area
         randomAreaUri.str().info();
         var result = randomAreaUri.GET();                            // makes a GET request to it
         return(result == "null");                                    // if the URL exists and the AuthToken is valid, we will get a null value as response
     }
     return(false);
 }
示例#11
0
        public static string HTTP_Request(this API_Firebase firebase, string method, object data)
        {
            var targetUrl = firebase.site_Uri().str();
            var jsonData  = data.notNull()
                                  ? data.json()
                                  : "";
            var web = new Web();

            web.Headers_Request.Add("X-HTTP-Method-Override", method);
            return(web.getUrlContents_POST(targetUrl, jsonData));
        }
示例#12
0
 public static API_Firebase submitThread_Start(this API_Firebase firebase)
 {
     if (firebase.SubmitThread.isNull())
     {
         firebase.SubmitThread = O2Thread.mtaThread(() =>
         {
             firebase.submitThread_HandleQueue();       // triggers the submit loop
             firebase.SubmitThread = null;              // set the SubmitThread to null to indicate that it is not alive any more
         });
     }
     return(firebase);
 }
        public void offline()
        {
            Assert.IsFalse(firebase.offline());

            firebase.Offline = true;
            Assert.IsTrue(firebase.offline());

            firebase.Offline = false;
            Assert.IsFalse(firebase.offline());

            firebase = null;
            Assert.IsTrue(firebase.offline());
        }
示例#14
0
        public Test_API_Firebase()
        {
            if (Tests_Consts.offline)
                Assert.Ignore("Ignoring Test because we are offline");

            tmQAConfig = TM_QA_Config.Current;
            if (tmQAConfig.isNull())
                Assert.Ignore("TM_QA_ConfigFile.Current was null (so no Firebase live config values");

            firebase = new API_Firebase("QA_Tests");

            userData.SecretData.Firebase_Site      = tmQAConfig.Firebase_Site;
            userData.SecretData.Firebase_AuthToken = tmQAConfig.Firebase_AuthToken;
        }
示例#15
0
        public static API_Firebase submitThread_HandleQueue(this API_Firebase firebase)
        {
            var next = firebase.next();

            while (next.notNull())
            {
                // "[SubmitThread] got next: {0}".info(next);

                if (firebase.offline() || firebase.site_Configured().isFalse())
                {
                    firebase.offlineQueue().add(next);
                }
                else
                {
                    ThreadPool.QueueUserWorkItem((o) => firebase.submit_Via_REST(next));
                }

                next = firebase.next();
            }
            return(firebase);
        }
示例#16
0
 public static string DELETE(this API_Firebase firebase)
 {
     return(firebase.HTTP_Request("DELETE", "{}"));
 }
示例#17
0
 public static BlockingCollection<API_Firebase.SubmitData> add(this BlockingCollection<API_Firebase.SubmitData> submitQueue, API_Firebase.SubmitData submitData)
 {
     if (submitQueue.notNull() && submitData.notNull())
         submitQueue.Add(submitData);
     return submitQueue;
 }
 public void submitQueue()
 {
     firebase = null;
     Assert.IsNull(firebase.submitQueue());
 }
示例#19
0
 public static int                                         submitQueue_Size(this API_Firebase firebase)
 {
     return(firebase.submitQueue().size());
 }
示例#20
0
 public static API_Firebase submit(this API_Firebase firebase, API_Firebase.SubmitData submitData)
 {
     return firebase.add(submitData);
 }
示例#21
0
 public static API_Firebase.SubmitData next(this API_Firebase firebase)
 {
     return(firebase.next(firebase.QueueMaxWait));
 }
示例#22
0
 public static API_Firebase.SubmitData next(this API_Firebase firebase, int maxWait)
 {
     return(firebase.submitQueue().next(maxWait));
 }
示例#23
0
 public static API_Firebase            submit(this API_Firebase firebase, API_Firebase.SubmitData submitData)
 {
     return(firebase.add(submitData));
 }
示例#24
0
 public static string GET(this API_Firebase firebase)
 {
     return(firebase.site_Uri().GET());
 }
示例#25
0
 public static bool         submitThread_Alive(this API_Firebase firebase)
 {
     return(firebase.SubmitThread.notNull());
 }
示例#26
0
 public static string POST(this API_Firebase firebase, object data)
 {
     return(firebase.HTTP_Request("POST", data));
 }
示例#27
0
 public static bool   offline(this API_Firebase firebase)
 {
     return(!firebase.notNull() || firebase.Offline || firebase.firebase_ForceOffline());
 }
示例#28
0
 public static Uri  site_Uri(this API_Firebase firebase)
 {
     return(firebase.site_Uri(firebase.Area));
 }
示例#29
0
 public static API_Firebase add(this API_Firebase firebase, API_Firebase.SubmitData submitData)
 {
     if (firebase.notNull() && submitData.notNull())
     {
         firebase.submitThread_Start();           // start a new SubmitThread (if there isn't one alive already)
         firebase.SubmitQueue.add(submitData);    // queues the request for submition
     }
     return firebase;
 }
示例#30
0
 public static bool site_Configured(this API_Firebase firebase)
 {
     return(firebase.notNull() &&
            firebase.firebase_Site().valid() &&
            firebase.firebase_AuthToken().valid());
 }
示例#31
0
        public static string submit_Via_REST(this API_Firebase firebase, API_Firebase.SubmitData submitData)
        {
            var result = "";
            if (submitData.notNull())
            {
                try
                {
                    switch(submitData.Type)
                    {
                        case API_Firebase.Submit_Type.GET:
                            result = firebase.GET();
                            break;
                        case API_Firebase.Submit_Type.ADD:
                            result = firebase.POST(submitData.Data);
                            break;
                        case API_Firebase.Submit_Type.SET:
                            result = firebase.PUT(submitData.Data);
                            break;
                    }
                }
                catch(Exception ex)
                {
                    ex.log("[API_Firebase] [submit_Via_REST] for: {0}".format(submitData));
                }
                if (result.notValid())                          // this could happen in the cases where the SSL failed to connect
                    firebase.offlineQueue().add(submitData);

            }
            return result;
        }