public static FinderToken DeserializeFromString(string serialized) { var parts = serialized.Split("--"); return(new FinderToken( EnumUtils.CastSafe <Interface>(parts[0].ParseToInt32Invariant()), EnumUtils.CastSafe <Implementation>(parts[1].ParseToInt32Invariant()), parts[2].ParseToInt32Invariant())); }
public async Task <(ActivationLinkArguments Data, TokenValidity Validity)> ParseAsync(string token) { return(await parseAsync(token, (reader, header) => { var action = EnumUtils.CastSafe <ActivationLinkAction>(reader.ReadByte()); return Task.FromResult(new ActivationLinkArguments(header.ProvderOrTarget, action)); })); }
public async Task <(ConfirmationToken Data, TokenValidity Validity)> ParseAsync(string token) { return(await parseAsync(token, async (reader, data) => { var operation = EnumUtils.CastSafe <AccountOperation>(reader.ReadByte()); var argument = reader.ReadString(); return await Task.FromResult <ConfirmationToken>(new ConfirmationToken(data.ProvderOrTarget, operation, argument)); })); }
public async Task <string> GenerateLink([Required] int actionRaw) { if (ModelState.IsValid) { var action = EnumUtils.CastSafe <ActivationLinkAction>(actionRaw); await S.Permissions.ValidateGenerateActivationLinkAsync(action); var currenUser = await S.Utilities.GetCurrentUserModelOrThrowAsync(); return(await S.ActivationLinks.GenerateLink(currenUser, action)); } else { throw new Exception(); } }
protected override object deserializeFromString(DataEntityFormat format, string serialized) { switch (format) { case DataEntityFormat.CALIBRATION_PACKET_ENTITIES_ARRAY: { var entities = serialized.Split(Global.NL); return(parseEntities().ToArray()); IEnumerable <CalibrationFileEntity> parseEntities() { foreach (var entity in entities) { var nameString = entity.Between("\"", "\"", false, false); var next = entity.Skip(entity.Find(nameString).Index + nameString.Length); var itemTypeString = next .SkipWhile(c => !char.IsDigit(c)) .TakeWhile(char.IsDigit).Aggregate(); next = next.Skip(next.Find(itemTypeString).Index + itemTypeString.Length); var dataTypeString = next .SkipWhile(c => !char.IsDigit(c)) .TakeWhile(char.IsDigit).Aggregate(); next = next.Skip(next.Find(dataTypeString).Index + dataTypeString.Length); var dataString = next .SkipWhile(c => c != '=') .Skip(1) .SkipWhile(c => c == '"') .TakeWhile(c => c != '"') .Aggregate(); var name = nameString; var itemType = EnumUtils.CastSafe <ItemTypes>(itemTypeString.ParseToInt8Invariant()); var dataType = EnumUtils.CastSafe <DataTypes>(dataTypeString.ParseToInt8Invariant()); var data = parseData(); yield return(new CalibrationFileEntity(name, itemType, dataType, data)); object parseData() { switch (dataType) { case DataTypes.FLOAT: return(dataString.Split(" ").Select(v => v.ParseToSingleInvariant()).ToArray()); case DataTypes.UINT16: return(dataString.Split(" ").Select(v => v.ParseToUInt16Invariant()).ToArray()); case DataTypes.INT16: return(dataString.Split(" ").Select(v => v.ParseToInt16Invariant()).ToArray()); case DataTypes.INT8: return(dataString.Split(" ").Select(v => v.ParseToInt8Invariant()).ToArray()); case DataTypes.STRING_CP1251: return(dataString); default: throw new NotSupportedException(); } } } } } default: throw new NotSupportedException(); } }