public static DataSet GetDataset(ScribeConnection connection, Extensions.Actions action, string eventId = null, DateTime?modifiedAfter = null, DateTime?modifiedBefore = null, string additionCondition = null, Dictionary <string, string> keypairs = null) { var strAction = action.Name(); var isKeyPairs = keypairs != null; var key = ConnectorCache.Generatekey(connection.ConnectionKey, strAction, connection.AccountId, connection.EventId, null, keypairs); DataSet ds = ConnectorCache.GetCachedData <DataSet>(key); if (ds != null) { return(ds); } if (isKeyPairs) { ds = GetKeyPairValueFromMemory(connection.ConnectionKey, strAction, connection.AccountId, connection.EventId, keypairs); if (ds != null) { return(ds); } } //If we do not have key pairs, will load all pages for the dataset ds = GetCompleteDatasetIteratively(connection, strAction, connection.AccountId, eventId, modifiedAfter, modifiedBefore, additionCondition, keypairs); if (ds != null) { ConnectorCache.StoreData(key, ds, connection.TTL); } if (!isKeyPairs) { StoreGeneratedKey(connection.ConnectionKey, strAction, key); } return(ds); }
public static JObject GetJObject(ScribeConnection connection, Extensions.Actions action, string accountId = null, string eventId = null) { var strAction = action.Name(); var key = ConnectorCache.Generatekey(connection.ConnectionKey, strAction, connection.AccountId, connection.EventId, null, null); JObject json = ConnectorCache.GetCachedData <JObject>(key); if (json != null) { Logger.WriteDebug($"The action {strAction} successfully returned in GetJobject from cache."); return(json); } HttpResponse result = DoHttpGetInternal(connection.BaseUrl, strAction, connection.AccessToken, accountId, eventId); if (!String.IsNullOrEmpty(result.RawText) && result.RawText.StartsWith("{\"status\":\"error\",\"msg\":\"Not authorized to access account")) { connection.ReConnnect(); if (connection.IsConnected) { result = DoHttpGetInternal(connection.BaseUrl, strAction, connection.AccessToken, accountId, eventId); } } if (result == null) { Logger.WriteError("Result of get was null in GetJObject"); throw new ApplicationException("Result of get was null"); } var res = result.RawText; json = JObject.Parse(res); if (json != null) { ConnectorCache.StoreData(key, json, connection.TTL); Logger.WriteDebug($"The action {strAction} successfully returned in GetJobject"); } return(json); }