Skip to main content

Posts

Showing posts from November, 2011

Observer Pattern With C# 4.0

Observer Pattern "The Observer Pattern Defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically." Publishers + Subscribers = Observer Pattern C# Introduced , IObserver<T> and IObservable<T> which will help push-based notification,also known as the observer design pattern. The IObservable<T> interface represents the class that sends notifications (the provider); the IObserver<T> interface represents the class that receives them (the observer). T represents the class that provides the notification information. An IObserver<T> implementation arranges to receive notifications from a provider (an IObservable<T> implementation) by passing an instance of itself to the provider's IObservable<T>.Subscribe method. This method returns an IDisposable object that can be used to unsubscribe the observer before the provider finishes sending...

CRM to SendEmail

Send email functionality with CRM internal static Boolean SendEmail(string toAddress, Guid? fromPartyGuid, string subjectLine, string body, Guid? contactId,string templateName) { CrmService crmService = GetCrmService(); //[[FROM activity party for the email. activityparty fromParty = new activityparty(); fromParty.partyid = new Lookup(); fromParty.partyid.type = EntityName.queue.ToString(); fromParty.partyid.Value = fromPartyGuid; //]] //[[TO activity party for email activityparty toParty = new activityparty(); toParty.partyid = new Lookup(); toParty.partyid.type = EntityName.contact.ToString(); toParty.partyid.Value = (contactId.HasValue) ? contactId.Value : new Guid(""); //]] //[[Create a new email and set its properties email emailInstance = new email(); //set email parameters emailInstance.from = new ac...

Create Document Dynamically (Umbraco)

You can create document and publish the content during run time, Below code snippets helps you to do it. public class UmbracoUtils { /// <summary> /// Create and publish the document programatically /// </summary> /// <param name="nodeName"></param> /// <param name="properties"></param> /// <param name="documentType"></param> /// <param name="parentId"></param> /// <returns>node id</returns> public static int CreateDocument(string nodeName, Dictionary<string, string> properties, int documentType, int parentId, List<string> roles = null) { DocumentType dt = new DocumentType(documentType); umbraco.BusinessLogic.User u = new umbraco.BusinessLogic.User(0); // Create the document Document d = Document.MakeNew(nodeName, dt, u, parentId); // Add values...

Logger with UmbracoLog

Umbraco logger is powerful tool and It can be extended to use in your Umbraco application to log anything that you want to do, instead of using another logger to do the task. /// <summary> /// Logger to log Error/Debug/Warning to Umbraco log table /// </summary> public class Logger { public enum LogLevels { DEBUG = 1, WARNING = 2, ERROR = 3, NONE = 100 } public static LogLevels CurrentLevel { get; set; } private static string StrLoggedInUserId; public static void SetStrLoggedInUserId() { if (StrLoggedInUserId == null || StrLoggedInUserId == "NA") { if (HttpContext.Current != null) { HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie != null) ...