Exemplo n.º 1
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            try
            {
                switch (message.Method)
                {
                case "sendMail":
                    List <string> toList  = ((JToken)message.Args[0]).ToObject <List <string> >();
                    string        subject = message.Args[1] as string;
                    string        body    = message.Args[2] as string;
                    List <string> ccList  = ((JToken)message.Args[3]).ToObject <List <string> >();
                    List <string> bccList = ((JToken)message.Args[4]).ToObject <List <string> >();

                    // Create email compose task and display
                    EmailComposeTask emailComposeTask = new EmailComposeTask();
                    emailComposeTask.To      = String.Join("; ", toList);
                    emailComposeTask.Subject = subject;
                    emailComposeTask.Body    = body;
                    emailComposeTask.Cc      = String.Join("; ", ccList);
                    emailComposeTask.Bcc     = String.Join("; ", bccList);
                    UiDispatcher.BeginInvoke(() =>
                    {
                        emailComposeTask.Show();
                    });

                    // Set app navigated to external page
                    Mowbly.AppNavigatedToExternalPage = true;

                    break;

                case "sendText":
                case "sendData":
                    // Create sms compose task and show
                    List <string> phoneNumbers = ((JToken)message.Args[0]).ToObject <List <string> >();
                    string        text         = message.Args[1] as string;

                    SmsComposeTask smsComposeTask = new SmsComposeTask();
                    smsComposeTask.To   = String.Join(";", phoneNumbers);
                    smsComposeTask.Body = text;
                    UiDispatcher.BeginInvoke(() =>
                    {
                        smsComposeTask.Show();
                    });

                    // Set app navigated to external page
                    Mowbly.AppNavigatedToExternalPage = true;

                    break;

                default:
                    Logger.Error("Feature " + Name + " does not support method " + message.Method);
                    break;
                }
            }
            catch (Exception ce)
            {
                Logger.Error("Exception occured. Reason - " + ce.Message);
            }
            await Task.FromResult(0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string callbackId = message.CallbackId;

            switch (message.Method)
            {
            case "getDeviceId":

                InvokeCallbackJavascript(callbackId, new MethodResult {
                    Result = DeviceManager.Instance.DeviceId
                });
                break;

            case "getMemoryStatus":

                Dictionary <string, string> memory = new Dictionary <string, string>();
                double availInternalMemory         = DEFAULT_MEMORY_VALUE;
                double applicationMemory           = DEFAULT_MEMORY_VALUE;
                try
                {
                    using (IsolatedStorageFile Storage = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        //Available memory in the internal storage.
                        availInternalMemory = Math.Round((double)Storage.AvailableFreeSpace / (1024 * 1024), 2);

                        //memory used by application
                        applicationMemory = Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage;
                        applicationMemory = Math.Round((double)applicationMemory / (1024 * 1024), 2);

                        // SD card not supported
                        memory.Add(KEY_AVAILABLE_MEMORY, availInternalMemory.ToString("#.00MB"));
                        memory.Add(KEY_TOTAL_MEMORY, Constants.STRING_UNAVAILABLE);
                        memory.Add(KEY_AVAILABLE_EXTERNAL_MEMORY, Constants.STRING_UNAVAILABLE);
                        memory.Add(KEY_TOTAL_EXTERNAL_MEMORY, Constants.STRING_UNAVAILABLE);
                        memory.Add(KEY_APPLICATION_MEMORY, applicationMemory.ToString("#.00MB"));
                    }
                }
                catch
                {
                    memory.Add(KEY_AVAILABLE_MEMORY, availInternalMemory.ToString("#.00MB"));
                    memory.Add(KEY_TOTAL_MEMORY, Constants.STRING_UNAVAILABLE);
                    memory.Add(KEY_AVAILABLE_EXTERNAL_MEMORY, Constants.STRING_UNAVAILABLE);
                    memory.Add(KEY_TOTAL_EXTERNAL_MEMORY, Constants.STRING_UNAVAILABLE);
                    memory.Add(KEY_APPLICATION_MEMORY, applicationMemory.ToString("#.00MB"));
                }
                InvokeCallbackJavascript(callbackId, new MethodResult {
                    Result = memory
                });
                break;

            default:
                Logger.Error("Feature " + Name + " does not support method " + message.Method);
                break;
            }
            await Task.FromResult(0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string callbackId = message.CallbackId;

            switch (message.Method)
            {
            case "request":
                try
                {
                    // Read args
                    HttpOptions options =
                        JsonConvert.DeserializeObject <HttpOptions>(message.Args[0].ToString());

                    // Check network available
                    if (NetworkInterface.GetIsNetworkAvailable())
                    {
                        await Request(options, callbackId);
                    }
                    else
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code  = MethodResult.FAILURE_CODE,
                            Error = new MethodError
                            {
                                Message = Mowbly.GetString(Constants.STRING_NO_CONNECTIVITY)
                            }
                        });
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("Error in Http request. Reason - " + e.Message);
                    InvokeCallbackJavascript(callbackId, new MethodResult
                    {
                        Code  = MethodResult.FAILURE_CODE,
                        Error = new MethodError
                        {
                            Message = e.Message
                        }
                    });
                }

                break;

            default:
                Logger.Error("Feature " + Name + " does not support method " + message.Method);
                break;
            }
        }
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            switch (message.Method)
            {
            case "commit":
                string gPreferences = message.Args[0] as string;
                SetGlobalPreferences(gPreferences);
                break;

            default:
                Logger.Error("Feature " + Name + " does not support method " + message.Method);
                break;
            }
            await Task.FromResult(0);
        }
        /// <summary>
        /// Invokes the native method call based on the parameters in the specified
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage ">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage ">JSMessage</see> object
        /// </param>
        /// <returns><see cref="System.Threading.Tasks.Task">Task</see></returns>
        internal async Task InvokeAsync(JSMessage message)
        {
            Feature f = GetFeature(message.Feature);

            if (f != null)
            {
                await Task.Run(() =>
                {
                    f.InvokeAsync(message);
                });
            }
            else
            {
                Logger.Error("Feature " + message.Feature + " not available.");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string callbackId = message.CallbackId;

            switch (message.Method)
            {
            case "getCurrentPosition":

                LocationOptions options =
                    JsonConvert.DeserializeObject <LocationOptions>(
                        message.Args[message.Args.Length - 1].ToString());

                // Configure Geolocator
                Geolocator geolocator = new Geolocator();
                if (options.Accuracy)
                {
                    geolocator.DesiredAccuracy   = PositionAccuracy.High;
                    geolocator.MovementThreshold = 100;
                }
                else
                {
                    geolocator.MovementThreshold = 1000;
                }

                // Request for position
                Geoposition position = await geolocator.GetGeopositionAsync(
                    new TimeSpan(0, 0, 0, 50),
                    timeout : TimeSpan.FromMilliseconds(options.Timeout));

                Geocoordinate coordinate = position.Coordinate;

                // Send result to JS layer
                InvokeCallbackJavascript(message.CallbackId, new MethodResult
                {
                    Result = GeocoordinateToMowblyCoordinate(coordinate)
                });

                break;

            default:
                Logger.Error("Feature " + Name + " does not support method " + message.Method);
                break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            switch (message.Method)
            {
            case "log":
                string logMessage = message.Args[0] as string;
                string logTag     = message.Args[1] as string;
                long   severity   = (long)message.Args[2];
                Logger logger     =
                    LoggerManager.Instance.GetLogger(LoggerManager.TYPE_USER_LOGGER);
                switch (severity)
                {
                case (long)LogPriority.Log_Priority.Debug:
                    logger.Debug(logTag, logMessage);
                    break;

                case (long)LogPriority.Log_Priority.Info:
                    logger.Info(logTag, logMessage);
                    break;

                case (long)LogPriority.Log_Priority.Warn:
                    logger.Warn(logTag, logMessage);
                    break;

                case (long)LogPriority.Log_Priority.Error:
                    logger.Error(logTag, logMessage);
                    break;

                case (long)LogPriority.Log_Priority.Fatal:
                    logger.Fatal(logTag, logMessage);
                    break;

                default:
                    break;
                }

                break;

            default:
                Logger.Error("Feature " + Name + " does not support method " + message.Method);
                break;
            }
            await Task.FromResult(0);
        }
Exemplo n.º 8
0
 internal async override void InvokeAsync(JSMessage message)
 {
     switch (message.Method)
     {
     case "showAsGallery":
         object             GalleryDetails = JsonConvert.DeserializeObject(message.Args[0].ToString());
         ImageGalleryViewer gallery        = new ImageGalleryViewer(GalleryDetails);
         UiDispatcher.BeginInvoke(() =>
         {
             try
             {
                 gallery.launchGallery();
             }
             catch (Exception e)
             {
                 Logger.Error(e.Message);
             }
         });
         break;
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string callbackId = message.CallbackId;

            try
            {
                // Variables
                SqliteConnection connection;
                DBConfig         dbConfig;
                DbTransaction    transaction;
                string           connectionId, query, queryId;
                long             dbSize;
                JObject          o;

                switch (message.Method)
                {
                case "openDatabase":

                    string    dbName     = message.Args[0] as string;
                    Int64     dblevel    = (Int64)message.Args[1];
                    FileLevel level      = (FileLevel)dblevel;
                    Int64     version    = (Int64)message.Args[2];
                    float     dbVersion  = (float)version;
                    string    dbPassword = message.Args[3] as string;
                    string    dbPath     = null;
                    if (dbName.Equals(Mowbly.GetProperty <string>(Constants.PROPERTY_LOGS_DB)))
                    {
                        dbPath = Mowbly.LogDatabaseFile;
                        if (!FileManager.FileExists(dbPath))
                        {
                            FileManager.CreateFile(dbPath);
                        }
                    }
                    else
                    {
                        dbPath = FileManager.GetAbsolutePath(new FilePath
                        {
                            Path        = Path.Combine(Constants.DIR_DB, String.Concat(dbName, dbVersion.ToString())),
                            Level       = level,
                            StorageType = StorageType.Internal
                        });
                    }

                    dbSize = FileManager.GetFileSize(dbPath);

                    // Create new connection
                    try
                    {
                        connection = new SqliteConnection();
                        connection.ConnectionString = DBUtils.GetConnectionString(dbPath, dbPassword);
                        connection.Open();
                        connectionId = Guid.NewGuid().ToString();
                        dbConfigDict.Add(connectionId, new DBConfig
                        {
                            DBName     = dbName,
                            DBVersion  = dbVersion,
                            DBPath     = dbPath,
                            DBPassword = dbPassword,
                            Connection = connection
                        });

                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = connectionId
                        });
                    }
                    catch (SqliteException se)
                    {
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_OPEN_ERROR), se.Message);
                        Logger.Error(error);
                        JToken  opt = message.Args[0] as JToken;
                        string  Id  = opt["queryId"].ToObject <string>();
                        JObject obj = new JObject();
                        obj.Add("queryId", Id);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = obj,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "executeQuery":

                    // Get connection id
                    JToken options = message.Args[0] as JToken;
                    connectionId = options["id"].ToObject <string>();
                    dbConfig     = dbConfigDict[connectionId];

                    // Read args
                    queryId = options["queryId"].ToObject <string>();
                    query   = options["sql"].ToObject <string>().Trim();
                    List <object> queryParams = options["params"].ToObject <List <object> >();

                    // Execute query
                    try
                    {
                        JArray data         = null;
                        int    rowsAffected = 0;
                        connection = dbConfig.Connection;

                        // Throw exception is connection is null
                        if (connection == null)
                        {
                            throw new ArgumentException(Mowbly.GetString(Constants.STRING_DATABASE_NO_CONNECTION_OPEN_ERROR));
                        }

                        // Execute query
                        if (query.ToLower().StartsWith("select"))
                        {
                            data = ProcessSelectQuery(ref connection, query, queryParams);
                        }
                        else
                        {
                            rowsAffected = ProcessNonQuery(ref connection, query, queryParams);
                        }

                        // Create result
                        o = new JObject();
                        o.Add("queryId", queryId);

                        JObject d = new JObject();
                        d.Add("rowsAffected", rowsAffected);
                        d.Add("insertId", connection.LastInsertRowId);
                        d.Add("rows", data);
                        o.Add("data", d);

                        // Notify JS
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = o
                        });
                    }
                    catch (SqliteException se)
                    {
                        // Error
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_QUERY_ERROR), se.Message);
                        Logger.Error(error);

                        // Create result
                        o = new JObject();
                        o.Add("queryId", queryId);

                        // Notify Js
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = o,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "beginTransaction":

                    connectionId = message.Args[0] as string;
                    dbConfig     = dbConfigDict[connectionId];

                    // Begin transaction
                    try
                    {
                        connection = dbConfig.Connection;
                        // Throw exception is connection is null
                        if (connection == null)
                        {
                            throw new ArgumentException(Mowbly.GetString(Constants.STRING_DATABASE_NO_CONNECTION_OPEN_ERROR));
                        }

                        transaction          = connection.BeginTransaction();
                        dbConfig.Transaction = transaction;

                        // Notify JS
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (SqliteException se)
                    {
                        // Error; Notify JS
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_TRANSACTION_ERROR), se.Message);
                        Logger.Error(error);
                        JToken  opt = message.Args[0] as JToken;
                        string  Id  = opt["queryId"].ToObject <string>();
                        JObject obj = new JObject();
                        obj.Add("queryId", Id);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = obj,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "commit":

                    connectionId = message.Args[0] as string;
                    dbConfig     = dbConfigDict[connectionId];

                    // Commit transaction
                    try
                    {
                        transaction = dbConfig.Transaction;
                        // Throw exception is transaction is null
                        if (transaction == null)
                        {
                            throw new ArgumentException(Mowbly.GetString(Constants.STRING_DATABASE_NO_TRANSACTION_ACTIVE_ERROR));
                        }
                        transaction.Commit();

                        queryId      = message.Args[1] as string;
                        o            = new JObject();
                        o["queryId"] = queryId;
                        o["data"]    = true;

                        // Notify JS
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = o
                        });
                    }
                    catch (SqliteException se)
                    {
                        // Error; Notify JS
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_TRANSACTION_ERROR), se.Message);
                        Logger.Error(error);
                        JToken  opt = message.Args[0] as JToken;
                        string  Id  = opt["queryId"].ToObject <string>();
                        JObject obj = new JObject();
                        obj.Add("queryId", Id);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = obj,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "rollback":

                    connectionId = message.Args[0] as string;
                    dbConfig     = dbConfigDict[connectionId];

                    // Commit transaction
                    try
                    {
                        transaction = dbConfig.Transaction;
                        transaction.Rollback();

                        queryId      = message.Args[1] as string;
                        o            = new JObject();
                        o["queryId"] = queryId;
                        o["data"]    = true;

                        // Notify JS
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = o
                        });
                    }
                    catch (SqliteException se)
                    {
                        // Error; Notify JS
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_TRANSACTION_ERROR), se.Message);
                        Logger.Error(error);
                        JToken  opt = message.Args[0] as JToken;
                        string  Id  = opt["queryId"].ToObject <string>();
                        JObject obj = new JObject();
                        obj.Add("queryId", Id);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = obj,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                default:
                    Logger.Error("Feature " + Name + " does not support method " + message.Method);
                    break;
                }
            }
            catch (Exception e)
            {
                // Error; Notify JS
                string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_OPERATION_ERROR), e.Message);
                Logger.Error(error);
                JToken  opt = message.Args[0] as JToken;
                string  Id  = opt["queryId"].ToObject <string>();
                JObject obj = new JObject();
                obj.Add("queryId", Id);
                InvokeCallbackJavascript(callbackId, new MethodResult
                {
                    Code   = MethodResult.FAILURE_CODE,
                    Result = obj,
                    Error  = new MethodError
                    {
                        Message = error
                    }
                });
            }
            await Task.FromResult(0);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            UiDispatcher.BeginInvoke(() =>
            {
                switch (message.Method)
                {
                case "alert":

                    if (activeControl == UiControl.None)
                    {
                        // Read args
                        string alertOptionsStr = message.Args[0] as string;
                        JObject alertOptions   = JObject.Parse(alertOptionsStr);
                        string alertTitle      = (string)alertOptions[KEY_TITLE];
                        string alertMsg        = (string)alertOptions[KEY_MESSAGE];
                        string alertCallbackId = (string)alertOptions[KEY_CALLBACK_ID];

                        // Create alert prompt
                        MessagePrompt alertPrompt = new MessagePrompt();
                        alertPrompt.Title         = alertTitle;
                        alertPrompt.Message       = alertMsg;

                        // Subscribe to OnCompleted event
                        EventHandler <PopUpEventArgs <string, PopUpResult> > onAlertPromptCompleted = null;
                        onAlertPromptCompleted = (sender, e) =>
                        {
                            // Set active control none
                            if (activeControl != UiControl.Progress)
                            {
                                activeControl = UiControl.None;
                            }
                            prompt = null;

                            UiDispatcher.BeginInvoke(() =>
                            {
                                // Notify JS layer
                                InvokeCallbackJavascript(alertCallbackId, new MethodResult());

                                // Unsubscrivbe from OnCompleted event
                                alertPrompt.Completed -= onAlertPromptCompleted;
                            });
                        };
                        alertPrompt.Completed += onAlertPromptCompleted;

                        // Show the alert prompt
                        alertPrompt.Show();

                        // Set active control
                        activeControl = UiControl.Alert;
                        prompt        = alertPrompt;
                    }
                    break;

                case "confirm":

                    if (activeControl == UiControl.None)
                    {
                        // Read args
                        string confirmOptionsStr = message.Args[0] as string;
                        JObject confirmOptions   = JObject.Parse(confirmOptionsStr);
                        List <Dictionary <string, string> > confirmButtons =
                            confirmOptions["buttons"].ToObject <List <Dictionary <string, string> > >();
                        if (confirmButtons.Count >= 2)
                        {
                            string confirmTitle      = (string)confirmOptions[KEY_TITLE];
                            string confirmMsg        = (string)confirmOptions[KEY_MESSAGE];
                            string confirmCallbackId = (string)confirmOptions[KEY_CALLBACK_ID];

                            // Create confirm prompt
                            MessagePrompt confirmPrompt   = new MessagePrompt();
                            confirmPrompt.Title           = confirmTitle;
                            confirmPrompt.Message         = confirmMsg;
                            confirmPrompt.IsCancelVisible = true;

                            // Subscribe to OnCompleted event
                            // Required if the user cancels the confirm dialog using device back key press
                            EventHandler <PopUpEventArgs <string, PopUpResult> > onConfirmPromptCompleted = null;
                            onConfirmPromptCompleted = (sender, e) =>
                            {
                                // Set active control none
                                activeControl = UiControl.None;
                                prompt        = null;

                                UiDispatcher.BeginInvoke(() =>
                                {
                                    // Notify JS layer
                                    InvokeCallbackJavascript(confirmCallbackId, -1);

                                    // Unsubscribe from OnCompleted event
                                    confirmPrompt.Completed -= onConfirmPromptCompleted;
                                });
                            };
                            confirmPrompt.Completed += onConfirmPromptCompleted;

                            // Function to return the button click handler encapsulating the index of the button
                            Func <int, RoutedEventHandler> GetButtonClickHandler = (btnIndex) =>
                            {
                                return(new RoutedEventHandler((o, args) =>
                                {
                                    // Unsubscribe from OnCompleted event
                                    // Not required as JS layer will be notified from here
                                    confirmPrompt.Completed -= onConfirmPromptCompleted;

                                    // Notify JS layer
                                    InvokeCallbackJavascript(confirmCallbackId, btnIndex);

                                    // Hide the confirm prompt
                                    confirmPrompt.Hide();

                                    // Set active control none
                                    activeControl = UiControl.None;
                                    prompt = null;
                                }));
                            };

                            // Remove the default buttons
                            confirmPrompt.ActionPopUpButtons.Clear();

                            // Create confirm buttons and add it to confirm prompt
                            int index = 0;
                            foreach (Dictionary <string, string> buttonDict in confirmButtons)
                            {
                                Button button = new Button {
                                    Content = buttonDict["label"]
                                };
                                button.Click += GetButtonClickHandler(index);
                                confirmPrompt.ActionPopUpButtons.Add(button);
                                index++;
                            }

                            // Show the alert prompt
                            confirmPrompt.Show();

                            // Set active control
                            activeControl = UiControl.Confirm;
                            prompt        = confirmPrompt;
                        }
                    }
                    break;

                case "hideProgress":

                    if (activeControl == UiControl.Progress)
                    {
                        CloudPact.MowblyFramework.Core.Controls.ProgressOverlay.Instance.Hide();

                        // Set active control none
                        activeControl = UiControl.None;
                    }
                    break;

                case "showProgress":

                    if (activeControl != UiControl.Progress)
                    {
                        string progressMsg = message.Args[1] as string;
                        CloudPact.MowblyFramework.Core.Controls.ProgressOverlay.Instance.Show(progressMsg);

                        // Set active control
                        activeControl = UiControl.Progress;
                    }
                    break;

                case "toast":

                    if (activeControl == UiControl.None)
                    {
                        string toastMsg = message.Args[0] as string;
                        int duration    = DURATION_TOAST_LONG;
                        if (message.Args.Length > 1)
                        {
                            duration = Convert.ToInt32(message.Args[1]);
                            duration = (duration == 0) ? DURATION_TOAST_SHORT :
                                       DURATION_TOAST_LONG;
                        }
                        ToastPrompt toastPrompt = new ToastPrompt
                        {
                            Message = toastMsg,
                            MillisecondsUntilHidden = duration
                        };
                        toastPrompt.Show();
                    }
                    break;

                default:
                    Logger.Error("Feature " + Name + " does not support method " + message.Method);
                    break;
                }
            });
            await Task.FromResult(0);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string callbackId = message.CallbackId;

            switch (message.Method)
            {
            case "getActiveNetwork":
                Tuple <NetworkType, string> activeNetwork = GetActiveNetwork();
                InvokeCallbackJavascript(callbackId, new MethodResult
                {
                    Code   = (int)activeNetwork.Item1,
                    Result = activeNetwork.Item2
                });
                break;

            case "isHostReachable":
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    string url     = message.Args[0] as string;
                    long   timeout = (long)message.Args[1];
                    try
                    {
                        using (HttpClient httpClient = new HttpClient())
                        {
                            httpClient.Timeout = TimeSpan.FromMilliseconds(timeout);
                            HttpResponseMessage response = await httpClient.GetAsync(new Uri(url));

                            int code = MethodResult.SUCCESS_CODE;
                            if (response.StatusCode != HttpStatusCode.OK)
                            {
                                code = MethodResult.FAILURE_CODE;
                            }
                            InvokeCallbackJavascript(callbackId, new MethodResult
                            {
                                Code   = code,
                                Result = (response.StatusCode != HttpStatusCode.NotFound)
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Error checking reachability of host. Reason - " + e.Message);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code  = MethodResult.FAILURE_CODE,
                            Error = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                }
                else
                {
                    string error = Mowbly.GetString(Constants.STRING_NO_CONNECTIVITY);
                    InvokeCallbackJavascript(callbackId, new MethodResult
                    {
                        Code  = MethodResult.FAILURE_CODE,
                        Error = new MethodError
                        {
                            Message = error
                        }
                    });
                }
                break;

            default:
                Logger.Error("Feature " + Name + " does not support method " + message.Method);
                break;
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Invokes the method specified in the
 /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage ">JSMessage</see> object.
 /// Will be overridden by the feature classes.
 /// </summary>
 /// <param name="message">
 /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage ">JSMessage</see> object
 /// </param>
 internal virtual async void InvokeAsync(JSMessage message)
 {
     await Task.FromResult(0);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string callbackId = message.CallbackId;

            FilePath options =
                JsonConvert.DeserializeObject <FilePath>(message.Args[message.Args.Length - 1].ToString());

            // Set the file path in FilePath options
            // Normal file operations get path as first parameter and options as second
            // Unzip method receives a file object with path in it already.
            if (!message.Method.Equals("unzip"))
            {
                options.Path = message.Args[0] as string;
            }


            string path;

            try
            {
                switch (message.Method)
                {
                case "deleteDirectory":
                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options, false);

                    // Delete directory
                    try
                    {
                        FileManager.DeleteDirectory(path);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                case "deleteFile":

                    // Get the absolute path
                    //Open : Ask
                    path = FileManager.GetAbsolutePath(options, false);

                    // Delete file
                    try
                    {
                        FileManager.DeleteFile(path);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                case "getDirectory":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options);

                    // Create directory
                    try
                    {
                        FileManager.CreateDirectory(path);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                case "getFile":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options);

                    // Create file
                    try
                    {
                        FileManager.CreateFile(path);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                case "getFilesJSONString":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options, false);

                    // Get files list
                    Tuple <bool, List <Dictionary <string, object> >, string> getFilesResult =
                        await FileManager.GetFoldersAndFilesAsync(path, options.StorageType);

                    if (getFilesResult.Item1)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Result = getFilesResult.Item2
                        });
                    }
                    else
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = getFilesResult.Item3
                            }
                        });
                    }
                    break;

                case "getRootDirectory":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options, false);

                    // Return root directory
                    InvokeCallbackJavascript(callbackId, new MethodResult {
                        Result = path
                    });
                    break;

                case "read":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options, false);

                    // Read file
                    try
                    {
                        string fileContentStr = FileManager.ReadAsString(path);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = fileContentStr
                        });
                    }
                    catch (Exception e)
                    {
                        Logger.Error("File not found" + e.Message);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = Mowbly.GetString(Constants.STRING_FILE_NOT_FOUND)
                            }
                        });
                    }
                    break;

                case "readData":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options, false);

                    // Read file
                    try
                    {
                        string fileContentData = Convert.ToBase64String(FileManager.ReadAsBytes(path));
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = fileContentData
                        });
                    }
                    catch (Exception e)
                    {
                        Logger.Error("File not found" + e.Message);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = Mowbly.GetString(Constants.STRING_FILE_NOT_FOUND)
                            }
                        });
                    }
                    break;

                case "testDirExists":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options, false);

                    // Test dir exists
                    try
                    {
                        bool isDirExists = FileManager.DirectoryExists(path);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = isDirExists
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                case "testFileExists":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options, false);

                    // Test file exists
                    try
                    {
                        bool isFileExists = FileManager.FileExists(path);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = isFileExists
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                case "unzip":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options, false);

                    // Source file
                    FilePath srcFileOptions = JsonConvert.DeserializeObject <FilePath>(message.Args[0].ToString());
                    string   srcFilePath    = FileManager.GetAbsolutePath(srcFileOptions, false);

                    if (!FileManager.FileExists(srcFilePath))
                    {
                        throw new Exception(Mowbly.GetString(Constants.STRING_FILE_NOT_FOUND));
                    }

                    // Unzip
                    try
                    {
                        FileManager.unzip(srcFilePath, path);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                case "write":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options);

                    // Write content to file
                    try
                    {
                        string fileContentStr      = message.Args[1] as string;
                        bool   shouldAppendContent = (bool)message.Args[2];
                        FileManager.WriteStringToFile(path, fileContentStr, shouldAppendContent);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                case "writeData":

                    // Get the absolute path
                    path = FileManager.GetAbsolutePath(options);

                    // Write content to file
                    try
                    {
                        byte[] fileContentBytes    = Convert.FromBase64String(message.Args[0] as string);
                        bool   shouldAppendContent = (bool)message.Args[1];
                        FileManager.WriteDataToFile(path, fileContentBytes, shouldAppendContent);
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = false,
                            Error  = new MethodError
                            {
                                Message = e.Message
                            }
                        });
                    }
                    break;

                default:
                    Logger.Error("Feature " + Name + " does not support method " + message.Method);
                    break;
                }
            }
            catch (Exception ce)
            {
                Logger.Error("Exception occured. Reason - " + ce.Message);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            switch (message.Method)
            {
            case "getPicture":
                int           source  = Convert.ToInt32(message.Args[0]);
                CameraOptions options =
                    JsonConvert.DeserializeObject <CameraOptions>(message.Args[1].ToString());
                string callbackId = message.CallbackId;
                try
                {
                    if (source == (int)Camera.Source.CAMERA)
                    {
                        FilePath filePath         = options.FilePath;
                        bool     isWriteToGallery = (filePath == null);
                    }

                    // Create the CameraTask
                    CameraTask cameraTask;
                    if (source == (int)Camera.Source.CAMERA)
                    {
                        Logger.Debug("Launching camera...");
                        cameraTask = new MowblyCameraCaptureTask(callbackId, options);
                    }
                    else
                    {
                        Logger.Debug("Launching photo chooser...");
                        cameraTask = new MowblyPhotoChooserTask(callbackId, options);
                    }

                    // Subscribe to CameraTask Completed event
                    cameraTask.Completed += OnCameraTaskCompleted;

                    // Show the CameraTask
                    UiDispatcher.BeginInvoke(() =>
                    {
                        cameraTask.Show();
                    });

                    // Make a note that app is navigated to external task
                    Mowbly.AppNavigatedToExternalPage = true;
                }
                catch (Exception ce)
                {
                    Logger.Error("Exception has occured. Reason - " + ce.Message);
                }

                break;

            case "getConfiguration":
                List <CameraConfig> cameraConfigList = await GetCameraConfigurations();

                MethodResult result = cameraConfigList.Count > 0 ?
                                      new MethodResult
                {
                    Result = cameraConfigList
                } :
                new MethodResult
                {
                    Code  = MethodResult.FAILURE_CODE,
                    Error = new MethodError
                    {
                        Message = Mowbly.GetString(Constants.STRING_CAMERA_INITIALIZATION_ERROR)
                    }
                };
                InvokeCallbackJavascript(message.CallbackId, result);
                break;

            default:
                Logger.Error("Feature " + Name + " does not support method " + message.Method);
                break;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string        callbackId = message.CallbackId;
            List <string> properties = null;

            try
            {
                switch (message.Method)
                {
                case "callContact":

                    Logger.Info("Calling contact...");

                    // Get the phone number
                    string phonenumber = message.Args[0] as string;

                    // Create and show the PhoneCall task
                    PhoneCallTask phoneCallTask = new PhoneCallTask();
                    phoneCallTask.PhoneNumber = phonenumber;
                    UiDispatcher.BeginInvoke(() =>
                    {
                        phoneCallTask.Show();
                    });

                    // Set app navigated to external page
                    Mowbly.AppNavigatedToExternalPage = true;
                    break;

                case "deleteContact":

                    Logger.Info("Deleting contact...");

                    string contactId = message.Args[0] as string;

                    try
                    {
                        ContactStore contactStore = await ContactStore.CreateOrOpenAsync(
                            ContactStoreSystemAccessMode.ReadWrite,
                            ContactStoreApplicationAccessMode.ReadOnly);

                        await contactStore.DeleteContactAsync(contactId);

                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        string error = String.Concat(
                            Mowbly.GetString(Constants.STRING_CONTACT_DELETE_ERROR),
                            e.Message);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code  = MethodResult.FAILURE_CODE,
                            Error = new MethodError
                            {
                                Message = error
                            }
                        });
                    }
                    break;

                case "findContact":

                    // Read args
                    string filter  = message.Args[0] as string;
                    JToken options = message.Args[1] as JToken;
                    properties = options["properties"].ToObject <List <string> >();
                    double limit = (double)options["limit"];

                    Logger.Info("Searching contacts for " + filter);

                    // Contacts search results handler
                    EventHandler <MowblyContactsSearchEventArgs> OnContactsSearchCompleted = null;
                    OnContactsSearchCompleted = (sender, e) =>
                    {
                        if (e.Status)
                        {
                            // Notify result to JS
                            InvokeCallbackJavascript(message.CallbackId, new MethodResult {
                                Result = e.W3Contacts
                            });
                        }
                        else
                        {
                            InvokeCallbackJavascript(message.CallbackId, new MethodResult {
                                Result = null
                            });
                        }
                    };

                    if (Regex.IsMatch(filter, @"^[0-9()-]+$"))
                    {
                        // Only numbers, search by phone number
                        SearchContactInUserDataAsync(filter, OnContactsSearchCompleted, true, FilterKind.PhoneNumber, limit, properties);
                    }
                    else
                    {
                        // Search by display name
                        SearchContactInUserDataAsync(filter, OnContactsSearchCompleted, true, FilterKind.DisplayName, limit, properties);
                    }
                    break;

                case "pickContact":


                    properties = ((JToken)message.Args[0]).ToObject <List <string> >();
                    ContactChooserTask contactChooserTask = new ContactChooserTask(callbackId);
                    EventHandler <ContactChooserTaskEventArgs> OnContactChooserTaskCompleted = null;
                    OnContactChooserTaskCompleted = (sender, e) =>
                    {
                        // Unsubscribe
                        contactChooserTask.OnCompleted -= OnContactChooserTaskCompleted;

                        // Notify result to JS
                        if (e.Contact != null)
                        {
                            W3Contact contact = new W3Contact(e.Contact, properties);
                            InvokeCallbackJavascript(e.CallbackId, new MethodResult {
                                Result = contact
                            });
                        }
                        else
                        {
                            InvokeCallbackJavascript(e.CallbackId, new MethodResult
                            {
                                Code  = MethodResult.FAILURE_CODE,
                                Error = new MethodError
                                {
                                    Message = Mowbly.GetString(Constants.STRING_ACTIVITY_CANCELLED)
                                }
                            });
                        }
                    };

                    // Subscribe to OnCompleted event
                    contactChooserTask.OnCompleted += OnContactChooserTaskCompleted;

                    // Show contact chooser task
                    UiDispatcher.BeginInvoke(() =>
                    {
                        try
                        {
                            contactChooserTask.Show();
                        }
                        catch (Exception e)
                        {
                            // Might fail at times since navigation is not allowed when task is not in foreground
                            string error = String.Concat(Mowbly.GetString(Constants.STRING_CONTACT_CHOOSE_FAILED), e.Message);
                            Logger.Error(error);
                            InvokeCallbackJavascript(callbackId, new MethodResult
                            {
                                Code  = MethodResult.FAILURE_CODE,
                                Error = new MethodError
                                {
                                    Message = error
                                }
                            });
                        }
                    });
                    break;

                case "saveContact":

                    try
                    {
                        // Create W3Contact object from JS contact
                        W3Contact w3Contact       = JsonConvert.DeserializeObject <W3Contact>(message.Args[0].ToString());
                        string    storedContactId = await w3Contact.SaveToNativeContactStore();

                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Result = storedContactId
                        });
                    }
                    catch (Exception e)
                    {
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_CONTACT_SAVE_FAILED), e.Message);
                        Logger.Error(error);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code  = MethodResult.FAILURE_CODE,
                            Error = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "viewContact":

                    // Get the param and type
                    string id = message.Args[0] as string;
                    Tuple <string, string> paramAndType = await GetSearchParamAndType(id);

                    if (paramAndType != null)
                    {
                        string            param             = paramAndType.Item1;
                        string            type              = paramAndType.Item2;
                        ContactViewerTask contactViewerTask = new ContactViewerTask(param, type);

                        // Show contact viewer task
                        UiDispatcher.BeginInvoke(() =>
                        {
                            try
                            {
                                contactViewerTask.Show();
                            }
                            catch (Exception e)
                            {
                                // Might fail at times since navigation is not allowed when task is not in foreground
                                string error = String.Concat(Mowbly.GetString(Constants.STRING_CONTACT_VIEW_FAILED), e.Message);
                                Logger.Error(error);
                                InvokeCallbackJavascript(callbackId, new MethodResult
                                {
                                    Code  = MethodResult.FAILURE_CODE,
                                    Error = new MethodError
                                    {
                                        Message = error
                                    }
                                });
                            }
                        });
                    }
                    else
                    {
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_CONTACT_VIEW_FAILED),
                                                     Mowbly.GetString(Constants.STRING_CONTACT_NOT_FOUND));
                        Logger.Error(error);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code  = MethodResult.FAILURE_CODE,
                            Error = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                default:
                    Logger.Error("Feature " + Name + " does not support method " + message.Method);
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error("Exception occured. Reason - " + e.Message);
            }
        }