Commit 9cb26e25 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Old JSON stuff displayed on client side

parent 499559e3
......@@ -71,7 +71,6 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UDP.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
......
......@@ -34,6 +34,7 @@ namespace FaceDetectionApp
FaceDetector.Instance.AttentionChecker += AttentoinCheck;
textBox1.Text = FaceDetector.Instance.GetActiveWindowTitle().ToString();
#endregion
#region mouseHook and keyboardHook Initialization
actHook = new UserActivityHook(); // crate an instance with global hooks
......
......@@ -44,6 +44,7 @@ namespace FaceDetectionApp
JSONMessage.CurrentTitle = FaceDetector.Instance.GetActiveWindowTitle();
JSONMessage.VisibleWindows = FaceDetector.Instance.Windows;
//write out to each connected listener
//Console.WriteLine(JSONMessage.ToString());
foreach (var s in sw) s.WriteLine(JSONMessage.ToString());
} catch(Exception e) {
Console.WriteLine(e.Message);
......@@ -131,7 +132,7 @@ namespace FaceDetectionApp
}
}
catch (Exception e) {
Console.WriteLine(e.Message);
Console.WriteLine(e.Message + " I am here");
}
if(swnew != null && sw.Contains(swnew)) sw.Remove(swnew);
......
using FaceDetectionMain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace FaceDetectionApp
{
//Old stuff that isn't used
class UDP
{
public static FaceDetector f;
private const int LIMIT = 6; //6 concurrent clients
private static UdpClient udpc;
private static IPEndPoint ep = null;
public static string state = "No Face";
private static void FaceDetectedCallback()
{
try
{
byte[] sdata = Encoding.ASCII.GetBytes("Face");
udpc.Send(sdata, sdata.Length, ep);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
private static void FaceLostCallback()
{
try
{
byte[] sdata = Encoding.ASCII.GetBytes("NoFace");
udpc.Send(sdata, sdata.Length, ep);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public static void Init()
{
f = new FaceDetector(true);
if (f.IsCapturing)
{
f.FaceDetectedEvent += FaceDetectedCallback;
f.FaceLostEvent += FaceLostCallback;
udpc = new UdpClient(2055);
Console.WriteLine("Server started, servicing on port 2055");
while (true)
{
byte[] rdata = udpc.Receive(ref ep);
byte[] sdata = Encoding.ASCII.GetBytes(state);
udpc.Send(sdata, sdata.Length, ep);
}
}
else
Console.WriteLine("Server not started, camera probably not attached");
}
}
}
......@@ -35,6 +35,9 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -43,12 +46,32 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FaceDetectionMain2\FaceDetectionMain.csproj">
<Project>{1B9679B2-5D28-4451-9538-671F32D3A4BD}</Project>
<Name>FaceDetectionMain</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
namespace FaceDetectionClientConsole
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(32, 29);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(12, 66);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(396, 309);
this.richTextBox1.TabIndex = 1;
this.richTextBox1.Text = "";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(420, 387);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FaceDetectionClientConsole
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FaceDetectionClientConsoel.Program.changes += changeInJSON;
}
public void changeInJSON()
{
label1.Text = FaceDetectionClientConsoel.Program.message.CurrectFaceState.ToString();
richTextBox1.Text = FaceDetectionClientConsoel.Program.message.CurrentTitle.ToString() + FaceDetectionClientConsoel.Program.message.VisibleWindows.ToString();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
......@@ -6,16 +6,118 @@ using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
namespace FaceDetectionClientConsoel
{
#region stuff from facedetectionmain
public enum FaceState { NoFace, Face }
[DataContract]
public class JSONMessage
{
[DataMember]
public WindowTitle CurrentTitle;
[DataMember]
public string VisibleWindows; //Change this to List<WindowTitle>
[DataMember]
public FaceState CurrectFaceState;
public JSONMessage(WindowTitle currentTitle, string visibleWindows)
{
CurrentTitle = currentTitle;
VisibleWindows = visibleWindows;
}
public JSONMessage(string JSON)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JSONMessage));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(JSON));
JSONMessage obj = (JSONMessage)ser.ReadObject(ms);
this.CurrentTitle = obj.CurrentTitle;
this.VisibleWindows = obj.VisibleWindows;
this.CurrectFaceState = obj.CurrectFaceState;
}
public string ToJSON()
{
MemoryStream stream1 = new MemoryStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JSONMessage));
ser.WriteObject(stream1, this);
string jsonString = Encoding.UTF8.GetString(stream1.ToArray());
stream1.Close();
return jsonString;
}
public override string ToString()
{
return ToJSON();
}
}
public struct WindowTitle
{
public string Title;
public string FilePath;
public bool Visible;
public WindowTitle(string title, string fp, bool visible)
{
Title = title;
FilePath = fp;
Visible = visible;
}
public override string ToString()
{
return "Title:" + Title + " FilePath:" + FilePath;
}
}
#endregion
public delegate void changesMade();
class Program
{
static void Main(string[] args)
public static JSONMessage message;
public static changesMade changes;
[STAThread]
static void Main()
{
Init();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FaceDetectionClientConsole.Form1());
}
public static void Init()
{
Thread t = new Thread(new ThreadStart(Service));
t.Start();
}
public static void Service()
{
TcpClient client = null;
try
{
//(new FaceDetectionClientConsole.Form1()).ShowDialog();
client = new TcpClient("127.0.0.1", 2055);
Stream s = client.GetStream();
StreamReader sr = new StreamReader(s);
......@@ -25,7 +127,13 @@ namespace FaceDetectionClientConsoel
{
//string name = Console.ReadLine();
//sw.WriteLine(name);
Console.WriteLine(sr.ReadLine()); //Should do new JSONMessage(sr.ReadLine()) instead
// Thread.Sleep(10);
String msg = sr.ReadLine();
message = new JSONMessage(msg); //Should do new JSONMessage(sr.ReadLine()) instead
Console.WriteLine(msg);
changes();
}
}
catch(Exception e) {
......@@ -34,8 +142,14 @@ namespace FaceDetectionClientConsoel
finally
{
if (client != null) {
if (client.GetStream() != null) client.GetStream().Close();
if (client.GetStream() != null)
{
client.GetStream().Close();
Console.WriteLine("Stream Not Present");
}
client.Close();
}
}
Console.ReadLine();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment