See here: How to launch .exe file in uwp app using fulltrustlauncher? – Stack Overflow
For a list of almost every MIME File Type, see here:
Common MIME types – HTTP | MDN (mozilla.org) and
All known MIME types (digipres.org)
The Key to success for BroadFileSystemAccess is to add it by hand to the XML Manifest and follow the information from MSDN (App capability declarations – UWP applications | Microsoft Docs):
The broadFileSystemAccess capability allows apps to get the same access to the file system as the user who is currently running the app without any additional file-picker style prompts during runtime. It is important to note that this capability is not required to access files that the user has already chosen using the FilePicker or FolderPicker.
This capability works for the Windows.Storage APIs. Because users can grant or deny the permission any time in Settings, you should ensure that your app is resilient to those changes. In the April 2018 update, the default for the permission is On. In the October 2018 update, the default is Off. It is also important that you do not declare any special folder capabilities such as Documents, Pictures, or Videos with this capability. You can enable this capability in your app by adding broadFileSystemAccess to your manifest. For an example, see the File access permissions article.
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp uap3 rescap"> ... <Applications> <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="YOURAPP.App"> <Extensions> <uap:Extension Category="windows.fileTypeAssociation"> <uap:FileTypeAssociation Name="YourFileTypeAssociation"> <uap:DisplayName>YOURDISPLAYNAME</uap:DisplayName> <uap:SupportedFileTypes> <uap:FileType ContentType="image/jpeg">.jpeg</uap:FileType> <uap:FileType ContentType="image/png">.png</uap:FileType> <uap:FileType ContentType="application/pdf">.pdf</uap:FileType> <uap:FileType ContentType="image/tiff">.tif</uap:FileType> <uap:FileType ContentType="image/tiff">.tiff</uap:FileType> <uap:FileType ContentType="image/jpeg">.jpg</uap:FileType> <uap:FileType ContentType="text/plain">.txt</uap:FileType> <uap:FileType ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document">.docx</uap:FileType> <uap:FileType ContentType="application/msword">.doc</uap:FileType> <uap:FileType ContentType="text/csv">.csv</uap:FileType> <uap:FileType ContentType="image/gif">.gif</uap:FileType> </uap:SupportedFileTypes> </uap:FileTypeAssociation> </uap:Extension> </Extensions> </Application> </Applications> <Capabilities> <Capability Name="internetClientServer" /> <Capability Name="privateNetworkClientServer" /> <Capability Name="internetClient" /> <uap:Capability Name="enterpriseAuthentication" /> <rescap:Capability Name="broadFileSystemAccess"/> </Capabilities> </Package>
To Resize (eventually edit the Height or Width to a higher value) the ContentDialog(s) you need to add the following lines to your App.xaml file and edit the Max values as you wish.
<Application.Resources> <x:Double x:Key="ContentDialogMaxWidth">1000</x:Double> <x:Double x:Key="ContentDialogMaxHeight">1000</x:Double> </Application.Resources>
The Key to successfully make a ListView scrollable is to set a Value to the Height property of the ListView as shown below in the highlighted rows.
<StackPanel Grid.Column="0" Grid.Row="0" Margin="4,2,0,0"> <uwp:HeaderedTextBlock Text="Header Title" /> <ListView x:Name="lvwMyEntities" Height="300" ItemsSource="{x:Bind local:Collections.MyEntities}" SelectionMode="Single" MinHeight="150" Grid.Row="0" ScrollViewer.VerticalScrollBarVisibility="Visible"> <ListView.ItemTemplate> <DataTemplate x:DataType="local:MyEntity"> <Grid Width="150" Height="150"> <Border BorderBrush="DarkGray" BorderThickness="0.5" > <StackPanel Orientation="Vertical" VerticalAlignment="Center" AllowDrop="true" DragEnter="PnlMyEntity_DragEnter" DragLeave="PnlMyEntity_DragLeave" DragOver="PnlMyEntity_DragOver" Drop="PnlMyEntity_Drop" DropCompleted="PnlMyEntity_DropCompleted"> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" FontWeight="Bold" Text="{x:Bind DisplayName}" FontSize="14" TextWrapping="WrapWholeWords" Margin="2"/> <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Bottom" Background="White"> <Image HorizontalAlignment="Center" VerticalAlignment="Bottom" Source="{x:Bind Image}" Stretch="Uniform" /> </StackPanel> </StackPanel> </Border> </Grid> </DataTemplate> </ListView.ItemTemplate> <ListView.ItemsPanel> <ItemsPanelTemplate> <ItemsWrapGrid x:Name="lvwPnlApo" Orientation="Horizontal"/> </ItemsPanelTemplate> </ListView.ItemsPanel> </ListView> </StackPanel>
Following things are important to notice:
-- Steps: -- 1. Replace Placeholders in this Script -- 2. Create Certificate/Private Key/PFX File -- 3. Adapt your C#/VB .NET Project with the SQL CLR Assembly to use the Certificate (PFX file). -- 4. Make changes to Server Instance to enable Common Language Runtime. Server-Instanz so einstellen, dass die strikte Security deaktiviert wird für CLR. -- 5. Create CLR Assembly in Sql Server. -- 6. (optionally) Drop old CLR Functions. -- 7. Create new CLR Functions. /* This Article is based on input from: https://github.com/MicrosoftDocs/sql-docs/issues/2052 (Comment of Solomon Rutzky) https://nielsberglund.com/2017/07/01/sqlclr-and-certificates/ (Niels Berglund) https://nielsberglund.com/2017/07/23/sql-server-2017-sqlclr---whitelisting-assemblies/ (Niels Berglund) Regards to all of you - thank you so much for your publishment! */ -- 1... /* Replace each of the following Placeholders using Ctrl+H with your own values: DWH -> Database name where the Assembly should be deployed to (excluding []) Win10Sdk64bitPath -> Path to the installation of Windows 10 SDK 64bit: C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64 CertFolderPath -> Path to the folder where the Certificate, Private Key and PFX files will be saved (excluding ""). e.g.: C:\DWH\Certificates AssemblyFullPath -> Full Path to the DLL file to create the CRL Assembly from (excluding ""). e.g.: C:\DWH\SqlServerClrFunctionsLib.dll SqlClrAssemblyName -> Name of Assembly under which it should be registered in your Database. e.g.: ClrFunctions CertAuthority -> Canonical Name of the Certificate's Authority (excluding "") e.g.: CompanyName Authority CertName -> Name of the Certificate file (excluding .cer, folders and excluding "") e.g.: Assemblies.CompanyName.Public CertPvkName -> Name of the PVK file (excluding .pvk, folders and excluding "") e.g.: Assemblies.CompanyName.PrivateKey CertPfxName -> Name of the PFX file (excluding .pfx, folders and excluding "") e.g.: Assemblies.CompanyName.PrivateKey CertPvkPassword -> Your strong Private Key Password (excluding "") CertPfxPassword -> Another (less-strong) Password to protect the PFX file (excluding "") */ -- 2.... -- Use Windows 10 SDK makecert.exe and pvk2pfx.exe to create a (public) Certificate, Private Key and export a PFX file: -- https://developer.microsoft.com/de-de/windows/downloads/windows-10-sdk/ -- 1. "Win10Sdk64bitPath\makecert.exe" -r -pe -n "CN=CertAuthority" -a sha256 -sky signature -cy authority -sv "CertFolderPath\CertPvkName.pvk" -len 2048 -m 144 "CertFolderPath\CertName.cer" -- you will be prompted for a Private Key Password - enter: CertPvkName -- -- 2. "Win10Sdk64bitPath\pvk2pfx.exe" -pvk "CertFolderPath\CertPvkName.pvk" -spc "CertFolderPath\CertName.cer" -pfx "CertFolderPath\CertPfxName.pfx" -pi "CertPvkName" -po "CertPfxPassword" -- 3.... -- 1. Copy previously created PFX file to the root of your C# .Net Project so that $(ProjectDir) matches the directory of the PFX file. -- 2. Sign DLL in Visual Studio using the created PFX file in step 2 by adding the following command to ---->>>> Post Build Event: <<<<<---- -- "Win10Sdk64bitPath\signtool.exe" sign /f "$(ProjectDir)CertPfxName.pfx" /p "CertPfxPassword" $(TargetDir)$(TargetFileName) -- 3. Build Project -- -- 4. Copy your signed DLL to "AssemblyFullPath" of the SQL Server. -- 4.... USE MASTER GO EXEC sp_configure 'show advanced options', 1; RECONFIGURE; GO EXEC sp_configure 'clr_enabled', 1 RECONFIGURE GO EXEC sp_configure 'clr strict security', 0; RECONFIGURE; GO -- Re-visit current server configuration (displays a list of all server settings): EXEC sp_configure GO /* Optional: Sometimes it might be necessary to change the Owner of the Database to the 'SA' (or 'dbo' or another Server Admin). -- This might be the case if your Database has been imported/restored from another server (or by another user). USE [DWH]; --SELECT owner_sid FROM sys.databases WHERE database_id = DB_ID('DWH') SELECT name FROM sys.database_principals WHERE sid = (SELECT TOP 1 owner_sid FROM sys.databases WHERE database_id = DB_ID('DWH')); EXEC sp_changedbowner @loginame = 'sa'; */ -- 5.... -- a.) Ensure, the SQL Server Service User (see services.msc and look out for your SQL Server Instance) -- has Read & Execute Permissions to the Assembly File USE [DWH]; -- Important to set context to the Database where you want to register your DLL! GO CREATE ASSEMBLY SqlClrAssemblyName from 'AssemblyFullPath' WITH PERMISSION_SET = UNSAFE -- use UNSAFE to be aligned with the Permission granted to the Certificate Login previsouly created GO -- In case of SQL Server Error Message 10134: It might be necessary to add your Assembly to the trusted_assemblies if your Functions won't execute... /* SELECT * FROM sys.assemblies a WHERE a.name LIKE '%SqlClrAssemblyName%'; -- Grab the BINARY of the Assembly file: SELECT content FROM sys.assembly_files WHERE name LIKE '%SqlClrAssemblyName%' DECLARE @hash varbinary(64), @clrName nvarchar(4000) = (SELECT name FROM sys.assemblies a WHERE a.name LIKE '%SqlClrAssemblyName%'); SELECT @hash = HASHBYTES('SHA2_512', (SELECT content FROM sys.assembly_files WHERE name LIKE '%SqlClrAssemblyName%')); SELECT @hash as Hash, @clrName as Name; EXEC sp_add_trusted_assembly @hash = @hash, @description = @clrName; SELECT * FROM sys.trusted_assemblies */ -- 6..... USE [DWH]; GO BEGIN TRAN DROP FUNCTION IF EXISTS common.ToBit; -- tbd... DROP FUNCTION IF EXISTS ... -- in case, you run into trouble and need to re-create the Assembly, execute this after Dropping previously created functions... -- DROP ASSEMBLY SqlClrAssemblyName; -- 7..... GO CREATE FUNCTION common.ToBit(@value sql_variant, @valueIfNull bit, @valueIfConvertError bit) RETURNS bit EXTERNAL NAME SqlClrAssemblyName.Scalar.ToBit; GO COMMIT TRAN /* After modifying the DLL it might be necessary to apply the following: ALTER ASSEMBLY SqlClrAssemblyName from 'AssemblyFullPath' WITH PERMISSION_SET = UNSAFE , UNCHECKED DATA; -- !! After changing the Certificate of the DLL, you might be required to update the HASH in the trusted_assemblies by re-invoking the Step 5. !! -- tbd... Create or Drop & re-create Functions... */
using System; using System.Text; using System.Data.SqlTypes; using System.Collections; using System.Globalization; using System.Collections.Generic; using System.Text.RegularExpressions; using Common; using SqlServerClrFunctionsLib; using Microsoft.SqlServer.Server; // TODO: For Unit Testing: Set the following options in this Project's Properties: // - Project | Build | Optimize Code => 0 // // TODO: For Deployment to SQL Server: Set the following options in this Project's Properties: // - Project | Build | Optimize Code => 1 /// <summary> /// Constraints for CLR Functions: /// https://docs.microsoft.com/en-us/sql/relational-databases/user-defined-functions/create-user-defined-functions-database-engine?view=sql-server-2017 /// /// Data Type Mapping: /// https://docs.microsoft.com/en-us/sql/relational-databases/clr-integration-database-objects-types-net-framework/mapping-clr-parameter-data?view=sql-server-2017 /// Extract: (SQL Server -> System.Data.SqlTypes.* -> .NET CLR Data Type /// bigint -> SqlInt64 -> Int64, Nullable{Int64} /// bit -> SqlBoolean -> Boolean, Nullable{Boolean} /// date -> SqlDateTime -> DateTime, Nullable{DateTime} /// decimal -> SqlDecimal -> Decimal, Nullable{Decimal} /// float -> SqlDouble -> Double, Nullable{Double} /// nvarchar -> SqlChars | SqlString -> String | Char[] // SQLChars is a better match for data transfer and access, and SQLString is a better match for performing String operations. /// nvarchar(1) -> SqlChars | SqlString -> Char | Nullable{char} /// sql_variant -> None -> Object /// </summary> public class Scalar { [SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true)] public static string LTrim(string value, string charsToTrim) { if (value == null || value == "") return value; else { return value.TrimStart(charsToTrim.ToCharArray()); } } /// <summary> /// Description: Konvertiert den übergebenen Wert @value in den entsprechenden Ja/Nein (Bit)-Wert (1 Bit). /// Es werden auch Strings mit Ja/Nein, J/N, Yes/No, Y/N, Si/No, True/False erkannt, sowie X/- erkannt. /// /// Wenn @value NULL ist, wird @valueIfNull zurückgegeben. /// Wenn ein Konvertierungsfehler auftritt, wird @valueIfConvertError zurückgegeben. /// </summary> /// <param name="value"></param> /// <param name="valueIfNull"></param> /// <param name="valueIfConvertError"></param> /// <returns></returns> [SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true)] public static bool? ToBit(Object value, bool? valueIfNull, bool? valueIfConvertError) { convertStringAgain: try { long lngValue; if (value == DBNull.Value) return valueIfNull; else if (value.GetType() == typeof(SqlBoolean)) return (bool?)((SqlBoolean)value).Value; else if (value is bool) return (bool)value; else if (value.GetType() == typeof(SqlString)) { string s = ((SqlString)value).Value; if (s.StartsWithAny(StringComparison.CurrentCultureIgnoreCase, "J", "Y", "S", "T", "W", "1", "X")) return true; else if (s.Length == 0 || s.StartsWithAny(StringComparison.CurrentCultureIgnoreCase, "N", "F", "0", "-", " ")) return false; } else if (value.GetType() == typeof(SqlChars)) { char[] val = ((SqlChars)value).Value; char c = val.Length > 0 ? val[0] : ' '; if (c.In('J', 'Y', 'S', 'T', 'W', '1', 'j', 'y', 's', 't', 'w', 'X', 'x')) return true; else if (c.In('N', 'F', '0', 'n', 'f', '-', ' ')) return false; } else if (value.GetType() == typeof(string)) { value = new SqlString((string)value); goto convertStringAgain; } else if (long.TryParse(Convert.ToString(value), out lngValue)) return lngValue != 0; return valueIfConvertError; } catch (Exception ex) { throw new InvalidOperationException(string.Format("Exception when converting the value '{0}' of type '{1}' to Bool! Message: {2}", value, value.GetType().FullName, ex.Message)); } } }
This short article explains the steps necessary to create and deploy a C# Library to SQL Server to use the faster execution of Scalar Functions, e.g. to convert any value to DateTime.
TODO: Describe C# Project and Code
Activate the “Optimize Code” and “Delay Sign Only” checkmarks in the Properties of the Project and Compile the Project.
Copy the compiled Lib.dll to a Location on the SQL Server, e.g. C:\DWH\Lib.dll
The SQL Server Database Engine User (see Services) requires Read & Execute Permissions for the File Location.
sp_configure 'clr strict security', 0; GO RECONFIGURE; GO USE DWH; GO -- DLL neu registrieren... CREATE ASSEMBLY ClrFunctions from 'C:\DWH\SqlServerClrFunctionsLib.dll' WITH PERMISSION_SET = SAFE;
CREATE FUNCTION common.ToDateTime(@value sql_variant, @valueIfNull datetime2(7), @valueIfConvertError datetime2(7)) RETURNS datetime2(7) EXTERNAL NAME ClrFunctions.Scalar.ToDateTime; GO
-- When code has been changed within DLL: ALTER ASSEMBLY ClrFunctions from 'C:\DWH\SqlServerClrFunctionsLib.dll' WITH PERMISSION_SET = SAFE , UNCHECKED DATA; -- ^^ it's possible that this step does not succeed. A restart of the Database Engine Service may be required. -- To Change the Signature of a Function, first drop then re-create function... BEGIN TRAN DROP FUNCTION common.ToBit; GO CREATE FUNCTION common.ToBit(@value sql_variant, @valueIfNull bit, @valueIfConvertError bit) RETURNS bit EXTERNAL NAME ClrFunctions.Scalar.ToBit; GO COMMIT
https://www.codeproject.com/articles/8874/strong-names-explained
System.TypeInitializationException
The type initializer for ‘{AStandardNetLibInYourProject}’ threw an exception.
For example, you have an explicit reference to System.Data.SqlClient > 4.5.0.1, either through a Nuget package reference or an Assembly Reference.
The consumed .net Standard 2.0 Library already contains (internally/transitively) a reference to System.Data.SqlClient 4.5.0.1
That binding causes the explicit reference to conflict.
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <RestoreProjectStyle>PackageReference</RestoreProjectStyle> </PropertyGroup> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
See also: https://stackoverflow.com/questions/49266384/there-is-possible-to-use-packagereference-in-xamarin-android-or-xamarin-ios-pr/49266856
and: https://github.com/xamarin/xamarin-macios/issues/3949
=== Zustandsinformationen vor Bindung === LOG: DisplayName = System.Data.SqlClient, Version=4.5.0.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified) LOG: Appbase = file:///C:/Workspaces/DWH/DwhApps/Dwh.Cmd.Etl.ImportFile/bin/Debug/ LOG: Ursprünglicher PrivatePath = NULL Aufruf von Assembly : Dwh.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: Diese Bindung startet im default-Load-Kontext. LOG: Die Anwendungskonfigurationsdatei wird verwendet: C:\Workspaces\DWH\DwhApps\Dwh.Cmd.Etl.ImportFile\bin\Debug\Dwh.Cmd.Etl.ImportFile.exe.Config LOG: Die Hostkonfigurationsdatei wird verwendet: LOG: Die Computerkonfigurationsdatei von C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config wird verwendet. LOG: In der Anwendungskonfigurationsdatei wurde eine Umleitung gefunden. 4.5.0.1 wird nach 4.6.1.0 umgeleitet. LOG: Verweis nach der Richtlinie: System.Data.SqlClient, Version=4.6.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a LOG: Download von neuem URL file:///C:/Workspaces/DWH/DwhApps/Dwh.Cmd.Etl.ImportFile/bin/Debug/System.Data.SqlClient.DLL. WRN: Der Vergleich des Assemblynamens führte zum Konflikt: Nebenversion. ERR: Das Setup der Assembly konnte nicht abgeschlossen werden (hr = 0x80131040). Die Suche wurde beendet.