private void HostMessageHandler(object sender, TopicArgs args)
        {
            if (args.DataObject is HostConfiguration)
            {
                HostConfiguration config = args.DataObject as HostConfiguration;

                //update it
                if (this.ContainsID(config.StationID))
                {
                    Host h = this[config.StationID];

                    lock (this.locker)
                    {
                        h.Config   = config;
                        h.Ip       = args.From.Address;
                        h.LastSeen = DateTime.Now;
                        h.Status   = HostStatus.OnLine;
                    }

                    NotifyUpdateHost(h);
                }
                else//add new
                {
                    var h = new Host {
                        Config = config, Ip = args.From.Address, LastSeen = DateTime.Now, Status = HostStatus.OnLine
                    };
                    this.InsertItem(0, h);

                    NotifyAddHost(h);
                }
            }
        }
        private void handler(object sender, TopicArgs args)
        {
            received = args.DataObject;
            System.Net.IPEndPoint ep = sender as System.Net.IPEndPoint;

            System.Diagnostics.Debug.WriteLine("received: from: " + args.From.ToString() + " Topic: " + args.Topic.ToString() + " msg: " + received.ToString());
            go.Set();
        }
 private void OnCenterQuery(object s, TopicArgs args)
 {
     if (args.DataObject is HostConfigurationQuery)
     {
         var cfg = new HostConfiguration(Configuration.Instance.GetStationID());
         cfg.CameraID = 2;
         cfg.Name     = Properties.Settings.Default.HostName;
         cfg.TotalStorageCapacityMB    = new FileSystemStorage(Properties.Settings.Default.OutputPath).GetTotalStorageMB();
         cfg.ReservedStorageCapacityMB = Configuration.Instance.GetReservedSpaceinMB();
         bus.Publish(Topics.HostReply, cfg, 3000);
     }
 }
Exemple #4
0
 /// <summary>
 /// Topic is being changed, this event happen before the topic is changed and if false is returned
 /// the topic change is ignored
 /// </summary>
 /// <param name="_TopicArgs"></param>
 /// <returns></returns>
 public virtual bool Hook_Topic(TopicArgs _TopicArgs)
 {
     return true;
 }
Exemple #5
0
    static Task <int> Main()
    {
        var config = new ConfigurationBuilder()
                     .AddUserSecrets(typeof(Program).Assembly)
                     .Build();

        var accountId = config.GetValue <string>("AccountId");
        var role      = config.GetValue <string>("Role");

        return(Deployment.RunAsync(() =>
        {
            var roleArn = Output.Format($"arn:aws:iam::{accountId}:role/{role}");

            var providerArgs = new ProviderArgs
            {
                Region = "eu-west-1",
                AssumeRole = new ProviderAssumeRoleArgs
                {
                    RoleArn = roleArn,
                    SessionName = "session"
                }
            };

            var provider = new Provider("sandboxEUWest1Provider", providerArgs);

            var options = new CustomResourceOptions
            {
                Provider = provider
            };

            // Worker SNS Notification
            var notificationTopicArgs = new TopicArgs
            {
                Name = "WorkerNotification",
            };
            var workerNotificationTopic = new Topic("workerNotification", notificationTopicArgs, options);

            // Lambda
            var functionType = typeof(Worker.Function);
            var handler = $"{functionType.Assembly.GetName().Name}::{functionType.FullName}::FunctionHandler";

            var function = new Function("WorkerFunction", new FunctionArgs
            {
                Name = "WorkerFunction",
                Runtime = "dotnetcore3.1",
                Environment = new FunctionEnvironmentArgs
                {
                    Variables = new InputMap <string>
                    {
                        { $"{Worker.Function.NotificationTopicArnKey}", workerNotificationTopic.Arn }
                    }
                },
                Code = new FileArchive("../Worker/bin/Release/netcoreapp3.1/publish"),
                ReservedConcurrentExecutions = 1,
                Handler = handler,
                Role = CreateLambdaRole(options).Arn,
                MemorySize = 512,
                Timeout = 60
            }, options);

            var permission = new Permission("WorkerSNSPermission", new PermissionArgs
            {
                Action = "lambda:InvokeFunction",
                Function = function.Arn,
                Principal = "sns.amazonaws.com",
                SourceArn = workerNotificationTopic.Arn,
            }, options);

            // Subscription
            var workerSubscription = new TopicSubscription("workerNotificationSubscription", new TopicSubscriptionArgs
            {
                Topic = workerNotificationTopic.Arn,
                Protocol = "lambda",
                Endpoint = function.Arn
            }, options);
        }));
    }