Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
soshimozi committed Sep 26, 2011
1 parent 6b947f7 commit 55439c8
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 173 deletions.
8 changes: 0 additions & 8 deletions ConsoleApplication1/ConsoleApplication1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@
<Project>{93FD4F32-5214-40E3-8E36-5B4E354F10C4}</Project>
<Name>SocketService.Framework.Client</Name>
</ProjectReference>
<ProjectReference Include="..\SocketService.Framework.Request\SocketService.Framework.Request.csproj">
<Project>{5266A3D3-25DC-492B-BFDC-973D79BA7D90}</Project>
<Name>SocketService.Framework.Request</Name>
</ProjectReference>
<ProjectReference Include="..\SocketService.Framework.SharedObjects\SocketService.Framework.SharedObjects.csproj">
<Project>{67292447-E315-4583-8FD5-14DEA8D4B08E}</Project>
<Name>SocketService.Framework.SharedObjects</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
26 changes: 1 addition & 25 deletions ConsoleApplication1/ConsoleApplication1.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocketService.Client.API",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocketService.Framework.Client", "..\SocketService.Framework.Client\SocketService.Framework.Client.csproj", "{93FD4F32-5214-40E3-8E36-5B4E354F10C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocketService.Framework.Request", "..\SocketService.Framework.Request\SocketService.Framework.Request.csproj", "{5266A3D3-25DC-492B-BFDC-973D79BA7D90}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocketService.Framework.SharedObjects", "..\SocketService.Framework.SharedObjects\SocketService.Framework.SharedObjects.csproj", "{67292447-E315-4583-8FD5-14DEA8D4B08E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocketService.Framework.Crypto", "..\SocketService.Framework.Crypto\SocketService.Framework.Crypto.csproj", "{4138075A-49CD-4A46-92CB-DFF64A0BB0B6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocketService.Crypto", "..\SocketService.Framework.Crypto\SocketService.Crypto.csproj", "{4138075A-49CD-4A46-92CB-DFF64A0BB0B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -53,26 +49,6 @@ Global
{93FD4F32-5214-40E3-8E36-5B4E354F10C4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{93FD4F32-5214-40E3-8E36-5B4E354F10C4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{93FD4F32-5214-40E3-8E36-5B4E354F10C4}.Release|x86.ActiveCfg = Release|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Debug|x86.ActiveCfg = Debug|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Release|Any CPU.Build.0 = Release|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{5266A3D3-25DC-492B-BFDC-973D79BA7D90}.Release|x86.ActiveCfg = Release|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Debug|x86.ActiveCfg = Debug|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Release|Any CPU.Build.0 = Release|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{67292447-E315-4583-8FD5-14DEA8D4B08E}.Release|x86.ActiveCfg = Release|Any CPU
{4138075A-49CD-4A46-92CB-DFF64A0BB0B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4138075A-49CD-4A46-92CB-DFF64A0BB0B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4138075A-49CD-4A46-92CB-DFF64A0BB0B6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand Down
31 changes: 14 additions & 17 deletions ConsoleApplication1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ private void Login(string userName)

private void GetRoomVariableRequest(string room, string varname)
{
GetRoomVariableRequest grvr = new GetRoomVariableRequest();
grvr.RoomName = room;
grvr.VariableName = varname;
//GetRoomVariableRequest grvr = new GetRoomVariableRequest();
//grvr.RoomName = room;
//grvr.VariableName = varname;

_server.SendRequestEncrypted(grvr);
//_server.SendRequestEncrypted(grvr);
}

private void JoinRoom(string roomName)
Expand All @@ -172,8 +172,8 @@ void engine_JoinRoom(object sender, JoinRoomEventArgs e)

private void CreateRoomVariable()
{
Console.Write("Room: ");
string room = Console.ReadLine();
//Console.Write("Room: ");
//string room = Console.ReadLine();

Console.WriteLine();
Console.Write("Name: ");
Expand All @@ -183,29 +183,26 @@ private void CreateRoomVariable()
Console.Write("Value: ");
string stringValue = Console.ReadLine();

ServerObject value = new ServerObject();
value.SetElementValue("__default__", stringValue, ServerObjectDataType.String);
SharedObject value = new SharedObject();
value.SetElementValue("__default__", stringValue, SharedObjectDataType.String);

ServerObject[] valueArray = new ServerObject[1];
ServerObject arrayObject = new ServerObject();
arrayObject.SetElementValue("value", 123, ServerObjectDataType.Integer);
SharedObject[] valueArray = new SharedObject[1];
SharedObject arrayObject = new SharedObject();
arrayObject.SetElementValue("value", 123, SharedObjectDataType.Integer);
valueArray[0] = arrayObject;

value.SetElementValue("arrayTest", valueArray, ServerObjectDataType.BzObjectArray);
value.SetElementValue("arrayTest", valueArray, SharedObjectDataType.BzObjectArray);

CreateRoomVariableRequest crvr = new CreateRoomVariableRequest();
crvr.Room = room;
//crvr.RoomId = room; get my room id
crvr.Name = name;
crvr.Variable = new RoomVariable() { RoomId = 0, Value = value };
crvr.Value = value;

_server.SendRequestEncrypted(crvr);
}

void engine_GetRoomVariableResponseRecieved(object sender, GetRoomVariableResponseArgs e)
{
Console.Write(e.Response.Room);
Console.Write(" : ");
Console.WriteLine(e.Response.Variable.Value.GetValueForElement("__default__"));
}

void engine_LoginResponseReceived(object sender, LoginResponseEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion SocketService.Client.API/ClientEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SocketService.Framework.Crypto;
using SocketService.Crypto;
using SocketService.Framework.Client.Sockets;
using SocketService.Framework.Client.Response;
using System.Net.Sockets;
Expand Down
6 changes: 3 additions & 3 deletions SocketService.Client.API/Data/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SocketService.Client.API.Data
public class Room
{
private readonly List<User> _userList = new List<User>();
private readonly Dictionary<String, RoomVariable> _roomVariableList = new Dictionary<String, RoomVariable>();
private readonly Dictionary<String, SharedObject> _roomVariableList = new Dictionary<String, SharedObject>();

private static int _nextId = 0;

Expand Down Expand Up @@ -113,7 +113,7 @@ where u.UserName.Equals(userName)

}

public void AddRoomVariable(String Name, RoomVariable Value)
public void AddRoomVariable(String Name, SharedObject Value)
{
Monitor.Enter(this);
try
Expand Down Expand Up @@ -157,7 +157,7 @@ public void RemoveVariable(string Name)

}

public void UpdateVariable(string Name, RoomVariable Value)
public void UpdateVariable(string Name, SharedObject Value)
{
Monitor.Enter(this);
try
Expand Down
2 changes: 2 additions & 0 deletions SocketService.Client.API/Data/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public bool IsMe
set;
}


public Room Room { get; set; }
}
}
38 changes: 20 additions & 18 deletions SocketService.Client.API/Manager/ManagerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ void engine_LeaveRoom(object sender, LeaveRoomEventArgs e)

void engine_RoomVariableUpdate(object sender, RoomVariableUpdateArgs e)
{
switch(e.Event.Action)
{
case RoomVariableUpdateAction.Add:
RoomManager.AddRoomVariable(e.Event.RoomId, e.Event.Name, e.Event.Variable);
break;

case RoomVariableUpdateAction.Delete:
RoomManager.DeleteRoomVariable(e.Event.RoomId, e.Event.Name);
break;

case RoomVariableUpdateAction.Update:
RoomManager.UpdateRoomVariable(e.Event.RoomId, e.Event.Name, e.Event.Variable);
break;
}
//switch(e.Event.Action)
//{
// case RoomVariableUpdateAction.Add:
// RoomManager.AddRoomVariable(e.Event.RoomId, e.Event.Name, e.Event.Variable);
// break;

// case RoomVariableUpdateAction.Delete:
// RoomManager.DeleteRoomVariable(e.Event.RoomId, e.Event.Name);
// break;

// case RoomVariableUpdateAction.Update:
// RoomManager.UpdateRoomVariable(e.Event.RoomId, e.Event.Name, e.Event.Variable);
// break;
//}
}

void engine_LoginResponseReceived(object sender, LoginResponseEventArgs e)
Expand Down Expand Up @@ -102,16 +102,18 @@ void engine_JoinRoom(object sender, JoinRoomEventArgs e)
room.Capacity = joinRoomEvent.Capacity;
room.IsHidden = joinRoomEvent.Hidden;

foreach (RoomVariable roomVariable in joinRoomEvent.RoomVariables)
{
room.AddRoomVariable(roomVariable.Name, roomVariable);
}
//foreach (SharedObject roomVariable in joinRoomEvent.RoomVariables)
//{
// room.AddRoomVariable(roomVariable.Name, roomVariable);
//}

foreach (UserListEntry userListEntry in joinRoomEvent.Users)
{
User u = this.UserManager.AddUser(this.UserListEntryToUser(userListEntry));
room.AddUser(u);
}

this.UserManager.Me.Room = room;
}

private User UserListEntryToUser(UserListEntry entry)
Expand Down
4 changes: 2 additions & 2 deletions SocketService.Client.API/Manager/RoomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void AddRoom(Room room)
}
}

public void AddRoomVariable(int RoomId, string Name, RoomVariable Value)
public void AddRoomVariable(int RoomId, string Name, SharedObject Value)
{
Room room = FindById(RoomId);
if (room != null)
Expand All @@ -63,7 +63,7 @@ public void DeleteRoomVariable(int RoomId, string Name)
}
}

public void UpdateRoomVariable(int RoomId, string Name, RoomVariable Value)
public void UpdateRoomVariable(int RoomId, string Name, SharedObject Value)
{
Room room = FindById(RoomId);
if (room != null)
Expand Down
2 changes: 1 addition & 1 deletion SocketService.Client.API/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Threading;
using System.Collections;
using System.Net.Sockets;
using SocketService.Framework.Crypto;
using SocketService.Crypto;
using SocketService.Framework.Client.Sockets;
using SocketService.Framework.Request;
using SocketService.Framework.Client.Serialize;
Expand Down
12 changes: 2 additions & 10 deletions SocketService.Client.API/SocketService.Client.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,9 @@
<Project>{93FD4F32-5214-40E3-8E36-5B4E354F10C4}</Project>
<Name>SocketService.Framework.Client</Name>
</ProjectReference>
<ProjectReference Include="..\SocketService.Framework.Crypto\SocketService.Framework.Crypto.csproj">
<ProjectReference Include="..\SocketService.Framework.Crypto\SocketService.Crypto.csproj">
<Project>{4138075A-49CD-4A46-92CB-DFF64A0BB0B6}</Project>
<Name>SocketService.Framework.Crypto</Name>
</ProjectReference>
<ProjectReference Include="..\SocketService.Framework.Request\SocketService.Framework.Request.csproj">
<Project>{5266A3D3-25DC-492B-BFDC-973D79BA7D90}</Project>
<Name>SocketService.Framework.Request</Name>
</ProjectReference>
<ProjectReference Include="..\SocketService.Framework.SharedObjects\SocketService.Framework.SharedObjects.csproj">
<Project>{67292447-E315-4583-8FD5-14DEA8D4B08E}</Project>
<Name>SocketService.Framework.SharedObjects</Name>
<Name>SocketService.Crypto</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
53 changes: 53 additions & 0 deletions SocketService.Framework.Client/SharedObjects/SharedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,59 @@ public class SharedObject
{
private Hashtable data = new Hashtable();

public SharedObject()
{
}

public SharedObject(object value)
{
SharedObjectDataType dt = DataTypeFromType(value.GetType());
SetElementValue("", value, dt);
}

private SharedObjectDataType DataTypeFromType(Type t)
{
if (t.IsAssignableFrom(typeof(string)))
{
return SharedObjectDataType.String;
}
else if (t.IsAssignableFrom(typeof(int)))
{
return SharedObjectDataType.Integer;
}
else if(t.IsAssignableFrom(typeof(long)))
{
return SharedObjectDataType.Long;
}
else if (t.IsAssignableFrom(typeof(double)))
{
return SharedObjectDataType.Double;
}
else if(t.IsAssignableFrom(typeof(byte)))
{
return SharedObjectDataType.Byte;
}
else if (t.IsAssignableFrom(typeof(char)))
{
return SharedObjectDataType.Character;
}
else if (t.IsClass)
{
return SharedObjectDataType.BzObject;
}
else if( t.IsArray)
{
// check array type
return DataTypeFromType(t.GetElementType());
}
else
{
return SharedObjectDataType.BzObject;
}


}

/// <summary>
/// Gets the read only copy.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@
<Compile Include="PublicMessageRequest.cs" />
<Compile Include="UpdateRoomVariableRequest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SocketService.Framework.Crypto\SocketService.Framework.Crypto.csproj">
<Project>{4138075A-49CD-4A46-92CB-DFF64A0BB0B6}</Project>
<Name>SocketService.Framework.Crypto</Name>
</ProjectReference>
<ProjectReference Include="..\SocketService.Framework.SharedObjects\SocketService.Framework.SharedObjects.csproj">
<Project>{67292447-E315-4583-8FD5-14DEA8D4B08E}</Project>
<Name>SocketService.Framework.SharedObjects</Name>
</ProjectReference>
</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.
Expand Down
Binary file modified SocketService.Framework/ServerData.sdf
Binary file not shown.
2 changes: 2 additions & 0 deletions SocketService/Actions/RoomActionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace SocketService.Actions
{
class RoomActionEngine : SingletonBase<RoomActionEngine>
{
public const string DefaultRoom = "";

public Room CreateRoom(string roomName)
{
Room room = RoomRepository.Instance.Query( r => r.Name.Equals(roomName) ).FirstOrDefault();
Expand Down
Loading

0 comments on commit 55439c8

Please sign in to comment.