/// <summary> /// Pushes a set of frames to IIS. Will trigger a connect if needed. /// </summary> private void PushStream(MediaStream stream, FileRoot TargetMp4fFile) { if (stream == null || stream.Frames == null) { return; // no frames. } SanitiseStream(stream); if (stream.Frames.Count < 1) { return; // no frames. } if (!PushServer.IsConnected(stream.TrackId)) { ConnectAndPushHeaders(stream, TargetMp4fFile); } // set start-of-fragment time from PTS stream.Offset = stream.Frames[0].FramePresentationTime - stream.Frames[0].FrameDuration; // Push the fragment var fragment_handler = TargetMp4fFile.GenerateFragment(stream); PushServer.PushData(stream.TrackId, fragment_handler.MoofData()); PushServer.PushData(stream.TrackId, fragment_handler.MdatData()); }
internal static void ReplaceBasic() { IProject proj = ProtoTestProj; foreach (var doc in proj.Documents) { CommonSyntaxTree syntax = doc.GetSyntaxTree(); FileTree = syntax; FileRoot = (CompilationUnitSyntax)syntax.GetRoot(); bool containingMethodToReplace = true; while (containingMethodToReplace) { containingMethodToReplace = SearchAndReplaceMethodsForTextCSharp(doc, "thisTest.Verify"); FileTree = SyntaxTree.Create(FileRoot); FileRoot = (CompilationUnitSyntax)FileTree.GetRoot(); } var UsingStmtForDict = Syntax.QualifiedName(Syntax.IdentifierName("System.Collections"), Syntax.IdentifierName("Generic")); FileRoot = FileRoot.AddUsings(Syntax.UsingDirective(UsingStmtForDict).NormalizeWhitespace()).NormalizeWhitespace(); File.WriteAllText(doc.FilePath, FileRoot.ToString()); //Console.WriteLine(result); } }
public void GetObjects_SingleRoot_TrueInclude_NoExclude() { var serviceContainer = new ManualServiceContainer(); serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer)); var context = new ExecutionContext(serviceContainer); var fileSystem = new MockFileSystem(); fileSystem.RegisterFile(@"C:\file1"); var root = new FileRoot(@"C:\file1", fileSystem); var include = new IRule[] { new TrueRule() }; var objectProvider = new FileSystemObjectProvider(root, include, null); var result = objectProvider.GetObjects(context).ToArray(); var expected = new IFileSystemObject[] { new FileObject(@"C:\file1", fileSystem), }; CollectionAssert.AreEqual(expected, result); }
public void GetObjects_MultiRoot() { var serviceContainer = new ManualServiceContainer(); serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer)); var context = new ExecutionContext(serviceContainer); var fileSystem = new MockFileSystem(); fileSystem.RegisterFile(@"C:\file1"); fileSystem.RegisterFile(@"C:\file2"); var root1 = new FileRoot(@"C:\file1", fileSystem); var root2 = new FileRoot(@"C:\file2", fileSystem); var roots = new IFileSystemRoot[] { root1, root2 }; var objectProvider = new FileSystemObjectProvider(roots, null, null); var result = objectProvider.GetObjects(context).ToArray(); var expected = new IFileSystemObject[] { new FileObject(@"C:\file1", fileSystem), new FileObject(@"C:\file2", fileSystem) }; CollectionAssert.AreEqual(expected, result); }
public FileRoot LoadB3D(string filePath) //, Transform conv,int hint ) { //collapse = !!(hint & MeshLoader::HINT_COLLAPSE); //animonly = !!(hint & MeshLoader::HINT_ANIMONLY); streamIn = File.OpenRead(filePath); clear(); RootObject = new FileRoot() { Name = "FILE_ROOT", }; string tag = readChunk(); if (tag != "BB3D") //BB3D { fclose(); return(null); } int version = readInt(); if (version > 1) { fclose(); return(null); } BlitzObject obj = null; while (chunkSize() > 0) { string chunkHead = readChunk(); switch (chunkHead) { case "TEXS": //readTextures(); break; case "BRUS": //readBrushes(); break; case "NODE": obj = readObject(RootObject); break; } exitChunk(); } fclose(); clear(); LoadedObjects.Insert(0, RootObject); return(RootObject); //?.getModel().getMeshModel(); }
/// <summary> /// Read the supplied configuration and prepare the transformer for work. /// </summary> private void PrepareTransformer(EncoderConfiguration.Configuration Configuration, List <EncoderPackage> Packages) { Config = Configuration; TimeSpan TargetDuration = TimeSpan.FromSeconds(Config.EncoderSettings.FragmentSeconds); PublishPoint = Config.Upload.VideoDestinationRoot; if (String.IsNullOrEmpty(PublishPoint)) { throw new ArgumentException("Publishing point must not be empty", "PublishUrl"); } PushServer = new IisSmoothPush(new Uri(PublishPoint)); TrackDurations = new Dictionary <int, long>(); TrackOffsets = new Dictionary <int, long>(); targetDuration = (ulong)TargetDuration.Ticks; Streams = new MediaStream[Packages.Count]; foreach (var pkg in Packages) { if (pkg.Specification.HasVideo && pkg.Specification.HasAudio) { throw new NotSupportedException("IIS Smooth output doesn't support pre-muxed streams"); } if (pkg.Specification.HasAudio) { Streams[pkg.JobIndex] = new MediaStream(); // for now, stream 0 is audio, and all others are video. Streams[pkg.JobIndex].TrackId = pkg.JobIndex + 1; Streams[pkg.JobIndex].FourCC = "mp3a"; // MP3 //Streams[pkg.JobIndex].FourCC = "mp4a"; // AAC Streams[pkg.JobIndex].Height = 0; Streams[pkg.JobIndex].Width = 0; Streams[pkg.JobIndex].Bitrate = 96000; //pkg.Job.Bitrate; // later! } else if (pkg.Specification.HasVideo) { Streams[pkg.JobIndex] = new MediaStream(); // for now, stream 0 is audio, and all others are video. Streams[pkg.JobIndex].TrackId = pkg.JobIndex + 1; Streams[pkg.JobIndex].FourCC = "H264"; // this is the M$ format, not iso (which is 'avc1') Streams[pkg.JobIndex].Height = Config.EncoderSettings.OutputHeight; // the actual size may be different due to scaling factor. Streams[pkg.JobIndex].Width = Config.EncoderSettings.OutputWidth; Streams[pkg.JobIndex].Bitrate = pkg.Job.Bitrate; } } Mp4fFile = new FileRoot(Streams); Demuxer = new MpegTS_Demux[Packages.Count]; for (int di = 0; di < Demuxer.Length; di++) { Demuxer[di] = new MpegTS_Demux(); } }
public void GoOffline() { if (Offline != null) { Offline(); } PublicChat = null; News = null; FileRoot.OnOffline(); FileRoot = null; // TODO: Should probably null much more here (HeartBeat etc). }
/// <summary> /// Used once per connection, this opens a long-life HTTP stream /// and pushes the very basic MP4 parts needed to get IIS working. /// </summary> private void ConnectAndPushHeaders(MediaStream stream, FileRoot TargetMp4fFile) { SmilGenerator smil = new SmilGenerator("HCS Encoder by Iain Ballard.", stream); smil.ApproxBitrate = stream.Bitrate; MP4_Mangler.ExtraBoxes.SmoothSmil ssmil = new MP4_Mangler.ExtraBoxes.SmoothSmil(smil.Generate()); PushServer.Connect(stream.TrackId); // This pushes to the subpath: Streams({id}-stream{index}) // push headers (only done once per track) // each one needs it's own HTTP Chunk, so don't concat! PushServer.PushData(stream.TrackId, TargetMp4fFile.GenerateFileSpec()); PushServer.PushData(stream.TrackId, ssmil.deepData()); PushServer.PushData(stream.TrackId, TargetMp4fFile.GenerateHeaders()); }
/// <summary> /// 解析を実施する /// </summary> /// <param name="eventContainer">イベントコンテナ</param> public void Analyze(EventContainer eventContainer) { // セマンティックモデルのリストを作成する var models = CreateModels(); if (!models.Any()) { // リスト作成失敗 throw new Exception("ファイルの解析に失敗しました。"); } // 解析処理収集 foreach (var model in models) { FileRoot.Create(model, eventContainer); } }
public void GetObjects_NonExistingFile() { var serviceContainer = new ManualServiceContainer(); serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer)); var context = new ExecutionContext(serviceContainer); var fileSystem = new MockFileSystem(); var root = new FileRoot(@"C:\root", fileSystem); var result = root.GetObjects(context).ToArray(); var expected = new IFileSystemObject[] { }; CollectionAssert.AreEqual(expected, result); }
private static bool SearchAndReplaceMethodsForTextCSharp(IDocument document, string textToSearch) { SyntaxNode syntaxNode = null; var syntaxNodes = from methodDeclaration in FileRoot.DescendantNodes() .Where(x => x is MethodDeclarationSyntax) select methodDeclaration; if (syntaxNodes != null && syntaxNodes.Count() > 0) { foreach (MethodDeclarationSyntax ele in syntaxNodes) { string bodyText = RemoveComments((ele).GetText().ToString()); if (Regex.IsMatch(bodyText, "\\b" + textToSearch + "\\b")) { syntaxNode = ele; break; } else { continue; } } } if (syntaxNode != null) { MemberDeclarationSyntax method = syntaxNode as MemberDeclarationSyntax; if (method != null) { ReplaceMethodTextCSharp(method, document, textToSearch); //update node return(true); } } //File.WriteAllText(@"G:\test.cs", FileRoot.ToString()); return(false); }
//private void OnApplicationFocus(bool focus) //{ // //更新目录 // UpdateFolder(); //} //更新目录方法 void UpdateFolder() { //初始输入输出目录 string InputDir = Application.dataPath + "/../Input/"; string OutputDir = Application.dataPath + "/../Output/"; //判断目录是否存在并创建 if (!Directory.Exists(InputDir)) { Directory.CreateDirectory(InputDir); } if (!Directory.Exists(OutputDir)) { Directory.CreateDirectory(OutputDir); } //删除目录列表元素 Button[] BtnList = FolderRoot.GetComponentsInChildren <Button>(); for (int i = 0; i < BtnList.Length; i++) { Destroy(BtnList[i].gameObject); } //创建目录列表元素 DirectoryInfo dir = new DirectoryInfo(InputDir); DirectoryInfo[] dii = dir.GetDirectories(); if (dii.Length > 0) { foreach (var item in dii) { GameObject btn = Instantiate(BtnItem, FolderRoot); btn.GetComponentInChildren <Text>().text = item.Name; //添加目录按钮点击事件 btn.GetComponent <Button>().onClick.AddListener(delegate { //删除图片列表 CurrentInputPath = item.ToString() + "/"; Button[] BtnList2 = FileRoot.GetComponentsInChildren <Button>(); for (int i = 0; i < BtnList2.Length; i++) { Destroy(BtnList2[i].gameObject); } //创建图片列表元素 var tmpDir = InputDir + item.Name + "/"; DirectoryInfo dir2 = new DirectoryInfo(tmpDir); var files = dir2.GetFiles(); if (files.Length > 0) { List <FileInfo> filesname = new List <FileInfo>(); foreach (var item2 in files) { if (item2.Extension == ".png" || item2.Extension == ".jpg") { filesname.Add(item2); } } for (int i = 0; i < filesname.Count; i++) { GameObject fileBtn = Instantiate(BtnItem, FileRoot); fileBtn.GetComponentInChildren <Text>().text = filesname[i].Name; //Destroy(fileBtn.GetComponent<Button>()); } } }); } } //删除视频列表元素 Button[] BtnList3 = ClipRoot.GetComponentsInChildren <Button>(); for (int i = 0; i < BtnList3.Length; i++) { Destroy(BtnList3[i].gameObject); } //创建视频列表元素 DirectoryInfo dir3 = new DirectoryInfo(OutputDir); var files2 = dir3.GetFiles(); List <FileInfo> filesname2 = new List <FileInfo>(); foreach (var item in files2) { if (item.Extension == ".webm") { filesname2.Add(item); } } for (int i = 0; i < filesname2.Count; i++) { GameObject fileBtn = Instantiate(BtnItem, ClipRoot); fileBtn.GetComponentInChildren <Text>().text = filesname2[i].Name; //添加视频列表按钮点击事件 fileBtn.GetComponent <Button>().onClick.AddListener(delegate { vp.source = VideoSource.Url; vp.url = OutputDir + fileBtn.GetComponentInChildren <Text>().text; vp.Play(); }); } }
public void RenameBtn() { DirectoryInfo dir = new DirectoryInfo(CurrentInputPath); var files = dir.GetFiles(); List <FileInfo> filesname = new List <FileInfo>(); foreach (var item in files) { if (item.Extension == ".png" || item.Extension == ".jpg") { filesname.Add(item); } } //foreach (var item in filesname) for (int i = 0; i < filesname.Count; i++) { string tmpstr = ""; if (int.Parse(RenameInputList[2].text) == 1) { filesname[i].MoveTo(CurrentInputPath + RenameInputList[0].text + i + RenameInputList[1].text + filesname[i].Extension); } else if (int.Parse(RenameInputList[2].text) == 2) { if (i < 10) { tmpstr = "0"; } else { tmpstr = ""; } filesname[i].MoveTo(CurrentInputPath + RenameInputList[0].text + tmpstr + i + RenameInputList[1].text + filesname[i].Extension); } else if (int.Parse(RenameInputList[2].text) == 3) { if (i < 10) { tmpstr = "00"; } else if (i > 9 && i < 100) { tmpstr = "0"; } else { tmpstr = ""; } filesname[i].MoveTo(CurrentInputPath + RenameInputList[0].text + tmpstr + i + RenameInputList[1].text + filesname[i].Extension); } else if (int.Parse(RenameInputList[2].text) == 4) { if (i < 10) { tmpstr = "000"; } else if (i > 9 && i < 100) { tmpstr = "00"; } else if (i > 99 && i < 1000) { tmpstr = "0"; } else { tmpstr = ""; } filesname[i].MoveTo(CurrentInputPath + RenameInputList[0].text + tmpstr + i + RenameInputList[1].text + filesname[i].Extension); } else if (int.Parse(RenameInputList[2].text) == 5) { if (i < 10) { tmpstr = "0000"; } else if (i > 9 && i < 100) { tmpstr = "000"; } else if (i > 99 && i < 1000) { tmpstr = "00"; } else if (i > 999 && i < 10000) { tmpstr = "0"; } else { tmpstr = ""; } filesname[i].MoveTo(CurrentInputPath + RenameInputList[0].text + tmpstr + i + RenameInputList[1].text + filesname[i].Extension); } RenamePanel.gameObject.SetActive(false); Button[] BtnList = FileRoot.GetComponentsInChildren <Button>(); for (int j = 0; j < BtnList.Length; j++) { Destroy(BtnList[j].gameObject); } //将参数修改为改名后的 InputFieldList[1].text = RenameInputList[0].text + "%" + RenameInputList[2].text + "d" + RenameInputList[1].text + filesname[0].Extension; } }
private static void ReplaceMethodTextCSharp(SyntaxNode node, IDocument document, string textToSearch) { string methodText = node.GetText().ToString(); bool isMethod = node is MethodDeclarationSyntax; string methodOrPropertyDefinition = isMethod ? "Method: " : " Invalid - not Method "; object methodName = ((MethodDeclarationSyntax)node).Identifier.Value; var body = (node as MethodDeclarationSyntax).Body; var statements = body.Statements; var originalTrailingTrivia = body.GetTrailingTrivia(); SyntaxList <StatementSyntax> newStatements = new SyntaxList <StatementSyntax>(); StatementSyntax statementNewTestmap = Syntax.ParseStatement("var testmap = new Dictionary<string, object>();"); newStatements = newStatements.Add(statementNewTestmap); SyntaxList <StatementSyntax> flattenedStmts = Flatten(statements); foreach (var statement in flattenedStmts) { //string stmtString = RemoveComments(statement).ToString(); string stmtString = statement.ToString(); stmtString = RemoveComments(stmtString); if (Regex.IsMatch(stmtString, "\\b" + textToSearch + "\\b")) { StatementSyntax newStatement = null; //string[] parameters = stmtString.Split(new char[] { '(', ',', ')' }); //if(parameters.Length == 4) //{ // if(parameters.Last() == "1") // { // Console.WriteLine(stmtString); // } //} //stmtString = TestmapAdd + "(" + parameters.ElementAt(1) + ", " + parameters.ElementAt(2) + ");" ; var invocation = Syntax.ParseExpression(RemoveComments(stmtString)) as InvocationExpressionSyntax; var args = invocation.ArgumentList.Arguments; //var args = GetParams(stmtString); if (args.Count() > 3) { throw new Exception(); } if (args.Count() == 3) { #if DEBUG if (args.Last().ToString() != "0") { Console.WriteLine(stmtString); } #endif // Console.WriteLine(stmtString); //stmtString = TestmapAdd + "(" + args.ElementAt(0) + ", " + args.ElementAt(1) + ");"; try { var registerArgs = new List <ArgumentSyntax> { args.ElementAt(0), args.ElementAt(1) }; var argSeparators = Enumerable.Repeat(Syntax.Token(SyntaxKind.CommaToken), registerArgs.Count - 1).ToList(); ArgumentListSyntax newArgList = Syntax.ArgumentList( arguments: Syntax.SeparatedList( registerArgs, argSeparators)); InvocationExpressionSyntax newInvokationNode = Syntax.InvocationExpression( Syntax.MemberAccessExpression( kind: SyntaxKind.MemberAccessExpression, expression: Syntax.ParseName("testmap"), name: Syntax.IdentifierName("Add"), operatorToken: Syntax.Token(SyntaxKind.DotToken)), newArgList); stmtString = newInvokationNode.ToString() + ";"; newStatement = Syntax.ParseStatement(stmtString); } catch (Exception e) { Console.WriteLine(e); } } if (args.Count() == 2) { stmtString = stmtString.Replace(textToSearch, TestmapAdd); } Console.WriteLine(stmtString); newStatement = Syntax.ParseStatement(stmtString); try { newStatements = newStatements.Add(newStatement); } catch (Exception e) { Console.WriteLine(e); } //stmtString.Replace(textToSearch, "thisTest.GenericVerify"); } else { newStatements = newStatements.Add(statement); } } newStatements = newStatements.Add(Syntax.ParseStatement("thisTest.GenericVerify(testmap);")); FileRoot = FileRoot.ReplaceNode(body, Syntax.Block(newStatements).WithTrailingTrivia(originalTrailingTrivia)).NormalizeWhitespace(); }