private void LogonOk()
        {
            // flip back - we're not on the right thread...
            this.Dispatcher.BeginInvoke(delegate()
            {
                // save...
                if (this.checkRememberMe.IsChecked.Value)
                {
                    SimpleXmlPropertyBag settings = SixBookmarksRuntime.Current.Settings;
                    settings[UsernameKey]         = this.textUsername.Text.Trim();
                    settings[PasswordKey]         = this.textPassword.Password.Trim();
                    settings.Save();
                }
                else
                {
                    this.ClearCredentials();
                }

                // do sync will come here...
                Sync sync = new Sync();
                sync.DoSync(delegate() {
                    // we worked...
                    Dispatcher.BeginInvoke(delegate()
                    {
                        NavigationService.Navigate(new Uri("/NavigatorPage.xaml", UriKind.RelativeOrAbsolute));
                    });
                }, Alert.GetFailedHandler(this));
            });
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // load the settings...
            SimpleXmlPropertyBag settings = SixBookmarksRuntime.Current.Settings;

            if (settings.ContainsKey(UsernameKey) && settings.ContainsKey(PasswordKey))
            {
                this.textUsername.Text     = settings[UsernameKey];
                this.textPassword.Password = settings[PasswordKey];

                // ok...
                this.DoLogon();
            }
        }
        private void ClearCredentials()
        {
            // set...
            SimpleXmlPropertyBag settings = SixBookmarksRuntime.Current.Settings;

            if (settings.ContainsKey(UsernameKey))
            {
                settings.Remove(UsernameKey);
            }
            if (settings.ContainsKey(PasswordKey))
            {
                settings.Remove(PasswordKey);
            }

            // save...
            settings.Save();
        }
        internal static SimpleXmlPropertyBag Load(string path, bool throwIfNotFound)
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

            // does the file exist?
            if (store.FileExists(path))
            {
                // load it...
                XDocument doc = null;
                using (Stream stream = store.OpenFile(path, FileMode.Open, FileAccess.Read))
                    doc = XDocument.Load(stream);

                // find the root...
                XElement root = doc.Element("Root");
                if (root == null)
                {
                    throw new InvalidOperationException("'root' is null.");
                }

                // load...
                SimpleXmlPropertyBag bag = new SimpleXmlPropertyBag(path);
                foreach (XElement element in root.Elements())
                {
                    bag[element.Name.LocalName] = element.Value;
                }

                // return...
                return(bag);
            }
            else
            {
                if (throwIfNotFound)
                {
                    throw new InvalidOperationException(string.Format("A file at '{0}' was not found.", path));
                }
                else
                {
                    // return a new one...
                    return(new SimpleXmlPropertyBag(path));
                }
            }
        }
Example #5
0
        /// <summary>
        /// Private constructor.
        /// </summary>
        private SixBookmarksRuntime()
        {
            // settings...
            this.Settings = SimpleXmlPropertyBag.Load("Settings.xml", false);

            // register the entity type...
            EntityType bookmark = new EntityType(typeof(Bookmark), "Bookmark");

            bookmark.AddField(Bookmark.BookmarkIdKey, Bookmark.BookmarkIdKey, DataType.Int32, -1).IsKey = true;
            bookmark.AddField(Bookmark.NameKey, Bookmark.NameKey, DataType.String, 128);
            bookmark.AddField(Bookmark.UrlKey, Bookmark.UrlKey, DataType.String, 128);
            bookmark.AddField(Bookmark.OrdinalKey, Bookmark.OrdinalKey, DataType.Int32, -1);
            bookmark.AddField(Bookmark.IsLocalModifiedKey, Bookmark.IsLocalModifiedKey, DataType.Boolean, -1).IsOnServer = false;
            bookmark.AddField(Bookmark.IsLocalDeletedKey, Bookmark.IsLocalDeletedKey, DataType.Boolean, -1).IsOnServer   = false;
            EntityType.RegisterEntityType(bookmark);

            // create a tombstone data entity type...
            EntityType tombstone = new EntityType(typeof(TombstoneData), "TombstoneData");

            tombstone.AddField(TombstoneData.TombstoneDataIdKey, TombstoneData.TombstoneDataIdKey, DataType.Int32, -1).IsKey = true;
            tombstone.AddField(TombstoneData.NameKey, TombstoneData.NameKey, DataType.String, 64);
            tombstone.AddField(TombstoneData.ValueKey, TombstoneData.ValueKey, DataType.String, 256);
            EntityType.RegisterEntityType(tombstone);
        }