Exemple #1
0
        /// <summary>
        /// Retrieves the process.
        /// </summary>
        /// <param name="id">The process id.</param>
        /// <param name="fetchHistory">The fetch history.</param>
        /// <param name="locId">The localization/language id.</param>
        /// <returns>The processEdit DTO object <see cref="ProcessEditDto" />.</returns>
        public ProcessEditDto FetchProcess(int id, IProcessFetchHistory fetchHistory = null, int locId = 0)
        {
            var process = new ProcessEditDto();
            const string commandText = "GetProcessWithLoc";

            if (fetchHistory != null)
                fetchHistory.BeginLogExecuteSP();

            Database.GetDataReader(
                commandText,
                600,
                r =>
                {
                    if (r == null || !r.Read())
                    {
                        return;
                    }

                    var sr = new SafeDataReader(r);

                    process.Id = sr.GetInt("Id");
                    process.Name = sr.GetString("Name").Trim();
                    process.Description = sr.GetString("Description");
                    process.Documentation = sr.GetString("Documentation");
                    process.SystemName = sr.GetString("SystemName");
                    process.IconId = sr.GetNullableInt("IconId");
                    process.Guid = sr.GetGuid("Guid");
                    process.IsPublishedCopy = sr.GetBool("IsPublishedCopy");
                    process.BaseProcessId = sr.GetNullableInt("BaseProcessId");
                    process.BaseProcessProcessId = sr.GetNullableInt("BaseProcessProcessId");
                    process.ProcessOption = sr.GetString("ProcessOption");
                    process.IsStateEnabled = sr.GetBool("IsStateEnabled", true);
                    process.DefaultStateId = sr.GetInt32("DefaultStateId");
                    process.AllowPaperclips = sr.GetBool("AllowPaperclips", true);
                    process.ColorId = sr.GetNullableInt("ColorId");
                    process.InheritanceContext = sr.GetString("InheritanceContext");
                    process.ShowDerivedProcess = sr.GetBool(Constants.ShowDerivedProcess);
                    process.PublishedProcessId = sr.GetInt("PublishedProcessId");
                    process.PublishedId = sr.GetInt("PublishedId");
                    process.IsSystem = sr.GetBool("IsSystem");
                    process.SimpleProcess = sr.GetBool("SimpleProcess");
                    process.IsInactive = sr.GetBool("IsInactive");
                    process.IsTabbedUI = sr.GetBool("IsTabbedUI");
                    process.IsTrackable = sr.GetBool("IsTrackable");
                    process.ShowSummaryPage = sr.GetBool("ShowSummaryPage");
                    process.AllowBatchProcessing = sr.GetBool("AllowBatchProcessing");
                    process.LastUpdated = sr.GetDateTime("LastUpdated");
                    process.IdentifierField = sr.GetString("IdentifierField");
                    var processVersionId = sr.GetInt("ProcessVersionId");

                    if (fetchHistory != null)
                        fetchHistory.LogExecuteSP();

                    if (processVersionId > 0)
                    {
                        process.Version = new VersionDto
                        {
                            ProcessId = processVersionId,
                            VersioningStyle = sr.GetEnum("VersioningStyle", VersioningStyles.Char),
                            StartingVersion = sr.GetString("StartingVersion"),
                            NextVersionStateGuid = sr.GetGuid("NextVersionStateGuid"),
                            PreviousVersionStateGuid = sr.GetGuid("PreviousVersionStateGuid"),
                            IncludeVersionNumberInList = sr.GetBool("IncludeVersionNumberInList"),
                            IncludeVersionDateInList = sr.GetBool("IncludeVersionDateInList"),
                            StateFilterGuid = sr.GetGuid("StateFilterGuid")
                        };
                    }

                    if (fetchHistory != null)
                        fetchHistory.ProcessHistoryDTO.FetchSectionsTime = Profiler.Profile(() => ReadSections(process, sr));
                    else
                        ReadSections(process, sr);

                    ReadRequiredRuleConfigs(process, sr);

                    if (fetchHistory != null)
                        fetchHistory.ProcessHistoryDTO.FetchSecurityConfigurationsTime = fetchHistory.Profile(
                            () =>
                            {
                                ReadProcessSecurityConfigurations(process, sr);
                                ReadProcessSecurityConfigs(process, sr);
                            });
                    else
                    {
                        ReadProcessSecurityConfigurations(process, sr);
                        ReadProcessSecurityConfigs(process, sr);
                    }

                    ReadStates(process, sr);
                    ReadEscalationActionOptions(process, sr);
                    ReadAssignmentActionOptions(process, sr);
                    ReadApprovalActionOptions(process, sr);
                    ReadActionRules(process, sr);
                    ReadFilters(process, sr);
                    ReadMetrics(process, sr);
                    ReadKpis(process, sr);
                    ReadCommands(process, sr);
                    ReadESyncProcesses(process, sr);
                    ReadReports(process, sr);
                    ReadProcessViews(process, sr);
                    ReadDataTriggers(process, sr);
                    ReadIntegrationServices(process, sr);
                    ReadSearchDisplayFields(process, sr);
                    ReadLayouts(process, sr);
                    ReadProcessDataIndexes(process, sr);
                    ReadExternalData(process, sr);
                },
                    CommandType.StoredProcedure,
                    new SqlParameter("p_id", id),
                    new SqlParameter("localizationId", locId));

            // run after GetProcessNew
            this.ReadDependencies(process);

            return process;
        }
Exemple #2
0
        /// <summary>
        /// Fetches checkbox options.
        /// </summary>
        /// <param name="processName">The process name.</param>
        /// <param name="fieldName">The field name.</param>
        /// <param name="isPublishedCopy">The is published copy.</param>
        /// <returns>The <see cref="CheckboxOptionsStepDto" />.</returns>
        public CheckboxOptionsStepDto FetchCheckboxOptions(string processName, string fieldName, bool isPublishedCopy = false)
        {
            const string CmdText =
                @"
DECLARE @fieldId AS INT

SELECT @fieldId = f.Id
FROM
    [dbo].[Processes] p
    INNER JOIN [dbo].[Sections] s ON s.ProcessId = p.Id
    INNER JOIN [dbo].[Fields] f ON f.SectionId = s.Id
WHERE p.[SystemName] = @processName AND p.IsRemoved = 0 AND p.IsPublishedCopy = @isPublishedCopy AND f.SystemName = @fieldName;

EXEC [dbo].[GetCheckboxOptionsStep] @FieldId = @fieldId;
";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            using (var cmd = new SqlCommand(CmdText, ctx.Connection))
            {
                cmd.Parameters.AddWithValue("@processName", processName);
                cmd.Parameters.AddWithValue("@fieldName", fieldName);
                cmd.Parameters.AddWithValue("@isPublishedCopy", isPublishedCopy);

                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        var dto = new CheckboxOptionsStepDto
                                      {
                                          Id = reader.GetInt32(0),
                                          IsSwitchToggle = reader.GetBool(1),
                                          DefaultValue = reader.GetBool(2),
                                          MainLabel = reader.GetString(3),
                                          UndefinedLabel = reader.GetString(4),
                                          TrueLabel = reader.GetString(5),
                                          FalseLabel = reader.GetString(6),
                                      };

                        return dto;
                    }
                }
            }

            return null;
        }
Exemple #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;
        }
Exemple #4
0
        /// <summary>
        /// Retrieves process information.
        /// </summary>
        /// <param name="id">The process id.</param>
        /// <returns>The process info object<see cref="ProcessInfoDTO" />.</returns>
        public ProcessInfoDTO FetchProcessInfo(int id)
        {
            var result = new ProcessInfoDTO();

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;
                const string Sql =
                    @"
SELECT  [Id] ,
        [Name] ,
        [Description] ,
        [SystemName] ,
        [IsSystem],
        [Documentation]
FROM    [Processes]
WHERE   id = @id";

                using (var cmd = new SqlCommand(Sql, cn))
                {
                    cmd.Parameters.AddWithValue("@id", id);

                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            result = new ProcessInfoDTO
                                         {
                                             Id = reader.GetInt32(0),
                                             Name = reader.GetString(1).Trim(),
                                             Description = reader.GetString(2),
                                             SystemName = reader.GetString(3),
                                             IsSystem = reader.GetBool(4),
                                             ProcessDocumentation = reader.GetString(5)
                                         };
                        }
                    }
                }
            }

            return result;
        }
Exemple #5
0
        /// <summary> Fetches the LDAP profiles. </summary>
        public IEnumerable<LdapProfileDTO> FetchLdapProfiles()
        {
            const string sql = @"
SELECT 
    [Id]
   ,[Name]
   ,[ServerType]
   ,[UseForLogin]
   ,[ServerPath]
   ,[Username]
   ,[Password]
   ,[RootPath]
   ,[SearchFilter]
   ,[UseSSL]
FROM [dbo].[LdapProfiles]";

            var resultList = new List<LdapProfileDTO>();

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

                    using (var sr = new SafeDataReader(reader))
                    {
                        while (reader.Read())
                        {
                            resultList.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")
                                });
                        }
                    }
                });

            return resultList;
        }
Exemple #6
0
        /// <summary>
        /// Fetches reverse cross ref list.
        /// </summary>
        /// <param name="processGuid">The process GUID.</param>
        /// <returns>The <see cref="IList" />.</returns>
        public IList<PublishedProcessInfoDTO> FetchReverseCrossRefList(Guid processGuid)
        {
            var result = new List<PublishedProcessInfoDTO>();
            const string CmdText =
                @"
-- Select processes with cross reference fields
DECLARE @pp_id INT
SELECT @pp_id = pp.[Id] FROM [dbo].[PublishedProcesses] pp WHERE pp.[ProcessGuid] = @processGuid

SELECT pp.[Id]
      ,p.[Name]
      ,p.[SystemName]
      ,p.[Id]
      ,p.[IsStateEnabled]
      ,p.[ProcessOption]
FROM [dbo].[PublishedProcesses] pp
INNER JOIN [dbo].[Processes] p ON p.[Id] = pp.[ProcessId]
INNER JOIN (SELECT DISTINCT s.[ProcessId] AS [Id]
FROM [dbo].[Sections] s
INNER JOIN [dbo].[Fields] f on f.[SectionId] = s.[Id]
INNER JOIN [dbo].[CrossRefRequredFieldStep] x on x.[FieldId] = f.[Id]
WHERE x.[CrossRefProcessId] = @pp_id) pu ON p.[Id] = pu.[Id]
WHERE pp.Id <> @pp_id

-- Select processes with checklist fields
DECLARE @pp_systemName AS NVARCHAR(200)
SELECT @pp_systemName = p.[SystemName] FROM [dbo].[Processes] p WHERE p.[Guid] = @processGuid AND p.[IsPublishedCopy] = 1 AND p.[IsRemoved] = 0

SELECT pp.[Id]
    ,p.[Name]
    ,p.[SystemName]
    ,p.[Id]
    ,p.[IsStateEnabled]
    ,p.[ProcessOption]
FROM [dbo].[PublishedProcesses] pp
INNER JOIN [dbo].[Processes] p ON p.[Id] = pp.[ProcessId]
INNER JOIN (SELECT DISTINCT s.[ProcessId] AS [Id]
FROM [dbo].[Sections] s
INNER JOIN [dbo].[Fields] f on f.[SectionId] = s.[Id]
INNER JOIN [dbo].[stepChecklist] x on x.[FieldId] = f.[Id]
WHERE x.[AnswerProcessSystemName] = @pp_systemName) pu ON p.[Id] = pu.[Id]
WHERE pp.Id <> @pp_id";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                using (var cmd = new SqlCommand(CmdText, cn))
                {
                    cmd.Parameters.AddWithValue("@processGuid", processGuid);

                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        do
                        {
                            while (reader.Read())
                            {
                                var dto = new PublishedProcessInfoDTO
                                              {
                                                  Id = reader.GetInt(0),
                                                  Name = reader.GetString(1),
                                                  SystemName = reader.GetString(2),
                                                  ProcessId = reader.GetInt(3),
                                                  IsStateEnabled = reader.GetBool(4),
                                                  ProcessOption = reader.GetEnum(5, ProcessOption.None)
                                              };

                                if (result.All(x => x.Id != dto.Id))
                                {
                                    result.Add(dto);
                                }
                            }
                        }
                        while (reader.NextResult());
                    }
                }
            }

            return result;
        }
Exemple #7
0
        /// <summary>
        /// Retrieves code.
        /// </summary>
        /// <param name="libraryType">The library type.</param>
        /// <returns>The <see cref="Dictionary{TKey,TValue}"/>.</returns>
        public Dictionary<string, SourceCodeDto> GetCode(LibraryTypes libraryType)
        {
            var result = new Dictionary<string, SourceCodeDto>();

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;
                using (var command = new SqlCommand("GetAllCode", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    if (((libraryType & LibraryTypes.System) == LibraryTypes.System)
                        && ((libraryType & LibraryTypes.Custom) == LibraryTypes.Custom))
                    {
                        command.Parameters.AddWithValue("@includeCustom", 1);
                        command.Parameters.AddWithValue("@includeSystem", 1);
                    }
                    else
                    {
                        command.Parameters.AddWithValue(
                            (libraryType & LibraryTypes.System) == LibraryTypes.System
                                ? "@includeSystem"
                                : "@includeCustom",
                            1);
                    }

                    using (var sr = new SafeDataReader(command.ExecuteReader()))
                    {
                        while (sr.Read())
                        {
                            var clientCode = sr.GetString(0);
                            var serverCode = sr.GetString(1);
                            var systemName = sr.GetString(2);
                            var isSystem = sr.GetBool(3);
                            var version = ParseVersion(sr.GetString(4));

                            result.Add(
                                systemName,
                                new SourceCodeDto
                                    {
                                        ClientCode = clientCode,
                                        ServerCode = serverCode,
                                        IsSystem = isSystem,
                                        Version = version
                                    });
                        }
                    }
                }
            }

            return result;
        }
Exemple #8
0
        /// <summary>
        /// Gets all usings for a specified business unit.
        /// </summary>
        /// <param name="businessUnitId">Id of the business unit.</param>
        /// <returns>IEnumerable{RecordUsingsDto}.</returns>
        public IEnumerable<RecordUsingsDto> GetBaseBusinessUnitUsings(int businessUnitId)
        {
            const string CmdText = @"
            SELECT 'UsingInFieldsSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as CommandName, NULL as ReportName
            FROM [dbo].[ProcessSecurityConfigs] sc
            JOIN [dbo].[Processes] p ON p.Id = sc.ProcessId
            WHERE @BusinessUnitId = BusinessUnitId

            UNION

            SELECT 'UsingInStateConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as CommandName, NULL as ReportName
            FROM [dbo].[States] s
            LEFT OUTER JOIN [dbo].[StateLinks] sl ON sl.StateOutGuid = s.Guid
            LEFT OUTER JOIN [dbo].[StateConnectorSecurityConfigurations] scsc ON scsc.StateInGuid = sl.StateInGuid AND scsc.StateOutGuid = sl.StateOutGuid
            JOIN [dbo].[Processes] p ON p.Id = s.ProcessId
            WHERE @BusinessUnitId = scsc.BusinessUnitId

            UNION

            SELECT 'UsingInCommandsSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, c.CommandName, NULL as ReportName
            FROM [dbo].[Commands] c
            LEFT OUTER JOIN [dbo].[ProcessCommandSecurityConfigurations] pcsc ON pcsc.ProcessCommandId = c.Id
            JOIN [dbo].[Processes] p ON p.Id = c.ProcessId
            WHERE @BusinessUnitId = pcsc.BusinessUnitId

            UNION

            SELECT 'UsingInReportSecurityConfigurations' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as CommandName, r.Title as ReportName
            FROM [dbo].[Reports] r
            LEFT OUTER JOIN [dbo].[ProcessReportSecurityConfigurations] prsc ON prsc.ReportId = r.Id
            JOIN [dbo].[Processes] p ON p.Id = r.ProcessId
            WHERE @BusinessUnitId = prsc.BusinessUnitId

            UNION

            SELECT 'UsingInProcessSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as CommandName, NULL as ReportName
            FROM [dbo].[ProcessSecurityConfigurations] sc
            JOIN [dbo].[Processes] p ON p.Id = sc.ProcessId
            WHERE @BusinessUnitId = BusinessUnitId
            ";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            using (var cmd = new SqlCommand(CmdText, ctx.Connection))
            {
                cmd.Parameters.AddWithValue("@BusinessUnitId", businessUnitId);

                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    var usings = new List<RecordUsingsDto>();

                    while (reader.Read())
                    {
                        var use = new RecordUsingsDto
                        {
                            UsingName = reader.GetString(0),
                            ProcessName = reader.GetString(1),
                            IsPublished = reader.GetBool(2),
                            CommandName = reader.GetString(3),
                            ReportName = reader.GetString(4),
                        };

                        usings.Add(use);
                    }

                    if (!usings.IsNullOrEmpty())
                    {
                        return usings;
                    }
                }
            }

            return null;
        }
Exemple #9
0
        /// <summary>
        /// Reads metrics.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="sr">The reader.</param>
        private static void ReadMetrics(ProcessEditDto process, SafeDataReader sr)
        {
            sr.NextResult();

            while (sr.Read())
            {
                process.Metrics.Add(new ProcessMetricEditDto
                {
                    Id = sr.GetInt32(0),
                    ProcessId = sr.GetInt32(1),
                    LastModifiedOn = sr.GetDateTime(2),
                    GuidId = sr.GetString(3),
                    Name = sr.GetString(4),
                    Documentation = sr.GetString(5),
                    SummaryType = sr.GetString(6),
                    LockFilter = sr.GetBool(7),
                    SnapshotFrequency = sr.GetString(8),
                    MetricFieldSystemName = sr.GetString(9),
                    GroupFieldOneSystemName = sr.GetString(10),
                    GroupFieldTwoSystemName = sr.GetString(11),
                    GroupFieldThreeSystemName = sr.GetString(12),
                    GroupFieldFourSystemName = sr.GetString(13),
                    FilterGuid = sr.GetGuid(14),
                    OrderByMetricField = sr.GetString(15),
                    OrderByAscending = (bool?)sr.GetValue(16),
                    FilterDefinition = sr.GetString(17)
                });
            }
        }
Exemple #10
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;
        }
Exemple #11
0
        /// <summary>
        /// The read security config fields.
        /// </summary>
        /// <param name="sr">The reader.</param>
        /// <param name="process">The process.</param>
        private static void ReadSecurityConfigFields(SafeDataReader sr, ProcessEditDto process)
        {
            sr.NextResult();
            while (sr.Read())
            {
                var securityConfigFieldDto = new ProcessSecurityConfigFieldDto
                {
                    Id = sr.GetInt32(0),
                    SecurityConfigId = sr.GetInt32(1),
                    CanView = sr.GetBool(2),
                    CanEdit = sr.GetBool(3),
                    Guid = sr.GetGuid(4),
                    FieldGuid = sr.GetGuid(5)
                };
                var config = process.SecurityConfigs.FirstOrDefault(sc => sc.Id == securityConfigFieldDto.SecurityConfigId);

                if (config != null)
                {
                    config.SecurityConfigFields.Add(securityConfigFieldDto);
                }
            }
        }
Exemple #12
0
        /// <summary>
        /// Reads process data indexes.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="sr">The reader.</param>
        private static void ReadProcessDataIndexes(ProcessEditDto process, SafeDataReader sr)
        {
            sr.NextResult();

            var temp = new List<ProcessDataIndexDto>();

            while (sr.Read())
            {
                temp.Add(new ProcessDataIndexDto
                {
                    Id = sr.GetInt32(0),
                    ProcessId = sr.GetInt32(1),
                    Name = sr.GetString(2),
                    Notes = sr.GetString(3),
                    IsUniqueIndex = sr.GetBool(4),
                    ViolationMessage = sr.GetString(5),
                    GuidId = sr.GetGuid(6),
                    ExcludeRemovedItems = sr.GetBoolean(7)
                });
            }

            var fieldsData = ReadProcessDataIndexesFields(sr);

            foreach (var processDataIndexDto in temp)
            {
                var dto = processDataIndexDto;
                var dataIndexFields = fieldsData.Where(x => x.DataIndexId == dto.Id);

                var processDataIndexFieldDtos = dataIndexFields as ProcessDataIndexFieldDto[] ??
                                                dataIndexFields.ToArray();

                process.DataIndexes.Add(new ProcessDataIndexDto(processDataIndexFieldDtos.ToList())
                {
                    Id = dto.Id,
                    ProcessId = dto.ProcessId,
                    Name = dto.Name,
                    Notes = dto.Notes,
                    ExcludeRemovedItems = dto.ExcludeRemovedItems,
                    IsUniqueIndex = dto.IsUniqueIndex,
                    ViolationMessage = dto.ViolationMessage,
                    GuidId = dto.GuidId
                });
            }
        }
Exemple #13
0
        /// <summary>
        /// Reads fields.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="sr">The reader.</param>
        private void ReadFields(ProcessEditDto process, SafeDataReader sr)
        {
            sr.NextResult();

            int? sectionId = null;
            SectionDto section = null;
            var times = new List<double>();

            while (sr.Read())
            {
                var start = DateTime.Now;
                var fieldDto = new FieldDto
                {
                    Id = sr.GetInt32(0),
                    Name = sr.GetSafeString(1, string.Empty).Replace(@"""", "''"),
                    FieldTypeId = sr.GetInt32(2),
                    SectionId = sr.GetInt32(3),
                    Width = sr.GetDouble(4),
                    RowSpan = sr.GetInt(5),
                    ShowInList = sr.GetBoolean(6),
                    IncludeInFilter = sr.GetBoolean(7),
                    HideFromDetails = sr.GetBoolean(8),
                    SystemName = sr.GetString(9),
                    Position = sr.GetInt32(10),
                    CopyFieldValueOnCopyItem = sr.GetBool(11),
                    DeepCopy = sr.GetBool(12),
                    Guid = sr.GetGuid(13),
                    SearchPosition = sr.GetInt(14),
                    SearchWidth = sr.GetInt(15),
                    IsBase = sr.GetBoolean(16),
                    UseInGlobalSearch = sr.GetBoolean(19),
                    PublishedCopyId = sr.GetNullableInt(21),
                    AllowLocalizedData = sr.GetBoolean("AllowLocalizedData")
                };

                if (fieldDto.SectionId != sectionId || section == null)
                {
                    section = process.Sections.First(s => s.Id == fieldDto.SectionId);
                    sectionId = fieldDto.SectionId;
                }

                fieldDto.FieldTypeInfo = new FieldTypeDto
                {
                    Id = fieldDto.FieldTypeId,
                    Name = sr.GetString(17),
                    DataType = sr.GetString(18),
                    CanBeRequired = sr.GetBoolean(20)
                };

                section.FieldList.Add(fieldDto);

                times.Add((DateTime.Now - start).TotalMilliseconds);
            }

            Profiler.Profile(() => this.ReadFieldEditors(process, sr));
        }
Exemple #14
0
        /// <summary>
        /// Gets all usings for a specified role.
        /// </summary>
        /// <param name="roleId">Id of the role.</param>
        /// <returns>IEnumerable{RecordUsingsDto}.</returns>
        public IEnumerable<RecordUsingsDto> GetBaseRoleUsings(int roleId)
        {
            const string CmdText = @"
            SELECT 'UsingInFieldsSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[ProcessSecurityConfigs] sc
            JOIN [dbo].[Processes] p ON p.Id = sc.ProcessId
            WHERE @RoleId = RoleId

            UNION

            SELECT 'UsingInStateConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL  as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[States] s
            LEFT OUTER JOIN [dbo].[StateLinks] sl ON sl.StateOutGuid = s.Guid
            LEFT OUTER JOIN [dbo].[StateConnectorSecurityConfigurations] scsc ON scsc.StateInGuid = sl.StateInGuid AND scsc.StateOutGuid = sl.StateOutGuid
            JOIN [dbo].[Processes] p ON p.Id = s.ProcessId
            WHERE @RoleId = scsc.RoleId

            UNION

            SELECT 'UsingInActions' as Using, p.Name as ProcessName, p.IsPublishedCopy, ad.Name as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[ActionDefinitions] ad
            LEFT OUTER JOIN [dbo].[EscalationActionOptions] ea ON ea.ActionId = ad.[Id]
            JOIN [dbo].[Processes] p ON p.Id = ad.ProcessId
            WHERE @RoleId = ea.RoleId

            UNION

            SELECT 'UsingInActions' as Using, p.Name as ProcessName, p.IsPublishedCopy, ad.Name as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[ActionDefinitions] ad
            LEFT OUTER JOIN [dbo].[AssignmentActionOptions] aa ON aa.ActionId = ad.[Id]
            JOIN [dbo].[Processes] p ON p.Id = ad.ProcessId
            WHERE @RoleId = aa.RoleId

            UNION

            SELECT 'UsingInCommandsSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as ActionName, c.CommandName, NULL as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[Commands] c
            LEFT OUTER JOIN [dbo].[ProcessCommandSecurityConfigurations] pcsc ON pcsc.ProcessCommandId = c.Id
            JOIN [dbo].[Processes] p ON p.Id = c.ProcessId
            WHERE @RoleId = pcsc.RoleId

            UNION

            SELECT 'UsingInFiltersSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as ActionName, NULL as CommandName, f.Name as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[Filters] f
            JOIN [dbo].[Processes] p ON p.Id = f.ProcessId
            WHERE @RoleID = ANY(SELECT Int_Value FROM fn_ParseText2Table(RoleIds, ','))

            UNION

            SELECT 'UsingInReportSecurityConfigurations' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as ActionName, NULL as CommandName, NULL as FilterName, r.Title as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[Reports] r
            LEFT OUTER JOIN [dbo].[ProcessReportSecurityConfigurations] prsc ON prsc.ReportId = r.Id
            JOIN [dbo].[Processes] p ON p.Id = r.ProcessId
            WHERE @RoleId = prsc.RoleId

            UNION

            SELECT 'UsingInProcessSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[ProcessSecurityConfigurations] sc
            JOIN [dbo].[Processes] p ON p.Id = sc.ProcessId
            WHERE @RoleID = RoleId

            UNION

            SELECT 'UsingInNavigationGroup' as Using, NULL as ProcessId, NULL as IsPublishedCopy, NULL as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, ng.Name as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[NavigationGroupSecurityConfigurations] ngs
            JOIN [dbo].[NavigationGroups] ng ON ng.Id = ngs.NavigationGroupId
            WHERE @RoleID = RoleId AND ngs.CanView = 1

            UNION

            SELECT 'UsingInNavigationItem' as Using, p.Name as ProcessName, NULL as IsPublishedCopy, NULL as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, ng.Name as NavigationGroupName, ni.Name as NavigationItemName
            FROM [dbo].[NavigationItemSecurityConfigurations] nis
            JOIN [dbo].[NavigationItems] ni ON ni.Id = nis.NavigationItemId
            JOIN [dbo].[PublishedProcesses] pp ON pp.Id = ni.PublishedProcessId
            JOIN [dbo].[Processes] p ON p.Id = pp.ProcessId
            JOIN [dbo].[NavigationGroups] ng ON ng.Id = ni.NavigationGroupId
            WHERE @RoleID = RoleId AND nis.CanView = 1

            UNION

            SELECT 'UsingInNavigationItem' as Using, NULL as ProcessName, NULL as IsPublishedCopy, NULL as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, ng.Name as NavigationGroupName, ni.Name as NavigationItemName
            FROM [dbo].[NavigationItemSecurityConfigurations] nis
            JOIN [dbo].[NavigationItems] ni ON ni.Id = nis.NavigationItemId
            JOIN [dbo].[NavigationGroups] ng ON ng.Id = ni.NavigationGroupId
            WHERE @RoleID = RoleId AND nis.CanView = 1 AND ni.PublishedProcessId IS NULL
            ";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            using (var cmd = new SqlCommand(CmdText, ctx.Connection))
            {
                cmd.Parameters.AddWithValue("@RoleID", roleId);

                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    var usings = new List<RecordUsingsDto>();

                    while (reader.Read())
                    {
                        var use = new RecordUsingsDto
                                      {
                                          UsingName = reader.GetString(0),
                                          ProcessName = reader.GetString(1),
                                          IsPublished = reader.GetBool(2),
                                          ActionName = reader.GetString(3),
                                          CommandName = reader.GetString(4),
                                          FilterName = reader.GetString(5),
                                          ReportName = reader.GetString(6),
                                          NavigationGroupName = reader.GetString(7),
                                          NavigationItemName = reader.GetString(8),
                                      };

                        usings.Add(use);
                    }

                    if (!usings.IsNullOrEmpty())
                    {
                        return usings;
                    }
                }
            }

            return null;
        }
Exemple #15
0
        public PublishedProcessInfoDTO FetchPublishedProcess(int id)
        {
            var result = new PublishedProcessInfoDTO();

            var sql = string.Format(CultureInfo.InvariantCulture, @"
SELECT pp.Id
      ,ISNULL(pl.ProcessName, p.[Name])
      ,p.Id AS ProcessId
      ,p.SystemName
      ,p.BaseProcessId
      ,p.ProcessOption
      ,p.SimpleProcess
      ,p.IsStateEnabled
FROM   [dbo].[PublishedProcesses] pp
       INNER JOIN Processes p ON  pp.ProcessId = p.Id
       INNER JOIN Processes p2 ON pp.ProcessGuid = p2.[Guid] and p2.[IsPublishedCopy] = 0
       LEFT OUTER JOIN dbo.Localizations l ON l.CultureName = '{0}'
       LEFT OUTER JOIN dbo.ProcessLocalizations pl ON pl.LocalizationId = l.Id AND p2.Id = pl.ProcessId
WHERE pp.id = @id", System.Threading.Thread.CurrentThread.CurrentUICulture.Name);

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;
                using (var cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.AddWithValue("@id", id);
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            result = new PublishedProcessInfoDTO
                                         {
                                             Id = reader.GetInt32(0),
                                             Name = reader.GetString(1),
                                             ProcessId = reader.GetInt32(2),
                                             SystemName = reader.GetString(3),
                                             ProcessOption =
                                                 !string.IsNullOrEmpty(reader.GetString(5))
                                                     ? (ProcessOption)
                                                       Enum.Parse(
                                                           typeof(ProcessOption), reader.GetString(5))
                                                     : ProcessOption.None,
                                             SimpleProcess = reader.GetBool(6),
                                             IsStateEnabled = reader.GetBoolean(7)
                                         };

                            if (!reader.IsDBNull(4))
                            {
                                result.BaseProcess = this.FetchPublishedProcess(reader.GetInt32(4));
                            }
                        }
                    }
                }
            }

            return result;
        }
Exemple #16
0
        /// <summary>
        /// Gets the states usings.
        /// </summary>
        /// <param name="stateGuid">The state identifier.</param>
        /// <returns>IEnumerable{RecordUsingsDto}.</returns>
        public IEnumerable<RecordUsingsDto> GetStatesUsings(Guid stateGuid)
        {
            const string CmdText = @"
            SELECT 'UsingInFieldsSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as ActionName, NULL as CommandName, NULL as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[ProcessSecurityConfigs] sc
            JOIN [dbo].[Processes] p ON p.Id = sc.ProcessId
            WHERE @StateGuid = StateGuid

            UNION

            SELECT 'UsingInCommandsSecurityConfigs' as Using, p.Name as ProcessName, p.IsPublishedCopy, NULL as ActionName, c.CommandName, NULL as FilterName, NULL as ReportName, NULL as NavigationGroupName, NULL as NavigationItemName
            FROM [dbo].[Commands] c
            LEFT OUTER JOIN [dbo].[ProcessCommandSecurityConfigurations] pcsc ON pcsc.ProcessCommandId = c.Id
            JOIN [dbo].[Processes] p ON p.Id = c.ProcessId
            WHERE @StateGuid = pcsc.StateGuid";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            using (var cmd = new SqlCommand(CmdText, ctx.Connection))
            {
                cmd.Parameters.AddWithValue("@StateGuid", stateGuid);

                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    var usings = new List<RecordUsingsDto>();

                    while (reader.Read())
                    {
                        var use = new RecordUsingsDto
                        {
                            UsingName = reader.GetString(0),
                            ProcessName = reader.GetString(1),
                            IsPublished = reader.GetBool(2),
                            ActionName = reader.GetString(3),
                            CommandName = reader.GetString(4),
                            FilterName = reader.GetString(5),
                            ReportName = reader.GetString(6),
                            NavigationGroupName = reader.GetString(7),
                            NavigationItemName = reader.GetString(8),
                        };

                        usings.Add(use);
                    }

                    if (!usings.IsNullOrEmpty())
                    {
                        return usings;
                    }
                }
            }

            return null;
        }
Exemple #17
0
        /// <summary>
        /// Retrieves published process by process name.
        /// </summary>
        /// <param name="processName">The process name.</param>
        /// <returns>The <see cref="PublishedProcessInfoDTO" />.</returns>
        public PublishedProcessInfoDTO FetchPublishedProcess(string processName)
        {
            var result = new PublishedProcessInfoDTO();

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;
                const string Sql =
                    @"
SELECT pp.Id
      ,Name
      ,p.Id AS ProcessId
      ,p.SystemName
      ,p.BaseProcessId
      ,p.ProcessOption
      ,p.SimpleProcess
      ,p.IsStateEnabled
FROM   [dbo].[PublishedProcesses] pp
       INNER JOIN Processes p ON  pp.ProcessId = p.Id
WHERE p.SystemName = @procName AND p.IsRemoved=0";
                using (var cmd = new SqlCommand(Sql, cn))
                {
                    cmd.Parameters.AddWithValue("@procName", processName);
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            result = new PublishedProcessInfoDTO
                                         {
                                             Id = reader.GetInt32(0),
                                             Name = reader.GetString(1),
                                             ProcessId = reader.GetInt32(2),
                                             SystemName = reader.GetString(3),
                                             ProcessOption =
                                                 !string.IsNullOrEmpty(reader.GetString(5))
                                                     ? (ProcessOption)
                                                       Enum.Parse(
                                                           typeof(ProcessOption), reader.GetString(5))
                                                     : ProcessOption.None,
                                             SimpleProcess = reader.GetBool(6),
                                             IsStateEnabled = reader.GetBoolean(7)
                                         };

                            if (!reader.IsDBNull(4))
                            {
                                result.BaseProcess = this.FetchPublishedProcess(reader.GetInt32(4));
                            }
                        }
                    }
                }
            }

            return result;
        }
Exemple #18
0
        /// <summary>
        /// Retrieves checklist step.
        /// </summary>
        /// <param name="processName">The process name.</param>
        /// <param name="fieldName">The field name.</param>
        /// <param name="isPublishedCopy">The is published copy.</param>
        /// <returns>The <see cref="ChecklistStepDto" />.</returns>
        public ChecklistStepDto FetchChecklistStep(string processName, string fieldName, bool isPublishedCopy = false)
        {
            const string CommandText = @"
DECLARE @fieldId AS INT

SELECT @fieldId = f.Id
FROM
    [dbo].[Processes] p
    INNER JOIN [dbo].[Sections] s ON s.ProcessId = p.Id
    INNER JOIN [dbo].[Fields] f ON f.SectionId = s.Id
WHERE p.[SystemName] = @processName AND p.IsRemoved = 0 AND p.IsPublishedCopy = @isPublishedCopy AND f.SystemName = @fieldName;

EXEC [dbo].[GetChecklistStep] @FieldId = @fieldId;";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            using (var cmd = new SqlCommand(CommandText, ctx.Connection))
            {
                cmd.Parameters.AddWithValue("@processName", processName);
                cmd.Parameters.AddWithValue("@fieldName", fieldName);
                cmd.Parameters.AddWithValue("@isPublishedCopy", isPublishedCopy);

                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        var dto = new ChecklistStepDto
                                      {
                                          QuestionProcessSystemName = reader.GetString(0),
                                          AnswerProcessSystemName = reader.GetString(1),
                                          AnswerProcessDefaultStateGuid = reader.GetGuid(2),
                                          CommentsFieldSystemName = reader.GetString(3),
                                          IsSingleQuestionView = reader.GetBool(4),
                                          ListDisplayFieldSystemName = reader.GetString(5),
                                          AllowAdhocQuestions = reader.GetBool(6),
                                          FilterDefinition = reader.GetString(7),
                                          FilterGuid = reader.IsDBNull(8) ? null : (Guid?)reader.GetGuid(8),
                                          CanChangeItemState = reader.GetBool(9),
                                          ShowLinkedItems = reader.GetBool(10),
                                          SortFieldSystemName = reader.GetString(11),
                                          SortDirection = reader.GetEnum(12, SortDirection.Ascending),
                                          HideValidationIcon = reader.GetBool(13)
                                      };

                        return dto;
                    }
                }
            }

            return null;
        }
Exemple #19
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;
        }