I'm pretty sure that this has more to do with my eyes than the code but I cant see many of the operators (very fuzzy).
I'm using VS 2010 pro and it seems to be having trouble with the Values.Where statements:
'System.Collections.Generic.Dictionary.ValueCollection' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Enumerable.Where(System.Collections.Generic.IEnumerable, System.Func)' has some invalid arguments.
and the FirstOrDefault() statements:
'Server2Server.Server2Server.SubServerType' does not contain a definition for 'FirstOrDefault' and no extension method 'FirstOrDefault' accepting a first argument of type 'Server2Server.Server2Server.SubServerType' could be found (are you missing a using directive or an assembly reference?)
Let me know whether I missed something had some sort of brain fart.
Thanks for any input,
This is what I got transcribed from the video plus whatever VS decided that it wanted to be happy:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExitGames.Logging;
using Server2Server.Server2Server;
namespace Server2Server.MasterServer
{
public class SubServerCollection : Dictionary
{
public IncomingSubServerPeer LoginServer { get; protected set; }
public IncomingSubServerPeer ChatServer { get; protected set; }
public object subServerPeer { get; set; }
protected static readonly ILogger Log = LogManager.GetCurrentClassLogger();
public void onConnect(IncomingSubServerPeer subServerPeer)
{
if (!subServerPeer.ServerId.HasValue)
{
throw new InvalidOperationException("Server ID cannot be Null");
}
if (subServerPeer.ServerId.HasValue)
{
lock (this)
{
IncomingSubServerPeer peer;
if (TryGetValue(subServerPeer.ServerId.Value, out peer))
{
peer.Disconnect();
Remove(subServerPeer.ServerId.Value);
if (subServerPeer.ServerId.Value == ChatServer.ServerId)
{
ChatServer = null;
}
if (subServerPeer.ServerId.Value == LoginServer.ServerId)
{
LoginServer = null;
}
}
Add(subServerPeer.ServerId.Value, subServerPeer);
ResetServers();
}
}
}
public void ResetServers()
{
if (ChatServer != null && ChatServer.SubServerType != SubServerType.Chat)
{
IncomingSubServerPeer peer = Values.Where(subServerPeer == subServerPeer.SubServerType.Chat).FirstOrDefault();
if (peer != null)
ChatServer = peer;
}
if (LoginServer != null && LoginServer.SubServerType != SubServerType.Login)
{
IncomingSubServerPeer peer = Values.Where(subServerPeer == subServerPeer.SubServerType.Login).FirstOrDefault();
if (peer != null)
LoginServer = peer;
}
if (ChatServer == null || ChatServer.ServerId == null)
{
ChatServer = Values.Where(subServerPeer >= subServerPeer.SubServerType.Chat).FirstOrDefault() ??
Values.Where(subServerPeer >= (subServerPeer.SubServerType & SubServerType.Chat) == SubServerType.Chat.FirstOrDefault());
}
if (LoginServer == null || LoginServer.ServerId == null)
{
LoginServer = Values.Where(subServerPeer >= subServerPeer.SubServerType.Login).FirstOrDefault() ??
Values.Where(subServerPeer >= (subServerPeer.SubServerType & SubServerType.Login) == SubServerType.Login.FirstOrDefault());
}
if (ChatServer != null)
{
Log.Debug ("Chat Server: " + ChatServer.ConnectionId);
}
if (LoginServer != null)
{
Log.Debug ("Login Server: " + LoginServer.ConnectionId);
}
}
public void onDisconnect(IncomingSubServerPeer subServerPeer)
{
if (!subServerPeer.ServerId.HasValue)
{
throw new InvalidOperationException("Server ID cannot be Null");
}
Guid id = subServerPeer.ServerId.Value;
lock (this)
{
IncomingSubServerPeer peer;
if (!TryGetValue(id, out peer)) return;
if (peer == subServerPeer)
{
Remove (id);
if (ChatServer != null && id == ChatServer.ServerId)
{
ChatServer = null;
}
if (LoginServer != null && id == LoginServer.ServerId)
{
LoginServer = null;
}
ResetServers();
}
}
}
}
}
jonathan.deceptive
Thu, 02/09/2012 - 18:02
Permalink
Hi Weepdrag,
Hi Weepdrag,
Not sure if you are still watching this, but your issue is with your Where statement. The Linq system is always meant to be like this:
object.LinqQuery(tester => tester.Test);
So what you are having issues with in the code is:
Values.Where(subServerPeer => subServerPeer.SubServerType == SubServerType.Login);
And you can't interchange >= and =>, think of => as a Goes-In-To operator rather than a greater-than-or-equal operator.
I hope this helps you out.
Regards,
Jonathan
weepdrag
Sun, 03/11/2012 - 15:17
Permalink
Thanks Jonathan,
Thanks Jonathan,
I thought it might have been something fairly simple. But fuzzy video and 50 year old eyes don't mix well.
I'll give it a shot, thanks
OK, that resolved a few of the errors, but, I need to go back through the video and see if I missed something else in syntax. Still have 14 errors to resolve most of which are of this type:
'object' does not contain a definition for 'SubServerType' and no extension method 'SubServerType' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) W:\deploy\*****\Server2Server\Server2Server\MasterServer\SubServerCollection.cs 57 90 Server2Server
'System.Collections.Generic.Dictionary.ValueCollection' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Enumerable.Where(System.Collections.Generic.IEnumerable, System.Func)' has some invalid arguments W:\deploy\******\Server2Server\Server2Server\MasterServer\SubServerCollection.cs 57 46 Server2Server
Argument 2: cannot convert from 'bool' to 'System.Func' W:\deploy\******\Server2Server\Server2Server\MasterServer\SubServerCollection.cs 57 59 Server2Server
Thanks again for pointing me in the right direction
nOograss
Mon, 05/14/2012 - 10:42
Permalink
Values.Where(..) params
Hi,
I'm currently having some trouble with this method,
IncomingSubServerPeer peer = Values.Where(subServerPeer => subServerPeer.SubServerType == SubServerType.Chat ).FirstOrDefault();
It is telling me that it can convert a lambda expression to System.Func
Any advise ?