Exemple #1
0
    protected void ButtonRun_Click(object sender, EventArgs e)
    {
        string errorMessage = null;

        try
        {
            DEAContext context = Session[_contextKey] as DEAContext;
            string     jsonIn  = context.ToJsonString(out errorMessage);
            if (string.IsNullOrEmpty(jsonIn))
            {
                throw new Exception(errorMessage);
            }
            string serviceUrl = ConfigurationManager.AppSettings["deaServiceUrl"];
            var    client     = new RestClient();
            client.BaseUrl = new Uri(serviceUrl);
            RestRequest deaRequest = new RestRequest();
            deaRequest.Method = Method.POST;
            deaRequest.AddParameter("text/plain", jsonIn, ParameterType.RequestBody);
            deaRequest.Resource = "json/DEA";
            var response = client.Execute(deaRequest);
            if (response.IsSuccessful && response.ResponseStatus == ResponseStatus.Completed)
            {
                string      jsonOut     = response.Content;
                DEAResponse deaResponse = JsonConvert.DeserializeObject <DEAResponse>(jsonOut);
                if (deaResponse == null)
                {
                    throw new Exception("Unable to de-serialize JSON response.  Please check the log of the service.");
                }
                if (deaResponse.OK == false)
                {
                    throw new Exception(deaResponse.errorMessage);
                }
                Session[_contextKey] = deaResponse.context;
                DEAEventArgs args = new DEAEventArgs();
                args.Cargo = "DEAContextOK";
                RaiseBubbleEvent(this, args);
            }
            else
            {
                if (!string.IsNullOrEmpty(response.ErrorMessage))
                {
                    throw new Exception(response.ErrorMessage);
                }
                else
                {
                    throw new Exception(response.ResponseStatus.ToString());
                }
            }
        }
        catch (Exception ex)
        {
            LabelError.Text    = ex.Message;
            LabelError.Visible = true;
            DEAEventArgs args = new DEAEventArgs();
            args.Cargo = "ERROR: " + ex.Message;
            RaiseBubbleEvent(this, args);
        }
    }
Exemple #2
0
    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {
        try
        {
            string err = string.Empty;
            if (FileUploadVar.HasFile)
            {
                VarFilePath = MapPath("~/App_Data/" + Session.SessionID.Trim() + "-" + FileUploadVar.FileName);
                FileUploadVar.SaveAs(VarFilePath);
            }
            else
            {
                err += "Please select a CSV file with variables' specifications.";
            }

            if (FileUploadProj.HasFile)
            {
                ProjFilePath = MapPath("~/App_Data/" + Session.SessionID.Trim() + "-" + FileUploadProj.FileName);
                FileUploadProj.SaveAs(ProjFilePath);
            }
            else
            {
                if (!string.IsNullOrEmpty(err))
                {
                    err += "<br/><br/>";
                }
                err += "Please select a CSV file with the projects' specifications.";
            }

            if (FileUploadConstraints.HasFile)
            {
                ConstFilePath = MapPath("~/App_Data/" + Session.SessionID.Trim() + "-" + FileUploadConstraints.FileName);
                FileUploadConstraints.SaveAs(ConstFilePath);
            }
            else
            {
                ConstFilePath = string.Empty;
            }

            if (!string.IsNullOrEmpty(err))
            {
                LabelContextError.Text    = err;
                LabelContextError.Visible = true;
            }
            else
            {
                bool ok = UploadFiles(out err);
                if (!ok)
                {
                    LabelContextError.Text    = err;
                    LabelContextError.Visible = true;
                }
                else
                {
                    File.Delete(VarFilePath);
                    File.Delete(ProjFilePath);
                    if (!string.IsNullOrEmpty(ConstFilePath))
                    {
                        File.Delete(ConstFilePath);
                    }
                    DEAEventArgs arg = new DEAEventArgs();
                    arg.Cargo = "DEAContextOK";
                    RaiseBubbleEvent(this, arg);
                }
            }
        }
        catch (Exception ex)
        {
            LabelError.Text    = ex.Message;
            LabelError.Visible = true;
        }
    }