Exemplo n.º 1
0
        private GridDefinition GetGridModel()
        {
            return(new GridDefinition {
                ModuleGuid = Module.ModuleGuid,
                SettingsModuleGuid = Module.PermanentGuid,
                PageSizes = new List <int>()
                {
                    5, 10, 20, 50
                },
                RecordType = typeof(BrowseItem),
                AjaxUrl = GetActionUrl(nameof(BrowseLog_GridData)),
                DirectDataAsync = async(int skip, int take, List <DataProviderSortInfo> sort, List <DataProviderFilterInfo> filters) => {
                    FlushLog();
                    DataProviderSortInfo.UpdateAlternateSortColumn(sort, filters, "UserId", "UserName");
                    using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                        DataProviderGetRecords <LogRecord> browseItems = await dataProvider.GetItemsAsync(skip, take, sort, filters);

                        return new DataSourceResult {
                            Data = (from s in browseItems.Data select new BrowseItem(Module, s)).ToList <object>(),
                            Total = browseItems.Total
                        };
                    }
                },
            });
        }
Exemplo n.º 2
0
        public async Task <ActionResult> DownloadLog(long cookieToReturn)
        {
            FlushLog();
            using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                string filename = dataProvider.GetLogFileName();
                if (!await FileSystem.FileSystemProvider.FileExistsAsync(filename))
                {
                    throw new Error(this.__ResStr("logNotFound", "The log file '{0}' cannot be located", filename));
                }
#if MVC6
                Response.Headers.Remove("Cookie");
                Response.Cookies.Append(Basics.CookieDone, cookieToReturn.ToString(), new Microsoft.AspNetCore.Http.CookieOptions {
                    HttpOnly = false, Path = "/"
                });
#else
                HttpCookie cookie = new HttpCookie(Basics.CookieDone, cookieToReturn.ToString());
                Response.Cookies.Remove(Basics.CookieDone);
                Response.SetCookie(cookie);
#endif

                string contentType = "application/octet-stream";
#if MVC6
                return(new PhysicalFileResult(filename, contentType)
                {
                    FileDownloadName = "Logfile.txt"
                });
#else
                FilePathResult result = new FilePathResult(filename, contentType);
                result.FileDownloadName = "Logfile.txt";
                return(result);
#endif
            }
        }
Exemplo n.º 3
0
 public async Task <ModuleAction> GetAction_RemoveAllAsync()
 {
     if (!IsAuthorized("RemoveLog"))
     {
         return(null);
     }
     using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
         if (!await dataProvider.IsInstalledAsync())
         {
             return(null);
         }
         if (!dataProvider.CanRemove)
         {
             return(null);
         }
     };
     return(new ModuleAction(this)
     {
         Url = Utility.UrlFor(typeof(BrowseLogModuleController), nameof(BrowseLogModuleController.RemoveAll)),
         NeedsModuleContext = true,
         Image = await CustomIconAsync("RemoveAll.png"),
         Style = ModuleAction.ActionStyleEnum.Post,
         LinkText = this.__ResStr("removeAllLink", "Remove All"),
         MenuText = this.__ResStr("removeAllMenu", "Remove All"),
         Legend = this.__ResStr("removeAllLegend", "Remove all log record for all sites"),
         Tooltip = this.__ResStr("removeAllTT", "Removes all log records for all sites"),
         Category = ModuleAction.ActionCategoryEnum.Delete,
         Mode = ModuleAction.ActionModeEnum.Any,
         Location = ModuleAction.ActionLocationEnum.NoAuto,
         ConfirmationText = this.__ResStr("removeConfirm", "Are you sure you want to remove ALL log records?"),
     });
 }
Exemplo n.º 4
0
 public async Task <ModuleAction> GetAction_DownloadZippedLogAsync()
 {
     if (!IsAuthorized("Downloads"))
     {
         return(null);
     }
     using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
         if (!await dataProvider.IsInstalledAsync())
         {
             return(null);
         }
         if (!dataProvider.CanDownload)
         {
             return(null);
         }
     };
     return(new ModuleAction(this)
     {
         Url = Utility.UrlFor(typeof(BrowseLogModuleController), nameof(BrowseLogModuleController.DownloadZippedLog)),
         NeedsModuleContext = true,
         CookieAsDoneSignal = true,
         Image = await CustomIconAsync("Download.png"),
         LinkText = this.__ResStr("dlZipLink", "Download Log (Zipped)"),
         MenuText = this.__ResStr("dlZipMenu", "Download Log (Zipped)"),
         Tooltip = this.__ResStr("dlZipTT", "Download the log file as a ZIP file"),
         Legend = this.__ResStr("dlZipLegend", "Downloads the log file as a ZIP file"),
         Style = ModuleAction.ActionStyleEnum.Normal,
         Category = ModuleAction.ActionCategoryEnum.Read,
         Mode = ModuleAction.ActionModeEnum.Any,
         Location = ModuleAction.ActionLocationEnum.NoAuto,
     });
 }
Exemplo n.º 5
0
        public async Task <ActionResult> RemoveAll()
        {
            FlushLog();
            using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                await dataProvider.RemoveItemsAsync(null);// that means all records

                return(Reload(null, PopupText: this.__ResStr("allRemoved", "All log records have been removed"), Reload: ReloadEnum.ModuleParts));
            }
        }
Exemplo n.º 6
0
        public async Task <ActionResult> DisplayLog(int key)
        {
            using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                LogRecord data = await dataProvider.GetItemAsync(key);

                if (data == null)
                {
                    throw new Error(this.__ResStr("notFound", "Record \"{0}\" not found."), key);
                }
                DisplayModel model = new DisplayModel();
                model.SetData(data);
                return(View(model));
            }
        }
Exemplo n.º 7
0
        public override async Task <MenuList> GetModuleMenuListAsync(ModuleAction.RenderModeEnum renderMode, ModuleAction.ActionLocationEnum location)
        {
            MenuList menuList = await base.GetModuleMenuListAsync(renderMode, location);

            if (location == ModuleAction.ActionLocationEnum.ModuleLinks)
            {
                using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                    menuList.New(await GetAction_RemoveAllAsync());
                    menuList.New(await GetAction_DownloadZippedLogAsync());
                    menuList.New(await GetAction_DownloadLogAsync());
                }
            }
            return(menuList);
        }
Exemplo n.º 8
0
        public async Task RemoveAsync(List <string> errorList)
        {
            LoggingConfigData config = await LoggingConfigDataProvider.GetConfigAsync();

            DateTime oldest = DateTime.UtcNow.AddDays(-config.Days);

            using (LogRecordDataProvider logDP = LogRecordDataProvider.GetLogRecordDataProvider()) {
                List <DataProviderFilterInfo> filters = DataProviderFilterInfo.Join(null, new DataProviderFilterInfo {
                    Field = nameof(LogRecord.TimeStamp), Operator = "<", Value = oldest
                });
                int removed = await logDP.RemoveItemsAsync(filters);

                errorList.Add(string.Format("{0} records removed from log data", removed));
            }
        }
Exemplo n.º 9
0
        public async Task <ActionResult> BrowseLog()
        {
            FlushLog();
            using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                await dataProvider.FlushAsync();// get the latest records

                BrowseModel model = new BrowseModel {
                    LogAvailable      = await dataProvider.IsInstalledAsync(),
                    BrowsingSupported = dataProvider.CanBrowse,
                    LoggerName        = dataProvider.LoggerName,
                };
                if (dataProvider.CanBrowse)
                {
                    model.GridDef = GetGridModel();
                }
                return(View(model));
            }
        }
Exemplo n.º 10
0
        public async Task <ActionResult> DownloadZippedLog(long cookieToReturn)
        {
            FlushLog();
            using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                string filename = dataProvider.GetLogFileName();
                if (!await FileSystem.FileSystemProvider.FileExistsAsync(filename))
                {
                    throw new Error(this.__ResStr("logNotFound", "The log file '{0}' cannot be located", filename));
                }
#if MVC6
#else
                HttpCookie cookie = new HttpCookie(Basics.CookieDone, cookieToReturn.ToString());
                Response.Cookies.Remove(Basics.CookieDone);
                Response.SetCookie(cookie);
#endif
                string        zipName = "Logfile.zip";
                YetaWFZipFile zipFile = new YetaWFZipFile {
                    FileName = zipName,
                };
                zipFile.AddFile(filename, "Logfile.txt");
                return(new ZippedFileResult(zipFile, cookieToReturn));
            }
        }