protected void Page_Load(object sender, EventArgs e) { DebugHelper.SetContext("GetImageVersion"); if (!QueryHelper.ValidateHash("hash")) { URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("imageeditor.badhashtitle") + "&text=" + ResHelper.GetString("imageeditor.badhashtext"))); } // Get the parameters Guid editorGuid = QueryHelper.GetGuid("editorguid", Guid.Empty); int num = QueryHelper.GetInteger("versionnumber", -1); // Load the temp file info if (num >= 0) { tfi = TempFileInfoProvider.GetTempFileInfo(editorGuid, num); } else { DataSet ds = TempFileInfoProvider.GetTempFiles(null, "FileNumber DESC", 1, null); if (!DataHelper.DataSourceIsEmpty(ds)) { tfi = new TempFileInfo(ds.Tables[0].Rows[0]); } } // Send the data SendFile(); DebugHelper.ReleaseContext(); }
/// <summary> /// Saves current version of image and discards all other versions. /// </summary> /// <param name="includeExtensionInName">If true file name is returned with extension</param> public void SaveCurrentVersion(bool includeExtensionInName) { if (LoadingFailed) { SavingFailed = true; } else { if (imgHelper != null) { TempFileInfo tfi = TempFileInfoProvider.GetTempFileInfo(InstanceGUID, CurrentVersion); if (tfi != null) { if (SaveImage != null) { tfi.Generalized.EnsureBinaryData(); SaveImage((includeExtensionInName ? tfi.FileName + "." + tfi.FileExtension.TrimStart('.') : tfi.FileName), tfi.FileExtension, tfi.FileMimeType, tfi.FileTitle, tfi.FileDescription, tfi.FileBinary, tfi.FileImageWidth, tfi.FileImageHeight); } } } if (!SavingFailed) { // Delete all versions TempFileInfoProvider.DeleteTempFiles(TempFileInfoProvider.IMAGE_EDITOR_FOLDER, InstanceGUID); } } }
protected void Page_Load(object sender, EventArgs e) { DebugHelper.SetContext("GetImageVersion"); if (!QueryHelper.ValidateHash("hash")) { URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("imageeditor.badhashtitle") + "&text=" + ResHelper.GetString("imageeditor.badhashtext"))); } // Get the parameters Guid editorGuid = QueryHelper.GetGuid("editorguid", Guid.Empty); int num = QueryHelper.GetInteger("versionnumber", -1); // Load the temp file info if (num >= 0) { tfi = TempFileInfoProvider.GetTempFileInfo(editorGuid, num); } else { DataSet ds = TempFileInfoProvider.GetTempFiles(null, "FileNumber DESC", 1, null); if (!DataHelper.DataSourceIsEmpty(ds)) { tfi = new TempFileInfo(ds.Tables[0].Rows[0]); } } // Send the data SendFile(); DebugHelper.ReleaseContext(); }
protected void Page_Load(object sender, EventArgs e) { DebugHelper.SetContext("GetImageVersion"); // Get the parameters Guid editorGuid = QueryHelper.GetGuid("editorguid", Guid.Empty); int num = QueryHelper.GetInteger("versionnumber", -1); // Load the temp file info if (num >= 0) { tempFile = TempFileInfoProvider.GetTempFileInfo(editorGuid, num); } else { var data = TempFileInfoProvider.GetTempFiles(null, "FileNumber DESC", 1, null); if (!DataHelper.DataSourceIsEmpty(data)) { tempFile = new TempFileInfo(data.Tables[0].Rows[0]); } } // Send the data SendFile(); DebugHelper.ReleaseContext(); }
protected void Page_Load(object sender, EventArgs e) { DebugHelper.SetContext("GetImageVersion"); // Get the parameters Guid editorGuid = QueryHelper.GetGuid("editorguid", Guid.Empty); int num = QueryHelper.GetInteger("versionnumber", -1); // Load the temp file info if (num >= 0) { tfi = TempFileInfoProvider.GetTempFileInfo(editorGuid, num); } else { DataSet ds = TempFileInfoProvider.GetTempFiles(null, "FileNumber DESC", 1, null); if (!DataHelper.DataSourceIsEmpty(ds)) { tfi = new TempFileInfo(ds.Tables[0].Rows[0]); } } // Send the data SendFile(); DebugHelper.ReleaseContext(); }
/// <summary> /// Processes the redo action. /// </summary> public void ProcessRedo() { CurrentVersion++; tempFile = TempFileInfoProvider.GetTempFileInfo(InstanceGUID, CurrentVersion); InitFileInfo(); PopulateConversionDropdownlist(); PropagateChanges(false); }
private void GetTempFileInfo(FileInformation file) { string path = file.Path; string fileName = Path.GetFileName(path); string extension = Path.GetExtension(path); tempFile = new TempFileInfo { Path = file.Path, FileName = Path.GetFileName(file.Path), BaseName = fileName.TrimEnd(extension.ToCharArray()), Directory = Path.GetDirectoryName(file.Path), Extension = extension, CreationDateTime = file.CreationDateTime.ToString(), }; }
public async Task <InfoModel <TempFileInfo> > UploadForActivityTempFile([FromForm] IFormFile file) { UserTempDir tempFileDir = (await UserInfoForLogin).GetUserTempDirForActivity(); TempFileInfo tempFileInfo = new TempFileInfo(); if (!tempFileDir.SaveTempFile(file, tempFileInfo)) { throw new Exception("上传失败!"); } return(new InfoModel <TempFileInfo> { Data = tempFileInfo }); }
public async Task <WavStream> ConvertAsync(Stream stream) { var section = configuration.GetSection("AudioToTextService.Core.WavAudioConverter"); var ffmpegPath = section["ffmpeg"]; using (var inputFile = await TempFileInfo.GenTempFileAsync(stream)) { var outputFile = Path.ChangeExtension(Path.GetTempFileName(), ".wav"); var cmd = String.Format(ToWavCmdLine, inputFile.FileName, outputFile); ProcessStartInfo psi = new ProcessStartInfo(ffmpegPath, cmd) { UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = Directory.GetCurrentDirectory(), RedirectStandardOutput = true, RedirectStandardError = true }; using (Process p = Process.Start(psi)) { //* Read the output (or the error) string ffmpegOutput = p.StandardOutput.ReadToEnd(); string ffmpegErrOutput = p.StandardError.ReadToEnd(); p.WaitForExit(); if (p.ExitCode != 0) { throw new Exception(ffmpegOutput + ffmpegErrOutput); } TimeSpan ts = ParseTimeFromFFMpegOutput(ffmpegErrOutput); return(new WavStream(outputFile, FileMode.Open, FileAccess.Read, ts)); } } }
/// <summary> /// Processes the undo action. /// </summary> public void ProcessUndo() { CurrentVersion--; tempFile = TempFileInfoProvider.GetTempFileInfo(InstanceGUID, CurrentVersion); InitFileInfo(); PopulateConversionDropdownlist(); PropagateChanges(false); }
/// <summary> /// Creates new version of image. /// </summary> /// <param name="data">Image data</param> /// <param name="name">File name</param> /// <param name="title">File title</param> /// <param name="description">File description</param> public void CreateVersion(byte[] data, string name, string title, string description) { if (IsUndoRedoPossible()) { // If current if ((CurrentVersion) >= MaxVersionsCount) { ShowError(GetString("img.errors.maxversion")); LoadingFailed = true; } else if (ImgHelper != null) { try { // Set the imagehelper to new data ImgHelper = new ImageHelper(data); CurrentVersion++; // Save new file version TempFileInfo tfi = new TempFileInfo(); tfi.FileDirectory = "ImageEditor"; tfi.FileBinary = data; tfi.FileParentGUID = InstanceGUID; tfi.FileExtension = "." + currentFormat; tfi.FileName = name; tfi.FileTitle = title; tfi.FileDescription = description; tfi.FileNumber = CurrentVersion; tfi.FileMimeType = "image/" + (currentFormat == "jpg" ? "jpeg" : currentFormat); tfi.FileImageWidth = ImgHelper.ImageWidth; tfi.FileImageHeight = ImgHelper.ImageHeight; tfi.FileSize = ImgHelper.SourceData.Length; tfi.FileSiteName = SiteContext.CurrentSiteName; tempFile = tfi; SetScriptProperties(true); // Delete all next temporary files before creating new TempFileInfoProvider.DeleteTempFiles(TempFileInfoProvider.IMAGE_EDITOR_FOLDER, InstanceGUID, CurrentVersion - 1, MaxVersionsCount); // Save new temporary file TempFileInfoProvider.SetTempFileInfo(tfi); // Oldest version is always current if creating new version OldestVersion = CurrentVersion; } catch (Exception ex) { ShowError(GetString("img.errors.processing"),ex.Message); EventLogProvider.LogException("Image editor", "LOAD", ex); LoadingFailed = true; } } } else { if (SaveImage != null) { string extension = "." + currentFormat; string mimetype = "image/" + (currentFormat == "jpg" ? "jpeg" : currentFormat); ImgHelper.LoadImage(data); SaveImage(name, extension, mimetype, title, description, data, ImgHelper.ImageWidth, ImgHelper.ImageHeight); } } }
protected void Page_Load(object sender, EventArgs e) { RegisterTrimScript(); if (LoadImageType != null) { LoadImageType(); } ltlScript.Text = ""; if (!URLHelper.IsPostback()) { // Display image if available data if (imageType != ImageHelper.ImageTypeEnum.None) { if (InitializeProperties != null) { InitializeProperties(); } if (!LoadingFailed) { currentFormat = imgHelper.ImageFormatToString(); } } // Create first version on first load (original) if (ImgHelper != null) { CreateVersion(ImgHelper.SourceData); } } else { // Load current version to edit tempFile = TempFileInfoProvider.GetTempFileInfo(InstanceGUID, CurrentVersion); if (tempFile != null) { tempFile.Generalized.EnsureBinaryData(); ImgHelper = new ImageHelper(tempFile.FileBinary); currentFormat = imgHelper.ImageFormatToString(); } if (!IsUndoRedoPossible() && (InitializeProperties != null)) { InitializeProperties(); } if (!LoadingFailed && (imgHelper != null)) { currentFormat = imgHelper.ImageFormatToString(); } } InitializeStrings(!RequestHelper.IsPostBack()); InitializeFields(); if (!URLHelper.IsPostback()) { // Initialize labels depending on image type in parent control if (InitializeLabels != null) { InitializeLabels(true); } } // Show tab 'Properties' if (ValidationHelper.GetBoolean(hdnShowProperties.Value, false)) { ScriptHelper.RegisterStartupScript(this, typeof(string), "ShowProperties", ScriptHelper.GetScript("ShowProperties(true, '" + hdnShowProperties.ClientID + "');")); } if (!IsPreview) { // Enable or disable meta data editor metaDataEditor.Enabled = Enabled; } }
protected void Page_Load(object sender, EventArgs e) { RegisterTrimScript(); if (LoadImageType != null) { LoadImageType(); } ltlScript.Text = ""; if (!URLHelper.IsPostback()) { // Display image if available data if (imageType != ImageHelper.ImageTypeEnum.None) { if (InitializeProperties != null) { InitializeProperties(); } if (!LoadingFailed) { currentFormat = imgHelper.ImageFormatToString(); } } // Create first version on first load (original) if (ImgHelper != null) { CreateVersion(ImgHelper.SourceData); } } else { // Load current version to edit tempFile = TempFileInfoProvider.GetTempFileInfo(InstanceGUID, CurrentVersion); if (tempFile != null) { tempFile.Generalized.EnsureBinaryData(); ImgHelper = new ImageHelper(tempFile.FileBinary); currentFormat = imgHelper.ImageFormatToString(); } if (!IsUndoRedoPossible() && (InitializeProperties != null)) { InitializeProperties(); } if (!LoadingFailed) { currentFormat = imgHelper.ImageFormatToString(); } } InitializeStrings(!RequestHelper.IsPostBack()); InitializeFields(); if (!URLHelper.IsPostback()) { // Initialize labels depending on image type in parent control if (InitializeLabels != null) { InitializeLabels(true); } } // Show tab 'Properties' if (ValidationHelper.GetBoolean(hdnShowProperties.Value, false)) { ScriptHelper.RegisterStartupScript(this, typeof(string), "ShowProperties", ScriptHelper.GetScript("ShowProperties(true, '" + hdnShowProperties.ClientID + "');")); } if (!IsPreview) { // Enable or disable meta data editor metaDataEditor.Enabled = Enabled; } }
/// <summary> /// Проанализировать файл. Считать и распарсить заголовок файла, заголовки асканов /// </summary> /// <param name="fi"></param> /// <returns></returns> private long AnalyzeFile(FileInfo fi) { long headerLength = -1; using (FileStream fs = new FileStream(fi.FullName, FileMode.Open)) { using (BinaryReader bReader = new BinaryReader(fs)) { // read file header int bscanLength = 0; TempFileInfo tempInfo = ReadFileHeader(bReader, fi, out bscanLength); headerLength = fs.Position; // read file ascan headers ReadFileDataSummary(bReader, fi, tempInfo, bscanLength); // save headers tempFileInfo = tempInfo; } } return headerLength; }
/// <summary> /// Считать заголовок файла /// </summary> /// <param name="bReader"></param> /// <param name="fi"></param> /// <param name="bscanLength"></param> /// <returns></returns> private TempFileInfo ReadFileHeader(BinaryReader bReader, FileInfo fi, out int bscanLength) { // file info short fileVersion = bReader.ReadInt16(); bscanLength = bReader.ReadInt32(); string comment = bReader.ReadString(); string timeCreated = bReader.ReadString(); // python settings uint startType = bReader.ReadUInt32(); uint bufferSize = bReader.ReadUInt32(); double frequency = bReader.ReadDouble(); uint control = bReader.ReadUInt32(); uint preHistory = bReader.ReadUInt32(); uint startDelay = bReader.ReadUInt32(); uint hysteresis = bReader.ReadUInt32(); uint packetNumber = bReader.ReadUInt32(); double threshold = bReader.ReadDouble(); uint controlSynchro = bReader.ReadUInt32(); uint waitTime = bReader.ReadUInt32(); int channelsNum = bReader.ReadInt32(); RshChannel[] channels = new RshChannel[channelsNum]; for (int i = 0; i < channels.Length; i++) { channels[i] = new RshChannel(); channels[i].control = bReader.ReadUInt32(); channels[i].delta = bReader.ReadDouble(); channels[i].gain = bReader.ReadUInt32(); } uint digitalPort = bReader.ReadUInt32(); // survey settings double dt = bReader.ReadDouble(); double dx = bReader.ReadDouble(); double eps = bReader.ReadDouble(); int zoom = bReader.ReadInt32(); string palette = bReader.ReadString(); int repRate = bReader.ReadInt32(); int marksCount = bReader.ReadInt32(); Dictionary<int, int> Marks = new Dictionary<int, int>(); for (int i = 0; i < marksCount; i++) Marks.Add(bReader.ReadInt32(), bReader.ReadInt32()); PythonSettings pythset = new PythonSettings( startType, bufferSize, frequency, control, preHistory, startDelay, hysteresis, packetNumber, threshold, controlSynchro, channels, waitTime, digitalPort); TempFileInfo tempInfo = new TempFileInfo(fileVersion, pythset, Marks); Settings.Init(zoom, dx, dt, eps, palette, repRate, Settings.CalibrationProps); return tempInfo; }
private void ReadFileDataSummary(BinaryReader bReader, FileInfo fi, TempFileInfo tempFileInfo, int bscanLength) { List<int> ascanLengths = new List<int>(bscanLength); for (int i = 0; i < bscanLength; i++) { ascanLengths.Add(bReader.ReadInt32()); bReader.ReadBytes(ascanLengths[i] * 2); } tempFileInfo.ascanLengths = ascanLengths; }
/// <summary> /// Creates new version of image. /// </summary> /// <param name="data">Image data</param> /// <param name="name">File name</param> /// <param name="title">File title</param> /// <param name="description">File description</param> public void CreateVersion(byte[] data, string name, string title, string description) { if (IsUndoRedoPossible()) { // If current if ((CurrentVersion) >= MaxVersionsCount) { ShowError(GetString("img.errors.maxversion")); LoadingFailed = true; } else if (ImgHelper != null) { try { // Set the imagehelper to new data ImgHelper = new ImageHelper(data); CurrentVersion++; // Save new file version TempFileInfo tfi = new TempFileInfo(); tfi.FileDirectory = "ImageEditor"; tfi.FileBinary = data; tfi.FileParentGUID = InstanceGUID; tfi.FileExtension = "." + currentFormat; tfi.FileName = name; tfi.FileTitle = title; tfi.FileDescription = description; tfi.FileNumber = CurrentVersion; tfi.FileMimeType = "image/" + (currentFormat == "jpg" ? "jpeg" : currentFormat); tfi.FileImageWidth = ImgHelper.ImageWidth; tfi.FileImageHeight = ImgHelper.ImageHeight; tfi.FileSize = ImgHelper.SourceData.Length; tfi.FileSiteName = SiteContext.CurrentSiteName; tempFile = tfi; SetScriptProperties(true); // Delete all next temporary files before creating new TempFileInfoProvider.DeleteTempFiles(TempFileInfoProvider.IMAGE_EDITOR_FOLDER, InstanceGUID, CurrentVersion - 1, MaxVersionsCount); // Save new temporary file TempFileInfoProvider.SetTempFileInfo(tfi); // Oldest version is always current if creating new version OldestVersion = CurrentVersion; } catch (Exception ex) { ShowError(GetString("img.errors.processing"), ex.Message); EventLogProvider.LogException("Image editor", "LOAD", ex); LoadingFailed = true; } } } else { if (SaveImage != null) { string extension = "." + currentFormat; string mimetype = "image/" + (currentFormat == "jpg" ? "jpeg" : currentFormat); ImgHelper.LoadImage(data); SaveImage(name, extension, mimetype, title, description, data, ImgHelper.ImageWidth, ImgHelper.ImageHeight); } } }
public List<short[]> ReadTempFilePart(TempFileInfo _tempFileInfo, int startAscan, int length) { Logging.WriteToLog("StationaryFile.ReadTempFilePart()"); if (startAscan + length > _tempFileInfo.ascanLengths.Count) throw new NullReferenceException("Trying to read ascans that don't exist"); List<short[]> bscan = new List<short[]>(); // count the offset int skip = 0; for (int i = 0; i < startAscan; i++) skip += _tempFileInfo.ascanLengths[i] * 2; // read data bscan.Clear(); using (FileStream fs = new FileStream(this.curFile.FullName, FileMode.Open)) { fs.Position = skip; using (BinaryReader bReader = new BinaryReader(fs)) { for (int i = 0; i < length; i++) { short[] ascan = new short[_tempFileInfo.ascanLengths[startAscan + i]]; for (int j = 0; j < ascan.Length; j++) ascan[j] = bReader.ReadInt16(); bscan.Add(ascan); } } } return bscan; }