public virtual MessageRouterResult AddEngagementAndClearPendingRequest(Party conversationOwnerParty, Party conversationClientParty)
        {
            MessageRouterResult result = new MessageRouterResult()
            {
                ConversationOwnerParty  = conversationOwnerParty,
                ConversationClientParty = conversationClientParty
            };

            if (conversationOwnerParty != null && conversationClientParty != null)
            {
                try
                {
                    EngagedParties.Add(conversationOwnerParty, conversationClientParty);
                    PendingRequests.Remove(conversationClientParty);
                    result.Type = MessageRouterResultType.EngagementAdded;
                }
                catch (ArgumentException e)
                {
                    result.Type         = MessageRouterResultType.Error;
                    result.ErrorMessage = e.Message;
                    System.Diagnostics.Debug.WriteLine($"Failed to add engagement between parties {conversationOwnerParty} and {conversationClientParty}: {e.Message}");
                }
            }
            else
            {
                result.Type         = MessageRouterResultType.Error;
                result.ErrorMessage = "Either the owner or the client is missing";
            }

            return(result);
        }
        public async Task Init()
        {
            PendingRequests.Clear();

            var id     = int.Parse(JWTService.DecodeJWT());
            var search = new Model.Requests.RequestSearchRequest
            {
                ShowInactive = false,
                StatusId     = (int)Models.Status.Pending
            };

            var requestList = await _requestService.GetAll <List <Request> >(search);

            foreach (var request in requestList)
            {
                var address = await _addressService.GetById <Address>(request.DeliveryAddress);

                var country = await _countryService.GetById <Country>((int)address.CountryId);

                var newRequest = new ClientDashboardRequest
                {
                    Address   = country.Name + ", " + address.ZipCode + ", " + address.City,
                    Date      = request.Date,
                    Price     = request.Price,
                    RequestId = request.RequestId
                };

                IsPendingVisible        = true;
                IsPendingMessageVisible = false;
                PendingRequests.Add(newRequest);
            }
            PendingHeight = PendingRequests.Count * 36;
        }
예제 #3
0
        public TopupRequestsResponse CreatePendingTopupsResponse(List <TopupRequestEN> requests)
        {
            TopupRequestsResponse response     = new TopupRequestsResponse();
            PendingRequests       requestsList = new PendingRequests();

            requestsList.PendingRequestsList = new List <TopupRequestItem>();

            try
            {
                foreach (var item in requests)
                {
                    TopupRequestItem req = new TopupRequestItem();
                    req.Amount         = Convert.ToString(item.Amount);
                    req.Date           = item.RequestDate;
                    req.DateGMT        = item.RequestDateISO;
                    req.Nickname       = item.ConsumerNickname;
                    req.OperatorName   = item.OperatorName;
                    req.PhoneNumber    = item.TargetPhone;
                    req.TopUpRequestID = item.TopupRequestID;
                    requestsList.PendingRequestsList.Add(req);
                }

                response.pendingRequests = requestsList;
                response.count           = requestsList.PendingRequestsList.Count;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
            }

            return(response);
        }
        public virtual MessageRouterResult AddPendingRequest(Party party)
        {
            MessageRouterResult result = new MessageRouterResult()
            {
                ConversationClientParty = party
            };

            if (party != null)
            {
                if (PendingRequests.Contains(party))
                {
                    result.Type = MessageRouterResultType.EngagementAlreadyInitiated;
                }
                else
                {
                    PendingRequests.Add(party);
                    result.Type = MessageRouterResultType.EngagementInitiated;
                }
            }
            else
            {
                result.Type         = MessageRouterResultType.Error;
                result.ErrorMessage = "The given party instance is null";
            }

            return(result);
        }
예제 #5
0
파일: Group.cs 프로젝트: vadian/Novus
        public void AddPlayerToGroup(string playerID)
        {
            if (!PlayerList.Contains(playerID))
            {
                InformPlayersInGroup(MySockets.Server.GetAUser(playerID).Player.FullName + " has joined the group.");

                PlayerList.Add(playerID);
                MySockets.Server.GetAUser(playerID).GroupName = GroupName;
                if (PendingInvitations.Contains(playerID))
                {
                    PendingInvitations.Remove(playerID);
                }
                if (PendingRequests.Contains(playerID))
                {
                    PendingRequests.Remove(playerID);
                }

                InformPlayerInGroup("You have joined '" + GroupName + "'.", playerID);
            }

            if (GroupRuleForLooting == GroupLootRule.Master_Looter && string.IsNullOrEmpty(MasterLooter))
            {
                MySockets.Server.GetAUser(LeaderID).MessageHandler("You have not yet assigned someone in the group as the master looter.");
            }
        }
        internal static void Request(MarketerDataRequest marketerDataRequest)
        {
            var cachedType = CachedRequests.FirstOrDefault(x => x.RawMarketType.id == marketerDataRequest.Id.ToString() && x.Region == marketerDataRequest.Region && x.SolarSystem == marketerDataRequest.SolarSystem);

            if (cachedType != null)
            {
                if (cachedType != null)
                {
                    var difference = marketerDataRequest.Timestamp - cachedType.Timestamp;
                    if (difference.TotalMinutes > 30)
                    {
                        CachedRequests.Remove(cachedType);
                    }
                    else
                    {
                        return;
                    }
                }
            }

            var pendingRequest = PendingRequests.FirstOrDefault(x => x.Id == marketerDataRequest.Id && x.Region == marketerDataRequest.Region && x.SolarSystem == marketerDataRequest.SolarSystem);

            if (pendingRequest != null)
            {
                return;
            }

            PendingRequests.Add(marketerDataRequest);

            if (PendingRequests.Count(x => x.Region == marketerDataRequest.Region && x.SolarSystem == marketerDataRequest.SolarSystem) >= 200)
            {
                Request(marketerDataRequest.Region, marketerDataRequest.SolarSystem);
            }
        }
예제 #7
0
        public async Task HttpStructuredClientSendTest()
        {
            var cloudEvent = new CloudEvent
            {
                Type                     = "com.github.pull.create",
                Source                   = new Uri("https://github.com/cloudevents/spec/pull/123"),
                Id                       = "A234-1234-1234",
                Time                     = SampleTimestamp,
                DataContentType          = MediaTypeNames.Text.Xml,
                Data                     = "<much wow=\"xml\"/>",
                ["comexampleextension1"] = "value",
                ["utf8examplevalue"]     = "æøå"
            };

            string ctx     = Guid.NewGuid().ToString();
            var    content = cloudEvent.ToHttpContent(ContentMode.Structured, new JsonEventFormatter());

            content.Headers.Add(TestContextHeader, ctx);

            PendingRequests.TryAdd(ctx, context =>
            {
                // Structured events contain a copy of the CloudEvent attributes as HTTP headers.
                var headers = context.Request.Headers;
                Assert.Equal("1.0", headers["ce-specversion"]);
                Assert.Equal("com.github.pull.create", headers["ce-type"]);
                Assert.Equal("https://github.com/cloudevents/spec/pull/123", headers["ce-source"]);
                Assert.Equal("A234-1234-1234", headers["ce-id"]);
                Assert.Equal("2018-04-05T17:31:00Z", headers["ce-time"]);
                // Note that datacontenttype is mapped in this case, but would not be included in binary mode.
                Assert.Equal("text/xml", headers["ce-datacontenttype"]);
                Assert.Equal("application/cloudevents+json; charset=utf-8", context.Request.ContentType);
                Assert.Equal("value", headers["ce-comexampleextension1"]);
                // The non-ASCII attribute value should have been URL-encoded using UTF-8 for the header.
                Assert.Equal("%C3%A6%C3%B8%C3%A5", headers["ce-utf8examplevalue"]);

                var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter());

                Assert.Equal(CloudEventsSpecVersion.V1_0, receivedCloudEvent.SpecVersion);
                Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
                Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
                Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
                AssertTimestampsEqual(SampleTimestamp, cloudEvent.Time.Value);
                Assert.Equal(MediaTypeNames.Text.Xml, receivedCloudEvent.DataContentType);
                Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);

                Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
                Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
                context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return(Task.CompletedTask);
            });

            var httpClient = new HttpClient();
            var result     = (await httpClient.PostAsync(new Uri(ListenerAddress + "ep"), content));

            if (result.StatusCode != HttpStatusCode.NoContent)
            {
                throw new InvalidOperationException(result.Content.ReadAsStringAsync().GetAwaiter().GetResult());
            }
        }
예제 #8
0
        public ActionResult CancelFriendRequest(int?id)
        {
            PendingRequests pendingRequest = db.PendingRequests.Find(id);

            db.PendingRequests.Remove(pendingRequest);
            db.SaveChanges();
            return(RedirectToAction("RequestFriend", "Friends"));
        }
예제 #9
0
파일: Group.cs 프로젝트: vadian/Novus
        public void RequestJoin(string playerID)
        {
            PendingRequests.Add(playerID);
            string message = string.Format("{0} requests permission to join the group.", MySockets.Server.GetAUser(playerID).Player.FullName);

            MySockets.Server.GetAUser(playerID).MessageHandler("Your request to join the group has been sent to the group leader.");
            InformGroupLeader(message);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            PendingRequests pendingRequests = db.PendingRequests.Find(id);

            db.PendingRequests.Remove(pendingRequests);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #11
0
        private void Update()
        {
            if (IsWaiting)
            {
                var curTime = Time.unscaledTime;

                foreach (var request in PendingRequests)
                {
                    if (request.Request.isDone)
                    {
                        if (!request.Silent)
                        {
                            Debug.Log("Request DONE: " + request.Request.url + " and the error return text is: " + request.Request.error + "; the returned text is: " + request.Request.text);
                        }

                        if (request.LifelineRequest)
                        {
                            if (request.Request.text == "Kill")
                            {
                                Debug.Log("Network system lifeline request response received; triggering application to kill itself");
                            #if UNITY_EDITOR
                                if (EditorApplication.isPlaying)
                                {
                                    EditorApplication.isPlaying = false;
                                }
                                else
                            #endif
                                System.Diagnostics.Process.GetCurrentProcess().Kill();
                            }
                            else
                            {
                                // This was a lifeline request whose >Unity WWW object has timed out.<  We have no control to set timeout on a WWW object
                                Debug.Log("Network system lifeline request's WWW object has timed out; creating a new request");
                                ResendRequest(request);
                            }
                        }
                    }
                    else
                    {
                        if (curTime - request.RequestStartTime > request.TimeoutSecs)
                        {
                            request.TimedOut = true;
                            if (!request.Silent)
                            {
                                Debug.Log("Request TIMED OUT after " + request.TimeoutSecs + " seconds: " + request.Request.url);
                            }
                        }
                    }
                }

                PendingRequests.RemoveAll(x => x.Request.isDone || x.TimedOut);

                if (PendingRequests.Count == 0)
                {
                    IsWaiting = false;
                }
            }
        }
        public virtual bool RemovePendingRequest(Party party)
        {
            if (party is EngageableParty)
            {
                (party as EngageableParty).ResetRequestMadeTime();
            }

            return(PendingRequests.Remove(party));
        }
예제 #13
0
        public virtual bool RemovePendingRequest(Party party)
        {
            if (party is PartyWithTimestamps)
            {
                (party as PartyWithTimestamps).ResetConnectionRequestTime();
            }

            return(PendingRequests.Remove(party));
        }
예제 #14
0
        public override void DeleteAll()
        {
            base.DeleteAll();

            AggregationParties.Clear();
            UserParties.Clear();
            BotParties.Clear();
            PendingRequests.Clear();
            ConnectedParties.Clear();
        }
        public async Task HttpStructuredClientReceiveTest()
        {
            string ctx = Guid.NewGuid().ToString();

            PendingRequests.TryAdd(ctx, async context =>
            {
                try
                {
                    var cloudEvent = new CloudEvent
                    {
                        Type                     = "com.github.pull.create",
                        Source                   = new Uri("https://github.com/cloudevents/spec/pull/123"),
                        Id                       = "A234-1234-1234",
                        Time                     = SampleTimestamp,
                        DataContentType          = MediaTypeNames.Text.Xml,
                        Data                     = "<much wow=\"xml\"/>",
                        ["comexampleextension1"] = "value",
                        ["utf8examplevalue"]     = "æøå"
                    };

                    await context.Response.CopyFromAsync(cloudEvent, ContentMode.Structured, new JsonEventFormatter());
                    context.Response.StatusCode = (int)HttpStatusCode.OK;
                }
                catch (Exception e)
                {
                    using (var sw = new StreamWriter(context.Response.OutputStream))
                    {
                        sw.Write(e.ToString());
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    }
                }

                context.Response.Close();
            });

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Add(TestContextHeader, ctx);
            var result = await httpClient.GetAsync(new Uri(ListenerAddress + "ep"));

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            Assert.True(result.IsCloudEvent());
            var receivedCloudEvent = await result.ToCloudEventAsync(new JsonEventFormatter());

            Assert.Equal(CloudEventsSpecVersion.V1_0, receivedCloudEvent.SpecVersion);
            Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
            Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
            Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
            AssertTimestampsEqual(SampleTimestamp, receivedCloudEvent.Time.Value);
            Assert.Equal(MediaTypeNames.Text.Xml, receivedCloudEvent.DataContentType);
            Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);

            Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
            Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
        }
예제 #16
0
파일: Group.cs 프로젝트: vadian/Novus
 public void CancelJoinRequest(string playerID)
 {
     if (PendingRequests.Contains(playerID))
     {
         PendingRequests.Remove(playerID);
     }
     else
     {
         MySockets.Server.GetAUser(playerID).MessageHandler("You never submitted a request to join this group.");
     }
 }
예제 #17
0
        public virtual void DeleteAll()
        {
            AggregationParties.Clear();
            UserParties.Clear();
            BotParties.Clear();
            PendingRequests.Clear();
            ConnectedParties.Clear();
#if DEBUG
            LastMessageRouterResults.Clear();
#endif
        }
예제 #18
0
        // GET: Vän
        public ActionResult StartIndex()
        {
            var db                = new ApplicationDbContext();
            var currentID         = User.Identity.GetUserId();
            var incommingRequests = db.VänFörfrågningar.Where(f => f.Person2 == currentID);
            var outgoingrequests  = db.VänFörfrågningar.Where(f => f.Person1 == currentID);
            var pending           = new PendingRequests {
                Incomming = incommingRequests.Count(), Outgoing = outgoingrequests.Count()
            };

            return(View(pending));
        }
예제 #19
0
        // GET: Friend
        // Startsidan för vänlistan/kontaktlistan.
        // Hämtar info om det finns inkommande eller utgående förfrågningar.
        public ActionResult Index()
        {
            var ctx               = new ProfileDbContext();
            var currentID         = User.Identity.GetUserId();
            var incommingRequests = ctx.FriendRequestModels.Where(f => f.Person2 == currentID);
            var outgoingrequests  = ctx.FriendRequestModels.Where(f => f.Person1 == currentID);
            var pending           = new PendingRequests {
                Incomming = incommingRequests.Count(), Outgoing = outgoingrequests.Count()
            };

            return(View(pending));
        }
 public ActionResult Edit([Bind(Include = "PendingRequestId,CustomerIdOne,CustomerIdTwo")] PendingRequests pendingRequests)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pendingRequests).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerIdTwo = new SelectList(db.Customers, "CustomerId", "FirstName", pendingRequests.CustomerIdTwo);
     ViewBag.CustomerIdOne = new SelectList(db.Customers, "CustomerId", "FirstName", pendingRequests.CustomerIdOne);
     return(View(pendingRequests));
 }
예제 #21
0
        public ActionResult AcceptFriendRequest(int?id)
        {
            Friend          addToFriendList = new Friend();
            PendingRequests pendingRequest  = db.PendingRequests.Find(id);

            addToFriendList.CustomerIdOne = pendingRequest.CustomerIdOne;
            addToFriendList.CustomerIdTwo = pendingRequest.CustomerIdTwo;
            db.Friends.Add(addToFriendList);
            db.PendingRequests.Remove(pendingRequest);
            db.SaveChanges();
            return(RedirectToAction("RequestFriend", "Friends"));
        }
예제 #22
0
        public async Task HttpBinaryClientSendTest()
        {
            var cloudEvent = new CloudEvent
            {
                Type                     = "com.github.pull.create",
                Source                   = new Uri("https://github.com/cloudevents/spec/pull/123"),
                Id                       = "A234-1234-1234",
                Time                     = SampleTimestamp,
                DataContentType          = MediaTypeNames.Text.Xml,
                Data                     = "<much wow=\"xml\"/>",
                ["comexampleextension1"] = "value",
                ["utf8examplevalue"]     = "æøå"
            };

            string ctx     = Guid.NewGuid().ToString();
            var    content = cloudEvent.ToHttpContent(ContentMode.Binary, new JsonEventFormatter());

            content.Headers.Add(TestContextHeader, ctx);

            PendingRequests.TryAdd(ctx, context =>
            {
                Assert.True(context.Request.IsCloudEvent());

                var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter());

                Assert.Equal(CloudEventsSpecVersion.V1_0, receivedCloudEvent.SpecVersion);
                Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
                Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
                Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
                AssertTimestampsEqual(SampleTimestamp, cloudEvent.Time.Value);
                Assert.Equal(MediaTypeNames.Text.Xml, receivedCloudEvent.DataContentType);

                // The non-ASCII attribute value should have been URL-encoded using UTF-8 for the header.
                Assert.True(content.Headers.TryGetValues("ce-utf8examplevalue", out var utf8ExampleValues));
                Assert.Equal("%C3%A6%C3%B8%C3%A5", utf8ExampleValues.Single());
                Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);

                Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
                // The non-ASCII attribute value should have been correctly URL-decoded.
                Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
                context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return(Task.CompletedTask);
            });

            var httpClient = new HttpClient();
            var result     = await httpClient.PostAsync(new Uri(ListenerAddress + "ep"), content);

            if (result.StatusCode != HttpStatusCode.NoContent)
            {
                throw new InvalidOperationException(result.Content.ReadAsStringAsync().GetAwaiter().GetResult());
            }
        }
        public Task ChangeStatus(long requestId, int currentStatusId, int newStatusId, string message)
        {
            var item = PendingRequests.First(it => it.Id == requestId);

            if (item.StatusId != currentStatusId)
            {
                var msg = string.Format("StatusId mismatch (expected: {0}, actual: {1})", currentStatusId, item.StatusId);
                throw new InvalidOperationException(msg);
            }

            item.StatusId = newStatusId;
            return(Task.CompletedTask);
        }
예제 #24
0
파일: Group.cs 프로젝트: vadian/Novus
        public void Disband(string message)
        {
            foreach (string playerID in PlayerList)
            {
                MySockets.Server.GetAUser(playerID).MessageHandler(message);
            }

            PendingInvitations.Clear();
            PendingRequests.Clear();
            PlayerList.Clear();
            LeaderID  = null;
            GroupName = null;
        }
        // GET: PendingRequests/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PendingRequests pendingRequests = db.PendingRequests.Find(id);

            if (pendingRequests == null)
            {
                return(HttpNotFound());
            }
            return(View(pendingRequests));
        }
예제 #26
0
        /// <summary>Performs a HTTP GET request. </summary>
        /// <param name="request">The <see cref="HttpGetRequest"/>. </param>
        /// <param name="token">The <see cref="CancellationToken"/>. </param>
        /// <param name="progress">The <see cref="IProgress{T}"/>. </param>
        /// <returns>The <see cref="HttpResponse"/>. </returns>
        public static async Task <HttpResponse> GetAsync(HttpGetRequest request, CancellationToken token, IProgress <HttpProgress> progress = null)
        {
            var uri     = GetQueryString(request, request.Query);
            var handler = CreateHandler(request, uri);

            using (var client = CreateClient(request, handler))
            {
                var result = new HttpResponse(request);
                result.HttpClient = client;
                lock (PendingRequests)
                    PendingRequests.Add(result);

                try
                {
                    var response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, token);
                    await CreateResponse(result, uri, request, handler, response, token, progress);

                    result.HttpStatusCode = response.StatusCode;
                    if (!response.IsSuccessStatusCode)
                    {
                        result.Exception = new HttpStatusException(response.StatusCode.ToString())
                        {
                            Result         = result,
                            HttpStatusCode = result.HttpStatusCode
                        }
                    }
                    ;
                }
                catch (Exception exception)
                {
                    if (result.Exception == null)
                    {
                        result.Exception = exception;
                        throw;
                    }
                }
                finally
                {
                    lock (PendingRequests)
                        PendingRequests.Remove(result);
                }

                if (result.Exception != null)
                {
                    throw result.Exception;
                }

                return(result);
            }
        }
예제 #27
0
        public ActionResult RequestFriend(FriendsViewModel model)
        {
            int             customerIdTwo = Int32.Parse(model.RequestedCustomerId);
            string          userId        = User.Identity.GetUserId();
            int             customerIdOne = (from x in db.Customers where x.UserId == userId select x.CustomerId).FirstOrDefault();
            PendingRequests request       = new PendingRequests();

            request.CustomerIdOne = customerIdOne;
            request.CustomerIdTwo = customerIdTwo;
            db.PendingRequests.Add(request);
            db.SaveChanges();

            return(RedirectToAction("RequestFriend", "Friends"));
        }
예제 #28
0
        public async Task HttpBinaryWebRequestSendTest()
        {
            var cloudEvent = new CloudEvent
            {
                Type                     = "com.github.pull.create",
                Source                   = new Uri("https://github.com/cloudevents/spec/pull/123"),
                Id                       = "A234-1234-1234",
                Time                     = SampleTimestamp,
                DataContentType          = MediaTypeNames.Text.Xml,
                Data                     = "<much wow=\"xml\"/>",
                ["comexampleextension1"] = "value",
                ["utf8examplevalue"]     = "æøå"
            };

            string         ctx            = Guid.NewGuid().ToString();
            HttpWebRequest httpWebRequest = WebRequest.CreateHttp(ListenerAddress + "ep");

            httpWebRequest.Method = "POST";
            await cloudEvent.CopyToHttpWebRequestAsync(httpWebRequest, ContentMode.Binary, new JsonEventFormatter());

            httpWebRequest.Headers.Add(TestContextHeader, ctx);

            PendingRequests.TryAdd(ctx, context =>
            {
                var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter());

                Assert.Equal(CloudEventsSpecVersion.V1_0, receivedCloudEvent.SpecVersion);
                Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
                Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
                Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
                AssertTimestampsEqual(SampleTimestamp, cloudEvent.Time.Value);
                Assert.Equal(MediaTypeNames.Text.Xml, receivedCloudEvent.DataContentType);
                Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);

                // The non-ASCII attribute value should have been URL-encoded using UTF-8 for the header.
                Assert.Equal("%C3%A6%C3%B8%C3%A5", context.Request.Headers["ce-utf8examplevalue"]);

                Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
                Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
                context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return(Task.CompletedTask);
            });

            var result = (HttpWebResponse)await httpWebRequest.GetResponseAsync();

            var content = new StreamReader(result.GetResponseStream()).ReadToEnd();

            Assert.True(result.StatusCode == HttpStatusCode.NoContent, content);
        }
예제 #29
0
        internal static void ProcessPendingRequests()
        {
            var done = false;

            while (!done)
            {
                done = true;
                var pendingRequest = PendingRequests.FirstOrDefault();
                if (pendingRequest != null)
                {
                    Request(pendingRequest.Region, pendingRequest.SolarSystem);
                    done = false;
                }
            }
        }
예제 #30
0
        public async Task HttpBinaryClientReceiveTest()
        {
            string ctx = Guid.NewGuid().ToString();

            PendingRequests.TryAdd(ctx, async context =>
            {
                var cloudEvent = new CloudEvent()
                {
                    Type            = "com.github.pull.create",
                    Source          = new Uri("https://github.com/cloudevents/spec/pull/123"),
                    Id              = "A234-1234-1234",
                    Time            = SampleTimestamp,
                    DataContentType = MediaTypeNames.Text.Xml,
                    // TODO: This isn't JSON, so maybe we shouldn't be using a JSON formatter?
                    // Further thought: separate out payload formatting from event formatting.
                    Data = "<much wow=\"xml\"/>",
                    ["comexampleextension1"] = "value",
                    ["utf8examplevalue"]     = "æøå"
                };

                await cloudEvent.CopyToHttpListenerResponseAsync(context.Response, ContentMode.Binary, new JsonEventFormatter());
                context.Response.StatusCode = (int)HttpStatusCode.OK;
            });

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Add(TestContextHeader, ctx);
            var result = await httpClient.GetAsync(new Uri(ListenerAddress + "ep"));

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);

            // The non-ASCII attribute value should have been URL-encoded using UTF-8 for the header.
            Assert.True(result.Headers.TryGetValues("ce-utf8examplevalue", out var utf8ExampleValues));
            Assert.Equal("%C3%A6%C3%B8%C3%A5", utf8ExampleValues.Single());

            var receivedCloudEvent = await result.ToCloudEventAsync(new JsonEventFormatter());

            Assert.Equal(CloudEventsSpecVersion.V1_0, receivedCloudEvent.SpecVersion);
            Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
            Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
            Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
            AssertTimestampsEqual(SampleTimestamp, receivedCloudEvent.Time.Value);
            Assert.Equal(MediaTypeNames.Text.Xml, receivedCloudEvent.DataContentType);
            Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);

            Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
            Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
        }