Beispiel #1
0
        public virtual object Download(Durados.Security.Cloud.ICloudCredentials cloudCredentials, string lambdaFunctionName)
        {
            string         url     = BaseUrl + "/downloadLambda";
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("POST", url, false);
            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("credentials", cloudCredentials.GetCredentials());
            data.Add("cloudProvider", cloudCredentials.GetProvider());
            data.Add("functionName", lambdaFunctionName);

            request.setRequestHeader("content-type", "application/json");

            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            request.send(jss.Serialize(data));

            if (request.status != 200)
            {
                throw new NodeJsException(request.responseText.TrimStart("{}; ".ToCharArray()));
            }

            object response = null;

            try
            {
                response = jss.Deserialize <object>(request.responseText);
            }
            catch (Exception exception)
            {
                throw new Durados.DuradosException("Could not parse NodeJS response", exception);
            }

            return(response);
        }
Beispiel #2
0
        public virtual void ExecuteOld(object controller, Dictionary <string, Parameter> parameters, View view, Dictionary <string, object> values, DataRow prevRow, string pk, string connectionString, int currentUsetId, string currentUserRole, IDbCommand command, IDbCommand sysCommand, string actionName, string arn, Durados.Security.Cloud.ICloudCredentials awsCredentials)
        {
            const string Payload      = "Payload";
            const string ErrorMessage = "errorMessage";

            bool isDebug = IsDebug(values);

            string         url     = BaseUrl + "/callLambda";
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("POST", url, false);
            Dictionary <string, object> data = new Dictionary <string, object>();

            Dictionary <string, object> payload = GetCallLambdaPayload(controller, parameters, view, values, prevRow, pk, connectionString, currentUsetId, currentUserRole, command);

            string functionName = view.Name + "_" + actionName;
            string folder       = view.Database.GetCurrentAppName();

            data.Add("folder", folder);
            data.Add("functionName", functionName);
            data.Add("payload", payload);
            data.Add("Role", arn);
            if (isDebug)
            {
                if (!System.Web.HttpContext.Current.Items.Contains(JavaScript.GuidKey))
                {
                    System.Web.HttpContext.Current.Items.Add(JavaScript.GuidKey, Guid.NewGuid());
                }
                data.Add("getLog", true);
            }

            request.setRequestHeader("content-type", "application/json");

            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            request.send(jss.Serialize(data));

            if (request.status != 200)
            {
                throw new NodeJsException(request.responseText.TrimStart("{}; ".ToCharArray()));
            }

            Dictionary <string, object> response = null;

            try
            {
                response = jss.Deserialize <Dictionary <string, object> >(request.responseText);
            }
            catch (Exception exception)
            {
                throw new Durados.DuradosException("Could not parse NodeJS response", exception);
            }

            if (response.ContainsKey(FunctionError))
            {
                if (response.ContainsKey(Payload))
                {
                    var responsePayload = response[Payload];
                    if (responsePayload is string)
                    {
                        IDictionary <string, object> responsePayloadError = null;
                        try
                        {
                            responsePayloadError = jss.Deserialize <Dictionary <string, object> >((string)responsePayload);
                        }
                        catch
                        {
                            throw new NodeJsException((string)responsePayload);
                        }
                        if (responsePayloadError.ContainsKey(ErrorMessage))
                        {
                            throw new NodeJsException(responsePayloadError[ErrorMessage].ToString());
                        }
                        else
                        {
                            throw new NodeJsException((string)responsePayload);
                        }
                    }
                    else
                    {
                        throw new NodeJsException(request.responseText.TrimStart("{}; ".ToCharArray()));
                    }
                }
                else
                {
                    throw new NodeJsException(request.responseText.TrimStart("{}; ".ToCharArray()));
                }
            }

            if (response != null && values != null)
            {
                if (isDebug)
                {
                    //HandleLog(response);
                }

                if (!values.ContainsKey(JavaScript.ReturnedValueKey))
                {
                    values.Add(JavaScript.ReturnedValueKey, response);
                }
                else
                {
                    values[JavaScript.ReturnedValueKey] = response;
                }
            }
        }
Beispiel #3
0
        public virtual void Execute(object controller, Dictionary <string, Parameter> parameters, View view, Dictionary <string, object> values, DataRow prevRow, string pk, string connectionString, int currentUserId, string currentUserRole, IDbCommand command, IDbCommand sysCommand, string actionName, string arn, Durados.Security.Cloud.ICloudCredentials cloudCredentials, bool isLambda)
        {
            bool isDebug = IsDebug(values);

            string         url     = BaseUrl + "/invokeFunction";
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("POST", url, false);
            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("credentials", cloudCredentials.GetCredentials());
            data.Add("cloudProvider", cloudCredentials.GetProvider());
            data.Add("method", GetActionMethod());
            Dictionary <string, object> payload = GetCallLambdaPayload(controller, parameters, view, values, prevRow, pk, connectionString, currentUserId, currentUserRole, command);

            string folder      = view.Database.GetCurrentAppName();
            string functionArn = arn + folder + "_" + view.Name + "_" + actionName;

            if (isLambda)
            {
                functionArn = arn;
                payload     = GetCallLambdaPayloadExternal(controller, parameters, view, values, prevRow, pk, connectionString, currentUserId, currentUserRole, command);

                foreach (string key in values.Keys)
                {
                    string stripedKey = key.StripToken();
                    if (payload.ContainsKey(stripedKey))
                    {
                        throw new WorkflowEngineException("You can not add " + stripedKey + " parameter in the request body");
                    }

                    if (key != DebugKey)
                    {
                        payload.Add(stripedKey, values[key]);
                    }
                }
            }

            data.Add("payload", payload);
            data.Add("function", cloudCredentials.GetFunctionObject(functionArn));
            Guid requestId = Guid.NewGuid();

            if (isDebug)
            {
                if (!System.Web.HttpContext.Current.Items.Contains(JavaScript.GuidKey))
                {
                    System.Web.HttpContext.Current.Items.Add(JavaScript.GuidKey, requestId);
                }
                else
                {
                    requestId = (Guid)System.Web.HttpContext.Current.Items[JavaScript.GuidKey];
                }

                string appName  = (string)System.Web.HttpContext.Current.Items["appName"];
                string username = (string)System.Web.HttpContext.Current.Items["username"];
                string token    = (string)System.Web.HttpContext.Current.Request.Headers["authorization"];


                data.Add("backandRequest", new { id = requestId.ToString(), appName = appName, username = username, accessToken = token });

                data.Add("isProduction", false);
            }
            else
            {
                data.Add("isProduction", true);
            }

            request.setRequestHeader("content-type", "application/json");

            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            request.send(jss.Serialize(data));

            if (IsFunction(view))
            {
                FunctionResponse(request, jss, values, isDebug, requestId);
                return;
            }

            if (request.status != 200)
            {
                throw new NodeJsException(request.responseText.TrimStart("{}; ".ToCharArray()));
            }

            Dictionary <string, object> response = null;

            try
            {
                response = jss.Deserialize <Dictionary <string, object> >(request.responseText);
            }
            catch (Exception exception)
            {
                throw new Durados.DuradosException("Could not parse NodeJS response", exception);
            }

            if (response.ContainsKey(FunctionError))
            {
                if (response.ContainsKey(Payload))
                {
                    var responsePayload = response[Payload];
                    if (responsePayload is string)
                    {
                        IDictionary <string, object> responsePayloadError = null;
                        try
                        {
                            responsePayloadError = jss.Deserialize <Dictionary <string, object> >((string)responsePayload);
                        }
                        catch
                        {
                            throw new NodeJsException((string)responsePayload);
                        }
                        if (responsePayloadError.ContainsKey(ErrorMessage))
                        {
                            throw new NodeJsException(responsePayloadError[ErrorMessage].ToString());
                        }
                        else
                        {
                            throw new NodeJsException((string)responsePayload);
                        }
                    }
                    else
                    {
                        throw new NodeJsException(request.responseText.TrimStart("{}; ".ToCharArray()));
                    }
                }
                else
                {
                    throw new NodeJsException(request.responseText.TrimStart("{}; ".ToCharArray()));
                }
            }

            if (response != null && values != null)
            {
                if (isDebug)
                {
                    HandleLog(response, requestId);
                }

                CleanResponse(response);


                if (!values.ContainsKey(JavaScript.ReturnedValueKey))
                {
                    values.Add(JavaScript.ReturnedValueKey, response);
                }
                else
                {
                    values[JavaScript.ReturnedValueKey] = response;
                }
            }
        }