예제 #1
0
        private static IEntityServices SetupConnection(int connectionId, string domainName)
        {
            ConnectionDto connection;

            using (var db = new TenantDb(ConnectionString.ForDomain(domainName)))
            {
                var conn = db.Connections.Single(x => x.ConnectionId == connectionId && x.IsActive);
                connection = new ConnectionDto
                {
                    ConnectionId = conn.ConnectionId,
                    Url = conn.Url.Trim(),
                    UserName = conn.UserName.Trim(),
                    Password = conn.Password.Trim()
                };
            }
            IAuthenticator authenticator = new Authentication();
            IOrganizationService organizationService = authenticator.Authenticate(new AuthenticationInformation
            {
                OrganizationUri = connection.Url,
                UserName = connection.UserName,
                Password = connection.Password
            });

            IEntityServices entityService = new EntityServices(organizationService);
            return entityService;
        }
예제 #2
0
        public SchedulerDto SaveScheduling(ApplicationContext context, SchedulerDto schedule)
        {
            using (var db = new TenantDb(ConnectionString.ForDomain(context.TenantDomainName)))
            {
                var sch = new Schedule
                {
                    Name = schedule.Name,
                    SourceConnectionId = schedule.SourceConnectionId,
                    TargetConnectionId = schedule.TargetConnectionId,
                    RegardingEntityName = schedule.RegardingEntityName,
                    SourceViewId = schedule.SourceViewId,
                    NotificationEmails = schedule.Emails,
                    IsActive = schedule.IsActive,
                    CreatedBy = context.UserId,
                    CreatedOn = DateTime.Now,
                    ModifiedBy = context.UserId,
                    ModifiedOn = DateTime.Now
                };

                db.Schedules.Add(sch);
                db.SaveChanges();

                schedule.ScheduleId = sch.ScheduleId;
                var excecution = new ExecutionDto
                {
                    ScheduleId = schedule.ScheduleId,
                    IsOnDemenad = false,
                    CreatedBy = schedule.CreatedBy
                };
                SaveExecution(context.TenantDomainName, excecution);

                MailService.SendMail(schedule.Emails, MailMessageType.SchedulerCreated);
                return schedule;
            }
        }
예제 #3
0
 public IEnumerable<ConnectionDto> GetConnectionsList(string domainName)
 {
     using (var db = new TenantDb(ConnectionString.ForDomain(domainName)))
     {
         var connections = db.Connections
             .Where(x => x.IsActive)
             .Select(x => new ConnectionDto
             {
                 ConnectionId = x.ConnectionId,
                 Name = x.Description,
                 ConnectionType = x.ConnectionType,
                 UserName = x.UserName,
                 Password = x.Password,
                 Url = x.Url
             })
             .ToList();
         return connections;
     }
 }
예제 #4
0
 public List<ConnectionDto> GetConnectionList(string domainName, ConnectionType type)
 {
     using (var db = new TenantDb(ConnectionString.ForDomain(domainName)))
     {
         var connections = db.Connections
             .Where(x => x.IsActive && x.ConnectionType == (int)type)
             .Select(x => new ConnectionDto
             {
                 ConnectionId = x.ConnectionId,
                 Name = x.Description,
                 ConnectionType = x.ConnectionType,
                 UserName = x.UserName,
                 Password = x.Password,
                 Url = x.Url,
                 ValidationStatus = x.ValidationStatus,
                 ValidationMessage = x.ValidationMessage,
                 IsActive = x.IsActive
             })
             .ToList();
         return connections;
     }
 }
예제 #5
0
        public ConnectionDto GetConnectionById(string domainName, int connectionId)
        {
            using (var db= new TenantDb(ConnectionString.ForDomain(domainName)))
            {
                var cnx = db.Connections
                    .Single(x => x.ConnectionId == connectionId && x.IsActive);

                var connection = new ConnectionDto
                    {
                        ConnectionId = cnx.ConnectionId,
                        Name = cnx.Description,
                        ConnectionType = cnx.ConnectionType,
                        UserName = cnx.UserName,
                        Password = cnx.Password,
                        Url = cnx.Url,
                        ValidationStatus = cnx.ValidationStatus,
                        ValidationMessage = cnx.ValidationMessage,
                        IsActive = cnx.IsActive
                    };
                return connection;
            }
        }
예제 #6
0
 public void SaveConnection(ApplicationContext context, ConnectionDto connection)
 {
     using (var db=new TenantDb(ConnectionString.ForDomain(context.TenantDomainName)))
     {
         var conn = new Connection
         {
             Description = connection.Name,
             ConnectionType = connection.ConnectionType,
             UserName = connection.UserName,
             Password = connection.Password,
             Url = connection.Url,
             ValidationStatus = connection.ValidationStatus,
             ValidationMessage = connection.ValidationMessage ?? String.Empty,
             CreatedOn = DateTime.Now,
             CreatedBy = context.UserId,
             ModifiedBy = context.UserId,
             ModifiedOn = DateTime.Now,
             IsActive = true
         };
         db.Connections.Add(conn);
         db.SaveChanges();
     }
 }
예제 #7
0
        public List<ExecutionDto> GetExecutions(string domainName)
        {
            using (var db = new TenantDb(ConnectionString.ForDomain(domainName)))
            {
                var execs = db.Excecutions
                    .Select(x => new ExecutionDto
                    {
                        ScheduleId = x.ScheduleId,
                        ScheduleName = x.Schedule.Name,
                        IsOnDemenad = x.IsOnDemand,
                        StartTime = x.StartTime,
                        EndTime = x.EndTime,
                        Status = (ExcecutionStatusEnum)x.Status,
                        ExecutionId = x.ExecutionId
                    })
                    .ToList();

                return execs;
            }
        }
예제 #8
0
        public void UpdateExecution(string domainName, int executionId, ExcecutionStatusEnum status)
        {
            using (var db = new TenantDb(ConnectionString.ForDomain(domainName)))
            {
                var exec = db.Excecutions
                    .Single(x => x.ExecutionId == executionId && x.Status < (int) status && x.IsActive);

                exec.Status = (int)status;
                exec.ModifiedOn = DateTime.Now;
                db.SaveChanges();

                if (status == ExcecutionStatusEnum.Finished)
                {
                    MailService.SendMail(exec.Schedule.NotificationEmails, MailMessageType.FileMovementFinished);
                }
            }
        }
예제 #9
0
 public void SaveExecution(string domainName, ExecutionDto excecution)
 {
     using (var db = new TenantDb(ConnectionString.ForDomain(domainName)))
     {
         var exec = new Excecution()
         {
             ScheduleId =  excecution.ScheduleId,
             IsOnDemand = excecution.IsOnDemenad,
             StartTime = DateTime.Now,
             Status = (int)ExcecutionStatusEnum.Created,
             IsActive = true,
             CreatedBy = excecution.CreatedBy,
             CreatedOn = DateTime.Now,
             ModifiedBy = excecution.CreatedBy,
             ModifiedOn = DateTime.Now
         };
         db.Excecutions.Add(exec);
         db.SaveChanges();
         excecution.ExecutionId = exec.ExecutionId;
     }
 }
예제 #10
0
        public List<SchedulerDto> GetSchedulers(string domainName)
        {
            using (var db = new TenantDb(ConnectionString.ForDomain(domainName)))
            {
                var schedulers = db.Schedules
                    .Where(x => x.IsActive)
                    .Select(x => new SchedulerDto
                    {
                        ScheduleId = x.ScheduleId,
                        Name = x.Name,
                        SourceConnectionId = x.SourceConnectionId,
                        SourceConnectionName = x.Connection.Description,
                        TargetConnectionId = x.TargetConnectionId,
                        TargetConnectionName = x.Connection1.Description,
                        RegardingEntityName = x.RegardingEntityName,
                        SourceViewId = x.SourceViewId,
                        Emails = x.NotificationEmails,
                        IsActive = x.IsActive
                    })
                    .OrderByDescending(x => x.ScheduleId)
                    .ToList();

                return schedulers;
            }
        }
예제 #11
0
        public bool HasTenantDb(Guid userId)
        {
            var user = GetUserAccountInformation(userId);
            try
            {
                using (var db = new TenantDb(ConnectionString.ForDomain(user.TenantDomain)))
                {
                    var test = db.Schedules.FirstOrDefault();
                    return true;
                }
            }
            catch (EntityException ex)
            {
                var inner = ex.InnerException as SqlException;
                if (inner != null && inner.Number == 4060)
                {
                    return false;
                }

                throw;
            }
        }