/// <summary>
        /// prepare the serialized data file for download
        /// </summary>
        /// <param name="mimeType"></param>
        /// <returns></returns>
        public ActionResult PrepareDownloadFile(string mimeType)
        {
            // if we have already a matching file cached, we can short circuit here
            if ((null != Session[SESSION_FILE]) && ((Dictionary <string, string>)Session[SESSION_FILE]).ContainsKey(mimeType))
            {
                return(Json(new { error = false, mimeType = mimeType }, JsonRequestBehavior.AllowGet));
            }
            long selectedDataStructureId = 0;

            if (Session["DataStructureId"] != null)
            {
                selectedDataStructureId = (long)Session["DataStructureId"];
            }

            // helper class
            DownloadManager downloadManager = new DownloadManager();

            // filename
            // use unix timestamp to make filenames unique
            string        filename = Models.Settings.get("lui:filename:download") as string;
            LUIQueryModel model    = (LUIQueryModel)Session["LUICalModel"];
            string        mean     = "";

            if (model.TypeOfMean.SelectedValue != "empty")
            {
                mean = "_" + model.TypeOfMean.SelectedValue;
            }
            filename += "_" + model.ComponentsSet.SelectedValue + "_" + model.Scales.SelectedValue + mean + "_" + DateTime.Now.ToString("yyyy-MM-dd");

            // datastructure ID
            //int dsId = (int)Settings.get("lui:datastructure");

            // depends on the requested type
            string path = "";

            switch (mimeType)
            {
            case "text/csv":
            case "text/tsv":
                path = downloadManager.GenerateAsciiFile(FILE_NAMESPACE, Session[SESSION_TABLE] as DataTable, filename, mimeType);
                break;

            case "application/vnd.ms-excel.sheet.macroEnabled.12":
            case "application/vnd.ms-excel":
                //path = outputDataManager.GenerateExcelFile(FILE_NAMESPACE, Session[SESSION_TABLE] as DataTable, filename, selectedDataStructureId);
                break;

            default:
                Response.StatusCode = 420;
                return(Json(new { error = true, msg = "Unknown file-type: " + mimeType }, JsonRequestBehavior.AllowGet));
            }

            // store path in session for further download
            if (null == Session[SESSION_FILE])
            {
                Session[SESSION_FILE] = new Dictionary <string, string>();
            }
            ((Dictionary <string, string>)Session[SESSION_FILE])[mimeType] = path;

            return(Json(new { error = false, mimeType = mimeType }, JsonRequestBehavior.AllowGet));
        }