Esempio n. 1
0
        public bool AddLogEvents(WriteTransaction txn, WriteLogEvent logEvent)
        {
            var replicaValue = logEvent.LocallySaved.GetReplicaValue(_replicaId);

            if (!replicaValue.HasValue)
            {
                throw new ArgumentException(nameof(logEvent), $"VectorClock for the event is not properly prepared and empty for this replicaId: '{_replicaId}'");
            }

            return(txn.Add(_table, ToTableKey(replicaValue.Value), ToTableValue(logEvent)));
        }
        public void StartTest()
        {
            try
            {
                var requestUrls = HelperUtils.ReadXmlFromUrl(url);
                WriteLogEvent?.Invoke(string.Format("Get href count: {0}", requestUrls.Count));
                if (requestUrls != null && requestUrls.Any())
                {
                    IEnumerable <Task> tasks = from url in requestUrls select SendRequest(url);

                    var requestTask = tasks.ToArray();
                    Task.WaitAll(requestTask);
                }
                WriteLogEvent?.Invoke("Request done!");
            }
            catch (Exception ex)
            {
                WriteLogEvent?.Invoke(string.Format("Can not open this url:{0}{1}Exception:{2}", url, Environment.NewLine, ex.Message));
            }
        }
        public async Task SendRequest(string requestUrl)
        {
            try
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    var response = await httpClient.GetAsync(requestUrl);

                    var result = response.IsSuccessStatusCode;
                    WriteLogEvent?.Invoke(string.Format("Send request url: {0}, Result: {1}, ResponseCode:{2}", requestUrl, response.IsSuccessStatusCode ? "Success" : "Falied", response.StatusCode.ToString()));
                    if (!response.IsSuccessStatusCode)
                    {
                        WriteFaliedUrlEvent?.Invoke(requestUrl);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogEvent?.Invoke(string.Format("Send request url: {0}, Result: Failed, Because error has happend:{1}", requestUrl, ex.ToString()));
                WriteFaliedUrlEvent?.Invoke(requestUrl);
            }
        }
Esempio n. 4
0
 public TableValue ToTableValue(WriteLogEvent logEvent) => logEvent.ToByteArray();
Esempio n. 5
0
        public override UserInfo Login(string userName, string pass, string code = "")
        {
            try
            {
                HttpItem cookieItem = new HttpItem()
                {
                    Host      = GetHost(base.Url),
                    URL       = Url + "/ssid1?url=/",
                    Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
                    Method    = "GET",
                    UserAgent = "Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/71.0.3578.98Safari/537.36",
                    Cookie    = "ssid1=8f08f51f9c3a4f47d0a81569d0296baf; random=8135; affid=null",
                };
                var cookieRes = helper.GetHtml(cookieItem);
                var cookie    = cookieRes.Cookie;

                HttpItem loginItem = new HttpItem()
                {
                    Host      = GetHost(Url),
                    URL       = Url + "/web/rest/cashlogin?account=" + userName + "&password="******"application/json,text/plain,*/*",
                    Method    = "Post",
                    UserAgent = "Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/71.0.3578.98Safari/537.36",
                    Cookie    = cookie
                };
                var loginRes  = helper.GetHtml(loginItem);
                var obj       = JObject.Parse(loginRes.Html);
                var issuccess = obj["success"].ToString();
                if (issuccess.ToLower() != "true")
                {
                    WriteLogEvent.Invoke("登录失败:" + loginRes.Html); return(null);
                }
                var      agreenPar      = obj["message"].ToString();
                HttpItem agreenHtmlItem = new HttpItem()
                {
                    Host      = GetHost(Url),
                    URL       = Url + "/member/agreement?" + agreenPar,
                    Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
                    Method    = "GET",
                    UserAgent = "Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/71.0.3578.98Safari/537.36",
                    Cookie    = cookie
                };
                var agreeRes = helper.GetHtml(agreenHtmlItem);

                var date      = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                var timestamp = DateTimeTools.GetTimeStamp(date);

                agreeRes.Cookie = agreeRes.Cookie.Replace("HttpOnly,", "");
                agreeRes.Cookie = agreeRes.Cookie.Replace("HttpOnly", "");
                agreeRes.Cookie = agreeRes.Cookie + "_skin_=blue; defaultLT=SGFT; " + cookie + ";";
                base.Cookie     = agreeRes.Cookie;

                UserInfo userInfo = new UserInfo();
                userInfo.LoginCookie = agreeRes.Cookie;
                var balance = GetMoneyStr();
                userInfo.Money = Convert.ToDecimal(balance);
                userInfo.State = "登陆成功";
                WriteLogEvent.Invoke("会员登录成功");
                return(userInfo);
            }
            catch (Exception ee)
            {
                WriteLogEvent.Invoke("登录失败"); return(null);
            }
        }
Esempio n. 6
0
        public async ValueTask <bool> WriteLogAsync(WriteLogEvent logEvent)
        {
            await _eventBus.Publish(logEvent).ConfigureAwait(false);

            return(true);
        }
Esempio n. 7
0
        public bool WriteLog(WriteLogEvent logEvent)
        {
            _eventBus.Publish(logEvent);

            return(true);
        }
Esempio n. 8
0
        public async Task <ulong> SyncHandler(WriteLogEvent syncEvent)
        {
            var posn = syncEvent.LocallySaved.GetReplicaValue(_targetReplicaId);

            if (!posn.HasValue)
            {
                throw new EventLogException($"Broken syncEvent.LocallySaved during replication '{syncEvent.LocallySaved}'. For replica '{_targetReplicaId}'");
            }
            var pos = posn.Value;

            if (_cancellationToken.IsCancellationRequested)
            {
                return(pos);
            }

            switch (syncEvent.LoggedEventCase)
            {
            case WriteLogEvent.LoggedEventOneofCase.Updated:
                var addedOrUpdated = syncEvent.Updated;
                await _lmdb.WriteAsync(txn =>
                {
                    var addMetadata = new KvMetadata
                    {
                        Status        = Active,
                        Expiry        = addedOrUpdated.Expiry,
                        Action        = Replicated,
                        Originated    = syncEvent.Originated,
                        ValueMetadata = syncEvent.ValueMetadata,
                        CorrelationId = syncEvent.CorrelationId
                    };

                    var wasUpdated = _kvTable.Add(
                        txn,
                        new KvKey(addedOrUpdated.Key),
                        addMetadata,
                        new KvValue(addedOrUpdated.Value),
                        (key, vcOld, vcNew) => vcOld.Earlier(vcNew));
                    _replicationTable.SetLastPos(txn, _targetReplicaId, pos);
                    _kvTable.StatusTable.IncrementCounters(txn, replicatedAdds: 1);
                    // TODO: Should we do anything if the value wasn't updated? Maybe logging?
                }, false, true);

                break;

            case WriteLogEvent.LoggedEventOneofCase.Deleted:
                var deleted = syncEvent.Deleted;
                await _lmdb.WriteAsync(txn =>
                {
                    _updateClock(txn, _targetReplicaId, syncEvent.LocallySaved.GetReplicaValue(_targetReplicaId));
                    var delMetadata = new KvMetadata
                    {
                        Status              = KvMetadata.Types.Status.Deleted,
                        Expiry              = syncEvent.LocallySaved.TicksOffsetUtc.ToTimestamp(),
                        Action              = Replicated,
                        Originated          = syncEvent.Originated,
                        OriginatorReplicaId = syncEvent.OriginatorReplicaId,
                        CorrelationId       = syncEvent.CorrelationId,
                        ValueMetadata       = syncEvent.ValueMetadata,
                    };

                    var kvKey = new KvKey(deleted.Key);
                    _kvTable.Delete(txn, kvKey, delMetadata);
                    _replicationTable.SetLastPos(txn, _targetReplicaId, pos);
                    _kvTable.StatusTable.IncrementCounters(txn, replicatedDeletes: 1);
                    // TODO: Should we do anything if the value wasn't updated? Maybe logging?
                }, false, true);

                break;

            case WriteLogEvent.LoggedEventOneofCase.None:
                throw new ArgumentException("syncEvent", $"Unexpected LogEvent case: {syncEvent.LoggedEventCase}");

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(pos);
        }
Esempio n. 9
0
 /// <summary>
 /// Запуск события записи лога.
 /// </summary>
 /// <param name="message"> Сообщение лога. </param>
 public static void WriteLine(string message)
 {
     WriteLogEvent?.Invoke($@"{DateTime.Now} {message}");
 }