private void StopDownloadTasks(ResourceGroupBeingUpdated resourceGroup) { foreach (var downloadTaskId in resourceGroup.DownloadTaskIds) { m_Owner.DownloadService.StopDownloading(downloadTaskId, true); } }
private void Fail(ResourceGroupBeingUpdated resourceGroup, Exception e, string errorMessageFormat) { foreach (var downloadTaskId in resourceGroup.DownloadTaskIds) { m_Owner.DownloadService.StopDownloading(downloadTaskId, true); } resourceGroup.DownloadTaskIds.Clear(); var errorMessage = e == null ? errorMessageFormat : Utility.Text.Format(errorMessageFormat, e.ToString()); if (resourceGroup.CallbackSet.OnAllFailure != null) { resourceGroup.CallbackSet.OnAllFailure(errorMessage, resourceGroup.CallbackContext); } else { if (e != null) { throw new Exception(string.Empty, e); } else { throw new Exception(errorMessage); } } }
public void StartUpdatingResourceGroup(int groupId, ResourceGroupUpdateCallbackSet callbackSet, object context) { if (!IsReady) { throw new InvalidOperationException("Not ready."); } if (!AvailableResourceGroupIds.Contains(groupId)) { throw new ArgumentException(Utility.Text.Format("Resource group '{0}' is not available.", groupId)); } if (GetResourceGroupStatus(groupId) == ResourceGroupStatus.UpToDate) { throw new InvalidOperationException(Utility.Text.Format("Resource group '{0}' is already up-to-date.", groupId)); } if (AvailableResourceGroupIds.Contains(0) && groupId != 0 && GetResourceGroupStatus(0) != ResourceGroupStatus.UpToDate) { throw new InvalidOperationException("You have to update resource group 0 first."); } if (m_ResourceGroupsBeingUpdated.ContainsKey(groupId)) { throw new InvalidOperationException($"Resource group '{groupId}' is being updated."); } var resourceSummary = ResourceSummaries[groupId]; var resourceGroup = new ResourceGroupBeingUpdated { GroupId = groupId, Summary = resourceSummary, CallbackSet = callbackSet, CallbackContext = context, }; m_ResourceGroupsBeingUpdated.Add(groupId, resourceGroup); foreach (var resourceToUpdate in resourceSummary) { var downloadContext = new DownloadContext { RootUrlIndex = 0, ResourcePath = resourceToUpdate.Key, ResourceGroupId = groupId, }; var resourceInfo = m_Owner.m_RemoteIndex.ResourceInfos[resourceToUpdate.Key]; var downloadTaskInfo = new DownloadTaskInfo( Utility.Text.Format("{0}/{1}_{2}{3}", RootUrls[0], resourceToUpdate.Key, resourceInfo.Crc32, Constant.ResourceFileExtension), Path.Combine(m_Owner.ReadWritePath, resourceToUpdate.Key + Constant.ResourceFileExtension), resourceInfo.Size, resourceInfo.Crc32, new DownloadCallbackSet { OnFailure = m_OnDownloadFailure, OnSuccess = m_OnDownloadSuccess, OnProgress = m_OnDownloadProgress, }, downloadContext); resourceGroup.DownloadTaskIds.Add(m_Owner.DownloadModule.StartDownloading(downloadTaskInfo)); } }
private void SingleFail(ResourceGroupBeingUpdated resourceGroup, string resourcePath, string errorMessage) { if (resourceGroup.CallbackSet.OnSingleFailure != null) { resourceGroup.CallbackSet.OnSingleFailure(resourcePath, errorMessage, resourceGroup.CallbackContext); } else { throw new InvalidOperationException(errorMessage); } }