Example #1
0
        public IApplication RegisterApplication(IClientToken clientToken, string applicationName, string applicationVersionFingerprint)
        {
            if (clientToken == null)
            {
                throw new ArgumentNullException("clientToken");
            }
            if (applicationName == null)
            {
                throw new ArgumentNullException("applicationName");
            }

            var initiative = _repository.GetInitiativeByClientToken((ClientToken)clientToken);

            if (initiative == null)
            {
                throw new InvalidOperationException("Invalid client token.");
            }

            var application = initiative.ApplicationGroups.SelectMany(x => x.Applications).SingleOrDefault(x => x.Name == applicationName);

            if (application != null)
            {
                return(application);
            }

            var applicationGroup = GetDefaultApplicationGroup(initiative);

            application = new Application(Guid.NewGuid(), applicationName, DateTime.UtcNow, null, null);
            applicationGroup.Add(application);

            _repository.UpdateInitiative(initiative);

            return(application);
        }
        /// <summary>
        /// 添加List新方法,查找IUserClient类型
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public ClientToken Find(IClientToken other)
        {
            //if (other == null)
            //{
            //    throw new ArgumentNullException("不能传入空");
            //}
            //var find = base.Find((item) =>
            //{
            //    try
            //    {
            //        var b1 = item.Address.Equals(other.Address) ;
            //        var b2 = item.ServicePort == other.ServicePort;
            //        return b1 && b2;
            //    }
            //    catch (Exception e)
            //    {
            //        return false;
            //    }
            //});

            return(ClientTokenList.Find(this, other));
        }
        public static ClientToken Find(List <ClientToken> tokenList, IClientToken other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("不能传入空");
            }
            var find = tokenList.Find((item) =>
            {
                try
                {
                    var b1 = item.Address.Equals(other.Address);
                    var b2 = item.ServicePort == other.ServicePort;
                    return(b1 && b2);
                }
                catch (Exception e)
                {
                    return(false);
                }
            });

            return(find);
        }
Example #4
0
 public bool Equals(IClientToken other)
 {
     return(other.Address.Equals(this.Address) &&
            other.ServicePort == this.ServicePort);
 }