Saturday, September 6, 2014

Some overview of Entity Framework implementation

  1.         private agsEntities agsEntities = new agsEntities(connectionstring);
  3.         public ObservableCollection<FAMILY> FamilyCollection.....
  4.         ..........INotify
  7.         public ObjectQuery<FAMILY> FamiliesQuery;
  8. // FAMILY class is defined as:      public partial class FAMILY : EntityObject
  9. // mostly this was autocreated by EF
  10.         public ObjectQuery<FAMILY> GetFAMILIESQuery(agsEntities agsEntities)
  11.         {
  12.             ObjectQuery<FAMILY> fAMILIESQuery = agsEntities.FAMILIES;
  13.             return fAMILIESQuery;
  14.         }
  16.         private CollectionViewSource _familiesViewSource;
  17.         public CollectionViewSource FamiliesViewSource
  18.         {
  19.             get
  20.             {
  21.                 if (_familiesViewSource == null)
  22.                     GetFamilyViewSource();
  23.                 return _familiesViewSource;
  24.             }
  25.         }
  27.         private void GetFamilyViewSource()
  28.         {
  29.             // Load data into FAMILIES
  30. //this is ObjectQuery<T>
  31.             this.FamiliesQuery = this.GetFAMILIESQuery(this.agsEntities);
  32. //this is a CollectionViewSource......
  33.             this._familiesViewSource = new CollectionViewSource();
  34. //this is an ObjectResult<T>
  35.             this._familiesViewSource.Source = this.FamiliesQuery.Execute(MergeOption.AppendOnly);
  36. //refresh the view (in this case a DataGrid is bound to FamiliesViewSource
  37.             this._familiesViewSource.View.Refresh();
  38. //and into an observable collection just in case
  39. //agsEntities.FAMILIES is defined by EF as:       public ObjectSet<FAMILY> FAMILIES
  40.             foreach (FAMILY thing in agsEntities.FAMILIES)
  41.                 FamilyCollection.Add(thing);
  43.         }

Friday, September 5, 2014

Installing/Using Entity Framework on Visual Studio 2010 with NPGSQL DDEXprovider extension

Win 7 - 64 bit
Visual Studio 2010 Ultimate SP1
.NET 4.0 only.

Entity Framework 6.1.30610.0, NpgSQL version , also includes Mono.Security.

DDEX Provider Extension ( plugin / add-in ) for VS 2010 only (none other)
- adds PostgreSQL to the Add Item | Create ADO.NET Entity Data Model menu.


Step 1: Extract the files from the DLL. Copy Npgsql.dll and Mono.Security.dll to an important system folder, like program files or windows, because they will be going in the system-wide GAC (Global Assembly Cache) and you dont want to delete them by accident if you had them in Downloads\stupidname.

Step 2:
RunVisual Studio 2010 as Administrator, click "Tools | Visual Studio Command Prompt" (this launches an elevated / admin command prompt, WITH the proper PATH Variables to find gacutil. If you cannot find gacutil, I have provided it, it is also located in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\
Make sure you point it to the right path- take note that program files is administrator only. Run the following command to Install to the GAC.

gacutil -i "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Npgsql40\Npgsql.dll"
gacutil -i "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Npgsql40\Mono.Security.dll"

Step 3:
Extract NpgsqlDdexProvider.rar anywhere and Double Click the NpgsqlDdexProvider.vsix file (in  to load the provider into the menu)

Step 4:
In the same Admin Command Prompt, run notepad.exe and edit the machine.config (needs admin)


Search for <DbProviderFactories>  inside <> and add the following line. Take note that the existing entry has a closing </DbProviderFactories> tag on the end of the line. You must add it before this. Formatting it with Enter, Tabs, and spaces are ok, like XML code.

    <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
For example, This is the way it is written on my own computer:

<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />

Step 5:
Open your visual studio solution / project that you want to use. Right click "Add references" and locate and add 4 of the 6 DLL files you extracted from NpgSQL-EF.rar (Mono.Security is not needed, Legacy is not needed) - so you need these 4: EntityFramework.dll , EntityFramework.SqlServer.dll , Npgsql.dll , Npgsql.EntityFramework.dll

Step 6:
A new file named "App.config" was created at the bottom of your project. Locate the <providers> section and add this provider:
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
If you need to use legacy, for some reason, add:
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFrameworkLegacy" />

Step 7:
Re-Build your project. "Build menu | Rebuild"

Step 8:
Right Click your PROJECT itself in solution explorer.
Add -> New Item...
ADO.NET Entity Data Model
Now, Follow these nice Instructions made for 2013, the first picture has 4 icons instead of 2, so you want to:
"Generate From Database"

(Where I got the procedure from - written for 2013: )

It took me a very long time to figure this out, alot of errors, I couldnt find the extension, I needed to compile it myself, and I needed Visual Studio 2010 SP1 SDK to do it.

Saturday, August 23, 2014

FileTime 1.0

Download FileTime version 1.0

FileTime, v1.0 - Can modify folder and file timestamps in bulk / recursively.

Feature: Bulk timestamp modification based on rules.

When you copy files with windows, it changes the dates of files to the time you copied it. But the "Modification" date is still intact. The folder dates however are completely changed, and with this program, you can bulk fix them based on the rule you choose. (usually using the intact file modification time to fix the 3 wrong dates on the parent folder. For file moves, the situation is a bit better, only the date accessed gets messed up (IMO the least useful of the three). For folder moves, oddly, the folder creation date is the only one that remains intact.

Mode 1: Standard
Mode 2: Set Folder timestamps based on the files inside.

Created completely in C#, and .NET 2.0 using Visual Studio 2010 (WinForms).
Source is available upon request.

Authored by genBTC.
Date: August 24, 2014

How to Use:
Mode 1: Standard Mode
 Take note of the "Recurse" checkbox, and "Perform on files" checkbox.
 Starts at the root folder, works its way down(deeper).
Mode 2: Recursively Set Folders based on Files/Dirs Inside
 Starts at the root folder, inspects whats inside, decides what to use as the time source (either file or subdir), oldest/newest/random file, and which attribute (or any/random) based on what radiobuttons are used. Then sets the date of the root folder on what is in the root folder. Then it recursively digs deeper and repeats the same process for any/all subdirectorys. Does not change dates of any files.

After clicking the "Update" button, in either mode, a second "Confirm" window will open up.
This confirm window is an essential part of the program, where you can double check what exactly will be done, remove from, add to, change date/times, and open Windows Explorer.
The confirm window has a choice of "Update if date is newer/older/always" - a filter mask, that applies once you click the final "Confirm" button.

-From Currently Selected cannot be selected if nothing on the right side is selected.
-To unselect something (since Ctrl click doesnt work) on the right side, there is a small blank empty space next to the scrollbar that you can click. (Outside of the first column).
-On the confirm window, there is an issue where selecting items will cause the checkboxes to change. I built in a protection circuit that will prevent this (to make it seem normal) but you will find that if you try to change the checkboxes within 800ms of selecting something, it won't let you. The other side of this means that if you manage to hold the mouse button down for more than 800ms between when you select something and when you let go, you will bypass the protection and the checkbox will change. I have not found a better solution for this, as it is inherent in the ListView control for WinForms.

A Side Note on Read Only Folders:
-Read only folders are actually not what you think they are. Windows uses the folder read-only flag for internal purposes. The checkbox in the Windows Explorer Properties window of a user folder serves only one purpose, it is there to allow a user to change the read-only status of All the sub-files inside the folder at once. It _is_ possible to change the folder read-only flag to "not read-only" (with attrib -r) but absolutely nothing is gained by doing this. This confusing checkbox is not to be confused with PERMISSIONS. For further reading  It is not recommended to change the read-only flag on folders such as C:\Windows\Fonts, because it literally is what makes the special custom view be displayed.  This program should still modify Timestamps of read-only FOLDERS but not read-only files (unless it is desired/set).