Beispiel #1
0
        /// <summary>
        /// Asynchronous method to execute the server response.
        /// </summary>
        /// <param name="result">Contains the DC_ServerResponse that the server sent.</param>
        private void getResponseResult(IAsyncResult result)
        {
            GetResponseDelegate     del             = result.AsyncState as GetResponseDelegate;
            ServerConnectorResponse server_response = del.EndInvoke(result);

            execServerResponse(server_response);
        }
Beispiel #2
0
        /// <summary>
        /// Asynchronous method to handle the completion of the file upload process.
        /// </summary>
        /// <param name="result">Contains the DC_ServerResponse that the server sent.</param>
        private void postFileStreamResult(IAsyncResult result)
        {
            PostFileStreamDelegate  del             = result.AsyncState as PostFileStreamDelegate;
            ServerConnectorResponse server_response = del.EndInvoke(result);

            if (!server_response.canceled)
            {
                upload_completed.Invoke(server_response);
            }
        }
Beispiel #3
0
        private void deleteUpload_response(ServerConnectorResponse response)
        {
            switch (response.getCalledMethod())
            {
            case "file_delete_failure_owner":
                this.Invoke(new MethodInvoker(file_delete_failure_owner));
                break;

            case "file_delete_failure":
                this.Invoke(new MethodInvoker(file_delete_failure));
                break;

            case "file_delete_confirmation":
                this.Invoke(new MethodInvoker(file_delete_confirmation));
                break;

            default:
                connector.execServerResponse(response);
                break;
            }
        }
Beispiel #4
0
        private void uploadCompleted(ServerConnectorResponse response)
        {
            connectionClosed();
            upload_response = response;

            switch (response.getCalledMethod())
            {
            case "upload_failed_exceeded_toal_used_space":
                this.Invoke((MethodInvoker)upload_failed_exceeded_toal_used_space);
                break;

            case "upload_failed_exceeded_file_size":
                this.Invoke((MethodInvoker)upload_failed_exceeded_file_size);
                break;

            case "upload_successful":
                this.Invoke((MethodInvoker)upload_successful);
                break;

            case "upload_failed_db_error":
                this.Invoke((MethodInvoker)upload_failed_db_error);
                break;

            case "upload_failed_could_not_handle_file":
                this.Invoke((MethodInvoker)upload_failed_could_not_handle_file);
                break;

            case "upload_failed_not_connected":
                this.Invoke((MethodInvoker)upload_failed_not_connected);
                break;

            default:
                connector.execServerResponse(response);
                break;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Asynchronously execute a method on the server and have a callback executed on a completed query.
        /// </summary>
        /// <param name="method">Method name to execute on the server.</param>
        /// <param name="callback">Delegate to call when the server request has been sent and the response has been read.</param>
        /// <param name="arguments">Arguments to pass to the method on the server.</param>
        public void callServerMethod(string method, ServerConnectorMethodCallback callback, params object[] arguments)
        {
            // Determine if multiple arguments are being passed or just one array.
            if (arguments.GetType().Equals(typeof(object[])) == false)
            {
                arguments = new object[] { arguments };
            }
            RequestQuery queue_query = new RequestQuery()
            {
                upload    = false,
                method    = method,
                callback  = callback,
                arguments = arguments
            };

            if (requestAlowed(queue_query) == false)
            {
                return;
            }

            Uri uri = buildUri(method);
            GetResponseDelegate get = new GetResponseDelegate(getResponse);

            if (callback == null)
            {
                get.BeginInvoke(uri, arguments, new AsyncCallback(getResponseResult), get);
            }
            else
            {
                get.BeginInvoke(uri, arguments, new AsyncCallback(delegate(IAsyncResult result) {
                    GetResponseDelegate del = result.AsyncState as GetResponseDelegate;
                    ServerConnectorResponse server_response = del.EndInvoke(result);
                    callback(server_response);
                }), get);
            }
        }
        /// <summary>
        /// Method to handle the execution and error handling of the server response.
        /// </summary>
        /// <param name="response">Server sent response to deal with.</param>
        public void execServerResponse(ServerConnectorResponse response)
        {
            // If a transport error occurred, let the user know.
            if(response.error) {
                // We should only alert the user if something is wrong with the request on their system, and not errors with missing files on the server.
                if(response.error_status != WebExceptionStatus.ProtocolError) {
                    Client.form_Login.Invoke((MethodInvoker)delegate {
                        MessageBox.Show("Encountered error when reading server response.  Details: \n\n" + response.error_info);
                    });
                }
            }

            // Check to see if the headers have even been set.
            if(response.headers == null) {
                Client.form_Login.Invoke((MethodInvoker)Client.form_Login.serverInvalid);
                server_info.is_connected = false;
                return;
            }

            string method = response.getCalledMethod();

            // Ensure that the server is calling a method.
            if(method == null) {
                Client.form_Login.Invoke((MethodInvoker)Client.form_Login.serverInvalid);
                server_info.is_connected = false;
                return;
            }

            // Try to get the requested method from the list of valid actions.
            MethodInfo requested_method = typeof(ClientActions).GetMethod(method);
            if(requested_method != null) {
                int param_count = requested_method.GetParameters().Length;
                try {
                    if(response.body == "false" && param_count == 0) {
                        requested_method.Invoke(actions, null);
                    } else {
                        requested_method.Invoke(actions, new object[] { response.body });
                    }
                } catch(ClientActionsInternalException) { // Internal exception.  Add to a log list?

                } catch (Exception e){ // All other exceptions.
                    Client.form_Login.Invoke((MethodInvoker)delegate {
                        MessageBox.Show("Client unhandled exception.\n\nException:\n" + e.Message);
                    });
                }

            } else {
                Client.form_Login.Invoke((MethodInvoker)delegate {
                    MessageBox.Show("Server requested invalid method.  This is usually due to an outdated client.\n\nError:\n" + response.body);
                });
            }
        }
Beispiel #7
0
        /// <summary>
        /// Method to handle the execution and error handling of the server response.
        /// </summary>
        /// <param name="response">Server sent response to deal with.</param>
        public void execServerResponse(ServerConnectorResponse response)
        {
            // If a transport error occurred, let the user know.
            if (response.error)
            {
                // We should only alert the user if something is wrong with the request on their system, and not errors with missing files on the server.
                if (response.error_status != WebExceptionStatus.ProtocolError)
                {
                    Client.form_Login.Invoke((MethodInvoker) delegate {
                        MessageBox.Show("Encountered error when reading server response.  Details: \n\n" + response.error_info);
                    });
                }
            }

            // Check to see if the headers have even been set.
            if (response.headers == null)
            {
                Client.form_Login.Invoke((MethodInvoker)Client.form_Login.serverInvalid);
                server_info.is_connected = false;
                return;
            }

            string method = response.getCalledMethod();

            // Ensure that the server is calling a method.
            if (method == null)
            {
                Client.form_Login.Invoke((MethodInvoker)Client.form_Login.serverInvalid);
                server_info.is_connected = false;
                return;
            }

            // Try to get the requested method from the list of valid actions.
            MethodInfo requested_method = typeof(ClientActions).GetMethod(method);

            if (requested_method != null)
            {
                int param_count = requested_method.GetParameters().Length;
                try {
                    if (response.body == "false" && param_count == 0)
                    {
                        requested_method.Invoke(actions, null);
                    }
                    else
                    {
                        requested_method.Invoke(actions, new object[] { response.body });
                    }
                } catch (ClientActionsInternalException) { // Internal exception.  Add to a log list?
                } catch (Exception e) {                    // All other exceptions.
                    Client.form_Login.Invoke((MethodInvoker) delegate {
                        MessageBox.Show("Client unhandled exception.\n\nException:\n" + e.Message);
                    });
                }
            }
            else
            {
                Client.form_Login.Invoke((MethodInvoker) delegate {
                    MessageBox.Show("Server requested invalid method.  This is usually due to an outdated client.\n\nError:\n" + response.body);
                });
            }
        }
        private void uploadCompleted(ServerConnectorResponse response)
        {
            connectionClosed();
            upload_response = response;

            switch(response.getCalledMethod()) {
                case "upload_failed_exceeded_toal_used_space":
                    this.Invoke((MethodInvoker)upload_failed_exceeded_toal_used_space);
                    break;

                case "upload_failed_exceeded_file_size":
                    this.Invoke((MethodInvoker)upload_failed_exceeded_file_size);
                    break;

                case "upload_successful":
                    this.Invoke((MethodInvoker)upload_successful);
                    break;

                case "upload_failed_db_error":
                    this.Invoke((MethodInvoker)upload_failed_db_error);
                    break;

                case "upload_failed_could_not_handle_file":
                    this.Invoke((MethodInvoker)upload_failed_could_not_handle_file);
                    break;

                case "upload_failed_not_connected":
                    this.Invoke((MethodInvoker)upload_failed_not_connected);
                    break;

                default:
                    connector.execServerResponse(response);
                    break;
            }
        }
        private void deleteUpload_response(ServerConnectorResponse response)
        {
            switch(response.getCalledMethod()) {
                case "file_delete_failure_owner":
                    this.Invoke(new MethodInvoker(file_delete_failure_owner));
                    break;

                case "file_delete_failure":
                    this.Invoke(new MethodInvoker(file_delete_failure));
                    break;

                case "file_delete_confirmation":
                    this.Invoke(new MethodInvoker(file_delete_confirmation));
                    break;

                default:
                    connector.execServerResponse(response);
                    break;
            }
        }