Skip to content

Commit

Permalink
More work on optimizing Zily
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeliux committed Nov 2, 2023
1 parent c2d7b35 commit 4184c97
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 443 deletions.
4 changes: 0 additions & 4 deletions src/ISide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public interface ISide
/// </summary>
Version Version { get; }

/// <summary>
/// Gets the identifiers of the <see cref="ISide"/>.
/// </summary>
string[] Identifiers { get; }

/// <summary>
/// Gets the name of the <see cref="ISide"/>.
Expand Down
52 changes: 26 additions & 26 deletions src/Side.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,20 @@ namespace SAPTeam.Zily
public class Side : ISide
{
/// <inheritdoc/>
public string Protocol { get; }
public virtual string Protocol { get; }

/// <inheritdoc/>
public Version Version { get; }
public virtual Version Version { get; }

/// <inheritdoc/>
public string[] Identifiers { get; }

/// <inheritdoc/>
public string Name { get; }
public virtual string Name { get; }

/// <summary>
/// Initializes a new instance of the <see cref="Side"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this side.
/// </param>
public Side(string protocol)
public Side()
{
Protocol = protocol;

}

/// <summary>
Expand All @@ -39,32 +33,38 @@ public Side(string protocol)
/// <param name="protocol">
/// The name of protocol implemented by this side.
/// </param>
/// <param name="version">
/// The version of the side.
/// </param>
/// <param name="name">
/// The name of the side.
/// </param>
public Side(string protocol, string name)
public Side(string protocol, Version version, string name)
{
Protocol = protocol;
Version = version;
Name = name;
}

/// <summary>
/// Initializes a new instance of the <see cref="Side"/>.
/// Gets the string identifier of this Side.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this side.
/// </param>
/// <param name="name">
/// The name of the side.
/// </param>
/// <param name="identifiers">
/// The identifiers of the side.
/// </param>
public Side(string protocol, string name, string[] identifiers)
/// <returns></returns>
public string GetIdentifier()
{
Protocol = protocol;
Name = name;
Identifiers = identifiers;
return $"{Protocol};{Version.ToString()};{Name}";
}

/// <summary>
/// Parses an string identifier to an instance of <see cref="Side"/>.
/// </summary>
/// <param name="identifier"></param>
/// <returns></returns>
public static Side Parse(string identifier)
{
string[] data = identifier.Split(';');

return new Side(data[0], Version.Parse(data[1]), data[2]);
}
}
}
59 changes: 12 additions & 47 deletions src/ZilyClientSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,13 @@ namespace SAPTeam.Zily
/// </summary>
public class ZilyClientSide : ZilySide
{
/// <summary>
/// Initializes a new instance of the <see cref="ZilyClientSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
public ZilyClientSide(string protocol) : base(protocol, "Zily Side", new string[]{"zily"})
{

}

/// <summary>
/// Initializes a new instance of the <see cref="ZilyClientSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
/// <param name="name">
/// The name of this zily instance.
/// </param>
public ZilyClientSide(string protocol, string name) : base(protocol, name, new string[]{"zily", name})
{

}

/// <summary>
/// Initializes a new instance of the <see cref="ZilyClientSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
/// <param name="name">
/// The name of this zily instance.
/// </param>
/// <param name="identifiers">
/// The identifiers of this zily instance.
/// </param>
public ZilyClientSide(string protocol, string name, string[] identifiers) : base(protocol, name, identifiers)
{

}

/// <inheritdoc/>
public override void ParseHeader(ZilyHeader header)
{
switch (header.Flag)
{
case ZilyHeaderFlag.Disconnected:
logger.Information("Zily server did shutdown");
Parent.logger.Information("Zily server did shutdown");
break;
}

Expand All @@ -67,11 +25,18 @@ public override void ParseHeader(ZilyHeader header)
/// </summary>
public void Connect()
{
logger.Information("Establishing a Zily connection");
Parent.logger.Information("Establishing a Zily connection");
Parent.Send(new ZilyHeader(ZilyHeaderFlag.SideIdentifier));

if (Parent.IsClosed)
{
return;
}

Parent.WriteCommand(new ZilyHeader(ZilyHeaderFlag.Connected));
Parent.IsOnline = true;

zs.WriteCommand(new ZilyHeader(ZilyHeaderFlag.Connected));
zs.IsOnline = true;
logger.Information("Connected to the Zily server");
Parent.logger.Information("Connected to {name}", Parent.OtherSide.Name);
}
}
}
5 changes: 5 additions & 0 deletions src/ZilyHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace SAPTeam.Zily
/// </summary>
public class ZilyHeader
{
/// <summary>
/// Gets an static Ok header object.
/// </summary>
public static ZilyHeader Ok { get; } = new ZilyHeader(ZilyHeaderFlag.Ok);

/// <summary>
/// Gets or Sets the packet flag.
/// </summary>
Expand Down
9 changes: 7 additions & 2 deletions src/ZilyHeaderFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ public class ZilyHeaderFlag
public const int Disconnected = 5;

/// <summary>
/// Contains a packet with console message
/// Contains a packet with Side information.
/// </summary>
public const int Write = 6;
public const int SideIdentifier = 6;

/// <summary>
/// Contains a packet with console message.
/// </summary>
public const int Write = 7;
}
}
45 changes: 2 additions & 43 deletions src/ZilyPipeServerSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,10 @@ namespace SAPTeam.Zily
/// </summary>
public class ZilyPipeServerSide : ZilyServerSide
{
/// <summary>
/// Initializes a new instance of the <see cref="ZilyPipeServerSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
public ZilyPipeServerSide(string protocol) : base(protocol, "Zily Side", new string[]{"zily"})
{

}

/// <summary>
/// Initializes a new instance of the <see cref="ZilyPipeServerSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
/// <param name="name">
/// The name of this zily instance.
/// </param>
public ZilyPipeServerSide(string protocol, string name) : base(protocol, name, new string[]{"zily", name})
{

}

/// <summary>
/// Initializes a new instance of the <see cref="ZilyPipeServerSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
/// <param name="name">
/// The name of this zily instance.
/// </param>
/// <param name="identifiers">
/// The identifiers of this zily instance.
/// </param>
public ZilyPipeServerSide(string protocol, string name, string[] identifiers) : base(protocol, name, identifiers)
{

}

/// <inheritdoc/>
public override void Wait()
{
((NamedPipeServerStream)zs.Stream).WaitForConnection();
((NamedPipeServerStream)Parent.Stream).WaitForConnection();
}
}
}
53 changes: 7 additions & 46 deletions src/ZilyServerSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,23 @@ namespace SAPTeam.Zily
/// </summary>
public class ZilyServerSide : ZilySide
{
/// <summary>
/// Initializes a new instance of the <see cref="ZilyServerSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
public ZilyServerSide(string protocol) : base(protocol, "Zily Side", new string[]{"zily"})
{

}

/// <summary>
/// Initializes a new instance of the <see cref="ZilyServerSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
/// <param name="name">
/// The name of this zily instance.
/// </param>
public ZilyServerSide(string protocol, string name) : base(protocol, name, new string[]{"zily", name})
{

}

/// <summary>
/// Initializes a new instance of the <see cref="ZilyServerSide"/>.
/// </summary>
/// <param name="protocol">
/// The name of protocol implemented by this zily side.
/// </param>
/// <param name="name">
/// The name of this zily instance.
/// </param>
/// <param name="identifiers">
/// The identifiers of this zily instance.
/// </param>
public ZilyServerSide(string protocol, string name, string[] identifiers) : base(protocol, name, identifiers)
{

}

/// <summary>
/// Waits until a client connects to the server and then establishes the Zily connection.
/// </summary>
public void Accept()
{
bool everConnected = false;

logger.Debug("Waiting for client");
Parent.logger.Debug("Waiting for client");
Wait();

while (true)
{
var header = ZilyHeader.Parse(zs.Stream);
var header = ZilyHeader.Parse(Parent.Stream);
if (!everConnected)
{
logger.Information("A new client connected to the pipe server");
logger.Information("Establishing a Zily connection");
Parent.logger.Information("A new client connected to the pipe server");
Parent.logger.Information("Establishing a Zily connection");
everConnected = true;
}

Expand All @@ -81,6 +39,9 @@ public void Accept()
}
}

/// <summary>
/// Waits before starting client acceptation.
/// </summary>
public virtual void Wait()
{

Expand Down
Loading

0 comments on commit 4184c97

Please sign in to comment.