/// <summary> /// Calls the GrabzIt web service to take the screenshot and saves it to the target path provided /// </summary> /// <remarks> /// Warning, this is a SYNCHONOUS method and can take up to 5 minutes before a response /// </remarks> /// <param name="saveToFile">The file path that the screenshot should saved to.</param> /// <returns>Returns the true if it is successful otherwise it throws an exception.</returns> public bool SaveTo(string saveToFile) { int attempt = 0; while (true) { try { GrabzItFile result = SaveTo(); if (result == null) { return(false); } result.Save(saveToFile); break; } catch (GrabzItException e) { throw e; } catch (Exception) { if (attempt < 3) { attempt++; continue; } throw new GrabzItException("An error occurred trying to save the capture to: " + saveToFile, ErrorCode.FileSaveError); } } return(true); }
protected override void Process(HttpContext context, string filename, string id, string message, string customId, string format) { GrabzItClient grabzItClient = GrabzItClient.Create(ConfigurationManager.AppSettings["ApplicationKey"], ConfigurationManager.AppSettings["ApplicationSecret"]); GrabzItFile file = grabzItClient.GetResult(id); //Ensure that the application has the correct rights for this directory. file.Save(context.Server.MapPath("~/results/" + filename)); }
public ActionResult Handler(string filename, string id, string message, string customId, string format) { GrabzItClient grabzItClient = GrabzItClient.Create(ConfigurationManager.AppSettings["ApplicationKey"], ConfigurationManager.AppSettings["ApplicationSecret"]); GrabzItFile file = grabzItClient.GetResult(id); //Ensure that the application has the correct rights for this directory. file.Save(Server.MapPath("~/results/" + filename)); return(null); }
protected void grabzIt_ScreenShotComplete(object sender, ScreenShotEventArgs result) { if (!string.IsNullOrEmpty(result.Message)) { lblMessage.Text = result.Message; lblMessage.Style.Clear(); lblMessage.CssClass = "error"; } GrabzItFile file = grabzItClient.GetResult(result.ID); //Ensure that the application has the correct rights for this directory. file.Save(Server.MapPath("~/results/" + result.Filename)); }
/// <summary> /// Calls the GrabzIt web service to take the screenshot and returns a GrabzItFile object /// </summary> /// <remarks> /// Warning, this is a SYNCHONOUS method and can take up to 5 minutes before a response /// </remarks> /// <returns>Returns a GrabzItFile object containing the screenshot data.</returns> public GrabzItFile SaveTo() { lock (thisLock) { string id = Save(); if (string.IsNullOrEmpty(id)) { return(null); } //Wait until it is possible to be ready Thread.Sleep(3000 + request.Options.GetStartDelay()); //Wait for it to be ready. while (true) { Status status = GetStatus(id); if (!status.Cached && !status.Processing) { throw new GrabzItException("The capture did not complete with the error: " + status.Message, ErrorCode.RenderingError); } if (status.Cached) { GrabzItFile result = GetResult(id); if (result == null) { throw new GrabzItException("The capture could not be found on GrabzIt.", ErrorCode.RenderingMissingScreenshot); } return(result); } Thread.Sleep(3000); } } }