jueves, 15 de noviembre de 2012

LOG4NET filename as datetime



  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>



  <log4net>
  <appender name="FileAppender" type="log4net.Appender.FileAppender">
    <file type="log4net.Util.PatternString" value="myPrefix%date{yyyyMMdd}.fileExtension" />

    <appendToFile value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline"/>
    </layout>
  </appender>
  <root>
    <level value="All"/>
    <appender-ref ref="FileAppender"/>
  </root>
  </log4net>

viernes, 7 de septiembre de 2012

Jquery Selector example


This Gets all input type=text and return a string containing a list
with the Ids and the values.
example:

Id0:500,Id1:501,Id2:502,Id3:503,Id4:504,


<script> var parameters = '';
     $('[type="text"]').each(function (index)
     {
         parameters += $(this).attr('id') + ":" + $(this).attr('value') + ',';
     });


alert( parameters );

</script>

Explanation:

[ attribute=value] in this case attribute=type, value=text.

For more information about jquery selectors visit:http://api.jquery.com/category/selectors/

jueves, 2 de agosto de 2012

SRP: Single Responsibility Principle THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE.


I want to show you  how SRP helps us to deal with the requirement and with the  requirement  changes. 
This is a real life problem I encountered in my work.

1)
The Idea is to build a WindowServices that runs somes processes in backGound.
There are 7 processes each one has its own hour to run and it is set from the database.

The first implementation was this:
We have a timer that polls the database each 5 minutes and checks if the process should run.
The process excecution is serial.




















2) The next change we were asked to do was to run processes in paralell, then the Services Class had  to be modified



















3) Next the services were installed in 3 nodes and now we could have a sincronitalization problem, then the Services Class had to be modified to fix it.




We noticed that "services class" had at least two differents responsibilities, one is To check the timer and the other one is to checks if the process should run.
In short we could add new functionalities such as Loggings, Exception Hangling and so on.
A better soluction  could have been to give the responsibility to check the process and run the process to another new class.It could be called ProcessDispatcher, and write new interfaces. 









Para ver otro ejemplo de este principio ver este el blog de NELO.











jueves, 12 de julio de 2012

Slipt string/int in Oracle 11g

Steps:

1)
CREATE OR REPLACE TYPE INTEGER_TABLE AS TABLE OF INTEGER

2)


CREATE OR REPLACE FUNCTION SPLIT_INT
(
    P_LIST VARCHAR2,
    P_DEL VARCHAR2 := ','
) RETURN INTEGER_TABLE PIPELINED
IS
    L_IDX    PLS_INTEGER;
    L_LIST    VARCHAR2(32767) := P_LIST;
BEGIN
    LOOP
        L_IDX := INSTR(L_LIST,P_DEL);
        IF L_IDX > 0
THEN
            PIPE ROW(SUBSTR(L_LIST,1,L_IDX-1));
            L_LIST := SUBSTR(L_LIST,L_IDX+LENGTH(P_DEL));
        ELSE
            PIPE ROW(L_LIST);
            EXIT;
        END IF;
    END LOOP;
    RETURN;
END SPLIT_INT;

3) How to use it?



SELECT * FROM TABLE_NAME table
  WHERE
    table.Id IN (SELECT COLUMN_VALUE AS ID FROM TABLE ( SPLIT_INT ( Input_Parameter_string)))


Tomado de: http://www.aprender-a-programar.com/funcion-split-en-oracle



sábado, 2 de junio de 2012

SVN Tortoise - ANK - Visual Studio 2010

How to use Tortoise SVN in Visual Studio 2010?


1. Install ANK for visual Studio 2010

Tools->  Extension Manager -> Search: AnkSVN - Subversion Support for Visual Studio

2. Install Tortoise SVN.

3.Looking for a free SVN server, for example Assembla.

Upload your files in the server choosen.


4. In Visual Studio 

Tools -> Options -> Source Control -> Plug-in Selection -> Select AnkhSVN
5. Donwload your project from the server and open it in visual Studio 2010.




For example 
My Assembla directory is:
http://subversion.assembla.com/svn/JJTripode_GenericPos/
























































Find and Replace with a Break Line - Regular Expresions

I had a hard time trying to replace :



with




I had to replace it nearly 1200 times!!!!, then I found a SEXY way to do it  USING
THE FIND AND REPLACE WINDOWS AND REGULAR EXPRESIONS:
I manage to do that with this:

find       : e\)\n:b^12\{ 
replace : e\)\n            \{\n                Log(e);


Explanation:
Find Pattern:  'e' follow  ')'             note:  ')'  is a special character in regular expresion then if you want to include it in your pattern you have to put escape caracter before '\'.
\n indicates break line | new line.
:b indicates a white space, then   ^12 indicates repetitions. :b^12 indicates 12 white spaces.
\{   escape character follow {.

Replace pattern:
The only change is that the 12th white spaces must be changed by explicit twelve white spaces.


Another Example: Add [Serialize] to a Class

namespace Entities\n\{

namespace Entities\n\{\n[Serializable]