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); }
public static BlockingCollection <API_Firebase.SubmitData> offlineQueue(this API_Firebase firebase) { if (firebase.notNull()) { return(firebase.OfflineQueue); } return(null); }
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()); }
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); }
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); }
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); }
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); }
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); }
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)); }
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()); }
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; }
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); }
public static string DELETE(this API_Firebase firebase) { return(firebase.HTTP_Request("DELETE", "{}")); }
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()); }
public static int submitQueue_Size(this API_Firebase firebase) { return(firebase.submitQueue().size()); }
public static API_Firebase submit(this API_Firebase firebase, API_Firebase.SubmitData submitData) { return firebase.add(submitData); }
public static API_Firebase.SubmitData next(this API_Firebase firebase) { return(firebase.next(firebase.QueueMaxWait)); }
public static API_Firebase.SubmitData next(this API_Firebase firebase, int maxWait) { return(firebase.submitQueue().next(maxWait)); }
public static API_Firebase submit(this API_Firebase firebase, API_Firebase.SubmitData submitData) { return(firebase.add(submitData)); }
public static string GET(this API_Firebase firebase) { return(firebase.site_Uri().GET()); }
public static bool submitThread_Alive(this API_Firebase firebase) { return(firebase.SubmitThread.notNull()); }
public static string POST(this API_Firebase firebase, object data) { return(firebase.HTTP_Request("POST", data)); }
public static bool offline(this API_Firebase firebase) { return(!firebase.notNull() || firebase.Offline || firebase.firebase_ForceOffline()); }
public static Uri site_Uri(this API_Firebase firebase) { return(firebase.site_Uri(firebase.Area)); }
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 static bool site_Configured(this API_Firebase firebase) { return(firebase.notNull() && firebase.firebase_Site().valid() && firebase.firebase_AuthToken().valid()); }
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; }