Esempio n. 1
0
        static internal async void StartMessageGeneratorAsync(int delayInMilliseconds)
        {
            // the name of the component and the topic happen to be the same here...
            const string PubsubComponentName = "receivemediapost";
            const string PubsubTopicName     = "receivemediapost";

            TimeSpan delay = TimeSpan.FromMilliseconds(delayInMilliseconds);

            DaprClientBuilder daprClientBuilder = new DaprClientBuilder();

            DaprClient client = daprClientBuilder.Build();

            while (true)
            {
                SocialMediaMessage message = GeneratePost();

                try
                {
                    Console.WriteLine("Publishing");
                    using (PublishCallTime.NewTimer())
                    {
                        await client.PublishEventAsync <SocialMediaMessage>(PubsubComponentName, PubsubTopicName, message);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Caught {0}", e.ToString());
                    PublishFailureCount.Inc();
                }

                await Task.Delay(delay);
            }
        }
Esempio n. 2
0
        private void wpfBTchatbutton_Click(object sender, RoutedEventArgs e)
        {
            Button             button  = (Button)sender;
            SocialMediaMessage message = (SocialMediaMessage)button.DataContext;

            IUser user = User.GetUserFromScreenName(message.Handle);
            ContactWitnessDialog witnessDialogue = new ContactWitnessDialog(user.Id);

            witnessDialogue.Show();
        }
Esempio n. 3
0
        public async Task <IActionResult> PostMessageBinding([FromBody] SocialMediaMessage message)
        {
            Console.WriteLine("enter messagebinding");

            var duration = DateTime.UtcNow - message.PreviousAppTimestamp;

            BindingDuration.Set(duration.TotalSeconds);

            Console.WriteLine($"{message.CreationDate}, {message.CorrelationId}, {message.MessageId}, {message.Message}, {message.Sentiment}");

            int    indexOfHash = message.Message.LastIndexOf('#');
            string hashTag     = message.Message.Substring(indexOfHash + 1);
            string key         = hashTag + "_" + message.Sentiment;

            var actorId = new ActorId(key);
            var proxy   = ActorProxy.Create <IHashTagActor>(actorId, "HashTagActor");

            Console.WriteLine($"Increasing {key}.");
            Exception ex = null;

            try
            {
                await proxy.Increment(key);

                Console.WriteLine($"Increasing {key} successful.");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Increasing {key} failed with {e}");
                ex = e;
                ActorMethodFailureCount.Inc();
            }

            if (ActorMethodFailureCount.Value > 10)
            {
                throw ex;
            }

            return(Ok(new HTTPResponse("Received")));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a grid showing message information.
        /// </summary>
        /// <param name="message">will be used to show info</param>
        /// <param name="maxWidth">maximum width used to calculate the height</param>
        /// <returns>a list of grids containing the information grid and the images</returns>
        private List <Grid> CreateMessagePanel(SocialMediaMessage message, double maxWidth)
        {
            List <Grid> grids = new List <Grid>();
            var         grid  = new Grid {
                Width = maxWidth, Margin = new Thickness(0, 8, 0, 0)
            };                                                                            // Margin between messages on the page

            for (int i = 0; i < 4; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });                                                                                              // Adding four automatic rows
            }
            for (int i = 0; i < 2; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Auto
                });                                                                                                   // Adding two automatic collumns
            }
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            AddTextRow(grid, 0, "Gebruiker", message.User);
            AddTextRow(grid, 1, "Twitter naam", message.Handle);
            AddTextRow(grid, 2, "Omschrijving", message.Message);
            AddTextRow(grid, 3, "Datum en tijd", $"{message.DateTime}");

            grid.DataContext = message;                                // Used to access the message later on for the images
            grid.Measure(new Size(maxWidth, double.PositiveInfinity)); // Required to calculate where to put it on the page
            grids.Add(grid);

            if (message.Media.Count > 0)
            {
                for (int i = 0; i < message.Media.Count; i++)
                {
                    Grid imageGrid = new Grid {
                        Width = maxWidth
                    };
                    imageGrid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = GridLength.Auto
                    });
                    imageGrid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });

                    var img1 = _images[message.Media[i].URL];
                    imageGrid.Children.Add(img1);
                    Grid.SetColumn(img1, 0);

                    if (++i < message.Media.Count)
                    {
                        imageGrid.ColumnDefinitions.Add(new ColumnDefinition {
                            Width = GridLength.Auto
                        });

                        var img2 = _images[message.Media[i].URL];
                        imageGrid.Children.Add(img2);
                        Grid.SetColumn(img2, 1);

                        // Calculating aspect ratios of images
                        var ar1 = img1.Source.Width / img1.Source.Height;
                        var ar2 = img2.Source.Width / img2.Source.Height;
                        var arm = ar1 + ar2; // Max aspect

                        // Percentage of total aspect times maxwidth gives the width for the given aspect ratio making the images equal height
                        img1.Width = ar1 / arm * maxWidth;
                        img2.Width = ar2 / arm * maxWidth;
                    }
                    else
                    {
                        img1.Width = maxWidth;
                    }

                    imageGrid.Measure(new Size(maxWidth, double.PositiveInfinity));
                    grids.Add(imageGrid);
                }
            }
            return(grids);
        }