void addValidFolders(SWIFolder folder, List <SWIFolder> result)
 {
     if (folder.right == 0)
     {
         //Add only folder with rights
         foreach (var childFolder in folder.folders)
         {
             addValidFolders(childFolder, result);
         }
     }
     else
     {
         result.Add(folder);
     }
 }
Exemple #2
0
        SWIFolder getFolder(string path)
        {
            checkSWIAuthentication();
            if (string.IsNullOrEmpty(path))
            {
                throw new Exception("Error: path must be supplied");
            }
            if (path.Contains("..\\"))
            {
                throw new Exception("Error: invalid path");
            }
            SWIFolder result = new SWIFolder();

            result.path  = path;
            result.right = 0;
            result.sql   = WebUser.SqlModel;
            result.SetFullPath(getFullPath(path));

            if (result.IsPersonal)
            {
                //Personal
                if (WebUser.PersonalFolderRight == PersonalFolderRight.None)
                {
                    throw new Exception("Error: this user has no personal folder");
                }
                result.SetManageFlag(true, true, result.Path == "");
                result.expand = false;
                string prefix = Repository.GetPersonalFolderName(WebUser);
                result.name     = (result.Path == "" ? prefix : Path.GetFileName(result.Path));
                result.fullname = prefix + (result.Path == "" ? "\\" : "") + result.Path;
                result.right    = (int)FolderRight.Edit;
                result.files    = (WebUser.PersonalFolderRight == PersonalFolderRight.Files);
            }
            else
            {
                result.name     = (result.Path == "\\" ? Translate("Reports") : Repository.TranslateFolderName(path));
                result.fullname = Translate("Reports") + Repository.TranslateFolderPath(result.Path);
                SecurityFolder securityFolder = WebUser.FindSecurityFolder(path);
                if (securityFolder != null)
                {
                    result.SetManageFlag(securityFolder.UseSubFolders, securityFolder.ManageFolder, securityFolder.IsDefined);
                    result.expand = securityFolder.ExpandSubFolders;
                    result.right  = (int)securityFolder.FolderRight;
                    result.files  = securityFolder.FilesOnly;
                }
            }
            return(result);
        }
        /// <summary>
        /// Returns the views and outputs of a report.
        /// </summary>
        public ActionResult SWIGetReportDetail(string path)
        {
            writeDebug("SWIGetReportDetail");
            try
            {
                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }

                var file = getFileDetail(path);
                if (file.right == 0)
                {
                    throw new Exception("Error: no right on this report or file");
                }

                string newPath = getFullPath(path);
                if (!System.IO.File.Exists(newPath))
                {
                    throw new Exception("Report path not found");
                }
                Repository      repository = Repository;
                Report          report     = Report.LoadFromFile(newPath, repository, false);
                SWIReportDetail result     = new SWIReportDetail();
                result.views   = (from i in report.Views.Where(i => i.WebExec && i.GUID != report.ViewGUID) select new SWIView()
                {
                    guid = i.GUID, name = i.Name, displayname = report.TranslateViewName(i.Name)
                }).ToList();
                result.outputs = ((FolderRight)folder.right >= FolderRight.ExecuteReportOuput) ? (from i in report.Outputs.Where(j => j.PublicExec || string.IsNullOrEmpty(j.UserName) || (!j.PublicExec && j.UserName == WebUser.Name)) select new SWIOutput()
                {
                    guid = i.GUID, name = i.Name, displayname = report.TranslateOutputName(i.Name)
                }).ToList() : new List <SWIOutput>();
                if (result.views.Count == 0 && result.outputs.Count == 0)
                {
                    result.views = (from i in report.Views.Where(i => i.WebExec) select new SWIView()
                    {
                        guid = i.GUID, name = i.Name, displayname = report.TranslateViewName(i.Name)
                    }).ToList();
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }
Exemple #4
0
 public ActionResult SWICreateFolder(string path)
 {
     try
     {
         SWIFolder folder = getFolder(path);
         if (folder.manage == 0)
         {
             throw new Exception("Error: no right to create in this folder");
         }
         Directory.CreateDirectory(folder.GetFullPath());
         return(Json(new object { }));
     }
     catch (Exception ex)
     {
         return(handleSWIException(ex));
     }
 }
 public ActionResult SWIDeleteFolder(string path)
 {
     try
     {
         SWIFolder folder = getFolder(path);
         if (folder.manage != 2)
         {
             throw new Exception("Error: no right to delete this folder");
         }
         Directory.Delete(folder.GetFullPath());
         return(Json(new object { }));
     }
     catch (Exception ex)
     {
         return(HandleSWIException(ex));
     }
 }
Exemple #6
0
 public ActionResult SWISearch(string path, string pattern)
 {
     try
     {
         SWIFolder folder = getFolder(path);
         var       files  = new List <SWIFile>();
         path = folder.GetFullPath();
         searchFolder(folder, pattern, files);
         return(Json(new SWIFolderDetail()
         {
             files = files.ToArray()
         }));
     }
     catch (Exception ex)
     {
         return(handleSWIException(ex));
     }
 }
Exemple #7
0
 public ActionResult SWIRenameFolder(string source, string destination)
 {
     try
     {
         SWIFolder folderSource = getFolder(source);
         SWIFolder folderDest   = getFolder(destination);
         if (folderSource.manage != 2 || folderDest.manage != 2)
         {
             throw new Exception("Error: no right to rename this folder");
         }
         Directory.Move(folderSource.GetFullPath(), folderDest.GetFullPath());
         return(Json(new object { }));
     }
     catch (Exception ex)
     {
         return(handleSWIException(ex));
     }
 }
 /// <summary>
 /// Delete a sub-folder in the repository. The folder must be empty.
 /// </summary>
 public ActionResult SWIDeleteFolder(string path)
 {
     writeDebug("SWIDeleteFolder");
     try
     {
         SWIFolder folder = getFolder(path);
         if (folder.manage != 2)
         {
             throw new Exception("Error: no right to delete this folder");
         }
         Directory.Delete(folder.GetFullPath());
         Audit.LogAudit(AuditType.FolderDelete, WebUser, folder.GetFullPath());
         return(Json(new object { }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(HandleSWIException(ex));
     }
 }
        public ActionResult SWIGetFolderDetail(string path)
        {
            writeDebug("SWIGetFolderDetail");
            try
            {
                SWIFolder folder = getFolder(path);
                var       files  = new List <SWIFile>();
                if (folder.right > 0)
                {
                    foreach (string newPath in Directory.GetFiles(folder.GetFullPath(), "*.*"))
                    {
                        //check right on files only
                        if (folder.files && FileHelper.IsSealReportFile(newPath))
                        {
                            continue;
                        }
                        if (folder.IsPersonal && newPath.ToLower() == WebUser.ProfilePath.ToLower())
                        {
                            continue;
                        }

                        files.Add(new SWIFile()
                        {
                            path     = folder.Combine(Path.GetFileName(newPath)),
                            name     = Repository.TranslateFileName(newPath) + (FileHelper.IsSealReportFile(newPath) ? "" : Path.GetExtension(newPath)),
                            last     = System.IO.File.GetLastWriteTime(newPath).ToString("G", Repository.CultureInfo),
                            isreport = FileHelper.IsSealReportFile(newPath),
                            right    = folder.right
                        });
                    }
                }
                setCookie(SealLastFolderCookieName, path);

                return(Json(new SWIFolderDetail()
                {
                    folder = folder, files = files.ToArray()
                }));
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }
 public ActionResult SWICreateFolder(string path)
 {
     writeDebug("SWICreateFolder");
     try
     {
         SWIFolder folder = getFolder(path);
         if (folder.manage == 0)
         {
             throw new Exception("Error: no right to create in this folder");
         }
         Directory.CreateDirectory(folder.GetFullPath());
         Audit.LogAudit(AuditType.FolderCreate, WebUser, folder.GetFullPath());
         return(Json(new object { }));
     }
     catch (Exception ex)
     {
         return(HandleSWIException(ex));
     }
 }
        private void inlineGetRootFolder()
        {
            checkSWIAuthentication();
            List <SWIFolder> result = new List <SWIFolder>();

            //Personal
            if (WebUser.PersonalFolderRight != PersonalFolderRight.None)
            {
                var personalFolder = getFolder(SWIFolder.GetPersonalRoot());
                fillFolder(personalFolder);
                result.Add(personalFolder);
            }
            //Report
            var folder = getFolder("\\");

            fillFolder(folder);
            result.Add(folder);

            WebUser.Folders = result;
        }
 public ActionResult SWIRenameFolder(string source, string destination)
 {
     writeDebug("SWIRenameFolder");
     try
     {
         SWIFolder folderSource = getFolder(source);
         SWIFolder folderDest   = getFolder(destination);
         if (folderSource.manage != 2 || folderDest.manage != 2)
         {
             throw new Exception("Error: no right to rename this folder");
         }
         Directory.Move(folderSource.GetFullPath(), folderDest.GetFullPath());
         Audit.LogAudit(AuditType.FolderRename, WebUser, folderSource.GetFullPath(), string.Format("Rename to '{0}'", folderDest.GetFullPath()));
         return(Json(new object { }));
     }
     catch (Exception ex)
     {
         return(HandleSWIException(ex));
     }
 }
Exemple #13
0
        public ActionResult SWIGetReportDetail(string path)
        {
            try
            {
                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }

                string newPath = getFullPath(path);
                if (!System.IO.File.Exists(newPath))
                {
                    throw new Exception("Report path not found");
                }
                Repository      repository = Repository;
                Report          report     = Report.LoadFromFile(newPath, repository);
                SWIReportDetail result     = new SWIReportDetail();
                result.views   = (from i in report.Views.Where(i => i.WebExec && i.GUID != report.ViewGUID) select new SWIView()
                {
                    guid = i.GUID, name = i.Name, displayName = report.TranslateViewName(i.Name)
                }).ToArray();
                result.outputs = ((FolderRight)folder.right >= FolderRight.ExecuteReportOuput) ? (from i in report.Outputs.Where(j => j.PublicExec || (!j.PublicExec && j.UserName == WebUser.Name)) select new SWIOutput()
                {
                    guid = i.GUID, name = i.Name, displayName = report.TranslateOutputName(i.Name)
                }).ToArray() : new SWIOutput[] { };
                if (result.views.Length == 0 && result.outputs.Length == 0)
                {
                    result.views = (from i in report.Views.Where(i => i.WebExec) select new SWIView()
                    {
                        guid = i.GUID, name = i.Name, displayName = report.TranslateViewName(i.Name)
                    }).ToArray();
                }

                return(Json(result));
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }
        public ActionResult SWIDeleteFiles(string paths)
        {
            writeDebug("SWIDeleteFiles");
            try
            {
                checkSWIAuthentication();
                if (string.IsNullOrEmpty(paths))
                {
                    throw new Exception("Error: paths must be supplied");
                }

                foreach (var path in paths.Split('\n'))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        SWIFolder folder = getParentFolder(path);
                        if ((FolderRight)folder.right != FolderRight.Edit)
                        {
                            throw new Exception("Error: no right to edit in this folder");
                        }
                        string fullPath = getFullPath(path);
                        if (FileHelper.IsSealReportFile(fullPath) && FileHelper.ReportHasSchedule(fullPath))
                        {
                            //Delete schedules...
                            var report = Report.LoadFromFile(fullPath, Repository, false);
                            report.Schedules.Clear();
                            report.SynchronizeTasks();
                        }

                        FileHelper.DeleteSealFile(fullPath);

                        Audit.LogAudit(AuditType.FileDelete, WebUser, path);
                    }
                }
                return(Json(new object { }));
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }
        /// <summary>
        /// Returns all the folders of the user (including Personal folders).
        /// </summary>
        public ActionResult SWIGetRootFolders()
        {
            writeDebug("SWIGetRootFolders");
            try
            {
                checkSWIAuthentication();
                List <SWIFolder> result = new List <SWIFolder>();
                //Personal
                if (WebUser.PersonalFolderRight != PersonalFolderRight.None)
                {
                    var personalFolder = getFolder(SWIFolder.GetPersonalRoot());
                    fillFolder(personalFolder);
                    result.Add(personalFolder);
                }
                //Report
                var folder = getFolder(Path.DirectorySeparatorChar.ToString());
                fillFolder(folder);
                if (WebUser.ShowAllFolders)
                {
                    result.Add(folder);
                }
                else
                {
                    addValidFolders(folder, result);
                }

                //Folders Script
                WebUser.Folders      = result;
                WebUser.ScriptNumber = 1;
                foreach (var group in WebUser.SecurityGroups.Where(i => !string.IsNullOrEmpty(i.FoldersScript)).OrderBy(i => i.Name))
                {
                    RazorHelper.CompileExecute(group.FoldersScript, WebUser);
                    WebUser.ScriptNumber++;
                }
                return(Json(WebUser.Folders, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }
        /// <summary>
        /// Returns the list of file names and details matching a search in the repository.
        /// </summary>
        public ActionResult SWISearch(string path, string pattern)
        {
            writeDebug("SWISearch");
            try
            {
                checkSWIAuthentication();
                SWIFolder folder = getFolder(path);
                var       files  = new List <SWIFile>();
                path = folder.GetFullPath();
                searchFolder(folder, pattern, files);

                return(Json(new SWIFolderDetail()
                {
                    files = files
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }
        public ActionResult SWExecuteReport(string path, bool?render, string viewGUID, string outputGUID)
        {
            writeDebug("SWExecuteReport");
            try
            {
                if (!CheckAuthentication())
                {
                    return(Content(_loginContent));
                }

                Report     report     = null;
                Repository repository = null;

                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }
                if (!string.IsNullOrEmpty(outputGUID) && (FolderRight)folder.right == FolderRight.Execute)
                {
                    throw new Exception("Error: no right to execute output on this folder");
                }

                string filePath = getFullPath(path);
                if (!System.IO.File.Exists(filePath))
                {
                    throw new Exception("Error: report does not exist");
                }
                repository = Repository.CreateFast();
                report     = Report.LoadFromFile(filePath, repository);

                var execution = initReportExecution(report, viewGUID, outputGUID, false);
                execution.RenderHTMLDisplayForViewer();
                return(getFileResult(report.HTMLDisplayFilePath, report));
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
Exemple #18
0
        void searchFolder(SWIFolder folder, string pattern, List <SWIFile> files)
        {
            foreach (string newPath in Directory.GetFiles(folder.GetFullPath(), "*.*").Where(i => !FileHelper.IsSealAttachedFile(i) && Path.GetFileName(i).ToLower().Contains(pattern.ToLower())))
            {
                files.Add(new SWIFile()
                {
                    path     = folder.Combine(Path.GetFileName(newPath)),
                    name     = folder.fullname + "\\" + Repository.TranslateFileName(newPath) + (FileHelper.IsSealReportFile(newPath) ? "" : Path.GetExtension(newPath)),
                    last     = System.IO.File.GetLastWriteTime(newPath).ToString("G", Repository.CultureInfo),
                    isReport = FileHelper.IsSealReportFile(newPath),
                    right    = folder.right
                });
            }

            foreach (string subFolder in Directory.GetDirectories(folder.GetFullPath()))
            {
                SWIFolder sub = getFolder(folder.Combine(subFolder));
                if (sub.right > 0)
                {
                    searchFolder(sub, pattern, files);
                }
            }
        }
Exemple #19
0
        void fillFolder(SWIFolder folder)
        {
            List <SWIFolder> subFolders = new List <SWIFolder>();

            if (folder.IsPersonal && WebUser.PersonalFolderRight == PersonalFolderRight.None)
            {
                return;
            }

            string folderPath = folder.GetFullPath();

            foreach (string subFolder in Directory.GetDirectories(folderPath))
            {
                SWIFolder sub = getFolder(folder.Combine(subFolder));
                //Add if right on this folder, or a sub folder is defined with this root
                if ((sub.right > 0) || WebUser.SecurityGroups.Exists(i => i.Folders.Exists(j => j.Path.StartsWith(sub.path + (sub.path == "\\" ? "" : "\\")) && j.FolderRight != FolderRight.None)))
                {
                    fillFolder(sub);
                    subFolders.Add(sub);
                }
            }
            folder.folders = subFolders.ToArray();
        }
        public ActionResult SWViewFile(string path)
        {
            writeDebug("SWViewFile");
            try
            {
                if (!CheckAuthentication())
                {
                    return(Content(_loginContent));
                }

                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }

                return(getFileResult(getFullPath(path), null));
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
Exemple #21
0
        public ActionResult SWIExecuteReport(string path, bool?render, string viewGUID, string outputGUID)
        {
            try
            {
                checkSWIAuthentication();

                Report     report     = null;
                Repository repository = null;

                if (string.IsNullOrEmpty(path))
                {
                    throw new Exception("Error: path must be supplied");
                }
                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }

                string filePath = getFullPath(path);
                if (!System.IO.File.Exists(filePath))
                {
                    throw new Exception("Error: report does not exist");
                }
                repository = Repository.CreateFast();
                report     = Report.LoadFromFile(filePath, repository);

                var execution = initReportExecution(report, viewGUID, outputGUID);
                execution.RenderHTMLDisplayForViewer();
                return(getFileResult(report.HTMLDisplayFilePath, report));
            }
            catch (Exception ex)
            {
                return(handleSWIException(ex));
            }
        }
        public ActionResult SWExecuteReportToResult(string path, string viewGUID, string outputGUID, string format)
        {
            writeDebug("SWExecuteReportToResult");
            try
            {
                if (!CheckAuthentication())
                {
                    return(Content(_loginContent));
                }

                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }
                if (!string.IsNullOrEmpty(outputGUID) && (FolderRight)folder.right == FolderRight.Execute)
                {
                    throw new Exception("Error: no right to execute output on this folder");
                }

                string filePath = getFullPath(path);
                if (!System.IO.File.Exists(filePath))
                {
                    throw new Exception("Error: report does not exist");
                }
                Repository repository = Repository.CreateFast();
                Report     report     = Report.LoadFromFile(filePath, repository);

                var execution = initReportExecution(report, viewGUID, outputGUID, true);
                execution.Execute();
                while (report.Status != ReportStatus.Executed && !report.HasErrors)
                {
                    Thread.Sleep(100);
                }

                ActionResult result = null;
                if (!string.IsNullOrEmpty(outputGUID))
                {
                    result = getFileResult(report.ResultFilePath, report);
                }
                else
                {
                    string fileResult = "";
                    if (string.IsNullOrEmpty(format))
                    {
                        format = "html";
                    }
                    if (format.ToLower() == "print")
                    {
                        fileResult = execution.GeneratePrintResult();
                    }
                    else if (format.ToLower() == "pdf")
                    {
                        fileResult = execution.GeneratePDFResult();
                    }
                    else if (format.ToLower() == "excel")
                    {
                        fileResult = execution.GenerateExcelResult();
                    }
                    else if (format.ToLower() == "csv")
                    {
                        fileResult = execution.GenerateCSVResult();
                    }
                    else
                    {
                        fileResult = execution.GenerateHTMLResult();
                    }
                    result = getFileResult(fileResult, report);
                }
                report.PreInputRestrictions.Clear();
                return(result);
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
        public ActionResult ActionNavigate(string execution_guid)
        {
            writeDebug("ActionNavigate");
            try
            {
                if (!CheckAuthentication())
                {
                    return(_loginContentResult);
                }
                if (string.IsNullOrEmpty(execution_guid))
                {
                    return(new EmptyResult());
                }

                ReportExecution execution = getExecution(execution_guid);
                if (execution != null)
                {
                    if (execution.RootReport == null)
                    {
                        execution.RootReport = execution.Report;
                    }

                    string nav = Request.Form[ReportExecution.HtmlId_navigation_id];
                    NameValueCollection parameters = null;
                    if (Request.Form.ContainsKey(ReportExecution.HtmlId_navigation_parameters))
                    {
                        parameters = HttpUtility.ParseQueryString(Request.Form[ReportExecution.HtmlId_navigation_parameters]);
                    }

                    if (nav.StartsWith(NavigationLink.FileDownloadPrefix)) //File download
                    {
                        var filePath = NavigationContext.NavigateScript(nav, execution.Report, parameters);
                        if (!string.IsNullOrEmpty(filePath) && System.IO.File.Exists(filePath))
                        {
                            return(getFileResult(filePath, null));
                        }
                        else
                        {
                            throw new Exception(string.Format("Invalid file path got from the navigation script: '{0}'", filePath));
                        }
                    }
                    else if (nav.StartsWith(NavigationLink.ReportScriptPrefix)) //Report Script
                    {
                        var data = NavigationContext.NavigateScript(nav, execution.Report, parameters);
                        return(Json(data));
                    }
                    else if (nav.StartsWith(NavigationLink.ReportExecutionPrefix)) //Report Script
                    {
                        Report report    = execution.Report;
                        string path      = report.Repository.ReportsFolder + nav.Substring(3);
                        var    newReport = Report.LoadFromFile(path, report.Repository);
                        newReport.WebUrl = report.WebUrl;
                        execution        = new ReportExecution()
                        {
                            Report = newReport
                        };
                        report = newReport;
                        setSessionValue(report.ExecutionGUID, execution);

                        WebHelper.WriteLogEntryWebDetail(EventLogEntryType.Information, string.Format("Execute report '{0}'", report.FilePath), getContextDetail(Request, WebUser));

                        report.ExecutionContext = ReportExecutionContext.WebReport;
                        report.SecurityContext  = WebUser;
                        report.CurrentViewGUID  = report.ViewGUID;

                        report.InitForExecution();
                        execution.RenderHTMLDisplayForViewer();
                        return(getFileResult(report.HTMLDisplayFilePath, report));
                    }
                    else
                    {
                        execution = NavigationContext.Navigate(nav, execution.RootReport);
                        Report report = execution.Report;
                        //Check rights if not in subreports folder
                        if (!report.FilePath.StartsWith(report.Repository.SubReportsFolder))
                        {
                            SWIFolder folder = getParentFolder(report.FilePath.Replace(report.Repository.ReportsFolder, ""));
                            if (folder.right == 0)
                            {
                                throw new Exception(string.Format("Error: no right to execute a report on the folder '{0}'", folder.path));
                            }
                        }

                        setSessionValue(report.ExecutionGUID, execution);

                        WebHelper.WriteLogEntryWebDetail(EventLogEntryType.Information, string.Format("Navigation report '{0}'", report.FilePath), getContextDetail(Request, WebUser));

                        report.ExecutionContext = ReportExecutionContext.WebReport;
                        report.SecurityContext  = WebUser;
                        report.CurrentViewGUID  = report.ViewGUID;

                        report.InitForExecution();
                        execution.RenderHTMLDisplayForViewer();
                        return(getFileResult(report.HTMLDisplayFilePath, report));
                    }
                }
                else
                {
                    throw new Exception(string.Format("No report execution found in session '{0}'", execution_guid));
                }
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
        public ActionResult SWIMoveFile(string source, string destination, bool copy)
        {
            writeDebug("SWIMoveFile");
            try
            {
                SWIFolder folderSource = getParentFolder(source);
                if (folderSource.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }
                SWIFolder folderDest = getParentFolder(destination);
                if ((FolderRight)folderDest.right != FolderRight.Edit)
                {
                    throw new Exception("Error: no right to edit on the destination folder");
                }

                string sourcePath      = getFullPath(source);
                string destinationPath = getFullPath(destination);
                if (!System.IO.File.Exists(sourcePath))
                {
                    throw new Exception("Error: source path is incorrect");
                }
                if (folderDest.files && FileHelper.IsSealReportFile(sourcePath))
                {
                    throw new Exception(Translate("Warning: only files (and not reports) can be copied to this folder."));
                }
                if (System.IO.File.Exists(destinationPath) && copy)
                {
                    destinationPath = FileHelper.GetUniqueFileName(Path.GetDirectoryName(destinationPath), Path.GetFileNameWithoutExtension(destinationPath) + " - Copy" + Path.GetExtension(destinationPath), Path.GetExtension(destinationPath));
                }

                bool hasSchedule = (FileHelper.IsSealReportFile(sourcePath) && FileHelper.ReportHasSchedule(sourcePath));
                FileHelper.MoveSealFile(sourcePath, destinationPath, copy);
                if (copy)
                {
                    Audit.LogAudit(AuditType.FileCopy, WebUser, sourcePath, string.Format("Copy to '{0}'", destinationPath));
                }
                else
                {
                    Audit.LogAudit(AuditType.FileMove, WebUser, sourcePath, string.Format("Move to '{0}'", destinationPath));
                }
                if (hasSchedule)
                {
                    //Re-init schedules...
                    var report = Report.LoadFromFile(destinationPath, Repository, false);
                    if (copy)
                    {
                        //remove schedules
                        report.InitGUIDAndSchedules();
                        report.SaveToFile();
                    }
                    report.SchedulesWithCurrentUser = false;
                    report.SynchronizeTasks();
                }
                return(Json(new object { }));
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }
        public ActionResult SWExecuteReport(string Ami_token, string Report_name, string ProjectId)
        {
            //var path = "\\Dashboard - Sales.srex";
            var path       = Report_name;
            var render     = false;
            var viewGUID   = "";
            var outputGUID = "";

            try
            {
                this.inlineLogin();
                this.inlineGetRootFolder();

                if (!CheckAuthentication())
                {
                    return(Content(_loginContent));
                }

                Report     report     = null;
                Repository repository = null;

                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }
                if (!string.IsNullOrEmpty(outputGUID) && (FolderRight)folder.right == FolderRight.Execute)
                {
                    throw new Exception("Error: no right to execute output on this folder");
                }

                string filePath = getFullPath(path);
                if (!System.IO.File.Exists(filePath))
                {
                    throw new Exception("Error: report does not exist");
                }
                repository = Repository.CreateFast();
                report     = Report.LoadFromFile(filePath, repository);
                report.Models[0].Restrictions[0].Value1 = ProjectId;
                report.Models[1].Restrictions[1].Value1 = ProjectId;

                var execution = initReportExecution(report, viewGUID, outputGUID);
                execution.RenderHTMLDisplayForViewer();
                //return getFileResult(report.HTMLDisplayFilePath, report);

                execution.Execute();
                while (report.Status != ReportStatus.Executed)
                {
                    Console.WriteLine("waiting...");
                    Thread.Sleep(100);
                }

                Helper.WriteLogEntryWeb(EventLogEntryType.Information, "Viewing result of report {1} for user '{0}'", WebUser.Name, report.FilePath);
                if (report.HasErrors)
                {
                    Helper.WriteLogEntryWeb(EventLogEntryType.Error, "Report {0} ({1}) execution errors:\r\n{2}", report.FilePath, WebUser.Name, report.ExecutionErrors);
                }
                string filePath2 = report.ForOutput || report.HasExternalViewer ? report.HTMLDisplayFilePath : report.ResultFilePath;
                if (!System.IO.File.Exists(filePath2))
                {
                    throw new Exception("Error: Result file path does not exists...");
                }
                return(getFileResult(filePath2, report));
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
Exemple #26
0
        public ActionResult SWIExecuteReportToResult(string path, string viewGUID, string outputGUID, string format)
        {
            try
            {
                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }

                string filePath = getFullPath(path);
                if (!System.IO.File.Exists(filePath))
                {
                    throw new Exception("Error: report does not exist");
                }
                Repository repository = Repository.CreateFast();
                Report     report     = Report.LoadFromFile(filePath, repository);

                var execution = initReportExecution(report, viewGUID, outputGUID);
                execution.Execute();
                while (report.Status != ReportStatus.Executed)
                {
                    System.Threading.Thread.Sleep(100);
                }

                string result = "";
                if (!string.IsNullOrEmpty(outputGUID))
                {
                    //Copy the result output to temp
                    result = publishReportResult(report);
                }
                else
                {
                    string fileResult = "";
                    if (string.IsNullOrEmpty(format))
                    {
                        format = "html";
                    }
                    if (format.ToLower() == "print")
                    {
                        fileResult = execution.GeneratePrintResult();
                    }
                    else if (format.ToLower() == "pdf")
                    {
                        fileResult = execution.GeneratePDFResult();
                    }
                    else if (format.ToLower() == "excel")
                    {
                        fileResult = execution.GenerateExcelResult();
                    }
                    else
                    {
                        fileResult = execution.GenerateHTMLResult();
                    }
                    result = execution.Report.WebTempUrl + Path.GetFileName(fileResult);
                }
                report.PreInputRestrictions.Clear();
                return(Json(new { url = result }));
            }
            catch (Exception ex)
            {
                return(handleSWIException(ex));
            }
        }
Exemple #27
0
        public ActionResult SWIExecuteReportToResult(string path, string viewGUID, string outputGUID, string format)
        {
            try
            {
                SWIFolder folder = getParentFolder(path);
                if (folder.right == 0)
                {
                    throw new Exception("Error: no right on this folder");
                }

                string filePath = getFullPath(path);
                if (!System.IO.File.Exists(filePath))
                {
                    throw new Exception("Error: report does not exist");
                }
                Repository repository = Repository.CreateFast();
                Report     report     = Report.LoadFromFile(filePath, repository);

                var execution = initReportExecution(report, viewGUID, outputGUID);

                /*
                 * report.ExecutionContext = ReportExecutionContext.WebReport;
                 * report.SecurityContext = WebUser;
                 * report.CurrentViewGUID = report.ViewGUID;
                 *
                 * //Init Pre Input restrictions
                 * report.PreInputRestrictions.Clear();
                 * foreach (string key in Request.Form.Keys) report.PreInputRestrictions.Add(key, Request.Form[key]);
                 * foreach (string key in Request.QueryString.Keys) report.PreInputRestrictions.Add(key, Request.QueryString[key]);
                 *
                 * //execute to output
                 * if (!string.IsNullOrEmpty(outputGUID))
                 * {
                 *  report.OutputToExecute = report.Outputs.FirstOrDefault(i => i.GUID == outputGUID);
                 *  report.ExecutionContext = ReportExecutionContext.WebOutput;
                 *  if (report.OutputToExecute != null) report.CurrentViewGUID = report.OutputToExecute.ViewGUID;
                 * }
                 *
                 * //execute with custom view
                 * if (!string.IsNullOrEmpty(viewGUID)) report.CurrentViewGUID = viewGUID;
                 *
                 * ReportExecution execution = new ReportExecution() { Report = report };
                 *
                 * Session[report.ExecutionGUID] = execution;
                 *
                 * int index = Request.Url.OriginalString.ToLower().IndexOf("swiexecutereport");
                 * if (index == -1) throw new Exception("Invalid URL");
                 * report.WebUrl = Request.Url.OriginalString.Substring(0, index);
                 * repository.WebPublishFolder = Path.Combine(Request.PhysicalApplicationPath, "temp");
                 * repository.WebApplicationPath = Path.Combine(Request.PhysicalApplicationPath, "bin");
                 * if (!Directory.Exists(repository.WebPublishFolder)) Directory.CreateDirectory(repository.WebPublishFolder);
                 * FileHelper.PurgeTempDirectory(repository.WebPublishFolder);
                 *
                 * report.InitForExecution();
                 * initInputRestrictions(report);
                 */
                execution.Execute();
                while (report.Status != ReportStatus.Executed)
                {
                    System.Threading.Thread.Sleep(100);
                }

                string result = "";
                if (!string.IsNullOrEmpty(outputGUID))
                {
                    //Copy the result output to temp
                    result = publishReportResult(report);
                }
                else
                {
                    string fileResult = "";
                    if (string.IsNullOrEmpty(format))
                    {
                        format = "html";
                    }
                    if (format.ToLower() == "print")
                    {
                        fileResult = execution.GeneratePrintResult();
                    }
                    else if (format.ToLower() == "pdf")
                    {
                        fileResult = execution.GeneratePDFResult();
                    }
                    else if (format.ToLower() == "excel")
                    {
                        fileResult = execution.GenerateExcelResult();
                    }
                    else
                    {
                        fileResult = execution.GenerateHTMLResult();
                    }
                    result = execution.Report.WebTempUrl + Path.GetFileName(fileResult);
                }
                report.PreInputRestrictions.Clear();
                return(Json(new { url = result }));
            }
            catch (Exception ex)
            {
                return(handleSWIException(ex));
            }
        }
Exemple #28
0
 SWIFolder getParentFolder(string path)
 {
     return(getFolder(SWIFolder.GetParentPath(path)));
 }