private void FinishUriSchemeCallbackWithError(IntPtr request, int errorCode) { uint domain = GLib.GetFileErrorQuark(); var error = new GError(domain, errorCode, IntPtr.Zero); WebKit.UriScheme.FinishSchemeRequestWithError(request, ref error); }
private void FinishUriSchemeCallbackWithError(IntPtr request) { uint domain = GLib.GetFileErrorQuark(); var error = new GError(domain, 4, IntPtr.Zero); // error code 4 = not found WebKit.UriScheme.FinishSchemeRequestWithError(request, ref error); }
public void ReadFile(string data) { IntPtr error = IntPtr.Zero; IntPtr handle = IntPtr.Zero; try { handle = rsvg_handle_new_from_data(data, data.Length - 1, out error); } catch (Exception e) { throw e; } if (handle == IntPtr.Zero) { if (error != IntPtr.Zero) { GError errorstruct = (GError)Marshal.PtrToStructure(error, typeof(GError)); throw new Exception(errorstruct.message); } throw new Exception(); } else { _rsvgHandle = handle; } }
static byte[] ConvertToBytes(byte[] content, string toEncoding, string fromEncoding) { if (content.LongLength > int.MaxValue) { throw new Exception("Content too large."); } IntPtr nr = IntPtr.Zero, nw = IntPtr.Zero; IntPtr clPtr = new IntPtr(content.Length); IntPtr errptr = IntPtr.Zero; IntPtr cc = g_convert(content, clPtr, toEncoding, fromEncoding, ref nr, ref nw, ref errptr); if (cc != IntPtr.Zero) { //FIXME: check for out-of-range conversions on uints int len = (int)(uint)nw.ToInt64(); byte[] buf = new byte [len]; System.Runtime.InteropServices.Marshal.Copy(cc, buf, 0, buf.Length); g_free(cc); return(buf); } else { GError err = (GError)Marshal.PtrToStructure(errptr, typeof(GError)); string reason = Utf8PtrToString(err.Msg); string message = string.Format("Failed to convert content from {0} to {1}: {2}.", fromEncoding, toEncoding, reason); InvalidEncodingException ex = new InvalidEncodingException(message); g_error_free(errptr); throw ex; } }
public void Ctor_ShouldThrowWhenDirectoryNotFound() { var expected = new GError( 75, 4, "Failed to open file “/tmp/doesNotExists/gschemas.compiled”: open() failed: No such file or directory"); var ex = Assert.Throws <GSettingsSchemaSourceException>(() => new GSettingsSchemaSource("/tmp/doesNotExists", null, true)); Assert.Equal(expected.code, ex.Details.code); Assert.Equal(expected.domain, ex.Details.domain); Assert.Equal(expected.message, ex.Details.message); }
private void ClearCore() { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "Clearing adal cache"); bool cacheFileExists = File.Exists(CacheFilePath); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"ReadDataCore Cache file exists '{cacheFileExists}'"); TryProcessFile(() => { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "Before deleting the cache file"); try { File.Delete(CacheFilePath); } catch (Exception e) { _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, $"Problem deleting the cache file '{e}'"); } WriteVersionFile(); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"After deleting the cache file. Last write time is '{_lastVersionToken}'"); }); if (SharedUtilities.IsMacPlatform()) { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "Before delete mac keychain"); MacKeyChain.DeleteKey( CreationProperties.MacKeyChainServiceName, CreationProperties.MacKeyChainAccountName); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "After delete mac keychain"); } else if (SharedUtilities.IsLinuxPlatform()) { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"Before deletring secret from linux keyring"); IntPtr error = IntPtr.Zero; Libsecret.secret_password_clear_sync( schema: GetLibsecretSchema(), cancellable: IntPtr.Zero, error: out error, attribute1Type: CreationProperties.KeyringAttribute1.Key, attribute1Value: CreationProperties.KeyringAttribute1.Value, attribute2Type: CreationProperties.KeyringAttribute2.Key, attribute2Value: CreationProperties.KeyringAttribute2.Value, end: IntPtr.Zero); if (error != IntPtr.Zero) { try { GError err = (GError)Marshal.PtrToStructure(error, typeof(GError)); _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, $"An error was encountered while clearing secret from keyring in the {nameof(AdalCacheStorage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'"); } catch (Exception e) { _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, $"An exception was encountered while processing libsecret error information during clearing secret in the {nameof(AdalCacheStorage)} ex:'{e}'"); } } _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "After deleting secret from linux keyring"); } else if (!SharedUtilities.IsWindowsPlatform()) { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "Not supported platform"); throw new PlatformNotSupportedException(); } }
private void WriteDataCore(byte[] data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"Write Data core, goign to write '{data.Length}' to the storage"); if (SharedUtilities.IsMacPlatform() || SharedUtilities.IsLinuxPlatform()) { if (SharedUtilities.IsMacPlatform()) { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "Before write to mac keychain"); MacKeyChain.WriteKey( CreationProperties.MacKeyChainServiceName, CreationProperties.MacKeyChainAccountName, data); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "After write to mac keychain"); } else if (SharedUtilities.IsLinuxPlatform()) { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "Before saving to linux keyring"); IntPtr error = IntPtr.Zero; Libsecret.secret_password_store_sync( schema: GetLibsecretSchema(), collection: CreationProperties.KeyringCollection, label: CreationProperties.KeyringSecretLabel, password: Convert.ToBase64String(data), cancellable: IntPtr.Zero, error: out error, attribute1Type: CreationProperties.KeyringAttribute1.Key, attribute1Value: CreationProperties.KeyringAttribute1.Value, attribute2Type: CreationProperties.KeyringAttribute2.Key, attribute2Value: CreationProperties.KeyringAttribute2.Value, end: IntPtr.Zero); if (error != IntPtr.Zero) { try { GError err = (GError)Marshal.PtrToStructure(error, typeof(GError)); _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, $"An error was encountered while saving secret to keyring in the {nameof(AdalCacheStorage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'"); } catch (Exception e) { _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, $"An exception was encountered while processing libsecret error information during saving in the {nameof(AdalCacheStorage)} ex:'{e}'"); } } _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "After saving to linux keyring"); } // Change data to 1 byte so we can write it to the cache file to update the last write time using the same write code used for windows. data = new byte[] { 1 }; } string directoryForCacheFile = Path.GetDirectoryName(CacheFilePath); if (!Directory.Exists(directoryForCacheFile)) { string directory = Path.GetDirectoryName(CacheFilePath); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"Creating directory '{directory}'"); Directory.CreateDirectory(directory); } _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"Cache file directory exists. '{Directory.Exists(directoryForCacheFile)}' now writing cache file"); TryProcessFile(() => { File.WriteAllBytes(CacheFilePath, data); WriteVersionFile(); }); }
private byte[] ReadDataCore() { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "ReadDataCore"); byte[] fileData = null; bool cacheFileExists = File.Exists(CacheFilePath); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"ReadDataCore Cache file exists '{cacheFileExists}'"); if (SharedUtilities.IsWindowsPlatform()) { if (cacheFileExists) { TryProcessFile(() => { fileData = File.ReadAllBytes(CacheFilePath); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"ReadDataCore, read '{fileData.Length}' bytes from the file"); }); } } else if (SharedUtilities.IsMacPlatform()) { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"ReadDataCore, Before reading from mac keychain"); fileData = MacKeyChain.RetrieveKey(CreationProperties.MacKeyChainServiceName, CreationProperties.MacKeyChainAccountName, _logger); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"ReadDataCore, read '{fileData?.Length}' bytes from the keychain"); } else if (SharedUtilities.IsLinuxPlatform()) { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"ReadDataCore, Before reading from linux keyring"); IntPtr error = IntPtr.Zero; string secret = Libsecret.secret_password_lookup_sync( schema: GetLibsecretSchema(), cancellable: IntPtr.Zero, error: out error, attribute1Type: CreationProperties.KeyringAttribute1.Key, attribute1Value: CreationProperties.KeyringAttribute1.Value, attribute2Type: CreationProperties.KeyringAttribute2.Key, attribute2Value: CreationProperties.KeyringAttribute2.Value, end: IntPtr.Zero); if (error != IntPtr.Zero) { try { GError err = (GError)Marshal.PtrToStructure(error, typeof(GError)); _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, $"An error was encountered while reading secret from keyring in the {nameof(AdalCacheStorage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'"); } catch (Exception e) { _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, $"An exception was encountered while processing libsecret error information during reading in the {nameof(AdalCacheStorage)} ex:'{e}'"); } } else if (string.IsNullOrEmpty(secret)) { _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, "No matching secret found in the keyring"); } else { _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, "Base64 decoding the secret string"); fileData = Convert.FromBase64String(secret); _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"ReadDataCore, read '{fileData?.Length}' bytes from the keyring"); } } else { _logger.TraceEvent(TraceEventType.Error, /*id*/ 0, "Platform not supported"); throw new PlatformNotSupportedException(); } return(fileData); }
public static extern void FinishSchemeRequestWithError(IntPtr request, ref GError error);
public GSettingsSchemaSourceException(string message, GError details, Exception innerException) : base(message, innerException) { Details = details; }
static extern IntPtr rsvg_handle_new_from_data(byte[] data, int len, out GError error);
static extern IntPtr rsvg_handle_new_from_file(string file_name, out GError error);