コード例 #1
0
        static async Task <List <Action> > GetActions()
        {
            return(await Task.Run(async() =>
            {
                var list = new List <Action>();
                var parameters = new Dictionary <string, string> {
                    { "pheidiaction", "complexAction" }, { "pheidiparams", "action**:**GetIpheidiActions**,**" }
                };
                HttpResponseMessage response = await PheidiNetworkManager.SendHttpRequestAsync(parameters, new TimeSpan(0, 0, 30));
                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string responseContent = response.Content.ReadAsStringAsync().Result;
                        Debug.WriteLine("Reponse:" + responseContent);
                        try
                        {
                            List <Dictionary <string, object> > fields = PheidiNetworkManager.GetFields(responseContent);
                            foreach (var f in fields)
                            {
                                var action = new Action()
                                {
                                    NoSeq = f["ACO_A_NoSeq"].ToString(),
                                    Name = f["ACO_A_Action"].ToString(),
                                    Category = f["Category"].ToString(),
                                    Description = f["SousCategory"].ToString()
                                };
                                list.Add(action);
                            }

                            list.OrderBy((arg) => arg.Category).ThenBy((arg) => arg.Description);
                        }
                        catch
                        {
                            var answer = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseContent);
                            if (answer["STATUS"] == "Good")
                            {
                                if (answer.ContainsKey("VALUE"))
                                {
                                    try
                                    {
                                        list = JsonConvert.DeserializeObject <List <Action> >(answer["VALUE"]);
                                        Debug.WriteLine("List Generated");
                                    }
                                    catch (Exception e)
                                    {
                                        Debug.WriteLine(e.Message);
                                    }
                                }
                            }
                        }
                    }
                }
                return list;
            }));
        }
コード例 #2
0
        public static void RunActionAnswer(Action action)
        {
            try
            {
                var fields = PheidiNetworkManager.GetFields(action.ActionAnswer);
                if (fields != null)
                {
                    foreach (var f in fields)
                    {
                        var field = f as Dictionary <string, object>;
                        if (field != null)
                        {
                            if (field.ContainsKey("autoClick"))
                            {
                                var    autoClick = field["autoClick"] as string;
                                string script    = "AutoClick(" + autoClick + ",0,0);";

                                BrowserPage.InsertJavscript(script);
                            }

                            if (field.ContainsKey("message" + App.Language.ToUpper()))
                            {
                                string lang        = App.Language.ToUpper();
                                string message     = field["message" + lang] as string;
                                string title       = "Pheidi";
                                string textConfirm = "Ok";
                                string textCancel  = "Cancel";
                                foreach (var key in field.Keys)
                                {
                                    if (key == "bCancel" + lang)
                                    {
                                        textCancel = field["bCancel" + lang] as string;
                                    }

                                    else if (key == "bConfirm" + lang)
                                    {
                                        textConfirm = field["bConfirm" + lang] as string;
                                    }

                                    else if (key == "title" + lang)
                                    {
                                        title = field["title" + lang] as string;
                                    }
                                }

                                if (App.IsInBackground)
                                {
                                    Debug.WriteLine("ActionManger - RunActionAnswer - SendNotification");
                                    App.NotificationManager.SendNotification(message, title, "nearby_square", action);
                                }
                                else
                                {
                                    Debug.WriteLine("ActionManger - RunActionAnswer - DisplayAlert");
                                    System.Action confirm = () => { };
                                    confirm = () =>
                                    {
                                        action.Event = "onConfirm";
                                        ExecuteAction(action);
                                    };


                                    System.Action cancel = () =>
                                    {
                                        action.Event = "onCancel";
                                        ExecuteAction(action);
                                    };

                                    if (!string.IsNullOrEmpty(textCancel))
                                    {
                                        App.NotificationManager.DisplayAlert(message, title, textConfirm, textCancel, confirm, cancel);
                                    }
                                    else
                                    {
                                        App.NotificationManager.DisplayAlert(message, title, textConfirm, confirm);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the geofence from server.
        /// </summary>
        /// <returns><c>true</c>, if geofence from server was gotten, <c>false</c> otherwise.</returns>
        public async Task <bool> GetGeofenceUpdateFromServer()
        {
            if (!Application.Current.Properties.ContainsKey("LastGeofenceSync"))
            {
                Application.Current.Properties["LastGeofenceSync"] = "2000-01-01 00:00:00";
            }
            var parameters = new Dictionary <string, string> {
                { "pheidiaction", "complexaction" }, { "pheidiparams", "action**:**GetGeofenceUpdate**,**Last_Update_Date**:**" + Application.Current.Properties["LastGeofenceSync"] + "**,**" }
            };
            HttpResponseMessage response = PheidiNetworkManager.SendHttpRequestAsync(parameters, new TimeSpan(0, 0, 30)).Result;

            if (response != null)
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    string responseContent = response.Content.ReadAsStringAsync().Result;
                    Debug.WriteLine("Reponse:" + responseContent);
                    try
                    {
                        if (Geofences == null)
                        {
                            GetGeofenceFromDatabase();
                        }
                        List <Geofence> list = new List <Geofence>();
                        var             geo  = new Geofence();
                        try
                        {
                            var fields = PheidiNetworkManager.GetFields(responseContent);
                            foreach (var field in fields)
                            {
                                geo = new Geofence();

                                geo.NoSeq = field.ContainsKey("GEO_A_NoSeq") ? field["GEO_A_NoSeq"]?.ToString() : string.Empty;

                                geo.EnterActionName = field.ContainsKey("GAR_ACO_A_Action_EnterAction") ? field["GAR_ACO_A_Action_EnterAction"]?.ToString() : string.Empty;

                                geo.ExitActionName = field.ContainsKey("GAR_ACO_A_Action_ExitAction") ? field["GAR_ACO_A_Action_ExitAction"]?.ToString() : string.Empty;

                                geo.Name = field.ContainsKey("GEO_A_Name") ? field["GEO_A_Name"]?.ToString() : string.Empty;

                                geo.DeleteFlag = field.ContainsKey("GEO_B_DeleteFlag") ? (bool.Parse(field["GEO_B_DeleteFlag"]?.ToString() ?? false.ToString()) ? 1 : 0) : 0;

                                geo.CreationDate = field.ContainsKey("GEO_S_CrDate") ? DateTime.Parse(field["GEO_S_CrDate"]?.ToString()) : DateTime.Now;

                                geo.LastModification = field.ContainsKey("GEO_S_LastModDate") ? DateTime.Parse(field["GEO_S_LastModDate"]?.ToString()) : DateTime.Now;

                                geo.Latitude = field.ContainsKey("GEO_N_Latitude") ? double.Parse(field["GEO_N_Latitude"]?.ToString()) : 0;

                                geo.Longitude = field.ContainsKey("GEO_N_Longitude") ? double.Parse(field["GEO_N_Longitude"]?.ToString()) : 0;

                                geo.NotificationEnabled = field.ContainsKey("GAR_B_NotificationFlag") ? bool.Parse(field["GAR_B_NotificationFlag"]?.ToString() ?? false.ToString()) : true;

                                geo.PublicFlag = field.ContainsKey("GEO_B_PublicFlag") ? bool.Parse(field["GEO_B_PublicFlag"]?.ToString() ?? false.ToString()) ? 1 : 0 : 0;

                                geo.Radius = field.ContainsKey("GEO_N_Radius") ? double.Parse(field["GEO_N_Radius"]?.ToString()) : ApplicationConst.DefaultGeofenceRadius;

                                geo.ServerNoseq = App.ServerInfoNoseq;

                                geo.User = App.UserNoseq;

                                list.Add(geo);
                            }
                            Debug.WriteLine("List Generated");
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("GetGeofenceUpdate - Creating List: " + e.Message);
                        }
                        List <Geofence> toRemove = new List <Geofence>();
                        foreach (var geofence in list)
                        {
                            try
                            {
                                if (Geofences.Any(g => g.NoSeq == geofence.NoSeq))
                                {
                                    //Delete la copie local si celle au serveur à déjà été supprimée.
                                    if (geofence.DeleteFlag == 1)
                                    {
                                        var data = await DatabaseHelper.Database.GetItem <Geofence>(geofence.NoSeq);

                                        await DatabaseHelper.Database.DeleteItemAsync <Geofence>(data);

                                        toRemove.Add(geofence);
                                    }
                                    //Update la copie local pour correspondre à celle du serveur.
                                    else
                                    {
                                        var data = Geofences.First(g => g.NoSeq == geofence.NoSeq);
                                        data.DeleteFlag          = geofence.DeleteFlag;
                                        data.Latitude            = geofence.Latitude;
                                        data.Longitude           = geofence.Longitude;
                                        data.Name                = geofence.Name;
                                        data.Radius              = geofence.Radius;
                                        data.LastModification    = DateTime.Now;
                                        data.EnterActionName     = geofence.EnterActionName;
                                        data.ExitActionName      = geofence.ExitActionName;
                                        data.NotificationEnabled = geofence.NotificationEnabled;
                                        await DatabaseHelper.Database.UpdateItem(data);
                                    }
                                }
                                else
                                {
                                    //Ajoute une nouvelle geofence si la copie locale n'existe pas.
                                    if (geofence.DeleteFlag == 0)
                                    {
                                        await DatabaseHelper.Database.SaveItemAsync(geofence);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine("GetGeofenceUpdate - Updating geofence: " + e.Message);
                            }
                        }
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            foreach (var geofence in toRemove)
                            {
                                try
                                {
                                    Geofences.Remove(Geofences.FirstOrDefault((arg) => arg.NoSeq == geofence.NoSeq));
                                }
                                catch (Exception e)
                                {
                                    Debug.WriteLine("GetGeofenceUpdate - Removing deleted: " + e.Message);
                                }
                            }
                        });

                        Application.Current.Properties["LastGeofenceSync"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        Debug.WriteLine("Geofence: Synch done");
                        await Application.Current.SavePropertiesAsync();

                        return(true);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine("GetGeofenceUpdate: " + e.Message);
                    }
                }
            }
            return(false);
        }