Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new machine id.
        /// </summary>
        /// <param name="type">Machine type string</param>
        /// <param name="friendlyName">Friendly machine name</param>
        /// <param name="runtime">PSharpRuntime</param>
        internal MachineId(string type, string friendlyName, PSharpRuntime runtime)
        {
            Type    = type;
            Runtime = runtime;

            if (this.Runtime.IsTest())
            {
                this.Value = runtime.GenerateTestId();
                // Checks for overflow.
                Runtime.Assert(Value != ulong.MaxValue, "Detected MachineId overflow.");
            }

            if (string.IsNullOrWhiteSpace(friendlyName))
            {
                friendlyName = Runtime.GetFriendlyName(Type);
            }

            FriendlyName = friendlyName;
            Endpoint     = Runtime.NetworkProvider.GetLocalEndpoint();
            Name         = $"({Type})-{FriendlyName}";
        }