Using BSON type provider in F# Script - mongodb

I'm trying to use the Bson type provider to do some work with a MongoDB database. in an F# script.
I've taken the following steps.
I've created the Bson files by using:-
mongodump /host:starbug /db:Logger /out:data
I've built the type provider from the source from https://github.com/visemet/FSharp.Data.Bson
I've created the following F# script file:
#I "../../FSharp.Data.Bson/bin" // Location of Dll's created by step 1.
#r "FSharp.Data.Bson.Runtime.dll"
#r "FSharp.Data.Bson.dll"
#r "MongoDB.Bson.dll"
open BsonProvider
type AccessLogs = BsonProvider<"./data/EkmLogger/access_logs.bson">
type SQLiteLogs = BsonProvider<"./data/EkmLogger/sqlite_logs.bson">
let accessLogs = AccessLogs.GetSamples().[0]
But the last line is showing the following error in VS 2013
The type provider 'BsonProvider.ProviderImplementation.BsonProvider' reported an error in the context of provided type 'BsonProvider.BsonProvider,Path="./data/Logger/access_logs.bson"', member 'GetSamples'.
The error: Could not load file or assembly 'FSharp.Data.Bson.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified. C:\Development\fsharp-scripts\Logger\AccessSqliteStats.fsx
Any idea what's wrong?

Related

Check for empty file and quit cakebuild

I am attempting to write a check in my Cake build script to pull in a file from BuildParameters and check if the file contents are empty -- if contents are empty, throw an exception and quit the build.
I am attempting to use FileReadText from the FileHelpers namespace but for some reason I cannot get my build to recognize the file command. I am following the syntax and documentation found here: https://cakebuild.net/api/Cake.FileHelpers/FileHelperAliases/97F5679A
Here is the code I am trying in build.cake:
var fileReadText= FileReadText(Parameters.TestParameters.TestListFP);
var fileText= fileReadText.ThrowIfNullOrEmpty(nameof(fileReadText));
The argument Parameters.TestParameters.TestListFP is set in my Parameters.cake file as such:
TestListFP = context.File("C:\Some\Path\some_file_name.txt");
Using the above code, I see this error:
error CS0103: The name 'FileReadText' does not exist in the current
context
Note that I do not have a ICakeContext in build.cake, just BuildParameters.
I tried to resolve the issue by adding using Cake.FileHelpers; at the top of my build.cake file, but then I see this error:
The type or namespace name 'FileHelpers' does not exist in the namespace 'Cake' (are you missing an assembly reference?)
The script works fine without my FileReadText code, so I know TestListFP is actually a valid file.
I think I am inherently misunderstanding how to use FileHelpers and FileReadText and I could not find any examples of usage in documentation or anywhere else. If anyone has guidance on how to use this method, or a better way to accomplish what I am trying to do, I would appreciate the help.
Have you added the #addin pre-processor directive, as mentioned here:
https://github.com/cake-contrib/Cake.FileHelpers/#cakefilehelpers
You can easily reference Cake.FileHelpers directly in your build script via a cake addin:
#addin "Cake.FileHelpers"

POSTGRESQL - ERROR: could not load library pgafis.so : undefined symbol: lfsparms_V2

I'm using PGAFIS library for fingerprint matching. For this i have installed postgresql and having some user defined c functions.
PGAFIS contain makefile, .control file, sql and unpacked sql file everything
I have compiled and pgafis.so file for the same and everyfile is on right location.
In my PGAdmin-III when i run CREATE EXTENSION pgafis it gives me following error:
ERROR: could not load library "/usr/lib/postgresql/9.4/lib/pgafis.so": /usr/lib/postgresql/9.4/lib/pgafis.so: undefined symbol: lfsparms_V2
SQL state: XX000
Please help. Thanks in advance
(This is a follow-up from Postgresql user defined c function issues)
I expect you forgot to link to the required library.
Try adding
PG_LIBS = -lmindtct
or whatever. If it's not on the default linker path you'll need to need to add -L/path/to/the/containing/directory to PG_CPPFLAGS too.

How to read a file content from EF Configuration.cs file?

I am using EF 6 Code-base migration.
I want to read the file from Configuration.cs Seed() method to insert as default data.
I am using HostingEnvironment.MapPath() as below:
string _homeContent = System.IO.File.ReadAllText( HostingEnvironment.MapPath(#"~/Data/DefaultContents/Home.html"));
But HostingEnvironment.MapPath return null value when I run the Update-database command from Package-Management Console.
Running Seed method.
System.ArgumentNullException: Value cannot be null.
Parameter name: path
at System.IO.File.ReadAllText(String path)
Kindly advise how to read the physical file from Configuration.cs Seed() method.
May I answer by myself.
Server.MapPath and HostingEnvironment.MapPath is not available in this time because HttpContext object is not ready yet.
AppDomain.CurrentDomain.BaseDirectory return "..\your project directory\bin"
E.g. C:\YourSolutionDirectory\YourProjectDirectory\bin
But we need to go up from "bin" folder, so that using Path.Combine() method and get exact file path.
string homeFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", #"Data\DefaultContents\Home.html");
Result: C:\YourSolutionDirectory\YourProjectDirectory\Data\DefaultContents\Home.html

ConfigurationType error when using Entity Framework migrate.exe with multiple migration configurations

In my solution, I have a Data project that contains multiple Entity Framework 6.1.3 migration configuration classes. My goal is to run Entity Framework migration steps - for one of them, against an existing database - from TeamCity (or, to simplify, from a command line).
The migration configuration class I am using is the following:
namespace MyProject.Data
{
public partial class MyCustomMigrationConfiguration :
DbMigrationsConfiguration<MyCustomContext>
{
public MyCustomMigrationConfiguration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = true;
MigrationsDirectory = #"Migrations\MyCustomContext\MigrationSteps";
}
}
}
I can successfully run the following command from Package Manager Console in Visual Studio:
Update-Database -Verbose -StartUpProject Web -ConnectionString '-my
connection string here-' -ConfigurationTypeName
MyCustomMigrationConfiguration -ConnectionProviderName
'System.Data.SqlClient'
I want to do the same thing from a command line, so I run this:
migrate.exe MyProject.Data.dll "MyCustomMigrationConfiguration"
/startUpConfigurationFile=MyProject.Web.dll.config
/connectionString="-my connection string here-;"
/connectionProviderName="System.Data.SqlClient" /verbose
However, I get the following error:
ERROR: The migrations configuration type
MyCustomMigrationConfiguration was not be found in the assembly
‘MyProject.Data'.
Any suggestions on how to fix this, please?
You can specify the directory where are all the dependencies (assemblies) needed to run your code. You can do that by using the /startUpDirectory option, as explained here:
Specify working directory
Migrate.exe MyApp.exe /startupConfigurationFile=”MyApp.exe.config” /startupDirectory=”c:\MyApp”
If you assembly has dependencies or reads files relative to the working directory then you will need to set startupDirectory.
Found the solution (I ended up downloading the Entity Framework source code from http://entityframework.codeplex.com/ and debugging the migrate console application).
Apparently, all the dependencies of MyProject.Data.dll need to be copied in the same folder with it and migrate.exe, otherwise the Entity Framework migrate.exe tool will throw the misleading error message above.
Entity Framework could really use better error handling and a clearer error message in this case.
As a reference to Entity Framework devs: the following code in TypeFinder.cs was returning a null type because the dependencies of MyProject.Data.dll were not copied in the folder of migrate.exe:
type = _assembly.GetType(typeName, false);

Catalog access method clarification

I have stored the macro in a local working directory as shown
I would like to access the macro with following code:
libname test 'C:\Users\Desktop\Enhancement\';
filename prtsort catalog 'TEST.SASMACR';
%include prtsort(Printtext) ;
WHile it gives following error:
ERROR: Entry PRINTTEXT.SOURCE not found in catalog TEST.SASMACR.
ERROR: Cannot %INCLUDE member Printtext in the aggregate PRTSORT.
ERROR: Entry PRINTTEXT.SOURCE not found in catalog TEST.SASMACR.
ERROR: Cannot %INCLUDE member Printtext in the aggregate PRTSORT.
Anyone can delight me, which part i did wrong? Thanks
If you are trying to re-use stored compiled macros that have previously been saved in your folder then you don't need to %include them from the catalogue. After defining your libref test pointing to the folder, you just need to set
option mstored sasmstore = test;
and your session should pick up all macros stored there automatically.