예제 #1
0
        public Context()
        {
            try
            {
                var serialization = IsolatedStorage.ReadFromIsolatedStorage("Connections", string.Empty);
                var array         = JsonConvert.DeserializeObject <XbmcConnection[]>(serialization);
                Connections = new ObservableCollection <XbmcConnection>(array);
            }
            catch (Exception)
            {
                Connections = new ObservableCollection <XbmcConnection>();
            }

#if DEBUG
            if (!Connections.Any())
            {
                var cnx = new XbmcConnection
                {
                    IsDefault = true,
                    Xbmc      = new KodiRemote.Core.Connection("123", "80", "xbmc", "")
                };
                Connections.Add(cnx);
            }
#endif
        }
        /// <summary>
        /// The get access token.
        /// </summary>
        /// <param name="authorizationCode">
        /// The web auth result response data.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task GetAccessToken(string authorizationCode)
        {
            var authCode = authorizationCode.Split('=')[1];

            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(Constants.GitterBaseAddress);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("client_id", Constants.ClientKey),
                    new KeyValuePair <string, string>("client_secret", Constants.OauthSecret),
                    new KeyValuePair <string, string>("code", authCode),
                    new KeyValuePair <string, string>("redirect_uri", Constants.RedirectUrl),
                    new KeyValuePair <string, string>("grant_type", "authorization_code")
                });

                var result = await httpClient.PostAsync(Constants.TokenEndpoint, content);

                string     resultContent = result.Content.ReadAsStringAsync().Result;
                JsonObject value         = JsonValue.Parse(resultContent).GetObject();
                string     accessToken   = value.GetNamedString("access_token");

                Debug.WriteLine("Access Token = " + accessToken);

                await IsolatedStorage.SaveToken(string.Format("Bearer {0}", accessToken));
            }

            Frame.Navigate(typeof(RoomsPage));
        }
        /// <summary>
        /// Load the saved favorites from a file in isolated storage.
        /// Perform culture conversion if needed
        /// </summary>
        /// <returns>Deserialized object</returns>
        internal static FavoriteCollection LoadFromFile()
        {
            IsolatedStorage <FavoriteCollection> f = new IsolatedStorage <FavoriteCollection>();
            FavoriteCollection loadedFile          = f.LoadFromFile(FavoriteData.FavoriteFileName);

            if (loadedFile == null)
            {
                loadedFile = new FavoriteCollection();
            }

            /* In the case where the favorites were stored in one language, but we have
             * switched to another language, check to see if the first item category matches
             * the current locale. If it does, then break out. Othewise, convert all of the
             * unit information into the current locale
             */
            foreach (FavoriteData d in loadedFile)
            {
                if (string.Compare(d.Category,
                                   Resources.Strings.ResourceManager.GetString(d.CategoryResource),
                                   StringComparison.OrdinalIgnoreCase) == 0)
                {
                    break;
                }
                d.Category       = Resources.Strings.ResourceManager.GetString(d.CategoryResource);
                d.SourceUnitName = Resources.Strings.ResourceManager.GetString(d.SourceUnitNameResource);
                d.TargetUnitName = Resources.Strings.ResourceManager.GetString(d.TargetUnitNameResource);
                d.LabelName      = string.Format(CultureInfo.CurrentCulture,
                                                 UnitConverter.Resources.Strings.FavoriteItemLabel,
                                                 d.SourceUnitName, d.TargetUnitName);
            }
            return(loadedFile);
        }
예제 #4
0
파일: Cache.cs 프로젝트: Stephen-Y/Apps
 public static void SaveFile(string filename, string contents)
 {
     lock (typeof(Cache))
     {
         IsolatedStorage.WriteAllText(CacheFolder + "/" + filename, contents);
     }
 }
예제 #5
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string url;

            if (NavigationContext.QueryString.TryGetValue("url", out url))
            {
                mediaPlayer.Source = new Uri(url);
            }
            else
            {
                var filename = NavigationContext.QueryString["filename"];
                stateFile = DownloadInfo.GetStateFile(filename);
                mediaPlayer.SetSource(IsolatedStorage.OpenFileToRead(filename));
            }

            // only restore position for downloaded videos
            if (stateFile != null)
            {
                if (!position.HasValue && IsolatedStorage.FileExists(stateFile))
                {
                    position = TimeSpan.FromTicks(long.Parse(IsolatedStorage.ReadAllText(stateFile), CultureInfo.InvariantCulture));
                }
                if (position.HasValue)
                {
                    mediaPlayer.RestoreMediaState(new MediaState
                    {
                        IsPlaying = true,
                        IsStarted = true,
                        Position  = position.Value,
                    });
                }
            }
        }
예제 #6
0
        /// <summary>
        ///     Writes the Blob to Isolated Storage
        /// </summary>
        /// <param name="data"></param>
        public void SetLocalFileBytes(Byte[] data)
        {
            string filePath = IsolatedStorage.GetFileNameTypeFromMediaType(Id, _blobMediaType);

            IsolatedStorage.SaveFile(filePath, data);
            //new MediaLibrary().SavePicture(filePath, data);
        }
예제 #7
0
 public static void SaveObject(this IsolatedStorage isoStorage, object obj, string fileName)
 {
     using (IsolatedStorageFileStream writeStream = new IsolatedStorageFileStream(fileName, FileMode.Create))
     {
         BinaryFormatter formatter = new BinaryFormatter();
         formatter.Serialize(writeStream, obj);
     }
 }
        public void UpdateTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            storage.AddItem("String", "test");
            storage.UpdateItem("String", "test1");

            Assert.AreEqual(storage.GetItem<string>("String"), "test1");
        }
예제 #9
0
        public void UpdateTest()
        {
            IsolatedStorage storage = new IsolatedStorage();

            storage.AddItem("String", "test");
            storage.UpdateItem("String", "test1");

            Assert.AreEqual(storage.GetItem <string>("String"), "test1");
        }
예제 #10
0
 public void DeleteVideo()
 {
     IsolatedStorage.Delete(GetBaseFilename() + DoneSuffix);
     IsolatedStorage.Delete(GetBaseFilename() + CourseTopicNameSuffix);
     IsolatedStorage.Delete(GetBaseFilename() + LectureTitleSuffix);
     IsolatedStorage.Delete(GetBaseFilename() + IndexSuffix);
     IsolatedStorage.Delete(GetBaseFilename() + StateSuffix);
     RefreshStatus();
 }
예제 #11
0
        /// <summary>
        /// Saves file on a thread pool thread
        /// </summary>
        /// <param name="data">Data to save</param>
        /// <param name="completed">Delegate to call on completed</param>
        /// <param name="handleException">Exception handler delegate</param>
        internal static void BeginSaveToFile(
            FavoriteCollection data,
            Action completed,
            Action <Exception> handleException)
        {
            IsolatedStorage <FavoriteCollection> f = new IsolatedStorage <FavoriteCollection>();

            f.BeginSave(FavoriteData.FavoriteFileName, data, completed, handleException);
        }
예제 #12
0
        public Applications Restore()
        {
            var deserializer = new XmlSerializer(_applications.GetType());
            var file         = IsolatedStorage.OpenFile(DataFile, FileMode.Open, FileAccess.Read);
            var result       = deserializer.Deserialize(file);

            file.Close();
            return((Applications)result);
        }
        public void AddObjectTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            object value = "test";
            string key = "Object";
            storage.AddItem(key, value);
            object result = storage.GetItem<object>(key);

            Assert.AreEqual(value, result);
        }
예제 #14
0
파일: Cache.cs 프로젝트: Stephen-Y/Apps
 public static void DeleteAllFiles()
 {
     lock (typeof(Cache))
     {
         foreach (var filename in IsolatedStorage.GetFiles(CacheFolder))
         {
             IsolatedStorage.Delete(filename);
         }
     }
 }
예제 #15
0
        public void Save()
        {
            var file = IsolatedStorage.CreateFile(DataFile);

            var serializer = new XmlSerializer(_applications.GetType());

            serializer.Serialize(file, _applications);

            file.Close();
        }
        public void AddStringTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            string value = "test";
            string key = "String";
            storage.AddItem(key, value);
            string result = storage.GetItem<string>(key);

            Assert.AreEqual(value, result);
        }
        public void AddClassTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            var value = new StorageModel() { Name = "name", Value = "default" };
            string key = "Class";
            storage.AddItem(key, value);
            StorageModel result = storage.GetItem<StorageModel>(key);

            Assert.AreEqual(value, result);
        }
예제 #18
0
 // this might be called more than once
 private void OnCompletion(BackgroundTransferRequest request)
 {
     lock (typeof(DownloadInfo))
     {
         Monitor = null;
         IsolatedStorage.Move(GetBaseFilename(), GetBaseFilename() + DoneSuffix);
         RefreshStatus();
         SafeRemoveRequest(request);
     }
 }
        public void RemoveTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            string value = "test";
            string key = "String";

            storage.AddItem(key, value);
            Assert.IsTrue(storage.ContainItem(key));
            storage.RemoveItem(key);
            Assert.IsFalse(storage.ContainItem(key));
        }
예제 #20
0
        public static T LoadObject <T>(this IsolatedStorage isoStorage, string fileName)
        {
            IsolatedStorageFileStream readStream = new IsolatedStorageFileStream(fileName, FileMode.Open);
            BinaryFormatter           formatter  = new BinaryFormatter();
            T readData = (T)formatter.Deserialize(readStream);

            readStream.Flush();
            readStream.Close();

            return(readData);
        }
예제 #21
0
        public void AddStringTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            string          value   = "test";
            string          key     = "String";

            storage.AddItem(key, value);
            string result = storage.GetItem <string>(key);

            Assert.AreEqual(value, result);
        }
예제 #22
0
        public void AddObjectTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            object          value   = "test";
            string          key     = "Object";

            storage.AddItem(key, value);
            object result = storage.GetItem <object>(key);

            Assert.AreEqual(value, result);
        }
예제 #23
0
        public void RemoveTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            string          value   = "test";
            string          key     = "String";

            storage.AddItem(key, value);
            Assert.IsTrue(storage.ContainItem(key));
            storage.RemoveItem(key);
            Assert.IsFalse(storage.ContainItem(key));
        }
예제 #24
0
파일: Cache.cs 프로젝트: Stephen-Y/Apps
 public static IDictionary <string, string> GetFiles()
 {
     lock (typeof(Cache))
     {
         var files = new Dictionary <string, string>();
         foreach (var filename in IsolatedStorage.GetFiles(CacheFolder))
         {
             files.Add(Path.GetFileName(filename), IsolatedStorage.ReadAllText(filename));
         }
         return(files);
     }
 }
예제 #25
0
 // this might be called more than once
 private void OnFailure(BackgroundTransferRequest request)
 {
     lock (typeof(DownloadInfo))
     {
         Monitor = null;
         IsolatedStorage.Delete(GetBaseFilename());
         IsolatedStorage.Delete(GetBaseFilename() + CourseTopicNameSuffix);
         IsolatedStorage.Delete(GetBaseFilename() + LectureTitleSuffix);
         IsolatedStorage.Delete(GetBaseFilename() + IndexSuffix);
         SafeRemoveRequest(request);
     }
 }
예제 #26
0
        private static IDownloadInfo Get(string filename, IDictionary <string, BackgroundTransferRequest> backgroundTransferRequests)
        {
            var parts           = filename.Replace(DoneSuffix, null).Substring(filename.LastIndexOf('/') + 1).Split('_');
            var courseId        = int.Parse(parts[0]);
            var lectureId       = int.Parse(parts[1]);
            var courseTopicName = IsolatedStorage.ReadAllText(GetBaseFilename(courseId, lectureId) + CourseTopicNameSuffix) ?? "<Unknown Course>";
            var lectureTitle    = IsolatedStorage.ReadAllText(GetBaseFilename(courseId, lectureId) + LectureTitleSuffix) ?? "<Unknown Lecture>";
            var indexStr        = IsolatedStorage.ReadAllText(GetBaseFilename(courseId, lectureId) + IndexSuffix);
            int index;

            int.TryParse(indexStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out index);
            return(new DownloadInfo(courseId, courseTopicName, lectureId, lectureTitle, index, backgroundTransferRequests));
        }
예제 #27
0
        public void AddClassTest()
        {
            IsolatedStorage storage = new IsolatedStorage();
            var             value   = new StorageModel()
            {
                Name = "name", Value = "default"
            };
            string key = "Class";

            storage.AddItem(key, value);
            StorageModel result = storage.GetItem <StorageModel>(key);

            Assert.AreEqual(value, result);
        }
예제 #28
0
        public static async Task <Firmware> LoadAsync()
        {
            var folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");

            var file = await folder.GetFileAsync(DataFile);

            Firmware data = await IsolatedStorage <Firmware> .LoadFromFile(file);

            if (data == null)
            {
                data = new Firmware();
            }
            return(data);
        }
예제 #29
0
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     position = mediaPlayer.Position;
     if (stateFile != null)
     {
         if (mediaPlayer.NaturalDuration.HasTimeSpan && (mediaPlayer.NaturalDuration.TimeSpan - position.Value).TotalSeconds < 5)
         {
             IsolatedStorage.Delete(stateFile);
         }
         else
         {
             IsolatedStorage.WriteAllText(stateFile, position.Value.Ticks.ToString(CultureInfo.InvariantCulture));
         }
     }
 }
예제 #30
0
        public void FlushTest()
        {
            IsolatedStorage storage = new IsolatedStorage();

            storage.AddItem("String1", "test");
            storage.AddItem("String2", "test");
            storage.AddItem("String3", "test");
            storage.AddItem("String4", "test");

            storage.FlushAll();

            Assert.IsFalse(storage.ContainItem("String1"));
            Assert.IsFalse(storage.ContainItem("String2"));
            Assert.IsFalse(storage.ContainItem("String3"));
            Assert.IsFalse(storage.ContainItem("String4"));
        }
        public void FlushTest()
        {
            IsolatedStorage storage = new IsolatedStorage();

            storage.AddItem("String1", "test");
            storage.AddItem("String2", "test");
            storage.AddItem("String3", "test");
            storage.AddItem("String4", "test");

            storage.FlushAll();

            Assert.IsFalse(storage.ContainItem("String1"));
            Assert.IsFalse(storage.ContainItem("String2"));
            Assert.IsFalse(storage.ContainItem("String3"));
            Assert.IsFalse(storage.ContainItem("String4"));
        }
예제 #32
0
        public void Save()
        {
            var store = new IsolatedStorage <Settings>();

            if (!saving)
            {
                saving = true;
                try
                {
                    store.SaveToFile(SettingsFileName, this);
                }
                finally
                {
                    saving = false;
                }
            }
        }
예제 #33
0
        public async Task SaveAsync()
        {
            var store = new IsolatedStorage <Settings>();

            if (!saving)
            {
                saving = true;
                try
                {
                    Debug.WriteLine("Saving settings to : " + SettingsFolder);
                    await store.SaveToFileAsync(SettingsFolder, SettingsFileName, this);
                }
                finally
                {
                    saving = false;
                }
            }
        }
예제 #34
0
        public static Settings Load()
        {
            var      store  = new IsolatedStorage <Settings>();
            Settings result = null;

            try
            {
                result = store.LoadFromFile(SettingsFileName);
            }
            catch
            {
            }
            if (result == null)
            {
                result = new Settings();
                result.Save();
            }
            return(result);
        }
예제 #35
0
        public static Settings Load()
        {
            var      store  = new IsolatedStorage <Settings>();
            Settings result = null;

            try
            {
                Debug.WriteLine("Loading settings from : " + SettingsFolder);
                result = store.LoadFromFile(SettingsFolder, SettingsFileName);
            }
            catch
            {
            }
            if (result == null)
            {
                result = new Settings();
            }
            return(result);
        }
예제 #36
0
        public static IEnumerable <IDownloadInfo> GetAll()
        {
            var backgroundTransferRequests = GetBackgroundTransferRequests();

            foreach (var request in backgroundTransferRequests.Values)
            {
                var downloadInfo = Get(request.Tag, backgroundTransferRequests);
                if (downloadInfo.Downloading && !downloadInfo.Downloaded)
                {
                    // if it is already downloaded, the Get removed it from the BackgroundTransferService,
                    // but this time it's still present as a duplicate
                    yield return(downloadInfo);
                }
            }
            foreach (var filename in IsolatedStorage.GetFiles(TransfersFolder, DoneSuffix))
            {
                yield return(Get(filename, backgroundTransferRequests));
            }
        }
 public static void save(IsolatedStorage storage)
 {
     settings[storageKey] = storage;
     settings.Save();
 }
        public static IsolatedStorage load()
        {
            //IsolatedStorageSettings.ApplicationSettings.Clear();
            //MessageBox.Show("Data will be erased!", "Metroist", MessageBoxButton.OK);

            IsolatedStorage storage;
            settings.TryGetValue<IsolatedStorage>(storageKey, out storage);
            if (storage == null)
            {
                storage = new IsolatedStorage();
            }
            if(storage.LocalLoginInfo == null)
                storage.LocalLoginInfo = new LocalLogin() { isRecorded = false };
            //if (storage.LoginInfo == null)
            //    storage.LoginInfo = new Login();
            if (storage.Projects == null)
                storage.Projects = new List<Project>();
            if (storage.Items == null)
                storage.Items = new List<Item>();
            if (storage.StartPageTasks == null)
                storage.StartPageTasks = new List<Item>();
            if (storage.Notes == null)
                storage.Notes = new List<Note>();
            //if (storage.ActualLanguage == null)
            //    storage.ActualLanguage = new English();
            if (storage.Settings == null)
                storage.Settings = new Settings() { DateStringHome = FilterOption.TodayFilterOption };
            if (storage.ItemsToSync == null)
                storage.ItemsToSync = new ObservableCollection<Dictionary<string, object>>();

            return storage;
        }
예제 #39
0
 public async Task SaveAsync()
 {
     var store = new IsolatedStorage<Settings>();
     if (!saving)
     {
         saving = true;
         try
         {
             Debug.WriteLine("Saving settings to : " + SettingsFolder);
             await store.SaveToFileAsync(SettingsFolder, SettingsFileName, this);
         }
         finally
         {
             saving = false;
         }
     }
 }
예제 #40
0
 public static async Task<Settings> LoadAsync()
 {
     var store = new IsolatedStorage<Settings>();
     Settings result = null;
     try
     {
         Debug.WriteLine("Loading settings from : " + SettingsFolder);
         result = await store.LoadFromFileAsync(SettingsFolder, SettingsFileName);
     }
     catch
     {
     }
     if (result == null)
     {
         result = new Settings();
         await result.SaveAsync();
     }
     return result;
 }