private static void CreateHelper(string path) { using (var pin = new PinCollection()) { NativeCommon.FabricDirectoryCreate(pin.AddBlittable(path)); } }
public static IntPtr CreateCounterSet(FabricPerformanceCounterSetDefinition counterSetDefinition, IEnumerable <FabricPerformanceCounterDefinition> counters) { IntPtr counterSetHandle = IntPtr.Zero; #if !DotNetCoreClrLinux NativeTypes.FABRIC_COUNTER_SET_INITIALIZER nativeCounterSet = new NativeTypes.FABRIC_COUNTER_SET_INITIALIZER(); using (var pin = new PinCollection()) { nativeCounterSet.CounterSetId = pin.AddBlittable(counterSetDefinition.Guid.ToString()); nativeCounterSet.CounterSetName = pin.AddBlittable(counterSetDefinition.Name); nativeCounterSet.CounterSetDescription = pin.AddBlittable(counterSetDefinition.Description); nativeCounterSet.CounterSetInstanceType = (UInt32)counterSetDefinition.CategoryType; nativeCounterSet.NumCountersInSet = (UInt32)counters.Count(); var nativeCounters = new NativeTypes.FABRIC_COUNTER_INITIALIZER[counters.Count()]; int index = 0; foreach (FabricPerformanceCounterDefinition ctr in counters) { nativeCounters[index].CounterId = (UInt32)ctr.Id; nativeCounters[index].BaseCounterId = (UInt32)ctr.BaseId; nativeCounters[index].CounterType = (UInt32)ctr.CounterType; nativeCounters[index].CounterName = pin.AddBlittable(ctr.Name); nativeCounters[index].CounterDescription = pin.AddBlittable(ctr.Description); index++; } nativeCounterSet.Counters = pin.AddBlittable(nativeCounters); Utility.WrapNativeSyncInvokeInMTA(() => { NativeCommon.FabricPerfCounterCreateCounterSet(pin.AddBlittable(nativeCounterSet), out counterSetHandle); }, "PerformanceCountersInterop.CreateCounterSet"); } #endif return(counterSetHandle); }
private static string GetFullPathHelper(string path) { using (var pin = new PinCollection()) { return(StringResult.FromNative(NativeCommon.FabricGetFullPath(pin.AddBlittable(path)))); } }
private static string GetVersionInfoHelper(string path) { using (var pin = new PinCollection()) { return(StringResult.FromNative(NativeCommon.FabricFileGetVersionInfo(pin.AddBlittable(path)))); } }
static unsafe SharedRealmHandleExtensions() { NativeCommon.Initialize(); NativeMethods.RefreshAccessTokenCallbackDelegate refresh = RefreshAccessTokenCallback; NativeMethods.SessionErrorCallback error = HandleSessionError; NativeMethods.SessionProgressCallback progress = HandleSessionProgress; NativeMethods.SessionWaitCallback wait = HandleSessionWaitCallback; GCHandle.Alloc(refresh); GCHandle.Alloc(error); GCHandle.Alloc(progress); GCHandle.Alloc(wait); NativeMethods.install_syncsession_callbacks(refresh, error, progress, wait); NativeMethods.OpenRealmCallback openRealm = HandleOpenRealmCallback; GCHandle.Alloc(openRealm); NativeMethods.install_syncmanager_callbacks(openRealm); _logCallback = HandleLogMessage; GCHandle.Alloc(_logCallback); }
/// <summary> /// <para>Encrypt text string with an X509 certificate in a file.</para> /// </summary> /// <param name="textToEncrypt"> /// <para>The text to encrypt.</para> /// </param> /// <param name="certFileName"> /// <para>The encryption certificate file path.</para> /// </param> /// <param name="algorithmOid"> /// <para>The encryption algorithm object identifier (OID).</para> /// </param> /// <returns> /// <para>The encrypted text as <see cref="System.String" />.</para> /// </returns> public static string EncryptTextByCertFile( string textToEncrypt, string certFileName, string algorithmOid) { using (PinCollection pin = new PinCollection()) { try { return(NativeTypes.FromNativeString(NativeCommon.FabricEncryptText2( pin.AddObject(textToEncrypt), pin.AddObject(certFileName), pin.AddObject(algorithmOid)))); } catch (Exception ex) { COMException comEx = Utility.TryTranslateExceptionToCOM(ex); if (comEx != null) { throw comEx; } throw; } } }
public void FakeExceptionThrowTest() { using (Realm.GetInstance()) { Assert.Throws <RealmPermissionDeniedException>(() => NativeCommon.fake_a_native_exception((IntPtr)RealmExceptionCodes.RealmPermissionDenied)); } }
/// <summary> /// <para>Encrypt text string with an installed X509 certificate.</para> /// </summary> /// <param name="textToEncrypt"> /// <para>The text to encrypt.</para> /// </param> /// <param name="thumbprint"> /// <para>The thumbprint of encryption certificate.</para> /// </param> /// <param name="storeName"> /// <para>The name of certificate store, from which encryption certificate is retrieved.</para> /// </param> /// <param name="storeLocation"> /// <para>The certificate store location to retrieve encryption certificate.</para> /// </param> /// <param name="algorithmOid"> /// <para>The encryption algorithm object identifier (OID).</para> /// </param> /// <returns> /// <para>The encrypted text as <see cref="System.String" />.</para> /// </returns> public static string EncryptText( string textToEncrypt, string thumbprint, string storeName, StoreLocation storeLocation, string algorithmOid) { using (PinCollection pin = new PinCollection()) { try { return(NativeTypes.FromNativeString(NativeCommon.FabricEncryptText( pin.AddObject(textToEncrypt), pin.AddObject(thumbprint), pin.AddObject(storeName), (NativeTypes.FABRIC_X509_STORE_LOCATION)storeLocation, pin.AddObject(algorithmOid)))); } catch (Exception ex) { COMException comEx = Utility.TryTranslateExceptionToCOM(ex); if (comEx != null) { throw comEx; } throw; } } }
private static void SetSfInstalledMobyHelper(string fileContents) { using (var pin = new PinCollection()) { NativeCommon.FabricSetSfInstalledMoby(pin.AddBlittable(fileContents)); } }
public static unsafe void WriteStructured(ref GenericEventDescriptor eventDescriptor, ulong userDataCount, EventDataDescriptor *eventDataPtr) { try { //using (var pin = new PinCollection()) fixed(GenericEventDescriptor *eventDescriptorPtr = &eventDescriptor) { var traceEvent = new NativeTypes.FABRIC_ETW_TRACE_EVENT_PAYLOAD() { EventDescriptor = (IntPtr)eventDescriptorPtr,//pin.AddBlittable(eventDescriptor), EventDataDescriptorList = new NativeTypes.FABRIC_ETW_TRACE_EVENT_DATA_DESCRIPTOR_LIST() { Count = userDataCount, UserDataDescriptor = (IntPtr)eventDataPtr }, Reserved = IntPtr.Zero }; NativeCommon.WriteManagedStructuredTrace(ref traceEvent); } } catch (Exception ex) { Console.WriteLine("Exception during interop structured trace writing: {0}", ex); Console.WriteLine("EventId: {0}, UserDataCount {1}", eventDescriptor.EventId, userDataCount); } }
public void FakeExceptionThrowLoopingTest() { using (Realm.GetInstance()) { for (int i = 0; i < 10000; ++i) { #if DEBUG bool caughtIt = false; // Assert.Throws doesn't work with the VS debugger which thinks the exception is uncaught try { NativeCommon.fake_a_native_exception((IntPtr)RealmExceptionCodes.RealmPermissionDenied); } catch (RealmPermissionDeniedException) { caughtIt = true; } Assert.That(caughtIt, "Should have caught the expected exception"); #else Assert.Throws <RealmPermissionDeniedException>( () => NativeCommon.fake_a_native_exception((IntPtr)RealmExceptionCodes.RealmPermissionDenied)); #endif } } }
public static string DecryptValue(string textToDecrypt) { using (PinCollection pin = new PinCollection()) { return(NativeTypes.FromNativeString(NativeCommon.FabricDecryptText( pin.AddObject(textToDecrypt), NativeTypes.FABRIC_X509_STORE_LOCATION.FABRIC_X509_STORE_LOCATION_LOCALMACHINE))); } }
private static void RemoveReadOnlyAttributeHelper(string path) { using (var pin = new PinCollection()) { NativeCommon.FabricFileRemoveReadOnlyAttribute( pin.AddBlittable(path)); } }
private static bool IsSymbolicLinkHelper(string path) { using (var pin = new PinCollection()) { BOOLEAN result; NativeCommon.FabricDirectoryIsSymbolicLink(pin.AddBlittable(path), out result); return(NativeTypes.FromBOOLEAN(result)); } }
private static void MoveHelper(string src, string des) { using (var pin = new PinCollection()) { NativeCommon.FabricFileMove( pin.AddBlittable(src), pin.AddBlittable(des)); } }
public static bool IsSignatureValid(string filename) { using (var pin = new PinCollection()) { BOOLEAN isValid; NativeCommon.VerifyFileSignature(pin.AddBlittable(filename), out isValid); return(NativeTypes.FromBOOLEAN(isValid)); } }
public void TearDown() { if (_isSetup) { CustomTearDown(); NativeCommon.reset_for_testing(); _isSetup = false; } }
private static void DeleteHelper(string path, bool deleteReadonly) { using (var pin = new PinCollection()) { NativeCommon.FabricFileDelete( pin.AddBlittable(path), NativeTypes.ToBOOLEAN(deleteReadonly)); } }
private SecureString DecryptValueHelper(string encryptedValue) { using (var pin = new PinCollection()) { return(StringResult.FromNativeToSecureString(NativeCommon.FabricDecryptText( pin.AddBlittable(encryptedValue), NativeTypes.FABRIC_X509_STORE_LOCATION.FABRIC_X509_STORE_LOCATION_LOCALMACHINE))); } }
private static bool ExistsHelper(string path) { using (var pin = new PinCollection()) { BOOLEAN isExisted; NativeCommon.FabricFileExists(pin.AddBlittable(path), out isExisted); return(NativeTypes.FromBOOLEAN(isExisted)); } }
private static SecureString DecryptTextHelper(string encryptedValue, StoreLocation storeLocation) { using (var pin = new PinCollection()) { return(StringResult.FromNativeToSecureString(NativeCommon.FabricDecryptText( pin.AddBlittable(encryptedValue), (NativeTypes.FABRIC_X509_STORE_LOCATION)storeLocation))); } }
private static void DeleteHelper(string path, bool recursive, bool deleteReadOnlyFiles) { using (var pin = new PinCollection()) { NativeCommon.FabricDirectoryDelete( pin.AddBlittable(path), NativeTypes.ToBOOLEAN(recursive), NativeTypes.ToBOOLEAN(deleteReadOnlyFiles)); } }
static unsafe SyncUserHandle() { NativeCommon.Initialize(); NativeMethods.ApiKeysCallback apiKeysCallback = HandleApiKeysCallback; GCHandle.Alloc(apiKeysCallback); NativeMethods.initialize(apiKeysCallback); }
private static LinuxPackageManagerType GetLinuxPackageManagerTypeHelper() { using (var pin = new PinCollection()) { Int32 packageManagerType = 0; NativeCommon.GetLinuxPackageManagerType(out packageManagerType); return((LinuxPackageManagerType)packageManagerType); } }
private static void CopyHelper(string src, string des, bool overwrite) { using (var pin = new PinCollection()) { NativeCommon.FabricFileCopy( pin.AddBlittable(src), pin.AddBlittable(des), NativeTypes.ToBOOLEAN(overwrite)); } }
private static Int64 GetSizeHelper(string path) { using (var pin = new PinCollection()) { Int64 size = 0; NativeCommon.FabricFileGetSize( pin.AddBlittable(path), out size); return(size); } }
private static DateTime GetLastWriteTimeHelper(string path) { using (var pin = new PinCollection()) { NativeTypes.NativeFILETIME lastWriteTime; NativeCommon.FabricFileGetLastWriteTime( pin.AddBlittable(path), out lastWriteTime); return(NativeTypes.FromNativeFILETIME(lastWriteTime)); } }
public void TearDown() { if (_isSetup) { CustomTearDown(); NativeCommon.reset_for_testing(); _isSetup = false; Realm.DeleteRealm(RealmConfiguration.DefaultConfiguration); } }
private static void ReplaceHelper(string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors) { using (var pin = new PinCollection()) { NativeCommon.FabricFileReplace( pin.AddBlittable(destinationFileName), pin.AddBlittable(sourceFileName), pin.AddBlittable(destinationBackupFileName), NativeTypes.ToBOOLEAN(ignoreMetadataErrors)); } }
protected string DecryptText(string text, StoreLocation storeLocation) { using (var pin = new PinCollection()) { // Calling native API directly because we need to return string instead of SecureString for this cmdlet, // and we do not want to have a public managed API that returns string instead of SecureString. return(StringResult.FromNative(NativeCommon.FabricDecryptText( pin.AddBlittable(text), (NativeTypes.FABRIC_X509_STORE_LOCATION)storeLocation))); } }