示例#1
0
 static public void AddLoggedUsed(SecurityUser user)
 {
     lock (LoggedUsers)
     {
         if (!LoggedUsers.Contains(user))
         {
             LoggedUsers.Add(user);
         }
     }
 }
示例#2
0
 static public void RemoveLoggedUsed(SecurityUser user)
 {
     lock (LoggedUsers)
     {
         if (LoggedUsers.Contains(user))
         {
             LoggedUsers.Remove(user);
         }
     }
 }
示例#3
0
 SecurityUser CreateWebUser()
 {
     if (Repository == null)
     {
         CreateRepository();
     }
     var user = new SecurityUser(Repository.Security);
     Session[SessionUser] = user;
     return user;
 }
示例#4
0
 /// <summary>
 /// Remove a logged user
 /// </summary>
 static public void RemoveLoggedUsed(SecurityUser user)
 {
     lock (LoggedUsers)
     {
         if (LoggedUsers.Contains(user))
         {
             LoggedUsers.Remove(user);
         }
         UsersCountLogs.Add(new Tuple <DateTime, int>(DateTime.Now, SealSecurity.LoggedUsers.Where(i => i.IsAuthenticated).Count()));
     }
 }
示例#5
0
        public string GetPersonalFolder(SecurityUser user)
        {
            //add hash to the end of the name
            var    hash   = Helper.CalculateHash(user.WebUserName);
            string result = Path.Combine(PersonalFolder, string.Format("{0}_{1}", FileHelper.CleanFilePath(user.WebUserName), hash));

            if (!Directory.Exists(result))
            {
                Directory.CreateDirectory(result);
            }
            return(result);
        }
示例#6
0
 /// <summary>
 /// Executes the audit script for a given event
 /// </summary>
 public static void LogAudit(AuditType type, SecurityUser user, Report report, ReportSchedule schedule)
 {
     try
     {
         var script = Repository.Instance.Configuration.AuditScript;
         if (!string.IsNullOrEmpty(Repository.Instance.Configuration.AuditScript))
         {
             var audit = new Audit()
             {
                 Type = type, User = user, Report = report, Schedule = schedule
             };
             RazorHelper.CompileExecute(script, audit, Key);
         }
     }
     catch (Exception ex)
     {
         var message = string.Format("Error executing the Audit Script:\r\n{0}", ex.Message);
         Helper.WriteLogEntry("Seal Audit", EventLogEntryType.Error, ex.Message);
     }
 }
示例#7
0
 /// <summary>
 /// Executes the audit script for a given event
 /// </summary>
 public static void LogAudit(AuditType type, SecurityUser user, string path = null, string detail = null, string error = null, Report report = null, ReportSchedule schedule = null)
 {
     try
     {
         if (Repository.Instance.Configuration.AuditEnabled)
         {
             var script = Repository.Instance.Configuration.AuditScript;
             if (string.IsNullOrEmpty(script))
             {
                 script = AuditScriptTemplate;
             }
             var audit = new Audit()
             {
                 Type = type, User = user, Path = path, Detail = detail, Error = error, Report = report, Schedule = schedule
             };
             RazorHelper.CompileExecute(script, audit, Key);
         }
     }
     catch (Exception ex)
     {
         var message = string.Format("Error executing the Audit Script:\r\n{0}", ex.Message);
         Helper.WriteLogEntry("Seal Audit", EventLogEntryType.Error, ex.Message);
     }
 }
示例#8
0
 /// <summary>
 /// Audit a report execution
 /// </summary>
 public static void LogReportAudit(AuditType type, SecurityUser user, Report report, ReportSchedule schedule)
 {
     Audit.LogAudit(report.HasErrors ? AuditType.ReportExecutionError : AuditType.ReportExecution, report.SecurityContext, report.FilePath, null, report.ExecutionErrors, report, schedule);
 }
示例#9
0
 /// <summary>
 /// Returns the dashboard personal folder path of a user
 /// </summary>
 public string GetDashboardPersonalFolder(SecurityUser user)
 {
     return(Path.Combine(GetPersonalFolderName(user), "Dashboards"));
 }
示例#10
0
 /// <summary>
 /// Returns the personal folder name of a user
 /// </summary>
 public string GetPersonalFolderName(SecurityUser user)
 {
     return(TranslateWeb("Personal") + string.Format(" ({0})", user.GetPersonalFolderName()));;
 }
示例#11
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                setContext(context);
                if (_emailDevice != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperTestEmail")
                    {
                        _emailDevice.SendTestEmail();
                    }
                }
                else if (_metaConnection != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckConnection")
                    {
                        _metaConnection.CheckConnection();
                    }
                    if (context.PropertyDescriptor.Name == "HelperCreateFromExcelAccess")
                    {
                        string accessDriver = "Microsoft Access Driver (*.mdb)";
                        string excelDriver = "Microsoft Excel Driver (*.xls)";
                        try
                        {
                            List<string> drivers = Helper.GetSystemDriverList();
                            string accessDriver2 = "Microsoft Access Driver (*.mdb, *.accdb)";
                            if (drivers.Contains(accessDriver2)) accessDriver = accessDriver2;
                            string excelDriver2 = "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)";
                            if (drivers.Contains(excelDriver2)) excelDriver = excelDriver2;
                        }
                        catch { }

                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Title = "Open an Excel or an MS Access File";
                        dlg.CheckFileExists = true;
                        dlg.CheckPathExists = true;
                        dlg.InitialDirectory = _metaConnection.Source.Repository.RepositoryPath;
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            string ext = Path.GetExtension(dlg.FileName);
                            string driver = "";
                            if (ext == ".xls" || ext == ".xlsx" || ext == ".xlsm" || ext == ".xlsb")
                            {
                                _metaConnection.DatabaseType = DatabaseType.MSExcel;
                                driver = excelDriver;
                            }
                            else if (ext == ".mdb" || ext == ".accdb")
                            {
                                _metaConnection.DatabaseType = DatabaseType.MSAccess;
                                driver = accessDriver;
                            }
                            else throw new Exception("Please select an Excel or MS Access file");

                            string path = dlg.FileName.Replace(_metaConnection.Source.Repository.RepositoryPath, Repository.SealRepositoryKeyword);
                            _metaConnection.ConnectionString = string.Format(@"Provider=MSDASQL.1;Extended Properties=""DBQ={0};Driver={{{1}}};""", path, driver);
                            setModified();
                            MessageBox.Show("The connection has been created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else if (_metaTable != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperRefreshColumns")
                    {
                        _metaTable.Refresh();
                        setModified();
                        initEntity(_metaTable);
                    }
                    if (context.PropertyDescriptor.Name == "HelperCheckTable")
                    {
                        _metaTable.CheckTable(null);
                    }
                }
                else if (_metaEnum != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperRefreshEnum")
                    {
                        _metaEnum.RefreshEnum();
                        setModified();
                    }
                }
                else if (_metaColumn != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckColumn")
                    {
                        _metaColumn.MetaTable.CheckTable(_metaColumn);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperCreateEnum")
                    {
                        MetaEnum result = _metaColumn.Source.CreateEnumFromColumn(_metaColumn);
                        _metaColumn.EnumGUID = result.GUID;
                        initEntity(result);
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperShowValues")
                    {
                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            string result = _metaColumn.MetaTable.ShowValues(_metaColumn);
                            ExecutionForm frm = new ExecutionForm(null);
                            frm.Text = "Show values";
                            frm.cancelToolStripButton.Visible = false;
                            frm.pauseToolStripButton.Visible = false;
                            frm.logTextBox.Text = result;
                            frm.logTextBox.SelectionStart = 0;
                            frm.logTextBox.SelectionLength = 0;
                            frm.ShowDialog();
                        }
                        finally
                        {
                            Cursor.Current = Cursors.Default;
                        }
                    }
                    else if (context.PropertyDescriptor.Name == "HelperCreateDrillDates")
                    {
                        var year = _metaColumn.MetaTable.Source.AddColumn(_metaColumn.MetaTable);
                        year.DisplayName = _metaColumn.DisplayName + " Year";
                        year.Type = ColumnType.DateTime;
                        year.DateTimeStandardFormat = DateTimeStandardFormat.Custom;
                        year.Format = "yyyy";
                        var month = _metaColumn.MetaTable.Source.AddColumn(_metaColumn.MetaTable);
                        month.DisplayName = _metaColumn.DisplayName + " Month";
                        month.Type = ColumnType.DateTime;
                        month.DateTimeStandardFormat = DateTimeStandardFormat.Custom;
                        month.Format = "MM/yyyy";
                        if (_metaColumn.MetaTable.Source.Connection.DatabaseType == DatabaseType.Oracle)
                        {
                            year.Name = string.Format("trunc({0},'year')", _metaColumn.Name);
                            month.Name = string.Format("trunc({0},'month')", _metaColumn.Name);
                        }
                        else if (_metaColumn.MetaTable.Source.Connection.DatabaseType == DatabaseType.MSSQLServer)
                        {
                            year.Name = string.Format("select dateadd(dd, -day({0}) + 1, dateadd(mm, -month({0}) + 1, cast({0} as Date)))", _metaColumn.Name);
                            month.Name = string.Format("select dateadd(dd, -day({0}) + 1, cast({0} as Date))", _metaColumn.Name);
                        }
                        else if (_metaColumn.MetaTable.Source.Connection.DatabaseType == DatabaseType.MSAccess)
                        {
                            year.Name = string.Format("DateSerial(DatePart('yyyy',{0}), 1, 1)", _metaColumn.Name);
                            month.Name = string.Format("DateSerial(DatePart('yyyy',{0}), DatePart('m',{0}), 1)", _metaColumn.Name);
                        }
                        year.DrillChildren.Add(month.GUID);
                        month.DrillChildren.Add(_metaColumn.GUID);
                        initEntity(_metaColumn.MetaTable);
                        setModified();
                        MessageBox.Show("A 'Year' column and a 'Month' column have been added to the table with a drill hierarchy.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperCreateSubReport")
                    {
                        Report report = Report.Create(Repository.Create());
                        //Only on detail view
                        report.Views.Clear();
                        report.AddView(ReportViewTemplate.ModelDetailHTMLName);
                        report.Views[0].InitParameters(true);
                        report.Views[0].Parameters.First(i => i.Name == "restriction_button").BoolValue = false;

                        report.Sources.RemoveAll(i => i.MetaSourceGUID != _metaColumn.Source.GUID);

                        if (report.Sources.Count == 0) throw new Exception("Unable to create the detail report. Please save the Data Source first...");

                        //And one model
                        ReportModel model = report.Models[0];
                        model.SourceGUID = _metaColumn.Source.GUID;
                        //Add all the element of the table
                        foreach (var el in _metaColumn.MetaTable.Columns.OrderBy(i => i.DisplayOrder))
                        {
                            ReportElement element = ReportElement.Create();
                            element.MetaColumnGUID = el.GUID;
                            element.Name = el.Name;
                            element.PivotPosition = (el == _metaColumn ? PivotPosition.Page : PivotPosition.Row);
                            model.Elements.Add(element);
                        }

                        string entityName = _metaColumn.MetaTable.Name;
                        if (entityName.EndsWith("s")) entityName = entityName.Substring(0, entityName.Length - 1);
                        string path = Path.Combine(_metaColumn.MetaTable.Source.Repository.SubReportsFolder, Helper.CleanFileName(entityName + " Detail.") + Repository.SealReportFileExtension);
                        path = FileHelper.GetUniqueFileName(path);

                        var sr = new SubReport() { Path = path.Replace(_metaColumn.Source.Repository.RepositoryPath, Repository.SealRepositoryKeyword), Name = entityName + " Detail" };
                        //And the restriction, try to find out the table primary keys
                        try
                        {
                            DataTable schemaTables = ((OleDbConnection)_metaColumn.Source.GetOpenConnection()).GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, null);
                            Helper.DisplayDataTable(schemaTables);
                            foreach (DataRow row in schemaTables.Rows)
                            {
                                string schema = "";
                                if (schemaTables.Columns.Contains("TABLE_SCHEMA")) schema = row["TABLE_SCHEMA"].ToString();
                                else if (schemaTables.Columns.Contains("TABLE_SCHEM")) schema = row["TABLE_SCHEM"].ToString();
                                string fullName = (!string.IsNullOrEmpty(schema) ? _metaColumn.Source.GetTableName(schema) + "." : "") + _metaColumn.Source.GetTableName(row["TABLE_NAME"].ToString());
                                if (row["TABLE_NAME"].ToString() == _metaColumn.MetaTable.Name || fullName == _metaColumn.MetaTable.Name)
                                {
                                    var col = _metaColumn.MetaTable.Columns.FirstOrDefault(i => i.Name.ToLower() == row["COLUMN_NAME"].ToString().ToLower() || i.Name.ToLower().EndsWith("." + row["COLUMN_NAME"].ToString().ToLower()));
                                    if (col != null)
                                    {
                                        sr.Restrictions.Add(col.GUID);
                                    }
                                    else
                                    {
                                        //not all pk available....
                                        sr.Restrictions.Clear();
                                        break;
                                    }
                                }
                            }
                        }
                        catch { }

                        string message = "";
                        if (sr.Restrictions.Count == 0)
                        {
                            //no PK found, we add the value itself...
                            sr.Restrictions.Add(_metaColumn.GUID);
                            message = "The Sub-Report restriction is based on the Column.";
                        }
                        else
                        {
                            message = "The Sub-Report restrictions are based on the table Primary Keys.";
                        }

                        foreach (var guid in sr.Restrictions)
                        {
                            ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                            restriction.MetaColumnGUID = guid;
                            restriction.PivotPosition = PivotPosition.Row;
                            restriction.Prompt = PromptType.Prompt;
                            restriction.Operator = Operator.Equal;
                            model.Restrictions.Add(restriction);
                            if (!string.IsNullOrEmpty(model.Restriction)) model.Restriction += "\r\nAND ";
                            model.Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;
                        }

                        report.SaveToFile(path);
                        _metaColumn.SubReports.Add(sr);

                        if (MessageBox.Show(string.Format("A Sub-Report named '{0}' has been created in the dedicated Repository folder.\r\n{1}\r\nDo you want to edit it using a new Report Designer ?", Path.GetFileName(path), message), "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            Process.Start(path);
                        };

                        _metaColumn.UpdateEditor();
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperAddSubReport")
                    {
                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Filter = string.Format(Repository.SealRootProductName + " Reports files (*.{0})|*.{0}|All files (*.*)|*.*", Repository.SealReportFileExtension);
                        dlg.Title = "Select a Sub-Report having prompted restrictions";
                        dlg.CheckFileExists = true;
                        dlg.CheckPathExists = true;
                        dlg.InitialDirectory = _metaColumn.Source.Repository.SubReportsFolder;
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            Report report = Report.LoadFromFile(dlg.FileName, _metaColumn.Source.Repository);
                            var sr = new SubReport() { Path = report.FilePath.Replace(_metaColumn.Source.Repository.RepositoryPath, Repository.SealRepositoryKeyword), Name = Path.GetFileNameWithoutExtension(dlg.FileName) };

                            foreach (var model in report.Models.Where(i => i.Source.MetaSourceGUID == _metaColumn.Source.GUID))
                            {
                                foreach (var restriction in model.Restrictions.Where(i => i.Prompt != PromptType.None))
                                {
                                    var col = _metaColumn.MetaTable.Columns.FirstOrDefault(i => i.GUID == restriction.MetaColumnGUID);
                                    if (col != null)
                                    {
                                        sr.Restrictions.Add(col.GUID);
                                    }
                                }
                            }

                            if (sr.Restrictions.Count == 0) throw new Exception("Unable to add this Sub-Report:\r\nThe report does no contain any prompted restriction belonging to the table...");

                            _metaColumn.SubReports.Add(sr);
                            MessageBox.Show(string.Format("The Sub-Report named '{0}' has been added with {1} restriction(s).", Path.GetFileName(dlg.FileName), sr.Restrictions.Count), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            _metaColumn.UpdateEditor();
                            setModified();
                        }
                    }
                    else if (context.PropertyDescriptor.Name == "HelperOpenSubReportFolder")
                    {
                        Process.Start(_metaColumn.Source.Repository.SubReportsFolder);
                    }
                }
                else if (_metaJoin != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckJoin")
                    {
                        _metaJoin.CheckJoin();
                    }
                }
                else if (_reportView != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperReloadConfiguration")
                    {
                        _reportView.InitParameters(false);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetParameters")
                    {
                        _reportView.InitParameters(true);
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetCSSParameters")
                    {
                        _reportView.InitParameters(true, true, false);
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetNVD3Parameters")
                    {
                        _reportView.InitParameters(true, false, true);
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetChartConfiguration")
                    {
                        _reportView.ResetChartConfiguration();
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetPDFConfigurations")
                    {
                        _reportView.PdfConfigurations = new List<string>();
                        _reportView.PdfConverter = null;
                        _reportView.Information = Helper.FormatMessage("The PDF configuration values have been reset");
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetExcelConfigurations")
                    {
                        _reportView.ExcelConfigurations = new List<string>();
                        _reportView.ExcelConverter = null;
                        _reportView.Information = Helper.FormatMessage("The Excel configuration values have been reset");
                        setModified();
                    }
                }
                else if (_reportSchedule != null)
                {
                    if (HandlerInterface != null && context.PropertyDescriptor.Name == "HelperEditProperties")
                    {
                        HandlerInterface.EditSchedule(_reportSchedule);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperRunTaskScheduler")
                    {
                        Process.Start(Path.Combine(Environment.SystemDirectory, "taskschd.msc"), "/s");
                    }
                }
                else if (_parameter != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperResetParameterValue")
                    {
                        _parameter.Value = _parameter.ConfigValue;
                        setModified();
                    }
                }
                else if (_security != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperSimulateLogin")
                    {
                        SecurityUser user = new SecurityUser(_security);
                        user.WebUserName = _security.TestUserName;
                        user.WebPassword = _security.TestPassword;
                        if (_security.TestCurrentWindowsUser) user.WebPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                        user.Authenticate();
                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            ExecutionForm frm = new ExecutionForm(null);
                            frm.Text = "Test a login";
                            frm.cancelToolStripButton.Visible = false;
                            frm.pauseToolStripButton.Visible = false;
                            frm.logTextBox.Text = user.AuthenticationSummary;
                            frm.logTextBox.SelectionStart = 0;
                            frm.logTextBox.SelectionLength = 0;
                            frm.ShowDialog();
                        }
                        finally
                        {
                            Cursor.Current = Cursors.Default;
                        }

                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

            return value;
        }
示例#12
0
        public void InitForExecution()
        {
            string fileName = "", fileFolder = "";
            if (ForOutput)
            {
                //Check custom Output Parameters and CSS
                Parameter.CopyParameters(OutputToExecute.ViewParameters, OutputToExecute.View.Parameters);
                Parameter.CopyParameters(OutputToExecute.ViewCSS, OutputToExecute.View.CSS);

                //Add the security context for the output if specified
                if (!string.IsNullOrWhiteSpace(OutputToExecute.UserName) || !string.IsNullOrWhiteSpace(OutputToExecute.UserGroups))
                {
                    SecurityContext = new SecurityUser(Repository.Security) { Name = OutputToExecute.UserName };
                    string[] groups= OutputToExecute.UserGroups.Replace(";", "\r").Replace("\n", "").Split('\r');
                    foreach (string group in groups) SecurityContext.AddSecurityGroup(group);
                }

                if (!string.IsNullOrEmpty(OutputToExecute.UserCulture))
                {
                    SecurityContext.SetDefaultCulture(OutputToExecute.UserCulture);
                }
            }

            try
            {
                var template = ExecutionView.Template; //This force to init parameters
                fileName = ResultFileName;
                fileFolder = ResultFolder;
                if (ForOutput && OutputToExecute.Device is OutputFolderDevice)
                {
                    //For folder output, we do not need a unique file name
                    ResultFilePath = Path.Combine(ResultFolder, Path.GetFileNameWithoutExtension(fileName)) + (!HasExternalViewer || string.IsNullOrEmpty(ExecutionView.ExternalViewerExtension) ? Path.GetExtension(fileName) : "." + ExecutionView.ExternalViewerExtension);
                }
                else
                {
                    //get unique file name in the result folder
                    ResultFilePath = FileHelper.GetUniqueFileName(Path.Combine(ResultFolder, fileName), "." + ExecutionView.ExternalViewerExtension);
                }
                ResultFilePrefix = FileHelper.GetResultFilePrefix(ResultFilePath);
                if (Repository.Configuration.IsLocal && ExecutionContext != ReportExecutionContext.WebReport && ExecutionContext != ReportExecutionContext.WebOutput && !Directory.Exists(Path.Combine(ResultFolder, "images")) && !ExecutionView.Views.Exists(i => i.Template.Name == ReportViewTemplate.ModelCSVExcelName))
                {
                    try
                    {
                        //copy images folder (for jquery images)
                        FileHelper.CopyDirectory(Path.Combine(Repository.ViewContentFolder, "images"), Path.Combine(ResultFolder, "images"), false);
                    }
                    catch { }
                }

                //Display path is always an HTML one...
                HTMLDisplayFilePath = FileHelper.GetUniqueFileName(Path.Combine(DisplayFolder, ResultFilePrefix + ".htm"));

                //Clear some cache values...
                _displayNameEx = null;

            }
            catch (Exception ex)
            {
                Cancel = true;
                if (string.IsNullOrEmpty(fileFolder) && OutputToExecute != null && !string.IsNullOrEmpty(OutputToExecute.FolderPath)) fileFolder = OutputToExecute.FolderPath;
                ExecutionErrors += string.Format("Error initializing report Path, check your report execution or output Path '{0}'\r\n{1}\r\n", Path.Combine(fileFolder, fileName), ex.Message);
            }

            if (!string.IsNullOrEmpty(InitScript))
            {
                try
                {
                    Helper.ParseRazor(InitScript, this);
                }
                catch(Exception ex2)
                {
                    ExecutionErrors += string.Format("Error executing init script\r\n{0}\r\n", ex2.Message);
                }
            }
        }
示例#13
0
 public string GetPersonalFolderName(SecurityUser user)
 {
     return TranslateWeb("Personal") + string.Format(" ({0})", user.WebUserName); ;
 }
示例#14
0
 public string GetPersonalFolder(SecurityUser user)
 {
     //add hash to the end of the name
     var hash = Helper.CalculateHash(user.WebUserName);
     string result = Path.Combine(PersonalFolder, string.Format("{0}_{1}", FileHelper.CleanFilePath(user.WebUserName), hash));
     if (!Directory.Exists(result)) Directory.CreateDirectory(result);
     return result;
 }
示例#15
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                setContext(context);
                if (_emailDevice != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperTestEmail")
                    {
                        _emailDevice.SendTestEmail();
                    }
                }
                else if (_metaConnection != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckConnection")
                    {
                        _metaConnection.CheckConnection();
                    }
                    if (context.PropertyDescriptor.Name == "HelperCreateFromExcelAccess")
                    {
                        string accessDriver = "Microsoft Access Driver (*.mdb)";
                        string excelDriver = "Microsoft Excel Driver (*.xls)";
                        try
                        {
                            List<string> drivers = Helper.GetSystemDriverList();
                            string accessDriver2 = "Microsoft Access Driver (*.mdb, *.accdb)";
                            if (drivers.Contains(accessDriver2)) accessDriver = accessDriver2;
                            string excelDriver2 = "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)";
                            if (drivers.Contains(excelDriver2)) excelDriver = excelDriver2;
                        }
                        catch { }

                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Title = "Open an Excel or an MS Access File";
                        dlg.CheckFileExists = true;
                        dlg.CheckPathExists = true;
                        dlg.InitialDirectory = _metaConnection.Source.Repository.RepositoryPath;
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            string ext = Path.GetExtension(dlg.FileName);
                            string driver = "";
                            if (ext == ".xls" || ext == ".xlsx" || ext == ".xlsm" || ext == ".xlsb")
                            {
                                _metaConnection.DatabaseType = DatabaseType.MSExcel;
                                driver = excelDriver;
                            }
                            else if (ext == ".mdb" || ext == ".accdb")
                            {
                                _metaConnection.DatabaseType = DatabaseType.MSAccess;
                                driver = accessDriver;
                            }
                            else throw new Exception("Please select an Excel or MS Access file");

                            string path = dlg.FileName.Replace(_metaConnection.Source.Repository.RepositoryPath, Repository.SealRepositoryKeyword);
                            _metaConnection.ConnectionString = string.Format(@"Provider=MSDASQL.1;Extended Properties=""DBQ={0};Driver={{{1}}};""", path, driver);
                            setModified();
                            MessageBox.Show("The connection has been created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else if (_metaTable != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperRefreshColumns")
                    {
                        _metaTable.Refresh();
                        setModified();
                        initEntity(_metaTable);
                    }
                    if (context.PropertyDescriptor.Name == "HelperCheckTable")
                    {
                        _metaTable.CheckTable(null);
                    }
                }
                else if (_metaEnum != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperRefreshEnum")
                    {
                        _metaEnum.RefreshEnum();
                        setModified();
                    }
                }
                else if (_metaColumn != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckColumn")
                    {
                        _metaColumn.MetaTable.CheckTable(_metaColumn);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperCreateEnum")
                    {
                        MetaEnum result = _metaColumn.Source.CreateEnumFromColumn(_metaColumn);
                        _metaColumn.EnumGUID = result.GUID;
                        initEntity(result);
                        setModified();
                    }
                    if (context.PropertyDescriptor.Name == "HelperShowValues")
                    {
                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            string result = _metaColumn.MetaTable.ShowValues(_metaColumn);
                            ExecutionForm frm = new ExecutionForm(null);
                            frm.Text = "Show values";
                            frm.cancelToolStripButton.Visible = false;
                            frm.pauseToolStripButton.Visible = false;
                            frm.logTextBox.Text = result;
                            frm.logTextBox.SelectionStart = 0;
                            frm.logTextBox.SelectionLength = 0;
                            frm.ShowDialog();
                        }
                        finally
                        {
                            Cursor.Current = Cursors.Default;
                        }
                    }
                }
                else if (_metaJoin != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckJoin")
                    {
                        _metaJoin.CheckJoin();
                    }
                }
                else if (_reportView != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperReloadConfiguration")
                    {
                        _reportView.InitParameters(false);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetParameters")
                    {
                        _reportView.InitParameters(true);
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetChartConfiguration")
                    {
                        _reportView.ResetChartConfiguration();
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetNVD3ChartConfiguration")
                    {
                        var defaultValue = _reportView.Template.Parameters.FirstOrDefault(i => i.Name == Parameter.NVD3ConfigurationParameter);
                        if (_reportView.NVD3ConfigurationParameter != null && defaultValue != null)
                        {
                            _reportView.NVD3Configuration = defaultValue.TextValue;
                            _reportView.Information = Helper.FormatMessage("NVD3 Chart configuration has been reset");
                            setModified();
                        }
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetPDFConfigurations")
                    {
                        _reportView.PdfConfigurations = new List<string>();
                        _reportView.PdfConverter = null;
                        _reportView.Information = Helper.FormatMessage("The PDF configuration values have been reset");
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetExcelConfigurations")
                    {
                        _reportView.ExcelConfigurations = new List<string>();
                        _reportView.ExcelConverter = null;
                        _reportView.Information = Helper.FormatMessage("The Excel configuration values have been reset");
                        setModified();
                    }
                }
                else if (_reportSchedule != null)
                {
                    if (HandlerInterface != null && context.PropertyDescriptor.Name == "HelperEditProperties")
                    {
                        HandlerInterface.EditSchedule(_reportSchedule);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperRunTaskScheduler")
                    {
                        Process.Start(Path.Combine(Environment.SystemDirectory, "taskschd.msc"), "/s");
                    }
                }
                else if (_parameter != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperResetParameterValue")
                    {
                        _parameter.Value = _parameter.ConfigValue;
                        setModified();
                    }
                }
                else if (_security != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperSimulateLogin")
                    {
                        SecurityUser user = new SecurityUser(_security);
                        user.WebUserName = _security.TestUserName;
                        user.WebPassword = _security.TestPassword;
                        if (_security.TestCurrentWindowsUser) user.WebPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                        user.Authenticate();
                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            ExecutionForm frm = new ExecutionForm(null);
                            frm.Text = "Test a login";
                            frm.cancelToolStripButton.Visible = false;
                            frm.pauseToolStripButton.Visible = false;
                            frm.logTextBox.Text = user.AuthenticationSummary;
                            frm.logTextBox.SelectionStart = 0;
                            frm.logTextBox.SelectionLength = 0;
                            frm.ShowDialog();
                        }
                        finally
                        {
                            Cursor.Current = Cursors.Default;
                        }

                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

            return value;
        }