Example #1
0
        protected override void Execute(CodeActivityContext context)
        {
            {
                String Error   = "";
                bool   Res     = false;
                bool   Success = false;
                String Resp    = "";

                try
                {
                    var node = new Uri(URL.Get(context));
                    ConnectionConfiguration config;

                    if (AuthenticationRequired.Get(context) == true)
                    {
                        config = new ConnectionConfiguration(node).BasicAuthentication(UserName.Get(context), Password.Get(context));
                    }
                    else
                    {
                        config = new ConnectionConfiguration(node);
                    }

                    var lowlevelClient = new ElasticLowLevelClient(config);

                    var insertData = lowlevelClient.IndexPut <BytesResponse>
                                         (Index.Get(context), Type.Get(context), ID.Get(context), JsonData.Get(context));

                    var responseBytes = insertData.Body;

                    if (responseBytes == null)
                    {
                        responseBytes = insertData.ResponseBodyInBytes;
                    }

                    Resp = Encoding.UTF8.GetString(responseBytes, 0, responseBytes.Length);

                    Success = insertData.Success;

                    if (Success == true)
                    {
                        Error = "";
                        Res   = true;

                        ErrorMessage.Set(context, Error);
                        Response.Set(context, Resp);
                        Result.Set(context, Res);
                    }
                    else
                    {
                        throw insertData.OriginalException;
                    }
                }
                catch (Exception ex)
                {
                    Error = "Failed to insert data to ElasticSearch. " + ex.Message;
                    Res   = false;

                    ErrorMessage.Set(context, Error);
                    Response.Set(context, Resp);
                    Result.Set(context, Res);
                }
            }
        }