Esempio n. 1
0
        public void SyncFiles()
        {
            var filesNeedAddToDB    = new List <File>();
            var filesNeedAddToLocal = new List <File>();

            foreach (var localFile in Files)
            {
                if (!_dataProvider.FileExists(localFile.Path))
                {
                    filesNeedAddToDB.Add(localFile);
                }
            }

            foreach (var dbFilePath in _dataProvider.GetFilesPaths())
            {
                var localFile = Files.FirstOrDefault(f => f.Path == dbFilePath);

                if (localFile == null)
                {
                    filesNeedAddToLocal.Add(_dataProvider.GetFile(dbFilePath));
                }
            }

            Files.AddRange(filesNeedAddToLocal);
            _dataProvider.AddFiles(filesNeedAddToDB.ToArray());

            SyncComplete?.Invoke(this);
        }