/// <summary> /// Creates a new archive based on the specified stream. /// </summary> public Archive(Stream stream) { if (!stream.CanRead) { throw new IOException("Archive stream must be readable."); } if (!stream.CanSeek) { throw new IOException("Archive stream must be seekable."); } this.stream = stream; br = new BinaryReader(stream); bw = new BinaryWriter(stream); if (stream.Length == 0) { bw.Write(Encoding.ASCII.GetBytes("Archive:")); Reserve(); stream.Position = 8; bw.Write((short)5); bw.Write(0); bw.Write(-1); bw.Write(""); bw.Flush(); } stream.Position = 0; if (Encoding.ASCII.GetString(br.ReadBytes(8)) != "Archive:") { throw new Exception("Stream is not a valid archive."); } entries.Add(new FileInfo(this, "", 0, 1)); AStream a = new AStream((FileInfo)entries[0]); BinaryReader ar = new BinaryReader(a); next_dir = ar.ReadInt32(); string s; while ((s = ar.ReadString()) != "") { int i = ar.ReadInt32(), j = ar.ReadInt32(); if (i < 0) { entries.Add(new DirInfo(this, s, i, j)); } else { entries.Add(new FileInfo(this, s, i, j)); } } a.Close(); }
public void Start() { for (int i = 0; i < N; i++) { AStream.Process(Time); } var frequency = AStream.GetFrequency(); Probabilities = EmpiricalProbs(frequency, N); TProbs = TheoreticalProbs(ALambda, Time, Probabilities.Length); Average = 0; double E = 0; for (int i = 0; i < Probabilities.Length; i++) { Average += Probabilities[i] * i; E += TProbs[i] * i; } AverageError = Math.Abs((Average - E) / E); Variance = 0; double D = 0; for (int i = 0; i < Probabilities.Length; i++) { Variance += Probabilities[i] * i * i; D += TProbs[i] * i * i; } Variance -= Average * Average; D -= E * E; VarianceError = Math.Abs((Variance - D) / D); ChiSquare = 0; for (int i = 0; i < Probabilities.Length; i++) { ChiSquare += (frequency[i] - N * TProbs[i]) * (frequency[i] - N * TProbs[i]) / (N * TProbs[i]); } if (Probabilities.Length > 1) { CriticalValue = ChiSquared.InvCDF(Probabilities.Length - 1, 1 - 0.05); if (ChiSquare <= CriticalValue) { ChiSquareTest = true; } else { ChiSquareTest = false; } } }
public SIndex(STransaction tr, SIndex x, AStream f) : base(x, f) { table = tr.Fix(x.table); long[] c = new long[x.cols.Length]; var i = 0; for (var b = x.cols.First(); b != null; b = b.Next()) { c[i++] = tr.Fix(b.Value); } cols = SList <long> .New(c); rows = x.rows; }
SIndex(SDatabase d, AStream f) : base(Types.SIndex, f) { table = f.GetLong(); var n = f.ReadByte(); var c = new long[n]; for (var i = 0; i < n; i++) { c[i] = f.GetInt(); } cols = SList <long> .New(c); rows = new SMTree(Info((STable)d.objects.Lookup(table), cols)); }
public void Start() { for (int i = 0; i < N; i++) { AStream.Process(t); } var frequency = AStream.GetFrequency(); possbilities = EmpiricalProbs(frequency, N); teorPossibs = TheoreticalProbs(ALambda, t, possbilities.Length); Average = 0; double E = 0; for (int i = 0; i < possbilities.Length; i++) { Average += possbilities[i] * i; E += teorPossibs[i] * i; } AverageError = Math.Abs((Average - E) / E); Variance = 0; double D = 0; for (int i = 0; i < possbilities.Length; i++) { Variance += possbilities[i] * i * i; D += teorPossibs[i] * i * i; } Variance -= Average * Average; D -= E * E; VarianceError = Math.Abs((Variance - D) / D); Chi = 0; for (int i = 0; i < possbilities.Length; i++) { Chi += (frequency[i] - N * teorPossibs[i]) * (frequency[i] - N * teorPossibs[i]) / (N * teorPossibs[i]); } if (possbilities.Length > 1) { CriticalValue = ChiSquared.InvCDF(possbilities.Length - 1, 0.95); if (Chi <= CriticalValue) { ChiTest = true; } else { ChiTest = false; } } }
/// <summary> /// Burns a boot image and data files to disc in a single session /// using files from a single directory tree. /// </summary> /// <param name="recorder">Burning Device. Must be initialized.</param> /// <param name="path">Directory of files to burn. /// \\winbuilds\release\winmain\latest.tst\amd64fre\en-us\skus.cmi\staged\windows /// </param> /// <param name="bootFile">Path and filename of boot image. /// \\winbuilds\release\winmain\latest.tst\x86fre\bin\etfsboot.com /// </param> public void CreateBootDisc(IDiscRecorder2 recorder, String path, String bootFile) { // -------- Adding Boot Image Code ----- Console.WriteLine("Creating BootOptions"); IBootOptions bootOptions = new MsftBootOptions(); bootOptions.Manufacturer = "Microsoft"; bootOptions.PlatformId = PlatformId.PlatformX86; bootOptions.Emulation = EmulationType.EmulationNone; // Need stream for boot image file Console.WriteLine("Creating IStream for file {0}", bootFile); IStream iStream = new AStream( new FileStream(bootFile, FileMode.Open, FileAccess.Read, FileShare.Read)); bootOptions.AssignBootImage(iStream); // Create disc file system image (ISO9660 in this example) IFileSystemImage fsi = new MsftFileSystemImage(); fsi.FreeMediaBlocks = -1; // Enables larger-than-CD image fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemUDF; // Hooking bootStream to FileSystemObject fsi.BootImageOptions = bootOptions; // Hooking content files FileSystemObject fsi.Root.AddTree(path, false); IFileSystemImageResult result = fsi.CreateResultImage(); IStream stream = result.ImageStream; // Create and write stream to disc using the specified recorder. IDiscFormat2Data dataWriterBurn = new MsftDiscFormat2Data(); dataWriterBurn.Recorder = recorder; dataWriterBurn.ClientName = "IMAPI Sample"; dataWriterBurn.Write(stream); Console.WriteLine("----- Finished writing content -----"); }
internal void UpdateDirs() { AStream a = new AStream((FileInfo)entries[0], FileAccess.ReadWrite); BinaryWriter aw = new BinaryWriter(a); aw.Write(next_dir); foreach (DirInfo di in entries) { if (di.Name == "") { continue; } aw.Write(di.Name); aw.Write(di.Index); aw.Write(di.Parent); } aw.Write(""); a.SetLength(a.Position); a.Close(); }
protected SQuery(SQuery q, AStream f) : base(q, f) { display = SDict <int, string> .Empty; cpos = SDict <int, Serialisable> .Empty; names = SDict <string, Serialisable> .Empty; }
public override STransaction Commit(STransaction tr, int c, AStream f) { return(base.Commit(tr, f)); }
public Stream Open(string path, FileMode mode, FileAccess access) { DirInfo di = FindInfo(path); if (di != null && !(di is FileInfo)) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path)); } switch (mode) { case FileMode.Append: if (access == FileAccess.Read) { throw new IOException("Appending requires writing access."); } if (di == null) { goto case FileMode.CreateNew; } break; case FileMode.Create: if (di == null) { goto case FileMode.CreateNew; } else { goto case FileMode.Truncate; } case FileMode.CreateNew: if (di != null) { throw new IOException("File already exists."); } StringCollection sa = new StringCollection(ResolvePath(path)); string s = sa[sa.Count - 1]; sa.RemoveAt(sa.Count - 1); di = FindInfo("\\" + string.Join("\\", sa.ToArray())); if (di == null) { throw new IOException("Path does not exist."); } di = new FileInfo(this, s, Reserve(), di.Index); entries.Add(di); break; case FileMode.Open: if (di == null) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path)); } break; case FileMode.OpenOrCreate: if (di == null) { goto case FileMode.CreateNew; } else { break; } case FileMode.Truncate: ((FileInfo)di).Length = 0; break; } Stream st = new AStream((FileInfo)di, access); if (mode == FileMode.Append) { st.Position = st.Length; } return(st); }