Ejemplo n.º 1
0
        /// <summary>
        /// Actions on service start
        /// </summary>
        private static void OnStartEvent()
        {
            try
            {
                List <RunningInstance> instances = ServersWatcher.Instances;

                EC2Helper       ec2Helper = EC2Helper.Make();
                RunningInstance instance  = ec2Helper.GetCurrentInstance(instances);

                if (instance == null)
                {
                    return;
                }

                // Assign elastic IP if it is free and tag exists
                var tag = ec2Helper.GetElasticIpTag(instance);
                if (tag != null)
                {
                    ec2Helper.AssignElasticIpByTag(instance, tag);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, EventLogEntryType.Error);
                throw new Exception(ex.Message, ex);
            }
        }
Ejemplo n.º 2
0
        private static void ConsoleStartTest()
        {
            try
            {
                List <RunningInstance> instances = ServersWatcher.Instances;

                EC2Helper       ec2Helper = EC2Helper.Make();
                RunningInstance instance  = ec2Helper.GetCurrentInstance(instances);

                if (instance == null)
                {
                    return;
                }

                Console.WriteLine("Instance: {0}", ServersWatcher.GetInstanceName(instance));

                // Assign elastic IP if it is free and tag exists
                var tag = ec2Helper.GetElasticIpTag(instance);
                if (tag != null)
                {
                    Console.WriteLine("Tag value: {0}", tag.Value);
                    ec2Helper.AssignElasticIpByTag(instance, tag);
                }
                else
                {
                    Console.WriteLine("Tag not found");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }