private async void GetStory() { SetFormState(AddStoryFormState.GettingStory); try { var storyParm = txtStoryParm.Text; if (string.IsNullOrEmpty(storyParm)) { throw new ArgumentNullException("storyParm"); } // If it's a URL, just get the parameter. Uri uriOutput; if (Uri.TryCreate(storyParm, UriKind.Absolute, out uriOutput)) { storyParm = uriOutput.Segments.Last(); // Just get the last part, should be the story ID } _log.Debug($"Getting story info: {storyParm}"); var storyResult = await _wdcReader.GetInteractiveStory(storyParm, _wdcClient, _ctSourceWdcClient.Token); // Made it here, request was successfull _story = storyResult; SetStoryInfo(storyResult); } catch (OperationCanceledException ex) { // Do nothing } catch (Exception ex) { // TODO error handling _log.Warn("Error while trying to get story", ex); ShowError("Error trying to get story", "An error occurred while trying to get the story info.", ex); } finally { SetFormState(_story == null ? AddStoryFormState.ReadToGetStory : AddStoryFormState.ReadyToSave); } }
// Update the story details private async Task SyncStoryInfo(WdcInteractiveStory story) { var ct = _ctSource.Token; ct.ThrowIfCancellationRequested(); _log.InfoFormat("Syncing story info: {0}", story.ID); var remoteStory = await _wdcReader.GetInteractiveStory(story.ID, _wdcClient, _ctSource.Token); ct.ThrowIfCancellationRequested(); // Bring over changes story.Author = remoteStory.Author; story.Name = remoteStory.Name; story.ShortDescription = remoteStory.ShortDescription; story.Description = remoteStory.Description; story.LastUpdatedInfo = DateTime.Now; // Save changes ct.ThrowIfCancellationRequested(); _storyContainer.UpdateStory(story); }