private async Task ValidateEmailConfirmationNeeded(User user, IDto dto)
        {
            ValidateUserExists(user, dto);
            await ValidateEmailNotConfirmed(user, dto);

            ValidateUserNotLocked(user, dto);
        }
Esempio n. 2
0
        protected virtual bool IsFormChanged()
        {
            if (this.ListDto != null)
            {
                IDto oldDto  = this.CurrentDto;
                IDto newDto  = this.Dto;
                Type dtoType = oldDto.GetType();
                System.Reflection.PropertyInfo[] properties = dtoType.GetProperties();
                foreach (System.Reflection.PropertyInfo property in properties)
                {
                    object oldVar = dtoType.GetProperty(property.Name).GetValue(oldDto, null);
                    object newVar = dtoType.GetProperty(property.Name).GetValue(newDto, null);

                    if (oldVar == null && newVar == null)
                    {
                        continue;
                    }
                    if (oldVar != null && newVar == null)
                    {
                        return(true);
                    }
                    if (oldVar == null && newVar != null)
                    {
                        return(true);
                    }
                    if (!oldVar.Equals(newVar))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 3
0
 private void SendSingleDeleteRequest(IDto _dto)
 {
     if (_dto != null)
     {
         cvERepo.sendData(_dto, options);
     }
 }
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            JsonProperty property = base.CreateProperty(member, memberSerialization);

            if (typeof(IDto).IsAssignableFrom(property.DeclaringType))
            {
                if (property.PropertyName.ToLower() == nameof(IDto.ExcludedProperties).ToLower())
                {
                    property.ShouldSerialize = instance => false;
                }
                else
                {
                    property.ShouldSerialize = instance =>
                    {
                        IDto dto = instance as IDto;
                        if (dto.ExcludedProperties != null && dto.ExcludedProperties.Length > 0)
                        {
                            string lowerPropertyName = property.PropertyName.ToLower();
                            return(!dto.ExcludedProperties.Any(p => p.ToLower() == lowerPropertyName));
                        }
                        return(true);
                    };
                }
            }

            return(property);
        }
Esempio n. 5
0
 public bool Initialize(DtoBase rootDto, string path, IAuthenticationService authenticationService)
 {
     if (ListenPort < 1024)
     {
         return(false);
     }
     _rootDto = rootDto;
     _authenticationService = authenticationService;
     try
     {
         _listener = new TcpListener(IPAddress.Any, ListenPort)
         {
             ExclusiveAddressUse = true
         };
         _listenerThread = new Thread(ListenerThreadProc)
         {
             Name         = "Remote client session listener",
             IsBackground = true
         };
         _listenerThread.Start();
         return(true);
     }
     catch (Exception e)
     {
         Logger.Error(e, "Initialization of ServerHost error.");
     }
     return(false);
 }
Esempio n. 6
0
        protected void UpdateRelation <Tdto, Tentity>(IList <Tdto> dtos, IList <Tentity> entities)
            where Tdto : IDto
            where Tentity : CranEntity, IIdentifiable, new()
        {
            IEnumerable <int>           idsEntities      = entities.Select(x => x.Id);
            IEnumerable <int>           idsDtos          = dtos.Select(x => x.Id);
            IEnumerable <IIdentifiable> entitiesToDelete = entities.Where(x => idsDtos.All(id => id != x.Id)).Cast <IIdentifiable>();
            IEnumerable <IIdentifiable> entitiesToUpdate = entities.Where(x => idsDtos.Any(id => id == x.Id)).Cast <IIdentifiable>();
            IEnumerable <IIdentifiable> dtosToAdd        = dtos.Where(x => x.Id <= 0).Cast <IIdentifiable>();

            //Delete
            foreach (IIdentifiable entity in entitiesToDelete)
            {
                _context.Remove(entity);
            }

            //Update
            foreach (CranEntity entity in entitiesToUpdate)
            {
                IDto dto = dtos.Single(x => x.Id == entity.Id);
                CopyData(dto, entity);
            }

            //Add
            foreach (IDto dto in dtosToAdd)
            {
                Tentity entity = new Tentity();
                CopyData(dto, entity);
                _context.Set <Tentity>().Add(entity);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Update UserGroup data to Database
        /// </summary>
        /// <param name="updateDto">
        /// object that contains data to update
        /// </param>
        /// <returns>
        /// 0: insert successful
        /// others: Sql Exception
        /// </returns>
        public int UpdateData(IDto updateDto)
        {
            SYS_UserGroupsDao userGroupDao = new SYS_UserGroupsDao();
            SYS_UserGroupsDto dto          = (SYS_UserGroupsDto)updateDto;

            return(userGroupDao.UpdateData(dto));
        }
Esempio n. 8
0
        /// <summary>
        /// Insert Permission for UserGroup
        /// </summary>
        /// <param name="insertDto">
        /// object that contains data to insert
        /// </param>
        /// <returns>
        /// 0: insert successful
        /// others: Sql Exception
        /// </returns>
        public int InsertPermisionData(IDto insertDto)
        {
            SYS_UserGroupsDao userGroupDao = new SYS_UserGroupsDao();
            SYS_UserGroupsDto dto          = (SYS_UserGroupsDto)insertDto;

            return(userGroupDao.InsertPermissionData(dto));
        }
Esempio n. 9
0
        public int UpdatePassword(IDto userDto)
        {
            int returnCode = 0;

            try
            {
                SYS_ChangePasswordDto dto = (SYS_ChangePasswordDto)userDto;
                var mUser = this.ms_users.FirstOrDefault(m => m.Code == dto.UserCode && m.Password == dto.PasswordCurrent);
                if (mUser != null)
                {
                    mUser.Password = dto.PasswordNew;
                    this.Saves(CommonData.FunctionGr.SY_ChangePassword, CommonData.Action.Update,
                               new { mUser.Code, dto.PasswordCurrent, dto.PasswordNew },
                               typeof(ms_users).Name);
                }
                else
                {
                    returnCode = 9;
                }
            }
            catch (System.Exception ex)
            {
                returnCode = this.ProcessDbException(ex);
            }

            return(returnCode);
        }
Esempio n. 10
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="dto">The dto.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(WorkflowAction action, IDto dto, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            string activityTypeId = GetAttributeValue(action, "ActivityType");

            if (String.IsNullOrWhiteSpace(activityTypeId))
            {
                action.AddLogEntry("Invalid Activity Type Property");
                return(false);
            }

            var workflow = action.Activity.Workflow;

            var activityType = workflow.WorkflowType.ActivityTypes
                               .Where(a => a.Id.ToString() == activityTypeId).FirstOrDefault();

            if (activityType != null)
            {
                workflow.Activities.Add(WorkflowActivity.Activate(activityType, workflow));
                action.AddLogEntry(string.Format("Activated new '{0}' activity", activityType.ToString()));
                return(true);
            }

            action.AddLogEntry(string.Format("Could Not activate new '{0}' activity!", activityType.ToString()));
            return(false);
        }
Esempio n. 11
0
        public int SelectUsersByGroup(IDto selectDto, out DataTable dtUsers)
        {
            SYS_GroupsAssignDao groupAssignDao = new SYS_GroupsAssignDao();
            SYS_UserGroupsDto   userGroupsDto  = (SYS_UserGroupsDto)selectDto;

            return(groupAssignDao.SelectDataByGroup(userGroupsDto, out dtUsers));
        }
Esempio n. 12
0
        /// <summary>
        /// Processes this instance.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.SystemException"></exception>
        internal virtual bool Process(IDto dto, out List <string> errorMessages)
        {
            AddSystemLogEntry("Processing...");

            ActionComponent workflowAction = this.ActionType.WorkflowAction;

            if (workflowAction == null)
            {
                throw new SystemException(string.Format("The '{0}' component does not exist, or is not active", workflowAction));
            }

            this.ActionType.LoadAttributes();

            bool success = workflowAction.Execute(this, dto, out errorMessages);

            AddSystemLogEntry(string.Format("Processing Complete (Success:{0})", success.ToString()));

            if (success)
            {
                if (this.ActionType.IsActionCompletedOnSuccess)
                {
                    this.MarkComplete();
                }

                if (this.ActionType.IsActivityCompletedOnSuccess)
                {
                    this.Activity.MarkComplete();
                }
            }

            return(success);
        }
Esempio n. 13
0
        public MyNode(Node <IDto, string> baseNode)
        {
            Item = baseNode.Item;

            var tree = baseNode.Children.Connect()
                       .Transform(n => new MyNode(n))
                       .Sort(SortExpressionComparer <MyNode> .Ascending(node =>
            {
                switch (node.Item.DtoType)
                {
                case DtoType.Address:
                    return(Convert.ToInt32((((int)node.Item.DtoType).ToString() + node.Item.AddressId.ToString())));

                case DtoType.Project:
                    return(Convert.ToInt32((((int)node.Item.DtoType).ToString() + node.Item.AddressId.ToString() + (node.Item as ProjectDto).ProjectId.ToString())));

                case DtoType.Quotation:
                    return(Convert.ToInt32((((int)node.Item.DtoType).ToString() + node.Item.AddressId.ToString() + (node.Item as QuotationDto).QuotationId.ToString())));

                default:
                    return(node.Item.AddressId);
                }
            }))
                       .Bind(out _subItems)
                       .DisposeMany()
                       .Subscribe();
        }
Esempio n. 14
0
        public int CheckExistDataHaveIPAdd(IDto loginDto, out int iResult, out string message)
        {
            LoginDao loginDao = new LoginDao();
            LoginDto dto      = (LoginDto)loginDto;

            return(loginDao.CheckExistDataHaveIPAdd(dto, out iResult, out message));
        }
Esempio n. 15
0
 public bool Initialize(DtoBase rootDto, IPrincipalProvider principalProvider)
 {
     if (ListenPort < 1024)
     {
         return(false);
     }
     _rootDto           = rootDto;
     _principalProvider = principalProvider;
     try
     {
         _listener = new TcpListener(IPAddress.Any, ListenPort)
         {
             ExclusiveAddressUse = true
         };
         _listenerThread = new Thread(ListenerThreadProc)
         {
             Name         = $"Remote client session listener on port {ListenPort}",
             IsBackground = true
         };
         _listenerThread.Start();
         return(true);
     }
     catch (Exception e)
     {
         Logger.Error(e, "Initialization of {0} error.", this);
     }
     return(false);
 }
Esempio n. 16
0
        public void MapsEnumerableOfDtosUsingInterfaces()
        {
            IEnumerable <IDto> dtos = new IDto[]
            {
                new Dto1
                {
                    P0 = 10,
                    P1 = 11
                },
                new Dto2
                {
                    P0 = 20,
                    P2 = 22
                }
            };

            var domainObjects = this.mapper.Map <IEnumerable <IDomainType> >(dtos).ToArray();

            domainObjects.Length.ShouldBe(dtos.Count());

            var domainObject1 = domainObjects[0].ShouldBeOfType <DomainType1>();

            domainObject1.Prop0.ShouldBe(10);
            domainObject1.Prop1.ShouldBe(11);

            var domainObject2 = domainObjects[1].ShouldBeOfType <DomainType2>();

            domainObject2.Prop0.ShouldBe(20);
            domainObject2.Prop2.ShouldBe(22);
        }
Esempio n. 17
0
        /// <summary>
        /// The table name.
        /// </summary>
        /// <param name="dto">
        /// The dto.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static Tuple <string, int> TableNameColumnCount(this IDto dto)
        {
            var tableName   = ((TableNameAttribute)dto.GetType().GetCustomAttribute(typeof(TableNameAttribute), false)).Value;
            var columnCount = dto.GetColumnProperties().Count();

            return(new Tuple <string, int>(tableName, columnCount));
        }
Esempio n. 18
0
        /// <summary>
        /// Search Data in UserState table
        /// </summary>
        /// <param name="iDto">
        /// Dto of UserState form
        /// </param>
        /// <param name="dtResult">
        /// Out a Datatable that contains search result(all columns) in UserState table
        /// </param>
        /// <returns>
        /// 0: Update successful
        /// 1: Access denied, login to database fail(invalid username, invalid password)
        /// 2: Invalid host, cannot find server(host) that set in app config file
        /// 3: Invalid database, cannot find database that set in DbConfig file
        /// 4: Lost connection, cannot connect to database because lost connection
        /// 5: Duplicate key: insert Primary Key or Unique Key that already exist in database
        /// 6: Forgeign key not exist: insert a foreign key that not exist in primary key
        /// 7: Foreign Key Violation: Foreign Key Violation (delete primary key that is foreign key in other table)
        /// 8: Data not found: Delete or Update data that not exist in database
        /// 9: Exception occured: other exception
        /// </returns>
        public int SearchData(IDto searchDto, out DataTable dtResult)
        {
            SYS_UserStateDao dao = new SYS_UserStateDao();
            SYS_UserStateDto dto = (SYS_UserStateDto)searchDto;

            return(dao.SelectData(dto, out dtResult));
        }
        public ServerSession(TcpClient client, IAuthenticationService authenticationService, IDto initialObject) : base(client)
        {
            _initialObject     = initialObject;
            _delegates         = new ConcurrentDictionary <delegateKey, Delegate>();
            _serializer        = JsonSerializer.CreateDefault();
            _referenceResolver = new ReferenceResolver();
            _referenceResolver.ReferencePropertyChanged += _referenceResolver_ReferencePropertyChanged;
            _referenceResolver.ReferenceDisposed        += _referencedObjectDisposed;
            _serializer.ReferenceResolver = _referenceResolver;
            _serializer.TypeNameHandling  = TypeNameHandling.Objects;
            _serializer.Context           = new StreamingContext(StreamingContextStates.Remoting);
#if DEBUG
            _serializer.Formatting = Formatting.Indented;
#endif
            if (!(client.Client.RemoteEndPoint is IPEndPoint endPoint))
            {
                throw new UnauthorizedAccessException($"Client RemoteEndpoint {Client.Client.RemoteEndPoint} is invalid");
            }
            _sessionUser = authenticationService.FindUser(AuthenticationSource.IpAddress, endPoint.Address.ToString());
            if (_sessionUser == null)
            {
                throw new UnauthorizedAccessException($"Access from {Client.Client.RemoteEndPoint} not allowed");
            }
            StartThreads();
        }
        void _referencedObjectDisposed(object o, EventArgs a)
        {
            IDto dto = o as IDto;

            if (dto == null)
            {
                return;
            }
            var delegatesToRemove = _delegates.Keys.Where(k => k.Item1 == dto.DtoGuid);

            foreach (var dk in delegatesToRemove)
            {
                Delegate delegateToRemove;
                if (_delegates.TryRemove(dk, out delegateToRemove))
                {
                    EventInfo ei = dto.GetType().GetEvent(dk.Item2);
                    ei.RemoveEventHandler(dto, delegateToRemove);
                    Debug.WriteLine($"Server: Delegate {dk.Item2}  on {dto} removed;");
                }
            }
            WebSocketMessage message = new WebSocketMessage()
            {
                DtoGuid     = dto.DtoGuid,
                MessageType = WebSocketMessage.WebSocketMessageType.ObjectDisposed,
#if DEBUG
                DtoName = dto.ToString(),
#endif
            };

            Send(_serialize(message));
            Debug.WriteLine($"Server: ObjectDisposed notification on {dto} sent");
        }
Esempio n. 21
0
 public void RemoveReference(IDto dto)
 {
     if (_knownDtos.TryRemove(dto.DtoGuid, out var removed))
     {
         removed.PropertyChanged -= Dto_PropertyChanged;
     }
 }
 private async Task ValidatePasswordsMatch(User user, string password, IDto dto)
 {
     if (!await _userManager.CheckPasswordAsync(user, password))
     {
         Logger.LogWarning($"Login failed, dto:{dto.ToJson()}, user: {user.ToJson()}");
         throw new LocalException("Unauthorized", HttpStatusCode.Unauthorized);
     }
 }
Esempio n. 23
0
        /// <summary>
        /// Make a new model and inject dto values
        /// </summary>
        /// <typeparam name="TModel">The type of the model</typeparam>
        /// <param name="dto">The dto object that contains the property values</param>
        /// <returns>A new instance of TModel with the same property values of this dto</returns>
        public static TModel ToModel <TModel>(this IDto <TModel> dto)
            where TModel : class, new()
        {
            var model = new TModel();

            dto.UpdateModel(model);
            return(model);
        }
Esempio n. 24
0
        public int CheckLogin(IDto loginDto, out int iResult, out string employeeCode, out string displayName, out string skin)
        {
            LoginDao loginDao = new LoginDao();
            LoginDto dto      = (LoginDto)loginDto;

            dto.Password = UserSession.Md5(dto.Password);
            return(loginDao.CheckExistData(dto, out iResult, out employeeCode, out displayName, out skin));
        }
Esempio n. 25
0
        public int UpdateData(IDto updateDto)
        {
            SYS_ParameterDao dao = new SYS_ParameterDao();
            SYS_ParameterDto dto = (SYS_ParameterDto)updateDto;

            ConvertDataDto(ref dto);
            return(dao.UpdateData(dto));
        }
Esempio n. 26
0
 private void ValidateUserExists(User user, IDto dto)
 {
     if (user == null)
     {
         Logger.LogWarning($"User not found, dto:{dto.ToJson()}");
         throw new LocalException("NotFound", HttpStatusCode.NotFound);
     }
 }
Esempio n. 27
0
 private void ValidateRoleExists(Role role, IDto dto, User currentUser)
 {
     if (role == null)
     {
         Logger.LogWarning($"Role not found, currentUser:{currentUser.ToJson()}, dto:{dto.ToJson()}");
         throw new LocalException("NotFound", HttpStatusCode.NotFound);
     }
 }
Esempio n. 28
0
        //public int CheckLogin(IDto loginDto, out int iResult, out string employeeCode, out string displayName)
        //{
        //    LoginDao loginDao = new LoginDao();
        //    LoginDto dto = (LoginDto)loginDto;
        //    dto.Password = UserSession.Md5(dto.Password);
        //    return loginDao.CheckExistData(dto, out iResult, out employeeCode, out displayName);
        //}
        public int CheckExistDataHaveIPAdd(IDto loginDto, out int iResult, out string employeeCode, out string displayName, out string ipAddress, out string computerName)
        {
            LoginDao loginDao = new LoginDao();
            LoginDto dto      = (LoginDto)loginDto;

            dto.Password = UserSession.Md5(dto.Password);
            return(loginDao.CheckExistDataHaveIPAdd(dto, out iResult, out employeeCode, out displayName, out ipAddress, out computerName));
        }
Esempio n. 29
0
        public IList <CatalogDto> GetAcatalogFilter(IDto editableObject, TypeActionInSystem typeActionInSystem)
        {
            //            var result = new DomainGenerator()
            //                .With<AcatalogDto>(x => x.For(c => c.Name, new StringGenerator(1, 4, 'N', 'A'))).Many<AcatalogDto>(10);
            var result = Builder <CatalogDto> .CreateListOfSize(10).Build();

            return(result);
        }
 private void ValidateUserAllowed(User user, IDto dto)
 {
     if (user == null)
     {
         Logger.LogWarning($"User not found, dto:{dto.ToJson()}");
         throw new LocalException("Unauthorized", HttpStatusCode.Unauthorized);
     }
 }
Esempio n. 31
0
 public virtual void Transfer(IDto source)
 {
     IIdentityObject data = source as IIdentityObject;
     if (data != null)
     {
         // this.Id = data.Id;
         // this.ETag = data.ETag;
     }
 }
Esempio n. 32
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="dto">The dto.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute( WorkflowAction action, IDto dto, out List<string> errorMessages )
        {
            errorMessages = new List<string>();

            action.Activity.Workflow.MarkComplete();
            action.AddLogEntry( "Marked workflow complete" );

            return true;
        }
Esempio n. 33
0
 public virtual void Transfer(IDto source)
 {
     IEntityModelBase data = source as IEntityModelBase;
     if (data != null)
     {
         this.Id = data.Id;
         // this.ETag = data.ETag;
     }
 }
 public virtual void Transfer(IDto source)
 {
     base.Transfer(source);
     VersionableEntityModelBase vdata = source as VersionableEntityModelBase;
     if (vdata != null)
     {
         this.StartDate = vdata.StartDate;
         this.EndDate = vdata.EndDate;
     }
 }
Esempio n. 35
0
        public override void Transfer(IDto source)
        {
            IEmployee data = source as IEmployee;
            if (data != null)
            {
                this.EmpId = data.EmpId;
                this.FirstName = data.FirstName;
                this.LastName = data.LastName;

                this.SetSelfLink();
            }
        }
Esempio n. 36
0
 public override void Transfer(IDto source)
 {
     base.Transfer(source);
     ISkillset data = source as ISkillset;
     if (data != null)
     {
         this.Id = data.Id;
         this.ShortName = data.ShortName;
         this.LongName = data.LongName;
         this.Description = data.Description;
         this.SetSelfLink();
     }
 }
Esempio n. 37
0
 public override void Transfer(IDto source)
 {
     base.Transfer(source);
     IProject data = source as IProject;
      if (data != null)
      {
          this.Id = data.Id;
          this.ShortName = data.ShortName;
          this.LongName = data.LongName;
          this.Description = data.Description;
          this.ProjectStartDate = data.ProjectStartDate;
          this.ProjectEndDate = data.ProjectEndDate;
          this.SetSelfLink();
      }
 }
Esempio n. 38
0
        // [DataMember(Name = "lon")]
        // [JsonProperty(PropertyName = "lon")]
        // public long Longitude { get; set; }
        //
        // [DataMember(Name = "lat")]
        // [JsonProperty(PropertyName = "lat")]
        // public long Latitude { get; set; }
        public override void Transfer(IDto source)
        {
            base.Transfer(source);
            ILocation data = source as ILocation;
            if (data != null)
            {
                this.Id = data.Id;
                this.CountryId = data.CountryId;
                this.CountryName = data.CountryName;
                this.ShortName = data.ShortName;

                this.LongName = data.LongName;
                this.Description = data.Description;

                this.Coordinate = data.Coordinate;
                this.SetSelfLink();
            }
        }
Esempio n. 39
0
 /// <summary>
 /// Executes the specified workflow.
 /// </summary>
 /// <param name="action">The workflow action.</param>
 /// <param name="dto">The dto.</param>
 /// <param name="errorMessages">The error messages.</param>
 /// <returns></returns>
 public abstract Boolean Execute( WorkflowAction action, IDto dto, out List<string> errorMessages );
Esempio n. 40
0
        public override void Transfer(IDto source)
        {
            IEmployee data = source as IEmployee;
            if (data != null)
            {
                this.EmpId = data.EmpId;
                this.EmployeeFID = data.EmployeeFID;
                this.FirstName = data.FirstName;
                this.LastName = data.LastName;
                this.MiddleName = data.MiddleName;

                this.JoiningDate = data.JoiningDate;
                this.RelivedOn = data.RelivedOn;
                this.SetSelfLink();
            }
        }