Example #1
0
        /// <summary>
        /// Reads the palette.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>PaletteDTO.</returns>
        private static PaletteDTO ReadPalette(SafeDataReader reader)
        {
            return new PaletteDTO
                       {
                           Id = reader.GetInt32(0),
                           Name = reader.GetString(1),

                           MainBackColor = (uint)reader.GetInt64(2),
                           MainFrontColor = (uint)reader.GetInt64(3),
                           StrongBackColor = (uint)reader.GetInt64(4),
                           StrongFrontColor = (uint)reader.GetInt64(5),
                           CalmBackColor = (uint)reader.GetInt64(6),
                           CalmFrontColor = (uint)reader.GetInt64(7),
                       };
        }
        public override void CopyNavigationMenu()
        {
            var values = new List<string>();
            const string commandText = @"
SELECT Id, Name, SystemName, LastModifiedOn, IconURL, Sequence, IconId from NavigationGroups
";
            using (var ctx = GetMetaDatabaseConnectionManager())
            {
                using (var cmd = new SqlCommand(commandText, ctx.Connection))
                {
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            values.Add(string.Format("({0},'{1}','{2}','{3}','{4}',{5},{6})", reader.GetInt32(0), reader.GetString(1), reader.GetString(2),
                                reader.GetDateTime(3).ToString("yyyy-MM-dd HH:mm:ss"), reader.GetString(4), reader.GetDouble(5), reader.IsDBNull(6) ? "NULL" : reader.GetInt32(6).ToString()));
                        }
                    }
                }
            }

            var script = string.Format(@"
  
SET IDENTITY_INSERT __NavigationGroup ON
MERGE INTO [dbo].[__NavigationGroup] AS TARGET USING (
    VALUES {0}
                                                     ) 
        AS Source([Id], [Name], [SystemName], [LastModifiedOn], [IconURL], [Sequence],[Icon]) ON TARGET.id = Source.Id -- update matched rows
 WHEN MATCHED THEN
UPDATE
SET [Name] = Source.[Name],
    [SystemName] = Source.[SystemName],
    [LastModifiedOn] = Source.[LastModifiedOn],
    [IconURL] = Source.[IconURL],
    [Sequence] = Source.[Sequence],
    [Icon] = Source.[Icon],
    [IsRemoved] = 0  -- insert new rows
 WHEN NOT MATCHED BY TARGET THEN
INSERT ([Id],
        [Name],
        [SystemName],
        [LastModifiedOn],
        [IconURL],
        [Sequence],
        [Icon],
        [IsRemoved])
VALUES ([Id],
        [Name],
        [SystemName],
        [LastModifiedOn],
        [IconURL],
        [Sequence],
        [Icon],
        0)

 -- delete rows that are in the target but not the source
WHEN NOT MATCHED BY SOURCE THEN
DELETE ;

SET IDENTITY_INSERT __NavigationGroup OFF
", string.Join(",", values));

            ExecuteSql(script);

            values.Clear();
            const string navItemsCommandText = @"
SELECT ni.id, 
       ni.guid, 
       ni.NAME, 
       p.systemname, 
       NULL, 
       ni.lastmodifiedon, 
       sequence, 
       navigationgroupid, 
       ni.[description], 
       c.[Color],
       ni.IconId
            
   
FROM   [dbo].[navigationitems] ni 
       INNER JOIN publishedprocesses pp 
               ON pp.id = ni.publishedprocessid 
       INNER JOIN processes p 
               ON pp.processid = p.id AND p.IsPublishedCopy = 1
       LEFT OUTER JOIN  colors as c on c.Id = p.[ColorId]
       WHERE p.IsRemoved = 0
      
";
            using (var ctx = GetMetaDatabaseConnectionManager())
            {
                using (var cmd = new SqlCommand(navItemsCommandText, ctx.Connection))
                {
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            values.Add(string.Format(CultureInfo.InvariantCulture, "({0}, '{1}', '{2}', '{3}', '{4}', '{5}', {6}, {7}, '{8}', {9}, {10})", reader.GetInt32(0), reader.GetGuid(1), Escape(reader.GetString(2)), reader.GetString(3), reader.GetString(4),
                                reader.GetDateTime(5).ToString("yyyy-MM-dd HH:mm:ss"), reader.GetDouble(6), reader.GetInt32(7), Escape(reader.GetString(8)), reader.GetInt64(9), reader.IsDBNull(10) ? "null" : reader.GetInt32(10).ToString()));
                        }
                    }
                }
            }

            if (values.Count == 0)
                return;

            script = string.Format(@"
  
SET IDENTITY_INSERT __NavigationItem ON
MERGE INTO [dbo].[__NavigationItem] AS TARGET USING (
    VALUES {0}
                                                     ) 
        AS Source([Id], [Guid], [Name], [SystemName], [IconURL], [LastModifiedOn], [Sequence], [NavigationGroupId], [Description], [ProcessColor], [IconId]) ON TARGET.id = Source.Id -- update matched rows
 WHEN MATCHED THEN
UPDATE
SET [Guid] = Source.[Guid],
    [Name] = Source.[Name],
    [SystemName] = Source.[SystemName],
    [IconURL] = Source.[IconURL],
    [LastModifiedOn] = Source.[LastModifiedOn],    
    [NavigationGroup] = Source.[NavigationGroupId],
    [Description] = Source.[Description],
    [Sequence] = Source.[Sequence], -- insert new rows
    [ProcessColor] = Source.[ProcessColor],
    [Icon] = Source.[Iconid]

 WHEN NOT MATCHED BY TARGET THEN
INSERT ([Id],
        [Guid],
        [Name],
        [SystemName],        
        [IconURL],
        [LastModifiedOn],
        [Sequence],
        [NavigationGroup],
        [Description],
        [ProcessColor],
        [IsRemoved],
        [Icon])
VALUES ([Id],
        [Guid],
        [Name],
        [SystemName],        
        [IconURL],
        [LastModifiedOn],
        [Sequence],
        [NavigationGroupId],
        [Description],
        [ProcessColor],
        0,
        [IconId])

 -- delete rows that are in the target but not the source
WHEN NOT MATCHED BY SOURCE THEN
DELETE ;

SET IDENTITY_INSERT __NavigationItem OFF  ", string.Join(",", values));

            ExecuteSql(script);

            //------------------------------------------------------
            values.Clear();
            const string navigationGroupSecurityConfigurationsScript = @"
SELECT ngscs.[id],       
       ngscs.[NavigationGroupId], 
       ngscs.[RoleId], 
       ngscs.[CanView]  
FROM   [dbo].[NavigationGroupSecurityConfigurations] ngscs";
            using (var ctx = GetMetaDatabaseConnectionManager())
            {
                using (var cmd = new SqlCommand(navigationGroupSecurityConfigurationsScript, ctx.Connection))
                {
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            values.Add(string.Format(CultureInfo.InvariantCulture, "({0}, '{1}', '{2}', '{3}')", reader.GetInt32(0),reader.GetInt32(1), reader.GetInt32(2), reader.GetBoolean(3)));
                        }
                    }
                }
            }


            if (values.Count == 0)
                return;

            script = string.Format(@"SET IDENTITY_INSERT __NavigationGroupSecurity ON
MERGE INTO [dbo].[__NavigationGroupSecurity] AS TARGET USING (
    VALUES {0}                                                     ) 
        AS Source([Id], [NavigationGroup], [RoleId], [CanView]) ON TARGET.id = Source.Id -- update matched rows
 WHEN MATCHED THEN
UPDATE
SET [NavigationGroup] = Source.[NavigationGroup],
    [RoleId] = Source.[RoleId],
    [CanView] = Source.[CanView]
   
 WHEN NOT MATCHED BY TARGET THEN
INSERT ([Id],
        [NavigationGroup],
        [RoleId],
        [CanView],
        [IsRemoved])
VALUES ([Id],
        [NavigationGroup],
        [RoleId],
        [CanView],
        0)

 -- delete rows that are in the target but not the source
WHEN NOT MATCHED BY SOURCE THEN
DELETE ;

SET IDENTITY_INSERT __NavigationGroupSecurity OFF  ", string.Join(",", values));
            ExecuteSql(script);


            //------------------------------------------------------
            values.Clear();
            const string navigationItemsSecurityConfigurationsScript = @"
SELECT ngscs.[id],       
       ngscs.[NavigationItemId], 
       ngscs.[RoleId], 
       ngscs.[CanView]  
FROM   [dbo].[NavigationItemSecurityConfigurations] ngscs";
            using (var ctx = GetMetaDatabaseConnectionManager())
            {
                using (var cmd = new SqlCommand(navigationItemsSecurityConfigurationsScript, ctx.Connection))
                {
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            values.Add(string.Format(CultureInfo.InvariantCulture, "({0}, '{1}', '{2}', '{3}')", reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetBoolean(3)));
                        }
                    }
                }
            }


            if (values.Count == 0)
                return;

            script = string.Format(@"SET IDENTITY_INSERT __NavigationItemSecurity ON
MERGE INTO [dbo].[__NavigationItemSecurity] AS TARGET USING (
    VALUES {0}                                                     ) 
        AS Source([Id], [NavigationItem], [RoleId], [CanView]) ON TARGET.id = Source.Id -- update matched rows
 WHEN MATCHED THEN
UPDATE
SET [NavigationItem] = Source.[NavigationItem],
    [RoleId] = Source.[RoleId],
    [CanView] = Source.[CanView]
   
 WHEN NOT MATCHED BY TARGET THEN
INSERT ([Id],
        [NavigationItem],
        [RoleId],
        [CanView],
        [IsRemoved])
VALUES ([Id],
        [NavigationItem],
        [RoleId],
        [CanView],
        0)

 -- delete rows that are in the target but not the source
WHEN NOT MATCHED BY SOURCE THEN
DELETE ;

SET IDENTITY_INSERT __NavigationItemSecurity OFF  ", string.Join(",", values));
            ExecuteSql(script);
        }
Example #3
0
        /// <summary>
        /// Retrieves publish history.
        /// </summary>
        /// <param name="processId">The process id.</param>
        /// <param name="numberOfRecords">The number of records.</param>
        /// <returns>The list of DTO objects.</returns>
        public IEnumerable<PublishHistoryDto> FetchPublishHistory(int processId, int numberOfRecords = 10)
        {
            const string Query = @"
SELECT TOP (@count)  Date ,
        Id ,
        IsSuccess ,
        ProcessId ,
        TimeToBuildClientLib ,
        TimeToBuildServerLib ,
        TimeToPublish ,
        TimeToRegisterPublishedCopy ,
        TimeToRetrieve ,
        TimeToUpdateRuntime ,
        TriggeredBy ,
        TriggeredByProcess FROM dbo.PublishHistory
WHERE ProcessId = @processId
ORDER BY Date DESC
";
            var result = new List<PublishHistoryDto>();
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                using (var cmd = new SqlCommand(Query, connection))
                {
                    cmd.Parameters.AddWithValue("@count", numberOfRecords);
                    cmd.Parameters.AddWithValue("@processId", processId);

                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        {
                            while (reader.Read())
                            {
                                var item = new PublishHistoryDto
                                               {
                                                   Date = reader.ReadDateTime(0),
                                                   IsSuccess = reader.GetBool(2),
                                                   ProcessId = reader.GetInt32(3),
                                                   TimeToPublish = reader.GetInt64(6)
                                               };

                                result.Add(item);
                            }
                        }
                    }
                }
            }

            return result;
        }
Example #4
0
        public IPagedList<ProcessInfoDTO> FetchList(string filter, int pageNumber, int pageSize, string filterExpression)
        {
            var result = new PagedList<ProcessInfoDTO>();

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;
                var sql = @"
DECLARE @p0 AS INT
SET @p0 = {1}

DECLARE @p1 AS INT
SET @p1 = {2};

SELECT [t1].[Id],
       [t1].[Name],
       [t1].[Description],
       [t1].[Icon],
       CASE
            WHEN [t1].PublishedCopyId IS NULL THEN 0
            ELSE 1
       END AS IsPublished,
       [t1].[SystemName],
       [t1].[Guid],
       [t1].[Color],
       [t1].IsInactive,
       [t1].IsSystem,
       [t1].[Documentation]
FROM   (
           SELECT ROW_NUMBER() OVER(ORDER BY [t0].[Name], [t0].[Id]) AS
                  [ROW_NUMBER],
                  [t0].[Name],
                  [t0].SystemName,
                  [t0].[Guid],
                  [t0].Id,
                  [t0].[Description],
                  [t0].[Documentation],
                  [t0].IsInactive,
                  [t0].IsSystem,
                  [i].Icon,
                  [c].Color,
                  (
                      SELECT id
                      FROM   Processes p
                      WHERE  p.Guid = [t0].Guid
                             AND p.IsPublishedCopy = 1
                             AND p.IsRemoved = 0
                  ) AS PublishedCopyId
           FROM   [dbo].[Processes] AS [t0]
                  LEFT OUTER JOIN Icons i
                       ON  [t0].IconId = [i].Id
                  LEFT OUTER JOIN Colors c
                       ON [t0].ColorId = [c].Id
           {0}
       ) AS [t1]
WHERE  [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1
ORDER BY
       [t1].[ROW_NUMBER]
";
                var fieldFilterWhere = AdoHelper.BuildFilterStatement(FilterDescriptor.GetFilterList(filterExpression), "Processes", tableAlias: "[t0]");
                var globalFilterWhere = AdoHelper.BuildFilterStatement(filter, new[] { "[t0].Name", "[t0].Description" });
                var where = string.Format(CultureInfo.InvariantCulture, "WHERE IsRemoved = 0 AND IsPublishedCopy = 0 {0} {1}", globalFilterWhere, fieldFilterWhere);

                if (pageSize == 0)
                {
                    pageSize = int.MaxValue;
                }

                var commandText = string.Format(CultureInfo.InvariantCulture, sql, where, pageNumber * pageSize, pageSize);

                using (var cmd = new SqlCommand(commandText, cn))
                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        result.Add(
                            new ProcessInfoDTO
                                {
                                    Id = reader.GetInt32(0),
                                    Name = reader.GetString(1),
                                    Description = reader.GetString(2),
                                    Icon = AdoHelper.ReadImage(reader, 3),
                                    IsPublished = reader.GetInt32(4) != 0,
                                    SystemName = reader.GetString(5),
                                    Guid = reader.GetGuid(6),
                                    ProcessColor = reader.GetInt64(7),
                                    IsInactive = reader.GetBool(8),
                                    IsSystem = reader.GetBool(9),
                                    ProcessDocumentation = reader.GetString(10),
                                });
                    }
                }

                sql = string.Format(CultureInfo.InvariantCulture, "SELECT TotalRowCount = (SELECT COUNT(t0.Id) FROM Processes [t0] {0}), TotalActiveRowCount = (SELECT COUNT(t0.Id) FROM dbo.Processes t0 {0} AND t0.IsInactive = 0 AND t0.SimpleProcess = 0)", where);

                using (var cmd = new SqlCommand(sql, cn))
                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        result.TotalRowCount = reader.GetInt32(0);
                        result.TotalActiveRowCount = reader.GetInt32(1);
                    }
                }
            }

            return result;
        }
Example #5
0
        /// <summary>
        /// Adds the navigation item.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="currentGroup">The current group.</param>
        private static void AddNavigationItem(SafeDataReader reader, NavigationGroupDTO currentGroup)
        {
            var navItemDto = new NavigationItemDTO
                                 {
                                     Id = reader.GetInt32(5),
                                     Name = reader.GetString(6),
                                     SystemName = reader.GetString(7),
                                     IconId = reader.GetNullableInt(8),
                                     IconUrl = reader.GetString(9),
                                     AssemblyName = reader.GetString(10),
                                     ProcessId = reader.GetNullableInt(11),
                                     ProcessSystemName = reader.GetString(13),
                                     Description = reader.GetString(17)
                                 };
            navItemDto.Description = navItemDto.ProcessId == null ? reader.GetString("HelpText") : reader.GetString(reader.GetOrdinal("Description"));
            navItemDto.BackgroundColor = reader.GetInt64(reader.GetOrdinal("BackgroundColor"));
            navItemDto.ProcessViewGuid = reader.GetNullableGuid(reader.GetOrdinal("ProcessViewGuid"));
            navItemDto.IsSystem = reader.GetNullableBool(reader.GetOrdinal("IsSystem"));
            navItemDto.IsBeta = reader.GetBoolean(reader.GetOrdinal("IsBeta"));
            var processName = reader.GetString(12);

            if (!string.IsNullOrEmpty(processName))
                navItemDto.Name = processName;

            currentGroup.NavigationItems.Add(navItemDto);
        }
Example #6
0
        /// <summary>
        /// Fetches the colors.
        /// </summary>
        /// <returns>IEnumerable{ColorInfoDto}.</returns>
        public IEnumerable<ColorInfoDto> FetchColors()
        {
            var result = new List<ColorInfoDto>();
            const string Sql = @"
SELECT
     [Id]
    ,[Color]
FROM
    [dbo].[Colors]
";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;
                if (cn.State != ConnectionState.Open)
                {
                    cn.Open();
                }

                using (var cmd = new SqlCommand(Sql, cn))
                {
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var dto = new ColorInfoDto { Id = reader.GetInt32(0), Color = reader.GetInt64(1) };
                            result.Add(dto);
                        }
                    }
                }
            }

            return result;
        }
Example #7
0
        /// <summary>
        /// Reads field backcolor rules.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="sr">The reader.</param>
        private static void ReadFieldBackcolorRules(ProcessEditDto process, SafeDataReader sr)
        {
            int? ruleId = null;
            ProcessActionRuleEditDto rule = null;

            sr.NextResult();

            while (sr.Read())
            {
                var dto = new FieldBackcolorRuleEditDto
                {
                    RuleId = sr.GetInt32(0),
                    RuleGuid = sr.GetGuid(1),
                    FieldGuid = sr.GetGuid(2),
                    BackColor = sr.GetInt64(3),
                    FieldSystemName = sr.GetString(4),
                    FieldName = sr.GetString(5)
                };

                if (dto.RuleId != ruleId)
                {
                    rule = process.ActionRules.First(r => r.Id == dto.RuleId);
                    ruleId = rule.Id;
                }

                rule.FieldBackcolorRules.Add(dto);
            }
        }
Example #8
0
        /// <summary>
        /// The read states.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="sr">The reader.</param>
        private static void ReadStates(ProcessEditDto process, SafeDataReader sr)
        {
            sr.NextResult();

            while (sr.Read())
            {
                var stateDto = new StateDto
                {
                    Id = sr.GetInt32(0),
                    Name = sr.GetString(1),
                    Documentation = sr.GetString(2),
                    DesignPositionLeft = sr.GetDouble(3),
                    DesignPositionTop = sr.GetDouble(4),
                    DesignDecisionPositionLeft = sr.GetDouble(5),
                    DesignDecisionPositionTop = sr.GetDouble(6),
                    Guid = sr.GetGuid(7),
                    MetaId = sr.GetInt32(8),
                    Color = sr.GetInt64("Color")
                };

                process.States.Add(stateDto);
            }

            ReadConnectors(process, sr);
        }
Example #9
0
        /// <summary>
        /// Fetches the system options.
        /// </summary>
        /// <returns>SystemOptionsDTO.</returns>
        public SystemOptionsDTO FetchSystemOptions()
        {
            const string Sql = @"
SELECT TOP 1 [SystemOptionsID]
	  ,[LastModifiedOn]
	  ,[LoginHTML]
	  ,[AuditLogin]
	  ,[AuditLogout]
	  ,[AnimateWindows]
	  ,[TempDocumentUNC]
	  ,[TempDocumentURI]
	  ,[PaperclipUNC]
	  ,[PaperclipURI]
	  ,[FileUploadURI]
	  ,[FileProcessorURI]
	  ,[InactivitySetting]
	  ,[InactivityMinutes]
	  ,[DaysBeforeAccountDisabled]
	  ,[DelayAfterInvalidLogin]
	  ,[DelayAfterInvalidLoginTimeout]
	  ,[InvalidLoginAttemptCount]
	  ,[InvalidLoginAttemptTime]
	  ,[DisableAccountSetting]
	  ,[InvalidLoginTimeout]
	  ,[SessionInactivityTimeoutAction]
	  ,[IsMandatoryPasswordChange]
	  ,[PasswordExpirationAction]
	  ,[PasswordExpirationDays]
	  ,[MinimumPasswordLength]
      ,[EnableSpecialChar]
      ,[EnableUpperLowerCase]
	  ,[PasswordHistoryCount]
	  ,[PasswordStrengthExpression]
	  ,[NotifyLastSucccessfulLogin]
	  ,[NotifyLastUnsucccessfulLogin]
	  ,[NotifyUserLastLoginAttempts]
	  ,[NotifyLastLoginAttemptsDays]
	  ,[NotifyUserSecurityChanges]
	  ,[SMTPServer]
	  ,[SMTPPort]
      ,[SMTPUseSsl]
	  ,[SMTPUseAuth]
	  ,[SMTPAuthName]
	  ,[SMTPAuthPass]
	  ,[EmailFromAddress]
      ,[EmailFromCurrentUser]
      ,[ReportsPath]
      ,[IsUnderMaintenance]
      ,[Theme]
      ,[AllowRememberMe]
      ,[MaxFileSize]
      ,[ShowWarningMessage]
      ,[WarningMessage]
      ,[WarningCaption]
      ,[ShowInfoMessage]
      ,[InfoMessage]
      ,[InfoCaption]
      ,[ShowSuccessMessage]
      ,[SuccessMessage]
      ,[SuccessCaption]
      ,[RestrictExportTo]
      ,[DisableSearchGrouping]
      ,[DisableSearchAll]
  FROM [dbo].[SystemOptions]

SELECT TOP 1
	   sso.[IsEnabled] AS SSOEnabled
      ,sso.[AllowSSOApproval]
      ,sso.[SAMLVersion]
      ,sso.[Issuer] AS SSOIssuer
      ,sso.[IdPTargetUrl]
      ,sso.[IdPLogoutUrl]
      ,CASE LEN(sso.IDPCertificate) WHEN 0 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END AS HasNoSSOCertificate
FROM  [dbo].[SSOOptions] sso

SELECT 
    ldap.[Id]
   ,ldap.[Name]
   ,ldap.[ServerType]
   ,ldap.[UseForLogin]
   ,ldap.[ServerPath]
   ,ldap.[Username]
   ,ldap.[Password]
   ,ldap.[RootPath]
   ,ldap.[SearchFilter]
   ,ldap.[UseSSL]
FROM [dbo].[LdapProfiles] ldap
";
/*
   SELECT  id ,
           Body ,
           Header ,
           Date
   FROM    dbo.news
   ORDER BY Date DESC
*/


            SystemOptionsDTO dto = null;

            Database.GetDataReader(
                Sql,
                reader =>
                    {
                        if (reader == null)
                        throw new DataAccessException(Resources.FailedToRetrieveSystemOptions);

                if (!reader.Read())
                {
                    dto = new SystemOptionsDTO { InactivityMinutes = 1, MinimumPasswordLength = 1};
                    InsertSystemOptions(dto);
                }
                else
                {
                    using (var sr = new SafeDataReader(reader))
                    {
                        dto = new SystemOptionsDTO
                            {
                                SystemOptionsId = sr.GetInt("SystemOptionsID"),
                                LoginHtml = sr.GetString("LoginHTML"),
                                AuditLogin = sr.GetBool("AuditLogin"),
                                AuditLogout = sr.GetBool("AuditLogout"),
                                AnimateWindows = sr.GetBool("AnimateWindows", true),
                                TempDocumentUNC = sr.GetString("TempDocumentUNC"),
                                TempDocumentURI = sr.GetString("TempDocumentURI"),
                                PaperclipUNC = sr.GetString("PaperclipUNC"),
                                PaperclipURI = sr.GetString("PaperclipURI"),
                                FileUploadURI = sr.GetString("FileUploadURI"),
                                FileProcessorURI = sr.GetString("FileProcessorURI"),                                
                                InactivitySetting = sr.GetEnum("InactivitySetting", InactivityTypesEnum.None),
                                InactivityMinutes = sr.GetInt("InactivityMinutes"),
                                DaysBeforeAccountDisabled = sr.GetInt("DaysBeforeAccountDisabled"),
                                DelayAfterInvalidLogin = sr.GetBool("DelayAfterInvalidLogin"),
                                DelayAfterInvalidLoginTimeout = sr.GetInt("DelayAfterInvalidLoginTimeout"),
                                InvalidLoginAttemptCount = sr.GetInt("InvalidLoginAttemptCount"),
                                InvalidLoginAttemptTime = sr.GetInt("InvalidLoginAttemptTime"),
                                DisableAccountSetting = sr.GetEnum("DisableAccountSetting", DisableAccountActionsType.DisableAdmin),
                                InvalidLoginTimeout = sr.GetInt("InvalidLoginTimeout"),
                                SessionInactivityTimeoutAction = sr.GetEnum("SessionInactivityTimeoutAction", InactivityTimoutActionEnum.None),
                                IsMandatoryPasswordChange = sr.GetBool("IsMandatoryPasswordChange"),
                                PasswordExpirationAction = sr.GetEnum("PasswordExpirationAction", PasswordExpirationActions.NoAction),
                                PasswordExpirationDays = sr.GetInt("PasswordExpirationDays"),
                                MinimumPasswordLength = sr.GetInt("MinimumPasswordLength"),
                                EnableSpecialChar = sr.GetBool("EnableSpecialChar"),
                                EnableUpperLowerCase = sr.GetBool("EnableUpperLowerCase"),
                                PasswordHistoryCount = sr.GetInt("PasswordHistoryCount"),
                                PasswordStrengthExpression = sr.GetString("PasswordStrengthExpression"),
                                NotifyUserLastSucccessfulLogin = sr.GetBool("NotifyLastSucccessfulLogin"),
                                NotifyUserLastUnsucccessfulLogin = sr.GetBool("NotifyLastUnsucccessfulLogin"),
                                NotifyUserLastLoginAttempts = sr.GetBool("NotifyUserLastLoginAttempts"),
                                NotifyUserLastLoginAttemptsDays = sr.GetInt("NotifyLastLoginAttemptsDays"),
                                NotifyUserSecurityChanges = sr.GetBool("NotifyUserSecurityChanges"),
                                SMTPServer = sr.GetString("SMTPServer"),
                                SMTPPort = sr.GetInt("SMTPPort", 25),
                                SMTPUseSsl = sr.GetBool("SMTPUseSsl"),
                                SMTPUseAuth = sr.GetBool("SMTPUseAuth"),
                                SMTPAuthName = sr.GetString("SMTPAuthName"),
                                SMTPAuthPass = sr.GetString("SMTPAuthPass"),
                                EmailFromAddress = sr.GetString("EmailFromAddress"),
                                EmailFromCurrentUser = sr.GetBoolean("EmailFromCurrentUser"),
                                ReportsPath = sr.GetString("ReportsPath"),
                                IsUnderMaintenance = sr.GetBool("IsUnderMaintenance"),
                                Theme = sr.GetString("Theme"),
                                AllowRememberMe = sr.GetBool("AllowRememberMe"),
                                MaxFileSize = (ulong)sr.GetInt64("MaxFileSize"),
                                LdapProfiles = new List<LdapProfileDTO>(),
                                SSOOptions = new SSOOptionsDTO(),
                                ShowWarning = sr.GetBool("ShowWarningMessage"),
                                WarningMessage = sr.GetString("WarningMessage"),
                                WarningCaption = sr.GetString("WarningCaption"),
                                ShowInfo = sr.GetBool("ShowInfoMessage"),
                                InfoMessage = sr.GetString("InfoMessage"),
                                InfoCaption = sr.GetString("InfoCaption"),
                                ShowSuccess = sr.GetBool("ShowSuccessMessage"),
                                SuccessMessage = sr.GetString("SuccessMessage"),
                                SuccessCaption = sr.GetString("SuccessCaption"),
                                RestrictExportTo = sr.GetInt("RestrictExportTo"),
                                DisableSearchGrouping = sr.GetBool("DisableSearchGrouping"),
                                DisableSearchAll = sr.GetBool("DisableSearchAll"),
                           };

                        sr.NextResult();
                        while (sr.Read())
                        {
                            dto.SSOOptions.IsEnabled = sr.GetBool("SSOEnabled");
                            dto.SSOOptions.AllowSSOApproval = sr.GetBool("AllowSSOApproval");
                            dto.SSOOptions.SAMLVersion = sr.GetString("SAMLVersion");
                            dto.SSOOptions.Issuer = sr.GetString("SSOIssuer");
                            dto.SSOOptions.IdPTargetUrl = sr.GetString("IdPTargetUrl");
                            dto.SSOOptions.IdPLogoutUrl = sr.GetString("IdPLogoutUrl");
                            dto.SSOOptions.HasNoCertificate = sr.GetBoolean("HasNoSSOCertificate");
                        }

                        sr.NextResult();
                        while (sr.Read())
                        {
                            dto.LdapProfiles.Add(
                                new LdapProfileDTO
                                {
                                    Id = sr.GetInt32("Id"),
                                    Name = sr.GetString("Name"),
                                    ServerType = (LdapServerTypes) sr.GetInt32("ServerType"),
                                    UseForLogin = sr.GetBool("UseForLogin"),
                                    ServerPath = sr.GetString("ServerPath"),
                                    Username = TryDecrypt(sr.GetString("Username")),
                                    Password = TryDecrypt(sr.GetString("Password")),
                                    RootPath = sr.GetString("RootPath"),
                                    SearchFilter = sr.GetString("SearchFilter"),
                                    UseSSL = sr.GetBoolean("UseSSL")
                                });
                        }
                    }
                }

                //reader.NextResult();

                //while (reader.Read())
                //{
                //    dto.NewsList.Add(new NewsDto
                //                         {
                //                             Id = reader.GetInt32(0),
                //                             Body = reader.GetString(1),
                //                             Header = reader.GetString(2),
                //                             Date = reader.GetDateTime(3)
                //                         });
                //}
            });

            return dto;
        }