February 2012 - Posts

Asp.net MVC 3 Deployment

With MVC 3 you could deploy to remote site, create package.

in My case I need to create the package.

How to do that?

in your vs 2010 sp1.

  • Right Click on the MVC3 Project –>Add deployable Dependency-> Check “asp.net MVC” and “asp.net webpages with Razor Syntax”, this will make sure all the presequites dll are being copied to bin folder
  • Right click again –> Build deployment Package
  • Go to that Folder setting, get the package or zip file

Now if you have problem running that cmd/bat file , it’s related to ms deploy.

Install Ms deploy in the server

you can import manually on your IIS manager console in the server.

just choose the website and click Import and choose the zip file.

Done Smile

http://weblogs.asp.net/scottgu/archive/2010/09/13/automating-deployment-with-microsoft-web-deploy.aspx

Remember that on that machine must have :

everything under world wide web->application…-> Checked

“regiis –I” is your latest weapon

.

Share this post: | | | |
Posted by cipto with no comments

Telerik asp.net MVC Extension Custom Grid Command

I’ve got a case that I want to do something after Removing Item on Shopping Cart Grid. I wanna do other action which my subtotal is outside of the grid.

so I need to passed extra data also on the action.

Using and following Telerik API for Grid.

the way how you do it is

on Telerik Grid

   1: columns.Command(commands =>
   2:        {
   3:            commands.Custom("Remove")
   4:                   .Text("Remove")
   5:                   .DataRouteValues(route => route.Add(o => o.OrderItemID).RouteKey("OrderItemID"))
   6:                   .Ajax(true)
   7:                   .Action("RemoveItemCart", "ShoppingCart").HtmlAttributes(new { style = "text-align: center" });
   8:  
   9:        });
  10:  
  11:     }).Footer(false)
  12: .ClientEvents(events => events.OnComplete("onComplete")))

On Controller Return JSON and our custom Data

   1: [HttpPost]
   2:       public JsonResult RemoveItemCart(int id)
   3:       {
   4:           var cartID=ShoppingCart.GetCartId(this.HttpContext);
   5:           ShoppingCart.RemoveFromCart(cartID, id);
   6:           var cartmodel = GetAllItems();
   7:           return Json(new {items=cartmodel.CartItems,Total = cartmodel.Total});
   8:       }

On our Javascript event which is on complete , Bind Grid manually

   1: function onComplete(e) {
   2:        if (e.name == "Remove") {
   3:            debugger;
   4:            var grid = $("#ShoppingCartGrid").data("tGrid");
   5:            grid.dataBind(e.response.items);
   6:            $('#subtotal').html(e.response.Total);
   7:        }    
   8:    }
Share this post: | | | |
Posted by cipto with no comments

asp.net mvc 3 and EF , Circular Reference Issue

This problem is caused by the default JSON serializer is not smart enough to deal with Entity of EF reference each other.

there are couple of solving you can find on internet using Automapper, other better json serializer, but In my Opinion the best one is simply, Generate your ViewModel with what property you need.

although I enable all Lazyload that I disabled, am using codefirst. so put back again virtual the issue remain.

In your View page. avoid using Model.Entity.ReferenceEntity.ColumnName, instead generate what you want .

Example :

Order and OrderItems.

avoid using OrderItems.Product.Description

instead in your ViewModel generate ProductDescription.

and on your linq to Entity query

 

   1: var results = (from a in db.tblCmOrderItems.Include("tblCmProduct")
   2:                                  where a.orderID == order.orderID
   3:                                  select new ShoppingCartItem
   4:                                  {
   5:                                      ValidUntil = validUntil,
   6:                                      UnitPrice = a.unitPrice,
   7:                                      UnitCost = a.unitCost,
   8:                                      Quantity = a.quantity,
   9:                                      OrderItemID = a.orderItemID,
  10:                                      ProductName = a.tblCmProduct.productName,
  11:                                      ProductDescription = a.tblCmProduct.description,
  12:                                      ProductID = a.tblCmProduct.productID
  13:                                  }).ToList();

 

This way You keep the rule of Thumb View only deal with what being passed on and follow the ViewModel Concept.

Share this post: | | | |
Posted by cipto with no comments

How to Debug CRM 2011 Plugin

Well there are a couple of ways and steps of doing it.

Like putting it in sandbox, enable it by registry editing.

and than attach debugger….

But it turns out you could do something like Die in PHP.

What ever you put on Trace , it will appended on the message when exception is thrown.

localContext.Trace([Output server variable)

throw new Exception(“Trace message”);

and you should see it when you Trigger it correctly Smile

Share this post: | | | |
Posted by cipto with no comments

How to Capture WCF/HTTP Post using Fiddler on IIS server

This is very interesting. as I’ve got to examine whether a call is being made to a Services/WCF on external site.

on Localhost Fiddler which capture everything correct. because fiddler run under your local account.

If you test on IIS, it’s different though . Worker process run under network service.

you can change it to whatever. but that is a hassle, so complicated.

Since it’s during post back than call services.

When we do simple enabled Fiddler on firefox. it will just set that browser proxy to 127.0.0.1:8888 where Fiddler listen to.

But that is not enough it’s not capturing what are being post and what are the external UI.

The best approach is by adding on web.config

<defaultProxy>
      <proxy
              usesystemdefault="False"
              bypassonlocal="True"
              proxyaddress="
http://127.0.0.1:8888"             
              />
    </defaultProxy>

 

 

You can now see on fiddler Smile

http://www.west-wind.com/weblog/posts/2009/Jan/14/Monitoring-HTTP-Output-with-Fiddler-in-NET-HTTP-Clients-and-WCF-Proxies

Share this post: | | | |
Posted by cipto with no comments

iTextSharp

iTExtSharp is a port from java iText. an open source to export things to PDF

you could actually export HTML to PDF. it’s very powerful as you can generate on the fly. just a bit of twist you can make report with PDF, or export things to PDF.

since PDF is like vector based. it’s very scalable meaning when printing it can scale to your preferred page size.

unfortunately there is not enough documentation. and the java thing seems to be a bit different in .Net one.

I am using the latest at this article is written, it’s 5.1.3. You could have the iText documentation in Java, or books like iText in action second edition.

things change a bit in property name. like to set the PageEvent actually it’s on writer.PageEvent=[your custom event]

To Export from HTML to PDF ,follow this pattern. this is also example for adding footer.

public class GeneratePDFHandler : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{

context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
CultureInfo culture = new CultureInfo("en-AU");
string ReferalID = context.Request.QueryString["id"];

string contents = File.ReadAllText(context.Server.MapPath("~/template.htm"));
// Create a Document object
iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 50, 50, 25, 25);

// Create a new PdfWriter object, specifying the output stream
var output = new MemoryStream();
var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, output);
writer.PageEvent = new MYPdf();
// Open the Document for writing
document.Open();
// var logo = iTextSharp.text.Image.GetInstance(context.Server.MapPath("~/Images/IoptixxGray.gif"));
//logo.SetAbsolutePosition(10, 10);
//document.Add(logo);

contents = contents.Replace("[Name]", "Cipto");
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null);


foreach (var htmlElement in parsedHtmlElements)
document.Add(htmlElement as IElement);



document.Close();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename=WorkOrder-{0}.pdf", ReferalID));
context.Response.BinaryWrite(output.ToArray());
}
}

Template.htm as you might guess has the html and a marker to be replaced in above example it’s [Name]

 

public class MYPdf : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document)
{

Rectangle rect=new Rectangle(50, 50, 545, 792);
var footerfont = FontFactory.GetFont("Arial",8);
ColumnText.ShowTextAligned(writer.DirectContent,
Element.ALIGN_CENTER, new Phrase("My Footer Message", footerfont),
(rect.GetLeft(0) + rect.GetRight(0)) / 2,
rect.GetBottom(0) - 45, 0);
}
}
For images you can add logo. or embed it in your html template. but the source must be a full internet URL

 

Share this post: | | | |
Posted by cipto with no comments

CRM 2011 SDK explanation Part 1

if you are some one that is sitting between CRM 4 sdk, and 2011 SDK. you'll end up and should upgrade using the 2011 one.

Because 2011 support lot's of fix, improvement, easy to use API than 4th version.

since CRM 2011 use WCF there has to be lot's of improvement, also from the size compression being transported.

CRM 2011 SDK support backward compability,as when it deals with CRM 4. it point to the old asmx services , 2007/xxx.asmx

 

use organizationservice.LoadProperty to load your Lazy load relation property, for example invoices_products

CRM 2011 support Federation Authenticaiton/Claim based authentication.

You only need to use the crmHelperClass and provide username and password with out domain.

 

Solution is major improvement in 2011. a lot of thing are being simplefied because of this.

on 4th version you've got that metadata thing. but Solution means you can package you custom entity, Plugin and import it again to another CRM instance

 

Plugin also being enhanced. Now after you install the Developer Tools. which comes with the SDK

You'll get Solution template, Plus CRM Explorer. Plus when developing Plugin/Workflow you get what they called CRM Package, right click and Deploy :)

You'll get Default class called Plugin which provide you with localContext, you can access the servicecontext,organizationcontext,entity here.

It's a very good one, because now you can implement Base plugin for multiple entities, before you need to create class and another class

It's also recommend to deploy it to your Solution. that way when you moved from staging, to prod server. you only import the solution

the CRM 2011 service is also supporting for you to upload your CRM through SDK

 

most easy to use is Early bound, generate it using CRMSVCutil which will generate strong type for you.

to make sure things is there or not. think of solution.

CRM 2011 use WIF 

LINQ to FetchXMl service request is deprecated

 

 

Share this post: | | | |
Posted by cipto with no comments

Google map is so god damn easy

Google map v3 is very easy to implement. it will take you just minutes to create great application

it's HTML5 and mobile compatible also. sadly again not showing on IE7.

You could add Markup , and "Controls" to the map . so that the map take 1 full screen, and your control (html element)

are shown as you choices, on top left, center , bottom right as you like.

you can change icon easily by defining the icon. so cool

all you have to do is have the geocode location.

 

like on mine it needs filter by post code,  so search through the geolocation, set center and zoom in

 

 

 

Share this post: | | | |
Posted by cipto with no comments

Ninject and customMembership asp.net mvc 3

you use Custom Membership and Ninject and inside your custom membership you'd like to use Property Injection.

The result is always null. why? because asp.net has it's own static property for membership.

which is membership.provider. and this instance is not part of instance ninject management.

to workaround it , you need to use kernel.inject  . but on the generate aspnetmvc.cs you would see that it's injection on PreApplicationStart event and won't let you.

so use on PostApplicationStartMethod

[assembly: WebActivator.PreApplicationStartMethod(typeof(TopRankFantasy.App_Start.NinjectMVC3), "Start")]
[assembly: WebActivator.PostApplicationStartMethod(typeof(TopRankFantasy.App_Start.NinjectMVC3), "RegisterMembership")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(TopRankFantasy.App_Start.NinjectMVC3), "Stop")]

public static void RegisterMembership()
        {
            bootstrapper.Kernel.Inject(Membership.Provider);
        }

Share this post: | | | |
Posted by cipto with no comments
Filed under: