Example #1
0
 public static void CleanHeaders()
 {
     lock (typeof(HeadersManager))
     {
         _instance = null;
     }
 }
Example #2
0
        public static HeadersManager GetInstance()
        {
            if (_instance == null)
            {
                lock (headersLock)
                {
                    if (_instance == null)
                    {
                        _instance = new HeadersManager();
                    }
                }
            }

            return(_instance);
        }
Example #3
0
        public static HeadersManager GetInstance()
        {
            if (_instance == null)
            {
                lock (headersLock)
                {
                    if (_instance == null)
                    {
                        _instance = new HeadersManager();
                        _instance.AddHeader(HeadersEnum.APP_ID_NAME, Backendless.AppId);
                        _instance.AddHeader(HeadersEnum.SECRET_KEY_NAME, Backendless.SecretKey);
                        _instance.AddHeader(HeadersEnum.APP_TYPE_NAME, "REST");
                    }
                }
            }

            return(_instance);
        }
Example #4
0
        public static void InvokeAsync <T>(string className, string methodName, object[] args, bool enableUnderFlowInspection, AsyncCallback <T> callback)
        {
            var responder = new Responder <T>(response =>
            {
                if (callback != null)
                {
                    callback.ResponseHandler.Invoke(response);
                }
            }, fault =>
            {
                var backendlessFault = new BackendlessFault(fault);
                if (callback != null)
                {
                    callback.ErrorHandler.Invoke(backendlessFault);
                }
                else
                {
                    throw new BackendlessException(backendlessFault);
                }
            });

            try
            {
                ResponseThreadConfigurator responseConfig = null;

                if (enableUnderFlowInspection)
                {
                    responseConfig = new ResponseThreadConfigurator(SetupUnderFlowListener);
                }

                client.Invoke <T>(className, methodName, args, null, HeadersManager.GetInstance().Headers, responder, responseConfig);
            }
            catch (System.Exception ex)
            {
                var backendlessFault = new BackendlessFault(ex.Message);
                if (callback != null)
                {
                    callback.ErrorHandler.Invoke(backendlessFault);
                }
                throw new BackendlessException(backendlessFault);
            }
        }
Example #5
0
        public static HeadersManager GetInstance()
        {
            if (_instance == null)
            {
                lock (headersLock)
                {
                    if (_instance == null)
                    {
                        _instance = new HeadersManager();
                        _instance.AddHeader( HeadersEnum.APP_ID_NAME, Backendless.AppId );
                        _instance.AddHeader( HeadersEnum.SECRET_KEY_NAME, Backendless.SecretKey );
                        _instance.AddHeader(HeadersEnum.APP_TYPE_NAME, "WP");
                        _instance.AddHeader(HeadersEnum.API_VERSION, "1.0");
                       
                    }
                }
            }

            return _instance;
        }
Example #6
0
        public static T InvokeSync <T>(string className, string methodName, object[] args, bool enableUnderFlowInspection)
        {
            T result = default(T);
            BackendlessFault backendlessFault = null;
            AutoResetEvent   waiter           = new AutoResetEvent(false);

            var responder = new Responder <T>(r =>
            {
                result = r;
                waiter.Set();
            }, f =>
            {
                backendlessFault = new BackendlessFault(f);
                waiter.Set();
            });

            try
            {
                ResponseThreadConfigurator responseConfig = null;

                if (enableUnderFlowInspection)
                {
                    responseConfig = new ResponseThreadConfigurator(SetupUnderFlowListener);
                }

                client.Invoke <T>(className, methodName, args, null, HeadersManager.GetInstance().Headers, responder, responseConfig);
                waiter.WaitOne(System.Threading.Timeout.Infinite);
            }
            catch (System.Exception ex)
            {
                throw new BackendlessException(ex.Message);
            }

            if (backendlessFault != null)
            {
                throw new BackendlessException(backendlessFault);
            }

            return(result);
        }
Example #7
0
 public static void CleanHeaders()
 {
     lock (typeof(HeadersManager))
       {
     _instance = null;
       }
 }
Example #8
0
        private static void GetRestApiRequestCommand(Api api, object[] args, out Method method, out string url, out Dictionary <string, string> headers)
        {
            // Common
            headers = HeadersManager.GetInstance().Headers;
            url     = Backendless.Url + "/" + Backendless.VersionNum + "/";

            switch (api)
            {
            case Api.USERSERVICE_REGISTER:
                method = Method.POST;
                url   += "users/register";
                break;

            case Api.USERSERVICE_UPDATE:
                method = Method.PUT;
                url   += "users/";
                url   += args[1]; // + <user-id>
                break;

            case Api.USERSERVICE_LOGIN:
                method = Method.POST;
                url   += "users/login";
                break;

            case Api.USERSERVICE_LOGOUT:
                method = Method.GET;
                url   += "users/logout";
                break;

            case Api.USERSERVICE_RESTOREPASSWORD:
                method = Method.GET;
                url   += "users/restorepassword/";
                url   += args[1]; // + <user-identity-property>
                break;

            case Api.USERSERVICE_GETUSERROLES:
                method = Method.GET;
                url   += "users/userroles";
                break;

            case Api.USERSERVICE_DESCRIBEUSERCLASS:
                method = Method.GET;
                url   += "users/userclassprops";
                break;

            case Api.PERSISTENCESERVICE_CREATE:
                method = Method.POST;
                url   += "data/";
                url   += args[1]; // + <table-name>
                break;

            case Api.PERSISTENCESERVICE_UPDATE:
                method = Method.PUT;
                url   += "data/";
                url   += args[1] + "/" + args[2]; // + <table-name>/<object-id>
                break;

            case Api.PERSISTENCESERVICE_REMOVE:
                method = Method.DELETE;
                url   += "data/";
                url   += args[1] + "/" + args[2]; // + <table-name>/<object-id>
                break;

            case Api.PERSISTENCESERVICE_FIND:
                method = Method.GET;
                url   += "data/";
                url   += args[1]; // + <table-name>
                if (args[2] != null)
                {
                    url += "/" + args[2]; // + /<object-id> or first or last
                }
                if (args[3] != null)
                {
                    url += "?" + args[3];
                }
                break;

            case Api.PERSISTENCESERVICE_DESCRIBE:
                method = Method.GET;
                url   += "data/";
                url   += args[1] + "/properties"; // + <table-name>/properties
                break;

            case Api.FILESERVICE_REMOVE:
                method = Method.DELETE;
                url   += "files/";
                url   += args[1]; // + <path>/<filename> or <path>
                break;

            case Api.GEOSERVICE_ADDCATEGORY:
                method = Method.PUT;
                url   += "geo/categories/";
                url   += args[1]; // + <categoryName>
                break;

            case Api.GEOSERVICE_DELETECATEGORY:
                method = Method.DELETE;
                url   += "geo/categories/";
                url   += args[1]; // + <categoryName>
                break;

            case Api.GEOSERVICE_GETCATEGORIES:
                method = Method.GET;
                url   += "geo/categories";
                break;

            case Api.GEOSERVICE_SAVEPOINT:
                method = Method.PUT;
                url   += "geo/points";
                url   += args[1];
                break;

            case Api.GEOSERVICE_UPDATEPOINT:
                method = Method.PATCH;
                url   += "geo/points";
                url   += args[1];
                break;

            case Api.GEOSERVICE_GETPOINTS:
                method = Method.GET;
                url   += "geo/points";
                url   += args[1];
                break;

            case Api.GEOSERVICE_GETRECT:
                method = Method.GET;
                url   += "geo/rect";
                url   += args[1];
                break;

            case Api.GEOSERVICE_RELATIVEFIND:
                method = Method.GET;
                url   += "geo/relative/points";
                url   += args[1];
                break;

            case Api.MESSAGINGSERVICE_PUBLISH:
                method = Method.POST;
                url   += "messaging/";
                url   += args[1]; // + <channel-name>
                break;

            case Api.MESSAGINGSERVICE_CANCEL:
                method = Method.DELETE;
                url   += "messaging/";
                url   += args[1]; // + <message-id>
                break;

            case Api.MESSAGINGSERVICE_SUBSCRIBE:
                method = Method.POST;
                url   += "messaging/";
                url   += args[1] + "/subscribe"; // + <channel-name>/subscribe
                break;

            case Api.MESSAGINGSERVICE_POLLMESSAGES:
                method = Method.GET;
                url   += "messaging/";
                url   += args[1] + "/" + args[2]; // + <channel-name>/<subscription-id>
                break;

            case Api.MESSAGINGSERVICE_SENDEMAIL:
                method = Method.POST;
                url   += "messaging/email";
                break;

            case Api.MESSAGINGSERVICE_REGISTERDEVICEONSERVER:
                method = Method.POST;
                url   += "messaging/registrations";
                break;

            case Api.MESSAGINGSERVICE_GETREGISTRATION:
                method = Method.GET;
                url   += "messaging/registrations/";
                url   += args[1]; // + <device-id>
                break;

            case Api.MESSAGINGSERVICE_UNREGISTERDEVICEONSERVER:
                method = Method.DELETE;
                url   += "messaging/registrations/";
                url   += args[1]; // + <device-id>
                break;

            case Api.EVENTS_DISPATCH:
                method = Method.POST;
                url   += "servercode/events/";
                url   += args[1]; // + <event name>
                break;

            case Api.COUNTERSERVICE_RESET:
                method = Method.PUT;
                url   += "counters/";
                url   += args[1] + "/reset"; // + <counterName>/reset
                break;

            case Api.COUNTERSERVICE_GET:
                method = Method.GET;
                url   += "counters/";
                url   += args[1]; // + <counterName>
                break;

            case Api.COUNTERSERVICE_GET_INC:
                method = Method.PUT;
                url   += "counters/";
                url   += args[1] + "/get/increment"; // + <counterName>/get/increment
                break;

            case Api.COUNTERSERVICE_INC_GET:
                method = Method.PUT;
                url   += "counters/";
                url   += args[1] + "/increment/get"; // + <counterName>/increment/get
                break;

            case Api.COUNTERSERVICE_GET_DEC:
                method = Method.PUT;
                url   += "counters/";
                url   += args[1] + "/get/decrement"; // + <counterName>/get/decrement
                break;

            case Api.COUNTERSERVICE_DEC_GET:
                method = Method.PUT;
                url   += "counters/";
                url   += args[1] + "/decrement/get"; // + <counterName>/decrement/get
                break;

            case Api.COUNTERSERVICE_ADD_GET:
                method = Method.PUT;
                url   += "counters/";
                url   += args[1] + "/incrementby/get?value=" + args[2]; // + <counterName>/incrementby/get?value=<value>
                break;

            case Api.COUNTERSERVICE_GET_ADD:
                method = Method.PUT;
                url   += "counters/";
                url   += args[1] + "/get/incrementby?value=" + args[2]; // + <counterName>/get/incrementby?value=<value>
                break;

            case Api.COUNTERSERVICE_COM_SET:
                method = Method.PUT;
                url   += "counters/";
                url   += args[1] + "/get/compareandset?expected=" + args[2] + "&updatedvalue=" + args[3]; // + <counterName>/get/compareandset?expected=<expected>&updatedvalue=<updated>
                break;

            case Api.CACHESERVICE_PUT:
                method = Method.PUT;
                url   += "cache/";
                url   += args[1];
                if ((int)args[2] != 0)
                {
                    url += "?timeout=" + args[2]; // + <key>?timeout=<timeToLive>
                }
                break;

            case Api.CACHESERVICE_GET:
                method = Method.GET;
                url   += "cache/";
                url   += args[1]; // + <key>
                break;

            case Api.CACHESERVICE_CONTAINS:
                method = Method.GET;
                url   += "cache/";
                url   += args[1] + "/check"; // + <key>/check
                break;

            case Api.CACHESERVICE_EXPIREIN:
                method = Method.PUT;
                url   += "cache/";
                url   += args[1] + "/expireIn?timeout=" + args[2]; // + <key>/expireIn?timeout=<seconds>
                break;

            case Api.CACHESERVICE_EXPIREAT:
                method = Method.PUT;
                url   += "cache/";
                url   += args[1] + "/expireAt?timestamp=" + args[2]; // + <key>/expireAt?timestamp=<timestamp>
                break;

            case Api.CACHESERVICE_DELETE:
                method = Method.DELETE;
                url   += "cache/";
                url   += args[1]; // + <key>
                break;

            case Api.LOGGERSERVICE_PUT:
                method = Method.PUT;
                url   += "log";
                break;

            default:
                throw new BackendlessException("GetRequestData() bad parameter 'api'");
            }
        }