Exemplo n.º 1
0
        // GET: /form?v=variables
        // POST: /form (by 'Download results', 'View results', 'Download request' or 'Upload request')
        public ActionResult Form()
        {
            var method = HttpContext.Request.HttpMethod;
            var config = WebApiApplication.GetExtendedFetchConfiguration(DateTime.MaxValue);

            if (method == "GET")
            {
                return(View("Form", new RequestFormModel(config, Request.QueryString, false)));
            }
            else if (method == "POST")
            {
                if (Request.Form["uploadRequest"] != null)
                {
                    if (Request.Files == null || Request.Files.Count < 1)
                    {
                        var model = new RequestFormModel(config);
                        model.RequestUploadErrors = "No file with request is specified";
                        return(View("Form", model));
                    }
                    else
                    {
                        return(View("Form", new RequestFormModel(config, Request.Files[0].InputStream)));
                    }
                }
                else
                {
                    var model = new RequestFormModel(config, Request.Form, true);
                    if (model.HasErrors)
                    {
                        return(View("Form", model));
                    }

                    if (Request.Form["downloadRequest"] != null)
                    {
                        return(File(
                                   Encoding.UTF8.GetBytes(model.GetRequestText()),
                                   "text/plain",
                                   "request.txt"));
                    }
                    else if (Request.Form["view"] != null)
                    {
                        return(Redirect("v1/FetchClimate2.html#" + model.GetClientUrlParameters()));
                    }

                    // Download data
                    int    minPtsPerPartition          = FrontendSettings.Current.MinPtsPerPartition;
                    int    maxPtsPerPartition          = FrontendSettings.Current.MaxPtsPerPartition;
                    double jobRegistrationPermitedTime = FrontendSettings.Current.AllowedJobRegistrationSpan;
                    int    totalWorkers = RoleEnvironment.Roles["FetchWorker"].Instances.Count;

                    string query      = "";
                    var    jobManager = WebApiApplication.GetSharedJobManager(HttpContext);
                    if (model.Points.Count > 0)
                    {
                        string points = "";
                        foreach (var fr in model.GetRequestsForPoints())
                        {
                            var jobStatus = jobManager.Submit(fr, fr.GetSHAHash(), jobRegistrationPermitedTime, minPtsPerPartition, maxPtsPerPartition, totalWorkers);
                            if (points.Length > 0)
                            {
                                points += ",";
                            }
                            points += jobStatus.Hash;
                        }
                        query += "?p=" + HttpUtility.UrlEncode(points);
                    }
                    int index = 1;
                    foreach (var g in model.Grids)
                    {
                        string hashes = "";
                        foreach (var fr in model.GetRequestsForGrid(g))
                        {
                            var jobStatus = jobManager.Submit(fr, fr.GetSHAHash(), jobRegistrationPermitedTime, minPtsPerPartition, maxPtsPerPartition, totalWorkers);
                            if (hashes.Length > 0)
                            {
                                hashes += ",";
                            }
                            hashes += jobStatus.Hash;
                        }
                        if (query.Length > 0)
                        {
                            query += "&";
                        }
                        else
                        {
                            query += "?";
                        }
                        query = String.Concat(query, "g", index++, "=", HttpUtility.UrlEncode(hashes));
                    }

                    return(Redirect("results" + query));
                }
            }
            else
            {
                throw new Exception("Method is not allowed");
            }
        }
Exemplo n.º 2
0
 // GET /datasources
 public ActionResult DataSources()
 {
     return(View("DataSources", WebApiApplication.GetExtendedFetchConfiguration(DateTime.MaxValue)));
 }