Esempio n. 1
0
        private void OnFileDownloaded(MetaListItemInfo item,
                                      string path, byte[] bytes)
        {
            var dispatcher = Dispatcher;

            try
            {
                using (var buffer = new MemoryStream(bytes))
                {
                    if (string.IsNullOrEmpty(_folder))
                    {
                        if (!DatabaseVerifier.Verify(dispatcher, buffer))
                        {
                            return;
                        }

                        var name = item.Title.RemoveKdbx();

                        var storage = new DatabaseInfo();
                        storage.SetDatabase(buffer, new DatabaseDetails
                        {
                            Url      = path,
                            Name     = name,
                            Modified = item.Modified,
                            Type     = SourceTypes.Synchronizable,
                            Source   = DatabaseUpdater.SKYDRIVE_UPDATER,
                        });
                    }
                    else
                    {
                        var hash = KeyFile.GetKey(buffer);
                        if (hash == null)
                        {
                            dispatcher.BeginInvoke(() => MessageBox.Show(
                                                       Properties.Resources.InvalidKeyFile,
                                                       Properties.Resources.KeyFileTitle,
                                                       MessageBoxButton.OK));

                            return;
                        }

                        new DatabaseInfo(_folder)
                        .SetKeyFile(hash);
                    }
                }

                dispatcher.BeginInvoke(
                    this.BackToDBs);
            }
            finally
            {
                dispatcher.BeginInvoke(() =>
                                       progBusy.IsBusy = false);
            }
        }
Esempio n. 2
0
        private void OnFileDownloaded(MetaListItemInfo item,
            string path, byte[] bytes)
        {
            var dispatcher = Dispatcher;

            try
            {
                using (var buffer = new MemoryStream(bytes))
                {
                    if (string.IsNullOrEmpty(_folder))
                    {
                        if (!DatabaseVerifier.Verify(dispatcher, buffer))
                            return;

                        var name = item.Title.RemoveKdbx();

                        var storage = new DatabaseInfo();
                        storage.SetDatabase(buffer, new DatabaseDetails
                        {
                            Url = path,
                            Name = name,
                            Modified = item.Modified,
                            Type = SourceTypes.Synchronizable,
                            Source = DatabaseUpdater.SKYDRIVE_UPDATER,
                        });
                    }
                    else
                    {
                        var hash = KeyFile.GetKey(buffer);
                        if (hash == null)
                        {
                            dispatcher.BeginInvoke(() => MessageBox.Show(
                                Properties.Resources.InvalidKeyFile,
                                Properties.Resources.KeyFileTitle,
                                MessageBoxButton.OK));

                            return;
                        }

                        new DatabaseInfo(_folder)
                            .SetKeyFile(hash);
                    }
                }

                dispatcher.BeginInvoke(
                    this.BackToDBs);
            }
            finally
            {
                dispatcher.BeginInvoke(() =>
                    progBusy.IsBusy = false);
            }
        }
Esempio n. 3
0
        private static ListItem Translate(
            MetaListItemInfo item)
        {
            var info = new ListItem
            {
                Tag = item,
            };

            if (item != null)
            {
                info.Timestamp = item.Modified;
            }

            return(info);
        }
Esempio n. 4
0
        public void Download(string path,
                             Action <MetaListItemInfo, string, byte[]> complete)
        {
            byte[]           bytes = null;
            MetaListItemInfo item  = null;

            var waitInfo    = new ManualResetEvent(false);
            var waitContent = new ManualResetEvent(false);

            _client.ExecuteAsync(
                Request(path + "/content"), x =>
            {
                bytes = x.RawBytes;
                waitContent.Set();
            });

            _client.ExecuteAsync(
                Request(path), x =>
            {
                try
                {
                    var root = JsonConvert
                               .DeserializeXNode(x.Content, "root")
                               .Root;

                    if (root == null)
                    {
                        return;
                    }

                    item = new MetaListItemInfo(root);
                }
                finally
                {
                    waitInfo.Set();
                }
            });

            ThreadPool.QueueUserWorkItem(_ =>
            {
                waitInfo.WaitOne();
                waitContent.WaitOne();

                var id = GetSyncPath(item.Path);
                complete(item, id, bytes);
            });
        }
Esempio n. 5
0
        private static ListItem Translate(
            MetaListItemInfo item)
        {
            var info = new ListItem
            {
                Tag = item,
            };

            if (item != null)
                info.Timestamp = item.Modified;

            return info;
        }
Esempio n. 6
0
        public void Download(string path,
            Action<MetaListItemInfo, string, byte[]> complete)
        {
            byte[] bytes = null;
            MetaListItemInfo item = null;

            var waitInfo = new ManualResetEvent(false);
            var waitContent = new ManualResetEvent(false);

            _client.ExecuteAsync(
                Request(path + "/content"), x =>
                {
                    bytes = x.RawBytes;
                    waitContent.Set();
                });

            _client.ExecuteAsync(
                Request(path), x =>
                {
                    try
                    {
                        var root = JsonConvert
                            .DeserializeXNode(x.Content, "root")
                            .Root;

                        if (root == null)
                            return;

                        item = new MetaListItemInfo(root);
                    }
                    finally
                    {
                        waitInfo.Set();
                    }
                });

            ThreadPool.QueueUserWorkItem(_ =>
            {
                waitInfo.WaitOne();
                waitContent.WaitOne();

                var id = GetSyncPath(item.Path);
                complete(item, id, bytes);
            });
        }
Esempio n. 7
0
        public void List(string path, Action<MetaListItemInfo,
            MetaListItemInfo[]> complete)
        {
            if (string.IsNullOrEmpty(path))
                path = "me/skydrive";

            MetaListItemInfo parent = null;
            var items = new MetaListItemInfo[0];

            var waitItems = new ManualResetEvent(false);
            var waitParent = new ManualResetEvent(false);

            _client.ExecuteAsync(Request(path + "/files"),
                x =>
                {
                    try
                    {
                        var root = JsonConvert
                            .DeserializeXNode(x.Content, "root")
                            .Root;

                        if (root == null)
                            return;

                        items = root
                            .Elements("data")
                            .Select(e => new MetaListItemInfo(e))
                            .ToArray();
                    }
                    finally
                    {
                        waitItems.Set();
                    }
                });

            _client.ExecuteAsync(Request(path), x =>
            {
                try
                {
                    var root = JsonConvert
                        .DeserializeXNode(x.Content, "root")
                        .Root;

                    if (root == null)
                        return;

                    parent = new MetaListItemInfo(root);
                }
                finally
                {
                    waitParent.Set();
                }
            });

            ThreadPool.QueueUserWorkItem(_ =>
            {
                waitItems.WaitOne();
                waitParent.WaitOne();
                complete(parent, items);
            });
        }
Esempio n. 8
0
        public void List(string path, Action <MetaListItemInfo,
                                              MetaListItemInfo[]> complete)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = "me/skydrive";
            }

            MetaListItemInfo parent = null;
            var items = new MetaListItemInfo[0];

            var waitItems  = new ManualResetEvent(false);
            var waitParent = new ManualResetEvent(false);

            _client.ExecuteAsync(Request(path + "/files"),
                                 x =>
            {
                try
                {
                    var root = JsonConvert
                               .DeserializeXNode(x.Content, "root")
                               .Root;

                    if (root == null)
                    {
                        return;
                    }

                    items = root
                            .Elements("data")
                            .Select(e => new MetaListItemInfo(e))
                            .ToArray();
                }
                finally
                {
                    waitItems.Set();
                }
            });

            _client.ExecuteAsync(Request(path), x =>
            {
                try
                {
                    var root = JsonConvert
                               .DeserializeXNode(x.Content, "root")
                               .Root;

                    if (root == null)
                    {
                        return;
                    }

                    parent = new MetaListItemInfo(root);
                }
                finally
                {
                    waitParent.Set();
                }
            });

            ThreadPool.QueueUserWorkItem(_ =>
            {
                waitItems.WaitOne();
                waitParent.WaitOne();
                complete(parent, items);
            });
        }