Saturday, 23 July 2016

C# Retrieve Get Directory User Attributes

UserPrincipal user = UserPrincipal.FindByIdentity(GetPrincipalContext(), IdentityType.SamAccountName, alias);
if (user != null)
{   
    DirectoryEntry directoryEntry = (user.GetUnderlyingObject() as DirectoryEntry);
    DirectorySearcher adSearch = new DirectorySearcher(directoryEntry);   
    adSearch.SearchScope = SearchScope.Subtree;
    adSearch.Filter = "(&(ObjectClass=user)(sAMAccountName=" + alias + "))";
    SearchResult sResult = adSearch.FindOne();

    if (sResult.Properties.Contains(attribute))
        propertyValue = sResult.Properties[attribute][0].ToString();
}


Monday, 16 May 2016

Run a C# .cs file from a Powershell Script

$source =
@"
   public class BasicTest
   {
     public static int Add(int a, int b) {
        return (a + b);
     }

     public int Multiply(int a, int b) {
       return (a * b);
     }
   }
"@

# type definition - must be declared
Add-Type -TypeDefinition $source
 

# access a static method
[BasicTest]::Add(4, 3)

# create instance of class and call a non-static method
$basicTestObject = New-Object BasicTest
$basicTestObject.Multiply(5, 2)



Wednesday, 4 May 2016

Escape text for HTML - Embed Symbols in HTML

ASP.NET 
    var encoded = System.Web.HttpUtility.HtmlEncode(un_encoded);

C# console and Windows apps 
    var encoded = System.Security.SecurityElement.Escape(un_encoded);


Tuesday, 12 April 2016

Using Checksums to test for Unexpected Database Schema Changes

USE [DATABASE-NAME]
GO

SELECT CHECKSUM_AGG (CHECKSUM (
                TABLE_NAME,
                COLUMN_NAME,
                CHARACTER_MAXIMUM_LENGTH ))
FROM INFORMATION_SCHEMA.COLUMNS


Thursday, 7 April 2016

Database Object Generator

Database Object Generator creates objects for tables in a database. Objects are generated as C# code. Here are two different DataObject Generators:

  • DbObjectGenerator
    Plug-in for Visual Studio. no DLLs, no maintainability issues, and no startup performance cost... more 
  • CodeTrigger
    Code Generation For C#, WPF, WCF, SQL SERVER/ORACLE/MYSQL and Visual Studio 2010-2015... more 

CoffeeScripts

CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way... more


Analysis Service in Power BI Report Server

 We couldn’t connect to the Analysis Services server. Make sure you’ve entered the connection string correctly... link