/// <summary> /// Represents an empty (no-op) action. /// </summary> /// <param name="controller">The controller.</param> protected void EmptyAction(Controller controller) { controller.CancelView(); }
/// <summary> /// Invoked when a step is accessed on the url, /// i.e. http://host/mywizard/firststep.rails and /// when an inner action is invoked like http://host/mywizard/firststep-save.rails /// </summary> /// <param name="controller"></param> private void OnStepActionRequested(Controller controller) { if (currentStepInstance != null && !HasRequiredSessionData(controller)) { StartWizard(controller, false); } controller.CancelView(); IRailsEngineContext context = controller.Context; IWizardController wizController = (IWizardController) controller; String wizardName = WizardUtils.ConstructWizardNamespace(controller); String currentStep = (String) context.Session[wizardName + "currentstep"]; // The step will inherit the controller property bag, // this way filters can pass values to the step property without having to know it currentStepInstance.PropertyBag = controller.PropertyBag; // If OnBeforeStep returns false we stop if (!wizController.OnBeforeStep(wizardName, currentStep, currentStepInstance)) { return; } // Initialize step data so instance members can be used // executor.InitializeController(urlInfo.Area, urlInfo.Controller, innerAction); // Record the step we're working with WizardUtils.RegisterCurrentStepInfo(controller, currentStepInstance.ActionName); // The step cannot be accessed in the current state of matters if (!currentStepInstance.IsPreConditionSatisfied(controller.Context)) { return; } // Dispatch process try { // TODO: Invoke Whole step here // currentStepInstance.Process(controller.Context, // urlInfo.Area, urlInfo.Controller, innerAction); currentStepExecutor.ProcessSelectedAction(); } finally { wizController.OnAfterStep(wizardName, currentStep, currentStepInstance); currentStepExecutor.Dispose(); } }
public void Execute(Controller controller) { try { string filename = Path.GetTempFileName(); logger.Info("Saving tabular data into " + filename); controller.PropertyBag["filename"] = filename; TabularQuery query = TabularQuery.Find(int.Parse(controller.Params["table"])); CustomQuery customQuery = new CustomQuery(query.SelectStatement); customQuery.Logger = GlobalApplication.CreateLogger(typeof(CustomQuery)); QueryResults results = customQuery .ConfigureFilters(controller.Params) .Execute(); /* * IMPORTANT: To make sure the Excel applicaton quits properly follow the below steps: * SEE: http://support.microsoft.com/default.aspx?scid=kb;en-us;317109 * * 1. each COM object should be a new variable * 2. use System.Runtime.InteropServices.Marshal.ReleaseComObject when finished with an object * 3. set variable to null * 4. call the Quit method of the application * 5. run garbage collection methods */ logger.Debug("initializing Excel application"); Application excel = new Application(); Workbooks books = excel.Workbooks; Workbook book = books.Add(Missing.Value) as Workbook; Sheets sheets = book.Worksheets as Sheets; Worksheet sheet; excel.Visible = true; logger.Debug("removing unneeded sheets"); while (sheets.Count > 1) { sheet = book.ActiveSheet as Worksheet; sheet.Delete(); } sheet = book.ActiveSheet as Worksheet; sheet.Name = query.Title; // first row is column names for (int i = 0; i < results.Columns.Length; i++) { ((Range)sheet.Cells[1, i + 1]).Font.Bold = true; sheet.Cells[1, i + 1] = results.Columns[i]; } // subsequent rows are values for (int i = 0; i < results.Rows.Count; i++) { object[] row = results.Rows[i]; for (int j = 0; j < row.Length; j++) { sheet.Cells[i + 2, j + 1] = row[j]; } } logger.Debug("saving excel workbook"); book.SaveCopyAs(filename); book.Saved = true; books.Close(); logger.Debug("cleaning up COM objects"); Marshal.ReleaseComObject(sheet); Marshal.ReleaseComObject(sheets); Marshal.ReleaseComObject(book); Marshal.ReleaseComObject(books); sheet = null; sheets = null; book = null; books = null; logger.Debug("closing excel application"); excel.Quit(); logger.Debug("final clean up and freeing of resources"); Marshal.ReleaseComObject(excel); excel = null; GC.GetTotalMemory(false); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.GetTotalMemory(true); logger.Debug("sending content"); controller.CancelView(); controller.CancelLayout(); IResponse response = controller.Context.Response; string attachment = String.Format("attachment; filename=\"{0}.xlsx\"", query.Title); string contentLength = new FileInfo(filename).Length.ToString(); response.Clear(); response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; response.AppendHeader("Content-Disposition", attachment); response.AppendHeader("Content-Length", contentLength); response.WriteFile(filename); } catch (Exception e) { logger.Error("Could not export to Excel", e); controller.Response.StatusCode = 500; } }
protected void RenderFromTemplate(String templateName, Controller controller) { StringWriter writer = new StringWriter(); IDictionary context = new Hashtable(); context.Add("flash", controller.Context.Flash); foreach(DictionaryEntry entry in controller.PropertyBag) { context.Add(entry.Key, entry.Value); } #if USE_LOCAL_TEMPLATES templateEngine.Process( context, templateName, writer ); #else templateEngine.Process( context, "Castle.MonoRail.ActiveRecordScaffold/Templates/" + templateName, writer ); #endif if (useDefaultLayout) { StringWriter layoutwriter = new StringWriter(); context.Add("childContent", writer.GetStringBuilder().ToString()); #if USE_LOCAL_TEMPLATES templateEngine.Process(context, "layout.vm", layoutwriter); #else templateEngine.Process(context, "Castle.MonoRail.ActiveRecordScaffold/Templates/layout.vm", layoutwriter); #endif writer = layoutwriter; controller.CancelView(); controller.Response.Write(writer.GetStringBuilder().ToString()); } else { controller.DirectRender(writer.GetStringBuilder().ToString()); } }