General discussion

Locked

Aloks Blog

By alok ·
Tags: Off Topic
blog root

This conversation is currently closed to new comments.

8 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

free online book

by alok In reply to Aloks Blog

<p class="mobile-post"><DIV><FONT face=Arial size=2>Theres a free online book on security programming on windows programming using .net .....it can be found at....http://pluralsight.com/wiki/default.aspx/Keith.GuideBook.HomePage</FONT></DIV> <DIV> </DIV></p><p><div class="blogdisclaim"><a href="http://gizmozblog.blogspot.com/2005/03/free-online-book.html">This post originally appeared on an external website</a></div>

Collapse -

You can find a good book on object oriented design...

by alok In reply to Aloks Blog

You can find a good book on object oriented design here........http://g.oswego.edu/dl/oosd/ (don't know why they give out their books for free).... <a href='http://www.hello.com/' target='ext'><img src='http://photos1.blogger.com/pbh.gif' alt='Posted by Hello' border='0' style='border:0px;padding:0px;background:transparent;' align='absmiddle'></a><p><div class="blogdisclaim"><a href="http://gizmozblog.blogspot.com/2005/03/you-can-find-good-book-on-object.html">This post originally appeared on an external website</a></div>

Collapse -

Super updates...

by alok In reply to Aloks Blog

<p><span style="font-family:arial;">I am working on a C# webservice project where you have to transfer a lot of image files. I was not quite satisfied that the binary data I sent was converted to a 64 bit string and then converted back to binary. Finally I found that using DIME in WSE you can actually send the binary data without converting them, they just add them as attachments. Also, one another major problem was that the desktop capture didn't show the cursor, I also found the solution for that. Here is the revised version of the code.....</span><br /><br />On the server........<br /><span style="font-family:courier;"><br /><p><blockquote><br />byte [] img = null;<br />lock(_robj){<br />img = _robj.GetDesktopBitmapBytes(); //this is just a method for capturing the screen and returning it as it binary value<br />}<br />System.IO.MemoryStream ms = compress.CompressBitmap(img);//this method is used to compress the image<br />Bitmap bmp = (Bitmap) Image.FromStream(ms);<br />Graphics g = Graphics.FromImage(bmp);<br />Point cursor = System.Windows.Forms.Control.MousePosition;<br />cursorimage.Draw(g, new Rectangle(cursor.X,cursor.Y,cursor.X+50,cursor.Y+50));<br/><br />g.Save();<br />System.IO.MemoryStream ms2 = new System.IO.MemoryStream();<br />bmp.Save (ms2,System.Drawing.Imaging.ImageFormat.Jpeg);<br />Display.AppendText("-------------------------------\n");<br />Display.AppendText("Saving Image\n");<br />DimeAttachment dattach = new DimeAttachment("imagefile","image/jpeg",TypeFormat.MediaType,ms2);<br />proxy.RequestSoapContext.Attachments.Clear();//clear previous attachment...<br />proxy.RequestSoapContext.Attachments.Add(dattach);<br />try{<br />proxy.SaveImage();<br />}<br />catch(Exception exp){<br />Display.AppendText(exp.ToString());<br />}<br />Display.AppendText("Image Saved at " + DateTime.Now.ToString()+"\n");<br />Display.AppendText("--------------------------------\n");</blockquote><br /></span><br /></p><br /><br /><p><span style="font-family:arial;">On the client.......(which is actually the webservice on this case)</span></p><br /><br /><p><blockquote><span style="font-family:courier;"><br />[SoapDocumentMethod(OneWay=true)]<br />[WebMethod]<br />public void SaveImage()<br />{<br />UsernameToken user = GetUsernameToken((RequestSoapContext.Current));<br />string sessionvalue = user.Principal.Identity.Name+"_save";<br />Object _countobj = Application[sessionvalue];<br />int count;<br />if (_countobj == null) count = 0;<br />else{count = (Int32) _countobj;<br />count = (count+1)%Globals.imageperuser;<br />}<br />Image bmp =null;<br />bmp = new Bitmap(RequestSoapContext.Current.Attachments["imagefile"].Stream);<br />string username = user.Principal.Identity.Name;<br />string userimagepath = imagepath+"\\"+username+"image_"+count.ToString()+".jpg";<br />bmp.Save(userimagepath, System.Drawing.Imaging.ImageFormat.Jpeg );<br />SessionManager smanager = (SessionManager) Application["_smanager"];<br />smanager.SetExpirationTime(username);<br />Application[sessionvalue] = count;<br />}<br /></blockquote></span><p><div class="blogdisclaim"><a href="http://gizmozblog.blogspot.com/2005/03/super-updates.html">This post originally appeared on an external website</a></div>

Collapse -

Javascript update!!

by alok In reply to Aloks Blog

<div xmlns="http://www.w3.org/1999/xhtml">
<p class="mobile-post"><span>So the project I am working on also involves a web client, the client part which shows the images from another computers screen. Now there were several problems that we faced, we had to do it without using any ActiveX components or the custom active controls build using .NET. So we had to use javascript to develop this. Now, it is pretty easy to load a new image with javascript, but as the pictures in our system are constantly changed, first we run into the problem of browser caching. Wen browser caching is enabled, once the picture is loaded, loading the picture a second time shows the same image (of course it loads faster) but does not show the new version of the picture. But thankfully there is a quick fix for that. For example if the image is http://www.whatever.com/test.jpg and you want to load a new version of the picture you can do this using http://www.whatever.com/test.jpg?t=0009. Now the postfix doesn't actually do anything, but the browser doesn't know that, so it loads the image as if it were loading it for the first time, without browser catching. The scope of this technique doesn't just apply to images, it can be very useful wih html or other server-side pages. I personally use it constantly to see the new changes I have made to my blog. Of course, if the prefix DOES actually exist, then you may run into some problems. So that was the solution to the first problem. Another, a more critical one was that the use could actually see the pictures being loaded, which was quite not acceptable. What we wanted was for the pictures to load at once, without the user noticing that a new image was loaded(obviously, he can see the new version of the image). Now we all know that one sure method of achieving that is using preloading. When you use a script in javascript like </span><br /><span><br /><span>image = new Image();<br />image.src = "c:\welcome.jpg";</span> <br /><span><br /><span>the browser loads the image and saves it in is cache, and when the image is actually displayed on the browser, it is displayed very quickly. Now this works well in other cases, since once the images are preloaded, newer version of the same images are not required. As we later found out, just preloading the images didn't work. One of the problems was that the preload method is called asyncronously, so if you display the image immediately after preloading, it fails. Of course, it preloads the image, but when you display it before it is completely loaded in the cache, you will see the image being loaded. So one way to fix this would be using a setTimeout() immediately after calling the preload method. But this method has its catch too. Because of the varying bandwidth, how do you know how much time should you allocate. If you set the method for 10 seconds, then it would be too slow for those with higher bandwidth and not enough for those using dial-up. One other point, the setTimeout() method is also called asyncronously, and the code below it is executed immediately, So some code like:</span> <br /><span><br /><span>
<blockquote><span><span>//do something</span> <br /></span><span><span>setTimeout('dostuff()', 10000) //time in<br />milliseconds</span> <br /></span><span><span><span>//stuff to do after<br />10000 seconds</span> </span><br /></span></blockquote></span><br /><span><br /><span>doesn't work. You can include the latter part in the method dostuff() instead.</span> <br /><span>Of course, the only logical thing to do here is to show the image only after completely loading the image. Surprisingly, even this causes some flickers. So just to make sure, I set a timeout of 200 milliseconds so that we can be perfectly sure. Heres the code....</span> <br /><span>
<blockquote><br /><span><br /><br /><br /><br /><br /><script<br />language='JavaScript' type='text/javascript'><br /><br />image =<br />'c:\\images\\kimage_0.jpg' //name of the image<br /><br />image1 = new<br />Image();<br /><br />function showimage(){<br /><br /></span><span>if (!image1.complete)<br />{<br />setTimeout('showimage()',200);<br />return;<br />}<br />else{<br />document.images['off'].src<br />= document.images['on'].src;<br />document.images['on'].src =<br />image1.src;<br />Start_on();<br />document.images['off'].src<br />= document.images['on'].src;<br />}<br />}<br /></span><span>function Start_on() {<br />tmp = new Date()<br />tmp = '?'+tmp.getTime()<br />image1.src =<br />image+tmp<br />image1.onload =<br />function(){setTimeout('showimage()',200);}<br />image1.onerror =<br />function(){setTimeout('Start_on()',200);}<br />}<br /></span><br /></span><span>
<div id="two"><br /><img<br />name='off' src = 'c:\images\kimage_0.jpg'><br /></div><br />
<div id="one"><br /><img<br />name='on' src = 'c:\images\kimage_0.jpg' onload<br />='javascript:Start_on()'><br /></div><br /><br /><br /></span></blockquote></span><br /><span>And also just to be really sure, I used two div tags, one that displays the latest image and the other that shows the previous one, so that and even if something goes wrong, I have one that works. </span><br /><span>Its just something that works perfectly for a webcam or something like that. </span><br /></div>
<p>
<div class="blogdisclaim"><a href="http://gizmozblog.blogspot.com/2005/03/javascript-update.html">This post originally appeared on an external website</a></div></span></span></span></span>

Collapse -

No more oldies...

by alok In reply to Aloks Blog

<span style="font-family:arial;"><span style="font-family:verdana;">Now that refreshing the image has been solved, we move on to another minor update. Instead of refreshing only one image, we save the incoming image streams into multiple files and then rotate through the image files. Now, since the files are saved asynchronously, one file may be updated later than others and as we rotate throught the pictures, we will come across an 'old' image in midst of 'new' ones. To solve this problem, we have to check the write timestamp on the images. Then we can save the latest timestamp from among the images and discard images whose timestamp is older than this timestamp.<br /></span><br /></span><blockquote><span style="font-family:courier new;">private string GetNewImage(string me, string host)<br />{<br />string sessionvalue = me+"_retrieve_"+host;<br />Object _countobj = Context.Cache[sessionvalue];<br /><br />int count;<br />if (_countobj == null) count = 0;<br />else<br />{<br />count = (Int32) _countobj;<br />count = (count+1)%Globals.imageperuser;<br />}<br />Context.Cache[sessionvalue] = count;<br />string userimagepath = Globals.imagepath+"\\"+host+"image_"+count.ToString()+".jpg";<br />long image_timestamp = System.IO.File.GetLastWriteTime(userimagepath).ToFileTime();<br />string str_timestamp = me+"_timestamp_"+host;<br />object prevtimestamp = Context.Cache[str_timestamp];<br />if(prevtimestamp !=null && (long) prevtimestamp>image_timestamp) return this.GetNewImage(me,host);<br />Context.Cache[str_timestamp] = image_timestamp;<br />return userimagepath;<br />}<br /><br />[WebMethod]<br />public void RetriveImage(string host, int sessionid)<br />{<br />UsernameToken user = GetUsernameToken((RequestSoapContext.Current));<br />if (ValidUserSession(host,sessionid) && IsUsernameToken((RequestSoapContext.Current)))<br />{<br />string userimagepath = GetNewImage(user.Principal.Identity.Name,host);<br />SoapContext respContext = ResponseSoapContext.Current;<br />DimeAttachment dimeAttach = new DimeAttachment("image/jpeg",TypeFormat.MediaType,userimagepath);<br />respContext.Attachments.Add(dimeAttach);<br />}<br />}</span></blockquote><span style="font-family:verdana;">Well this works nicely for a webservice, and with a few modifications, it is also possible to use this method with web applications.<br /><br /></span><blockquote><span style="font-family:courier new;">using System;<br />using System.Collections;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.Web;<br />using System.Web.SessionState;<br />using System.Web.UI;<br />using System.Web.UI.WebControls;<br />using System.Web.UI.HtmlControls;<br /><br />namespace WebApplication2<br />{<br /><br />/// <summary><br />/// Summary description for imagehandler.<br />/// </summary><br />public class imagehandler : System.Web.UI.Page<br />{<br /><br />private void Page_Load(object sender, System.EventArgs e)<br />{<br /><br />// Put user code to initialize the page here<br />//string src = Request.QueryString["src"];<br />if (Session["clienthandle"]==null)<br />{<br />Response.Write("You are not authorized to view this page.");<br />return;<br />}<br /><br />string imagesrc = GetNewImage(User.Identity.Name.ToString(),(string)Session["clienthandle"]);<br />System.Drawing.Image bmp = System.Drawing.Image.FromFile(imagesrc);<br />Response.ContentType = "image/jpeg";<br />bmp.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);<br />}<br /><br />private string GetNewImage(string me, string host)<br />{<br />string imagefolder = System.Configuration.ConfigurationSettings.AppSettings["imagefolder"];<br />string sessionvalue = me+"_retrieve_"+host;<br />Object _countobj = Application[sessionvalue];<br />int count;<br />if (_countobj == null)<br />{<br />count = 0;<br />Application[sessionvalue] = count;<br />return imagefolder+"wait.jpg";<br />}<br />else<br />{<br />count = (Int32) _countobj;<br />count = (count+1)%Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["imageperusers"]);<br />}<br /><br />Application[sessionvalue] = count;<br />string userimagepath = imagefolder+host+"image_"+count.ToString()+".jpg";<br />long image_timestamp = System.IO.File.GetLastWriteTime(userimagepath).ToFileTime();<br />string str_timestamp = me+"_timestamp_"+host;<br />object prevtimestamp = Application[str_timestamp];<br />if(prevtimestamp !=null && (long) prevtimestamp>image_timestamp) return this.GetNewImage(me,host);<br />Application[str_timestamp] = image_timestamp;<br />return userimagepath;<br />}<br /><br />#region Web Form Designer generated code<br />override protected void OnInit(EventArgs e)<br />{<br />//<br />// CODEGEN: This call is required by the ASP.NET Web Form Designer.<br />//<br />InitializeComponent();<br />base.OnInit(e);<br />}<br />/// <summary><br />/// Required method for Designer support - do not modify<br />/// the contents of this method with the code editor.<br />/// </summary><br />private void InitializeComponent()<br />{<br />this.Load += new System.EventHandler(this.Page_Load);<br />}<br />#endregion<br />}<br />}</span></blockquote><p><div class="blogdisclaim"><a href="http://gizmozblog.blogspot.com/2005/03/no-more-oldies.html">This post originally appeared on an external website</a></div>

Collapse -

Well lately I haven't been working on my main proj...

by alok In reply to Aloks Blog

Well lately I haven't been working on my main project, I'm just finishing up on some other stuff....<br />Anyways, I totally canned the previous model because it was pretty slow, when you had to check the timestamp on the images and the overhead in saving and opening files from a hard drive. So now the code is completely revamped using Caching. So now I just cache the images and retrieve them from the cache itself, without saving it on the hard drive. This has so many advantages above the other. For one, I had developed this session manager class which would check for valid sessions running, now I have no need for that altogether, all user session which are not used within a given timeframe are disposed of.<br />Here is the code although I still need to make some minor changes.....<br /><br /><blockquote><span style="font-family:courier new;">using System;<br />using System.Web;<br />using System.Web.Caching;<br />using<br />System.IO;<br /><br />namespace DesktopCaptureService<br />{<br />/// <summary><br />/// Specification for entering data into the cache...<br />/// for<br />users: "user."+username<br />/// for the queue: "updater."+username<br />///<br />/// </summary><br />public class CacheHelper:System.Web.HttpApplication<br />{<br /><br />static CacheHelper()<br />{<br />//<br />// TODO: Add constructor logic<br />here<br />//<br />}<br />/// <summary><br />///<br />/// </summary><br />/// <param name="username"></param><br />public static int UserSessionStart(string username,<br />int sessionid)<br />{<br />int session =<br />DatabaseHelper.StartSession(username,sessionid);<br />if (session !=<br />DatabaseHelper.INVALIDSESSION)<br />HttpContext.Current.Cache.Insert("user."+username, session, null,<br />Cache.NoAbsoluteExpiration,<br />TimeSpan.FromMinutes(Globals.sessionexpirationtime),CacheItemPriority.High,new<br />CacheItemRemovedCallback(RemovedCallback));<br />return session;<br />}<br />/// <summary><br />///<br />/// </summary><br />/// <param name="username"></param><br />public static void UserSessionStop(string username)<br />{<br />HttpContext.Current.Cache.Remove("user."+username);<br />DatabaseHelper.StopSession(username);<br />}<br />/// <summary><br />///<br />/// </summary><br />/// <param name="username"></param><br />/// <param name="ms"></param><br />public static void InsertImage(string username,<br />MemoryStream ms)<br />{<br />if (HttpContext.Current.Cache["user."+username] !=<br />null)<br />{<br />System.Collections.Queue updater=<br />(System.Collections.Queue)HttpContext.Current.Cache["updater."+username];<br />if<br />( updater == null )<br />{<br />updater= new System.Collections.Queue();<br />HttpContext.Current.Cache.Insert("updater."+username, updater, new<br />CacheDependency(null,new string[]{"user."+username}));<br />updater=<br />(System.Collections.Queue)HttpContext.Current.Cache["updater."+username];<br />}<br /><br /><br />if (updater.Count <><br />///<br />/// </summary><br />/// <param name="username"></param><br />/// <returns></returns><br />public static<br />MemoryStream NextImage(string username)<br />{<br />if<br />(HttpContext.Current.Cache["user."+username] != null)<br />{<br />System.Collections.Queue updater=<br />(System.Collections.Queue)HttpContext.Current.Cache["updater."+username];<br />if<br />( updater == null ) return null;<br />if (updater.Count ==1) return<br />(MemoryStream)updater.Peek();<br /><br />return (MemoryStream) updater.Dequeue();<br />}<br />return null;<br /><br />}<br /><br />private static void<br />RemovedCallback(string k, object v,CacheItemRemovedReason r)<br />{<br />if<br />(r==CacheItemRemovedReason.Expired r==CacheItemRemovedReason.Removed )<br />{<br />string username = k.Substring(k.IndexOf('.')+1);<br />HttpContext.Current.Cache.Remove("updater."+username);<br />}<br /><br />}<br />}<br />}<br /><br /><br />[SoapDocumentMethod(OneWay=true)]<br />[WebMethod]<br />public<br />void SaveImage()<br />{<br />// UsernameToken user =<br />GetUsernameToken((RequestSoapContext.Current));<br />// string sessionvalue =<br />user.Principal.Identity.Name+"_save";<br />//<br />// Object _countobj =<br />Context.Cache[sessionvalue];<br />// int count;<br />// if (_countobj == null)<br />count = 0;<br />// else<br />// {<br />// count = (Int32) _countobj;<br />// count =<br />(count+1)%Globals.imageperuser;<br />// }<br />// Image bmp =null;<br />//<br />//<br />bmp = new Bitmap(RequestSoapContext.Current.Attachments["imagefile"].Stream);<br />// string username = user.Principal.Identity.Name;<br />// string<br />userimagepath = imagepath+"\\"+username+"image_"+count.ToString()+".png";<br />//<br />bmp.Save(userimagepath, System.Drawing.Imaging.ImageFormat.Png);<br />//<br />SessionManager smanager = (SessionManager) Context.Cache["_smanager"];<br />//<br />smanager.SetExpirationTime(username);<br />// Context.Cache[sessionvalue] =<br />count;<br /><br /><br />UsernameToken user =<br />GetUsernameToken((RequestSoapContext.Current));<br />string username =<br />user.Principal.Identity.Name;<br />CacheHelper.InsertImage(username,(System.IO.MemoryStream)RequestSoapContext.Current.Attachments["imagefile"].Stream);<br /><br />}<br /><br /><br />[WebMethod]<br />public void RetriveImageCached(string<br />host, int sessionid)<br />{<br />UsernameToken user =<br />GetUsernameToken((RequestSoapContext.Current));<br /><br />if<br />(ValidUserSession(host,sessionid) &&<br />IsUsernameToken((RequestSoapContext.Current)))<br />{<br />// string userimagepath<br />= GetNewImage(user.Principal.Identity.Name,host);<br />//<br />// SoapContext<br />respContext = ResponseSoapContext.Current;<br />// DimeAttachment dimeAttach =<br />new DimeAttachment("image/jpeg",TypeFormat.MediaType,userimagepath);<br />//<br />// respContext.Attachments.Add(dimeAttach);<br /><br />string username =<br />user.Principal.Identity.Name ;<br />SoapContext respContext =<br />ResponseSoapContext.Current;<br />DimeAttachment dimeAttach = new<br />DimeAttachment("image/gif",TypeFormat.MediaType,CacheHelper.NextImage(host));<br />respContext.Attachments.Add(dimeAttach);<br />}<br /><br />}<br />}<br /></span></blockquote><p><div class="blogdisclaim"><a href="http://gizmozblog.blogspot.com/2005/04/well-lately-i-havent-been-working-on.html">This post originally appeared on an external website</a></div>

Collapse -

A Beginner's Guide to Delphi Programming

by alok In reply to Aloks Blog

<div xmlns="http://www.w3.org/1999/xhtml">
<a href="http://delphi.about.com/od/beginners/a/delphicourse.htm">A Beginner's Guide to Delphi Programming</a>
<br />There's a free online guide on Delphi programming.............</div><p><div class="blogdisclaim"><a href="http://gizmozblog.blogspot.com/2005/06/beginners-guide-to-delphi-programming.html">This post originally appeared on an external website</a></div>

Collapse -

Database Connection Strings

by alok In reply to Aloks Blog

<div xmlns="http://www.w3.org/1999/xhtml">
<a href="http://www.sqlstrings.com/SQL-Server-connection-strings.htm">ADO SQL Database Connection Strings - SQL Server, MS Access, MySQL, Oracle, PostgreSQL, DB2, ...</a>: "'Driver={SQL Server};Server=Your_Server_Name;Database=Your_Database_Name;Uid=Your_Username;Pwd=Your_Password;' "Have a habit of forgetting those silly dabatase connection strings? You don't have to look any further....</div><p><div class="blogdisclaim"><a href="http://gizmozblog.blogspot.com/2005/06/database-connection-strings.html">This post originally appeared on an external website</a></div>

Back to After Hours Forum
8 total posts (Page 1 of 1)  

Related Discussions

Related Forums