Archive for the 'geek' 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 30
 
March 27
asp.net ajax, its a hack but it works?
posted by mike at 12:23 pm

so when I started fooling around w/ asp.net ajax... back when it was called atlas... I would talk w/ fellow developers and say "well it seems like a hack, but it works". We even talked about starting an asp.net ajax blog... and calling it that... because atlas felt like a total hack when ever you wanted to do something out of their "hey drop it in an update panel" mantra.

well today I found something that reminded me very much of that feeling.... it kind of goes along w/ the key up issue that came up last week. This time I'm making a custom control, to do essentially what the titles on pageflakesdo, allow some one to click on a section of text, edit it, on blur flip it back to text, and fire an ajax postback.... I had done this a while ago... but guess didnt test it so much... because i just found that if you didnt change the text, but just blured it wouldnt fire the event. Essentially what I found was the "ontextchange" event was doing exactly as described, it would only fire when the control was blured, and changed.

so I hacked this.

C#:
  1. txtEdit.Attributes.Add("onblur","$get('" + txtEdit.ClientID + "').value+=' ';" + this.Page.GetPostBackEventReference(txtEdit));

doh

 
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
asp.net ajax postback on keyup
posted by mike at 9:30 pm

so I got a question from some one via the cmap group, for some help with a kind of tricky asp.net ajax problem. So they had been using a pagemethod, to retrieve a list from a web service to update a datalist. Sounds simple enough... but the problem w/ using web services from client code in asp.net ajax is that the page method, which although it exists in the codebehind of a page, and used to be accessable from the instance of the page in atlas, now has to be static... anywho.... so the problem is if you call a webservice in client js, its hard to do things like bind a datalist...

so my solution/kludge was to add the postback js call of a control, to the onkeyup js event of the textbox. Basicly forcing the textbox to do a asp.net postback on a keyup (really this should be only posted back like every 3 key ups...)

heres the aspx

CODE:
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="onkeyuppostback.aspx.cs" Inherits="onkeyuppostback" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7.     <title>Untitled Page</title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.     <div>
  12.     <asp:ScriptManager runat="server" ID="smTest" EnablePartialRendering="true"></asp:ScriptManager>
  13.         <asp:TextBox runat="server" ID="txtTest" AutoPostBack="True" OnTextChanged="txtTest_TextChanged"></asp:TextBox>
  14.     <asp:UpdatePanel runat="server" ID="upTest">
  15.         <ContentTemplate>
  16.             &nbsp;
  17.         <asp:DataList runat="server" ID="dlTest" Width="207px">
  18.             <ItemTemplate>
  19.                 <%# Container.DataItem %>
  20.             </ItemTemplate>
  21.         </asp:DataList>     
  22.         </ContentTemplate>
  23.         <Triggers>
  24.             <asp:AsyncPostBackTrigger ControlID="txtTest" />
  25.         </Triggers>
  26.     </asp:UpdatePanel>
  27.     </div>
  28.     </form>
  29. </body>
  30. </html>

and here is the cs

C#:
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. public partial class onkeyuppostback : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.        txtTest.Attributes.Add("onkeyup", this.GetPostBackClientEvent(this.txtTest,string.Empty));
  17.     }
  18.  
  19.     protected void txtTest_TextChanged(object sender, EventArgs e)
  20.     {
  21.         dlTest.DataSource = System.DateTime.Now.ToString();
  22.         dlTest.DataBind();
  23.     }
  24. }

so yah kind of kludgy, but is an option in general for doing something in js, which will force a asp.net ajax updatepanel postback... for example, add a button somewhere, have it w/ a style display:none;, then on serverside create a js function that calls its postback function.

 
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
getting back on my posting horse
posted by mike at 1:41 pm

so I need to get back on my posting horse, and sadly for family alot of my posts are going to be geek related... my goal is to post at least 1 technical thing a day.... to both get posting again, and to contribute to the dev resources out there, I get so much from reading tech blogs i might as well contribute a bit.  so in short.. sorry good friends and family, but your going to end up reading allot of code / geeky discussion you dont care about....

 
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. }

 
November 18
code.setMyHeadache();
posted by mike at 11:59 pm

so since I started my new job I have essentially been working on developing 1 product. This is a big switch from my last job, where I was essentially more of a web handy man. Now im more of an in house carpenter, only instead of something reliable like wood and nails, im using .net and coldfusion. This week the product went live. I should feel some serious accomplishment, this thing is pretty slick and involved me doing / learning how to do the following.

  • design and develop stand alone multithreaded applications and windows services in c#, which use oo design and essentially monitor and restart themselves. Including managing windows processes and creating its own message queues
  • helping design ,creating functionality of, and consuming a web service to control different part of the apps
  • integrated c# / coldfusion / asp.net / sql server stored procedures
  • some interface elements built using ajax

all in all its a pretty slick little app, that I would post a link to if it werent for my fear of googeling coworkers/bosses and the such.
Read the rest of this entry »