/// <summary> /// Write a page from memory to storage. This will update the CRC before writing. /// </summary> public void CommitPage(BasicPage page) { if (page == null) { throw new Exception("Can't commit a null page"); } if (page.PageId < 0) { throw new Exception("Page ID must be valid"); } var pageId = page.PageId; page.UpdateCRC(); lock (_fslock) { var ms = new MemoryStream(BasicPage.PageRawSize); page.Freeze().CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); var buffer = ms.ToArray() ?? throw new Exception($"Failed to serialise page {pageId}"); _fs.Seek(HEADER_SIZE + (pageId * BasicPage.PageRawSize), SeekOrigin.Begin); _fs.Write(buffer, 0, buffer.Length); Flush(); } }
protected void Page_Load(object sender, EventArgs e) { try { CheckUserActionPermission(ETEMEnums.SecuritySettings.ShowDownloadLogFile, true); string resourcesFolderName = BasicPage.GetSettingByCode(ETEMModel.Helpers.ETEMEnums.AppSettings.ResourcesFolderName).SettingValue; DirectoryInfo directory = new DirectoryInfo(resourcesFolderName + "\\log"); //FileInfo logFile = directory.GetFiles().OrderByDescending(s => s.LastWriteTime).FirstOrDefault(); string initialZipFileName = BaseHelper.ZipFolder(directory); this.OpenPageForDownloadFile("../Share/DownloadFile.aspx", "FilePath=" + initialZipFileName); } catch (Exception ex) { BaseHelper.Log("Грешка в Page_Load " + formResource.PagePath); BaseHelper.Log(ex.Message); BaseHelper.Log(ex.StackTrace); } }
protected void btnAddToArchive_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.hdnInitFilePath.Value)) { try { string uploadPath = this.hdnInitFilePath.Value; DirectoryInfo dirInfoArchive = null; FileInfo fileInfoArchive = null; CheckBox chbxFileToArchive = new CheckBox(); LinkButton lbtnOpenDirectory = new LinkButton(); foreach (GridViewRow row in this.fexUploadFiles.GvExplorer.Rows) { chbxFileToArchive = row.FindControl("chbxFileToArchive") as CheckBox; if (chbxFileToArchive.Checked) { lbtnOpenDirectory = row.FindControl("lbtnOpenDirectory") as LinkButton; if (!string.IsNullOrEmpty(lbtnOpenDirectory.Text)) { dirInfoArchive = new DirectoryInfo(uploadPath + "\\" + "Archive"); if (!dirInfoArchive.Exists) { dirInfoArchive.Create(); } fileInfoArchive = new FileInfo(uploadPath + "\\" + lbtnOpenDirectory.Text); string fileNameToArchive = this.AdminClientRef.GetFileVersion(lbtnOpenDirectory.Text); fileInfoArchive.MoveTo(dirInfoArchive.FullName + "\\" + fileNameToArchive); } } } this.fexUploadFiles.FormLoad(uploadPath); UserControlLoad(); /*ScriptManager.RegisterStartupScript( * this.Page, * this.Page.GetType(), * "ReloadForm", * "<script type=\"text/javascript\" language=\"javascript\">window.opener.reloadForm();</script>", * false * ); */ } catch (Exception ex) { BasicPage.LogDebug("Грешка при преместване на избрани файлове към архив (папка 'Archive') - метод 'btnAddToArchive_Click', форма 'UploadFile.aspx'!" + ex.ToString()); BaseHelper.LogToMail("Грешка при преместване на избрани файлове към архив (папка 'Archive') - метод 'btnAddToArchive_Click', форма 'UploadFile.aspx'!" + ex.ToString()); } } }
protected void Page_Load(object sender, EventArgs e) { string menu = lblPage.Text.Trim(); if (!BasicPage.GetPermission(menu)) { Response.Redirect("/Login.aspx"); } }
/// <summary> /// Maps the <see cref="BasicPage"/> onto a new <see cref="NavigationItem"/>. /// </summary> /// <param name="basePage">The base page.</param> /// <returns>The navigation item.</returns> private static NavigationItem MapBaseToNavigationDto(BasicPage basePage) => new NavigationItem { NodeId = basePage.NodeId, Guid = basePage.Guid, ParentId = basePage.ParentId, Name = basePage.Name, NodeAliasPath = basePage.NodeAliasPath, Culture = basePage.Culture };
protected void btnLoginAS_Click(object sender, EventArgs e) { BasicPage currentPage = this.Page as BasicPage; currentPage.MakeLoginByUserID(this.hdnRowMasterKey.Value); UserProps userProps = new UserProps(); BasicPage.LogDebug("Потребител " + userProps.UserName + " влезе в системата"); Response.Redirect(Welcome.formResource.PagePath); }
public App() { InitializeComponent(); // MainPage = new SettingsFilterPage(); MainPage = new BasicPage() { BindingContext = "TestContext" }; }
public async Task CreateAsync(string title, string content) { var page = new BasicPage { Title = title, Content = content }; this.db.Add(page); await this.db.SaveChangesAsync(); }
public void simple_page_fields_round_trip() { var subject = new BasicPage(0); Assert.That(subject.DataLength, Is.EqualTo(0), "Unexpected default length"); Assert.That(subject.PrevPageId, Is.EqualTo(-1), "Unexpected default page ID"); subject.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 0, 6); subject.PrevPageId = 32790; Assert.That(subject.DataLength, Is.EqualTo(6), "Unexpected modified length"); Assert.That(subject.PrevPageId, Is.EqualTo(32790), "Unexpected modified page ID"); }
protected void Page_Load(object sender, EventArgs e) { string menu = lblPage.Text.Trim(); if (!BasicPage.GetPermission(menu)) { Response.Redirect("/Login.aspx"); } try { string sql = @"select * from Menus"; dsmenus = SQLHelper.GetDataSet(sql); } catch (Exception ex) { } }
/// <summary> /// Write a data stream from its current position to end to a new page chain. Returns the end page ID. /// This ID should then be stored either inside the index document, or to one of the core versions. /// </summary> public int WriteStream(Stream dataStream) { if (dataStream == null) { throw new Exception("Data stream must be valid"); } var bytesRequired = dataStream.Length - dataStream.Position; var pagesRequired = BasicPage.CountRequired(bytesRequired); var pages = new int[pagesRequired]; AllocatePageBlock(pages); return(WriteStreamInternal(dataStream, pagesRequired, pages)); }
//protected void lbtnOpenFile_Click(object sender, EventArgs e) //{ // string repfilename = ((LinkButton)sender).CommandArgument.ToString(); // FileStream readRepFile = File.OpenRead(repfilename); // if (readRepFile.Length != 0) // { // byte[] repData = new byte[readRepFile.Length]; // readRepFile.Read(repData, 0, (int)readRepFile.Length); // readRepFile.Flush(); // readRepFile.Close(); // Response.Clear(); // Response.AddHeader("Content-Disposition", "attachment;filename=" + Path.GetFileName(repfilename)); // //Response.ContentType = "application/excel"; // Response.BinaryWrite(repData); // Response.End(); // } protected void imgBtnDelete_Click(object sender, ImageClickEventArgs e) { string[] info = ((ImageButton)sender).CommandArgument.ToString().Split('|'); try { FileInfo fi = new FileInfo(info[0].ToString()); DirectoryInfo dirInfoToDeletedFiles = new DirectoryInfo(this.HdnRootDirectoryValue + "\\" + "Deleted"); if (!dirInfoToDeletedFiles.Exists) { Directory.CreateDirectory(dirInfoToDeletedFiles.FullName); } // **** string fileNameToDelete = this.AdminClientRef.GetFileVersion(fi.Name); fi.MoveTo(dirInfoToDeletedFiles.FullName + "\\" + fileNameToDelete); // fi.Delete(); FormLoad(this.HdnRootDirectoryValue); /*ScriptManager.RegisterStartupScript( * this.Page, * this.Page.GetType(), * "ReloadForm", * "<script type=\"text/javascript\" language=\"javascript\">window.opener.reloadForm();</script>", * false * ); */ if (Parent != null) { if ((Parent as SMCFileUploder) != null) { (Parent as SMCFileUploder).CustomFolder = dirInfoToDeletedFiles.FullName.Split('\\')[3].ToString(); (Parent as SMCFileUploder).UserControlLoad(); } } } catch (Exception ex) { BasicPage.LogDebug("Грешка при изтриване на файл от списък с прикачени файлове - метод 'imgBtnDelete_Click', форма 'FileExplorer.ascx'!" + ex.ToString()); BaseHelper.LogToMail("Грешка при изтриване на файл от списък с прикачени файлове - метод 'imgBtnDelete_Click', форма 'FileExplorer.ascx'!" + ex.ToString()); } }
/// <summary> /// Read a page from the storage stream to memory. This will check the CRC. /// </summary> public BasicPage?GetRawPage(int pageId, bool ignoreCrc = false) { if (pageId < 0) { return(null); } var result = new BasicPage(pageId); lock (_fslock) { _fs.Seek(HEADER_SIZE + (pageId * BasicPage.PageRawSize), SeekOrigin.Begin); result.Defrost(_fs); } if (!ignoreCrc && !result.ValidateCrc()) { throw new Exception($"Reading page {pageId} failed CRC check"); } return(result); }
public void simple_page_crc_checks_work() { var subject = new BasicPage(0) { DataLength = 0, PrevPageId = 20, }; subject.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 0, 6); subject.UpdateCRC(); Assert.That(subject.CrcHash, Is.Not.Zero, "CRC did not update"); Assert.That(subject.ValidateCrc(), Is.True, "CRC check failed, but should have passed"); subject.PrevPageId = 30; Assert.That(subject.ValidateCrc(), Is.False, "CRC check passed, but should have failed"); subject.UpdateCRC(); Assert.That(subject.ValidateCrc(), Is.True, "CRC check failed, but should have passed"); subject.Write(new byte[] { 1, 2, 99, 4, 5, 6 }, 0, 0, 6); Assert.That(subject.ValidateCrc(), Is.False, "CRC check passed, but should have failed"); }
public void FormLoad(string directoryPath) { // CurrentDirectoryPath = directoryPath; IList <Directories> res = new List <Directories>(); Directories dirs; try { if (string.IsNullOrEmpty(directoryPath)) { this.gvExplorer.DataSource = null; this.gvExplorer.DataBind(); return; } DirectoryInfo directory = new DirectoryInfo(directoryPath); if (!directory.Exists) { this.gvExplorer.DataSource = null; this.gvExplorer.DataBind(); return; } DirectoryInfo[] directories = directory.GetDirectories(); foreach (var item in directories) { if (!this.CanViewFolderDeleted && item.Name == "Deleted") { continue; } dirs = new Directories(); dirs.FullName = item.FullName; dirs.Name = item.Name; dirs.Type = "Папка"; dirs.LastWriteTime = Convert.ToDateTime(item.LastWriteTime); dirs.IsFile = "false"; dirs.ImageSRC = "../Images/Folder.png"; //Директории не могат да се трият dirs.DeleteVisible = false; dirs.CbxVisible = false; dirs.ChbxToArchiveVisible = false; res.Add(dirs); } FileInfo[] files = directory.GetFiles(); foreach (var item in files) { dirs = new Directories(); dirs.FullName = item.FullName; dirs.Name = item.Name; dirs.Type = "Файл"; dirs.LastWriteTime = Convert.ToDateTime(item.LastWriteTime); dirs.FileLength = (item.Length / 1024).ToString(); dirs.IsFile = "true"; dirs.ImageSRC = "../Images/FileXPtest.png"; dirs.DeleteVisible = (directory.Name.Equals("Deleted") ? false : CanDeleteFiles); dirs.CbxVisible = CanViewCbxlink; dirs.ChbxToArchiveVisible = this.CanViewToArchive; res.Add(dirs); } if (res.Count != 0) { this.gvExplorer.DataSource = res; this.gvExplorer.DataBind(); } else { this.gvExplorer.DataSource = null; this.gvExplorer.DataBind(); } } catch (Exception ex) { BasicPage.LogDebug("Грешка при зареждане на списък с прикачени файлове - метод 'FormLoad', форма 'FileExplorer.ascx'!" + ex.ToString()); BasicPage.LogError("Грешка при зареждане на списък с прикачени файлове - метод 'FormLoad', форма 'FileExplorer.ascx'!" + ex.ToString()); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (this.fuAddFileToArchive.HasFile) { try { string trimmedFileName = this.fuAddFileToArchive.FileName.Split('.')[0].Trim() + "." + this.fuAddFileToArchive.FileName.Split('.')[1].Trim(); string uploadPath = this.hdnInitFilePath.Value; CheckBox chbxFileToArchive = new CheckBox(); LinkButton lbtnOpenDirectory = new LinkButton(); foreach (GridViewRow row in this.fexUploadFiles.GvExplorer.Rows) { chbxFileToArchive = row.FindControl("chbxFileToArchive") as CheckBox; if (chbxFileToArchive.Checked) { lbtnOpenDirectory = row.FindControl("lbtnOpenDirectory") as LinkButton; break; } } if (!string.IsNullOrEmpty(lbtnOpenDirectory.Text)) { DirectoryInfo dirInfoArchive = new DirectoryInfo(uploadPath + "\\" + "Archive"); if (!dirInfoArchive.Exists) { dirInfoArchive.Create(); } FileInfo fileInfoArchive = new FileInfo(uploadPath + "\\" + lbtnOpenDirectory.Text); string fileNameToArchive = this.AdminClientRef.GetFileVersion(lbtnOpenDirectory.Text); fileInfoArchive.MoveTo(dirInfoArchive.FullName + "\\" + fileNameToArchive); } string uploadFileFullName = uploadPath + "\\" + trimmedFileName; FileInfo fileInfoNew = new FileInfo(uploadFileFullName); if (fileInfoNew.Exists) { ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "Error_Has_Same_File", "<script type=\"text/javascript\" language=\"javascript\">alert('" + "Съществува прикачен файл със същото име!" + "');</script>", false ); } //filter ententions by control proporty bool allowFileExtentiton = true; List <string> listAllowedExtentions = new List <string>(); string extention = fileInfoNew.Extension.ToLower(); //check if there is set filter for the file Extentions if (!string.IsNullOrEmpty(AllowedFileExtentions)) { listAllowedExtentions = AllowedFileExtentions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (!listAllowedExtentions.Any(s => s == extention)) { allowFileExtentiton = false; } } //if the control is user for Diploma images upload.The images have to have specific requierments bool meetDimentionRequierments = true; if (IsForDiplomaImages.HasValue && IsForDiplomaImages.Value) { //if the files are jpg i can check there dimention if (extention == Constants.FILE_JPG_EXTENSION) { //create temp directory to save the file in it, to get it as an image after that string tempDirectoryPath = uploadPath + Constants.DIRECTORY_SLASH + "temp" + Constants.DIRECTORY_SLASH; DirectoryInfo tempDirInfo = Directory.CreateDirectory(tempDirectoryPath); string tempFileFullPath = tempDirInfo.FullName + trimmedFileName; this.fuAddFileToArchive.SaveAs(tempFileFullPath); using (var img = System.Drawing.Image.FromFile(tempFileFullPath)) { float horisontalResolution = img.HorizontalResolution;//gives pixels per inch float verticalResolution = img.VerticalResolution; var height = img.Height; var width = img.Width; if (height < Constants.EXPORT_MIN_DIPLOMA_IMAGE_HEIGHT || width < Constants.EXPORT_MIN_DIPLOMA_IMAGE_WIDTH || horisontalResolution < Constants.EXPORT_MIN_DIPLOMA_IMAGE_PIXEL_PER_INCH || verticalResolution < Constants.EXPORT_MIN_DIPLOMA_IMAGE_PIXEL_PER_INCH) { meetDimentionRequierments = false; } } //delete the temp directory Directory.Delete(tempDirectoryPath, true); } //if the file is pdf i can } if (allowFileExtentiton && meetDimentionRequierments) { //here is actual save of the file on the server DirectoryInfo dirInfoUploadPath = Directory.CreateDirectory(uploadPath); this.fuAddFileToArchive.SaveAs(uploadFileFullName); this.fexUploadFiles.FormLoad(uploadPath); } else if (allowFileExtentiton == false) { ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "Error_Not_Extentions_File", "<script type=\"text/javascript\" language=\"javascript\">alert(' \"Позволени са само файлове с разширение: " + AllowedFileExtentions + "');</script>", false ); } else if (meetDimentionRequierments == false) { ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "Error_Not_Extentions_File", "<script type=\"text/javascript\" language=\"javascript\">alert('Минимален размер: 2 мегапиксела (1600х1200).Документите се сканират с резолюция 72 dpi.');</script>", false ); } UserControlLoad(); //Добавя качения файл към SearchEngine Index //SearchEngine.AddFileToIndex(uploadPath + "\\" + fuAddFileToArchive.FileName); //SearchInstance.AddFile(uploadFileFullName); /*ScriptManager.RegisterStartupScript( * this.Page, * this.Page.GetType(), * "ReloadForm", * "<script type=\"text/javascript\" language=\"javascript\">window.opener.reloadForm();</script>", * false * ); */ } catch (Exception ex) { BasicPage.LogDebug("Грешка при прикачване на файл към обект или документ - метод 'btnAdd_Click', форма 'UploadFile.aspx'!" + ex.ToString()); BaseHelper.LogToMail("Грешка при прикачване на файл към обект или документ - метод 'btnAdd_Click', форма 'UploadFile.aspx'!" + ex.ToString()); } } ReloadCallingControl(); }