HasInstance() public method

Checks if an app with a specific instance ID exists
public HasInstance ( string instanceId ) : bool
instanceId string
return bool
示例#1
0
        /// <summary>
        /// Copy all information from the manifest into the new app instance
        /// and add it to the registry
        /// </summary>
        /// <param name="registry">the registry being visited</param>
        public override void VisitRegistry(Registry registry)
        {
            // Drop the connection if the instance ID is a duplicate
            if (registry.HasInstance(manifest.InstanceId))
            {
                failure = new ManifestFail("Instance ID " + manifest.InstanceId + " already in use", instance);
                return;
            }

            if (manifest.InstanceId != null)
            {
                instance.InstanceId = manifest.InstanceId;
            }
            instance.Name = manifest.Name;
            instance.Version = new Version(manifest.Version);
            instance.ApiVersion = (uint) manifest.API;
            instance.Description = manifest.Description;
            instance.DisplayName = manifest.DisplayName;
            foreach (string capability in manifest.Capabilities.Keys)
            {
                var c = new Capability(
                    capability,
                    new Version(manifest.Capabilities[capability])
                );
                instance.AddCapability(c);
            }
            foreach (string capability in manifest.Dependencies.Keys)
            {
                var c = new Capability(
                    capability,
                    new Version(manifest.Dependencies[capability])
                );
                instance.AddDependency(c);
            }
            registry.Register(instance);

            // We have to send the message to the instance on our own
            instance.AppStatus = Status.down;
            instance.Send("APP_MANIFEST_OK " + okMsg.Serialize());
            Log.Info(instance.DisplayName + " created with instance ID " + instance.InstanceId);
        }