protected override void UnpackResponse() { base.UnpackResponse(); // Create the streams we will be reading from. var responseStream = new MemoryStream(m_responsePayload); var responseReader = new BinaryReader(responseStream, Encoding.Unicode); // Check the response length. if (responseStream.Length < MinResponseMessageLength) { throw new MessageWrongSizeException("Set Package Item"); } // Try to unpack the data. try { // Seek past return code. responseReader.BaseStream.Seek(sizeof(int), SeekOrigin.Begin); var count = responseReader.ReadInt16(); for (int i = 0; i < count; i++) { var id = responseReader.ReadInt32(); var nameLength = responseReader.ReadUInt16(); var name = new string(responseReader.ReadChars(nameLength)); var isDefault = responseReader.ReadBoolean(); var package = new PackageItem { PackageId = id, PackageName = name }; ValidationPackages.Add(package); if (isDefault) { DefaultValidationPackage = package; } } } catch (EndOfStreamException e) { throw new MessageWrongSizeException("Set Package Item", e); } catch (Exception e) { throw new ServerException("Set Package Item", e); } // Close the streams. responseReader.Close(); }
public void OnActionExecuting(ActionExecutingContext context) { foreach (string key in context.ActionArguments.Keys) { if (!context.ActionArguments[key].GetType().IsValueType) { IEnumerable <IBrokenRule> broke = ValidationPackages.Validate(context.ActionArguments[key]); if (broke.IsNotEmpty()) { context.Result = new BadRequestObjectResult(broke); } } } }
public IEnumerable <IBrokenRule> InvalidRules(bool recheck = true) { brokenRules(recheck).AddRange(ValidationPackages.Validate(this)); return(broke); }