public Screenshot Create(string key, Screenshot instance) { ValidateInputs(() => _serviceInputValidator.ValidateAllPackageKeys(key, instance.PackageId, instance.PackageVersion)); Func<Screenshot> actionToExecute = () => { _packageAuthenticator.EnsureKeyCanAccessPackage(key, instance.PackageId, instance.PackageVersion); return _screenshotRepository.Create(instance); }; return ExecuteAction(actionToExecute, "The Screenshot could not be created"); }
public void CreateScreenshot(string packageId, string packageVersion, string externalScreenshotUrl) { var screenshot = new Screenshot { ScreenshotUri = externalScreenshotUrl, PackageId = packageId, PackageVersion = packageVersion }; string serviceRoot = _orchardServices.WorkContext.CurrentSite.As<GallerySettingsPart>().ServiceRoot; string accessKey = _userkeyService.GetAccessKeyForUser(_authenticationService.GetAuthenticatedUser().Id).AccessKey.ToString(); string uri = string.Format("{0}/{1}", ServiceConstants.ScreenshotServiceName, accessKey); using (var client = new HttpClient(serviceRoot)) { HttpContent screenshotContent = HttpContentExtensions.CreateDataContract(screenshot); using (HttpResponseMessage response = client.Post(uri, screenshotContent)) { if (response.StatusCode != HttpStatusCode.OK) { _orchardServices.Notifier.Error(T("Could not create screenshot. {0}", response.ReadContentAsStringWithoutQuotes())); } } } }