/// <summary> /// Inits XmpReader from media file. /// </summary> /// <exception cref="ArgumentNullException">File path provided is invalid: null or empty.</exception> /// <exception cref="InvalidOperationException">Initialization of handles failed in DLL.</exception> public static XmpReader InitFromMediaFile(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentNullException("filePath"); } XmpReader instance = new XmpReader(); string errorMsg = string.Empty; try { instance._xmpMetaHandle = GetMeta(filePath); } catch (Exception) { errorMsg = string.Format("Could not initialize XmpMeta from DLL for file {0}!", filePath); throw new InvalidOperationException(errorMsg); } if (instance._xmpMetaHandle == IntPtr.Zero) { errorMsg = string.Format("_xmpMetaHandle is <null> for file {0}!", filePath); throw new InvalidOperationException(errorMsg); } try { instance._xmpIteratorHandle = GetIterator(instance._xmpMetaHandle); } catch (Exception) { errorMsg = string.Format("Could not initialize XmpIterator from DLL for file {0}!", filePath); instance.Cleanup(); throw new InvalidOperationException(errorMsg); } if (instance._xmpIteratorHandle == IntPtr.Zero) { errorMsg = string.Format("_xmpIteratorHandle is <null> for file {0}!", filePath); instance.Cleanup(); throw new InvalidOperationException(errorMsg); } return(instance); }
/// <summary> /// Inits XmpReader from xml string. /// </summary> /// <exception cref="ArgumentNullException">XML string provided is invalid: null or empty.</exception> /// <exception cref="InvalidOperationException">Initialization of handles failed in DLL.</exception> public static XmpReader InitFromXml(string xml) { if (string.IsNullOrWhiteSpace(xml)) { throw new ArgumentNullException("xml"); } XmpReader instance = new XmpReader(); string errorMsg = string.Empty; try { instance._xmpMetaHandle = GetMetaFromXml(xml); } catch (Exception) { errorMsg = "Could not initialize XmpMeta from XML!"; throw new InvalidOperationException(errorMsg); } if (instance._xmpMetaHandle == IntPtr.Zero) { errorMsg = "_xmpMetaHandle is <null> for XML!"; throw new InvalidOperationException(errorMsg); } try { instance._xmpIteratorHandle = GetIterator(instance._xmpMetaHandle); } catch (Exception) { errorMsg = "Could not initialize XmpIterator from DLL XML!"; instance.Cleanup(); throw new InvalidOperationException(errorMsg); } if (instance._xmpIteratorHandle == IntPtr.Zero) { errorMsg = "_xmpIteratorHandle is <null> for XML!"; instance.Cleanup(); throw new InvalidOperationException(errorMsg); } return(instance); }