Ajout Serveur Web

This commit is contained in:
tzim 2013-12-30 19:59:51 +00:00
parent c563df7ac0
commit d588622879
26 changed files with 22414 additions and 8 deletions

View file

@ -45,6 +45,7 @@
</Reference> </Reference>
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Web" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic"> <EmbeddedResource Include="gtk-gui\gui.stetic">
@ -74,13 +75,48 @@
<LogicalName>style.gtkrc</LogicalName> <LogicalName>style.gtkrc</LogicalName>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="html\page.html">
<LogicalName>page.html</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\js\jquery-ui.js">
<LogicalName>js.jquery-ui.js</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\css\theme\jquery-ui.css">
<LogicalName>css.theme.jquery-ui.css</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\css\theme\images\ui-bg_glass_100_f6f6f6_1x400.png">
<LogicalName>css.theme.images.ui-bg_glass_100_f6f6f6_1x400.png</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\css\theme\images\ui-bg_flat_10_000000_40x100.png">
<LogicalName>css.theme.images.ui-bg_flat_10_000000_40x100.png</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\js\jquery-1.9.1.js">
<LogicalName>js.jquery-1.9.1.js</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\css\theme\images\ui-bg_diagonals-thick_18_b81900_40x40.png">
<LogicalName>css.theme.images.ui-bg_diagonals-thick_18_b81900_40x40.png</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\css\theme\images\ui-bg_diagonals-thick_20_666666_40x40.png">
<LogicalName>css.theme.images.ui-bg_diagonals-thick_20_666666_40x40.png</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\css\theme\images\ui-bg_highlight-soft_100_eeeeee_1x100.png">
<LogicalName>css.theme.images.ui-bg_highlight-soft_100_eeeeee_1x100.png</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\css\theme\images\ui-bg_glass_100_fdf5ce_1x400.png">
<LogicalName>css.theme.images.ui-bg_glass_100_fdf5ce_1x400.png</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="html\css\theme\images\ui-bg_glass_65_ffffff_1x400.png">
<LogicalName>css.theme.images.ui-bg_glass_65_ffffff_1x400.png</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Conduite.cs">
<LogicalName>cs</LogicalName>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="gtk-gui\generated.cs" /> <Compile Include="gtk-gui\generated.cs" />
<Compile Include="MainWindow.cs" /> <Compile Include="MainWindow.cs" />
<Compile Include="Main.cs" /> <Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" /> <Compile Include="AssemblyInfo.cs" />
<Compile Include="Conduite.cs" />
<Compile Include="gtk-gui\DMX2.MainWindow.cs" /> <Compile Include="gtk-gui\DMX2.MainWindow.cs" />
<Compile Include="UniversDMX.cs" /> <Compile Include="UniversDMX.cs" />
<Compile Include="Sequenceur.cs" /> <Compile Include="Sequenceur.cs" />
@ -113,6 +149,7 @@
<Compile Include="DriverBoitierV2.cs" /> <Compile Include="DriverBoitierV2.cs" />
<Compile Include="DriverBoitierV2UI.cs" /> <Compile Include="DriverBoitierV2UI.cs" />
<Compile Include="gtk-gui\DMX2.DriverBoitierV2UI.cs" /> <Compile Include="gtk-gui\DMX2.DriverBoitierV2UI.cs" />
<Compile Include="WebServer.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions> <ProjectExtensions>
@ -126,4 +163,18 @@
</Properties> </Properties>
</MonoDevelop> </MonoDevelop>
</ProjectExtensions> </ProjectExtensions>
<ItemGroup>
<Folder Include="html\" />
</ItemGroup>
<ItemGroup>
<None Include="html\js\jquery-ui-1.10.3.custom.js" />
<None Include="html\css\theme\images\animated-overlay.gif" />
<None Include="html\css\theme\images\ui-bg_gloss-wave_35_f6a828_500x100.png" />
<None Include="html\css\theme\images\ui-bg_highlight-soft_75_ffe45c_1x100.png" />
<None Include="html\css\theme\images\ui-icons_228ef1_256x240.png" />
<None Include="html\css\theme\images\ui-icons_222222_256x240.png" />
<None Include="html\css\theme\images\ui-icons_ef8c08_256x240.png" />
<None Include="html\css\theme\images\ui-icons_ffd27a_256x240.png" />
<None Include="html\css\theme\images\ui-icons_ffffff_256x240.png" />
</ItemGroup>
</Project> </Project>

View file

@ -40,7 +40,7 @@ namespace DMX2
void HandleDestroyed (object sender, EventArgs e) void HandleDestroyed (object sender, EventArgs e)
{ {
universEdite.AllumageForce[currDimm] = false; universEdite.AllumageForce = 0;
} }
void RenderUniversName (CellLayout cell_layout, CellRenderer cell, TreeModel tree_model, TreeIter iter) void RenderUniversName (CellLayout cell_layout, CellRenderer cell, TreeModel tree_model, TreeIter iter)
@ -228,7 +228,7 @@ namespace DMX2
majencour = true; majencour = true;
int id = (int)(spinDimmer.Value); int id = (int)(spinDimmer.Value);
universEdite.AllumageForce[currDimm] = false; universEdite.AllumageForce = 0;
btAllume.Active = false; btAllume.Active = false;
currDimm = id - 1; currDimm = id - 1;
@ -400,7 +400,8 @@ namespace DMX2
{ {
if (majencour) if (majencour)
return; return;
universEdite.AllumageForce[currDimm] = btAllume.Active; universEdite.AllumageForce = btAllume.Active?currDimm:0;
universEdite.AllumageForceVal = 255;
} }
protected void OnTxtParam1Changed (object sender, EventArgs e) protected void OnTxtParam1Changed (object sender, EventArgs e)
{ {

View file

@ -8,6 +8,7 @@ namespace DMX2
public static void Main (string[] args) public static void Main (string[] args)
{ {
bool fullscreen = false, aguibtn = false; bool fullscreen = false, aguibtn = false;
WebServer ws = null; bool webserv = true;
// Traitement des options en ligne de commande : // Traitement des options en ligne de commande :
@ -20,11 +21,16 @@ namespace DMX2
case "aguibtn": case "aguibtn":
aguibtn=true; aguibtn=true;
break; break;
case "nows":
webserv = false;
break;
default: default:
break; break;
} }
} }
if(webserv) ws = new WebServer();
// Initialisation GTK# // Initialisation GTK#
Application.Init (); Application.Init ();
@ -63,6 +69,8 @@ namespace DMX2
if (Conduite.Courante != null) { if (Conduite.Courante != null) {
Conduite.Courante.Dispose (); Conduite.Courante.Dispose ();
} }
if(ws!=null) ws.Dispose();
} }
static void HandleUnhandledException (GLib.UnhandledExceptionArgs args) static void HandleUnhandledException (GLib.UnhandledExceptionArgs args)

View file

@ -38,12 +38,26 @@ namespace DMX2
Dimmer[] _dimmers = new Dimmer[512]; Dimmer[] _dimmers = new Dimmer[512];
bool[] allumageForce = new bool[512]; int allumageForce = 0;
public bool[] AllumageForce { public int AllumageForce {
get { get {
return allumageForce; return allumageForce;
} }
set {
allumageForce = value;
}
}
int allumageForceVal= 255;
public int AllumageForceVal {
get {
return allumageForceVal;
}
set {
allumageForceVal = value;
}
} }
public string Nom; public string Nom;
@ -71,8 +85,8 @@ namespace DMX2
Debug.Assert(valeurs.Length == _dimmers.Length); Debug.Assert(valeurs.Length == _dimmers.Length);
for(int i = 0 ; i<count; i++) for(int i = 0 ; i<count; i++)
{ {
if(allumageForce[i]) { if(allumageForce==i) {
valeurs[i+offset] = 255; valeurs[i+offset] = allumageForceVal;
continue; continue;
} }

117
DMX-2.0/WebServer.cs Normal file
View file

@ -0,0 +1,117 @@
using System;
using System.Web;
using System.Net;
using System.Threading;
using System.Collections.Generic;
namespace DMX2
{
public class WebServer : IDisposable
{
HttpListener listner;
Thread loopthread=null;
string page;
List<string> resources;
public WebServer ()
{
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("page.html"))
using (System.IO.TextReader reader = new System.IO.StreamReader(stream))
page = reader.ReadToEnd();
resources = new List<string>(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames());
loopthread = new Thread(new ThreadStart(MainLoop));
loopthread.Start();
}
void MainLoop ()
{
listner = new HttpListener ();
listner.Prefixes.Add ("http://*:8089/");
listner.Start ();
HttpListenerContext context;
try {
while (null!=(context = listner.GetContext())) {
Console.WriteLine (context.Request.RawUrl);
string responseString = GetResponse (context);
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 ();
}
} catch {
}
}
string GetResponse (HttpListenerContext ctx)
{
HttpListenerRequest req = ctx.Request;
if (Conduite.Courante == null)
return "<html><body>Pas de conduite</body></html>";
if (req.Url.LocalPath.StartsWith ("/res/")) {
string res = req.Url.LocalPath.Remove(0,5).Replace('/','.');
Console.WriteLine( res);
if(res.EndsWith(".js"))
ctx.Response.ContentType= "application/javascript";
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 "";
}
switch (req.QueryString["id"]) {
default:
string univlist = ""; int i = 0;
foreach (UniversDMX univ in Conduite.Courante.Patches)
univlist = univlist + string.Format("<option value=\"{0}\">{1}</option>",i++,univ.Nom);
string data = page.Replace("<UNIVLIST>",univlist);
return data;
case "2" :
int univ, dimmer, val;
if(!int.TryParse(req.QueryString["univ"],out univ)) return "NOK";
if(!int.TryParse(req.QueryString["dimmer"],out dimmer)) return "NOK";
if(!int.TryParse(req.QueryString["val"],out val)) return "NOK";
if(univ<0 || univ>= Conduite.Courante.Patches.Count) return "NOK";
if(dimmer<=0 || dimmer > 512) return "NOK";
if(val <0 || val > 255) return "NOK";
Conduite.Courante.Patches[univ].AllumageForce = dimmer;
Conduite.Courante.Patches[univ].AllumageForceVal = val;
return "OK";
case "3":
int circuit, val;
if(!int.TryParse(req.QueryString["circuit"],out circuit)) return "NOK";
if(!int.TryParse(req.QueryString["val"],out val)) return "NOK";
if(circuit<0 || circuit>= Conduite.Courante.Circuits.Count) return "NOK";
if(val <0 || val > 255) return "NOK";
return "OK";
}
}
#region IDisposable implementation
public void Dispose ()
{
listner.Close();
loopthread.Abort();
loopthread.Join();
}
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

7
DMX-2.0/html/css/theme/jquery-ui.css vendored Normal file

File diff suppressed because one or more lines are too long

9597
DMX-2.0/html/js/jquery-1.9.1.js vendored Normal file

File diff suppressed because it is too large Load diff

1639
DMX-2.0/html/js/jquery-ui-1.10.3.custom.js vendored Normal file

File diff suppressed because it is too large Load diff

10827
DMX-2.0/html/js/jquery-ui.js vendored Normal file

File diff suppressed because it is too large Load diff

136
DMX-2.0/html/page.html Normal file
View file

@ -0,0 +1,136 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="/res/css/theme/jquery-ui.css">
<script src="/res/js/jquery-1.9.1.js"></script>
<script src="/res/js/jquery-ui.js"></script>
<script type="text/javascript">
function hop(code)
{
A=parseInt(this.dimmer.value)+parseInt(code);
A=Math.min(A,512);
A=Math.max(A,1);
this.dimmer.value=A;
}
function hop2(code)
{
A=parseInt(this.circuit.value)+parseInt(code);
A=Math.max(A,1);
this.circuit.value=A;
}
function remplir()
{
$( "#slider" ).slider({
orientation: "horizontal",
max: 255,
value: 0,
slide: refreshSwatch,
change: refreshSwatch
});
$( "#slider2" ).slider({
orientation: "horizontal",
max: 255,
value: 0,
slide: refreshSwatch2,
change: refreshSwatch2
});
}
function refreshSwatch()
{
B=$( "#slider").slider( "value" );
trans1(form.univ.value,form.dimmer.value,B);
}
function refreshSwatch2()
{
B=$( "#slider2").slider( "value" );
trans2(form2.circuit.value,B);
}
function trans1(univ,dimmer,val)
{
texte = file('/page.html?id=2&univ='+escape(univ)+'&dimmer='+escape(dimmer)+'&val='+escape(val));
}
function trans2(circuit,val)
{
texte = file('/page.html?id=3&circuit='+escape(circuit)+'&val='+escape(val));
}
function file(fichier)
{
xhr_object = new XMLHttpRequest();
xhr_object.open("GET", fichier, false);
xhr_object.send(null);
if(xhr_object.readyState == 4) return(xhr_object.responseText);
else return(false);
}
</script>
</head>
<body bgcolor="#FFFFBB">
<h1>Commande</h1>
<span id="toto">
<div id="univers">
<form name="form">
<table border="1">
<tr>
<th>
<label>Univers</label>
</th><td>
<select name="univ">
<UNIVLIST>
</select>
</td></tr><tr>
<th rowspan="3" >
<label>Dimmer</label>
</th><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>
</tr> <tr>
<td><input type="text" name="dimmer" id="dimmer" value="1" size="5" /></td>
</tr><tr>
<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>
</tr><tr>
<td colspan="2">
<div id="slider"></div>
<td>
</tr>
</table>
</form>
</div>
<div id="circuits">
<form name="form2">
<table border="1">
<tr>
<th rowspan="3" >
<label>Circuit</label>
</th><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')" >
</td></tr><tr>
<td><input type="text" name="circuit" id="circuit" value="1" size="5" /></td>
</tr><tr>
<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')" >
</tr><tr>
<td colspan="2">
<div id="slider2"></div>
<td>
</tr>
</table>
<script>remplir();</script>
</form>
</div>
</span>
</body>
</html>

9
DMX-2.0/web.html Normal file
View file

@ -0,0 +1,9 @@
<html>
<head>
<title>TEST</title>
</head>
<body>
ressource integree
</body>
</html>