Represents an instance of a role.
Inheritance: RuntimeBindingObject
示例#1
0
        public void RoleEnvironmentReturnsTheCurrentRoleInstanceWhichIsNotNull()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);

            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;

            Assert.NotNull(roleInstance);
        }
示例#2
0
        public void RoleEnvironmentReturnsTheCurrentRoleInstanceWhichIsNotNull()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime(typeof(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment).Assembly);
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;

            Assert.NotNull(roleInstance);
        }
        /// <summary>
        /// Initializes the current reader with respect to its environment.
        /// </summary>
        public void Initialize()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(AzureRoleEnvironmentContextReader.BaseDirectory);

            if (roleEnvironment.IsAvailable == true)
            {
                RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;
                if (roleInstance != null)
                {
                    this.roleInstanceName = roleEnvironment.CurrentRoleInstance.Id;
                    Role role = roleInstance.Role;
                    if (role != null)
                    {
                        this.roleName = role.Name;
                    }
                }
            }
        }