internal void Start(string folderPath, string id, string fullName, string description, string author, string groups, string prereq, int videoQuality, string started) { frameIndex = -1; startTime = DateTime.Now; imageType = "jpeg"; if (videoQuality > 0) { if (AmfSerializer == null) { AmfSerializer = new DataContractAmfSerializer(typeof(VisualAction), new[] { typeof(ReportSummary), typeof(ReportSummaryError), typeof(VisualElement), typeof(VisualReport), typeof(TestBound) }); } if (videoQuality == 4) // max quality level { imageType = "png"; animationEncoder = maxQualityEncoder; animationEncoderParameters = maxQualityEncoderParameters; } else { animationEncoder = GetEncoder(ImageFormat.Jpeg); animationEncoderParameters = new EncoderParameters(2); if (videoQuality == 3) // quality level { animationEncoderParameters.Param[1] = new EncoderParameter(Encoder.Quality, 70L); animationEncoderParameters.Param[0] = new EncoderParameter(Encoder.Compression, 70L); } else if (videoQuality == 2)// speed level { animationEncoderParameters.Param[1] = new EncoderParameter(Encoder.Quality, 35L); animationEncoderParameters.Param[0] = new EncoderParameter(Encoder.Compression, 20L); } else // size level { animationEncoderParameters.Param[1] = new EncoderParameter(Encoder.Quality, 10L); animationEncoderParameters.Param[0] = new EncoderParameter(Encoder.Compression, 100L); } } if (visualStream == null) { AtsvFilePath = folderPath + "\\" + fullName + ".tmp"; try { visualStream = new BufferedStream(new FileStream(AtsvFilePath, FileMode.Create)); currentAction = new VisualReport(id, fullName, description, author, groups, prereq, videoQuality, started); } catch { } } } }
internal void CreateMobile(string actionType, int actionLine, string actionScript, long timeLine, string channelName, double[] channelBound, string url, bool sync, bool stop) { currentAction.AddImage(this, url, channelBound, false); Flush(); if (sync) { currentAction = new VisualActionSync(this, stop, actionType, actionLine, actionScript, timeLine, channelName, channelBound, imageType, null, null, 0.0F, 0.0F, url); } else { currentAction = new VisualAction(this, stop, actionType, actionLine, actionScript, timeLine, channelName, channelBound, imageType, null, null, 0.0F, 0.0F, url); } }
internal void Flush() { currentAction.Index = frameIndex; frameIndex++; if (visualStream != null) { if (currentAction is VisualActionSync) { currentAction = new VisualAction(currentAction as VisualActionSync); } AmfSerializer.WriteObject(visualStream, currentAction); visualStream.Flush(); } }
public RecordExecution(int type, string[] commandsData, VisualRecorder recorder) : base() { RecordType recordType = (RecordType)type; if (recordType == RecordType.Stop) { recorder.Stop(); } else if (recordType == RecordType.Download) { response.type = 1; response.atsvFilePath = recorder.GetDownloadFile(); } else if (recordType == RecordType.Summary) { if (bool.TryParse(commandsData[0], out bool passed) && int.TryParse(commandsData[1], out int actions)) { if (!passed && commandsData.Length >= 8 && int.TryParse(commandsData[6], out int errorLine)) { recorder.Summary(passed, actions, commandsData[2], commandsData[3], commandsData[4], commandsData[5], errorLine, commandsData[7]); } else { recorder.Summary(passed, actions, commandsData[2], commandsData[3], commandsData[4]); } } } else { if (commandsData.Length > 0) { if (recordType == RecordType.Screenshot) { if (int.TryParse(commandsData[0], out int x) && int.TryParse(commandsData[1], out int y) && int.TryParse(commandsData[2], out int w) && int.TryParse(commandsData[3], out int h)) { response.Image = recorder.ScreenCapture(x, y, w, h); } } else if (recordType == RecordType.ScreenshotMobile) { response.Image = VisualAction.GetScreenshot(commandsData[0]); } else if (recordType == RecordType.Start) { string tempFolder = Path.GetTempPath() + "\\ats_recorder"; long freeSpace = 0; try { DriveInfo drive = new DriveInfo(new FileInfo(tempFolder).Directory.Root.FullName); freeSpace = drive.AvailableFreeSpace; } catch { } if (freeSpace > 100000000) { try { if (Directory.Exists(tempFolder)) { DirectoryInfo folder = new DirectoryInfo(tempFolder); foreach (FileInfo file in folder.EnumerateFiles()) { file.Delete(); } } else { Directory.CreateDirectory(tempFolder); } } catch { } string id = commandsData[0]; string fullName = commandsData[1]; string description = commandsData[2]; string author = commandsData[3]; string groups = commandsData[4]; string prereq = commandsData[5]; response.atsvFilePath = tempFolder + "\\" + fullName; _ = int.TryParse(commandsData[6], out int videoQuality); recorder.Start(tempFolder, id, fullName, description, author, groups, prereq, videoQuality, commandsData[7]); } else { response.ErrorCode = -50; response.ErrorMessage = "Not enough space available on disk : " + (freeSpace / 1024 / 1024) + " Mo"; } } else if (recordType == RecordType.Create) { string actionType = commandsData[0]; _ = int.TryParse(commandsData[1], out int line); string script = commandsData[2]; _ = long.TryParse(commandsData[3], out long timeLine); string channelName = commandsData[4]; double[] channelDimmension = new double[] { 0, 0, 1, 1 }; _ = double.TryParse(commandsData[5], out channelDimmension[0]); _ = double.TryParse(commandsData[6], out channelDimmension[1]); _ = double.TryParse(commandsData[7], out channelDimmension[2]); _ = double.TryParse(commandsData[8], out channelDimmension[3]); _ = bool.TryParse(commandsData[9], out bool sync); _ = bool.TryParse(commandsData[10], out bool stop); recorder.Create(actionType, line, script, timeLine, channelName, channelDimmension, sync, stop); } else if (recordType == RecordType.CreateMobile) { string actionType = commandsData[0]; _ = int.TryParse(commandsData[1], out int line); string script = commandsData[2]; _ = long.TryParse(commandsData[6], out long timeLine); string channelName = commandsData[4]; double[] channelDimmension = new double[] { 0, 0, 1, 1 }; _ = double.TryParse(commandsData[5], out channelDimmension[0]); _ = double.TryParse(commandsData[6], out channelDimmension[1]); _ = double.TryParse(commandsData[7], out channelDimmension[2]); _ = double.TryParse(commandsData[8], out channelDimmension[3]); string url = commandsData[9]; _ = bool.TryParse(commandsData[10], out bool sync); _ = bool.TryParse(commandsData[11], out bool stop); recorder.CreateMobile(actionType, line, script, timeLine, channelName, channelDimmension, url, sync, stop); } else if (recordType == RecordType.Image) { double[] screenRect = new double[] { 0, 0, 1, 1 }; _ = double.TryParse(commandsData[0], out screenRect[0]); _ = double.TryParse(commandsData[1], out screenRect[1]); _ = double.TryParse(commandsData[2], out screenRect[2]); _ = double.TryParse(commandsData[3], out screenRect[3]); _ = bool.TryParse(commandsData[4], out bool isRef); recorder.AddImage(screenRect, isRef); } else if (recordType == RecordType.ImageMobile) { double[] screenRect = new double[] { 0, 0, 1, 1 }; _ = double.TryParse(commandsData[0], out screenRect[0]); _ = double.TryParse(commandsData[1], out screenRect[1]); _ = double.TryParse(commandsData[2], out screenRect[2]); _ = double.TryParse(commandsData[3], out screenRect[3]); _ = bool.TryParse(commandsData[4], out bool isRef); recorder.AddImage(commandsData[5], screenRect, isRef); } else if (recordType == RecordType.Value) { recorder.AddValue(commandsData[0]); } else if (recordType == RecordType.Data) { recorder.AddData(commandsData[0], commandsData[1]); } else if (recordType == RecordType.Status) { _ = int.TryParse(commandsData[0], out int error); _ = long.TryParse(commandsData[1], out long duration); recorder.Status(error, duration); } else if (recordType == RecordType.Element) { double[] elementBound = new double[] { 0, 0, 0, 0 }; _ = double.TryParse(commandsData[0], out elementBound[0]); _ = double.TryParse(commandsData[1], out elementBound[1]); _ = double.TryParse(commandsData[2], out elementBound[2]); _ = double.TryParse(commandsData[3], out elementBound[3]); _ = long.TryParse(commandsData[4], out long searchDuration); _ = int.TryParse(commandsData[5], out int numElements); string searchCriterias = ""; if (commandsData.Length > 6) { searchCriterias = commandsData[6]; } string tag = "*"; string[] citeriasData = searchCriterias.Split(','); if (citeriasData.Length > 0) { tag = citeriasData[0]; if (citeriasData.Length == 1) { searchCriterias += "(no-criterias)"; } } recorder.AddElement(elementBound, searchDuration, numElements, searchCriterias, tag); } else if (recordType == RecordType.Position) { recorder.AddPosition(commandsData[0], commandsData[1], commandsData[2], commandsData[3]); } } } }
protected override void OnUpdate() { VisualAction.Move(Perception.InputDirection(), 0.5f); }