public void DeleteFileByGuid(Guid fileGuid)
        {
            _sqlDAc = new SqlDataAccess(_connectionString);
            _sqlValues = new Dictionary<string, object>();
            _sqlValues.Add("@fileGUID", fileGuid);
            _sqlCommand = "DeletefsFile";

            _sqlDAc.ExecuteByStoredProc(SqlDataAccess.ReturnType.NonQuery, _sqlCommand, ref _sqlValues);
        }
        public Dictionary<string, string> GenerateFilePlaceholder()
        {
            _sqlDAc = new SqlDataAccess(_connectionString);
            _sqlValues = new Dictionary<string, object>();
            _sqlCommand = "GeneratefsFilePlaceholder";
            Dictionary<string, string> filePlaceholderInformations = new Dictionary<string, string>();

            Object returnObject = _sqlDAc.ExecuteByStoredProc(SqlDataAccess.ReturnType.DataTable, _sqlCommand, ref _sqlValues);

            if (returnObject != null)
            {
                DataTable dataTable = (DataTable)returnObject;

                if (dataTable.Rows.Count > 0)
                {
                    DataRow[] dr = dataTable.Select();
                    filePlaceholderInformations.Add("GUIDFile", dr[0]["GUIDFile"].ToString());
                    filePlaceholderInformations.Add("bdPathName", dr[0]["bdPathName"].ToString());
                }
            }
            return filePlaceholderInformations;
        }
        public byte[] GetFileByDbPathName(string dbPathName)
        {
            try
            {
                _sqlDAc = new SqlDataAccess(_connectionString);
                _sqlValues = new Dictionary<string, object>();

                _sqlDAc.BeginTransaction();
                _sqlCommand = "SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()";

                _obj = _sqlDAc.ExecuteBySqlText(SqlDataAccess.ReturnType.Scalar, _sqlCommand, _sqlValues);

                _cxCtx = (byte[])_obj;

                // open the filestream to the blob
                SafeFileHandle handle = OpenSqlFilestream(dbPathName, DESIRED_ACCESS_READ, SQL_FILESTREAM_OPEN_NO_FLAGS, _cxCtx, (UInt32)_cxCtx.Length, 0);

                // open a Filestream to read the blob
                FileStream filestream = new FileStream(handle, FileAccess.Read);

                byte[] buffer = new byte[(int)filestream.Length];
                filestream.Read(buffer, 0, buffer.Length);
                filestream.Close();

                if (handle != null && !handle.IsClosed)
                    handle.Close();

               _sqlDAc.Commit();

                return buffer;
            }
            catch (Exception)
            {
                 _sqlDAc.Rollback();
                throw;
            }
        }
        private string GetFileDbPathNameByGuid(Guid fileGuid)
        {
            string bdpathName;
            _sqlDAc = new SqlDataAccess(_connectionString);
            _sqlValues = new Dictionary<string, object>();
            _sqlValues.Add("@fileGUID", fileGuid);
            _sqlCommand = "GetfsFilePathName";

            Object returnObject = _sqlDAc.ExecuteByStoredProc(SqlDataAccess.ReturnType.DataTable, _sqlCommand, ref _sqlValues);

            if (returnObject != null)
            {
                DataTable dataTable = (DataTable)returnObject;

                //se for encontrado algum relatório no banco com a guid recebida
                if (dataTable.Rows.Count > 0)
                {
                    DataRow[] dr = dataTable.Select();
                    //armazenando o guid e o pathName no array de strings
                    bdpathName = dr[0]["bdPathName"].ToString();
                }
                //Caso contrário retorna um array de bytes vazio
                else
                    return string.Empty;

                return bdpathName;
            }
            else
                return string.Empty;
        }
        private void UpdateReportStatus(Report report)
        {
            try
            {
                 _sqlDAc = new SqlDataAccess(_connectionString);
                 _sqlValues = new Dictionary<string, object>();

                 _sqlValues.Add("@reportGUID", report.ReportGuid);
                 _sqlValues.Add("@jsonReportResult", JsonHelper.ConvertToJSON(report));
                 if (!report.ReportGenerationStatus)
                     _sqlValues.Add("@errorDescription", report.ReportErrorDescription);

                 _sqlCommand = "UpdateReportStatus";

                 _sqlDAc.ExecuteByStoredProc(SqlDataAccess.ReturnType.NonQuery, _sqlCommand, ref _sqlValues);
            }
             catch (Exception ex)
             {
                 Exception newException = new Exception("Erro na geracao do historico do relatorio", ex);
                 throw newException;
             }
        }
        private void SaveReportsContainerInformation(ReportsContainer reportsContainer)
        {
            _sqlDAc = new SqlDataAccess(_connectionString);
            _sqlValues = new Dictionary<string, object>();

            reportsContainer.ReportsContainerGuid = Guid.NewGuid();

            _sqlValues.Add("@ReportsContainerGUID", reportsContainer.ReportsContainerGuid);
            _sqlValues.Add("@jsonReportsContainer", JsonHelper.ConvertToJSON(reportsContainer));
            _sqlValues.Add("@NetworkDomain", reportsContainer.NetworkDomain);
            _sqlValues.Add("@ReportUserLogin", reportsContainer.ReportUserLogin);
            _sqlValues.Add("@ReportUserPassword", reportsContainer.ReportUserPassword);
            _sqlValues.Add("@ReportServiceUrl", reportsContainer.ReportServiceUrl);
            _sqlValues.Add("@ReportExecutionUrl", reportsContainer.ReportExecutionUrl);

            _sqlCommand = "SaveReportContainerInformation";

            _sqlDAc.ExecuteByStoredProc(SqlDataAccess.ReturnType.NonQuery, _sqlCommand, ref _sqlValues);
        }
        private void SaveReportInformation(Report report, ReportsContainer reportsContainer)
        {
            _sqlDAc = new SqlDataAccess(_connectionString);
            _sqlValues = new Dictionary<string, object>();

            _sqlValues.Add("@jsonReport", JsonHelper.ConvertToJSON(report));
            _sqlValues.Add("@ReportName", report.ReportName);
            _sqlValues.Add("@reportsContainerGUID", reportsContainer.ReportsContainerGuid);

            if (report.ReportGuid != new Guid())
                _sqlValues.Add("@reportGUID", report.ReportGuid);

            _sqlCommand = "SaveReportInformation";

            var result = _sqlDAc.ExecuteByStoredProc(SqlDataAccess.ReturnType.Scalar, _sqlCommand, ref _sqlValues);

            report.ReportGuid = new Guid(result.ToString());
        }
        private ReportsContainer GetReportsContainerByGUID(Guid reportsContainerGUID)
        {
            ReportsContainer reportsContainer = null;
            _sqlDAc = new SqlDataAccess(_connectionString);
            _sqlValues = new Dictionary<string, object>();
            _sqlValues.Add("@reportsContainerGUID", reportsContainerGUID);
            _sqlCommand = "GetReportsContainerInformation";

            Object returnObject = _sqlDAc.ExecuteByStoredProc(SqlDataAccess.ReturnType.DataTable, _sqlCommand, ref _sqlValues);

            if (returnObject != null)
            {
                DataTable dataTable = (DataTable)returnObject;

                if (dataTable.Rows.Count > 0)
                {
                    DataRow[] dr = dataTable.Select();
                    reportsContainer = JsonHelper.ConvertToObject<ReportsContainer>(dr[0]["jsonReportsContainer"].ToString());
                }
            }
            return reportsContainer;
        }