Example #1
0
        protected override void doRegister(RegisterMeta meta)
        {
            string directory = $"/meou/provider/{meta.getGroup()}/{meta.getName()}/{meta.getVersion()}";

            try
            {
                var result = configClient.ExistsAsync(directory).ConfigureAwait(false).GetAwaiter().GetResult();
                if (!result)
                {
                    configClient.CreateRecursiveAsync(directory, null, org.apache.zookeeper.CreateMode.PERSISTENT).ConfigureAwait(false).GetAwaiter().GetResult();
                }
            }
            catch (Exception e)
            {
                if (logger.IsEnabled(LogLevel.Warning))
                {
                    logger.LogWarning($"Create parent path failed, directory: {directory}, {e}.");
                }
            }

            try
            {
                string tempPath = $"{directory}/{meta.getHost()}:{meta.getPort()}:{meta.getWeight()}:{meta.getConnCount()}";

                // The znode will be deleted upon the client's disconnect.
                configClient.CreateEphemeralAsync(tempPath).Wait();
            }
            catch (Exception e)
            {
                if (logger.IsEnabled(LogLevel.Warning))
                {
                    logger.LogWarning($"Create register meta: {meta} path failed, {e}.");
                }
            }
        }
Example #2
0
        protected override void doSubscribe(ServiceMeta serviceMeta)
        {
            string           directory     = $"/meou/provider/{serviceMeta.getGroup()}/{serviceMeta.getName()}/{serviceMeta.getVersion()}";
            IZKChildListener childListener = new ZKChildListener();

            childListener.ChildChangeHandler = (parentPath, currentChilds) =>
            {
                var          list = new List <RegisterMeta>(currentChilds.Count);
                RegisterMeta temp = null;
                foreach (var child in currentChilds)
                {
                    temp = parseRegisterMeta($"{parentPath}/{child}");
                    list.Add(temp);
                }

                notify(serviceMeta, list);

                return(Task.CompletedTask);
            };

            //childListener.ChildCountChangedHandler = async (parentPath, currentChilds) =>
            //{
            //    await notify(serviceMeta, NotifyEvent.CHILD_ADDED, 1L, new List<RegisterMeta>());
            //};
            configClient.SubscribeChildChanges(directory, childListener);
        }
Example #3
0
        public virtual void connectToRegistryServer(string connectString)
        {
            System.Collections.Concurrent.BlockingCollection <OfflineListener> c = new BlockingCollection <OfflineListener>();

            this.thread = new Thread(() =>
            {
                while (!shutdown)
                {
                    RegisterMeta meta = null;
                    try
                    {
                        queue.TryTake(out meta);
                        //doRegister(meta);
                    }
                    catch (Exception e)
                    {
                        if (meta != null)
                        {
                            if (logger.IsEnabled(LogLevel.Warning))
                            {
                                logger.LogWarning($"Register [{meta.getServiceMeta()}] fail: { e}, will try again...");
                            }

                            queue.Add(meta);
                        }
                    }
                }
            });
        }
Example #4
0
 public void unregister(RegisterMeta meta)
 {
     //if (!queue.(item))
     //{
     //    doUnregister(meta);
     //}
     doUnregister(meta);
 }
Example #5
0
        public async Task <JsonResult> Send(string eventId, string fullName, string phoneNumber, string email, string address, int type, List <string> eventDays)
        {
            if (string.IsNullOrWhiteSpace(fullName))
            {
                return(Json(-1));
            }

            if (string.IsNullOrWhiteSpace(phoneNumber))
            {
                return(Json(-2));
            }

            var emailPattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";

            if (!string.IsNullOrWhiteSpace(email) && !Regex.IsMatch(email, emailPattern))
            {
                return(Json(-3));
            }

            if (string.IsNullOrWhiteSpace(address))
            {
                return(Json(-5));
            }

            if (eventDays == null || eventDays.Count == 0)
            {
                return(Json(-6));
            }

            var listEventDayRegister = new List <EventDayRegisterMeta>();

            foreach (var item in eventDays)
            {
                listEventDayRegister.Add(new EventDayRegisterMeta
                {
                    EventDayId = item,
                });
            }

            var requestUrl   = _configuration.GetApiUrl();
            var apiService   = _configuration.GetApiServiceInfo();
            var feedbackMeta = new RegisterMeta
            {
                FullName          = fullName,
                PhoneNumber       = phoneNumber,
                Email             = email,
                Address           = type == 1 ? address : "",
                Note              = type == 2 ? address : "",
                Role              = Constants.RegisterRole.WalkInGuest,
                EventDayRegisters = listEventDayRegister
            };

            var result = await new HttpClientService()
                         .PostAsync <ActionResultResponse <string> >($"{requestUrl.ApiGatewayUrl}/api/v1/events/events/client/{eventId}/registers", feedbackMeta);

            return(Json(result));
        }
Example #6
0
        public async Task <IActionResult> InsertRegisterClient(string id, [FromBody] RegisterMeta registerMeta)
        {
            var result = await _eventService.InsertAsync(id, registerMeta);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Example #7
0
        public async Task <IActionResult> InsertRegister(string id, [FromBody] RegisterMeta registerMeta)
        {
            var result = await _registerService.Insert(id, CurrentUser.Id, CurrentUser.FullName, CurrentUser.Avatar, registerMeta);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Example #8
0
        private IList <RegisterMeta> ConsumerRegisterMetaFactory(AssemblyPart part)
        {
            var types = part.Types;

            List <RegisterMeta> meta     = new List <RegisterMeta>();
            RegisterMeta        tempMeta = null;

            foreach (var typeInfo in types)
            {
                if (!typeInfo.IsInterface || typeInfo.IsPrimitive)
                {
                    continue;
                }

                foreach (var attr in typeInfo.CustomAttributes)
                {
                    if (attr.AttributeType.Name != "ServiceConsumerAttribute")
                    {
                        continue;
                    }

                    tempMeta = new RegisterMeta();

                    foreach (var arg in attr.NamedArguments)
                    {
                        switch (arg.MemberName)
                        {
                        case "name":
                            tempMeta.setName(arg.TypedValue.Value.ToString());
                            break;

                        case "group":
                            tempMeta.setGroup(arg.TypedValue.Value.ToString());
                            break;

                        case "version":
                            tempMeta.setVersion(arg.TypedValue.Value.ToString());
                            break;
                        }
                    }

                    meta.Add(tempMeta);
                }
            }

            return(meta);
        }
Example #9
0
        private RegisterMeta parseRegisterMeta(String data)
        {
            String[]     array_0 = data.Split('/');
            RegisterMeta meta    = new RegisterMeta();

            meta.setGroup(array_0[3]);
            meta.setName(array_0[4]);
            meta.setVersion(array_0[5]);

            String[] array_1 = array_0[6].Split(':');
            meta.setHost(array_1[0]);
            meta.setPort(Convert.ToInt32(array_1[1]));
            meta.setWeight(Convert.ToInt32(array_1[2]));
            meta.setConnCount(Convert.ToInt32(array_1[3]));

            return(meta);
        }
Example #10
0
        protected override void doUnregister(RegisterMeta meta)
        {
            string directory = $"/meou/provider/{meta.getGroup()}/{meta.getName()}/{meta.getVersion()}";

            try
            {
                var result = configClient.ExistsAsync(directory).ConfigureAwait(false).GetAwaiter().GetResult();
                if (result)
                {
                    return;
                }
            }
            catch (Exception e)
            {
                if (logger.IsEnabled(LogLevel.Warning))
                {
                    logger.LogWarning($"Check exists with parent path failed, directory: { directory},{e}.");
                }
            }

            try
            {
                //meta.setHost(address);
                string tempPath = $"{directory}/{meta.getHost()}:{meta.getPort()}:{meta.getWeight()}:{meta.getConnCount()}";

                // The znode will be deleted upon the client's disconnect.
                configClient.DeleteAsync(tempPath).ConfigureAwait(false).GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                if (logger.IsEnabled(LogLevel.Warning))
                {
                    logger.LogWarning($"Delete register meta: {meta} path failed, {e}.");
                }
            }
        }
Example #11
0
        public async Task <ActionResultResponse <string> > InsertAsync(string eventId, RegisterMeta registerMeta)
        {
            var infoEvent = await GetInfoEvent(eventId);

            if (infoEvent == null)
            {
                return(new ActionResultResponse <string>(-1, _websiteResourceService.GetString("Event does not exists. Please try again.")));
            }

            if (infoEvent.Status != ApproverStatus.Approved)
            {
                return(new ActionResultResponse <string>(-2, _websiteResourceService.GetString("Event not approved. Please try again.")));
            }


            var registerId = Guid.NewGuid().ToString();
            var register   = new Register
            {
                Id = registerId,
                ConcurrencyStamp = registerId,
                EventId          = eventId,
                Note             = registerMeta.Note,
                RegisterTime     = DateTime.Now,
                IsStaff          = registerMeta.IsStaff,
                CreatorId        = string.Empty,
                CreatorFullName  = string.Empty,
                CreatorAvatar    = string.Empty,
                UserId           = null,
                Role             = registerMeta.Role,
                Avatar           = registerMeta.Avatar,
            };

            switch (registerMeta.Role)
            {
            case RegisterRole.Employee:
                if (!string.IsNullOrEmpty(registerMeta.UserId))
                {
                    register.FullName    = registerMeta.FullName;
                    register.PhoneNumber = registerMeta.PhoneNumber;
                    register.Email       = registerMeta.Email;
                    register.Address     = registerMeta.Address;
                    register.UserId      = registerMeta.UserId;
                }
                break;

            case RegisterRole.Customer:
                if (!string.IsNullOrEmpty(registerMeta.UserId))
                {
                    register.FullName    = registerMeta.FullName;
                    register.PhoneNumber = registerMeta.PhoneNumber;
                    register.Email       = registerMeta.Email;
                    register.Address     = registerMeta.Address;
                    register.UserId      = registerMeta.UserId;
                }
                break;

            case RegisterRole.WalkInGuest:
            case RegisterRole.Invitation:
            case RegisterRole.Professional:
                register.FullName    = registerMeta.FullName;
                register.PhoneNumber = registerMeta.PhoneNumber;
                register.Email       = registerMeta.Email;
                register.Address     = registerMeta.Address;
                break;
            }

            var isExists = await CheckExistsRegister(registerId, eventId, register.FullName, register.PhoneNumber);

            if (isExists)
            {
                return(new ActionResultResponse <string>(-4, _websiteResourceService.GetString("Register name: \"{0}\" already exists.", register.FullName)));
            }

            var result = await InsertRegisterAsync(register);

            if (result <= 0)
            {
                return(new ActionResultResponse <string>(result, _websiteResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }

            #region insertEventDayRegister.
            if (registerMeta.EventDayRegisters != null && registerMeta.EventDayRegisters.Any())
            {
                var resultInsertEventDayRegister = await InsertEventDayRegister();

                if (resultInsertEventDayRegister.Code <= 0)
                {
                    return(resultInsertEventDayRegister);
                }
            }
            #endregion

            var listEventDay = await GetListEvenDayByEventId(eventId);

            foreach (var eventDay in listEventDay)
            {
                await UpdateTotalEventDay(eventDay.Id);
            }

            return(new ActionResultResponse <string>(1, _websiteResourceService.GetString("Add new register successful."),
                                                     string.Empty, eventId));

            async Task <ActionResultResponse <string> > InsertEventDayRegister()
            {
                var eventDayRegisters = new List <EventDayRegister>();

                foreach (var eventDayRegister in registerMeta.EventDayRegisters)
                {
                    var infoEventDay = await GetInfoEventDay(eventDayRegister.EventDayId);

                    var isAllowAccompanyPerson = infoEventDay.IsAllowAccompanyPerson ?? infoEvent.IsAllowAccompanyPerson;
                    var limitedUsers           = infoEventDay.LimitedUsers != null
                        ? infoEventDay.LimitedUsers
                        : infoEvent.LimitedUsers;
                    var limitedAccompanyUsers       = infoEventDay.LimitedAccompanyPersons ?? infoEvent.LimitedAccompanyPersons;
                    var isAllowRegisterWhenOverload = infoEvent.IsAllowRegisterWhenOverload;

                    // neu ko bat cho dang ky vuot qua so nguoi
                    if (!isAllowRegisterWhenOverload)
                    {
                        if (limitedUsers > 0)
                        {
                            var userCount = infoEventDay.TotalRegisters + registerMeta.EventDayRegisters.Count;
                            if (userCount > limitedUsers)
                            {
                                return(new ActionResultResponse <string>(-5,
                                                                         _websiteResourceService.GetString("Limited users when overload. Please contact with administrator.")));
                            }
                        }
                    }

                    var isEventDayRegisterExists = await CheckExistsEventDay(eventDayRegister.EventDayId, registerId);

                    if (isEventDayRegisterExists)
                    {
                        continue;
                    }
                    var eventDayRegisterInsert = new EventDayRegister
                    {
                        RegisterId = registerId,
                        EventDayId = eventDayRegister.EventDayId,
                        Status     = EventDayStatus.NotYet
                    };
                    eventDayRegisters.Add(eventDayRegisterInsert);

                    if (isAllowAccompanyPerson && eventDayRegister.AccompanyPersons != null && eventDayRegister.AccompanyPersons.Any())
                    {
                        var accompanyPersons = new List <AccompanyPerson>();
                        foreach (var accompanyPerson in eventDayRegister.AccompanyPersons)
                        {
                            if (limitedAccompanyUsers > 0)
                            {
                                var accompanyUserCount = eventDayRegister.AccompanyPersons.Count;
                                if (accompanyUserCount > limitedAccompanyUsers)
                                {
                                    return(new ActionResultResponse <string>(-6, _websiteResourceService.GetString("Accompany persons when overload. Please contact with administrator.")));
                                }
                            }

                            var accompanyPersonInsert = new AccompanyPerson
                            {
                                Id          = Guid.NewGuid().ToString(),
                                RegisterId  = registerId,
                                FullName    = accompanyPerson.FullName,
                                PhoneNumber = accompanyPerson.PhoneNumber,
                                EventDayId  = eventDayRegister.EventDayId,
                                Status      = EventDayStatus.NotYet
                            };
                            accompanyPersons.Add(accompanyPersonInsert);
                        }

                        foreach (var accompanyPerson in accompanyPersons)
                        {
                            await InsertAccompanyPersonAsync(accompanyPerson);
                        }
                    }
                }

                var resulteventDayRegister = 0;

                foreach (var eventDayRegister in eventDayRegisters)
                {
                    resulteventDayRegister = await InsertEventDayRegisterAsync(eventDayRegister);
                }

                if (resulteventDayRegister > 0)
                {
                    return(new ActionResultResponse <string>(1, _websiteResourceService.GetString("Add new event day register successful.")));
                }

                await RollbackInsertEventDayRegister();
                await RollbackInsertRegister();

                return(new ActionResultResponse <string>(-7, _websiteResourceService.GetString("Can not insert event day register. Please contact with administrator.")));
            }

            async Task RollbackInsertRegister()
            {
                await DeleteRegister(registerId);
            }

            async Task RollbackInsertEventDayRegister()
            {
                await DeleteEventDayRegister(registerId);
            }
        }
Example #12
0
        public async Task <ActionResultResponse> Update(string eventId, string lastUpdateUserId, string lastUpdateFullName, string lastUpdateAvatar,
                                                        string registerId, RegisterMeta registerMeta)
        {
            var infoEvent = await _eventRepository.GetInfo(eventId);

            if (infoEvent == null)
            {
                return(new ActionResultResponse(-1, _websiteEventResourceService.GetString("Event does not exists. Please try again.")));
            }

            var info = await _registerRepository.GetInfo(registerId);

            if (info == null)
            {
                return(new ActionResultResponse(-1, _websiteEventResourceService.GetString("Register does not exists.")));
            }

            if (info.EventId != eventId)
            {
                return(new ActionResultResponse(-2,
                                                _websiteEventResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            if (info.ConcurrencyStamp != registerMeta.ConcurrencyStamp)
            {
                return(new ActionResultResponse(-3,
                                                _websiteEventResourceService.GetString(
                                                    "The register already updated by other people. you are not allowed to edit the register information.")));
            }

            var apiUrls = _configuration.GetApiUrl();

            if (apiUrls == null)
            {
                return(new ActionResultResponse <string>(-4,
                                                         _sharedResourceService.GetString(
                                                             "Missing some configuration. Please contact with administrator.")));
            }

            switch (registerMeta.Role)
            {
            case RegisterRole.Employee:
                if (!string.IsNullOrEmpty(registerMeta.UserId))
                {
                    info.FullName    = registerMeta.FullName;
                    info.PhoneNumber = registerMeta.PhoneNumber;
                    info.Email       = registerMeta.Email;
                    info.Address     = registerMeta.Address;
                    info.UserId      = registerMeta.UserId;
                }
                break;

            case RegisterRole.Customer:
                if (!string.IsNullOrEmpty(registerMeta.UserId))
                {
                    var resultCustomer = await new HttpClientService()
                                         .GetAsync <CustomerViewModel>($"{apiUrls.CustomerApiUrl}/Customers/{infoEvent.TenantId}/{registerMeta.UserId}");

                    info.FullName    = resultCustomer.FullName;
                    info.PhoneNumber = resultCustomer.PhoneNumber;
                    info.Email       = resultCustomer.Email;
                    info.Address     = resultCustomer.Address;
                    info.UserId      = registerMeta.UserId;
                    info.Avatar      = registerMeta.Avatar;
                    info.Role        = registerMeta.Role;
                }
                else
                {
                    var resultCustomer = await new HttpClientService()
                                         .GetAsync <string>($"{apiUrls.CustomerApiUrl}/Customers/GetCustomerId/{infoEvent.TenantId}/{registerMeta.FullName}/{registerMeta.PhoneNumber}/{registerMeta.Email}/{registerMeta.Address}");

                    info.FullName    = registerMeta.FullName;
                    info.PhoneNumber = registerMeta.PhoneNumber;
                    info.Email       = registerMeta.Email;
                    info.Address     = registerMeta.Address;
                    info.UserId      = resultCustomer;
                }
                break;

            case RegisterRole.WalkInGuest:
            case RegisterRole.Invitation:
            case RegisterRole.Professional:
                info.FullName    = registerMeta.FullName;
                info.PhoneNumber = registerMeta.PhoneNumber;
                info.Email       = registerMeta.Email;
                info.Address     = registerMeta.Address;
                break;
            }

            info.Avatar             = registerMeta.Avatar;
            info.Role               = registerMeta.Role;
            info.Note               = registerMeta.Note;
            info.IsStaff            = registerMeta.IsStaff;
            info.ConcurrencyStamp   = Guid.NewGuid().ToString();
            info.LastUpdate         = DateTime.Now;
            info.LastUpdateUserId   = lastUpdateUserId;
            info.LastUpdateFullName = lastUpdateFullName;
            info.LastUpdateAvatar   = lastUpdateAvatar;

            var isExists =
                await _registerRepository.CheckExists(registerId, eventId, info.FullName, info.PhoneNumber);

            if (isExists)
            {
                return(new ActionResultResponse <string>(-5,
                                                         _websiteEventResourceService.GetString("Register name: \"{0}\" already exists.",
                                                                                                info.FullName)));
            }

            await _registerRepository.Update(info);

            #region UpdateEventDayRegister.
            if (registerMeta.EventDayRegisters.Count > 0)
            {
                var resultUpdateEventDayRegister = await UpdateEventDayRegister();

                if (resultUpdateEventDayRegister.Code <= 0)
                {
                    return(resultUpdateEventDayRegister);
                }
            }
            #endregion

            var listEventDay = await _eventDayRepository.GetListEvenDayByEventId(eventId);

            foreach (var eventDay in listEventDay)
            {
                await UpdateTotal(eventDay.Id);
            }
            return(new ActionResultResponse(1, _websiteEventResourceService.GetString("Update register successful.")));

            async Task <ActionResultResponse <string> > UpdateEventDayRegister()
            {
                await _eventDayRegisterRepository.DeleteByRegisterId(registerId);

                await _accompanyPersonRepository.DeleteByRegisterId(registerId);

                var eventDayRegisters = new List <EventDayRegister>();

                foreach (var eventDayRegister in registerMeta.EventDayRegisters)
                {
                    var infoEventDay = await _eventDayRepository.GetInfo(eventDayRegister.EventDayId);

                    var isAllowAccompanyPerson      = infoEventDay.IsAllowAccompanyPerson ?? infoEvent.IsAllowAccompanyPerson;
                    var limitedUsers                = infoEventDay.LimitedUsers ?? infoEvent.LimitedUsers;
                    var limitedAccompanyUsers       = infoEventDay.LimitedAccompanyPersons ?? infoEvent.LimitedAccompanyPersons;
                    var isAllowRegisterWhenOverload = infoEvent.IsAllowRegisterWhenOverload;

                    // neu ko bat cho dang ky vuot qua so nguoi
                    if (!isAllowRegisterWhenOverload)
                    {
                        if (limitedUsers > 0)
                        {
                            var userCount = infoEventDay.TotalRegisters + registerMeta.EventDayRegisters.Count;
                            if (userCount > limitedUsers)
                            {
                                return(new ActionResultResponse <string>(-6,
                                                                         _websiteEventResourceService.GetString(
                                                                             "Limited users when overload. Please contact with administrator.")));
                            }
                        }
                    }

                    var isEventDayRegisterExists =
                        await _eventDayRegisterRepository.CheckExists(eventDayRegister.EventDayId,
                                                                      registerId);

                    if (isEventDayRegisterExists)
                    {
                        continue;
                    }
                    var eventDayRegisterInsert = new EventDayRegister
                    {
                        RegisterId = registerId,
                        EventDayId = eventDayRegister.EventDayId,
                        Status     = EventDayStatus.NotYet
                    };
                    eventDayRegisters.Add(eventDayRegisterInsert);

                    if (isAllowAccompanyPerson)
                    {
                        var accompanyPersons = new List <AccompanyPerson>();
                        foreach (var accompanyPerson in eventDayRegister.AccompanyPersons)
                        {
                            if (limitedAccompanyUsers > 0)
                            {
                                var accompanyUserCount = eventDayRegister.AccompanyPersons.Count;
                                if (accompanyUserCount > limitedAccompanyUsers)
                                {
                                    return(new ActionResultResponse <string>(-7,
                                                                             _websiteEventResourceService.GetString(
                                                                                 "Accompany persons when overload. Please contact with administrator.")));
                                }
                            }

                            var accompanyPersonInsert = new AccompanyPerson
                            {
                                Id          = Guid.NewGuid().ToString(),
                                RegisterId  = registerId,
                                FullName    = accompanyPerson.FullName,
                                PhoneNumber = accompanyPerson.PhoneNumber,
                                EventDayId  = eventDayRegister.EventDayId,
                                Status      = EventDayStatus.NotYet
                            };
                            accompanyPersons.Add(accompanyPersonInsert);
                        }

                        await _accompanyPersonRepository.Inserts(accompanyPersons);
                    }
                }
                var resulteventDayRegister = await _eventDayRegisterRepository.Inserts(eventDayRegisters);

                if (resulteventDayRegister > 0)
                {
                    return(new ActionResultResponse <string>(resulteventDayRegister,
                                                             _websiteEventResourceService.GetString("Add new event day register successful.")));
                }

                return(new ActionResultResponse <string>(-8,
                                                         _websiteEventResourceService.GetString(
                                                             "Can not insert event day register. Please contact with administrator.")));
            }
        }
Example #13
0
 public void register(RegisterMeta meta)
 {
     queue.Add(meta);
     doRegister(meta);
 }
Example #14
0
 protected abstract void doUnregister(RegisterMeta meta);