Пример #1
0
        public static T DoPut <T>(ScribeConnection connection, Extensions.Actions action, string eventId, Dictionary <string, string> keyPairValues)
        {
            var path   = buildPath(connection, action, eventId, keyPairValues);
            var http   = new HttpClient();
            var result = http.Put(path, null, HttpContentTypes.ApplicationJson);

            if (!String.IsNullOrEmpty(result.RawText) && result.RawText.StartsWith("{\"status\":\"error\",\"msg\":\"Not authorized to access account"))
            {
                connection.ReConnnect();
                if (connection.IsConnected)
                {
                    result = http.Put(path, null, HttpContentTypes.ApplicationJson);
                }
            }
            return(JsonConvert.DeserializeObject <T>(result.RawText));
        }
Пример #2
0
        private static string buildPath(ScribeConnection connection, Extensions.Actions action, string eventId, Dictionary <string, string> keyPairValues)
        {
            var path = string.Empty;

            if (String.IsNullOrEmpty(eventId))
            {
                path = $"{connection.BaseUrl}/api/v2/ereg/{action.Name()}?accesstoken={connection.AccessToken}";
            }
            else
            {
                path = $"{connection.BaseUrl}/api/v2/ereg/{action.Name()}?accesstoken={connection.AccessToken}&eventid={connection.EventId}";
            }

            foreach (var kp in keyPairValues)
            {
                path = $"{path}&{kp.Key}={kp.Value}";
            }
            return(path);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }