/// <summary> /// Read floating point number from stream. /// </summary> public float?ReadSingle ( [NotNull] IFormatProvider provider ) { Sure.NotNull(provider, nameof(provider)); if (!SkipWhitespace()) { return(null); } StringBuilder result = _ReadNumber(); return(float.Parse ( result.ToString(), provider )); }
/// <summary> /// Read fixed point number from stream. /// </summary> public decimal?ReadDecimal ( [NotNull] IFormatProvider provider ) { Sure.NotNull(provider, nameof(provider)); if (!SkipWhitespace()) { return(null); } StringBuilder result = _ReadNumber(); return(decimal.Parse ( result.ToString(), provider )); }
public static MenuFile ReadFromServer ( [NotNull] IIrbisConnection connection, [NotNull] FileSpecification fileSpecification ) { Sure.NotNull(connection, nameof(connection)); Sure.NotNull(fileSpecification, nameof(fileSpecification)); string response = connection.ReadTextFile(fileSpecification); if (string.IsNullOrEmpty(response)) { return(null); } MenuFile result = ParseServerResponse(response); return(result); }
/// <inheritdoc cref="IHandmadeSerializable.SaveToStream" /> public void SaveToStream ( BinaryWriter writer ) { Sure.NotNull(writer, nameof(writer)); writer.Write(Actualize); writer.Write(Autoin); writer.WriteNullable(Database); writer.WriteNullable(FileName); writer.WritePackedInt32(FirstRecord); writer.Write(FormalControl); writer.WritePackedInt32(MaxMfn); writer.WriteNullableArray(MfnList); writer.WritePackedInt32(MinMfn); writer.WritePackedInt32(NumberOfRecords); writer.WriteNullable(SearchExpression); writer.Write(Statements); }
public static List <T> ReadList <T> ( [NotNull] this BinaryReader reader ) where T : IHandmadeSerializable, new() { Sure.NotNull(reader, nameof(reader)); int count = reader.ReadPackedInt32(); List <T> result = new List <T>(count); for (int i = 0; i < count; i++) { T item = new T(); item.RestoreFromStream(reader); result.Add(item); } return(result); }
/// <inheritdoc cref="IHandmadeSerializable.RestoreFromStream" /> public void RestoreFromStream ( BinaryReader reader ) { Sure.NotNull(reader, "reader"); Name = reader.ReadNullableString(); Description = reader.ReadNullableString(); MaxMfn = reader.ReadPackedInt32(); LogicallyDeletedRecords = reader.ReadNullableInt32Array(); PhysicallyDeletedRecords = reader.ReadNullableInt32Array(); NonActualizedRecords = reader.ReadNullableInt32Array(); LockedRecords = reader.ReadNullableInt32Array(); DatabaseLocked = reader.ReadBoolean(); }
public static bool ContainsValue <TSource> ( [NotNull] this IEnumerable <TSource> source, TSource value, [NotNull] IEqualityComparer <TSource> comparer ) { Sure.NotNull(source, nameof(source)); Sure.NotNull(comparer, nameof(comparer)); foreach (TSource local in source) { if (comparer.Equals(local, value)) { return(true); } } return(false); }
/// <summary> /// Read array from stream /// </summary> public static T[] ReadArray <T> ( [NotNull] this BinaryReader reader ) where T : IHandmadeSerializable, new() { Sure.NotNull(reader, nameof(reader)); int count = reader.ReadPackedInt32(); T[] result = new T[count]; for (int i = 0; i < count; i++) { T item = new T(); item.RestoreFromStream(reader); result[i] = item; } return(result); }
public static BinaryWriter Write ( [NotNull] this BinaryWriter writer, [CanBeNull] short?value ) { Sure.NotNull(writer, nameof(writer)); if (value != null) { writer.Write(true); writer.Write(value.Value); } else { writer.Write(false); } return(writer); }
public static SubField[] GetSubField ( [NotNull] this IEnumerable <SubField> subFields, [CanBeNull] Action <SubField> action ) { Sure.NotNull(subFields, "subFields"); SubField[] result = subFields.NonNullItems().ToArray(); if (!ReferenceEquals(action, null)) { foreach (SubField subField in result) { action(subField); } } return(result); }
public static string[] ReadNullableStringArray ( [NotNull] this BinaryReader reader ) { Sure.NotNull(reader, nameof(reader)); string[] result = null; if (reader.ReadBoolean()) { int count = reader.ReadPackedInt32(); result = new string[count]; for (int i = 0; i < count; i++) { result[i] = reader.ReadString(); } } return(result); }
/// <summary> /// Constructor. /// </summary> public ByteNavigator ( [NotNull] byte[] data, int length, [NotNull] Encoding encoding ) { Sure.NotNull(data, nameof(data)); Sure.NonNegative(length, nameof(length)); Sure.NotNull(encoding, nameof(encoding)); if (length > data.Length) { length = data.Length; } _data = data; Length = length; Encoding = encoding; }
public static void Include ( [NotNull] JObject obj, [NotNull] Action <JProperty> resolver ) { Sure.NotNull(obj, nameof(obj)); Sure.NotNull(resolver, nameof(resolver)); JValue[] values = obj .SelectTokens("$..$include") .OfType <JValue>() .ToArray(); foreach (JValue value in values) { JProperty property = (JProperty)value.Parent; resolver(property); } }
public string[] GetFileText ( [NotNull] ServerResponse response ) { Sure.NotNull(response, nameof(response)); int count = Files.Count; string[] result = new string[count]; for (int i = 0; i < count; i++) { string text = response.GetAnsiString(); text = IrbisText.IrbisToWindows(text); result[i] = text; } return(result); }
public static byte[] Compress ( [NotNull] byte[] data ) { Sure.NotNull(data, nameof(data)); MemoryStream memory = new MemoryStream(); using (DeflateStream compressor = new DeflateStream ( memory, CompressionMode.Compress )) { compressor.Write(data, 0, data.Length); } return(memory.ToArray()); }
public static GblFile ParseLocalFile ( [NotNull] string fileName, [NotNull] Encoding encoding ) { Sure.NotNull(fileName, "fileName"); Sure.NotNull(encoding, "encoding"); using (StreamReader reader = TextReaderUtility.OpenRead ( fileName, encoding )) { GblFile result = ParseStream(reader); return(result); } }
public static string ChangeEncoding ( [CanBeNull] string text, [NotNull] Encoding fromEncoding, [NotNull] Encoding toEncoding ) { Sure.NotNull(fromEncoding, nameof(fromEncoding)); Sure.NotNull(toEncoding, nameof(toEncoding)); if (string.IsNullOrEmpty(text)) { return(text); } byte[] bytes = toEncoding.GetBytes(text); string result = fromEncoding.GetString(bytes); return(result); }
/// <inheritdoc cref="IHandmadeSerializable.RestoreFromStream" /> public void RestoreFromStream ( BinaryReader reader ) { Sure.NotNull(reader, nameof(reader)); Name = reader.ReadNullableString(); Prefix = reader.ReadNullableString(); DictionaryType = (DictionaryType)reader.ReadPackedInt32(); MenuName = reader.ReadNullableString(); OldFormat = reader.ReadNullableString(); Correction = reader.ReadNullableString(); Hint = reader.ReadNullableString(); ModByDicAuto = reader.ReadNullableString(); Logic = (SearchLogicType)reader.ReadPackedInt32(); Advance = reader.ReadNullableString(); Format = reader.ReadNullableString(); Truncation = reader.ReadBoolean(); }
public static AbstractClientSocket CreateSocket ( [NotNull] IrbisConnection connection, [NotNull] string typeName ) { Sure.NotNull(connection, nameof(connection)); Sure.NotNullNorEmpty(typeName, nameof(typeName)); Type type = Type.GetType(typeName, true).ThrowIfNull("Type.GetType"); AbstractClientSocket result = (AbstractClientSocket)Activator.CreateInstance ( type, connection ); connection.SetSocket(result); return(result); }
/// <inheritdoc cref="IHandmadeSerializable.RestoreFromStream" /> public void RestoreFromStream ( BinaryReader reader ) { Sure.NotNull(reader, nameof(reader)); Actualize = reader.ReadBoolean(); Autoin = reader.ReadBoolean(); Database = reader.ReadNullableString(); FileName = reader.ReadNullableString(); FirstRecord = reader.ReadPackedInt32(); FormalControl = reader.ReadBoolean(); MaxMfn = reader.ReadPackedInt32(); MfnList = reader.ReadNullableInt32Array(); MinMfn = reader.ReadPackedInt32(); NumberOfRecords = reader.ReadPackedInt32(); SearchExpression = reader.ReadNullableString(); Statements = reader.ReadNonNullCollection <GblStatement>(); }
public static SubField GetFirstSubField ( [NotNull] this IEnumerable <SubField> subFields, char code, [CanBeNull] string value ) { Sure.NotNull(subFields, "subFields"); foreach (SubField subField in subFields.NonNullItems()) { if (subField.Code.SameChar(code) && subField.Value.SameStringSensitive(value)) { return(subField); } } return(null); }
public static SubField GetFirstSubField ( [NotNull] this SubFieldCollection subFields, params char[] codes ) { Sure.NotNull(subFields, "subFields"); int count = subFields.Count; for (int i = 0; i < count; i++) { if (subFields[i].Code.OneOf(codes)) { return(subFields[i]); } } return(null); }
public static string EncodeStatements ( [NotNull] GblStatement[] statements ) { Sure.NotNull(statements, "statements"); StringBuilder result = new StringBuilder(); result.Append("!0"); result.Append(GblStatement.Delimiter); foreach (GblStatement item in statements) { result.Append(item.EncodeForProtocol()); } result.Append(GblStatement.Delimiter); return(result.ToString()); }
public static IEnumerable <string> WholeDatabase ( [NotNull] IIrbisConnection connection, [NotNull] string database, [NotNull] string format, int batchSize ) { Sure.NotNull(connection, "connection"); Sure.NotNullNorEmpty(database, "database"); Sure.NotNullNorEmpty(format, "format"); if (batchSize < 1) { Log.Error ( "BatchRecordFormatter::WholeDatabase: " + "batchSize=" + batchSize ); throw new ArgumentOutOfRangeException("batchSize"); } int maxMfn = connection.GetMaxMfn(database) - 1; if (maxMfn == 0) { return(new string[0]); } BatchRecordFormatter result = new BatchRecordFormatter ( connection, database, format, batchSize, Enumerable.Range(1, maxMfn) ); return(result); }
/// <inheritdoc cref="AbstractClientSocket.ExecuteRequest"/> public override byte[] ExecuteRequest ( byte[] request ) { Sure.NotNull(request, "request"); IrbisConnection connection = Connection as IrbisConnection; if (!ReferenceEquals(connection, null)) { connection.RawClientRequest = request; } _ResolveHostAddress(Connection.Host); using (new BusyGuard(Busy)) { using (TcpClient client = _GetTcpClient()) { Socket socket = client.Client; socket.Send(request); MemoryStream stream = Connection.Executive .GetMemoryStream(GetType()); byte[] result = socket.ReceiveToEnd(stream); Connection.Executive.ReportMemoryUsage ( GetType(), result.Length ); if (!ReferenceEquals(connection, null)) { connection.RawServerResponse = result; } return(result); } } }
/// <summary> /// Сохранение в поток обнуляемого объекта. /// </summary> public static BinaryWriter WriteNullable <T> ( [NotNull] this BinaryWriter writer, [CanBeNull] T obj ) where T : class, IHandmadeSerializable, new() { Sure.NotNull(writer, nameof(writer)); if (ReferenceEquals(obj, null)) { writer.Write(false); } else { writer.Write(true); obj.SaveToStream(writer); } return(writer); }
/// <summary> /// Сохранение в файл массива объектов /// с одновременной упаковкой. /// </summary> public static void SaveToZipFile <T> ( [NotNull][ItemNotNull] this T[] array, [NotNull] string fileName ) where T : IHandmadeSerializable, new() { Sure.NotNull(array, nameof(array)); Sure.NotNullNorEmpty(fileName, nameof(fileName)); using (Stream stream = File.Create(fileName)) using (DeflateStream deflate = new DeflateStream ( stream, CompressionMode.Compress )) using (BinaryWriter writer = new BinaryWriter(deflate)) { writer.WriteArray(array); } }
public static T RestoreNullable <T> ( [NotNull] this BinaryReader reader ) where T : class, IHandmadeSerializable, new() { Sure.NotNull(reader, nameof(reader)); bool isNull = !reader.ReadBoolean(); if (isNull) { return(null); } T result = new T(); result.RestoreFromStream(reader); return(result); }
/// <summary> /// Сохранение в файл объекта, /// умеющего сериализоваться вручную. /// </summary> public static void SaveToZipFile <T> ( [NotNull] this T obj, [NotNull] string fileName ) where T : class, IHandmadeSerializable, new() { Sure.NotNull(obj, nameof(obj)); Sure.NotNullNorEmpty(fileName, nameof(fileName)); using (Stream stream = File.Create(fileName)) using (DeflateStream deflate = new DeflateStream ( stream, CompressionMode.Compress )) using (BinaryWriter writer = new BinaryWriter(deflate)) { obj.SaveToStream(writer); } }
public static IrbisTreeFile ReadLocalFile ( [NotNull] string fileName, [NotNull] Encoding encoding ) { Sure.NotNullNorEmpty(fileName, "fileName"); Sure.NotNull(encoding, "encoding"); using (StreamReader reader = TextReaderUtility.OpenRead ( fileName, encoding )) { IrbisTreeFile result = ParseStream(reader); result.FileName = Path.GetFileName(fileName); return(result); } }