/// <summary> /// Set property value either public or private. /// </summary> public static void SetPropertyValue <TTarget, TValue> ( TTarget target, [NotNull] string propertyName, TValue value ) { Sure.NotNullNorEmpty(propertyName, nameof(propertyName)); PropertyInfo propertyInfo = typeof(TTarget).GetProperty ( propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static ); if (ReferenceEquals(propertyInfo, null)) { Log.Error ( nameof(ReflectionUtility) + "::" + nameof(SetPropertyValue) + ": can't find property=" + propertyName ); throw new ArgumentException(propertyName); } propertyInfo.SetValue(target, value, null); }
private void _ResolveHostAddress ( string host ) { Sure.NotNullNorEmpty(host, nameof(host)); if (ReferenceEquals(_address, null)) { _address = SocketUtility.ResolveAddressIPv4(host); if (_address.AddressFamily != AddressFamily.InterNetwork) { throw new IrbisNetworkException ( "Address must be IPv4 only!" ); } } //if (ReferenceEquals(_address, null)) //{ // throw new IrbisNetworkException // ( // "Can't resolve host " + host // ); //} }
public static RawRecord ParseMfnStatusVersion ( [NotNull] string line1, [NotNull] string line2, [NotNull] RawRecord record ) { Sure.NotNullNorEmpty(line1, nameof(line1)); Sure.NotNullNorEmpty(line2, nameof(line2)); Sure.NotNull(record, nameof(record)); Regex regex = new Regex(@"^(-?\d+)\#(\d*)?"); Match match = regex.Match(line1); record.Mfn = Math.Abs(int.Parse(match.Groups[1].Value)); if (match.Groups[2].Length > 0) { record.Status = (RecordStatus)int.Parse ( match.Groups[2].Value ); } match = regex.Match(line2); if (match.Groups[2].Length > 0) { record.Version = int.Parse(match.Groups[2].Value); } return(record); }
///// <summary> ///// Gets the custom attribute. ///// </summary> //[CanBeNull] //public static T GetCustomAttribute<T> // ( // [NotNull] PropertyDescriptor propertyDescriptor // ) // where T : Attribute //{ // return (T)propertyDescriptor.Attributes[typeof(T)]; //} ///// <summary> ///// Get default constructor for given type. ///// </summary> ///// <param name="type"></param> ///// <returns></returns> //public static ConstructorInfo GetDefaultConstructor // ( // [NotNull] Type type // ) //{ // ConstructorInfo result = type.GetConstructor // ( // BindingFlags.Instance | BindingFlags.Public, // null, // Type.EmptyTypes, // null // ); // return result; //} /// <summary> /// Get field value either public or private. /// </summary> public static object GetFieldValue <T> ( T target, [NotNull] string fieldName ) { Sure.NotNullNorEmpty(fieldName, nameof(fieldName)); FieldInfo fieldInfo = typeof(T).GetField ( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static ); if (ReferenceEquals(fieldInfo, null)) { Log.Error ( nameof(ReflectionUtility) + "::" + nameof(GetFieldValue) + ": can't find field=" + fieldName ); throw new ArgumentException(fieldName); } return(fieldInfo.GetValue(target)); }
public static RecordField ParseLine ( [NotNull] string line ) { Sure.NotNullNorEmpty(line, "line"); StringReader reader = new StringReader(line); RecordField result = new RecordField { Tag = NumericUtility.ParseInt32(_ReadTo(reader, '#')), Value = _ReadTo(reader, '^') }; while (true) { int next = reader.Read(); if (next < 0) { break; } char code = char.ToLower((char)next); string text = _ReadTo(reader, '^'); SubField subField = new SubField { Code = code, Value = text }; result.SubFields.Add(subField); } return(result); }
public static T[] ThrowIfNullOrEmpty <T> ( [CanBeNull] this T[] array, [NotNull] string message ) { Sure.NotNullNorEmpty(message, nameof(message)); if (ReferenceEquals(array, null)) { Log.Error ( nameof(ListUtility) + "::" + nameof(ThrowIfNullOrEmpty) + ": " + "array is null" ); throw new ArgumentNullException(message); } if (array.Length == 0) { Log.Error ( nameof(ListUtility) + "::" + nameof(ThrowIfNullOrEmpty) + ": " + "array is empty" ); throw new ArgumentException(message); } return(array); }
public static IList <T> ThrowIfNullOrEmpty <T> ( [CanBeNull] this IList <T> list, [NotNull] string message ) { Sure.NotNullNorEmpty(message, nameof(message)); if (ReferenceEquals(list, null)) { Log.Error ( nameof(ListUtility) + "::" + nameof(ThrowIfNullOrEmpty) + ": " + "list is null" ); throw new ArgumentNullException(message); } if (list.Count == 0) { Log.Error ( nameof(ListUtility) + "::" + nameof(ThrowIfNullOrEmpty) + ": " + "list is empty" ); throw new ArgumentException(message); } return(list); }
/// <summary> /// Saves <see cref="GblFile"/> to local JSON file. /// </summary> public static void SaveLocalJsonFile ( [NotNull] this GblFile gbl, [NotNull] string fileName ) { Sure.NotNull(gbl, "gbl"); Sure.NotNullNorEmpty(fileName, "fileName"); #if WINMOBILE || PocketPC Log.Error ( "GblUtility::SaveLocalJsonFile: " + "not implemented" ); throw new NotImplementedException(); #else string contents = JArray.FromObject(gbl) .ToString(Formatting.Indented); File.WriteAllText ( fileName, contents, IrbisEncoding.Utf8 ); #endif }
public static ProtocolLine Parse ( [NotNull] string line ) { Sure.NotNullNorEmpty(line, line); ProtocolLine result = new ProtocolLine { Text = line, Success = true }; string[] parts = line.Split('#'); foreach (string part in parts) { string[] p = part.Split('='); if (p.Length > 0) { string name = p[0].ToUpper(); string value = string.Empty; if (p.Length > 1) { value = p[1]; } switch (name) { case "DBN": result.Database = value; break; case "MFN": result.Mfn = value.SafeToInt32(); break; case "AUTOIN": result.Autoin = value; break; case "UPDATE": result.Update = value; break; case "STATUS": result.Status = value; break; case "UPDUF": result.UpdUf = value; break; case "GBL_ERROR": result.Error = value; result.Success = false; break; } } } return(result); }
/// <summary> /// Constructor. /// </summary> public BatchRecordFormatter ( [NotNull] string connectionString, [NotNull] string database, [NotNull] string format, int batchSize, [NotNull] IEnumerable <int> range ) { Sure.NotNullNorEmpty(connectionString, "connectionString"); Sure.NotNullNorEmpty(database, "database"); Sure.NotNullNorEmpty(format, "format"); Sure.NotNull(range, "range"); if (batchSize < 1) { Log.Error ( "BatchRecordFormatter::Constructor: " + "batchSize=" + batchSize ); throw new ArgumentOutOfRangeException("batchSize"); } Connection = ConnectionFactory.CreateConnection(connectionString); _ownConnection = true; Database = database; BatchSize = batchSize; Format = format; _packages = range.Slice(batchSize).ToArray(); TotalRecords = _packages.Sum(p => p.Length); }
public static GblFile ParseLocalXmlFile ( [NotNull] string fileName ) { Sure.NotNullNorEmpty(fileName, "fileName"); #if WINMOBILE || PocketPC Log.Error ( "GblUtility::ParseLocalXmlFile: " + "not implemented" ); throw new NotImplementedException(); #else string text = File.ReadAllText ( fileName, IrbisEncoding.Utf8 ); GblFile result = FromXml(text); return(result); #endif }
public static void ExpandTypes ( [NotNull] JObject obj, [NotNull] string nameSpace, [NotNull] string assembly ) { Sure.NotNull(obj, nameof(obj)); Sure.NotNullNorEmpty(nameSpace, nameof(nameSpace)); Sure.NotNullNorEmpty(assembly, nameof(assembly)); IEnumerable <JValue> values = obj .SelectTokens("$..$type") .OfType <JValue>(); foreach (JValue value in values) { string typeName = value.Value.ToString(); if (!typeName.Contains('.')) { typeName = nameSpace + "." + typeName + ", " + assembly; value.Value = typeName; } } }
public static IrbisUpperCaseTable ParseText ( [NotNull] Encoding encoding, [NotNull] string text ) { Sure.NotNull(encoding, "encoding"); Sure.NotNullNorEmpty(text, "text"); List <byte> table = new List <byte>(256); MatchCollection matches = Regex.Matches(text, @"\d+"); foreach (Match match in matches) { byte b = byte.Parse(match.Value); table.Add(b); } IrbisUpperCaseTable result = new IrbisUpperCaseTable ( encoding, table.ToArray() ); return(result); }
public static MarcRecord[] ParseAllFormat ( [NotNull] string database, [NotNull] IIrbisConnection connection, [NotNull] string[] lines ) { Sure.NotNullNorEmpty(database, "database"); Sure.NotNull(connection, "connection"); Sure.NotNull(lines, "lines"); List <MarcRecord> result = new List <MarcRecord>(); foreach (string line in lines) { MarcRecord record = new MarcRecord { HostName = connection.Host, Database = database }; record = ProtocolText.ParseResponseForAllFormat ( line, record ); // coverity[NULL_RETURNS] result.Add(record.ThrowIfNull("record")); } return(result.ToArray()); }
public static MarcRecord[] ParseAllFormat ( [NotNull] string database, [NotNull] ServerResponse response ) { Sure.NotNullNorEmpty(database, "database"); Sure.NotNull(response, "response"); List <MarcRecord> result = new List <MarcRecord>(); while (true) { MarcRecord record = new MarcRecord { HostName = response.Connection.Host, Database = database }; record = ProtocolText.ParseResponseForAllFormat ( response, record ); if (ReferenceEquals(record, null)) { break; } result.Add(record); } return(result.ToArray()); }
/// <summary> /// Set field value either public or private. /// </summary> public static void SetFieldValue <TTarget, TValue> ( TTarget target, [NotNull] string fieldName, TValue value ) where TTarget : class { Sure.NotNullNorEmpty(fieldName, nameof(fieldName)); FieldInfo fieldInfo = typeof(TTarget).GetField ( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static ); if (ReferenceEquals(fieldInfo, null)) { Log.Error ( nameof(ReflectionUtility) + "::" + nameof(SetFieldValue) + ": can't find field=" + fieldName ); throw new ArgumentException(fieldName); } fieldInfo.SetValue(target, value); }
/// <summary> /// Constructor. /// </summary> public FileLogger ( [NotNull] string fileName ) { Sure.NotNullNorEmpty(fileName, nameof(fileName)); FileName = fileName; }
/// <summary> /// Конструктор /// </summary> public IrbisDate ( [NotNull] string text ) { Sure.NotNullNorEmpty(text, "text"); Text = text; Date = ConvertStringToDate(text); }
/// <summary> /// Initializes a new instance of the /// <see cref="UnmanagedLibrary"/> class. /// </summary> /// <param name="name">The name.</param> public UnmanagedLibrary ( [NotNull] string name ) { Sure.NotNullNorEmpty(name, nameof(name)); Name = name; Handle = new SafeLibraryHandle(Kernel32.LoadLibrary(name)); }
/// <summary> /// Restore subfield from JSON. /// </summary> public static SubField FromJson ( [NotNull] string text ) { Sure.NotNullNorEmpty(text, "text"); SubField result = JsonConvert.DeserializeObject <SubField>(text); return(result); }
public GblSettings SetFileName ( [NotNull] string fileName ) { Sure.NotNullNorEmpty(fileName, nameof(fileName)); FileName = fileName; return(this); }
/// <summary> /// Constructor. /// </summary> public UniversalCommand ( [NotNull] IIrbisConnection connection, [NotNull] string commandCode ) : base(connection) { Sure.NotNullNorEmpty(commandCode, "commandCode"); CommandCode = commandCode; }
/// <summary> /// Save references to the archive file. /// </summary> public static void SaveToZipFile ( [NotNull][ItemNotNull] RecordReference[] references, [NotNull] string fileName ) { Sure.NotNull(references, "references"); Sure.NotNullNorEmpty(fileName, "fileName"); references.SaveToFile(fileName); }
/// <summary> /// Constructor. /// </summary> public FileSpecification ( IrbisPath path, [NotNull] string fileName ) { Sure.NotNullNorEmpty(fileName, nameof(fileName)); Path = path; FileName = fileName; }
public GblSettings SetSearchExpression ( [NotNull] string searchExpression ) { Sure.NotNullNorEmpty(searchExpression, nameof(searchExpression)); SearchExpression = searchExpression; return(this); }
public static Encoding FromConfig ( [NotNull] string key ) { Sure.NotNullNorEmpty(key, nameof(key)); string name = CM.AppSettings[key]; Encoding result = ByName(name); return(result); }
public static MenuFile ParseServerResponse ( [NotNull] string response ) { Sure.NotNullNorEmpty(response, nameof(response)); TextReader reader = new StringReader(response); MenuFile result = ParseStream(reader); return(result); }
/// <summary> /// Deserialize the string. /// </summary> public static T DeserializeString <T> ( [NotNull] string xmlText ) { Sure.NotNullNorEmpty(xmlText, "xmlText"); StringReader reader = new StringReader(xmlText); XmlSerializer serializer = new XmlSerializer(typeof(T)); return((T)serializer.Deserialize(reader)); }
public static ByteNavigator FromFile ( [NotNull] string fileName ) { Sure.NotNullNorEmpty(fileName, nameof(fileName)); byte[] data = File.ReadAllBytes(fileName); ByteNavigator result = new ByteNavigator(data); return(result); }
public static JObject ReadObjectFromFile ( [NotNull] string fileName ) { Sure.NotNullNorEmpty(fileName, nameof(fileName)); string text = File.ReadAllText(fileName); JObject result = JObject.Parse(text); return(result); }