Esempio n. 1
0
        public EntryEx(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            _entry = entry;
        }
Esempio n. 2
0
        protected override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled || _entry != null)
                return;

            var database = Cache.Database;
            if (database == null)
            {
                GoBack<MainPage>();
                return;
            }

            var id = NavigationContext
                .QueryString["entry"];

            _entry = database.GetEntry(id) ??
                CurrentEntry.Entry;

            foreach (var field in _entry.CustomFields.Take(3))
            {
                var item = new ApplicationBarMenuItem(field.Key);
                item.Click += (s, _) => SetValue(field.Value);
                ApplicationBar.MenuItems.Add(item);
            }
        }
Esempio n. 3
0
        protected override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
                return;

            _database = Cache.Database;
            if (_database == null)
            {
                this.BackToDBs();
                return;
            }

            string id;
            var queries = NavigationContext.QueryString;

            if (queries.TryGetValue("entry", out id))
                _entry = _database.GetEntry(id);
            else
            {
                id = queries["group"];
                _group = _database.GetGroup(id);
            }

            _target = _database.Root;
            Refresh();
        }
Esempio n. 4
0
        public EntryBinding(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            _entry = entry;
            _addedFields = new List<Field>();
        }
Esempio n. 5
0
        /// <summary>
        /// Deletes the specified entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        public void Delete(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            var time = GetTime(DateTime.Now);
            var element = _entries[entry.ID];

            element.Remove();
            _entries.Remove(entry.ID);

            _deletedObjs.Add(new XElement("DeletedObject",
                new XElement("UUID", entry.ID),
                new XElement("DeletionTime", time)));
        }
Esempio n. 6
0
        public GroupItem(Entry entry, Dispatcher dispatcher)
        {
            if (entry == null) throw new ArgumentNullException("entry");
            if (dispatcher == null) throw new ArgumentNullException("dispatcher");

            Title = entry.Title;
            Notes = entry.UserName;
            Icon = ThemeData.GetImage("entry");

            Overlay = Cache.GetOverlay(
                dispatcher, entry.Icon);

            _data = entry;
            _targetUri = Navigation.GetPathTo
                <EntryDetails>("id={0}", entry.ID);
        }
Esempio n. 7
0
        protected override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
                return;

            var database = Cache.Database;
            if (database == null)
            {
                GoBack<MainPage>();
                return;
            }

            var id = NavigationContext
                .QueryString["id"];

            _entry = database.GetEntry(id)
                ?? CurrentEntry.Entry;

            LoadCurrentState();
        }
Esempio n. 8
0
        private Entry ParseEntry(XmlReader reader)
        {
            var id = ReadId(reader);
            var icon = ParseIcon(reader);
            var lastModified = ReadLastModified(reader);
            var fields = ReadFields(reader);

            // Needed to ensure protected
            // fields decryption
            ReadHistories(reader);

            if (fields.Count == 0)
                return null;

            var entry = new Entry(fields)
            {
                ID = id,
                Icon = icon,
                LastModified = lastModified,
            };

            return entry;
        }
Esempio n. 9
0
        protected override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
                return;

            if (_entry != null)
            {
                UpdateNotes();
                txtPassword.Text = _entry.Password;

                _binding.HasChanges =
                    CurrentEntry.HasChanges;

                return;
            }

            var database = Cache.Database;
            if (database == null)
            {
                GoBack<MainPage>();
                return;
            }

            string id;
            var queries = NavigationContext.QueryString;

            Entry entry;
            if (queries.TryGetValue("id", out id))
            {
                entry = database.GetEntry(id);

                ThreadPool.QueueUserWorkItem(
                    _ => Cache.AddRecent(id));
            }
            else
            {
                entry = new Entry
                {
                    Password = Generator
                        .CharacterSets.NewEntry(),
                };
            }

            DisplayEntry(entry);
        }
Esempio n. 10
0
        private void DisplayEntry(Entry entry)
        {
            _entry = entry;

            _binding = new EntryEx(entry);
            _binding.HasChangesChanged += _binding_HasChangesChanged;
            _binding.HasChanges = entry.IsNew();

            CurrentEntry.Entry = entry;
            CurrentEntry.HasChanges = entry.IsNew();

            UpdateNotes();
            DataContext = _binding;

            var fields = entry.CustomFields.Count;
            if (fields == 0)
            {
                lnkFields.Visibility =
                    Visibility.Collapsed;
            }
            else
            {
                lnkFields.Visibility =
                    Visibility.Visible;

                lnkFields.Content = string.Format(
                    Properties.Resources.FieldsLink,
                    fields);
            }
        }
Esempio n. 11
0
 private static bool Matches(
     Entry entry, string text)
 {
     return Matches(text, new[]
     {
         entry.Title,
         entry.UserName,
         entry.Notes,
     });
 }
Esempio n. 12
0
        /// <summary>
        /// Updates the details of the specified entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        public void Details(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            var element = _entries[entry.ID];

            element
                .Element("History")
                .Add(Clone(element));

            SetFields(element, entry.GetAllFields());

            var time = DateTime.Now;
            entry.LastModified = time;

            element
                .Element("Times")
                .Element("LastModificationTime")
                .Value = GetTime(time);
        }
Esempio n. 13
0
 private void UpdateFieldsCount(Entry entry)
 {
     var mnuFields = AppMenu(0);
     mnuFields.Text = string.Format(
         Properties.Resources.FieldsMenuItem,
         entry.CustomFields.Count);
 }
Esempio n. 14
0
        /// <summary>
        /// Saves the new entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        public void New(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            var time = DateTime.Now;
            entry.LastModified = time;

            var timeValue = GetTime(time);
            var element = new XElement("Entry",
                new XElement("UUID", entry.ID),
                new XElement("IconID", 0),
                new XElement("ForegroundColor"),
                new XElement("BackgroundColor"),
                new XElement("OverrideURL"),
                new XElement("Tags"),
                new XElement("Times",
                    new XElement("LastModificationTime", timeValue),
                    new XElement("CreationTime", timeValue),
                    new XElement("LastAccessTime", timeValue),
                    new XElement("ExpiryTime", timeValue),
                    new XElement("Expires", "False"),
                    new XElement("UsageCount", 0),
                    new XElement("LocationChanged", timeValue)));

           

            element.Add(
                new XElement("AutoType",
                    new XElement("Enabled", "True"),
                    new XElement("DataTransferObfuscation", 0),
                    new XElement("Association",
                        new XElement("Window", "Target Window"),
                        new XElement("KeystrokeSequence",
                            "{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}"))),
                new XElement("History"));

            SetFields(element, entry.GetAllFields());

            var group = _groups[entry.Group.ID];
            group.Add(element);

            group
                .Element("Times")
                .Element("LastModificationTime")
                .Value = timeValue;

            _entries.Add(entry.ID, element);
        }
Esempio n. 15
0
        protected override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
                return;

            if (_binding != null)
            {
                _binding.Save();

                UpdateNotes();
                UpdateFieldsCount(_entry);
                txtPassword.Text = _binding.Password;

                return;
            }

            var database = Cache.Database;
            if (database == null)
            {
                this.BackToDBs();
                return;
            }

            string id;
            var queries = NavigationContext.QueryString;

            Entry entry;
            if (queries.TryGetValue("id", out id))
            {
                entry = database.GetEntry(id);

                ThreadPool.QueueUserWorkItem(
                    _ => Cache.AddRecent(id));
            }
            else
            {
                var config = database.Configuration;

                entry = new Entry
                {
                    Password = Generator
                        .CharacterSets.NewEntry(),
                    UserName = config.DefaultUserName,
                    Protections =
                        {
                            Title = config.ProtectTitle,
                            UserName = config.ProtectUserName,
                            Password = config.ProtectPassword,
                        }
                };

                txtTitle.Loaded += (sender, e1) =>
                    txtTitle.Focus();
            }

            DisplayEntry(entry);
            UpdateFieldsCount(entry);
        }
Esempio n. 16
0
 /// <summary>
 /// Deletes the specified entry.
 /// </summary>
 /// <param name="entry">The entry.</param>
 public void Delete(Entry entry)
 {
     _xmlWriter.Delete(entry);
 }
Esempio n. 17
0
 /// <summary>
 /// Updates the location of the specified entry.
 /// </summary>
 /// <param name="entry">The entry.</param>
 public void Location(Entry entry)
 {
     _xmlWriter.Location(entry);
 }
Esempio n. 18
0
        private void Delete(Entry entry)
        {
            var database = Cache.Database;
            var pernament = IsPernamentDelete();

            if (!ConfirmDelete(pernament,
                Properties.Resources.Entry,
                entry.Title))
            {
                return;
            }

            if (!pernament)
            {
                MoveToRecycleBin((writer, recycleBin) =>
                {
                    entry.Group.Entries
                        .Remove(entry);
                    recycleBin.Add(entry);

                    writer.Location(entry);
                });
            }
            else
            {
                Save(x =>
                {
                    x.Delete(entry);
                    database.Remove(entry);
                });
            }
        }
Esempio n. 19
0
        private void DisplayEntry(Entry entry)
        {
            _entry = entry;

            var config = entry.Protections;
            txtTitle.IsProtected = config.Title;
            txtPassword.IsProtected = config.Password;
            txtUsername.IsProtected = config.UserName;

            _binding = new EntryBinding(entry);
            _binding.HasChangesChanged += _binding_HasChangesChanged;
            _binding.HasChanges = entry.IsNew();

            CurrentEntry.Entry = _binding;
            _binding.HasChanges = entry.IsNew();

            UpdateNotes();
            DataContext = _binding;
        }
Esempio n. 20
0
        protected override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
                return;

            if (_binding != null)
            {
                _binding.Save();

                UpdateNotes();

                if (!String.IsNullOrEmpty(_binding.Password))
                {
                    txtPassword.Text = _binding.Password;
                }

                return;
            }

            DateTime convertedDate;
            if ((Cache.DbInfo != null) && (Cache.DbInfo.Details.Modified != null))
            {
                convertedDate = DateTime.Parse(Cache.DbInfo.Details.Modified);
                ApplicationTitle.Text = "WinPass - " + Cache.DbInfo.Details.Name + " (" + convertedDate + ")";
            }

            var database = Cache.Database;
            if (database == null)
            {
                this.BackToDBs();
                return;
            }

            string id;
            var queries = NavigationContext.QueryString;
            _fields = new ObservableCollection<FieldBinding>();
            Entry entry;
            if (queries.TryGetValue("id", out id))
            {
                entry = database.GetEntry(id);

                ThreadPool.QueueUserWorkItem(
                    _ => Cache.AddRecent(id));

                // Notes
                if (!String.IsNullOrEmpty(entry.Notes))
                    txtNotes.Text = entry.Notes;

                // Fields
                _fields = new ObservableCollection
                    <FieldBinding>(entry.CustomFields
                        .Select(x => new FieldBinding(x)));


            }
            else
            {
                var config = database.Configuration;

                entry = new Entry
                {
                    Password = Generator
                        .CharacterSets.NewEntry(),
                    UserName = config.DefaultUserName,
                    Protections =
                        {
                            Title = config.ProtectTitle,
                            UserName = config.ProtectUserName,
                            Password = config.ProtectPassword,
                        }
                };

                txtTitle.Loaded += (sender, e1) =>
                    txtTitle.Focus();
            }
            lstFields.ItemsSource = _fields;
            DisplayEntry(entry);
        }
Esempio n. 21
0
        /// <summary>
        /// Adds the specified entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        public void Add(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            entry.Group = this;
            _entries.Add(entry);
        }
Esempio n. 22
0
        /// <summary>
        /// Adds the new entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="groupId">The group id.</param>
        public void AddNew(Entry entry, string groupId)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            var group = !string.IsNullOrEmpty(groupId)
                ? _groups[groupId] : _root;

            entry.ID = Uuid.NewUuid();
            entry.Group = group;

            group.Entries.Add(entry);
            _entries.Add(entry.ID, entry);
        }
Esempio n. 23
0
 /// <summary>
 /// Removes the specified entry.
 /// </summary>
 /// <param name="entry">The entry.</param>
 public void Remove(Entry entry)
 {
     entry.Remove();
     _entries.Remove(entry.ID);
 }
Esempio n. 24
0
 /// <summary>
 /// Saves the new entry.
 /// </summary>
 /// <param name="entry">The entry.</param>
 public void New(Entry entry)
 {
     _xmlWriter.New(entry);
 }
Esempio n. 25
0
        /// <summary>
        /// Updates the location of the specified entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        public void Location(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            var element = _entries[entry.ID];
            element.Remove();

            var parent = _groups[entry.Group.ID];
            parent.Add(element);

            var time = DateTime.Now;
            entry.LastModified = time;

            element
                .Element("Times")
                .Element("LocationChanged")
                .Value = GetTime(time);
        }
Esempio n. 26
0
 /// <summary>
 /// Updates the details of the specified entry.
 /// </summary>
 /// <param name="entry">The entry.</param>
 public void Details(Entry entry)
 {
     _xmlWriter.Details(entry);
 }
Esempio n. 27
0
 private static bool Matches(
     Entry entry, string text)
 {
     var settings = AppSettings.Instance;
     if (settings.SearchInPW)
     {
         return Matches(text, new[]
         {
             entry.Title,
             entry.UserName,
             entry.Password,
             entry.Notes,
         });
     }
     else
     {
         return Matches(text, new[]
     {
         entry.Title,
         entry.UserName,
         entry.Notes,
     });
     }            
 }