Archive for the '.net' Category

April 23
like we need another lightbox
posted by mike at 10:14 am

so I love all the lightbox stuff out there, everyday there seems to be another one popup (pardon the pun) on ajaxian. What I dont like is there dependence on the relation tag, and how complicated they can get. So I made my own SimpleModal.js, basic gist is you call it from js, and you send it what ever content you want in it. This gives me more flexibility say to call some ajax to do a save on lightbox close.

heres the js

JAVASCRIPT:
  1. function simpleModal(c,s,ci)
  2. {
  3.     this.content = c;
  4.     this.closescript = s;
  5.     this.closeicon =ci;
  6. }
  7. simpleModal.prototype = {
  8.     openWindow:function()
  9.     {
  10.         this.getScroll();
  11.         this.setScroll(0,0);
  12.  
  13.         this.hideSelects(true);
  14.         bod = document.getElementsByTagName('body')[0];
  15.         overlay = document.createElement('div');
  16.         overlay.id  = 'modalOverlay';
  17.         lb  = document.createElement('div');
  18.         lb.id = 'modal';
  19.         lb.innerHTML += '<div style="text-align:right"><a href="javascript:'+this.closescript+';" style="">'+(this.closeicon!=''?'<img src="' + this.closeicon + '" border="0" alt="close" />':'X') + '</a></div>'+this.content;
  20.         
  21.         bod.appendChild(overlay);
  22.         bod.appendChild(lb);
  23.         
  24.         document.getElementById('modal').style.marginLeft=((document.body.clientWidth - document.getElementById('modal').clientWidth)/2)+'px';
  25.         document.getElementById('modal').style.display='block';
  26.       
  27.     }
  28.     ,
  29.     closeWindow:function()
  30.     {
  31.        this.hideSelects(false);
  32.        document.getElementById('modal').style.display='none';
  33.        bod = document.getElementsByTagName('body')[0];
  34.        bod.removeChild(document.getElementById('modalOverlay'));
  35.        bod.removeChild(document.getElementById('modal'));
  36.     }
  37.  
  38.      ,
  39.     // borrowed from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
  40.     /*---------------------------------------------------------------------------------------------*/   
  41.     hideSelects: function(visibility){
  42.         selects = document.getElementsByTagName('select');
  43.         for(i = 0; i <selects.length; i++) {
  44.         try{
  45.             selects[i].style.visibility = visibility;
  46.             }catch(err){}
  47.         }
  48.     },
  49.    
  50.     getScroll: function(){
  51.         if (self.pageYOffset) {
  52.             this.yPos = self.pageYOffset;
  53.         } else if (document.documentElement && document.documentElement.scrollTop){
  54.             this.yPos = document.documentElement.scrollTop;
  55.         } else if (document.body) {
  56.             this.yPos = document.body.scrollTop;
  57.         }
  58.     },
  59.    
  60.     setScroll: function(x, y){
  61.         window.scrollTo(x, y);
  62.     }
  63.    
  64.     /*----------------------------------------------------------------------------------------------*/
  65.    
  66. }

heres the css

HTML:
  1. #modalOverlay{
  2.     position:absolute;
  3.     top:0;
  4.     left:0;
  5.     width:100%;
  6.     height:100%;
  7.     z-index:5000;
  8.     background-color:#000;
  9.     -moz-opacity: 0.8;
  10.     opacity:.80;
  11.     filter: alpha(opacity=80);
  12. }
  13.  
  14. #modalOverlay[id]{
  15.     position:fixed;
  16. }
  17.  
  18. #modal{
  19.     position: absolute;
  20.     z-index:9999;
  21.     height:inherit;
  22.     border:10px solid #555555;
  23.     background:#FDFCE9;
  24.     text-align:left;
  25.     top: 40px;
  26.     left: 0;
  27.     width: inherit;
  28.     margin: 0 auto;
  29.     disply:none;
  30. }
  31.  
  32. #modal[id]{
  33.     position:fixed;
  34. }

and some implementation code

JAVASCRIPT:
  1. var uploader = new simpleModal('<iframe src="uploadfile.aspx" width="300" height="200" />','CloseUploadFile()','images/close.gif');
  2.  
  3. function UploadFile()
  4. {
  5.      uploader.openWindow();
  6. }
  7.              
  8. function CloseUploadFile()
  9. {
  10.     uploader.closeWindow();
  11.     <%=this.UpdateJS%>;
  12.     //in my case UpdateJS makes an Asp.Net Ajax postback
  13. }

 
April 20
CODECAMP WSE presentation
posted by mike at 10:08 pm

So April 21, I'm doing a presentation on WSE 3.0 at the cmap code camp.

here is where I post the content... first the slides.

and of course the working examples, these examples cover wse 3.0 turnkey security, routing, custom token managers, custom soap router, mtom services, and mtom clients both as a console app and a asp.net ajax app.

wse-codecamp-code-4-21-2007.zip

hope this helps some folks!

 
March 26
log4net god bless your debug setting
posted by mike at 2:35 pm

so I was having some problems getting log4net integrated with a site I was working on... for no reason It was not writing to the AdoNetAppender.

This is what I had as the adapter

XML:
  1. <appender name="ADONetAppender" type="log4net.Appender.AdoNetAppender">
  2.         <bufferSize value="1" />
  3.         <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  4.         <connectionString value="SERVER=127.0.0.1\sql;DATABASE=dbname;UID=sa;" />
  5.         <commandText value="INSERT INTO ProcessLogLog4Net (Message,thread,level,logger,exception) VALUES (@message,@thread,@log_level,@logger,@exception);" />
  6.         <parameter>
  7.             <parameterName value="@log_date" />
  8.             <dbType value="DateTime" />
  9.             <layout type="log4net.Layout.RawTimeStampLayout" />
  10.         </parameter>
  11.         <parameter>
  12.             <parameterName value="@thread" />
  13.             <dbType value="String" />
  14.             <size value="255" />
  15.             <layout type="log4net.Layout.PatternLayout">
  16.                 <conversionPattern value="%thread" />
  17.             </layout>
  18.         </parameter>
  19.         <parameter>
  20.             <parameterName value="@log_level" />
  21.             <dbType value="String" />
  22.             <size value="50" />
  23.             <layout type="log4net.Layout.PatternLayout">
  24.                 <conversionPattern value="%level" />
  25.             </layout>
  26.         </parameter>
  27.         <parameter>
  28.             <parameterName value="@logger" />
  29.             <dbType value="String" />
  30.             <size value="255" />
  31.             <layout type="log4net.Layout.PatternLayout">
  32.                 <conversionPattern value="%logger" />
  33.             </layout>
  34.         </parameter>
  35.         <parameter>
  36.             <parameterName value="@message" />
  37.             <dbType value="String" />
  38.             <size value="4000" />
  39.             <layout type="log4net.Layout.PatternLayout">
  40.                 <conversionPattern value="%message" />
  41.             </layout>
  42.         </parameter>
  43.         <parameter>
  44.             <parameterName value="@exception" />
  45.             <dbType value="String" />
  46.             <size value="2000" />
  47.             <layout type="log4net.Layout.ExceptionLayout" />
  48.         </parameter>
  49.         <filter type="log4net.Filter.LevelRangeFilter">
  50.             <acceptOnMatch value="true" />
  51.             <levelMin value="WARNING" />
  52.             <levelMax value="FATAL" />
  53.         </filter>
  54.  
  55.     </appender>

this is what I had when I constructed it in the wrapper object

C#:
  1. private static log4net.ILog Log
  2.         {
  3.             get
  4.             {
  5.                 if (_log == null)
  6.                 {
  7.                     log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Log4NetConfigFile));
  8.                     _log = log4net.LogManager.GetLogger(HttpContext.Current.Server.MachineName);
  9.                 }
  10.  
  11.                 return _log;
  12.             }
  13.         }

it worked just fine for the rolling adapter... I was stumped. Then I found this little nugget in the faq

XML:
  1. <add key="log4net.Internal.Debug" value="true"/>

at the end of the day, for one reason or another log4net couldn't resolve the domain of the sql box... If it werent for the debug pumping an error out to the console I would never have seen this and just keep hitting my head on the desk. good times

 
March 21
cfdump how i miss you some days
posted by mike at 12:20 pm

so when I was doing lots of cf on a daily basis, I would long for strongly typed data and a real ide w/ real integrated debugging tools... now doing .net dev day in day out , I have those things, and surely appreciate it... but... I miss cfdump. You needed to see in a page what a variable was at any given point, there you had it.... I had a problem the yesterday where a problem only existed on a production server. No nice debugger / ide on a production server, just little old notepad, and me. So I whipped up some reflection code, heres a snippet

C#:
  1. protected void PrintProperties(object o,System.Type[] allowable)
  2. {
  3.  
  4.    System.Type t = o.GetType();
  5.    System.Reflection.PropertyInfo[] properties_info = t.GetProperties();
  6.  
  7.    for (int y = 0; y <properties_info.Length; y++)
  8.   {
  9.       Response.Write(properties_info[y].Name + ":");
  10.      try
  11.     {
  12.         if (properties_info[y].GetValue(o, null) != null)
  13.             Response.Write(properties_info[y].GetValue(o, null).ToString());
  14.  
  15.        if ((!properties_info[y].GetValue(o, null).GetType().Equals(typeof(String)) ||!(properties_info[y].GetValue(o, null).GetType() is System.ValueType)) && (Array.IndexOf(allowable, properties_info[y].GetValue(o, null).GetType())> -1))
  16.     PrintComplexObject(o, properties_info[y], allowable);
  17.  
  18.  
  19.    }
  20.    catch
  21.   {
  22.    .......
  23.  
  24.      }
  25.  
  26.   }
  27.  
  28. }

So I know, cf no "real" data types, makes the writting of such stuff much easier, exctly why var_dump exists for php, but man, I wish I had something like that.... which stard me thinking I need an Ndump tag.... throw it on a page, and it dumps a variable / complex object in a session etc... I started working on some basic functionality for it today.... Have a Basic Library written, when I get time ill clean it up, put it in a custom tag and post it on up... emphasis on when I get TIME, what is this TIME I speak of.

UPDATE: so i spent some time today and have a working prototype of an Ndump tag/control if any one wants it just ask...

 
March 19
east coast time
posted by mike at 1:26 pm

so had to do something interesting for work that I thought would be usefull for others... 2 servers on each coast... need to write the same time, but code does not know which server its running on... so I use gmt to figure out the right time....

heres the solution in sql and c#... sql is useful , as that you could set the default of a datetime field in sql to dbo.fn_GetEastCoastTime(getdate().getutc())

SQL:
  1. CREATE FUNCTION [dbo].[fn_GetEastCoastTime]
  2. (@date datetime,@utcdate datetime
  3. )
  4. RETURNS datetime
  5. AS
  6. BEGIN
  7.  
  8. declare  @march datetime
  9. declare  @november datetime
  10. declare  @dstStart datetime
  11. declare  @dstEnd datetime
  12. declare  @difamt int
  13.  
  14. SET @march= '3/01/'+cast(year(@date)AS varchar)
  15. SET @november= '11/01/'+cast(year(@date)AS varchar)
  16.  
  17. SET @dstStart = DATEADD(wk,1,(@march)+(7-DATEPART(dw,(@march-
  18. Day(@march)))))
  19.  
  20. SET @dstEnd = DATEADD(wk,0,(@november)+(7-DATEPART(dw,(@november-
  21. Day(@november)))))
  22.  
  23. IF(@date> @dstStart AND @date <@dstEnd)
  24. SET @difamt = -4
  25. else
  26. SET @difamt = -5
  27.  
  28. RETURN dateadd(hour,datediff(hour,dateadd(hour,@difamt,@utcdate),@date),@date)
  29.  
  30. END

C#:
  1. public static DateTime EastCoastDate
  2.  
  3. {
  4.  
  5. get
  6.  
  7. {
  8.  
  9. int intTimeShift =-5;
  10.  
  11. if(TimeZone.CurrentTimeZone.IsDaylightSavingTime(System.DateTime.Now))
  12.  
  13. intTimeShift = -4;
  14.  
  15. TimeSpan hourdiff =  System.DateTime.UtcNow.AddHours(intTimeShift) - System.DateTime.Now;
  16.  
  17. return System.DateTime.Now.AddHours(hourdiff.Hours);
  18.  
  19. }
  20.  
  21. }