public static void GetLibraryMethod <T>(SupportedPlatform platform, IntPtr handle, string name, out T t) { IntPtr result; switch (platform) { case SupportedPlatform.Windows: result = NativeWindowsMethods.GetProcAddress(handle, name); if (result == IntPtr.Zero) { throw new EntryPointNotFoundException(name, GetLastWindowsError()); } break; case SupportedPlatform.Linux: case SupportedPlatform.MacOSX: result = NativeUnixMehods.dlsym(handle, name); if (result == IntPtr.Zero) { throw new EntryPointNotFoundException(name, GetLastErrorUnix()); } break; default: throw new NotSupportedException(); } t = (T)(object)Marshal.GetDelegateForFunctionPointer(result, typeof(T)); }
private static bool LoadDynamicLibrary(SupportedPlatform platform, string name, out IntPtr handle, out string location) { switch (platform) { case SupportedPlatform.Windows: handle = NativeWindowsMethods.LoadLibrary(name); if (handle == IntPtr.Zero) { goto default; } location = GetLocationWindows(handle) ?? name; return(true); case SupportedPlatform.Linux: case SupportedPlatform.MacOSX: handle = NativeUnixMehods.dlopen(name, 2 /* RTLD_NOW */); if (handle == IntPtr.Zero) { goto default; } location = GetLocationUnix(handle) ?? name; return(true); default: handle = IntPtr.Zero; location = null; return(false); } }
protected virtual ISet <Skimmer <TContext> > CreateSkimmers(TOptions analyzeOptions, TContext context) { IEnumerable <Skimmer <TContext> > skimmers; var result = new SortedSet <Skimmer <TContext> >(SkimmerIdComparer <TContext> .Instance); try { skimmers = CompositionUtilities.GetExports <Skimmer <TContext> >(RetrievePluginAssemblies(DefaultPluginAssemblies, analyzeOptions.PluginFilePaths)); SupportedPlatform currentOS = GetCurrentRunningOS(); foreach (Skimmer <TContext> skimmer in skimmers) { if (skimmer.SupportedPlatforms.HasFlag(currentOS)) { result.Add(skimmer); } else { Warnings.LogUnsupportedPlatformForRule(context, skimmer.Name, skimmer.SupportedPlatforms, currentOS); } } } catch (Exception ex) { Errors.LogExceptionInstantiatingSkimmers(context, DefaultPluginAssemblies, ex); ThrowExitApplicationException(context, ExitReason.UnhandledExceptionInstantiatingSkimmers, ex); } if (result.Count == 0) { Errors.LogNoRulesLoaded(context); ThrowExitApplicationException(context, ExitReason.NoRulesLoaded); } return(result); }
private HashSet <Skimmer <TContext> > CreateSkimmers(TContext context) { IEnumerable <Skimmer <TContext> > skimmers; HashSet <Skimmer <TContext> > result = new HashSet <Skimmer <TContext> >(); try { skimmers = CompositionUtilities.GetExports <Skimmer <TContext> >(DefaultPlugInAssemblies); SupportedPlatform currentOS = GetCurrentRunningOS(); foreach (Skimmer <TContext> skimmer in skimmers) { if (skimmer.SupportedPlatforms.HasFlag(currentOS)) { result.Add(skimmer); } else { Warnings.LogUnsupportedPlatformForRule(context, skimmer.Name, skimmer.SupportedPlatforms, currentOS); } } } catch (Exception ex) { Errors.LogExceptionInstantiatingSkimmers(context, DefaultPlugInAssemblies, ex); ThrowExitApplicationException(context, ExitReason.UnhandledExceptionInstantiatingSkimmers, ex); } if (result.Count == 0) { Errors.LogNoRulesLoaded(context); ThrowExitApplicationException(context, ExitReason.NoRulesLoaded); } return(result); }
private SdkHandle(IntPtr handle, SupportedPlatform platform, string location) : base(true) { SetHandle(handle); Platform = platform; Location = location; }
/// <summary> /// Returns the name of the native sdk binary that fits the current environment /// </summary> /// <param name="names">possible names of the native sdk binary</param> /// <param name="platform">detected platform</param> /// <returns>true if a matching binary exists</returns> public static bool TryGetNativeBinaryName(out string[] names, out SupportedPlatform platform) { // check if OS is 64-, 32-, or something else bit bool is64Bit; switch (Native.SizeOfPointer) { case 8: is64Bit = true; break; case 4: is64Bit = false; break; default: names = null; platform = 0; return(false); } // check if operating system is supported OperatingSystem operatingSystem = Environment.OSVersion; switch (operatingSystem.Platform) { case PlatformID.MacOSX: platform = SupportedPlatform.MacOSX; break; case PlatformID.Unix: platform = IsRunningOnMac() ? SupportedPlatform.MacOSX : SupportedPlatform.Linux; break; case PlatformID.Win32NT: if (operatingSystem.Version >= new Version(5, 1)) // if at least windows xp or newer { platform = SupportedPlatform.Windows; break; } else { goto default; } default: platform = 0; names = null; return(false); } // get name of the binary switch (platform) { case SupportedPlatform.MacOSX: names = new string[] { "mac/libts3client.dylib", "libts3client_mac.dylib", "libts3client.dylib" }; break; case SupportedPlatform.Linux: names = is64Bit ? new string[] { "linux/amd64/libts3client.so", "libts3client_linux_amd64.so", "libts3client.so" } : new string[] { "linux/x86/libts3client.so", "libts3client_linux_x86.so", "libts3client.so" }; break; case SupportedPlatform.Windows: names = is64Bit ? new string[] { "windows/win64/ts3client.dll", "ts3client_win64.dll", "ts3client.dll" } : new string[] { "windows/win32/ts3client.dll", "ts3client_win32.dll", "ts3client.dll" }; break; default: throw new NotImplementedException(); } return(true); }
public async Task <ActionResult <PlatformSyncResponse> > Register([FromBody] RegistrationData registrationData) { if (registrationData == null) { throw new ArgumentNullException("registrationData"); } if (registrationData.Auth0Id == null) { throw new ArgumentNullException("registrationData.Auth0Id"); } if (registrationData.PlatformId == null) { throw new ArgumentNullException("registrationData.PlatformId"); } if (this.GetCachedUser() != null) { throw new InvalidOperationException(); } try { string auth0Id = registrationData.Auth0Id; var auth0DbUser = await _dbContext.Auth0Query(auth0Id).FirstOrDefaultAsync(); var platformId = BitcornUtils.GetPlatformId(registrationData.PlatformId); //get all classes that inherit from SocialRegisteration, map to dictionary based on name //for example TwitchRegisteration will have key "twitch" var registerController = SupportedPlatform.AllocateController(_dbContext, platformId, _configuration); if (registerController != null) { if (!string.IsNullOrEmpty(platformId.Id) && platformId.Id.ToLower() != "undefined") { var result = await registerController.SyncPlatform(registrationData, auth0DbUser, platformId, auth0Id); if (result != null) { //claim transactions etc.. await registerController.OnSyncSuccess(result.SocialCreationTime, platformId); } return(result); } else { return(registerController.GetSyncOutput(auth0DbUser?.CreationTime, auth0DbUser, false)); } } else { return(StatusCode((int)HttpStatusCode.BadRequest)); } } catch (Exception e) { throw new Exception($"registration failed for {JsonConvert.SerializeObject(registrationData)}"); } throw new Exception("HOW THE F**K DID YOU GET HERE"); }
public static SdkHandle Load(SupportedPlatform platform, string[] possibleNames) { DllUnloaded.WaitOne(); IntPtr handle; string location; PlatformSpecific.LoadDynamicLibrary(platform, possibleNames, out handle, out location); return(new SdkHandle(handle, platform, location)); }
public static void UnloadDynamicLibrary(SupportedPlatform platform, IntPtr handle) { if (platform != SupportedPlatform.Android) { throw new NotSupportedException(); } if (NativeUnixMehods.dlclose(handle) != 0) { throw GetLastError() ?? new InvalidOperationException(); } }
public override string GetLibraryRelativePath(SupportedPlatform currentPlatform) { switch (currentPlatform) { case SupportedPlatform.Windows: return(@"runtimes\win\native\snappy64.dll"); case SupportedPlatform.Linux: // TODO: add support for Linux and MacOS later case SupportedPlatform.MacOS: default: throw new InvalidOperationException($"Snappy is not supported on the current platform: {currentPlatform}."); } }
public static void GetLibraryMethod <T>(SupportedPlatform platform, IntPtr handle, string name, out T t) { if (platform != SupportedPlatform.Android) { throw new NotSupportedException(); } IntPtr result = NativeUnixMehods.dlsym(handle, name); if (result == IntPtr.Zero) { throw new EntryPointNotFoundException(name, GetLastError()); } t = (T)(object)Marshal.GetDelegateForFunctionPointer(result, typeof(T)); }
/// <summary> /// Returns the name of the native sdk binary that fits the current environment /// </summary> /// <param name="names">possible names of the native sdk binary</param> /// <param name="platform">detected platform</param> /// <returns>true if a matching binary exists</returns> public static bool TryGetNativeBinaryName(out string[] names, out SupportedPlatform platform) { platform = SupportedPlatform.Android; // check if platform is 64-, 32-, or something else bit switch (Native.SizeOfPointer) { case 8: case 4: break; default: names = null; platform = 0; return(false); } names = new string[] { "libts3client.so", "libts3client_android.so" }; return(true); }
private INativeLibraryLoader CreateNativeLoader(SupportedPlatform currentPlatform, string libraryPath) { switch (currentPlatform) { case SupportedPlatform.Linux: return(new LinuxLibraryLoader(libraryPath)); case SupportedPlatform.MacOS: return(new DarwinLibraryLoader(libraryPath)); case SupportedPlatform.Windows: return(new WindowsLibraryLoader(libraryPath)); default: throw new PlatformNotSupportedException($"Unexpected platform {currentPlatform}."); } }
public static void LoadDynamicLibrary(SupportedPlatform platform, string[] possibleNames, out IntPtr handle, out string location) { if (platform != SupportedPlatform.Android) { throw new NotSupportedException(); } foreach (string possibleName in possibleNames) { handle = NativeUnixMehods.dlopen(possibleName, 2 /* RTLD_NOW */); if (handle != IntPtr.Zero) { location = possibleName; return; } } string message = string.Join(", ", possibleNames); throw new DllNotFoundException(message, GetLastError()); }
public static void UnloadDynamicLibrary(SupportedPlatform platform, IntPtr handle) { switch (platform) { case SupportedPlatform.Windows: if (NativeWindowsMethods.FreeLibrary(handle) == false) { throw GetLastWindowsError(); } break; case SupportedPlatform.Linux: case SupportedPlatform.MacOSX: if (NativeUnixMehods.dlclose(handle) != 0) { throw GetLastErrorUnix() ?? new InvalidOperationException(); } break; default: throw new NotSupportedException(); } }
public static void LoadDynamicLibrary(SupportedPlatform platform, string[] possibleNames, out IntPtr handle, out string location) { foreach (string possibleName in possibleNames) { if (LoadDynamicLibrary(platform, possibleName, out handle, out location)) { return; } } string message = string.Join(", ", possibleNames); switch (platform) { case SupportedPlatform.Windows: throw new DllNotFoundException(message, GetLastWindowsError()); case SupportedPlatform.Linux: case SupportedPlatform.MacOSX: throw new DllNotFoundException(message, GetLastErrorUnix()); default: throw new NotSupportedException(); } }
// public methods public string GetLibraryAbsolutePath(SupportedPlatform currentPlatform) { var relativePath = GetLibraryRelativePath(currentPlatform); return(GetAbsolutePath(relativePath)); }
internal static IEnumerable <ITestSettings> FilterSettings(this IEnumerable <ITestSettings> settings, MethodInfo methodInfo, SupportedPlatform platform, SupportedArchitecture platformArchitecture) { // Makre sure that the test runs for the platform and platform architecture SupportedPlatformAttribute platformAttribute = methodInfo.GetCustomAttribute <SupportedPlatformAttribute>(); // If platform attribute is not specified, implicitly assume that all platforms are supported if (null != platformAttribute) { if (!platformAttribute.Platform.HasFlag(platform)) { return(Enumerable.Empty <ITestSettings>()); } if (!platformAttribute.Architecture.HasFlag(platformArchitecture)) { return(Enumerable.Empty <ITestSettings>()); } } IReadOnlyCollection <SupportedCompilerAttribute> supportedCompilers = methodInfo.GetCustomAttributes <SupportedCompilerAttribute>().ToArray(); IReadOnlyCollection <SupportedDebuggerAttribute> supportedDebuggers = methodInfo.GetCustomAttributes <SupportedDebuggerAttribute>().ToArray(); IReadOnlyCollection <UnsupportedDebuggerAttribute> unsupportedDebuggers = methodInfo.GetCustomAttributes <UnsupportedDebuggerAttribute>().ToArray(); // Get the subset of test settings that match the requirements of the test. // The test will be run for each test setting in the set. If an empty set is returned, // the test is not run. return(settings.Where(s => (supportedCompilers.Count == 0 || supportedCompilers.Matches(s.CompilerSettings)) && (supportedDebuggers.Count == 0 || supportedDebuggers.Matches(s.DebuggerSettings)) && !unsupportedDebuggers.Matches(s.DebuggerSettings)) .Select(x => TestSettings.CloneWithName(x, methodInfo.Name)) .ToArray()); }
public static void LogUnsupportedPlatformForRule(IAnalysisContext context, string ruleId, SupportedPlatform supportedOS, SupportedPlatform currentOS) { // Rule '{0}' was disabled as it cannot run on the current platform '{1}'. It can only run on '{2}'. if (context == null) { throw new ArgumentNullException(nameof(context)); } string message = string.Format(CultureInfo.InvariantCulture, SdkResources.WRN998_NotSupportedPlatform, ruleId, currentOS, supportedOS); context.Logger.LogConfigurationNotification( new Notification { Locations = new List <Location> { new Location { PhysicalLocation = new PhysicalLocation { ArtifactLocation = new ArtifactLocation { Uri = context.TargetUri } } } }, Descriptor = new ReportingDescriptorReference { Id = Wrn998_UnsupportedPlatform }, Message = new Message { Text = message }, Level = FailureLevel.Warning, }); context.RuntimeErrors |= RuntimeConditions.RuleCannotRunOnPlatform; }
public SupportedPlatformAttribute(SupportedPlatform platform, SupportedArchitecture architecture) { this.Architecture = architecture; this.Platform = platform; }
internal static IEnumerable <ITestSettings> GetSettings(MethodInfo testMethod, SupportedPlatform platform, SupportedArchitecture platformArchitecture) { Parameter.AssertIfNull(testMethod, nameof(testMethod)); // Find the attribute in the context of the test method. // Currently, only look at the assembly of the test method. TestSettingsProviderAttribute providerAttribute = testMethod.DeclaringType?.GetTypeInfo().Assembly?.GetCustomAttribute <TestSettingsProviderAttribute>(); UDebug.AssertNotNull(providerAttribute, "Unable to locate TestSettingsProviderAttribute."); if (null == providerAttribute) { return(Enumerable.Empty <ITestSettings>()); } UDebug.AssertNotNull(providerAttribute.ProviderType, "TestSettingsProviderAttribute.ProviderType is null"); if (null == providerAttribute.ProviderType) { return(Enumerable.Empty <ITestSettings>()); } ITestSettingsProvider provider = null; lock (s_providerMapping) { // Get the provider from the attribute if the provider was not already created if (!s_providerMapping.TryGetValue(providerAttribute.ProviderType, out provider)) { // If not cached, create the provide from the attribute and cache it provider = (ITestSettingsProvider)Activator.CreateInstance(providerAttribute.ProviderType); s_providerMapping.Add(providerAttribute.ProviderType, provider); } } // Get the list of settings from the provider IEnumerable <ITestSettings> settings = provider.GetSettings(testMethod); UDebug.AssertNotNull(settings, "Settings were not provided by the test settings provider."); if (null == settings) { return(Enumerable.Empty <ITestSettings>()); } // Filter the settings according to the attribution on the test method return(settings.FilterSettings(testMethod, platform, platformArchitecture)); }
private static IEnumerable <ITestSettings> FilterSettings(string methodName, SupportedPlatform platform, SupportedArchitecture platformArchitecture) { MethodInfo methodInfo = AttributionTests.GetTestMethodInfo(methodName); return(AttributionTests.AllSettings.FilterSettings(methodInfo, platform, platformArchitecture)); }
private string GetColumnValueYesNo(SqlObjectInfo sqlObjectInfo, SupportedPlatform platform) { var isPlatformSupported = sqlObjectInfo.SupportedPlatforms.Contains(platform); return(isPlatformSupported ? "Yes" : "No"); }
/// <summary> /// Creates a new <see cref="LibraryParameters"/>-Object. /// </summary> /// <param name="nativeBinaryLocation">Location to the TeamSpeak library binary.</param> /// <param name="platform">Determines which platform specific code will be executed.</param> /// <param name="resourcesFolder">Path pointing to the directory where the soundbackends folder is located.</param> public LibraryParameters(string nativeBinaryLocation, SupportedPlatform platform, string resourcesFolder) { PossibleNativeBinaryLocations = new string[] { nativeBinaryLocation }; Platform = platform; ResourcesFolder = resourcesFolder; }
/// <summary> /// Returns the name of the native sdk binary that fits the current environment /// </summary> /// <param name="names">possible names of the native sdk binary</param> /// <param name="platform">detected platform</param> /// <returns>true if a matching binary exists</returns> public static bool TryGetNativeBinaryName(out string[] names, out SupportedPlatform platform) { platform = SupportedPlatform.iOS; names = new string[] { null }; return(true); }
public abstract string GetLibraryRelativePath(SupportedPlatform currentPlatform);
private string GetColumnValueVersion(SqlObjectInfo sqlObjectInfo, SupportedPlatform min, SupportedPlatform max) { var minPlatform = sqlObjectInfo.SupportedPlatforms.FirstOrDefault(platform => platform >= min && platform <= max); return(minPlatform == SupportedPlatform.Unknown ? "No" : minPlatform.ToString()); }
/// <summary> /// Returns the name of the native sdk binary that fits the current environment /// </summary> /// <param name="names">possible names of the native sdk binary</param> /// <param name="platform">detected platform</param> /// <returns>true if a matching binary exists</returns> public static bool TryGetNativeBinaryName(out string[] names, out SupportedPlatform platform) { return(PlatformSpecific.TryGetNativeBinaryName(out names, out platform)); }