public void ShouldExportTOHTMLFromStream() { string expectedFile = @"<!DOCTYPE html> <html> <head> <title>Events List</title> </head> <body><p><b>Date:</b> 2015.12.25</p> <p><b>Subject:</b> Christmas!</p><p><b>Title:</b> Christmas</p><p><b>Description:</b> Santa Claus</p><hr> </body> </html>"; expectedFile = expectedFile.Replace("\r", ""); Events newEvent = new Events(); string date = "2015/12/25"; string title = "Christams"; string description = "Santa Claus"; newEvent.Add(date, title,description); using (MemoryStream ms = new MemoryStream()) { using (IOStream streamObj = new IOStream(ms)) { streamObj.ExportEventsInHTMLStream(newEvent); var htmlContent = Encoding.UTF8.GetString(ms.ToArray()); htmlContent.ShouldContain(expectedFile); } } }
public ServerConnectionAdapter(IOStream ios, ServerNetworkTableEntryStore sntes, IncomingEntryReceiver ier, ServerAdapterManager sam, NetworkTableEntryTypeManager ntetm, NTThreadManager nttm) { base.\u002Ector(); ServerConnectionAdapter connectionAdapter = this; this.__\u003C\u003Econnection = new NetworkTableConnection(ios, ntetm); this.entryStore = sntes; this.transactionReceiver = ier; this.adapterListener = sam; this.gotoState(ServerConnectionState.__\u003C\u003EGOT_CONNECTION_FROM_CLIENT); this.readThread = nttm.newBlockingPeriodicThread((PeriodicRunnable) new ConnectionMonitorThread((ConnectionAdapter) this, this.__\u003C\u003Econnection), "Server Connection Reader Thread"); }
public NetworkTableConnection(IOStream ios, NetworkTableEntryTypeManager ntetm) { base.\u002Ector(); NetworkTableConnection networkTableConnection = this; this.WRITE_LOCK = (object) new Object(); this.__\u003C\u003Estream = ios; this.typeManager = ntetm; BufferedInputStream.__\u003Cclinit\u003E(); this.@is = new DataInputStream((InputStream) new BufferedInputStream(ios.getInputStream())); this.os = new DataOutputStream((OutputStream) new BufferedOutputStream(ios.getOutputStream())); this.isValid = true; }
public void ShouldLoadEventsFromStream() { var myFile = @"12/12/2015 12:00:00 AM subject 01/11/2015 12:00:00 AM subject title"; string[] expectedList = { @"12/12/2015 12:00:00 AM subject", @"01/11/2015 12:00:00 AM subject title" }; var stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(myFile)); IOStream news = new IOStream(stream); string[] text = news.GetLinesFromStream(); expectedList.ShouldEqual(text); }
private void ExportEvents(string path) { try { using (FileStream fs = new FileStream(path, FileMode.Create)) { Console.WriteLine("\n\tExporting file..."); IOStream stremObj = new IOStream(fs); stremObj.ExportEventsInHTMLStream(eventsList); } Console.WriteLine("\n\t{0} events were exported in '{1}' file .\n", eventsList.Length, path); } catch (IOException e) { Console.WriteLine("The file path didn't find!"); } }
public override void Close() { IOStream.Seek(0, SeekOrigin.Begin); Unknown1 = null; Unknown2 = null; }
public BitmapSource ReadImage(int paletteId) { using (SafeHGlobalHandle buff = IOStream.ReadBuff((int)(IOStream.Length - IOStream.Position))) return(BitmapSource.Create(256, buff.Length / 128, 96, 96, PixelFormats.Indexed4, Header.Palettes[paletteId], buff.DangerousGetHandle(), buff.Length, 128)); }
public override void Open() { BinaryReader br = new BinaryReader(IOStream); JsmHeader header = IOStream.ReadStruct <JsmHeader>(); int groupCount = (header.ScriptsOffset - 8) / 2; int scriptCount = (header.OperationsOffset - header.ScriptsOffset) / 2; int operationsCount = (int)((IOStream.Length - header.OperationsOffset) / 4); ushort index = 0; SortedList <ushort, JsmGroup> groups = new SortedList <ushort, JsmGroup>(groupCount); for (ushort i = 0; i < header.CountAreas; ++i) { JsmGroup group = ReadJsmGroup(br, index++, JsmModuleType.Area); groups.Add(group.Label, group); } for (ushort i = 0; i < header.CountDoors; ++i) { JsmGroup group = ReadJsmGroup(br, index++, JsmModuleType.Door); groups.Add(group.Label, group); } for (ushort i = 0; i < header.CountModules; ++i) { JsmGroup group = ReadJsmGroup(br, index++, JsmModuleType.Module); groups.Add(group.Label, group); } for (ushort i = 0; i < header.CountObjects; ++i) { JsmGroup group = ReadJsmGroup(br, index++, JsmModuleType.Object); groups.Add(group.Label, group); } JsmScript[] scripts = new JsmScript[scriptCount - 1]; for (int i = 0; i < scriptCount; ++i) { ushort pos = br.ReadUInt16(); bool flag = pos >> 15 == 1; pos &= 0x7FFF; if (i > 0) { scripts[i - 1].OperationsCount = (pos - scripts[i - 1].Position); } if (i < scriptCount - 1) { scripts[i] = new JsmScript(pos, flag); } } JsmOperation[] opertations = new JsmOperation[operationsCount]; for (int i = 0; i < operationsCount; i++) { opertations[i] = new JsmOperation(br.ReadUInt32()); } Groups = groups.Values.ToArray(); Scripts = scripts; Opertations = opertations; }
public void ConcurrencyTest() { using (TempFile temp = new TempFile()) using (ManualResetEvent stop = new ManualResetEvent(false)) using (TempFile copy = new TempFile()) using (TransactedCompoundFile test = new TransactedCompoundFile( new TransactedCompoundFile.Options(temp.TempPath) { BlockSize = 512, CreateNew = true })) using (WorkQueue workers = new WorkQueue(5)) { bool failed = false; workers.OnError += (o, e) => failed = true; for (int i = 0; i < 5; i++) { workers.Enqueue(() => ExersizeFile(stop, test)); } do { System.Threading.Thread.Sleep(1000); test.Commit(); File.Copy(temp.TempPath, copy.TempPath, true); Assert.AreEqual(0, copy.Length % 512); int hcount = (int)(copy.Length / 512); using (TransactedCompoundFile verify = new TransactedCompoundFile( new TransactedCompoundFile.Options(copy.TempPath) { BlockSize = 512, CreateNew = false })) { OrdinalList free = new OrdinalList(); free.Ceiling = hcount; for (int i = 0; i < hcount; i++) { uint h = verify.Create(); free.Add((int)h); if (h >= hcount) { break; } } int verifiedCount = 0; OrdinalList used = free.Invert(hcount); foreach (uint h in used) { // skip reserved offsets. if (h % (512 / 4) == 0 || (h + 1) % (512 / 4) == 0) { continue; } IOStream.ReadAllBytes(verify.Read(h)); verifiedCount++; } System.Diagnostics.Trace.WriteLine("Verified handle count: " + verifiedCount); } } while (!failed && System.Diagnostics.Debugger.IsAttached); stop.Set(); workers.Complete(false, 1000); Assert.IsFalse(failed); } }
/// <summary> Seperates the salt from the data provided </summary> public SaltedData(Stream saltedData) : this(IOStream.ReadAllBytes(saltedData), Salt.DefaultSize) { }
public override void Close() { IOStream.Seek(0, SeekOrigin.Begin); Entries = null; }
byte[] ISerializer <byte[]> .ReadFrom(Stream stream) { return(IOStream.ReadAllBytes(stream)); }
public bool Save(IOStream io, String fmt) { return(CPP.ReturnBool("$q->save($check(io)->$q.get(), fmt == nullptr ? nullptr : fmt->cstring().constData())")); }
private HttpStatusCode Exec(string method, string path, string contentType, byte[] payload, int count) { RequestUri = new Uri(_baseUri, path); Log.Verbose("{0} {1}", method, path); Stopwatch timer = new Stopwatch(); timer.Start(); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(RequestUri); req.CookieContainer = _cookies; req.UserAgent = UserAgent; req.Method = method; //Request Configuration req.Accept = "*/*"; req.KeepAlive = true; req.SendChunked = false; req.AllowAutoRedirect = false; req.UseDefaultCredentials = false; req.Timeout = (int)Timeout.TotalMilliseconds; req.ReadWriteTimeout = (int)Timeout.TotalMilliseconds; req.AutomaticDecompression = DecompressionMethods.None; req.ServicePoint.UseNagleAlgorithm = false; req.ServicePoint.Expect100Continue = false; req.ServicePoint.ConnectionLimit = 25; HttpWebResponse response = null; try { StatusCode = HttpStatusCode.Continue; ContentType = String.Empty; Content = EmptyBytes; RedirectUri = null; LastModified = null; ETag = null; ResponseHeaders = null; if (String.IsNullOrEmpty(RequestHeaders["Accept-Encoding"])) { req.Headers.Add("Accept-Encoding", "gzip"); } if (RequestHeaders.Count > 0) { foreach (string key in RequestHeaders.Keys) { req.Headers.Add(key, RequestHeaders[key]); } RequestHeaders.Clear(); } if (method == "POST") { req.ContentType = contentType; req.ContentLength = count; if (count > 0) { using (Stream io = req.GetRequestStream()) io.Write(payload, 0, count); } } response = GetResponse(req); } finally { timer.Stop(); Log.Verbose("{0} {1} ({2:n0} ms)", response == null ? 0 : response.StatusCode, path, timer.ElapsedMilliseconds); } using (response) { WebHeaderCollection headers = response.Headers; ResponseHeaders = headers; ContentType = headers[HttpResponseHeader.ContentType] ?? String.Empty; StatusCode = response.StatusCode; ETag = headers["ETag"]; DateTime modified; if (DateTime.TryParseExact(headers["Last-Modified"], "r", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AllowWhiteSpaces, out modified)) { LastModified = modified.ToLocalTime(); } if (StatusCode == HttpStatusCode.Redirect || StatusCode == HttpStatusCode.Moved || StatusCode == HttpStatusCode.SeeOther) { RedirectUri = new Uri(RequestUri, headers[HttpResponseHeader.Location]); } if (method == "HEAD") { Content = new byte[0]; } else { using (Stream input = response.GetResponseStream()) { int length; if (headers[HttpResponseHeader.ContentLength] != null && int.TryParse(headers[HttpResponseHeader.ContentLength], out length)) { Content = IOStream.Read(input, length); } else { Content = IOStream.ReadAllBytes(input); } if ((headers[HttpResponseHeader.ContentEncoding] ?? "").IndexOf("gzip", StringComparison.OrdinalIgnoreCase) >= 0 || (headers[HttpResponseHeader.TransferEncoding] ?? "").IndexOf("gzip", StringComparison.OrdinalIgnoreCase) >= 0) { Content = Content.Decompress(); } } if (StatusCode == HttpStatusCode.OK && Content.Length == 0) { Uri uriRedirect; Match m; if (!String.IsNullOrEmpty(ResponseHeaders["Refresh"]) && (m = Regex.Match(ResponseHeaders["Refresh"], @"^\d+\s*;\s*url\s*=\s*([^\s]+)\s*$")).Success && Uri.TryCreate(RequestUri, m.Groups[1].Value, out uriRedirect)) { RedirectUri = uriRedirect; StatusCode = HttpStatusCode.Redirect; } else { Log.Warning("The server returned emtpy content for the url = {0}", RequestUri); } } } return(StatusCode); } }
public void TestSaltStream() { Salt s = new Salt(); Assert.AreEqual(s.ToArray(), IOStream.ReadAllBytes(s.ToStream())); }
void ParsingEnd(ParseTaskRunner runner, HASMSource source) { if (InvokeRequired) { var del = new ParseTaskRunner.AsyncParseEndDelegate(ParsingEnd); Invoke(del, runner, source); } else { if (runner.Status == ParseTaskStatus.Failed) { ParseError error = runner.Tasks[runner.FailedTaskIndex].Error; error.Line++; MessageBox.Show($"Task \"{runner.Tasks[runner.FailedTaskIndex].Name}\" failed\n{error.ToString()}", "Parsing error", MessageBoxButtons.OK, MessageBoxIcon.Error); loadingCircle1.Visible = false; stopToolStripMenuItem.Enabled = false; tabControl1.Enabled = true; if (error.FileName != null) { bool found = false; foreach (TextEditor page in tabControl1.TabPages) { if (page.Path == error.FileName) { tabControl1.SelectedTab = page; found = true; break; } } if (!found) { AddTab(error.FileName); } if (error.Line != -1) { TextEditor tab = (tabControl1.SelectedTab as TextEditor); FastColoredTextBox tb = tab.TextBox; var minLines = 0; var maxLines = tb.LinesCount; var max = tb.VerticalScroll.Maximum; var min = tb.VerticalScroll.Minimum; var currentLine = error.Line; var maxLinesInScreen = tb.Height / tb.Font.SizeInPoints; if (tab.HighlightedLine != -1) { tb[tab.HighlightedLine].BackgroundBrush = Brushes.Transparent; tab.HighlightedLine = -1; } tab.HighlightedLine = error.Line - 1; tb[error.Line - 1].BackgroundBrush = Brushes.Pink; if (maxLinesInScreen < maxLines) { currentLine = Math.Max(Math.Abs((int)(maxLinesInScreen / 2) - currentLine) + 1, 1); int position = (int)((currentLine - minLines) * (max - min) / (float)(maxLines - minLines) + min); tb.VerticalScroll.Value = position - 1; tb.VerticalScroll.Value = position; } } } } else { IOStream stdOut = new IOStream("stdout", StreamDirection.Out); IOStream stdIn = new IOStream("stdin", StreamDirection.In); var runtime = source.Machine.CreateRuntimeMachine(source, new List <IOStream>() { stdOut, stdIn }); runThread = new Thread(p => { var result = runtime.Run(); if (result != null) { MessageBox.Show(result.ToString(), "Runtime error", MessageBoxButtons.OK, MessageBoxIcon.Error); } RunEnd(stdOut, runtime, source); }); runThread.Start(); } } }
public override void Close() { IOStream.Seek(0, SeekOrigin.Begin); Triangles = null; Accesses = null; }
public override void Open() { Close(); SoundIds = IOStream.ReadStructsByTotalSize <uint>(IOStream.Length); }
public override void Close() { IOStream.Seek(0, SeekOrigin.Begin); SoundIds = null; }
/// <summary> Combines the salt with the data provided </summary> public SaltedData(Salt salt, Stream data) : this(salt, IOStream.ReadAllBytes(data)) { }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(IOStream obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public virtual void Close(IOStream pFile) { assimp_swigPINVOKE.IOSystem_Close(swigCPtr, IOStream.getCPtr(pFile)); }
public SafeHGlobalHandle ReadData() { return(IOStream.ReadBuff((int)IOStream.Length)); }
public override void Open() { Close(); Entries = IOStream.ReadStructsByTotalSize <PcbEntry>(IOStream.Length); }
private bool register() { if (string.IsNullOrWhiteSpace(tb_register_name.Text)) { MessageBox.Show("Bạn chưa nhập tên đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_name.Focus(); return(false); } if (string.IsNullOrWhiteSpace(tb_register_password.Text)) { MessageBox.Show("Bạn chưa nhập mật khẩu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password.Focus(); return(false); } else { if (!MyValidate.validatePassword(tb_register_password.Text)) { MessageBox.Show("Mật khẩu không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password.Focus(); return(false); } } if (string.IsNullOrWhiteSpace(tb_register_password_validate.Text)) { MessageBox.Show("Bạn chưa xác nhận mật khẩu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password_validate.Focus(); return(false); } else { if (!MyValidate.validatePassword(tb_register_password_validate.Text)) { MessageBox.Show("Mật khẩu xác nhận không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password_validate.Focus(); return(false); } } if (!tb_register_password.Text.ToString().Equals(tb_register_password_validate.Text.ToString())) { MessageBox.Show("Xác nhận mật khẩu không trùng khớp" + tb_register_password.Text + tb_register_password_validate.Text, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password_validate.Focus(); return(false); } User user = new User(tb_register_name.Text, tb_register_password.Text); if (MyValidate.isUserExists(user, listUser)) { MessageBox.Show("Tài khoản đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_name.Focus(); tb_register_password_validate.Text = ""; tb_register_password.Text = ""; return(false); } else { List <User> list = new List <User>(); list.Add(user); IOStream.writeLineUser(pathDataSource, list, true); return(true); } }
public void VerifyLoadRulesWithBothCorruptions() { using (TempFile temp = new TempFile()) { var options = new TransactedCompoundFile.Options(temp.TempPath) { BlockSize = 512 }; const int count = 4; byte[] sample = new byte[options.MaxWriteSize / 3]; new Random().NextBytes(sample); using (TransactedCompoundFile file = new TransactedCompoundFile(options)) { for (uint h = 1u; h < count; h++) { Assert.AreEqual(h, file.Create()); } for (uint h = 1u; h < count; h++) { file.Write(h, sample, 0, sample.Length); } file.Commit(); } //Corrupts the primary of the first block, and secondary of the last block: using (Stream f = temp.Open()) { f.Write(sample, 0, 100); f.Seek(-100, SeekOrigin.End); f.Write(sample, 0, 100); } try { options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary; new TransactedCompoundFile(options).Dispose(); Assert.Fail("Should not load"); } catch (InvalidDataException) { } try { options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary; new TransactedCompoundFile(options).Dispose(); Assert.Fail("Should not load"); } catch (InvalidDataException) { } options.LoadingRule = TransactedCompoundFile.LoadingRule.Default; using (TransactedCompoundFile file = new TransactedCompoundFile(options)) { for (uint h = 1u; h < count; h++) { CompareBytes(sample, 0, sample.Length, IOStream.ReadAllBytes(file.Read(h))); } //Commit fixes corruption file.Commit(); } options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary; new TransactedCompoundFile(options).Dispose(); options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary; new TransactedCompoundFile(options).Dispose(); } }
public override void Close() { IOStream.Seek(0, SeekOrigin.Begin); Value = null; }
private OpenGLModel load3ds(IOStream fis) { OpenGLObject obj = null; int head_id; int head_len; int _siz; float[] _float; int[] _pts; bool done_vertex = false; bool done_pts = false; int vertexidx = -1; int vertexcnt = -1; String name; List <OpenGL3DS_Material> matlist; //materials (objects refer to material name) List <String> objlist; //object names (keyframe data refers to object name) String objname = ""; int objidx = -1; OpenGL3DS_Material mat; String matname = "", fn; int a, b, keys, u32; bool ok; int u16; OpenGLTranslate trans; OpenGLRotate rot; OpenGLScale scale; OpenGLModel mod; OpenGLUVMap map; int mapidx = -1; int skip = 0; int parent; int frameno; int s; datapos = 0; fis.Open(OpenMode.ReadOnly); data = fis.ReadAll().ToArray(); matlist = new List <OpenGL3DS_Material>(); objlist = new List <String>(); mod = new OpenGLModel(); while (!eof()) { head_id = readuint16(); head_len = readuint32(); if (head_len == -1) { break; //this does happen in some files } if (head_len < 6) { throw new Exception("head_len < 6 (" + head_len + ")"); //bad file } head_len -= 6; switch (head_id) { case 0x4d4d: //main chunk break; case 0x3d3d: //mesh chunk break; case 0xafff: //material chunk matname = ""; break; case 0xa000: //material chunk name matname = readname(head_len); break; case 0xa200: //texture details break; case 0xa300: //texture filename mat = new OpenGL3DS_Material(); fn = readname(head_len); mat.name = matname; mat.filename = fn; matlist.Add(mat); break; case 0x4000: //object chunk objname = readname(-1); //don't skip the whole chunk if (debug) { Console.WriteLine("obj=" + objname); } done_vertex = false; done_pts = false; break; case 0x4100: //triangular object chunk break; case 0x4110: //vertex list of a polygon skip = head_len; if (done_vertex) { Console.WriteLine("Warning : 2 vertex lists found for 1 object?"); break; } obj = new OpenGLObject(); obj.SetType(GL_TRIANGLES); //3ds only supports triangles obj.SetName(objname); mapidx = -1; mod.ol.Add(obj); objlist.Add(objname); _siz = readuint16(); skip -= 2; vertexidx = obj.GetVertexCount() * 3; vertexcnt = _siz; if (_siz == 0) { break; } _float = new float[_siz * 3]; for (a = 0; a < _siz; a++) { for (b = 0; b < 3; b++) { _float[a * 3 + b] = readfloat(); skip -= 4; } if (debug) { // Console.WriteLine(String.format("v=%3.3f,%3.3f,%3.3f", _float[a*3+0] , _float[a*3+1] , _float[a*3+2])); } } obj.AddVertex(_float); _float = null; done_vertex = true; break; case 0x4120: //Points list _siz = readuint16(); skip = _siz * 2 * 4; if (!done_vertex) { Console.WriteLine("Warning : pts list before vertex list?"); break; } if (done_pts) { Console.WriteLine("Warning : 2 pts lists found for 1 object?"); break; } if (_siz == 0) { break; } _pts = new int[3]; //p1,p2,p3,flgs per triangle for (a = 0; a < _siz; a++) { for (b = 0; b < 3; b++) { _pts[b] = (short)readuint16(); skip -= 2; } readuint16(); //skip flgs skip -= 2; obj.AddPoly(_pts); if (debug) { Console.WriteLine("p=" + _pts[0] + "," + _pts[1] + "," + _pts[2]); } } _pts = null; done_pts = true; break; case 0x4130: //object material name name = readname(head_len); mapidx++; map = obj.CreateUVMap(); map.SetName("uvmap" + mapidx); if (obj != null) { //find name in matlist ok = false; for (a = 0; a < matlist.Size(); a++) { if (matlist.Get(a).name.Equals(name)) { int idx = mod.AddTexture(matlist.Get(a).filename); map.SetTextureIndex(idx); ok = true; break; } } // if (!ok) throw new Exception("0x4130 : object material name not found in list : " + name); } if (debug) { Console.WriteLine("mat=" + map.GetTextureIndex()); } break; case 0x4140: //texture vertex list (UV) _siz = readuint16(); skip = _siz * 2 * 4; if (!done_vertex) { Console.WriteLine("Warning:Texture coords (UV) list before vertex list"); break; } if (_siz != vertexcnt) { Console.WriteLine("Warning:texture list siz != vertex list siz"); break; } if (_siz == 0) { break; } _float = new float[2]; for (a = 0; a < _siz; a++) { _float[0] = readfloat(); //U fis okay skip -= 4; _float[1] = 1.0f - readfloat(); //V must be inverted skip -= 4; obj.AddUV(_float, mapidx); if (debug) { // Console.WriteLine(String.format("t=%3.3f,%3.3f", _float[0] , _float[1])); } } _float = null; break; case 0x4160: //obj matrix //read in 3x3 matrix and show for now s = 0; //padding to convert to 4x4 matrix for (a = 0; a < 3 * 3; a++) { u32 = readuint32(); if ((a > 0) && (a % 3 == 0)) { s++; } //not sure what this matrix fis for??? But I don't seem to need it // obj.m.m[a+s] = readfloat(); // if (debug) Console.WriteLine("m=" + obj.m.m[a+s]); } obj.GetOrigin().x = readfloat(); obj.GetOrigin().y = readfloat(); obj.GetOrigin().z = readfloat(); if (debug) { Console.WriteLine("pos=" + obj.GetOrigin().x + "," + obj.GetOrigin().y + "," + obj.GetOrigin().z); } break; case 0xb000: //keyframe header break; case 0xb002: //object node chunk objidx = -1; break; case 0xb010: //keyframe object name name = readname(-1); readuint16(); //f1 readuint16(); //f2 parent = readuint16(); //parent //find name in objlist objidx = 0; ok = false; for (a = 0; a < objlist.Size(); a++) { if (objlist.Get(a).Equals(name)) { ok = true; break; } objidx++; } if (!ok) { objidx = -1; } else { obj = mod.ol.Get(objidx); if (parent != 65535) { obj.SetParent(parent); } obj = null; } //Console.WriteLine("0xb010 : name=" + name + ":objidx=" + objidx + ":parent=" + parent); break; case 0xb020: //keyframe pos skip = head_len; if (objidx == -1) { break; } obj = mod.ol.Get(objidx); u16 = readuint16(); //flgs skip -= 2; u32 = readuint32(); //r1 skip -= 4; u32 = readuint32(); //r2 skip -= 4; keys = readuint32(); //keys skip -= 4; _float = new float[3]; for (a = 0; a < keys; a++) { frameno = readuint32(); //frame # skip -= 4; u16 = readuint16(); //flgs skip -= 2; u32 = 0; if ((u16 & _3DS_FLG_TENSION) != 0) { u32++; } if ((u16 & _3DS_FLG_CONTINUITY) != 0) { u32++; } if ((u16 & _3DS_FLG_BIAS) != 0) { u32++; } if ((u16 & _3DS_FLG_EASE_TO) != 0) { u32++; } if ((u16 & _3DS_FLG_EASE_FROM) != 0) { u32++; } if (u32 > 0) { datapos += u32 * 4; //all ignored skip -= u32 * 4; } trans = new OpenGLTranslate(); for (b = 0; b < 3; b++) { _float[b] = readfloat(); skip -= 4; } trans.x = _float[0]; trans.y = _float[1]; trans.z = _float[2]; //Console.WriteLine("pos["+frameno+"]:"+pos.x+","+pos.y+","+pos.z+":flgs="+u16); obj.GetTranslateMap().Set(frameno, trans); if (obj.GetMaxFrameCount() < frameno) { obj.SetMaxFrameCount(frameno); } } _float = null; obj = null; break; case 0xb021: //keyframe rotate skip = head_len; if (objidx == -1) { break; } obj = mod.ol.Get(objidx); u16 = readuint16(); //flgs skip -= 2; u32 = readuint32(); //r1 skip -= 4; u32 = readuint32(); //r2 skip -= 4; keys = readuint32(); //keys skip -= 4; _float = new float[4]; for (a = 0; a < keys; a++) { frameno = readuint32(); //frame # skip -= 4; u16 = readuint16(); //flgs skip -= 2; u32 = 0; if ((u16 & _3DS_FLG_TENSION) != 0) { u32++; } if ((u16 & _3DS_FLG_CONTINUITY) != 0) { u32++; } if ((u16 & _3DS_FLG_BIAS) != 0) { u32++; } if ((u16 & _3DS_FLG_EASE_TO) != 0) { u32++; } if ((u16 & _3DS_FLG_EASE_FROM) != 0) { u32++; } if (u32 > 0) { datapos += u32 * 4; //all ignored skip -= u32 * 4; } rot = new OpenGLRotate(); for (b = 0; b < 4; b++) { _float[b] = readfloat(); skip -= 4; } rot.angle = _float[0] * 57.2957795f; //convert to degrees rot.x = _float[1]; rot.y = _float[2]; rot.z = _float[3]; //Console.WriteLine("rot["+frameno+"]:"+rot.angle+","+rot.x+","+rot.y+","+rot.z+":flgs="+u16); obj.GetRotateMap().Set(frameno, rot); if (obj.GetMaxFrameCount() < frameno) { obj.SetMaxFrameCount(frameno); } } _float = null; obj = null; break; case 0xb022: //keyframe scale skip = head_len; if (objidx == -1) { break; } obj = mod.ol.Get(objidx); u16 = readuint16(); //flgs skip -= 2; u32 = readuint32(); //r1 skip -= 4; u32 = readuint32(); //r2 skip -= 4; keys = readuint32(); //keys skip -= 4; _float = new float[3]; for (a = 0; a < keys; a++) { frameno = readuint32(); //frame # skip -= 4; u16 = readuint16(); //flgs skip -= 2; u32 = 0; if ((u16 & _3DS_FLG_TENSION) != 0) { u32++; } if ((u16 & _3DS_FLG_CONTINUITY) != 0) { u32++; } if ((u16 & _3DS_FLG_BIAS) != 0) { u32++; } if ((u16 & _3DS_FLG_EASE_TO) != 0) { u32++; } if ((u16 & _3DS_FLG_EASE_FROM) != 0) { u32++; } if (u32 > 0) { datapos += u32 * 4; //all ignored skip -= u32 * 4; } scale = new OpenGLScale(); for (b = 0; b < 3; b++) { _float[b] = readfloat(); skip -= 4; } scale.x = _float[0]; scale.y = _float[1]; scale.z = _float[2]; //Console.WriteLine("scale["+frameno+"]:"+scale.x+","+scale.y+","+scale.z+":flgs="+u16); obj.GetScaleMap().Set(frameno, scale); if (obj.GetMaxFrameCount() < frameno) { obj.SetMaxFrameCount(frameno); } } _float = null; obj = null; break; default: skip = head_len; break; } if (skip > 0) { datapos += skip; skip = 0; } } //setup any lights _siz = mod.ol.Size(); for (a = 0; a < _siz; a++) { obj = mod.ol.Get(a); } //delete temp lists matlist.Clear(); objlist.Clear(); return(mod); }
public override void Open() { Close(); Value = IOStream.ReadStruct <uint>(); }
public WebReply Put(WebRequest request, IOStream io) { return((WebReply)CPP.ReturnObject("new WebReply($q->put(*$check(request)->$value(), io->$q.get()))")); }
public override void Close() { IOStream.Seek(0, SeekOrigin.Begin); Header = null; Palettes = null; }
public void TestMarshalStream() { byte[] dataIn = new byte[1024]; byte[] copy; new Random().NextBytes(dataIn); GCHandle h = GCHandle.Alloc(dataIn, GCHandleType.Pinned); try { using (MarshallingStream stream = new MarshallingStream(h.AddrOfPinnedObject(), false, dataIn.Length)) { Assert.IsTrue(stream.CanRead); Assert.IsTrue(stream.CanWrite); Assert.IsTrue(stream.CanSeek); copy = new byte[(int)stream.Length]; IOStream.Read(stream, copy, (int)stream.Length); Assert.AreEqual(dataIn, copy); Assert.AreEqual(stream.Length, stream.Position); stream.Position = 0; Assert.AreEqual(0L, stream.Position); stream.Write(new byte[dataIn.Length], 0, dataIn.Length); Assert.AreEqual(new byte[dataIn.Length], dataIn); stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(0, stream.Position); stream.Write(copy, 0, dataIn.Length); Assert.AreEqual(dataIn, copy); stream.Seek(-10, SeekOrigin.Current); Assert.AreEqual(stream.Length - 10, stream.Position); stream.Seek(-stream.Length, SeekOrigin.End); Assert.AreEqual(0, stream.Position); stream.WriteByte(123); stream.Position = 0; Assert.AreEqual(123, stream.ReadByte()); } using (MarshallingStream stream = new MarshallingStream(h.AddrOfPinnedObject(), true, dataIn.Length)) { Assert.IsFalse(stream.CanWrite); copy = new byte[(int)stream.Length]; IOStream.Read(stream, copy, (int)stream.Length); Assert.AreEqual(dataIn, copy); try { stream.Write(new byte[10], 0, 10); Assert.Fail(); } catch (InvalidOperationException) { } stream.Dispose(); try { stream.Read(new byte[10], 0, 10); Assert.Fail(); } catch (ObjectDisposedException) { } } } finally { h.Free(); } }
public StreamReader(IOStream stream, uint bufferSize) { _stream = stream; _bufferSize = bufferSize; }