.comment-link {margin-left:.6em;}
Marc Boizeau's blog
Friday, March 13, 2009
  Go to wordpress
This blog is now quite inactive. Here:https://mboizeau.wordpress.com/article/algorithme-de-compression-grammatical-g6fqt9cl9ver-12/  some articles both in french and english. ( about Business intelligence for instance and DB design )
 Ce blog est maintenant inactif, vous trouverez ici : https://mboizeau.wordpress.com/article/algorithme-de-compression-grammatical-g6fqt9cl9ver-12 des articles en Français et en anglais ( Conception de base de données mais aussi algorithmes de compression)

Labels:

 
Tuesday, December 12, 2006
  When does the next bus pass?
I work in a remote bussiness center downtown Paris. Last weeks I spend nearly 3 hour a days comuting. Every evening, I have to wait for a bus and one time out of two it rains cats and dog. So every evening I check the bus company's web site in order to known at what time the next bus pass to my station. Late in the evening at Office I have no time to loose! So I decide to speed up this repetitive task: A few times ago(lol) I wrote a C# code to perform a web crawling. I used the same technology to code the following extractor. As usual this has been made with VS studio but, use csc.exe (.Net 1.1 framework) to compile it as well. (see previous posts for exact command line) using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net; using System.IO; using System.Text; using System.Text.RegularExpressions; namespace bus { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.RichTextBox richTextBox2; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; /// /// Use a regular expression to extract informations from a string /// all matching results are stored in a string array. /// /// /// /// private static string [] extractReg(string strHTML,Regex r) { Match m; String[] results = new String[101]; // Use the Matches method to find all matches in the input string. // Loop through the match collection to retrieve all // matches. int i=0; m = r.Match(strHTML); for (i=0; (m.Success &&amp;amp; i<100); m =" m.NextMatch())"> /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.richTextBox2 = new System.Windows.Forms.RichTextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(0, 0); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(344, 40); this.button1.TabIndex = 0; this.button1.Text = "check it "; this.button1.Click += new System.EventHandler(this.button1_Click); // // richTextBox1 // this.richTextBox1.Location = new System.Drawing.Point(0, 48); this.richTextBox1.Name = "-"; this.richTextBox1.Size = new System.Drawing.Size(160, 96); this.richTextBox1.TabIndex = 1; this.richTextBox1.Text = "-"; // // richTextBox2 // this.richTextBox2.Location = new System.Drawing.Point(168, 48); this.richTextBox2.Name = "-"; this.richTextBox2.Size = new System.Drawing.Size(176, 96); this.richTextBox2.TabIndex = 1; this.richTextBox2.Text = "-"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(352, 150); this.Controls.Add(this.richTextBox1); this.Controls.Add(this.button1); this.Controls.Add(this.richTextBox2); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } /// /// This is the main method here we call the web pages and extract method /// /// /// private void button1_Click(object sender, System.EventArgs e) { System.Net.HttpWebRequest r ; string strRes; int count =0; string [] nbmin ; //I found this regular expression which work well for RATP's real time bus position web site // You will have to change it regarding the information you want to check. Regex re = new Regex(">(?'1'[0-9]+ mn).*<", RegexOptions.IgnoreCaseRegexOptions.Compiled); // URL with rich querystrings RATP users will pay attention to "ligne" , "dir", standig for direction , "arr" standing for "arret" (los "libdir" and "lib arr") string URL1 ="http://www.ratp.info/horaires/index.php?reseau=BUS&etape=prec_bustram_ssotr&ligne=179&libligne=GARE+DE+ROBINSON+%2F+PONT+DE+SEVRES&dem=dem3&libarr=LA+BOURSIDIERE&libdir=GARE+DE+ROBINSON&act=act_valid&amp;amp;arr=179_5206_5436&dir=A"; string URL2 = "http://www.ratp.info/horaires/index.php?reseau=BUS&etape=prec_bustram_ssotr&ligne=179&libligne=GARE+DE+ROBINSON+%2F+PONT+DE+SEVRES&dem=dem3&libarr=LA+BOURSIDIERE&libdir=PONT+DE+SEVRES&act=act_valid&amp;amp;arr=179_5206_5436&dir=R"; r =(HttpWebRequest)WebRequest.Create(URL1); r.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials ; System.Net.HttpWebResponse rp = (HttpWebResponse)r.GetResponse(); // Gets the stream associated with the response. Stream receiveStream = rp.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader( receiveStream, encode ); Char[] read = new Char[256]; // Reads 256 characters at a time. count = readStream.Read( read, 0, 256 ); strRes =""; while (count > 0) { // Dumps the 256 characters on a string . String str = new String(read,0, count); strRes +=str; count = readStream.Read(read, 0, 256); } // Releases the resources of the response. rp.Close(); // Releases the resources of the Stream. readStream.Close(); //write the result of the extraction this.richTextBox1.Text = "Bus 179 en direction de Robinson" + String.Join("\n", extractReg(strRes,re)); strRes =""; r.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials ; r =(HttpWebRequest)WebRequest.Create(URL2); r.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials ; rp = (HttpWebResponse)r.GetResponse(); count =0; // Gets the stream associated with the response. receiveStream = rp.GetResponseStream(); encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format. readStream = new StreamReader( receiveStream, encode ); read = new Char[256]; // Reads 256 characters at a time. count = readStream.Read( read, 0, 256 ); while (count > 0) { // Dumps the 256 characters on a string . String str = new String(read,0, count); strRes +=str; count = readStream.Read(read, 0, 256); } // Releases the resources of the response. rp.Close(); // Releases the resources of the Stream. readStream.Close(); re = new Regex(">(?'1'[0-9]+ mn).*<", RegexOptions.IgnoreCaseRegexOptions.Compiled); //write the result this.richTextBox2.Text = "Bus 179 en direction de pont de Sèvres " + String.Join("\n", extractReg(strRes,re)); } } }
 
Wednesday, February 15, 2006
  Thanks
Hi everybody.

I didn’t post for a long time on this blog, sorry about this. Today I'm going to take the time to do something:

A quick ”Hello” to Stéphane, Eric, Eric (yes), Sophiane, Lucky (yes again), Bulent, Thierry, Christophe, Laurent, Fabienne, Sophianne, Michel and Nathalie. I worked with these guys and girls mainly on Oracle and Microsoft technologies for about three years. We made great things together.

Thanks for everything.
 
Friday, December 16, 2005
  googled2cd966929769ab9
This is what google asked me to put on the sitemap feature
 
Friday, December 02, 2005
  two lines in the datagrid header
Ok, this is a dirty workaround but it works. In a winform datagrid you can't directly change the columns header height. This is the workaround Eric, a collegue of mine find somewhere on internet : change the datagrid header font size without changing the column header font. for instance System.Drawing.Font f =new System.Drawing.Font("Verdana", 15.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,Convert.ToByte(0)); MyDatagrid.HeaderFont = f;
 
Wednesday, September 21, 2005
  Context saving with persistent datasets
This article propose a way to use dataset to make persistent an arbitrary set of data.in the context of a winform application

Sometimes you need to stored datas but you don't think a database is the right way.
For instance if you want to store the user's context (search criterias,options, the last time he use the application...) in order to set it back the next time the application is used, you need a specific tool.
To achieve this you may use a little xml file.
But, most of the time, you don't know exactly what you will need to store in advance.
So defining and changing and changing again the schema of the xml file could be something close to a good headache.

An idea is to propose a set of methods which adapt the schema inline.

The microsoft .Net DataSet object has two powerfull methods ReadXml and WriteXml.
These methods manipulates the datas and also the schema of the dataset.
So I choose this object to implement my context saving class for winform application.
(It could be easily adapt for a server side use)

The idea is that when a coder need a new persistent data, he use the following syntax:

Contexte.getSimpleval("MyDataName");
The schema will be changed at the first use and the next time, it will bring back the last setled value.

When modified, the data is stored like this:
Contexte.setSimpleval("MyNewinformationName", MyStringValue);// the stored info are here of string type

If the amount of information is important data could be sort by collections using the syntaxes:

getVal(string "MyNewCollectionName","MyNewinformationName")
and
setVal(string "MyNewCollectionName","MyNewinformationName", MyStringValue)

The "save()" and "load()" methods are called at the begining and at the end of the application.
(typically the onLoad and onClose events of the main window).

Here is the code of the class, please critisize, comment and ask questions!


using System;
using System.Data;
using System.IO;

namespace MyNamespace
{
/// <summary>
/// The Contexte class is used to make datas persistant
/// Marc Boizeau
/// Two types of data are managed
/// - collections: values identified by a collection name and a field name
/// - Simple values just identified by a name
/// </summary>
public class Contexte
{
private const string FILE_NAME="Context.xml";
// context data container dataset
static private DataSet ds;

public Contexte()
{
}

/// <summary>
/// Retrives the good path for context
/// </summary>
/// <returns> the context path, string </returns>
static private string getFilePath()
{
//to change
string path= Environment.GetEnvironmentVariable("APPDATA")+"/MyApplication/";

if (!Directory.Exists(path))
Directory.CreateDirectory(path);


path+=FILE_NAME;

return path ;

}
//load the dataset with the xml file
public static void load()
{
if (ds!=null)
ds = null;

ds = new DataSet("ContexteExpertises");

try
{
if (File.Exists(getFilePath()))
ds.ReadXml( getFilePath(),XmlReadMode.ReadSchema);
}
catch(Exception e)
{// files do
}

}

//save the datafile
public static void Save()
{
if(ds== null)
{
ds =new DataSet("ContexteExpertises");
}
ds.WriteXml(getFilePath(),XmlWriteMode.WriteSchema);
}

// retrieve a datatable by its name
private static DataTable getTable(string TableName)
{
DataTable dt;
if (!ds.Tables.Contains(TableName))
{
dt = new DataTable(TableName);
dt.Columns.Add("NAME");
dt.Columns.Add("VALUE");
dt.Constraints.Add("PK",dt.Columns["NAME"],true);
ds.Tables.Add(dt);
}
else
dt = ds.Tables[TableName];
return dt;
}

//retrieves a data by a table name and a field name
public static string getVal(string TableName, string Entry)
{
DataTable dt;
DataView dv;
dt = getTable(TableName);
dv = dt.DefaultView;

if (Entry==null)
Entry="";

dv.RowFilter= " NAME ='" + Entry+ "'";
//test if exists
if (dv.Count==0)
{//if not creates
DataRow dr =dt.NewRow();
dr["NAME"]= Entry;
dr["VALUE"]="";
dt.Rows.Add(dr);
}
//at this point the entry exist
return dt.Rows.Find(Entry)["VALUE"].ToString();
}


// setting a data
public static void setVal(string TableName, string Entry,string Val)
{
DataTable dt;
DataView dv;
dt = getTable(TableName);
dv = dt.DefaultView;
dv.RowFilter= " NAME ='" + Entry+ "'";

if (Entry==null)
Entry="";

if (Val==null)
Val="";

//test if exists
if (dv.Count==0)
{//if not creates
DataRow dr =dt.NewRow();
dr["NAME"]= Entry;
dr["VALUE"]= "";
dt.Rows.Add(dr);
}
//at this point the entry exists
dt.Rows.Find(Entry)["VALUE"]=Val;
}

/// <summary>
/// retrieves a simple value
/// </summary>
/// <param name="Entry"></param>
/// <returns></returns>
public static string getSimpleVal(string Entry)
{
if (ds==null)
load();
return getVal("SIMPLE", Entry);
}

/// <summary>
/// set a simple value
/// </summary>
/// <param name="Entry"></param>
/// <returns></returns>
public static void setSimpleVal(string Entry,string val)
{
if (ds==null)
load();
setVal("SIMPLE", Entry,val);
}



}
}
 
Tuesday, August 30, 2005
  .net webservice session
Maybe it is obvious but I've seen the question on a forum;
Q:"How to make the session collection work for a .net webservice like for asp.net? "

A:"Just put the following before the web method:"
[ WebMethod(Description="Desc",EnableSession=true)]

thats all folks!

hope this helps.

comments are welcome


Ok I've posted this a few time ago. And it still works. But, the session collection is not a real session objectin this case. It is instanciate just before the web method call, but I never seen when it is uninstanciate. For instance the "end_session" event never fire!
Also, I experiment troubles while debuging an object stored in this collection for a web method.
So, use this the least you can and do not expect this to be a good equivalent to the session collection in classical ASP .Net.
 
You are a developer and work with Oracle and Microsoft technologies? Have a look!
ATOM
How to:
Use updatable views in Access
Get data in Excel from Oracle 1
Get data in Excel from Oracle 2
Draw the Mandelbrot set using C#
Use the "Grouping Sets" SQl Syntax
Use the "Rollup" SQl Syntax
Use the "Rank over" SQl Syntax

Go to wordpress
When does the next bus pass?
Thanks
googled2cd966929769ab9
two lines in the datagrid header
Context saving with persistent datasets
.net webservice session
Winform, Web Services & credential
back to work
self description
ARCHIVES
October 2004 / November 2004 / December 2004 / January 2005 / February 2005 / March 2005 / April 2005 / June 2005 / August 2005 / September 2005 / December 2005 / February 2006 / December 2006 / March 2009 /


Powered by Blogger

mboizeau.free.fr