5 mai 2008

Silverlight 2 et Webservice

Pour accéder au Webservice via un client silverlight, il faut activer le cross domaine pour que le webService asmx ou WCF communique avec l'application Silverlight.

Pour cela, il suffit d'ajouter le fichier clientaccesspolicy.xml dans le répertoire contenant le web service.
Le contenu de ce fichier est:


-
-
-
-


-




Wcf Datacontract error with Linq

Erreur:
"Type System.Data.Objects.Entity' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute."

Pour résoudre l'erreur, ajouter l'attribut [DataContract()] dans le designer du fichier dbml pour chaque objets.

28 novembre 2007

How to show the CalendarExtender over a dropdown?

1. Add a new item (Style Sheet) to your project and call it ajaxcalendarfix.css
2. In the css file paste the following:
.ajax__calendar
{
position: relative;
left: 0px !important;
top: 0px !important;
visibility: visible;
display: block;
}
.ajax__calendar iframe
{
left: 0px !important;
top: 0px !important;
}

3. In your MasterPage (or aspx page if you're not using a MasterPage) include the following line in your "head" section below all other css entries (change the path for your unique setup):



4. In the CssClass properties of your Calendar Extender, type: ajax__calendar ajaxcalendarfix
Note the space character between "ajax__calendar" and "ajaxcalendarfix".
This will take the default css properties of the Ajax Calendar and apply the bug fix in ajaxcalendarfix. Using this solution, I didn't have to mess with div tags, IFrames, z-indexes, etc.

Team Foundation Server - Undo Check Out

On various projects, there are occassions when files are left locked by team members leaving the project or while on long vacations. In VSS, the administrator could simply select the file(s) and chose to undo-checkout.
A couple of months ago, our TFS installation was moved from one domain to another and some files were locked out with user accounts from a domain that was retired. Well, being the admin, I thought it was just a matter of selecting the files and unlocking them. Well, guess what - the option either didnt show up or when it did, it was grayed out. After researching this, I found out that the way to unlock, undo-check out is using the command line options:1. Check the status of the file in question
c:\tf status "$/ProjectRoot/Project/File" /server: /format:detailed

2. Since we need to know the name of the workspace for the next few commands, the following command will give us this information
c:\tf workspaces /owner:\ /computer:* /server:

3. Unlock the 'locked' file
c:\tf lock /lock:none "$/ProjectRoot/Project/File" /workspace:;\ /s:

4. If required, undo the changes using the following command
c:\tf undo "$/ProjectRoot/Project/File" /workspace:;\ /server:

For each of the above commands, you need to have the correct administrative rights on the project/TFS server.

18 octobre 2007

Response.Redirect into a new Window

It is "not possible" to redirect into a new window, because a redirect on the server causes a special HTTP response to be sent to the users browser, the client. The browsers native implementation interprets the special response code and sends the user off to the destination. The only way to open a new window is for it to be initiated on the client side, whether it be through script or clicking on a link.
So the solution always proposed to this problem is to instead write out some script that opens the window, rather than using Response.Redirect:



public static void Redirect(string url, string target, string windowFeatures)
{
HttpContext context = HttpContext.Current;
if ((String.IsNullOrEmpty(target) target.Equals("_self", StringComparison.OrdinalIgnoreCase)) && String.IsNullOrEmpty(windowFeatures))
{
context.Response.Redirect(url);
}
else
{
System.Web.UI.Page page = (System.Web.UI.Page)context.Handler;
if (page == null)
{
throw new InvalidOperationException("Cannot redirect to new window outside Page context.");
}
url = page.ResolveClientUrl(url);
string script;
if (!String.IsNullOrEmpty(windowFeatures))
{
script = @"window.open(""{0}"", ""{1}"", ""{2}"");";
}
else
{
script = @"window.open(""{0}"", ""{1}"");";
}
script = String.Format(script, url, target, windowFeatures);
ScriptManager.RegisterStartupScript(page, typeof(System.Web.UI.Page), "Redirect", script, true);
}
}



Than, use this method like:

Redirect("MyPage.aspx", "_blank", "status=no,toolbar=no,menubar=no,location=no,resizable=yes,titlebar=no");

17 octobre 2007

Concurrent access in ASP.NET

I want to know how many people are connected on my Web application
A user is in a group and we want to know if there is a user of the group who's inthe Site. But, it's possible to have 2 guys who use the same account. So i found this solution, with the Session and the Application in DotNet 2.0.

int ConnectedCount = 0;
if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{

//Dynamic string if you have more than 1 group of users
string HashTableName = "NameOfMyHashtable"
if (System.Web.HttpContext.Current.Session != null)
{

//Create new Hashtable if null:
Application[HashTableName] = Application[HashTableName] ?? new Hashtable();

//region Refresh information about current User
if (((Hashtable)Application[HashTableName]).Contains

(System.Web.HttpContext.Current.Session.SessionID))
{
((Hashtable) Application[HashTableName]).Remove

(System.Web.HttpContext.Current.Session.SessionID);
}
((Hashtable) Application[HashTableName]).Add(System.Web.HttpContext.Current.Session.SessionID,
DateTime.Now.AddMinutes(System.Web.HttpContext.Current.Session.Timeout));

//region clean Hashtable
foreach (string pKeys in ((Hashtable) Application[HashTableName]).Keys)
{
if (((DateTime) ((Hashtable) Application[HashTableName])[pKeys]).CompareTo(DateTime.Now) <

connectedcount =" ((Hashtable)"> 0 )
{
lblUsersConnected.Attributes.Add("class", "fontMessageError fade");
lblUsersConnected.Text = "Attention, il y a déjà " + ConnectedCount + " utilisateur connecté";
}

}

Collection was modified; enumeration operation may not execute.

If we want to change a value in a Hashtable, there is a problem with the Foreach loop:
Hashtable MyHt=new Hashtable();
MyHt.Add("my key", "my value");
.....

foreach (DictionaryEntry entry in MyHt)
{
MyHt[entry.Key] = "my value";
}
The is the error message :
"Collection was modified; enumeration operation may not execute."

So for resolve this, we juste do an
ArrayList arrayList = new ArrayList(((Hashtable)Application[AppName]).Keys);
IEnumerator listEnumerator = arrayList.GetEnumerator();
while (listEnumerator.MoveNext())
{
((Hashtable)Application[AppName])[Session.SessionID.ToString()] = DateTime.Now.AddMinutes(10);
Hashtable ht = (Hashtable)Application[AppName];
DateTime dateOfSession = Convert.ToDateTime(ht[listEnumerator.Current].ToString());
if (dateOfSession.CompareTo(DateTime.Now) < 0)
{
((Hashtable)Application[AppName]).Remove(Session.SessionID.ToString());
}
}