/// <summary> /// Only PBW is required to make a Portamento. /// If you provide empty on the others, we will use the default value: /// 0;(invalid) for pbs, 0 for pby, "" or s-curve for pbm /// If pbs does not have second parameter, it will be considered invalid as well. /// it is outside this class or USTNote's power to get information about previous notes, please read UST's constructor for its handling. /// </summary> /// <param name="PBS"></param> /// <param name="PBW"></param> /// <param name="PBY"></param> /// <param name="PBM"></param> public Portamento(string PBW, string PBS, string PBY, string PBM) { Segments = new List <PortamentoSegment>(); if (PBS == null || PBS.Trim().Length == 0) { this.PBS = new double[] { 0, double.NaN } } ; else { if (!PBS.Contains(";")) //starting y is 0 { if (!PBS.Contains(",")) //don't you just love working with legendary code { this.PBS = new double[] { Convert.ToDouble(PBS), double.NaN } } ; else { this.PBS = zusp.Split(PBS, ",").Select((s) => Convert.ToDouble(s)).ToArray(); } } else { this.PBS = zusp.Split(PBS, ";").Select((s) => Convert.ToDouble(s)).ToArray(); } } var w = zusp.SplitAsIs(PBW, ",") .Select((s) => (s.Equals("")) ? (0) : (Convert.ToDouble(s)))//empty entries means 0. .ToList(); var y = zusp.SplitAsIs(PBY, ",") .Select((s) => (s.Equals("")) ? (0) : (Convert.ToDouble(s)))//why though? i wonder. .ToList(); while (y.Count < w.Count - 1) { y.Add(0); //-1 because last point must be 0 as far as utau's concern, which is stupid. } var m = zusp.SplitAsIs(PBM, ",").ToList(); while (m.Count < w.Count) { m.Add(PBM_S_CURVE); } //initialize segments for (int i = 0; i < w.Count - 1; i++)//last segment is a special case. { Segments.Add(new PortamentoSegment(w[i], y[i], m[i])); } Segments.Add(new PortamentoSegment(w[w.Count - 1], 0, m[w.Count - 1])); //now fill the virtual arrays. this.PBW = new VirtualArray <double>((i) => (Segments[i].PBW), (i, v) => Segments[i].PBW = v, () => Segments.Count); this.PBY = new VirtualArray <double>((i) => (Segments[i].PBY), (i, v) => Segments[i].PBW = v, () => Segments.Count - 1); this.PBM = new VirtualArray <string>((i) => (Segments[i].PBM), (i, v) => Segments[i].PBM = v, () => Segments.Count); }
/// <summary> /// Escreve dados para a instancia. /// </summary> /// <param name="vBuffer">Buffer contendo os dados que serão escritos.</param> /// <param name="srcOffset">Offset da origem.</param> /// <param name="dstOffset">Offset de destino.</param> /// <param name="length">Quantidade de dados que serão escritos.</param> public void Write(VirtualArray vBuffer, int srcOffset, int dstOffset, int length) { UserBinaryObject obj2 = (this.Value is CallbackEntry) ? ((UserBinaryObject)((CallbackEntry)this.Value).Value) : ((UserBinaryObject)this.Value); if (obj2 != null) { obj2.Write(vBuffer, srcOffset, dstOffset, length); } }
public void Write(VirtualArray vBuffer, int srcOffset, int dstOffset, int length) { UserBinaryObject ubObject = (UserBinaryObject)(Value is CallbackEntry ? ((CallbackEntry)Value).Value : Value); if (ubObject != null) { ubObject.Write(vBuffer, srcOffset, dstOffset, length); } }
/// <summary> /// Escreve o buffer no item. /// </summary> /// <param name="vBuffer">buffer com os dados que serão inseridos.</param> /// <param name="srcOffset">Offset da origem dom buffer.</param> /// <param name="dstOffset">Offset de destino.</param> /// <param name="length">Quantidade de dados que serão escritors</param> public void Write(VirtualArray vBuffer, int srcOffset, int dstOffset, int length) { if (vBuffer != null) { VirtualArray dst = new VirtualArray(_data); VirtualArray.CopyData(vBuffer, new VirtualIndex(srcOffset), dst, new VirtualIndex(dstOffset), length, true); _noOfChunks = _data.Count; } }
public void consumeTestFalseOnNoLabelMatch() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-test"); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] {"-nottest"}, 0, 1); ParsedArgs pArgs = new ParsedArgs(); bool result = testDef.consume(vArgs, pArgs); Assert.IsFalse(result, "[ArgDef][consume] consume should return false when no label matches the input"); }
public void Deserialize(CompactReader reader) { _key = reader.ReadObject() as string; _lockHandle = reader.ReadObject() as string; _vBuffer = reader.ReadObject() as VirtualArray; _srcOffset = reader.ReadInt32(); _dstOffset = reader.ReadInt32(); _length = reader.ReadInt32(); _operationContext = reader.ReadObject() as OperationContext; }
public WriteToStreamOperation(string key, string lockHandle, VirtualArray vBuffer, int srcOffset, int dstOffset, int length, OperationContext operationContext) { _key = key; _lockHandle = lockHandle; _vBuffer = vBuffer; _srcOffset = srcOffset; _dstOffset = dstOffset; _length = length; _operationContext = operationContext; }
/// <summary> /// Lê dados da instancia. /// </summary> /// <param name="offset">Offset para leitura.</param> /// <param name="length">Quantidade que serão lidos.</param> /// <returns></returns> public VirtualArray Read(int offset, int length) { VirtualArray array = null; UserBinaryObject obj2 = (this.Value is CallbackEntry) ? ((UserBinaryObject)((CallbackEntry)this.Value).Value) : ((UserBinaryObject)this.Value); if (obj2 != null) { array = obj2.Read(offset, length); } return(array); }
public VirtualArray Read(int offset, int length) { VirtualArray vBuffer = null; UserBinaryObject ubObject = (UserBinaryObject)(Value is CallbackEntry ? ((CallbackEntry)Value).Value : Value); if (ubObject != null) { vBuffer = ubObject.Read(offset, length); } return(vBuffer); }
public void consumeTestFlag() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t" }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); Assert.IsTrue(pArgs.getValue<bool>("t"), "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered."); }
public override void Write(VirtualArray vBuffer, int srcOffset, int dstOffset, int length) { if (vBuffer == null) { return; } { VirtualArray vDstArray = new VirtualArray(_data); VirtualArray.CopyData(vBuffer, new VirtualIndex(srcOffset), vDstArray, new VirtualIndex(dstOffset), length, true); _noOfChunks = _data.Count; } }
public override void WriteToStream(string key, string lockHandle, VirtualArray vBuffer, int srcOffset, int dstOffset, int length, OperationContext operationContext) { try { base.Sync.AcquireWriterLock(-1); this.InternalCache.WriteToStream(key, lockHandle, vBuffer, srcOffset, dstOffset, length, operationContext); } finally { base.Sync.ReleaseWriterLock(); } }
public override int ReadFromStream(ref VirtualArray vBuffer, string key, string lockHandle, int offset, int length, OperationContext operationContext) { try { base.Sync.AcquireReaderLock(-1); return(this.InternalCache.ReadFromStream(ref vBuffer, key, lockHandle, offset, length, operationContext)); } finally { base.Sync.ReleaseReaderLock(); } }
public void getTest() { int[] ints = new int[3] { 0, 1, 2 }; VirtualArray<int> testArray = new VirtualArray<int>(ints); Assert.AreEqual(0, testArray[0], string.Format("[VirtualArray][get] expected {0}, received {1}", 0, testArray[0])); Assert.AreEqual(1, testArray[1], string.Format("[VirtualArray][get] expected {0}, received {1}", 1, testArray[1])); Assert.AreEqual(2, testArray[2], string.Format("[VirtualArray][get] expected {0}, received {1}", 2, testArray[2])); testArray.moveStartBy(1); Assert.AreEqual(1, testArray[0], string.Format("[VirtualArray][get] expected {0}, received {1}", 1, testArray[0])); Assert.AreEqual(2, testArray[1], string.Format("[VirtualArray][get] expected {0}, received {1}", 2, testArray[1])); testArray.moveStartBy(1); Assert.AreEqual(2, testArray[0], string.Format("[VirtualArray][get] expected {0}, received {1}", 2, testArray[0])); }
public override void Write(VirtualArray vBuffer, int srcOffset, int dstOffset, int length) { if (vBuffer == null) { return; } VirtualArray vDstArray = new VirtualArray(_data); VirtualArray.CopyData(vBuffer, new VirtualIndex(srcOffset), vDstArray, new VirtualIndex(dstOffset), length, true); _noOfChunks = _data.Count; //_lastChunkSize = ((byte[])_data[_data.Count - 1]).Length; _lastChunkSize += (length < 0 ? 0 : length) % LARGE_OBJECT_SIZE; }
public void consumeTestLabeledBoolAsArray() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.type = typeof(bool); testDef.argCount = 1; testDef.createArrayForArgCount1 = true; testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", "false" }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); bool[] result = pArgs.getArray<bool>("t"); Assert.AreEqual<int>(1, result.Length, "[ArgDef][consume] consume should create an array of size 1 when argCount is 1 and createArrayForArgCount1 is true"); Assert.IsFalse(result[0], "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered."); }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { Alachisoft.NCache.Common.Protobuf.ReadFromStreamCommand readFromStreamCommand = command.readFromStreamCommand; ReadFromStreamCommandInfo cmdInfo = new ReadFromStreamCommandInfo(); cmdInfo.key = readFromStreamCommand.key; cmdInfo.length = readFromStreamCommand.length; cmdInfo.lockHandle = readFromStreamCommand.lockHandle; cmdInfo.offset = readFromStreamCommand.offset; cmdInfo.requestId = readFromStreamCommand.requestId; int bytesRead = 0; List <byte[]> buffer = null; VirtualArray vBuffer = null; try { bytesRead = ((NCache)clientManager.CmdExecuter).Cache.ReadFromStream(ref vBuffer, cmdInfo.key, cmdInfo.lockHandle, cmdInfo.offset, cmdInfo.length, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); } catch (Exception e) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(e, command.requestID, command.commandID)); return; } Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.ReadFromStreamResponse readFromStreamResponse = new Alachisoft.NCache.Common.Protobuf.ReadFromStreamResponse(); if (bytesRead > 0) { foreach (byte[] buffersegment in vBuffer.BaseArray) { readFromStreamResponse.buffer.Add(buffersegment); } } readFromStreamResponse.bytesRead = bytesRead; response.requestId = cmdInfo.requestId; response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.READ_FROM_STREAM; response.readFromStreamResponse = readFromStreamResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); }
public virtual bool consume(VirtualArray<string> vArgs, ParsedArgs pArgs) { if (!isConsumeable(vArgs)) { return false; } pArgs.add(name, getValue(vArgs)); if (argCountIsRemainderOfArgs) { vArgs.moveStart(vArgs.endIndexExclusive); } else { vArgs.moveStartBy(argCount + 1); } return true; }
/// <summary> /// Lê os dados da instancia. /// </summary> /// <param name="offset"></param> /// <param name="length"></param> /// <returns></returns> public VirtualArray Read(int offset, int length) { VirtualArray dst = null; int num = this.Length; if (offset >= num) { return(new VirtualArray(0)); } if ((offset + length) > num) { length -= (offset + length) - num; } VirtualArray src = new VirtualArray(_data); dst = new VirtualArray((long)length); VirtualIndex srcIndex = new VirtualIndex(offset); VirtualIndex dstIndex = new VirtualIndex(); VirtualArray.CopyData(src, srcIndex, dst, dstIndex, length); return(dst); }
public override VirtualArray Read(int offset, int length) { VirtualArray vBuffer = null; int streamLength = Length; if (offset >= streamLength) { return(new VirtualArray(0)); } if (offset + length > streamLength) { length -= (offset + length - streamLength); } VirtualArray vSrc = new VirtualArray(_data); vBuffer = new VirtualArray(length); VirtualIndex vSrcIndex = new VirtualIndex(offset); VirtualIndex vDstIndex = new VirtualIndex(); VirtualArray.CopyData(vSrc, vSrcIndex, vBuffer, vDstIndex, length); return(vBuffer); }
public void consumeTestMultipleOptionEncounters() { ArgDef testDef = new ArgDef(); testDef.argLabels.AddRange(new string[]{"-test", "-t"}); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] {"-test", "-t"}, 0, 2); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); bool result2 = testDef.consume(vArgs, pArgs); bool errors = testDef.errorOccured(); Assert.IsFalse(result2, "[ArgDef][consume] consume should return false when a label is encountered twice."); Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error message when a label is encountered twice."); }
public abstract void Write(VirtualArray vBuffer, int srcOffset, int dstOffset, int length);
public new void Deserialize(CompactReader reader) { base.Deserialize(reader); _vBuffer = reader.ReadObject() as VirtualArray; _bytesRead = reader.ReadInt32(); }
public ReadFromStreamResult(VirtualArray vBuffer, int bytesRead, ClusterOperationResult.Result result) : base(result) { _vBuffer = vBuffer; _bytesRead = bytesRead; }
public void consumeTestRemainingString() { ArgDef testDef = new ArgDef(); testDef.name = "t"; testDef.argCountIsRemainderOfArgs = true; testDef.parseInit(ArgTypeParser.basicParsers); string[] testVals = new string[] { "what", "the", "french toast" }; VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString() }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); string[] result = pArgs.getArray<string>("t"); int i = 0; foreach (string val in result) { Assert.AreEqual<string>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values."); i++; } }
public void consumeTestOrderedEncounteredWrongType() { ArgDef testDef = new ArgDef(); testDef.name = "test"; testDef.type = typeof(int); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "a" }, 0, 1); ParsedArgs pArgs = new ParsedArgs(); bool result = testDef.consume(vArgs, pArgs); bool errors = testDef.errorOccured(); Assert.IsFalse(result, "[ArgDef][consume] consume should return false when the args provided don't match the arg def's type."); Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error when the args provided don't match the arg def's type."); }
public virtual void WriteToStream(string key, string lockHandle, VirtualArray vBuffer, int srcOffset, int dstOffset, int length, OperationContext operationContext) { }
public virtual ParsedArgs parseArgs(string[] args) { // setup stuff ParsedArgs pArgs = new ParsedArgs(); int orderedArgDefIx = 0; initArgDefs(); VirtualArray<string> vArgs = new VirtualArray<string>(args); // while (vArgs.length > 0) { bool argConsumed = false; for (int i = 0; !argConsumed && i < labeledArgDefs.Count; i++) { ArgDef def = labeledArgDefs[i]; argConsumed = def.consume(vArgs, pArgs); // test crap if (argConsumed) { Console.WriteLine(string.Format("[TEMP DEBUG] LArg '{0}' was consumed", def.name)); } // if (def.errorOccured()) { pArgs.addErrorMessages(def.getErrorMessages()); vArgs.moveStart(vArgs.endIndexExclusive); // this exits the outer while loop } } if (!argConsumed) { if (orderedArgDefIx >= orderedArgDefs.Count) { pArgs.addErrorMessage("Encountered more args than expected."); break; } ArgDef oDef = orderedArgDefs[orderedArgDefIx]; argConsumed = oDef.consume(vArgs, pArgs); orderedArgDefIx++; if (oDef.errorOccured()) { pArgs.addErrorMessages(oDef.getErrorMessages()); vArgs.moveStart(vArgs.endIndexExclusive); // this exits the outer while loop } else if (!argConsumed) { pArgs.addErrorMessage(string.Format("Unable to use arg '{0}'", vArgs[0])); vArgs.moveStart(vArgs.endIndexExclusive); // this exits the outer while loop } // test crap else { Console.WriteLine(string.Format("[Temp Debug] OArg '{0}' was consumed", oDef.name)); } // } } // end while if (pArgs.errorOccured()) { if (printErrorMessageOnInvalidArgs) { foreach (string message in pArgs.getErrorMessages()) { Console.WriteLine(message); } } if (printUsageOnInvalidArgs) { Console.WriteLine(getUsageString()); } } else { finishArgDefs(pArgs); } return pArgs; }
public void consumeTestNoVArgs() { ArgDef testDef = new ArgDef(); testDef.name = "test"; testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[]{}, 0, 0); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); }
public virtual int ReadFromStream(ref VirtualArray vBuffer, string key, string lockHandle, int offset, int length, OperationContext operationContext) { return(0); }
public void toListTest() { int[] ints = new int[] { 0, 1, 2, 4 }; VirtualArray<int> testArray = new VirtualArray<int>(ints); testArray.moveStartBy(1); testArray.moveEndBy(-1); List<int> result = testArray.toList(); Assert.AreEqual(2, result.Count, "[VirtualArray][toArray] Expected the result of toArray to have length 2"); Assert.AreEqual(1, result[0], "[VirtualArray][toArray] Encountered unexpected value in result of toArray."); Assert.AreEqual(2, result[1], "[VirtualArray][toArray] Encountered unexpected value in result of toArray."); }
public void setTest() { int[] ints = new int[3] { 0, 1, 2 }; VirtualArray<int> testArray = new VirtualArray<int>(ints); testArray[0] = -77; testArray[1] = -88; testArray[2] = -99; Assert.AreEqual(-77, testArray[0], string.Format("[VirtualArray][set] expected {0}, received {1}", -77, testArray[0])); Assert.AreEqual(-88, testArray[1], string.Format("[VirtualArray][set] expected {0}, received {1}", -88, testArray[1])); Assert.AreEqual(-99, testArray[2], string.Format("[VirtualArray][set] expected {0}, received {1}", -99, testArray[2])); testArray.moveStartBy(1); testArray[0] += 88; Assert.AreEqual(0, testArray[0], string.Format("[VirtualArray][set] expected {0}, received {1}", 0, testArray[0])); }
/// <summary> /// Only PBW is required to make a Portamento. /// If you provide empty on the others, we will use the default value: /// 0;(invalid) for pbs, 0 for pby, "" or s-curve for pbm /// If pbs does not have second parameter, it will be considered invalid as well. /// it is outside this class or USTNote's power to get information about previous notes, please read UST's constructor /// for its handling. /// </summary> /// <param name="pbs"></param> /// <param name="pbw"></param> /// <param name="pby"></param> /// <param name="pbm"></param> public Portamento(string pbw, string pbs, string pby, string pbm) { Segments = new List <PortamentoSegment>(); if (pbs == null || pbs.Trim().Length == 0) { Pbs = new[] { 0, double.NaN }; } else { if (!pbs.Contains(";")) //starting y is 0 { if (!pbs.Contains(",")) //don't you just love working with legendary code { Pbs = new[] { Convert.ToDouble(pbs), double.NaN } } ; else { Pbs = zusp.Split(pbs, ",").Select(s => Convert.ToDouble(s)).ToArray(); } } else { Pbs = zusp.Split(pbs, ";").Select(s => Convert.ToDouble(s)).ToArray(); } } var w = zusp.SplitAsIs(pbw, ",") .Select(s => s.Equals("") ? 0 : Convert.ToDouble(s)) //empty entries means 0. .ToList(); var y = zusp.SplitAsIs(pby, ",") .Select(s => s.Equals("") ? 0 : Convert.ToDouble(s)) //why though? i wonder. .ToList(); while (y.Count < w.Count - 1) { y.Add(0); //-1 because last point must be 0 as far as utau's concern, which is stupid. } var m = zusp.SplitAsIs(pbm, ",").ToList(); while (m.Count < w.Count) { m.Add(PbmSCurve); } //initialize segments for (var i = 0; i < w.Count - 1; i++) //last segment is a special case. { Segments.Add(new PortamentoSegment(w[i], y[i], m[i])); } Segments.Add(new PortamentoSegment(w[w.Count - 1], 0, m[w.Count - 1])); //now fill the virtual arrays. Pbw = new VirtualArray <double>(i => Segments[i].Pbw, (i, v) => Segments[i].Pbw = v, () => Segments.Count); Pby = new VirtualArray <double>(i => Segments[i].Pby, (i, v) => Segments[i].Pbw = v, () => Segments.Count - 1); Pbm = new VirtualArray <string>(i => Segments[i].Pbm, (i, v) => Segments[i].Pbm = v, () => Segments.Count); }
public void consumeTestListOfString() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.argCount = 5; testDef.parseInit(ArgTypeParser.basicParsers); string[] testVals = new string[] { "ok", "", "what ", "yeyeah", "turn down" }; VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString(), testVals[3].ToString(), testVals[4].ToString() }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); string[] result = pArgs.getArray<string>("t"); int i = 0; foreach (string val in result) { Assert.AreEqual<string>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values."); i++; } }
private bool isConsumeable(VirtualArray<string> vArgs) { if (vArgs.length <= 0) { throw new ArgDefException(string.Format("vArgs must have a length of at least 1. If you encounter this exception, something went wrong in ArgumentParser.parseArgs.")); } if (!isOrderedArg() && !labelMatch(vArgs[0])) { return false; // this isn't the arg we're looking for } if (++instanceCount > 1) { errorMessages.Add(string.Format("Encountered the option '{0}' more than once.", name)); return false; } if (!argCountIsRemainderOfArgs && vArgs.length < argCount + 1) { errorMessages.Add(string.Format("The option '{0}' expects {1} following arguments, only {2} were encountered.", name, argCount, vArgs.length - 1)); return false; } if (type != typeof(string)) { object dummyObj; if (isOrderedArg()) { if (!typeParsers[type].tryConvert(vArgs[0], out dummyObj)) { errorMessages.Add(string.Format("The '{0}' argument expects an argument of type '{1}', unable to parse '{2}'.", name, type, vArgs[0])); return false; } } else { int lastIx = argCount; if (argCountIsRemainderOfArgs) { lastIx = vArgs.length - 1; } for (int i = 1; i <= lastIx; i++) { if (!typeParsers[type].tryConvert(vArgs[i], out dummyObj)) { errorMessages.Add(string.Format("The '{0}' argument expects an argument of type '{1}', unable to parse '{2}'.", name, type, vArgs[i])); return false; } } } } return true; }
public void consumeTestListOfDouble() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.type = typeof(double); testDef.argCount = 3; testDef.parseInit(ArgTypeParser.basicParsers); double[] testVals = new double[] { -234.556, 0, 234234.234 }; VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString() }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); double[] result = pArgs.getArray<double>("t"); int i = 0; foreach (double val in result) { Assert.AreEqual<double>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values."); i++; } }
private object getValue(VirtualArray<string> vArgs) { if (argCount == 0 && !argCountIsRemainderOfArgs) { if (type == typeof(bool) && instanceCount > 0) { return true; } object val; typeParsers[type].tryConvert(vArgs[0], out val); return val; } int valOffset = -1; int startIx = 1; if (isOrderedArg()) { valOffset = 0; startIx = 0; } int lastIx = argCount; if (argCountIsRemainderOfArgs) { lastIx = vArgs.length - 1; } object[] vals = new object[lastIx + 1 + valOffset]; for (int i = startIx; i <= lastIx; i++) { object val; typeParsers[type].tryConvert(vArgs[i], out val); vals[i + valOffset] = val; } if (!createArrayForArgCount1 && vals.Length == 1) { return vals[0]; } return vals; }
public override int ReadFromStream(ref VirtualArray vBuffer, string key, string lockHandle, int offset, int length, OperationContext operationContext) { return(this.Internal.ReadFromStream(ref vBuffer, key, lockHandle, offset, length, operationContext)); }
public void consumeTestWrongNumberOfFollowingArgs() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-test"); testDef.argCount = 2; testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-test", "a" }, 0, 2); ParsedArgs pArgs = new ParsedArgs(); bool result = testDef.consume(vArgs, pArgs); bool errors = testDef.errorOccured(); Assert.IsFalse(result, "[ArgDef][consume] consume should return false when there are less remaining args than argCount."); Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error message when there are less remaining args than argCount."); }
public override void WriteToStream(string key, string lockHandle, VirtualArray vBuffer, int srcOffset, int dstOffset, int length, OperationContext operationContext) { this.Internal.WriteToStream(key, lockHandle, vBuffer, srcOffset, dstOffset, length, operationContext); }
public override void Write(VirtualArray vBuffer, int srcOffset, int dstOffset, int length) { throw new Exception("The method or operation is not implemented."); }
public void consumeTestLabeledDouble() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.type = typeof(double); testDef.argCount = 1; testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", "33.3" }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); Assert.AreEqual(33.3, pArgs.getValue<double>("t"), 0.01, "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); }
public void consumeTestOrderedInt() { ArgDef testDef = new ArgDef(); testDef.name = "test"; testDef.type = typeof(int); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "33" }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("test"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); Assert.AreEqual<int>(33, pArgs.getValue<int>("test"), "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered."); }