/// <summary>
 /// This method supports the infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="invocationManager"></param>
 /// <param name="memberInfo"></param>
 /// <param name="obj"></param>
 /// <param name="arguments"></param>
 /// <param name="result"></param>
 public void OnInvoked(IInvocationManager invocationManager, MemberInfo memberInfo, object obj, object[] arguments, object result)
 {
     if (result is DataSet)
     {
         if (_tableName != null)
         {
             DataSet dataSet = result as DataSet;
             if (dataSet.Tables.Contains(_tableName))
             {
                 DataTable dataTable = dataSet.Tables[_tableName];
                 if (_propertyName != null)
                 {
                     dataTable.ExtendedProperties.Add("alias", _propertyName);
                 }
                 ArrayList list = ConvertDataTable(dataTable);
                 invocationManager.Properties[dataTable] = list;
             }
         }
     }
     if (result is DataTable)
     {
         DataTable dataTable = result as DataTable;
         ArrayList list      = ConvertDataTable(dataTable);
         invocationManager.Result = list;
     }
 }
Ejemplo n.º 2
0
 public void HandleResult(IInvocationManager invocationManager, MethodInfo methodInfo, object obj, object[] arguments, object result)
 {
     if (result is DataSet)
     {
         DataSet  set  = result as DataSet;
         ASObject obj2 = new ASObject(this._remoteClass);
         foreach (KeyValuePair <object, object> pair in invocationManager.Properties)
         {
             if (pair.Key is DataTable)
             {
                 DataTable key = pair.Key as DataTable;
                 if (set.Tables.IndexOf(key) != -1)
                 {
                     if (!key.ExtendedProperties.ContainsKey("alias"))
                     {
                         obj2[key.TableName] = pair.Value;
                     }
                     else
                     {
                         obj2[key.ExtendedProperties["alias"] as string] = pair.Value;
                     }
                 }
             }
         }
         invocationManager.Result = obj2;
     }
 }
Ejemplo n.º 3
0
        private void ProcessAsyncData(object asyncDataObj)
        {
            object[] asyncData = (object[])asyncDataObj;

            string             callbackFunction = (string)asyncData[0];
            string             id = (string)asyncData[1];
            IInvocationManager invocationManager = (IInvocationManager)asyncData[2];
            Object             service           = (Object)asyncData[3];
            string             methodName        = (string)asyncData[4];
            string             query             = (string)asyncData[5];

            byte[] result           = this.ProcessPOSTResult(invocationManager, service, methodName, query);
            string jsonResultString = null;

            if (result != null && result.Length > 0)
            {
                jsonResultString = Encoding.UTF8.GetString(result);
            }
            else
            {
                jsonResultString = "null";                 // in order to send null values as a result for async callbacks
            }

            this.SendBackResult(callbackFunction, id, jsonResultString);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="invocationManager"></param>
        /// <param name="memberInfo"></param>
        /// <param name="obj"></param>
        /// <param name="arguments"></param>
        /// <param name="result"></param>
        public void HandleResult(IInvocationManager invocationManager, MemberInfo memberInfo, object obj, object[] arguments, object result)
        {
            if (result is DataSet)
            {
                DataSet  dataSet   = result as DataSet;
                ASObject asoResult = new ASObject(_remoteClass);

#if !(NET_1_1)
                foreach (KeyValuePair <object, object> entry in invocationManager.Properties)
#else
                foreach (DictionaryEntry entry in invocationManager.Properties)
#endif
                {
                    if (entry.Key is DataTable)
                    {
                        DataTable dataTable = entry.Key as DataTable;
                        if (dataSet.Tables.IndexOf(dataTable) != -1)
                        {
                            if (!dataTable.ExtendedProperties.ContainsKey("alias"))
                            {
                                asoResult[dataTable.TableName] = entry.Value;
                            }
                            else
                            {
                                asoResult[dataTable.ExtendedProperties["alias"] as string] = entry.Value;
                            }
                        }
                    }
                }
                invocationManager.Result = asoResult;
            }
        }
Ejemplo n.º 5
0
        public void OnInvoked(IInvocationManager invocationManager, MethodInfo methodInfo, object obj, object[] arguments, object result)
        {
            DataTable table;
            ArrayList list;

            if ((result is DataSet) && (this._tableName != null))
            {
                DataSet set = result as DataSet;
                if (set.Tables.Contains(this._tableName))
                {
                    table = set.Tables[this._tableName];
                    if (this._propertyName != null)
                    {
                        table.ExtendedProperties.Add("alias", this._propertyName);
                    }
                    list = this.ConvertDataTable(table);
                    invocationManager.Properties[table] = list;
                }
            }
            if (result is DataTable)
            {
                table = result as DataTable;
                list  = this.ConvertDataTable(table);
                invocationManager.Result = list;
            }
        }
        /// <summary>
        /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="invocationManager"></param>
        /// <param name="memberInfo"></param>
        /// <param name="obj"></param>
        /// <param name="arguments"></param>
        /// <param name="result"></param>
        public void HandleResult(IInvocationManager invocationManager, MemberInfo memberInfo, object obj, object[] arguments, object result)
		{
			if( result is DataSet )
			{
				DataSet dataSet = result as DataSet;
				ASObject asoResult = new ASObject(_remoteClass);

#if !(NET_1_1)
                foreach (KeyValuePair<object, object> entry in invocationManager.Properties)
#else
				foreach(DictionaryEntry entry in invocationManager.Properties)
#endif
				{
					if( entry.Key is DataTable )
					{
						DataTable dataTable = entry.Key as DataTable;
						if( dataSet.Tables.IndexOf(dataTable) != -1 )
						{
							if( !dataTable.ExtendedProperties.ContainsKey("alias") )
								asoResult[dataTable.TableName] = entry.Value;
							else
								asoResult[ dataTable.ExtendedProperties["alias"] as string ] = entry.Value;
						}
					}
				}
				invocationManager.Result = asoResult;
			}
		}
Ejemplo n.º 7
0
		/// <summary>
		/// This method supports the infrastructure and is not intended to be used directly from your code.
		/// </summary>
		/// <param name="invocationManager"></param>
		/// <param name="memberInfo"></param>
		/// <param name="obj"></param>
		/// <param name="arguments"></param>
		/// <param name="result"></param>
		public void HandleResult(IInvocationManager invocationManager, MemberInfo memberInfo, object obj, object[] arguments, object result) {
			if (invocationManager.Result is DataSet) {
				DataSet dataSet = result as DataSet;
				invocationManager.Result = TypeHelper.ConvertDataSetToASO(dataSet, false);
			}
			if (invocationManager.Result is DataTable) {
				DataTable dataTable = result as DataTable;
				invocationManager.Result = TypeHelper.ConvertDataTableToASO(dataTable, false);
			}
		}
Ejemplo n.º 8
0
        public byte[] ProcessPOSTResult(IInvocationManager invocationManager, Object service, string methodName, string query)
        {
            string queryString = null;

            if (query != null && query.Length > "json=".Length)
            {
                //queryString = ServiceURIHandler.UrlDecode(request.QueryString.Substring("json=".Length));
                queryString = query.Substring("json=".Length);
            }

            return(invocationManager.InvokeService(service, methodName, queryString));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="invocationManager"></param>
 /// <param name="memberInfo"></param>
 /// <param name="obj"></param>
 /// <param name="arguments"></param>
 /// <param name="result"></param>
 public void HandleResult(IInvocationManager invocationManager, MemberInfo memberInfo, object obj, object[] arguments, object result)
 {
     if (invocationManager.Result is DataSet)
     {
         DataSet dataSet = result as DataSet;
         invocationManager.Result = TypeHelper.ConvertDataSetToASO(dataSet, false);
     }
     if (invocationManager.Result is DataTable)
     {
         DataTable dataTable = result as DataTable;
         invocationManager.Result = TypeHelper.ConvertDataTableToASO(dataTable, false);
     }
 }
Ejemplo n.º 10
0
        public void ProcessAsyncPOSTResult(IInvocationManager invocationManager, Object service, string methodName, string query)
        {
            SystemLogger.Log (SystemLogger.Module .CORE, "Processing result asynchronously");
            SystemLogger.Log (SystemLogger.Module .CORE, "query: " + query);

            string callback = null;
            string ID = null;
            string JSON = null;

            // querystring format: callbackFunction$$$ID$$$json=******
            // [MOBPLAT-185], the "json" latest query parameter could not be present (for API methods without parameters)
            if (query!= null) {
                string token0 = "&";
                string token1 = "callback=";
                string token2 = "callbackid=";
                int nextParamToken = 0;

                if(query.IndexOf(token1)==0) {
                    query = query.Substring(token1.Length);
                    nextParamToken = query.IndexOf(token0);
                    if(nextParamToken==-1) nextParamToken = query.Length;
                    if(query.Length>=nextParamToken)
                        callback = query.Substring(0, nextParamToken);
                    if (query != null && query.Length > (nextParamToken + 1))
                        query = query.Substring (nextParamToken + 1);
                    else
                        query = null;
                }
                if(query!= null && query.IndexOf(token2)==0) {
                    query = query.Substring(token2.Length);
                    nextParamToken = query.IndexOf(token0);
                    if(nextParamToken==-1) nextParamToken = query.Length;
                    if(query.Length>=nextParamToken)
                        ID = query.Substring(0, nextParamToken);
                    if (query != null && query.Length > (nextParamToken + 1))
                        query = query.Substring(nextParamToken+1);
                    else
                        query = null;
                }

                JSON = query;
            }
            SystemLogger.Log (SystemLogger.Module .CORE, "callback function: " + callback);
            SystemLogger.Log (SystemLogger.Module .CORE, "callback ID: " + ID);
            SystemLogger.Log (SystemLogger.Module .CORE, "JSON data: " + JSON);

            this.ProcessServiceAsynchronously(callback, ID, invocationManager, service, methodName,JSON);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Processes the service asynchronously. Using NSAutoreleasePool monotouch class.
 /// </summary>
 /// <param name='callbackFunction'>
 /// Callback function.
 /// </param>
 /// <param name='id'>
 /// Identifier.
 /// </param>
 /// <param name='invocationManager'>
 /// Invocation manager.
 /// </param>
 /// <param name='service'>
 /// Service.
 /// </param>
 /// <param name='methodName'>
 /// Method name.
 /// </param>
 /// <param name='query'>
 /// Query.
 /// </param>
 protected override void ProcessServiceAsynchronously(string callbackFunction, string id, IInvocationManager invocationManager, Object service, string methodName, string query)
 {
     using (var pool = new NSAutoreleasePool()) {
         base.ProcessServiceAsynchronously(callbackFunction, id, invocationManager, service, methodName, query);
     };
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Processes the service asynchronously.
        /// Override this function to provide platform specific behaviour (such as, calling this in an autorelease pool)
        /// </summary>
        /// <param name='callbackFunction'>
        /// Callback function.
        /// </param>
        /// <param name='id'>
        /// Identifier.
        /// </param>
        /// <param name='invocationManager'>
        /// Invocation manager.
        /// </param>
        /// <param name='service'>
        /// Service.
        /// </param>
        /// <param name='methodName'>
        /// Method name.
        /// </param>
        /// <param name='query'>
        /// Query.
        /// </param>
        protected virtual void ProcessServiceAsynchronously(string callbackFunction, string id, IInvocationManager invocationManager, Object service, string methodName, string query)
        {
            object[] asyncData = new object[] { callbackFunction, id, invocationManager, service, methodName, query };

            var thread = new Thread(ProcessAsyncData);

            thread.Start(asyncData);
        }
Ejemplo n.º 13
0
        public virtual bool Process(HttpServer server, HttpRequest request, HttpResponse response)
        {
            SystemLogger.Log(SystemLogger.Module.CORE, " ############## " + this.GetType() + " -> " + request.Url);
            if (request.Url.StartsWith(SERVICE_URI))
            {
                SystemLogger.Log(SystemLogger.Module.CORE, "Service protocol.");

                bool asyncmode        = true;           // PLATFORM won't have anymore the sync mode for services.
                int  serviceUriLength = SERVICE_URI.Length;

                if (response.Header == null)
                {
                    response.Header = new Hashtable();
                }

                // Adding Header Cache-Control to "no-cache" to force no caching service requests
                string cacheControlHeader = DEFAULT_CACHE_CONTROL;

                response.ContentType = "application/json";
                IInvocationManager invocationManager = getInvocationManager(request.Method);

                try {
                    string   commandParams      = request.Url.Substring(serviceUriLength);
                    string[] commandParamsArray = commandParams.Split(new char[] { '/' });
                    string   serviceName        = commandParamsArray [0];

                    Object service    = serviceLocator.GetService(serviceName);
                    byte[] result     = null;
                    string methodName = commandParamsArray [1];

                    if (request.Method == "GET" && !asyncmode)
                    {
                        string[] methodParams = null;
                        if (commandParamsArray.Length > 2)
                        {
                            methodParams = new string[commandParamsArray.Length - 2];
                            for (int i = 2; i < commandParamsArray.Length; i++)
                            {
                                methodParams [i - 2] = commandParamsArray [i];
                            }
                        }

                        // Process result synchronously
                        result = this.ProcessGETResult(invocationManager, service, methodName, methodParams);
                    }
                    else if (request.Method == "POST")
                    {
                        if (asyncmode)
                        {
                            // Process result asynchronously
                            this.ProcessAsyncPOSTResult(invocationManager, service, methodName, request.QueryString);
                        }
                        else
                        {
                            // Process result synchronously
                            result = this.ProcessPOSTResult(invocationManager, service, methodName, request.QueryString);
                        }
                    }

                    if (asyncmode)
                    {
                        // Return acknowledge
                        response.Content = "{\"result\":\"Processed\"}";
                    }
                    else
                    {
                        response.RawContent = result;
                        if (response.RawContent == null)
                        {
                            response.Content = "null";

                            /* SERVICES COULD SEND NULL OBJETS.
                             *      SystemLogger.Log(SystemLogger.Module .CORE, "No content available for request [" + request.Url + "," + request.Method + "]. Continue to next handler...");
                             * return false;
                             */
                        }
                    }
                } catch (Exception e) {
                    SystemLogger.Log(SystemLogger.Module.CORE, "Exception when parsing request [" + request.Url + "]", e);
                    response.Content = "{\"result\":\"Malformed request\"}";
                }

                if (invocationManager.CacheControlHeader() != null)
                {
                    cacheControlHeader = invocationManager.CacheControlHeader();
                }

                if (response.Header.ContainsKey(CACHE_CONTROL_HEADER))
                {
                    response.Header[CACHE_CONTROL_HEADER] = cacheControlHeader;
                    SystemLogger.Log(SystemLogger.Module.CORE, "Updated Caching-Control header on response: " + cacheControlHeader);
                }
                else
                {
                    response.Header.Add(CACHE_CONTROL_HEADER, cacheControlHeader);
                    SystemLogger.Log(SystemLogger.Module.CORE, "Added Caching-Control header to response: " + cacheControlHeader);
                }

                return(true);
            }
            else
            {
                SystemLogger.Log(SystemLogger.Module.CORE, "Non service protocol. Continue to next handler...");
                return(false);
            }
        }
Ejemplo n.º 14
0
 private byte[] ProcessGETResult(IInvocationManager invocationManager, Object service, string methodName, string[] methodParams)
 {
     return(invocationManager.InvokeService(service, methodName, methodParams));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Processes the service asynchronously. Using NSAutoreleasePool monotouch class.
 /// </summary>
 /// <param name='callbackFunction'>
 /// Callback function.
 /// </param>
 /// <param name='id'>
 /// Identifier.
 /// </param>
 /// <param name='invocationManager'>
 /// Invocation manager.
 /// </param>
 /// <param name='service'>
 /// Service.
 /// </param>
 /// <param name='methodName'>
 /// Method name.
 /// </param>
 /// <param name='query'>
 /// Query.
 /// </param>
 protected override void ProcessServiceAsynchronously(string callbackFunction, string id, IInvocationManager invocationManager, Object service, string methodName, string query)
 {
     using (var pool = new NSAutoreleasePool ()) {
         base.ProcessServiceAsynchronously(callbackFunction, id, invocationManager, service, methodName, query);
     };
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Processes the service asynchronously.
        /// Override this function to provide platform specific behaviour (such as, calling this in an autorelease pool)
        /// </summary>
        /// <param name='callbackFunction'>
        /// Callback function.
        /// </param>
        /// <param name='id'>
        /// Identifier.
        /// </param>
        /// <param name='invocationManager'>
        /// Invocation manager.
        /// </param>
        /// <param name='service'>
        /// Service.
        /// </param>
        /// <param name='methodName'>
        /// Method name.
        /// </param>
        /// <param name='query'>
        /// Query.
        /// </param>
        protected virtual void ProcessServiceAsynchronously(string callbackFunction, string id, IInvocationManager invocationManager, Object service, string methodName, string query)
        {
            object[] asyncData = new object[] { callbackFunction, id, invocationManager, service, methodName, query};

            var thread = new Thread (ProcessAsyncData);
            thread.Start (asyncData);
        }
Ejemplo n.º 17
0
        public byte[] ProcessPOSTResult(IInvocationManager invocationManager, Object service, string methodName, string query)
        {
            string queryString = null;
            if (query != null && query.Length > "json=".Length) {
                //queryString = ServiceURIHandler.UrlDecode(request.QueryString.Substring("json=".Length));
                queryString = query.Substring ("json=".Length);
            }

            return invocationManager.InvokeService (service, methodName, queryString);
        }
Ejemplo n.º 18
0
        public void ProcessAsyncPOSTResult(IInvocationManager invocationManager, Object service, string methodName, string query)
        {
            SystemLogger.Log(SystemLogger.Module.CORE, "Processing result asynchronously");
            SystemLogger.Log(SystemLogger.Module.CORE, "query: " + query);

            string callback = null;
            string ID       = null;
            string JSON     = null;

            // querystring format: callbackFunction$$$ID$$$json=******
            // [MOBPLAT-185], the "json" latest query parameter could not be present (for API methods without parameters)
            if (query != null)
            {
                string token0         = "&";
                string token1         = "callback=";
                string token2         = "callbackid=";
                int    nextParamToken = 0;

                if (query.IndexOf(token1) == 0)
                {
                    query          = query.Substring(token1.Length);
                    nextParamToken = query.IndexOf(token0);
                    if (nextParamToken == -1)
                    {
                        nextParamToken = query.Length;
                    }
                    if (query.Length >= nextParamToken)
                    {
                        callback = query.Substring(0, nextParamToken);
                    }
                    if (query != null && query.Length > (nextParamToken + 1))
                    {
                        query = query.Substring(nextParamToken + 1);
                    }
                    else
                    {
                        query = null;
                    }
                }
                if (query != null && query.IndexOf(token2) == 0)
                {
                    query          = query.Substring(token2.Length);
                    nextParamToken = query.IndexOf(token0);
                    if (nextParamToken == -1)
                    {
                        nextParamToken = query.Length;
                    }
                    if (query.Length >= nextParamToken)
                    {
                        ID = query.Substring(0, nextParamToken);
                    }
                    if (query != null && query.Length > (nextParamToken + 1))
                    {
                        query = query.Substring(nextParamToken + 1);
                    }
                    else
                    {
                        query = null;
                    }
                }

                JSON = query;
            }
            SystemLogger.Log(SystemLogger.Module.CORE, "callback function: " + callback);
            SystemLogger.Log(SystemLogger.Module.CORE, "callback ID: " + ID);
            SystemLogger.Log(SystemLogger.Module.CORE, "JSON data: " + JSON);

            this.ProcessServiceAsynchronously(callback, ID, invocationManager, service, methodName, JSON);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="invocationManager"></param>
        /// <param name="memberInfo"></param>
        /// <param name="obj"></param>
        /// <param name="arguments"></param>
        /// <param name="result"></param>
        public void OnInvoked(IInvocationManager invocationManager, MemberInfo memberInfo, object obj, object[] arguments, object result)
		{
			if( result is DataSet )
			{
				if( _tableName != null )
				{
					DataSet dataSet = result as DataSet;
					if( dataSet.Tables.Contains(_tableName) )
					{
						DataTable dataTable = dataSet.Tables[_tableName];
						if( _propertyName != null )
							dataTable.ExtendedProperties.Add("alias", _propertyName);
						ArrayList list = ConvertDataTable(dataTable);
						invocationManager.Properties[dataTable] = list;
					}
				}
			}
			if( result is DataTable )
			{
				DataTable dataTable = result as DataTable;
				ArrayList list = ConvertDataTable(dataTable);
				invocationManager.Result = list;
			}
		}
Ejemplo n.º 20
0
 private byte[] ProcessGETResult(IInvocationManager invocationManager, Object service, string methodName, string[] methodParams)
 {
     return invocationManager.InvokeService (service, methodName, methodParams);
 }
Ejemplo n.º 21
0
        private void ProcessAsyncPOSTResult(IInvocationManager invocationManager, Object service, string methodName, string query)
        {
            SystemLogger.Log (SystemLogger.Module .CORE, "Processing result asynchronously");
            SystemLogger.Log (SystemLogger.Module .CORE, "query: " + query);

            string callback = null;
            string ID = null;
            string JSON = null;

            // querystring format: callbackFunction$$$ID$$$json=******
            if (query!= null) {
                string token0 = "&";
                string token1 = "callback=";
                string token2 = "callbackid=";

                if(query.IndexOf(token1)==0) {
                    query = query.Substring(token1.Length);
                    callback = query.Substring(0, query.IndexOf(token0));
                    query = query.Substring(query.IndexOf(token0)+1);
                }
                if(query.IndexOf(token2)==0) {
                    query = query.Substring(token2.Length);
                    ID = query.Substring(0, query.IndexOf(token0));
                    query = query.Substring(query.IndexOf(token0)+1);
                }

                JSON = query;
            }
            SystemLogger.Log (SystemLogger.Module .CORE, "callback function: " + callback);
            SystemLogger.Log (SystemLogger.Module .CORE, "callback ID: " + ID);
            SystemLogger.Log (SystemLogger.Module .CORE, "JSON data: " + JSON);

            this.ProcessServiceAsynchronously(callback, ID, invocationManager, service, methodName,JSON);
        }