D#E の世界

My Life, My Journey, My Thought mostly in Japan

Archive for the ‘IT Related’ Category

Programming stuff, technical stuff, etc

Automation part II

Posted by D#E on November 6, 2008

This time my boss wanted to make an automation program to copy files. Since some of the legacy code still written in VBA based on ms access. Everytime they want to distribute the new version they need to manually copy it to the target machine.

So he designed a scratch plan to do the automation. He give me a paper which basically tell me to

  1. ping the target computer
  2. if the ping got a reply copy the file
  3. if the ping failed. retry

After a few brainstorming, trial and error and also not to forget the internet search. We made this approach :

  1. create a database consists of PC information. eg: IP, update status, etc
  2. read the database from 1st record till the last record
  3. ping the target
  4. if the target reply, create the temporary drive letter (after make sure it’s available) and run a script file to copy the files to target’s pc. mark the status update as done and after that go to next record.
  5. if target doesn’t reply just abandon it and go to next record.
  6. check for the status update for all the records, if there is at least 1 record still not updated, repeat the step 2.

using .net framework 2.0 to do this made the job easier. I used a single thread to do the looping process and ping through the synchronous call (asynchronous might be faster but if more than 1 target’s pc on the record have the same drive letter than it would failed). beside , I need to make sure that the ping process only executed one at the time. that’s why I need the synchronous. The reason to use thread is to avoid the freezing UI.

Posted in IT Related | Leave a Comment »

Automation ? Just AutoIt

Posted by D#E on November 6, 2008

So last month my boss want to have some automation program for early installation setup for new pc.   Luckily he give me freedom to choose my weapon to acquire the target. Since it would be too cumbersome to do this in .net (new pc shipped in windows xp and by default windows xp’s framework still 1.1 and I already used both 2.0 and 3.5 right now) so developing using .net is not an option for me.

Next I would consider the script like vbs or even js but it didn’t do any good. And while searching the internet I found the perfect gem for this (I was looking for silent install automation I think).

And that gem is here

AUTOIT

it took a while to learn all the new syntax but it’s quite powerful. indeed for a freeware it’s awesomely powerful.

I do found some problem though because I’m in japan so I need to deal with japanese characters. Autoit seemed couldn’t handle the japanese characters well so my temporary workaround now is to save the japanese character inside some txt file and use autoit to open the file , copy, close the file, paste it on some text that I want to.

Automation is still new world for me. And by learning Autoit I feel I’ve added more arsenal to my weaponry to deal with the target :-P

Posted in IT Related | 1 Comment »

Lenovo X200 Impression

Posted by D#E on October 29, 2008

On my current line of work, sometimes I get the chance to taste the cutting edge newly released laptop. So far I’ve tried these laptops :

  • Dell Inspiron Mini (a small netbook from Dell)
  • Dell Latitude (currently the highest end of business series from Dell, up to 19 hours long battery life)
  • Lenovo Thinkpad X200 (ultra portable notebook that keep the balance between price and features)
  • Sony Vaio G series (stylish ultra portable notebook from sony)

in this post I will try to give my impression of Lenovo X200. The reason is because they let me to set the notebook from the fresh start, so I spent more time to operate this one rather than the other 3.

Pro

  • No sound at all. Just like Mac Air from apple. you wouldn’t notice the sound.
  • I got the SSD version so I experienced the fast response from SSD. windows shuts down in less than 3 seconds. (the experience might be differ if it’s not the SSD version)
  • very light
  • very thin
  • Keyboard is comfortable
  • Filled in with the latest technology in current generations (it just came out)

Con

  • no optical drive, just like MacAir. which is a big no for some people
  • the screen is not that good. I’m kinda feel that my 4 years old Toshiba Satellite’s screen is better
  • full of bloatware by lenovo (no big deal since you can opt to remove it, but still it’s the default settings)
  • only trackpoint with no touchpad. the trackpoint itself is awesome but it gets dirty only after couple hours of touching. And I knew that most of the people still prefer touchpad over trackpoint
  • the F1-F10 button on the keyboard look and feel cheap. but the rests are okay though

some interesting fact that I got when downgrading the Vista to Xp with the Lenovo downgrade CD

  • the downgrade process from Vista to Xp took approximately 2 hours
  • on Vista, the empty space is only 29 Gb, after downgrade to Xp I got empty space around 49 Gb. Mind you this Lenovo X200 is SSD 64 Gb version
  • I only tried Vista for about an hour. after downgrade to xp and do the setting etc. I found that the system was more stable in Vista.

Posted in IT Related | Leave a Comment »

Fighting malwares

Posted by D#E on July 28, 2008

Last week I did some mistake on my own that let some malwares get in to my notebook. This notebook almost became a brick, but luckily it survived. This is the second time in my life that a virus could actually get in to my system. The first time was like 4-5 years ago. And that is the virus that I get from university lab LoL. This time I got the virus because I accidentally hit the button ignore when my antivirus sent a notification of some malwares trying to get into my system.

Okay. so as soon as I noticed the malwares has infected my system. I put a memo on all the suspicious program that was recorded on both my avast (antivirus) and teatimer (spybot). After hours of cleaning up the file both in secret folder and registry and after several restart. I thought I have done. so I restart once again to make sure everythings fine.

But ALAS, this time I can’t login. Something struck in my head, oow I just realized that I delete a vital registry entry and now my system is dead. I deleted an entry in registry related to LSA which is related to autologon that I used on my system.

After shocking in awe. I went to my friend’s room to borrow pc so I could browse the internet on how to recover from this problem. I found out that with recovery console from windows xp’s cd, one could rebirth a registry structure. so using the recovery console from xp’s cd, I moved the file from repair folder the current system32’s folder. after restart, my pc is reborn. well…. not actually reborn, the whole file, data and program are still there, but the profile is gone. And the program that was installed under my old profile can’t run unless I reinstall them again in my current profile.

For a while it seems fine until I realized. My usb can’t work. after googling a little bit I found out that I’m actually in prefactory setting mode, so again I enter the regedit to edit the registry’s involved.

Ok so right now my pc survived from a near death.

refferences that I use to fix my pc :

http://forums.windrivers.com/printthread.php?t=65537
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q307545&ID=KB;EN-US;Q307545

Posted in IT Related | Leave a Comment »

asynchronous client callback with parameter

Posted by D#E on June 27, 2008

Background

The last time I put an entry in IT related categories is about asynchronous callback. This time I also trying to cover this things a little bit further. You can read my previous entry about this here

In my last post, the method only support 1 action, means if you have several button to activate different type of callback inside 1 page, it can’t be done with my previous way. This post will show you how to send different kind of parameter to enrich the callback

Code

.cs file

string cbref = Page.ClientScript.GetCallbackEventReference(this,”arg”,”result”,”",true);
string callbackscript = “function callserver(arg){“+cbref+”;}”;
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),”callback”,callbackscript,true);

//to assign it to a button
Button1.Attributes["onClick"] += “javascript:callserver(’set your argument here’)”;
Button1.Attributes["onClick"] += “;return false;”;

//Callback function
public void RaiseCallbackEvent (String eventArgument)
{
//arg is a variable which you need to define yourself
arg = eventArgument;
}

public String GetCallbackResult ()
{
return arg;
}

.aspx file (javascript part)

function result (arg)
{
if (arg == “1″) // you decide your logic here based on passed arguments

}

Basically all that can be done in client side can be done in the result function, since you can control the passed argument based on the clicked button or whatever control you decided. This method proves more robust and versatile approach better than my previous method. This way you are free to control everything that’s going on on callback session based on your defined arguments.

Reference :

http://www.themastech.net/Tutorials/ClientCallbacks/Default.aspx?fn=Part%202

Posted in IT Related | 1 Comment »

asynchronous client callback .net 2005

Posted by D#E on May 2, 2008

Background

Yes I know the .net 2008 is out with built in ajax designed for this client callback purpose. The heck, even many people used ajax in .net 2005 as a separate plug in. But in my development environment, I only have this standard .net 2005 and have no rights whatsoever to make changes like installing ajax. So in order to achieve this feature, I need to use the client callback provided in standard .net 2005.

Study case

This is my real life case. The goal is when you click the listbox and select some items, it fired an event which then decide whether a checkbox should be checked or not. This could be easily done by using the postback. That’s the way I did it before. And now I want to change it into client callback in order to avoid the client’s loading screen on postback

Code

.cs file

// define interface
public partial class ClassName : System.Web.UI.Page, ICallbackEventHandler

// code in page load

string script = Page.ClientScript.GetCallbackEventReference (this,”document.all['ListBox1'].options[document.all['ListBox1'].selectedindex].value”,
“JSfunction”,”null”);

ListBox1.Atrributes["onClick"] = script;

//Callback function
public void RaiseCallbackEvent (String eventArgument)
{
//arg is a variable which you need to define yourself
arg = eventArgument;
}

public String GetCallbackResult ()
{
return arg;
}

.aspx file (javascript part)

function JSfunction (arg, context)
{
if (arg == “1″)
document.forms[0].elements['cb'].checked = true;
}

Not many explanations here since the purpose of this entry is for my future reference

Posted in IT Related | 1 Comment »

Sql Server 2005 Data partition

Posted by D#E on April 30, 2008

Last week I got assignment to use data partition on Sql Server.

This entry is about setting the data partition and how to do the sliding window scenario.

Since the purpose is just as a reminder for me to do it next time. I won’t put much explanation in this one

How to set the database for data partition

  • make a file group
  • add a file into file group
  • make partition function
  • make a partition scheme
  • make a partition table based on the definition scheme


alter database [DBNAME] add filegroup [FGNAME]

alter database [DBNAME]
add file
(
name = ….. ,
filename = ‘C:\…\… .ndf’,
size = … ,
maxsize = … , //undefined would be set boundless limit
filegrowth = …//undefined would be autodefined as 1Mb
)
to filegroup [FGNAME]

create partition function [name] (datetime) as range right for values
(‘…’,'…’)

create partition scheme [schemename] as partition [functionname] to
(FGNAME, …. , …., [PRIMARY])

create table [TBLNAME]
(
…..
dateofsales datetime
….
) on schemename (dateofsales)

a memo for partition function

- right (a,b,c)

value < a

a <= value < b

b <= value < c

c <= value

- left (a,b,c)

value <= a

a < value <= b

b < value <= c

c < value

Sliding window scenario

switch

alter table [T1] switch partition [x] to [T2] partition [y]

merge

alter partition function [functionname] () merge range (‘yyyy/mm/dd’)

split

alter partition scheme [schemename] next used [FG1];
go
alter partition function [functioname] () split range (‘yyyy/mm/dd’)

note : the merge’s range is the old value, the split’s range is new value

Posted in IT Related | 2 Comments »

C# Backgroundworker quick overview

Posted by D#E on March 13, 2008

continuing from yesterday’s post in –HERE–

Today I tried out the backgroundworker component. It was actually a thread but being simplified and by using this component will make the code look neater. It also support the cancellation of thread. I used this backgroundworker as a process that will update the progress bar.

First thing you got to do is to drag the backgroundworker component on your windows application form.

to run the background worker use this code (for example inside button click)


backgroundWorker1.RunWorkerAsync();

and then you need to define what work it should do in DoWork function and as optional you could use the report progress too


private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
// write code here what do you want to do with the thread
//to report the progress use this
// backgroundWorker1.ReportProgress(10); // parameter is the percent completed
}

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}

the nice thing is with ordinary thread, it won’t let you access some GUI handled interface. But by using the backgroundworker, you’re free to access GUI interface such as progressbar anytime you want. Pretty nice huh???? Think again.

if you read my previous post about delegate –HERE– you will notice that I used delegate to access the progressbar. And I tried to experiment it again here. by stripping the report progress and progress changed part and integrate some delegate in DoWork process, I got this result

Method Runtime
Using BackgroundWorker only 46 seconds
Thread using delegate 36 seconds
BackgroundWorker using delegate 36 seconds
just a single main without progress bar 10 seconds

 

get the idea ? while backgroundworker could access all interface directly, it costs runtime performance. And for comparison, using no progress bar at all just cost 10 seconds on my program. They were all tested on same exact process. So THERE IS a trade off between good interface and performance cost. As a conclusion to this post, learning delegate won’t hurt if you’re planning to using thread.

Posted in IT Related | 5 Comments »

C# Updating ProgressBar inside Thread

Posted by D#E on March 12, 2008

Today my boss told me to learn about threading in C#. And I decided to use my previously finished FileSplitter program that I created. The idea is to add a progress bar so when the File is being processed, the bar would update itself in different thread.

After coding it, I got un-handled runtime exception. Apparently while thread could access the TextBox’s text element, it couldn’t access a GUI event handled element such as progress bar and or combo box. This is where the delegates come in (I heard about delegates last year but never intended to learn it throughly).

Delegates is actually just a function pointer just like in C or C++, in C# they change the system into delegates.

first of all you need to declare the delagate in your class

delegate void UpdateProgressDelegate();

after that make a function


void UpdateProgress()
{
//do some work here to update progress
//for example progressbar1.value = 10;

}

last one is to invoke it inside the thread

this.invoke(new UpdateProgressDelegate(UpdateProgress));

there you go. but you may ask what if I want to add parameters.

While I haven’t tried it myself but this link have the solution for that. Not only that, one of the post on that link stated that it’s better to use component called backgroundworker in order to achieve the same result.

The thread is extremely slow, my FileSplitter program run faster without the updating progress bar. I might gonna try the backgroundworker later on to compare the speed.

Posted in IT Related | Leave a Comment »