예제 #1
0
        public async Task InstallAsync()
        {
            UpdateStatus(WorkshopResourceStatus.Installing);
            var(_, dtos) = await WebServiceClient.GetResourceUpdatedFilesAsync(Id);

            foreach (var dto in dtos)
            {
                if ((FileServerStatus)dto.Status == FileServerStatus.Alive)
                {
                    var file = ResourceFileModel.FromDto(dto);
                    file.ResourceId = Id;
                    file.Status     = ResourceFileStatus.BeforeDownload;
                    Files.Add(file);
                }
            }
            DatabaseClient.SaveResourceFiles(Files);
            cts = new CancellationTokenSource();
            await DownloadAsync(cts.Token);
        }
예제 #2
0
        public async Task UpdateAsync()
        {
            var(lastFileChange, dtos) = await WebServiceClient.GetResourceUpdatedFilesAsync(Id, LastFileChangeDate);

            var toSave = new List <ResourceFileModel>(dtos.Count);

            foreach (var dto in dtos)
            {
                var file      = Files.FirstOrDefault(l => l.Id == dto.Id);
                var isNew     = file != null;
                var isDeleted = (FileServerStatus)dto.Status == FileServerStatus.Deleted;
                if (isNew && !isDeleted)
                {
                    file            = ResourceFileModel.FromDto(dto);
                    file.ResourceId = Id;
                    file.Status     = ResourceFileStatus.BeforeDownload;
                    Files.Add(file);
                }
                else if (isNew && isDeleted)
                {
                    // do nothing
                }
                else if (!isNew && !isDeleted)
                {
                    file.Sha1       = dto.Sha1;
                    file.Size       = dto.Size;
                    file.UpdateDate = dto.UpdateDate;
                    file.Status     = ResourceFileStatus.BeforeDownload;
                }
                else if (!isNew && isDeleted)
                {
                    file.DeleteFromDisk();
                    DatabaseClient.DeleteFile(file.Id);
                    Files.Remove(file);
                }
                toSave.Add(file);
            }
            DatabaseClient.UpdateResourceLastFileChange(Id, lastFileChange);
            DatabaseClient.SaveResourceFiles(toSave);
            cts = new CancellationTokenSource();
            await DownloadAsync(cts.Token);
        }