/// <summary>
 /// Creates a license validator with specfied public key.
 /// </summary>
 /// <param name="publicKey">public key</param>
 protected AbstractLicenseValidator(string publicKey)
 {
     LeaseTimeout = TimeSpan.FromMinutes(5);
     discoveryHost = new DiscoveryHost();
     LicenseAttributes = new Dictionary<string, string>();
     nextLeaseTimer = new Timer(LeaseLicenseAgain);
     this.publicKey = publicKey;
     this.senderId = Guid.NewGuid();
     discoveryHost.ClientDiscovered += DiscoveryHostOnClientDiscovered;
     discoveryHost.Start();
 }
Example #2
0
		private void OnMultipleLicensesWereDiscovered(object sender, DiscoveryHost.ClientDiscoveredEventArgs clientDiscoveredEventArgs)
		{
			logger.Error("A duplicate license was found at {0} for user {1}. User Id: {2}. Both licenses were disabled!",
				clientDiscoveredEventArgs.MachineName,
				clientDiscoveredEventArgs.UserName,
				clientDiscoveredEventArgs.UserId);

			CurrentLicense = new LicensingStatus
			{
				Status = "AGPL - Open Source",
				Error = true,
				Message =
					string.Format("A duplicate license was found at {0} for user {1}. User Id: {2}.", clientDiscoveredEventArgs.MachineName,
								  clientDiscoveredEventArgs.UserName,
								  clientDiscoveredEventArgs.UserId)
			};
		}
        private void DiscoveryHostOnClientDiscovered(object sender, DiscoveryHost.ClientDiscoveredEventArgs clientDiscoveredEventArgs)
        {
            if (senderId == clientDiscoveredEventArgs.SenderId) // we got our own notification, ignore it
                return;
            if (UserId != clientDiscoveredEventArgs.UserId) // another license, we don't care
                return;

            // same user id, different senders
            switch (MultipleLicenseUsageBehavior)
            {
                case MultipleLicenseUsage.AllowSameLicense:
                    return;
                case MultipleLicenseUsage.AllowForSameUser:
                    if (Environment.UserName == clientDiscoveredEventArgs.UserName)
                        return;
                    break;
                case MultipleLicenseUsage.Deny:
                    if (Environment.UserName == clientDiscoveredEventArgs.UserName &&
                        Environment.MachineName == clientDiscoveredEventArgs.MachineName)
                        return;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("invalid MultipleLicenseUsageBehavior: " + MultipleLicenseUsageBehavior);
            }
            var client = discoveryClient;
            if (client != null)
            {
                client.PublishMyPresence();
            }
            RaiseLicenseInvalidated();
            var onMultipleLicensesWereDiscovered = MultipleLicensesWereDiscovered;
            if (onMultipleLicensesWereDiscovered != null)
            {
                onMultipleLicensesWereDiscovered(this, clientDiscoveredEventArgs);
            }
            else
            {
                throw new InvalidOperationException("Multiple licenses were discovered, but no one is handling the MultipleLicensesWereDiscovered event");
            }
        }
 /// <summary>
 /// Creates a license validator with specified public key.
 /// </summary>
 /// <param name="publicKey">public key</param>
 protected AbstractLicenseValidator(string publicKey)
 {
     LeaseTimeout = TimeSpan.FromMinutes(5);
     discoveryHost = new DiscoveryHost();
     LicenseAttributes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
     this.publicKey = publicKey;
     discoveryHost.ClientDiscovered += DiscoveryHostOnClientDiscovered;
     sntpClient = new SntpClient(TimeServers);
 }
 private void RaiseMultipleLicenseDiscovered(DiscoveryHost.ClientDiscoveredEventArgs args)
 {
     var onMultipleLicensesWereDiscovered = MultipleLicensesWereDiscovered;
     if (onMultipleLicensesWereDiscovered != null)
     {
         onMultipleLicensesWereDiscovered(this, args);
     }
 }
        private void DiscoveryHostOnClientDiscovered(object sender, DiscoveryHost.ClientDiscoveredEventArgs clientDiscoveredEventArgs)
        {
            if (senderId == clientDiscoveredEventArgs.SenderId) // we got our own notification, ignore it
                return;

            if (UserId != clientDiscoveredEventArgs.UserId) // another license, we don't care
                return;

            // same user id, different senders
            switch (MultipleLicenseUsageBehavior)
            {
                case MultipleLicenseUsage.AllowForSameUser:
                    if (Environment.UserName == clientDiscoveredEventArgs.UserName)
                        return;
                    break;
            }

            RaiseLicenseInvalidated();
            RaiseMultipleLicenseDiscovered(clientDiscoveredEventArgs);
        }
        private void SetupDiscoveryHost(bool enableDiscovery)
        {
            DiscoveryEnabled = enableDiscovery;

            if (!enableDiscovery) return;

            senderId = Guid.NewGuid();
            discoveryHost = new DiscoveryHost();
            discoveryHost.ClientDiscovered += DiscoveryHostOnClientDiscovered;
            discoveryHost.Start();
        }
		/// <summary>
		/// Creates a license validator with specified public key.
		/// </summary>
		/// <param name="publicKey">public key</param>
		protected AbstractLicenseValidator(string publicKey)
		{
			LeaseTimeout = TimeSpan.FromMinutes(5);
			discoveryHost = new DiscoveryHost();
			LicenseAttributes = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
			this.publicKey = publicKey;
			discoveryHost.ClientDiscovered += DiscoveryHostOnClientDiscovered;
		}
		private void DiscoveryHostOnClientDiscovered(object sender, DiscoveryHost.ClientDiscoveredEventArgs clientDiscoveredEventArgs)
		{
			if (senderId == clientDiscoveredEventArgs.SenderId) // we got our own notification, ignore it
				return;
			if (UserId != clientDiscoveredEventArgs.UserId) // another license, we don't care
				return;

			// same user id, different senders
			switch (MultipleLicenseUsageBehavior)
			{
				case MultipleLicenseUsage.AllowForSameUser:
					if (Environment.UserName == clientDiscoveredEventArgs.UserName)
						return;
					break;
			}
			var client = discoveryClient;
			if (client != null)
			{
				client.PublishMyPresence();			
			}
			RaiseLicenseInvalidated();
			var onMultipleLicensesWereDiscovered = MultipleLicensesWereDiscovered;
			if (onMultipleLicensesWereDiscovered != null)
			{
				onMultipleLicensesWereDiscovered(this, clientDiscoveredEventArgs);
			}
		}
		/// <summary>
		/// Creates a license validator with specfied public key.
		/// </summary>
		/// <param name="publicKey">public key</param>
		protected AbstractLicenseValidator(string publicKey)
		{
			LeaseTimeout = TimeSpan.FromMinutes(5);
			discoveryHost = new DiscoveryHost();
			LicenseAttributes = new Dictionary<string, string>();
			nextLeaseTimer = new Timer(LeaseLicenseAgain);
			this.publicKey = publicKey;
			discoveryHost.ClientDiscovered += DiscoveryHostOnClientDiscovered;
			try
			{
				discoveryHost.Start();
			}
			catch (Exception e)
			{
				// we explicitly don't want bad things to happen if we can't do that
				Logger.ErrorException("Could not setup node discovery", e);
			}
		}