Friday, December 27, 2013

Visual C# - Avoiding Conflicts with Keywords

As a programmer, we all should be aware that keywords of a programming language cannot be used as identifiers. That is the case for Visual C# as well. We cannot use a keyword as an identifier. As we are aware that .NET framework is multilingual such conflicts can happen when we are referring libraries written in another language. An identifier in the external library can be conflicting with C# language.
The way to avoid this is by using the '@' symbol as a prefix to such identifiers. Ideally we cannot use 'class' as an identifier in C#. But this can be made possible by using it as '@class'. This is legal and is same as 'class'.

This is not the case for contextual keywords. They can be used as identifiers without '@' symbol. Ambiguity cannot arise within the context in which they are used.
Hope this helps !!!

Visual C# - Compiler Options

Below are the list of commands/options available for the Visual C# compiler. These options can be used through the csc.exe executable available along with the .NET framework.
In general case, the executable will be under %SystemRoot%\Microsoft.NET\Framework\<Framework-version>. In this path %SystemRoot% is the windows directory.

OUTPUT FILES

  • /out:<file> - Specify output file name (default: base name of file with main class or first file)
  • /target:exe - Build a console executable (default) (Short form: /t:exe)
  • /target:winexe - Build a Windows executable (Short form: /t:winexe)
  • /target:library - Build a library (Short form: /t:library)
  • /target:module - Build a module that can be added to another assembly (Short form: /t:module)
  • /target:appcontainerexe - Build an Appcontainer executable (Short form: /t:appcontainerexe)
  • /target:winmdobj - Build a Windows Runtime intermediate file that is consumed by WinMDExp (Short form: /t:winmdobj)
  • /doc:<file> - XML Documentation file to generate
  • /platform:<string> - Limit which platforms this code can run on: x86, Itanium, x64, arm, anycpu32bitpreferred, or anycpu. The default is anycpu.

INPUT FILES

  • /recurse:<wildcard> - Include all files in the current directory and subdirectories according to the wildcard specifications
  • /reference:<alias>=<file> - Reference metadata from the specified assembly file using the given alias (Short form: /r)
  • /reference:<file list> - Reference metadata from the specified assembly files (Short form: /r)
  • /addmodule:<file list> - Link the specified modules into this assembly
  • /link:<file list> - Embed metadata from the specified interop assembly files (Short form: /l)

RESOURCES

  • /win32res:<file> - Specify a Win32 resource file (.res)
  • /win32icon:<file> - Use this icon for the output
  • /win32manifest:<file> - Specify a Win32 manifest file (.xml)
  • /nowin32manifest - Do not include the default Win32 manifest
  • /resource:<resinfo> - Embed the specified resource (Short form: /res)
  • /linkresource:<resinfo> - Link the specified resource to this assembly (Short form: /linkres), Where the resinfo format is <file>[,<string name>[,public|private]]

CODE GENERATION

  • /debug[+|-] - Emit debugging information
  • /debug:{full|pdbonly} - Specify debugging type ('full' is default, and enables attaching a debugger to a running program)
  • /optimize[+|-] - Enable optimizations (Short form: /o)

ERRORS AND WARNINGS

  • /warnaserror[+|-] - Report all warnings as errors
  • /warnaserror[+|-]:<warn list> - Report specific warnings as errors
  • /warn:<n> - Set warning level (0-4) (Short form: /w)
  • /nowarn:<warn list> - Disable specific warning messages

LANGUAGE

  • /checked[+|-] - Generate overflow checks
  • /unsafe[+|-] - Allow 'unsafe' code
  • /define:<symbol list> - Define conditional compilation symbol(s) (Short form: /d)
  • /langversion:<string> - Specify language version mode: ISO-1, ISO-2, 3, 4, 5, or Default

SECURITY

  • /delaysign[+|-] - Delay-sign the assembly using only the public portion of the strong name key
  • /keyfile:<file> - Specify a strong name key file
  • /keycontainer:<string> - Specify a strong name key container
  • /highentropyva[+|-] - Enable high-entropy ASLR

MISCELLANEOUS

  • @<file> - Read response file for more options
  • /help - Display this usage message (Short form: /?)
  • /nologo - Suppress compiler copyright message
  • /noconfig - Do not auto include CSC.RSP file

ADVANCED

  • /baseaddress:<address> - Base address for the library to be built
  • /bugreport:<file> - Create a 'Bug Report' file
  • /codepage:<n> - Specify the codepage to use when opening source files
  • /utf8output - Output compiler messages in UTF-8 encoding
  • /main:<type> - Specify the type that contains the entry point (ignore all other possible entry points) (Short form: /m)
  • /fullpaths - Compiler generates fully qualified paths
  • /filealign:<n> - Specify the alignment used for output file sections
  • /pdb:<file> - Specify debug information file name (default: output file name with .pdb extension)
  • /errorendlocation - Output line and column of the end location of each error
  • /preferreduilang - Specify the preferred output language name.
  • /nostdlib[+|-] - Do not reference standard library (mscorlib.dll)
  • /subsystemversion:<string> - Specify subsystem version of this assembly
  • /lib:<file list> - Specify additional directories to search in for references
  • /errorreport:<string> - Specify how to handle internal compiler errors: prompt, send, queue, or none. The default is queue.
  • /appconfig:<file> - Specify an application configuration file containing assembly binding settings
  • /moduleassemblyname:<string> - Name of the assembly which this module will be a part of

WCF: Contracts an Introduction

In WCF all services expose contracts. Now a question arises what is a contract?
 
Contract is a platform neutral and standard way of describing what the service does. There are four types of contracts,
  • Service Contracts
  • Data Contracts
  • Fault Contracts
  • Message Contracts
Here we will try to define and use of each contract type.
 
Service Contracts describe which operations the client can perform on the service.
 
Data Contracts define which data types are passed to and from the service. WCF defines implicit contracts for built in types int and string, but we can easily define explicit  opt-in data contracts for custom types.
 
Fault Contracts define which errors are raised by the service and how the service handles and propagates errors to its clients.
 
Message Contracts allow services to interact directly with messages.
 
We will look into each of these Contracts in later blogs.

WCF : Addresses an Introduction

Every WCF service is associated with an address which will be used by the client to access the service. A WCF address provides two important elements,
  • Location of the service
  • Transport Protocol
Location service indicates that the name of the target machine, site or network; a communication port, pipe or queue and an optional specific path, or URI
 
Transport Protocol also called as Transport Schema is used to communicate with the service. Normally WCF supports below transport schemas
  • HTTP or HTTPS
  • TCP
  • IPC
  • Peer Network
  • MSMQ
  • Service Bus
Normally addresses have the below format,
[base address]/[optional port]
 
At the same time the base address has the format,
[transport]://[machine name or domain][:optional port]
 
HTTP addresses uses the http for transport and can also use HTTPS for secure transport. Typically uses http addresses with outward facing internet based services and we can specify a port also. If a specific port is not provided it will take the default port. For HTTP it is 80 and for HTTPS it would be 443. A sample http address is as follows,
 
TCP addresses uses net.tcp for transport and typically include a port number. If the port number is not provided the default for the tcp address is 808. A sample tcp address is as follows,
net.tcp://localhost:8002/MyService
 
IPC Addresses or Inter Process Communication addresses use net.pipe for transport, to indicate the use of the Windows named pipe mechanism. In WCF, services that use IPC can only accept calls from the same machine. So we have to either provide the machine name or the localhost followed by a unique string for the pipe name. It is not possible for two named pipe addresses to share a pipe name on the same machine because we can open a named pipe only once per machine. A sample IPC address is as follows,
net.pipe://localhost/MyPipe
 
MSMQ or Microsoft Message Queue addresses use net.msmq for transport. We must specify the queue name. If the queue is private we must provide the queue type as well. Samples for the MSMQ is as follows,
net.msmq://localhost/private/MyService
net.msmq://localhost/MyService
 
Windows Azure AppFabric Service Bus addresses use sb, http or https for transport and must include the service bus address along with the service namespace.
sb://MyNamespace.servicebus.windows.net/
 
Now you must have got an overall idea on different types of addresses used in WCF.

Saturday, December 21, 2013

CRM 2011 - Using Report Control to add a report to Dashboard

There can be scenarios where we have to create custom reports to the dashboards. This can be achieved easily using the custom tool Report Control. Download the report control solution from here.
 
Import the solution to our organization.
 
Now keep the report ready in our organization either by creating a new report or by reusing an existing report.
 
Get the report's GUID from CRM which needs to be added to the dashboard. Keep that handy for further use.
 
Whether you are planning to create a new dashboard or an existing dash board, add a new web resource to the dashboard.
 
In the properties window, add the web resource "new_ReportControl". Give proper field name and properties for the web resource.
 
If "Restrict cross frame scripting where supported" and "Pass record object type and unique identifier as parameters" check boxes are checked, then uncheck them.
 
In the custom parameters field, add the GUID value for the report to be added.
 
Full article can be read here. There is another approach for this same objective but it didn't work for me though. You can read the article here.
 
That's it we are done with the new report in our dash board.
 
Hope this helps !!!

Tuesday, December 3, 2013

Windows - How to delete a service which is no longer used?

There can be scenarios where we have some services in the server which is no longer used. In such a scenario its better to delete the same.

For that what you can do is,
  1. Open the command prompt as administrator.
  2. Type the command sc delete <service name>
  3. Enter
The service is deleted from the list.

There are other options to do the same. But the above one helped me to delete the same. If you need to go for other options for any reasons please check here.

Hope this helped you.

Configuration for CRM Plugins

CRM plugins are always great feature where we can automate many functionality which we cannot automate from user interface. But almost eve...