コード例 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            var settings = new ConnectionSettings(new Uri(URL.Get(context)));

            settings.ThrowExceptions(alwaysThrow: true);
            settings.PrettyJson();

            if (AuthenticationRequired.Get(context) == true)
            {
                settings.BasicAuthentication(Username.Get(context), Password.Get(context));
            }


            var esClient   = new ElasticClient(settings);
            var searchData = esClient.Search <UiPathESLog>(sd => sd
                                                           .Index(Index.Get(context))
                                                           .Size(MaxSize.Get(context))
                                                           .Query(q => q.
                                                                  Match(m => m
                                                                        .Field(f => f.processName)
                                                                        .Query(ProcessName.Get(context) == string.Empty ? "*" : ProcessName.Get(context))) &&
                                                                  q.
                                                                  Match(m => m
                                                                        .Field(f => f.robotName)
                                                                        .Query(RobotName.Get(context) == string.Empty ? "*" : RobotName.Get(context))) &&
                                                                  q
                                                                  .DateRange(r => r
                                                                             .Field(f => f.timeStamp)
                                                                             .GreaterThanOrEquals(StartTime.Get(context))
                                                                             .LessThanOrEquals(EndTime.Get(context)))));

            Logs.Set(context, searchData.Documents.ToArray());
        }
コード例 #2
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 searchData = lowlevelClient.Search <BytesResponse>(Index.Get(context), Type.Get(context), Query.Get(context));

                var responseBytes = searchData.Body;
                if (responseBytes == null)
                {
                    responseBytes = searchData.ResponseBodyInBytes;
                }

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

                Success = searchData.Success;

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

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

                ErrorMessage.Set(context, Error);
                Response.Set(context, Resp);
                Result.Set(context, Res);
            }
        }
コード例 #3
0
    protected override void OnPreInit(EventArgs e)
    {
        AuthenticationRequired AttrAuth = Utility.GetCustomAttribute <AuthenticationRequired>(this.GetType());

        if (AttrAuth != null && AttrAuth.Value)
        {
            if (!IsMember)
            {
                HttpContext.Current.Response.Redirect("Membership.aspx");
            }
        }
    }
コード例 #4
0
        private async Task <List <TResponse> > ExecuteRequest <TResponse>(Func <HttpClient, Task <HttpResponseMessage> > requestFunction, bool attemptReauthentication = true) where TResponse : IMessageBase
        {
            using (var handler = new HttpClientHandler()
            {
                CookieContainer = _cookieContainer
            })
                using (var client = new HttpClient(handler)
                {
                    BaseAddress = BaseUri, Timeout = Timeout
                })
                {
                    if (_hasSaneHttpClientValidationCallback)
                    {
                        var sslCallback = (SslCertificateValidation ? new HttpClientHandler().ServerCertificateCustomValidationCallback : (message, cert, chain, errors) => { return(true); });
                        handler.ServerCertificateCustomValidationCallback = sslCallback;
                    }

                    try
                    {
                        client.DefaultRequestHeaders.Referrer = client.BaseAddress;
                        try { client.DefaultRequestHeaders.Add("X-Csrf-Token", _cookieContainer.GetCookies(client.BaseAddress)["csrf_token"].Value); }
                        catch { }
                        var result = await requestFunction(client);

                        var json = await result.Content.ReadAsStringAsync();

                        List <TResponse> response = new List <TResponse>();
                        try
                        {
                            response = base.DeserializeResponseMessage <TResponse>(json);
                        }
                        catch (UnauthorizedAccessException)
                        {
                            if (attemptReauthentication)
                            {
                                AuthenticationRequired?.Invoke(this, new EventArgs());
                                return(await ExecuteRequest <TResponse>(requestFunction, false));
                            }
                        }

                        return(response);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("UniFi API Request Error", ex);
                    }
                }
        }
コード例 #5
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);


                    string data = @"{""doc"": " + JsonData.Get(context) + "}";
                    Console.WriteLine(data);
                    var updateData = lowlevelClient.Update <BytesResponse>
                                         (Index.Get(context), Type.Get(context), ID.Get(context), data);

                    var responseBytes = updateData.Body;
                    if (responseBytes == null)
                    {
                        responseBytes = updateData.ResponseBodyInBytes;
                    }

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

                    Success = updateData.Success;

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

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

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