Amelioration Webserver

This commit is contained in:
manu 2014-01-19 16:18:59 +00:00
parent 3e73515f0d
commit 636106176a
2 changed files with 61 additions and 30 deletions

View file

@ -40,10 +40,28 @@ namespace DMX2
Console.WriteLine (context.Request.RawUrl); Console.WriteLine (context.Request.RawUrl);
string responseString = GetResponse (context); string responseString = GetResponse (context);
// TODO : gerer autrement les resources // Pour les resources, on les renvoie si elles existent
byte[] buffer = System.Text.Encoding.UTF8.GetBytes (responseString); if (context.Request.Url.LocalPath.StartsWith ("/res/")) {
context.Response.ContentLength64 = buffer.Length; string res = context.Request.Url.LocalPath.Remove(0,5).Replace('/','.');
context.Response.OutputStream.Write (buffer, 0, buffer.Length); if(resources.Contains(res))
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(res))
{
byte[] buff = new byte[1024]; int l;
while( (l=stream.Read(buff,0,buff.Length))>0){
context.Response.OutputStream.Write(buff,0,l);
}
}
}
else
{
byte[] buffer = System.Text.Encoding.UTF8.GetBytes (responseString);
context.Response.ContentLength64 = buffer.Length;
context.Response.OutputStream.Write (buffer, 0, buffer.Length);
}
context.Response.OutputStream.Close (); context.Response.OutputStream.Close ();
} }
} catch { } catch {
@ -57,16 +75,7 @@ namespace DMX2
// Pas de conduite chargée, on renvoi un simple message // Pas de conduite chargée, on renvoi un simple message
if (Conduite.Courante == null) return "<html><body>Pas de conduite</body></html>"; if (Conduite.Courante == null) return "<html><body>Pas de conduite</body></html>";
// Pour les resources, on les renvoie si elles existent
if (req.Url.LocalPath.StartsWith ("/res/")) {
string res = req.Url.LocalPath.Remove(0,5).Replace('/','.');
if(resources.Contains(res))
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(res))
using (System.IO.TextReader reader = new System.IO.StreamReader(stream))
return reader.ReadToEnd();
else return "";
}
int circuit, univ, dimmer, val; int circuit, univ, dimmer, val;
// En fonction du http://xxxxxx:yyyy/?id= // En fonction du http://xxxxxx:yyyy/?id=

View file

@ -11,15 +11,33 @@
A=Math.min(A,512); A=Math.min(A,512);
A=Math.max(A,1); A=Math.max(A,1);
this.dimmer.value=A; this.dimmer.value=A;
B=$( "#slider").slider( "value" );
trans1(form.univ.value,form.dimmer.value,B);
} }
function hop2(code)
{ function hop2(code)
A=parseInt(this.circuit.value)+parseInt(code); {
A=Math.max(A,1); A=parseInt(this.circuit.value)+parseInt(code);
this.circuit.value=A; A=Math.max(A,1);
} this.circuit.value=A;
B=$( "#slider2").slider( "value" );
trans2(form2.circuit.value,B);
}
function Balckout()
{
$( "#slider2").slider( "value",0 );
//B=$( "#slider2").slider( "value" );
//trans2(form2.circuit.value,B);
}
function Full()
{
$( "#slider2").slider( "value",255 );
//B=$( "#slider2").slider( "value" );
//trans2(form2.circuit.value,B);
}
function remplir() function remplir()
{ {
$( "#slider" ).slider({ $( "#slider" ).slider({
@ -44,11 +62,12 @@
B=$( "#slider").slider( "value" ); B=$( "#slider").slider( "value" );
trans1(form.univ.value,form.dimmer.value,B); trans1(form.univ.value,form.dimmer.value,B);
} }
function refreshSwatch2()
{ function refreshSwatch2()
B=$( "#slider2").slider( "value" ); {
trans2(form2.circuit.value,B); B=$( "#slider2").slider( "value" );
} trans2(form2.circuit.value,B);
}
function trans1(univ,dimmer,val) function trans1(univ,dimmer,val)
{ {
@ -78,7 +97,7 @@
<span id="toto"> <span id="toto">
<div id="univers"> <div id="univers">
<form name="form"> <form name="form">
<table border="1"> <table border="0">
<tr> <tr>
<th> <th>
<label>Univers</label> <label>Univers</label>
@ -98,7 +117,7 @@
</tr><tr> </tr><tr>
<td><input type="button" value="C-" Onclick="hop('-100')"><input type="button" value="D-" Onclick="hop('-10')"> <td><input type="button" value="C-" Onclick="hop('-100')"><input type="button" value="D-" Onclick="hop('-10')">
<input type="button" value="U-" Onclick="hop('-1')"></td> <input type="button" value="U-" Onclick="hop('-1')"></td>
</tr><tr> </tr><tr><td> </td></tr><tr>
<td colspan="2"> <td colspan="2">
<div id="slider"></div> <div id="slider"></div>
<td> <td>
@ -109,7 +128,7 @@
<div id="circuits"> <div id="circuits">
<form name="form2"> <form name="form2">
<table border="1"> <table border="0">
<tr> <tr>
<th rowspan="3" > <th rowspan="3" >
<label>Circuit</label> <label>Circuit</label>
@ -121,11 +140,14 @@
</tr><tr> </tr><tr>
<td><input type="button" value="C-" Onclick="hop2('-100')"><input type="button" value="D-" Onclick="hop2('-10')"> <td><input type="button" value="C-" Onclick="hop2('-100')"><input type="button" value="D-" Onclick="hop2('-10')">
<input type="button" value="U-" Onclick="hop2('-1')" > <input type="button" value="U-" Onclick="hop2('-1')" >
</tr><tr> </tr><tr><td> </td> </tr><tr>
<td colspan="2"> <td colspan="2">
<div id="slider2"></div> <div id="slider2"></div>
<td> <td>
</tr> </tr>
<tr><td align="left"><input type="button" value="Blackout" Onclick="Balckout()"></td>
<td align="right"><input type="button" value="Full" Onclick="Full()"></td></tr>
</table> </table>
<script>remplir();</script> <script>remplir();</script>
</form> </form>