SQL unit-tests don’t work under Visual Studio

Check server connection “SQL -> SQL Server Test Configuration…”

Visual Studio SQL unit-test connection dialog
Visual Studio SQL unit-test connection dialog.

The setting is contained in app.config file of unit-test project. Make sure that it is excluded from commit by means of “Skip worktree” option.

How to compute path relatively program directory in Pascal?

An example computing path to the ‘Models’ directory located one level upper from program directory

FilePath:= ExtractFilePath(ParamStr(0));
FilePath:= IncludeTrailingPathDelimiter(FilePath) + '..' + PathDelim;
FilePath:= ExpandFileName(FilePath) + 'Models' + PathDelim;

How to validate XML file according to schema in C#?

In this example XML document is fully loaded into memory. So, it is not suitable for large files.

//  Creating schema set.
var schemas = new XmlSchemaSet();
schemas.Add("http://creditinfo.com/schemas/Sample/Data", "Data.xsd");

//  Checking document validity according to schema.
var d = XDocument.Load(fileName);
var message = "";

d.Validate(schemas, (o, e) => {
    message += e.Message + Environment.NewLine;
}, true);
if (message != "") {
    throw new Exception(message);
}

How to set up configuration parameters of .NET Core service deployed in Azure?

Connect to deployed service via FTP and open appsettings.json corresponding to release build. Add configuration object having the same structure as assumed by the application.

Example

 "AzureStorageConfig": {
    "ConnectionString": "...",
    "FileContainerName": "..."
 }

Corresponding .NET class has following structure.

 public class AzureStorageConfig
 {
     public string ConnectionString { get; set; }
     public string FileContainerName { get; set; }
 }

It is used as template of constructor parameter.

public class BlobStorage : IStorage
{
    private readonly AzureStorageConfig storageConfig;
    public BlobStorage(IOptions storageConfig)
    {
        this.storageConfig = storageConfig.Value;
    }
}

ASP.NET Core AppSettings for Azure App Service

Deploy ASP.NET Core apps to Azure App Service

Azure Tips and Tricks

How to get path to opened script in Prolog?

Example

%% Tests that X is substring (sublist) of S.
substring(X,S):-
    append(_,T,S),
    append(X,_,T),
    X \= [].

%% Returns path to one of opened sources having given FileName.
file_path(FileName, Path):-
    %% Consequently selects all opened sources.
    source_file(SourceFileName),
    %% Converts strings to lists to reuse clauses for list processing.
    string_to_list(SourceFileName,SourceFileNameList),
    string_to_list(FileName,FileNameList),
    %% Tests that given file name is incorporated
    %% into currently selected file name.
    substring(FileNameList,SourceFileNameList),
    %% Subtracts from SourceFileNameList (containing full path)
    %% the list FileNameList containing only file name characters.
    append(PathList,FileNameList,SourceFileNameList),
    %% Converts list of characters into string and put it into Path.
    string_to_list(Path,PathList).

Read more

Prolog – Finding the current directory, relative directory for ‘tell’ predicate

Check if string is substring in Prolog

If you need to consult any script located in the same folder as loaded script use

concat_strings(S1,S2,Result):-
    string_to_list(S1,L1),
    string_to_list(S2,L2),
    append(L1,L2,ResultingList),
    string_to_list(Result,ResultingList).

consult_file(FileName):-
    %% Gets path to the main script.
    file_path('main.pl',Path),
    %% Adds given file name to path.
    concat_strings(Path,FileName,FullFileName),
    consult(FullFileName).