Wednesday, March 6, 2013

Mac OSX | Installing PHP Composer under MAMP

Install MAMP:
This Assumed that you already install MAMP. If not just download and install from here.

Setup Bash Profile:
Open a terminal (Launchpad > Other > Terminal)

Biboyatienza-MacBook-Pro:~ biboyatienza$ open ~/.bash_profile


Then add/append the line below, at the time of this writing my MAMP is using php5.4.4

export PATH=/Applications/MAMP/bin/php/php5.4.4/bin:$PATH


Check PHP Setup And Install PHP Composer:
 Last login: Wed Mar 6 06:58:28 on ttys000  
 Biboyatienza-MacBook-Pro:~ biboyatienza$ php --version  
 PHP 5.4.4 (cli) (built: Jul 4 2012 17:28:56)   
 Copyright (c) 1997-2012 The PHP Group  
 Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies  
   with XCache v2.0.0, Copyright (c) 2005-2012, by mOo  
 Biboyatienza-MacBook-Pro:~ biboyatienza$ curl -s https://getcomposer.org/installer | php  
 #!/usr/bin/env php  
 All settings correct for using Composer  
 Downloading...  
 Composer successfully installed to: /Users/biboyatienza/composer.phar  
 Use it: php composer.phar  
 Biboyatienza-MacBook-Pro:~ biboyatienza$  

Tuesday, March 5, 2013

C# | How to write entry to Windows Event

Here's a sample code on how to write to Windows Event Logs.
Keep an eye on variable maximumCharacterThatTheWindowEventLogsCanHandled where I used 30,000 but for it's actually 32,766 :)

     private static void WriteToWindowsEventLog(string logs)  
     {  
       const string source = "biboyatienza Sample Windows Services";  
       const string log = "Application";  
       const int maximumCharacterThatTheWindowEventLogsCanHandled = 30000;  
       if (!EventLog.SourceExists(source))  
         EventLog.CreateEventSource(source, log);  
       string message = (logs.Length >= maximumCharacterThatTheWindowEventLogsCanHandled  
                   ? HttpUtility.HtmlEncode(logs).Substring(0, maximumCharacterThatTheWindowEventLogsCanHandled)  
                   : HttpUtility.HtmlEncode(logs));  
       EventLog.WriteEntry(source, message);  
     }  

Windows Event Logs | Log entry string is too long. A string written to the event log cannot exceed 32766 characters

 Date/Time: 05.03.2013 10:55:43  
 Method Name: CbtImportFromStaService.RunImportFromSta()  
 Error Details: Log entry string is too long. A string written to the event log cannot exceed 32766 characters.  
 Source: System  
 Stack Trace:  at System.Diagnostics.EventLog.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName)  
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)  
   at System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)  
   at System.Diagnostics.EventLog.WriteEntry(String source, String message)  
   at CBTImportFromSTA.WindowsService.Helpers.LogHelper.WriteToWindowsEventLogs(String logs)  
   at CBTImportFromSTA.WindowsService.Helpers.LogHelper.LogErrorsWindowsEventLogs(String exceptionContent)  
   at CBTImportFromSTA.WindowsService.Helpers.MailHelper.SendEmail(String exceptionContent, String optionalSubject)  
   at CBTImportFromSTA.WindowsService.CbtImportFromStaService.GetFirstXmlAttachmentOfEachEmail(MailMan mailman)  
   at CBTImportFromSTA.WindowsService.CbtImportFromStaService.FetchEmailsFrom_cbtresults_dot_import_at_osm_dot_biz_AndExtractOneXmlFileFromEachEmail()  
   at CBTImportFromSTA.WindowsService.CbtImportFromStaService.RunImportFromSta()