Esempio n. 1
0
        public async void SaveAsync(CacheFolder cache)
        {
            savePending = true;
            if (!saving)
            {
                saving = true;
                try
                {
                    savePending = false;
                    Log.WriteLine("Saving DataStore at time : " + DateTime.Now.ToString());
                    IsolatedStorage <DataStore> store = new IsolatedStorage <DataStore>(cache);
                    await store.SaveToFileAsync(DataFile, this);

                    if (savePending)
                    {
                        SaveAsync(cache);
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteLine("Error saving DataStore: " + ex.Message);
                }
                finally
                {
                    saving = false;
                }
            }
        }
Esempio n. 2
0
        public static async Task OpenLog(CacheFolder cache)
        {
            if (log == null)
            {
                try
                {
                    var file = await cache.CreateFileAsync("log.txt");

                    log = new StreamWriter(await file.OpenStreamForWriteAsync());
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error opening log: " + ex.Message);
                }
            }
        }
Esempio n. 3
0
        public static async Task <DataStore> LoadAsync(CacheFolder cache)
        {
            IsolatedStorage <DataStore> store = new IsolatedStorage <DataStore>(cache);
            DataStore data = await store.LoadFromFileAsync(DataFile);

            if (data == null)
            {
                data = new DataStore();
            }
            else
            {
                foreach (var info in data.Cameras.ToArray())
                {
                    if (info.StaticImageUrl != null)
                    {
                        data.Cameras.Remove(info);
                    }
                }
            }
            return(data);
        }
Esempio n. 4
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // load our local data store
            CacheFolder folder = new CacheFolder("Data");

            CacheFolder = folder;
            await folder.PopulateCache();

            await Log.OpenLog(folder);

            var store = await DataStore.LoadAsync(folder);

            if (!string.IsNullOrEmpty(store.SnapshotDirectory) && !string.IsNullOrEmpty(store.SnapshotDirectoryToken))
            {
                try
                {
                    store.SnapshotFolder = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFolderAsync(store.SnapshotDirectoryToken);

                    store.SnapshotDirectory = store.SnapshotFolder.Path;
                }
                catch
                {
                    // bummer, didn't work...
                    store.SnapshotDirectoryToken = null;
                }
            }

            if (store.SnapshotDirectory == null || store.SnapshotDirectoryToken == null)
            {
                store.SnapshotFolder = await CacheFolder.GetOrCreateFolder("Snapshots");

                store.SnapshotDirectory = store.SnapshotFolder.Path;
            }

            this.Firmware = await Firmware.LoadAsync();

            Log.WriteLine("OnLaunched {0}", args.Kind);

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content            = rootFrame;
                Window.Current.VisibilityChanged += OnWindowVisibilityChanged;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
Esempio n. 5
0
 public IsolatedStorage(CacheFolder cacheFolder)
 {
     this.cacheFolder = cacheFolder;
 }