Пример #1
0
        public static bool Sync()
        {
            var items = MainDb.GetDocuments();

            try
            {
                var toDelete = new List <long>();

                var docs = VkDisk.VkApi.Docs.Get(ownerId: VkDisk.VkApi.UserId).ToList();

                foreach (var item in items)
                {
                    var notFound = true;
                    foreach (var doc in docs)
                    {
                        if (item.DocumentId != doc.Id)
                        {
                            continue;
                        }

                        notFound = false;
                        docs.Remove(doc);
                        break;
                    }

                    if (notFound)
                    {
                        toDelete.Add(item.DocumentId);
                    }
                }

                if (toDelete.Count > 0 || docs.Count > 0)
                {
                    MainDb.DeleteDocuments(toDelete);
                    MainDb.AddDocuments(docs);

                    DocumentsChanged?.Invoke(docs, toDelete);
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }