Ejemplo n.º 1
0
        /// <summary>
        /// Ricostruisce le informazioni di accesso al Cloud da una precedente
        /// serializzazione
        /// </summary>
        private void DeSerialize()
        {
            try
            {
                Account = null;
                string       data         = File.ReadAllText(SerializationFileName, Encoding.UTF8);
                EncDecHelper encDecHelper = new EncDecHelper
                {
                    PasswordString = SerializationPassword
                };

                Xamarin.Auth.Account account = Xamarin.Auth.Account.Deserialize(encDecHelper.AESDecrypt(data, out bool warning));
                if (warning)
                {
                    Debug.Write(string.Format("Google Drive serialize file {0}. File seems to be corrupted. I have tried to recover the data.",
                                              SerializationFileName));
                }
                if (account != null)
                {
                    Account    = new OAuthAccountWrapper(account);
                    RememberMe = true;
                }
            }
            catch (FileNotFoundException)
            {
                // Accettabile
                Debug.WriteLine(string.Format("Deserialize: file {0} not found", SerializationFileName));
            }
            catch (Exception Ex)
            {
                Debug.WriteLine("Deserialize error: " + Ex.Message);
            }
        }
Ejemplo n.º 2
0
        public async Task Init(string AppId, Uri url, Func <NotificationInfo, Task <bool> > pushNotificationOpened)
        {
            OneSignalAppId = AppId;
            OneSignalUrl   = url;

            try
            {
                StorageFolder localFolder          = ApplicationData.Current.LocalFolder;
                StorageFile   pushNotificationFile = await localFolder.GetFileAsync("push.notification");

                if (pushNotificationFile != null)
                {
                    string content = await FileIO.ReadTextAsync(pushNotificationFile, Windows.Storage.Streams.UnicodeEncoding.Utf8);

                    if (content.Length > 0)
                    {
                        EncDecHelper encDecHelper = new EncDecHelper
                        {
                            Password = GetDevicePwd()
                        };
                        string decryptedContent = encDecHelper.AESDecrypt(content, out bool warning);
                        if (decryptedContent.Length > 0)
                        {
                            JObject json = JObject.Parse(decryptedContent);
                            PushNotificationToken    = json.Value <string>("token");
                            PushNotificationDeviceID = json.Value <string>("playerid");
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                // Il file non esiste
                PushNotificationToken    = "";
                PushNotificationDeviceID = "";
            }
            catch (Exception ex)
            {
                PushNotificationToken    = "";
                PushNotificationDeviceID = "";
                Debug.WriteLine("Errore durante la lettura del file di configurazione delle notifiche push. Exception: " + ex.Message);
                throw;
            }
        }