internal static T ExecuteOperation(string url, HttpMethod method, string username, string password, string body = "", string jsonRoot = "")
        {
            ActivitiRESTClient <T> client   = InitClient(FormatUrl(url), method, body);
            Response <T>           response = null;

            switch (method)
            {
            case HttpMethod.POST:
                response = client.Post(username, password);
                break;

            case HttpMethod.PUT:
                response = client.Post(username, password);
                break;

            case HttpMethod.GET:
                response = client.Get(username, password);
                break;

            case HttpMethod.DELETE:
                response = client.Delete(username, password);
                break;

            default:
                return(null);
            }

            return(response.ParseResponse(jsonRoot));
        }
        internal static byte[] GetBytes(string url, string username, string password)
        {
            ActivitiRESTClient <T> client   = InitClient(FormatUrl(url), HttpMethod.GET, string.Empty);
            Response <T>           response = null;

            response = client.Get(username, password, true);

            return(response.ByteData);
        }
        internal async Task <List <T> > GetAllAsync()
        {
            ActivitiRESTClient <T> client   = new ActivitiRESTClient <T>(_baseUrl + _url, HttpMethod.GET);
            Response <T>           response = await client.GetAsync(_username, _password);

            JObject jsonResponse = JObject.Parse(response.Body);

            return(JsonConvert.DeserializeObject <List <T> >(
                       jsonResponse.SelectToken("data").ToString()));
        }
        internal bool TryDelete(string id, out T responseObject)
        {
            var client = new ActivitiRESTClient <T>(string.Concat(_baseUrl, _url, "/", id), HttpMethod.DELETE);

            Response <T> response = client.Delete(_username, _password);
            int          status   = (int)response.StatusCode;

            responseObject = JsonConvert.DeserializeObject <T>(response.Body);

            return(status >= 200 && status < 300);
        }
        private static ActivitiRESTClient <T> InitClient(string url, HttpMethod method, string body)
        {
            ActivitiRESTClient <T> client = null;

            if (!string.IsNullOrEmpty(body))
            {
                client = new ActivitiRESTClient <T>(url, method, body);
            }
            else
            {
                client = new ActivitiRESTClient <T>(url, method);
            }

            return(client);
        }
        internal static Dictionary <string, string> GetProperties(string url, string username, string password)
        {
            ActivitiRESTClient <T>      client     = InitClient(FormatUrl(url), HttpMethod.GET, string.Empty);
            Response <T>                response   = null;
            Dictionary <string, string> properties = new Dictionary <string, string>();

            response = client.Get(username, password, true);
            if (response.Exception != null)
            {
                JObject json = JObject.Parse(response.Body);

                foreach (JToken jsonToken in json.Children())
                {
                    var next = jsonToken.Next;
                }

                return(properties);
            }
            else
            {
                throw response.Exception;
            }
        }
        internal static HttpStatusCode PostFile(string url, byte[] fileData, string fileName, string mimeType, string username, string password)
        {
            ActivitiRESTClient <T> client = InitClient(FormatUrl(url), HttpMethod.GET, string.Empty);

            return(client.PostFile(fileData, fileName, mimeType, username, password));
        }