Foxit PDF adapted by Google Chrome

Google has announced to use FoxIT PDF libraries through which you can manipulate PDF operation at browser level.

Indeed, it will further push us to develop software that are specific to Google platform. However, it will be good to see how others, like IE Firefox, will cop up with challenges that will push them to extend support of such features into their browsers as well.

I have been playing around with FoxIT. Overall I could see it is a nice & clean sdk that works in different platform. It can also work with encrypted form.

For .net developers there is a piece of samples available directly from the link:

http://cdn01.foxitsoftware.com/pub/foxit/sdk/net/1.x/1.0/FoxitPDFSDKForNET102_enu.zip

The main problem that I find with such type of SDK is that you have to create even a table through coding. If you want to attach chart, graphs in your pdf then things can go too much of writing. That is the main reason that I am no convinced to for for this product or develop something that is specific to the browser.

Now what could be the solution?

The solution that I recommend to my client is to go through RDLC, which is free (technically not) and it is a Microsoft Product, which is easy to design as well.

Here is the sample code that I can guess solve the problem of generating PDF from RDCL.

Warning[] warnings;

string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
DataSet dsGrpSum, dsActPlan, dsProfitDetails,
dsProfitSum, dsSumHeader, dsDetailsHeader, dsBudCom = null;

//This is optional if you have parameter then you can add parameters as much as you want
ReportParameter[] param = new ReportParameter[5];
param[0] = new ReportParameter("Report_Parameter_0", "1st Para", true);
param[1] = new ReportParameter("Report_Parameter_1", "2nd Para", true);
param[2] = new ReportParameter("Report_Parameter_2", "3rd Para", true);
param[3] = new ReportParameter("Report_Parameter_3", "4th Para", true);
param[4] = new ReportParameter("Report_Parameter_4", "5th Para");


DataSet dsData= "Fill this dataset with your data";
ReportDataSource rdsAct = new ReportDataSource("RptActDataSet_usp_GroupAccntDetails", dsActPlan.Tables[0]);
ReportViewer viewer = new ReportViewer();
viewer.LocalReport.Refresh();
viewer.LocalReport.ReportPath = "Reports/AcctPlan.rdlc"; //This is your rdlc name.
viewer.LocalReport.SetParameters(param);
viewer.LocalReport.DataSources.Add(rdsAct); // Add datasource here

// NOTE: You can also pass first parameter as :Excel.
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
// byte[] bytes = viewer.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename= filename" + "." + extension);
Response.OutputStream.Write(bytes, 0, bytes.Length); // create the file
Response.Flush(); // send it to the client to download
Response.End();

In conclusion, I will give it a go with generating PDF through SDK if I don’t have an access to RDLC technology. If you want to manipulate generated PDF then you might want to see PDF SDK as well. Otherwise, for simple operation such as generating PDF, my recommendation is for RDLC.

Should we go with Delegate or Interface?

Delegate and Interface can provide you a a great mechanism that will separate the definition from the declaration.
Before we go into the detail about when to use what, let us first understand what is delegate (C/C++ pointers) and what is interface.

What is Delegate?

A delegate is a pointer variable declared as a variable of custom build type that can stores the reference to a function. The type should define method’s return type and its parameter types.

The following define a delegate type called StreamWriter

delegate bool StreamWriter (string text);

Here’s a complete example:

delegate void StreamWriter (string text);

class Test {
static void Main() {
StreamWriter t = ConsoleWriter;
t("Print this");
}

public void ConsoleWriter(string value) {
Console.WriteLine(value);
}
}

What is Interface?

An interface defines a template for its implementors. Just like an construction architect gives a blue print look through model, a software architect can use Interface as a tool for a blue print look for classes.

Should we go for Delegate or Interface?

  • Use a delegate in the following circumstances:
  • An eventing design pattern is used; that is multicast capability is needed.
  • It is desirable to encapsulate a static method.
  • The caller has no need to access other properties, methods, or interfaces on the object implementing the method i.e. The interface defines only a single method.
  • Easy composition is desired.
  • A class may need more than one implementation of the method; The subscriber needs to implement the interface multiple times.

Use an interface in the following circumstances:

  • There is a group of related methods that may be called.
  • A class only needs one implementation of the method.
  • The class using the interface will want to cast that interface to other interface or class types.
  • The method being implemented is linked to the type or identity of the class: for example, comparison methods.

In conclusion, it all comes down to your architecture. If your architecture needs event looks like callback operations. Then delegate wins over Interface. But if you want to define few methods along with some properties to be available through template then interface is your best choice.

How can I easily tell what caused the error – DbEntityValidationException ?

I came across with the situation where I have used Entity Framework 6.0. While calling SaveChanges on my DbContext, I get the following exception:

System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

 

After going into the exception detail all I could get to know that there is an exception at SaveChanges() method. So this is what I have done:

System.Data.Entity.Validation.DbEntityValidationException was unhandled
 HResult=-2146232032
 Message=Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
 Source=EntityFramework
 StackTrace:
 at System.Data.Entity.Internal.InternalContext.SaveChanges()
 at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
 at System.Data.Entity.DbContext.SaveChanges()
 at ConsoleApplication1.Program.Main() in c:UsersamitmSkyDrivecodeConsoleApplication1ConsoleApplication1Program.cs:line 19
 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
 at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
 at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
 at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
 at System.Threading.ThreadHelper.ThreadStart()
 InnerException:

No where it is telling me about why it has actually occured.

 

Solution:

To solve this problem what I did is I override SaveChanges method, catch the exception of type DbEntityValidationException then get an entire exception through Linq:

public partial class BookContainer : DbContext
 {
 public BookContainer()
 : base("name=BookContainer")
 {
 }
public override int SaveChanges()
 {
 try
 {
 return base.SaveChanges();
 }
 catch (DbEntityValidationException ex)
 {
 // Retrieve the error messages as a list of strings.
 var errorMessages = ex.EntityValidationErrors
 .SelectMany(x => x.ValidationErrors)
 .Select(x => x.ErrorMessage);
 var fullErrorMessage = string.Join("; ", errorMessages);
 var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
// Throw a new DbEntityValidationException with the improved exception message.
 throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
 }
 }

 

Now when I get the exception result, I get it with “Column name” that has caused this trouble.


System.Data.Entity.Validation.DbEntityValidationException was unhandled
 HResult=-2146232032
 Message=Validation failed for one or more entities.
See 'EntityValidationErrors' property for more details.
The validation errors are: The WebSite field is required.;
The WebSite field is required.;
The WebSite field is required.; The WebSite field is required.
 Source=ConsoleApplication1
 StackTrace:
 at ConsoleApplication1.BookContainer.SaveChanges() in c:UsersamitmSkyDrivecodeConsoleApplication1ConsoleApplication1Book.Context.cs:line 45
 at ConsoleApplication1.Program.Main() in c:UsersamitmSkyDrivecodeConsoleApplication1ConsoleApplication1Program.cs:line 19
 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
 at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
 at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
 at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
 at System.Threading.ThreadHelper.ThreadStart()
 InnerException:

How to download my documents from Azure Blob?

I have been in the position where I’ve been storing data on blob. However, there was a request to export all data in-house so that the same can be given to the third party.

The document ID, which is stored in the SQL database, is given as blob name.

I have managed to achieve this through the following piece of code:

storageConnectionString = “DefaultEndpointsProtocol=https;AccountName=<azure blob name >;AccountKey=<your private Key to blob>”

Settings a = new Settings();

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(a.StorageConnectionString);

using (SqlConnection conn = new SqlConnection(a.ConnectionString))
{
string sqlCommandText = @”select documentID, documentName from documentTable”;

SqlCommand command = new SqlCommand(sqlCommandText, conn);
conn.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(“tra”);

while (reader.Read())
{

int documentID;
if (int.TryParse((reader[“DocID”] ?? “”).ToString(), out documentID))
{

string documentName = reader[“DocName”].ToString();

int subfolderID = documentID / 1000 * 1000;
var blobreference = string.Format(“docsearch/{0}/{1}”, subfolderID, documentID);
// Retrieve reference to a blob named “photo1.jpg”.
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobreference);

if (File.Exists(string.Format(@”C:TRAResume{0}”, documentName)))
{

}
else
{
// Save blob contents to a file.
using (var fileStream = System.IO.File.OpenWrite(string.Format(@”C:TRAResume{0}”, documentName)))
{

if (Program.Exists(blockBlob))
{
blockBlob.DownloadToStream(fileStream);
}
}
}
}

}
}
}
}

public static bool Exists(CloudBlockBlob blob)
{
try
{
blob.FetchAttributes();
return true;
}
catch
{
return false;

}
}

How to create jquery Plugin?

Idea behind this plugin is to catch any event on <a> link and open the URL on new screen.

/*! jQuery anchormaaster Plugin – v1.0 – 18/2/2014
* Copyright CM (c) 2014 codebased@hotmail.com; Licensed MIT */

(function ($) {

// function that go through each link available in the given html object/
// and connect click event for opening a link to the new window.
$.fn.linkExtender = function (options) {

// default settings are merged with options parameter.
var settings = $.extend({
channelmode: 0,
fullscreen: 0,
height: 600,
left: 50,
location: 0,
menubar: 0,
resizable: 1,
scrollbars: 0,
status: 1,
titlebar: 1,
toolbar: 1,
top: 100,
width: 800
}, options || {});

var winprop = JSON.stringify(settings).replace(/}|{|”/g, ”).replace(/:/g, “=”);

// loop through all a link that has been within
return this.find(“a”).each(function () {

$(this).click(function () {

// it did not worked as expected by sending settings object.
// window.open($(this).attr(‘href’), “anchormasterwinpop”, settings);
// hence I’d to use winprop – string based value.
window.open($(this).attr(‘href’), “anchormasterwinpop”, winprop);

// STOP THE CLICK BUBLE!!!
return false;
});
});
};
})(jQuery);

How to Extend string object in JavaScript?

$(function () {

// — DOM is ready to action on.

/*
Summary: startsWith should take a single argument and return true if the provided string is a
prefix of this.
*/

if (typeof String.prototype.startsWith !== ‘function’) {

// checked and there is no startsWith (pre-defined) method.
String.prototype.startsWith = function (prefix) {
return this.indexOf(prefix) == 0;
};
} else {

// raise the log message for the developer.
raiseLog(“startsWith prototype is already defined. Unable to attach StringExtensinos.js.startsWith”);
}

/*
Summary: endsWith should take a single argument and return true if the provided string is a
postfix of this.
*/

if (typeof String.prototype.endsWith !== ‘function’) {

// checked and there is no endsWith (pre-defined) method.
String.prototype.endsWith = function (postfix) {
return this.indexOf(postfix, this.length – postfix.length) !== -1;
};
} else {

// raise the log message for the developer.
raiseLog(“endsWith prototype is already defined. Unable to attach StringExtensinos.js.endsWith”);
}

/*
Summary: This method should remove all html/xml tags from this.
*/

if (typeof String.prototype.stripHtml !== ‘function’) {
// checked and there is o stripHtml (pre-defined) method.
String.prototype.stripHtml = function () {
// By wrapping around p tag we have made
// sure that it is actually a valid html.
return jQuery(‘<p>’ + this + ‘</p>’).text();
};
} else {

// raise the log message for the developer.
raiseLog(“stripHtml prototype is already defined. Unable to attach StringExtensinos.js.stripHtml”);
}

// raise the log to the console. This tool is handy for Mr. developer – F12
function raiseLog(message) {

// ensure that we have a console function available.
// later we may move this object into more jquery form and add a plugin.
if (typeof console == “object” && typeof console.log == ‘function’) {
console.log(message);
}
}
});

How to (re)-register Office 365 Desktop setup?

First, please let each user run the Office 365 Desktop Setup on their computer:

Sign in MOP, click Downloads, and click the button Set up under Set up and configure your Office desktop apps.

If this issue persists, you can use OSAUI.exe /K to reset and reactivate Office Professional Plus:
1. Click Start, type cmd in the search field, press Enter.
2. Run OSAUI.exe /K, you can locate OSAUI.exe from C:Program Files(x86)Common FilesMicrosoft SharedOFFICE14.

Then, it will prompt for user’s Office 365 ID and password and let Office 365 service retrieves a new product key.

If the commands above don’t work, please try OSAUI.exe /F to see if it works.

How can I test query without having any infrastructure?

Well I have faced very similar question on Sqlite. That, how can I check my sqlite query without installing any software?

I came across with the website called sqlfiddle.com.

In this website I could select different platform such as Sqlite, mySQL and even postgreSQL.

Here is what I have tried with an example of sqlite: http://sqlfiddle.com/#!7/d246c/1

 

 

ITIL: Change Management Process

Change Management Process

Purpose

The purpose of this process is “to control the lifecycle of all changes, enabling beneficial changes to be made with minimum disruption to IT services.
Objective

  • Keep abreast of the changes that happen in the business environment.
  • Ensure that changes are recorded and evaluated, and that authorized changes are prioritized, planned, tested, implemented, documented and reviewed in a controlled manner.
  • To control the items recorded in the configuration management system (CMS).
  • Optimize risk for the business.

Scope

The scope of this process covers everything that require changes, from the architecture and infrastructure to the processes, documentation, metrics, and tools that support your services, as well as changes to IT services and configuration items.

This scope covers changes that are required to run IT Services. However, it can exclude some changes:

  • Minor operational changes that need to be done as part of day-to-day management of the infrastructure may also excluded from the change management process.
  • You don’t need to enter a change request record if you are performing troubleshooting steps to restore normal service in response to an incident.
  • Restarting a client machine not require any change request. However, if an application server requires a reboot, then the action of rebooting may have an effect on large user population and requires a change request.

Type of changes

  • Standard changes: All those changes that has a pre-authorized approach to its execution. These changes are well-known and clearly understood risk. Because the procedures are known and risk is low; there is no steering committee approval is required; refer Change Management Process.
  • Emergency Changes: This type of change is in response to or in order to prevent a business-critical error. Emergency change advisory board (ECAB) should be given same rights as Change Advisory board.
  • Normal Changes: Where the request has came through Service Desk. The Seven Rs of assessment should be followed:

Who raised the change? What is the reason for the change? What is the return required from the change? What are the risks involved in the change? What resources are required to deliver the change? Who is responsible for the build, test and implementation of the change? What is the relationship between this change and other changes?

ITIL

Documents from Change Management:

The change schedule can be updated.

The projected schedule outage document can be updated.

The remediation plan should be in place to restore service back to normal; in case of change failure.

 

 

Bruce Tuckman's – Team Building Model

Bruce tuckman Model

 

 

tuckman’s forming storming norming performing four-stage model

The progression is:

forming
storming
norming
performing
Here are the features of each phase:

forming – stage 1

High dependence on leader for guidance and direction. Little agreement on team aims other than received from leader. Individual roles and responsibilities are unclear. Leader must be prepared to answer lots of questions about the team’s purpose, objectives and external relationships. Processes are often ignored. Members test tolerance of system and leader. Leader directs (similar to Situational Leadership® ‘Telling’ mode).

storming – stage 2

Decisions don’t come easily within group. Team members vie for position as they attempt to establish themselves in relation to other team members and the leader, who might receive challenges from team members. Clarity of purpose increases but plenty of uncertainties persist. Cliques and factions form and there may be power struggles. The team needs to be focused on its goals to avoid becoming distracted by relationships and emotional issues. Compromises may be required to enable progress. Leader coaches (similar to Situational Leadership® ‘Selling’ mode).

norming – stage 3

Agreement and consensus is largely forms among team, who respond well to facilitation by leader. Roles and responsibilities are clear and accepted. Big decisions are made by group agreement. Smaller decisions may be delegated to individuals or small teams within group. Commitment and unity is strong. The team may engage in fun and social activities. The team discusses and develops its processes and working style. There is general respect for the leader and some of leadership is more shared by the team. Leader facilitates and enables (similar to the Situational Leadership® ‘Participating’ mode).

performing – stage 4

The team is more strategically aware; the team knows clearly why it is doing what it is doing. The team has a shared vision and is able to stand on its own feet with no interference or participation from the leader. There is a focus on over-achieving goals, and the team makes most of the decisions against criteria agreed with the leader. The team has a high degree of autonomy. Disagreements occur but now they are resolved within the team positively and necessary changes to processes and structure are made by the team. The team is able to work towards achieving the goal, and also to attend to relationship, style and process issues along the way. team members look after each other. The team requires delegated tasks and projects from the leader. The team does not need to be instructed or assisted. Team members might ask for assistance from the leader with personal and interpersonal development. Leader delegates and oversees (similar to the Situational Leadership® ‘Delegating’ mode).

 

 

Reference :

http://www.businessballs.com/tuckmanformingstormingnormingperforming.htm

Book: Professional Scrum Development with Microsoft Visual Studio 2012.