protected static Endianness GetFormatEndianness(IOFormat format) { switch (format) { case IOFormat.LE: return(Endianness.Little); case IOFormat.BE: return(Endianness.Big); default: throw new ArgumentOutOfRangeException("format"); } }
// Parse string to cell contents at (col, row) in given workbook public static Cell Parse(String text, Workbook workbook, int col, int row) { if (!String.IsNullOrWhiteSpace(text)) { Scanner scanner = new Scanner(IOFormat.MakeStream(text)); Parser parser = new Parser(scanner); return(parser.ParseCell(workbook, col, row)); // May be null } else { return(null); } }
public void LoadParams(string[] arguments) { var cmdline = new aCommandLine(arguments); aCommandLineParameter parameter; // input parameter = mareep.GetLastCmdParam(cmdline, "-input"); if (parameter == null) { mareep.WriteError("WAVE: missing -input parameter."); } else if (parameter.Count == 0) { mareep.WriteError("WAVE: missing argument for -input parameter."); } mInput = parameter[0]; mInputFormat = GetFormat(Path.GetExtension(mInput)); if (mInputFormat == IOFormat.Raw) { if (parameter.Count < 2) { mareep.WriteError("WAVE: missing format for raw input."); } if (!Enum.TryParse(parameter[1], true, out mRawInputFormat)) { mareep.WriteError("WAVE: bad format '{0}' for raw input.", parameter[1]); } } // output parameter = mareep.GetLastCmdParam(cmdline, "-output"); if (parameter == null) { mareep.WriteError("WAVE: missing -output parameter."); } else if (parameter.Count == 0) { mareep.WriteError("WAVE: missing argument for -output parameter."); } mOutput = parameter[0]; mOutputFormat = GetFormat(Path.GetExtension(mOutput)); if (mOutputFormat == IOFormat.Raw) { if (parameter.Count < 2) { mareep.WriteError("WAVE: missing format for raw output."); } if (!Enum.TryParse(parameter[1], true, out mRawOutputFormat)) { mareep.WriteError("WAVE: bad format '{0}' for raw output.", parameter[1]); } } else if (mOutputFormat == IOFormat.AfcStream) { if (parameter.Count < 2) { mStreamFormat = StreamFormat.Adpcm; } else if (!Enum.TryParse(parameter[1], true, out mStreamFormat)) { mareep.WriteError("WAVE: bad stream format '{0}'.", parameter[1]); } } // mode if (mInputFormat == IOFormat.Raw && mOutputFormat == IOFormat.Raw) { mMode = Mode.RawToRaw; } else if (mInputFormat == IOFormat.Raw && mOutputFormat == IOFormat.MicrosoftWave) { mMode = Mode.RawToWav; } else if (mInputFormat == IOFormat.MicrosoftWave && mOutputFormat == IOFormat.Raw) { mMode = Mode.WavToRaw; } else if (mInputFormat == IOFormat.MicrosoftWave && mOutputFormat == IOFormat.AfcStream) { mMode = Mode.WavToStream; } else if (mInputFormat == IOFormat.AfcStream && mOutputFormat == IOFormat.MicrosoftWave) { mMode = Mode.StreamToWav; } else { mareep.WriteError("WAVE: unsupported combination of input and output formats."); } // mix mode parameter = mareep.GetLastCmdParam(cmdline, "-mix-mode"); if (parameter != null) { if (parameter.Count < 1) { mareep.WriteError("WAVE: bad -mix-mode parameter."); } if (!Enum.TryParse(parameter[0], true, out mMixerMode)) { mareep.WriteError("WAVE: bad mixer mode '{0}' in -mix-mode parameter.", parameter[0]); } } // sample rate parameter = mareep.GetLastCmdParam(cmdline, "-sample-rate"); if (parameter != null) { if (parameter.Count < 1) { mareep.WriteError("WAVE: missing argument for -sample-rate parameter."); } if (!Int32.TryParse(parameter[0], out mRawSampleRate) || mRawSampleRate < 0) { mareep.WriteError("WAVE: bad sample rate '{0}'.", parameter[0]); } } else if (mInputFormat == IOFormat.Raw && mOutputFormat != IOFormat.Raw) { mareep.WriteError("WAVE: missing -sample-rate parameter for raw input."); } // frame rate parameter = mareep.GetLastCmdParam(cmdline, "-frame-rate"); if (parameter != null) { if (parameter.Count < 1) { mareep.WriteError("WAVE: missing argument for -frame-rate parameter."); } if (!Int32.TryParse(parameter[0], out mStreamFrameRate) || mStreamFrameRate < 0) { mareep.WriteError("WAVE: bad frame rate '{0}'.", parameter[0]); } } else { mStreamFrameRate = 30; } // loop parameter = mareep.GetLastCmdParam(cmdline, "-loop"); if (parameter != null) { mStreamLoop = true; if (parameter.Count < 1) { mareep.WriteError("WAVE: missing argument for -loop parameter."); } if (!Int32.TryParse(parameter[0], out mStreamLoopStart) || mStreamLoopStart < 0) { mareep.WriteError("WAVE: bad loop value '{0}'.", parameter[0]); } } }
public T InternalTrackedGet <T>(Transaction transaction, string filePath, LockOperation intendedOperation, IOFormat format) { try { string cacheKey = Helpers.RemoveModFileName(filePath.ToLower()); transaction.LockFile(intendedOperation, cacheKey); if (core.settings.AllowIOCaching) { var cachedObject = core.Cache.Get(cacheKey); if (cachedObject != null) { core.Health.Increment(Constants.HealthCounterType.IOCacheReadHits); core.Log.Trace(String.Format("IO:CacheHit:{0}->{1}", transaction.ProcessId, filePath)); return((T)cachedObject.Value); } } core.Health.Increment(Constants.HealthCounterType.IOCacheReadMisses); core.Log.Trace(String.Format("IO:Read:{0}->{1}", transaction.ProcessId, filePath)); T deserializedObject; if (format == IOFormat.JSON) { string text = File.ReadAllText(filePath); deserializedObject = JsonConvert.DeserializeObject <T>(text); } else if (format == IOFormat.PBuf) { using (var file = File.OpenRead(filePath)) { deserializedObject = ProtoBuf.Serializer.Deserialize <T>(file); file.Close(); } } else { throw new NotImplementedException(); } if (core.settings.AllowIOCaching) { core.Cache.Upsert(cacheKey, deserializedObject); core.Health.Increment(Constants.HealthCounterType.IOCacheReadAdditions); } return(deserializedObject); } catch (Exception ex) { core.Log.Write("Failed to get JSON object.", ex); throw; } }
private void InternalTrackedPut(Transaction transaction, string filePath, object deserializedObject, IOFormat format) { try { string cacheKey = Helpers.RemoveModFileName(filePath.ToLower()); transaction.LockFile(Constants.LockOperation.Write, cacheKey); bool deferDiskWrite = false; if (transaction != null) { bool doesFileExist = File.Exists(filePath); if (doesFileExist == false) { transaction.RecordFileCreate(filePath); } else { transaction.RecordFileAlter(filePath); } if (core.settings.AllowDeferredIO && transaction.IsLongLived) { deferDiskWrite = transaction.DeferredIOs.RecordDeferredDiskIO(cacheKey, filePath, deserializedObject, format); } } if (deferDiskWrite == false) { core.Log.Trace(String.Format("IO:Write:{0}->{1}", transaction.ProcessId, filePath)); if (format == IOFormat.JSON) { string text = JsonConvert.SerializeObject(deserializedObject); File.WriteAllText(filePath, text); } else if (format == IOFormat.PBuf) { using (var file = File.Create(filePath)) { ProtoBuf.Serializer.Serialize(file, deserializedObject); file.Close(); } } else { throw new NotImplementedException(); } } else { core.Log.Trace(String.Format("IO:Write-Deferred:{0}->{1}", transaction.ProcessId, filePath)); } if (core.settings.AllowIOCaching) { core.Cache.Upsert(cacheKey, deserializedObject); core.Health.Increment(Constants.HealthCounterType.IOCacheWriteAdditions); } } catch (Exception ex) { core.Log.Write(String.Format("Failed to put JSON file for session {0}.", transaction.ProcessId), ex); throw; } }
protected static bool IsFormatBinary(IOFormat format) { return(format == IOFormat.LE || format == IOFormat.BE); }
/// <summary> /// Keeps a reference to a file so that we can defer serializing and writing it to disk. /// </summary> /// <param name="key"></param> /// <param name="reference"></param> /// <returns></returns> public bool RecordDeferredDiskIO(string key, string diskPath, object reference, IOFormat deferredFormat) { lock (this) { if (Collection.ContainsKey(key)) { var wrapper = Collection[key]; wrapper.Hits++; wrapper.DiskPath = diskPath; wrapper.LowerDiskPath = diskPath.ToLower(); wrapper.Reference = reference; wrapper.DeferredFormat = deferredFormat; } else { var wrapper = new DeferredDiskIOObject() { Hits = 1, DeferredFormat = deferredFormat, DiskPath = diskPath, LowerDiskPath = diskPath.ToLower(), Reference = reference }; Collection.Add(key, wrapper); } return(true); } }