コード例 #1
0
        public Task Delete(SessionCollection sessionCollection)
        {
            lock (Lck)
            {
                _storage.Remove(sessionCollection.SessionId);
            }

            return Task.FromResult(0);
        }
コード例 #2
0
        public async Task<bool> Send(SessionCollection sessionCollection, string sharedKey)
        {
            using (var httpClient = new HttpClient())
            using (var request = this._httpMessageFormatter.GetRequestMessage(sessionCollection, sharedKey))
            {
                request.Method = HttpMethod.Post;
                request.RequestUri = CollectorUri;

                var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

                return response.StatusCode == System.Net.HttpStatusCode.OK;
            }            
        }        
コード例 #3
0
        private static byte[] ConvertToByteArray(SessionCollection sessionCollection)
        {
            var c = sessionCollection.Collection;

            var cbuilder = new Collection.Builder();

            cbuilder.DeviceId = c.DeviceId;

            cbuilder.ClientId = c.ClientId;

            cbuilder.Session = c.Session;

            cbuilder.SystemVersion = c.SystemVersion;

            cbuilder.ProductVersion = c.ProductVersion;

            cbuilder.System = c.System;

            cbuilder.ProductGitHash = c.ProductGitHash;

            foreach (var p in c.Payloads)
            {
                var pBuilder = new Payload.Builder();

                pBuilder.At = p.At;

                pBuilder.Event = p.Event;

                pBuilder.Nr = p.Nr;

                pBuilder.UserId = p.UserId;

                pBuilder.Ip = p.Ip;

                pBuilder.Parameters = p.Parameters;

                pBuilder.IsTesting = p.IsTesting;

                var payload = pBuilder.Build();

                cbuilder.AddPayloads(payload);
            }

            return cbuilder.Build().ToByteArray();
        }
コード例 #4
0
        public HttpRequestMessage GetRequestMessage(SessionCollection sessionCollection, string sharedKey)
        {
            var result = new HttpRequestMessage();

            var content = ConvertToByteArray(sessionCollection);

            result.Content = new ByteArrayContent(content);

            var ts = DateTime.UtcNow.GetEpochUtc();

            result.Headers.Add("X-Hamustro-Time", ts.ToString());

            result.Headers.Add("X-Hamustro-Signature", CalculateCollectorSignature(ts, content, sharedKey));

            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/protobuf");

            return result;
        }
コード例 #5
0
        public Task Add(SessionCollection sessionCollection)
        {
            lock (Lck)
            {
                if (_storage.ContainsKey(sessionCollection.SessionId))
                {
                    foreach (var ce in sessionCollection.Collection.Payloads)
                    {
                        _storage[sessionCollection.SessionId].Collection.Payloads.Add(ce);
                    }
                }
                else
                {
                    _storage.Add(sessionCollection.SessionId, sessionCollection);
                }
            }

            return Task.FromResult(0);
        }