├── .gitignore
├── RaftDemo
├── Resources
│ ├── Entypo.ttf
│ ├── Entypo-license.txt
│ └── WindowsIcons-license.txt
├── Views
│ ├── Actors
│ │ ├── broker.png
│ │ ├── DiagramNodeBrokerView.xaml
│ │ ├── ClientView.xaml.cs
│ │ ├── DiagramNodeBrokerView.xaml.cs
│ │ ├── ClientView.xaml
│ │ └── ServerView.xaml.cs
│ ├── AttachDescriptorFromView.xaml
│ ├── LogEntryView.xaml.cs
│ ├── AppView.xaml.cs
│ ├── SimulationSettingsView.xaml.cs
│ ├── AttachDescriptorToView.xaml.cs
│ ├── AttachDescriptorFromView.xaml.cs
│ ├── AttachDescriptorToView.xaml
│ ├── LogEntryView.xaml
│ ├── AppView.xaml
│ └── SimulationSettingsView.xaml
├── ViewModels
│ ├── AppViewModel.cs
│ ├── IShell.cs
│ ├── AttachDescriptorToViewModel.cs
│ ├── AttachDescriptorFromViewModel.cs
│ ├── Actors
│ │ ├── BrokerViewModel.cs
│ │ ├── ClientViewModel.cs
│ │ └── ActorViewModel.cs
│ ├── ClientToServerConnectionViewModel.cs
│ ├── ServerToServerConnectionViewModel.cs
│ └── LogEntryViewModel.cs
├── FodyWeavers.xml
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ └── Resources.Designer.cs
├── Model
│ ├── DiagramNodeBroker.cs
│ ├── DiagramNodeClient.cs
│ ├── DiagramNodeServer.cs
│ ├── Messages.cs
│ ├── RaftSoundPlayer.cs
│ ├── RaftClient.cs
│ ├── SimulationSettings.cs
│ └── RaftHost.cs
├── NodeSoftware
│ ├── OutboundMessage.cs
│ ├── InboundMessage.cs
│ └── TimeoutTimer.cs
├── App.xaml.cs
├── packages.config
├── App.config
├── Converters
│ ├── BooleanToOpacityConverter.cs
│ ├── RaftStateToStyle.cs
│ └── RaftStateToColorConverter.cs
├── App.xaml
└── AppBootstrapper.cs
├── Report20150128-1922 — skrót.lnk
├── RaftAlgorithm
├── Messages
│ ├── RaftMessageBase.cs
│ ├── RequestVote.cs
│ ├── RequestVoteResult.cs
│ ├── ClientRequestRPC.cs
│ ├── AppendEntriesResult.cs
│ └── AppendEntriesRPC.cs
├── IRaftEventListener.cs
├── RaftNodeState.cs
├── IRaftNodeSettings.cs
├── LogEntry.cs
├── Properties
│ └── AssemblyInfo.cs
├── States
│ ├── RaftStateBase.cs
│ ├── Leader.cs
│ ├── Follower.cs
│ └── Candicate.cs
├── RaftAlgorithm.csproj
└── RaftEventResult.cs
├── RaftDemo.Tests
├── Images
│ ├── UnitTestLogo.scale-100.png
│ ├── UnitTestSmallLogo.scale-100.png
│ ├── UnitTestStoreLogo.scale-100.png
│ └── UnitTestSplashScreen.scale-100.png
├── UnitTest1.cs
├── Properties
│ └── AssemblyInfo.cs
└── Package.appxmanifest
├── ActorTest
├── packages.config
├── TestClientActor.cs
├── TestServerActor.cs
└── Properties
│ └── AssemblyInfo.cs
├── NetworkTest
├── packages.config
├── Properties
│ └── AssemblyInfo.cs
└── SchedlulerTest.cs
├── TaskSchedulerRun
├── App.config
├── Properties
│ └── AssemblyInfo.cs
├── Program.cs
├── TsTest.cs
├── TaskSchedulerRun.csproj
└── HighPrecisionTimer.cs
├── CaliDiagram
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ └── Resources.Designer.cs
├── packages.config
├── IConnectorSideStrategy.cs
├── Commands
│ ├── MoveNodeCommand.cs
│ ├── DiagramCommand.cs
│ ├── RemoveNodeCommand.cs
│ ├── AddNodeCommand.cs
│ └── AddConnectionCommand.cs
├── ViewModels
│ ├── DiagramBatchMode.cs
│ ├── AttachSides.cs
│ ├── AttachPoint.cs
│ └── DiagramHelpers.cs
├── Views
│ ├── EdgeView.xaml
│ ├── NodeBaseView.xaml
│ ├── DiagramView.xaml.cs
│ ├── EdgeView.xaml.cs
│ └── DiagramView.xaml
├── Model
│ ├── DiagramNodeBase.cs
│ ├── DiagramConnection.cs
│ └── DiagramModel.cs
├── CaliDiagramHelpers.cs
├── DefaultConnectionStrategy.cs
└── Serialization
│ ├── XmlSettings.cs
│ └── DiagramXmlSerializer.cs
├── NetworkModel
├── Actors
│ ├── ActorTimer.cs
│ ├── ActorEvents
│ │ ├── ActorEventBase.cs
│ │ ├── ActorEventType.cs
│ │ ├── TimerElapsedEvent.cs
│ │ ├── ChannelAddedEvent.cs
│ │ ├── ChannelRemovedEvent.cs
│ │ └── MessageReceivedEvent.cs
│ ├── ActorChannel.cs
│ ├── ClientActor.cs
│ ├── ActorBase.VirtualFunctions.cs
│ ├── ActorState.cs
│ ├── ServerActor.cs
│ └── ActorBase.cs
├── ConnectionState.cs
├── ChannelType.cs
├── NetworkNode.cs
├── InProcNetwork
│ ├── TaskScheduling
│ │ ├── TaskSchedulerTask.cs
│ │ └── TaskScheduler.cs
│ ├── SocketId.cs
│ ├── InProcServer.cs
│ └── InProcNetwork.cs
├── INetworkModel.cs
├── Properties
│ └── AssemblyInfo.cs
├── INetworkSocket.cs
├── NetworkClientState.cs
├── INetworkServer.cs
└── NetworkModel.csproj
├── DiagramDesigner.sln
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | pack
2 | packages
3 | */obj/
4 | */bin/
5 | *.suo
6 |
--------------------------------------------------------------------------------
/RaftDemo/Resources/Entypo.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toomasz/CaliDiagram/HEAD/RaftDemo/Resources/Entypo.ttf
--------------------------------------------------------------------------------
/Report20150128-1922 — skrót.lnk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toomasz/CaliDiagram/HEAD/Report20150128-1922 — skrót.lnk
--------------------------------------------------------------------------------
/RaftDemo/Views/Actors/broker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toomasz/CaliDiagram/HEAD/RaftDemo/Views/Actors/broker.png
--------------------------------------------------------------------------------
/RaftDemo/ViewModels/AppViewModel.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toomasz/CaliDiagram/HEAD/RaftDemo/ViewModels/AppViewModel.cs
--------------------------------------------------------------------------------
/RaftDemo/ViewModels/IShell.cs:
--------------------------------------------------------------------------------
1 | namespace RaftDemo
2 | {
3 | public interface IShell
4 | {
5 | void Close();
6 | }
7 | }
--------------------------------------------------------------------------------
/RaftAlgorithm/Messages/RaftMessageBase.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace RaftAlgorithm.Messages
3 | {
4 | public class RaftMessageBase
5 | {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/RaftDemo.Tests/Images/UnitTestLogo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toomasz/CaliDiagram/HEAD/RaftDemo.Tests/Images/UnitTestLogo.scale-100.png
--------------------------------------------------------------------------------
/RaftDemo.Tests/Images/UnitTestSmallLogo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toomasz/CaliDiagram/HEAD/RaftDemo.Tests/Images/UnitTestSmallLogo.scale-100.png
--------------------------------------------------------------------------------
/RaftDemo.Tests/Images/UnitTestStoreLogo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toomasz/CaliDiagram/HEAD/RaftDemo.Tests/Images/UnitTestStoreLogo.scale-100.png
--------------------------------------------------------------------------------
/RaftDemo/FodyWeavers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ActorTest/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/RaftDemo.Tests/Images/UnitTestSplashScreen.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toomasz/CaliDiagram/HEAD/RaftDemo.Tests/Images/UnitTestSplashScreen.scale-100.png
--------------------------------------------------------------------------------
/NetworkTest/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/RaftAlgorithm/IRaftEventListener.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace RaftAlgorithm
3 | {
4 | public interface IRaftEventListener
5 | {
6 | void OnElectionStarted();
7 | void OnAppendEntries();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/RaftDemo/Resources/Entypo-license.txt:
--------------------------------------------------------------------------------
1 | Entypo (http://www.entypo.com/) is created by Daniel Bruce and released under the Creative Commons, Share Alike/Attribution license.
2 |
3 | http://creativecommons.org/licenses/by-sa/3.0/
--------------------------------------------------------------------------------
/TaskSchedulerRun/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/RaftAlgorithm/RaftNodeState.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace RaftAlgorithm
3 | {
4 | public enum RaftNodeState
5 | {
6 | Booting,
7 | Follower,
8 | Candidate,
9 | Leader
10 | };
11 | }
12 |
--------------------------------------------------------------------------------
/RaftDemo/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/CaliDiagram/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/CaliDiagram/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/RaftDemo/Model/DiagramNodeBroker.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.Model;
2 | using System.Runtime.Serialization;
3 |
4 | namespace RaftDemo.Model
5 | {
6 | [DataContract]
7 | class DiagramNodeBroker : DiagramNodeBase
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/RaftDemo/Model/DiagramNodeClient.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.Model;
2 | using System.Runtime.Serialization;
3 |
4 | namespace RaftDemo.Model
5 | {
6 | [DataContract]
7 | class DiagramNodeClient : DiagramNodeBase
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/RaftDemo/Model/DiagramNodeServer.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.Model;
2 | using System.Runtime.Serialization;
3 |
4 | namespace RaftDemo.Model
5 | {
6 | [DataContract]
7 | class DiagramNodeServer:DiagramNodeBase
8 | {
9 |
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorTimer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors
8 | {
9 | public class ActorTimer
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/RaftDemo/NodeSoftware/OutboundMessage.cs:
--------------------------------------------------------------------------------
1 |
2 | using NetworkModel;
3 | namespace RaftDemo.NodeSoftware
4 | {
5 | public class OutboundMessage
6 | {
7 | public INetworkSocket DestinationChannel { get; set; }
8 | public object Message { get; set; }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/CaliDiagram/IConnectorSideStrategy.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.ViewModels;
2 |
3 | namespace CaliDiagram
4 | {
5 | ///
6 | /// Connector placement behaviour
7 | ///
8 | public interface IConnectorSideStrategy
9 | {
10 | AttachSides GetSidesForConnection(ConnectionViewModel connection);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/RaftDemo/ViewModels/AttachDescriptorToViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using CaliDiagram.ViewModels;
7 |
8 | namespace RaftDemo.ViewModels
9 | {
10 | class AttachDescriptorToViewModel : NodeBaseViewModel
11 | {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/RaftDemo/ViewModels/AttachDescriptorFromViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using CaliDiagram.ViewModels;
7 |
8 | namespace RaftDemo.ViewModels
9 | {
10 | public class AttachDescriptorFromViewModel: NodeBaseViewModel
11 | {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/RaftAlgorithm/Messages/RequestVote.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace RaftAlgorithm.Messages
3 | {
4 | public class RequestVote : RaftMessageBase
5 | {
6 | public string CandidateId { get; set; }
7 | public int CandidateTerm { get; set; }
8 | public override string ToString()
9 | {
10 | return "RV";
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorEvents/ActorEventBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors.ActorEvents
8 | {
9 | public abstract class ActorEventBase
10 | {
11 | public abstract ActorEventType EventType { get; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/RaftDemo/NodeSoftware/InboundMessage.cs:
--------------------------------------------------------------------------------
1 |
2 | using NetworkModel;
3 | namespace RaftDemo.NodeSoftware
4 | {
5 | ///
6 | /// Message origination from another component
7 | ///
8 | public class InboundMessage
9 | {
10 | public INetworkSocket SourceChannel { get; set; }
11 | public object Message { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/NetworkModel/ConnectionState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel
8 | {
9 | public enum ConnectionState
10 | {
11 | Closed,
12 | Connecting,
13 | Established,
14 | ConnectionFailed,
15 | Closing
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/RaftDemo.Tests/UnitTest1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
6 |
7 | namespace RaftDemo.Tests
8 | {
9 | [TestClass]
10 | public class UnitTest1
11 | {
12 | [TestMethod]
13 | public void TestMethod1()
14 | {
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorEvents/ActorEventType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors.ActorEvents
8 | {
9 | public enum ActorEventType
10 | {
11 | ChannelAdded,
12 | ChannelRemoved,
13 | MessageReceived,
14 | TimerElapsed
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorChannel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors
8 | {
9 | public class ActorChannel
10 | {
11 | public ActorChannel(INetworkSocket Socket)
12 | {
13 | this.Socket = Socket;
14 | }
15 | public INetworkSocket Socket { get; private set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/RaftDemo/ViewModels/Actors/BrokerViewModel.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.ViewModels;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RaftDemo.ViewModels.Actors
9 | {
10 | public class BrokerViewModel: NodeBaseViewModel
11 | {
12 | public BrokerViewModel(string name)
13 | {
14 | this.Name = name;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/CaliDiagram/Commands/MoveNodeCommand.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.ViewModels;
2 |
3 | namespace CaliDiagram.Commands
4 | {
5 | class MoveNodeCommand : DiagramCommand
6 | {
7 | public MoveNodeCommand(DiagramViewModel diagram):base(diagram)
8 | {
9 | Description = "Move";
10 | }
11 |
12 | public override void OnSelected()
13 | {
14 | Diagram.HelpText = "Drag and drop nodes!";
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/RaftDemo/Model/Messages.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace RaftDemo.Model
8 | {
9 | public class Message
10 | {
11 | public Message(string op)
12 | {
13 | this.Operation = op;
14 | }
15 | public string Operation
16 | {
17 | get;
18 | private set;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/RaftAlgorithm/IRaftNodeSettings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace RaftAlgorithm
8 | {
9 | public interface IRaftNodeSettings
10 | {
11 | int ClusterSize { get; }
12 | int LeaderTimeoutFrom { get; }
13 | int LeaderTimeoutTo { get; }
14 |
15 | int FollowerTimeoutFrom { get; }
16 | int FollowerTimeoutTo { get; }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CaliDiagram/ViewModels/DiagramBatchMode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CaliDiagram.ViewModels
4 | {
5 | public class DiagramBatchMode: IDisposable
6 | {
7 | private DiagramViewModel diagram;
8 | public DiagramBatchMode(DiagramViewModel diagram)
9 | {
10 | this.diagram = diagram;
11 | diagram.IsInBatchMode = true;
12 | }
13 |
14 | public void Dispose()
15 | {
16 | diagram.IsInBatchMode = false;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/RaftAlgorithm/Messages/RequestVoteResult.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace RaftAlgorithm.Messages
3 | {
4 | public class RequestVoteResponse : RaftMessageBase
5 | {
6 | public bool VoteGranted { get; set; }
7 | public int CurrentTerm { get; set; }
8 | public string VoterId { get; set; }
9 |
10 | public override string ToString()
11 | {
12 | if (VoteGranted)
13 | return "Yes";
14 | else
15 | return "No";
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ClientActor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors
8 | {
9 | ///
10 | /// NetworkClient actor can only make connection to server actors
11 | ///
12 | public class ClientActor : ActorBase
13 | {
14 | public ClientActor(INetworkModel networkModel)
15 | :base(networkModel)
16 | {
17 |
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ActorTest/TestClientActor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NetworkModel;
7 | using NetworkModel.Actors;
8 |
9 | namespace ActorTest
10 | {
11 | public class TestClientActor: ClientActor
12 | {
13 | public TestClientActor(INetworkModel networkModel) : base(networkModel)
14 | {
15 | }
16 |
17 | public void BroadcastMessage(object message)
18 | {
19 |
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/CaliDiagram/Views/EdgeView.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/RaftAlgorithm/Messages/ClientRequestRPC.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace RaftAlgorithm.Messages
8 | {
9 | public class ClientRequestRPC : RaftMessageBase
10 | {
11 | public TMessageType Message
12 | {
13 | get;
14 | set;
15 | }
16 | public ulong SequenceNumber
17 | {
18 | get;
19 | set;
20 | }
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/RaftDemo/Views/Actors/DiagramNodeBrokerView.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NetworkModel/ChannelType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel
8 | {
9 | public enum ChannelType
10 | {
11 | ///
12 | /// NetworkClient side channel
13 | ///
14 | Client,
15 | ///
16 | /// Server side channel
17 | ///
18 | Server,
19 | ///
20 | /// Listening channel
21 | ///
22 | Listening
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/CaliDiagram/Model/DiagramNodeBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Runtime.Serialization;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace CaliDiagram.Model
10 | {
11 | ///
12 | /// Base diagram node base
13 | ///
14 | [DataContract]
15 | public class DiagramNodeBase
16 | {
17 |
18 | [DataMember]
19 | public Point Location { get; set; }
20 | [DataMember]
21 | public string Name { get; set; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/ActorTest/TestServerActor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NetworkModel;
7 | using NetworkModel.Actors;
8 |
9 | namespace ActorTest
10 | {
11 | public class TestServerActor: ServerActor
12 | {
13 | public TestServerActor(INetworkModel networkModel, string address) : base(networkModel, address)
14 | {
15 | }
16 |
17 | protected override void OnMessageReceived(ActorChannel channel, object message)
18 | {
19 |
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/RaftDemo/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace RaftDemo
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | public App()
17 | {
18 | InitializeComponent();
19 | AppBootstrapper bootstrapper = new AppBootstrapper();
20 | bootstrapper.Initialize();
21 | }
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/CaliDiagram/Model/DiagramConnection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Runtime.Serialization;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace CaliDiagram.Model
9 | {
10 | ///
11 | /// Diagram connection
12 | ///
13 | [DataContract]
14 | public class DiagramConnection
15 | {
16 | public DiagramConnection()
17 | {
18 |
19 | }
20 | [DataMember]
21 | public DiagramNodeBase From { get; set; }
22 | [DataMember]
23 | public DiagramNodeBase To { get; set; }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/CaliDiagram/ViewModels/AttachSides.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace CaliDiagram.ViewModels
3 | {
4 | ///
5 | /// Represents side pair used to determine connection attach points sides
6 | ///
7 | public class AttachSides
8 | {
9 | public AttachSides(AttachDirection fromSide, AttachDirection toSide)
10 | {
11 | FromSide = fromSide;
12 | ToSide = toSide;
13 | }
14 | public AttachDirection FromSide
15 | {
16 | get;
17 | private set;
18 | }
19 | public AttachDirection ToSide
20 | {
21 | get;
22 | private set;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorEvents/TimerElapsedEvent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors.ActorEvents
8 | {
9 | public class TimerElapsedEvent: ActorEventBase
10 | {
11 | public TimerElapsedEvent(ActorTimer timer)
12 | {
13 | Timer = timer;
14 | }
15 | public override ActorEventType EventType
16 | {
17 | get
18 | {
19 | return ActorEventType.TimerElapsed;
20 | }
21 | }
22 | public ActorTimer Timer { get; private set; }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorEvents/ChannelAddedEvent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors.ActorEvents
8 | {
9 | public class ChannelAddedEvent : ActorEventBase
10 | {
11 | public ChannelAddedEvent(ActorChannel channel)
12 | {
13 | Channel = channel;
14 | }
15 | public override ActorEventType EventType
16 | {
17 | get
18 | {
19 | return ActorEventType.ChannelAdded;
20 | }
21 | }
22 | public ActorChannel Channel { get; private set; }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorEvents/ChannelRemovedEvent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors.ActorEvents
8 | {
9 | public class ChannelRemovedEvent : ActorEventBase
10 | {
11 | public ChannelRemovedEvent(ActorChannel channel)
12 | {
13 | Channel = channel;
14 | }
15 | public override ActorEventType EventType
16 | {
17 | get
18 | {
19 | return ActorEventType.ChannelRemoved;
20 | }
21 | }
22 | public ActorChannel Channel { get ; private set;}
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/CaliDiagram/Commands/DiagramCommand.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.ViewModels;
2 | using System.Windows;
3 |
4 | namespace CaliDiagram.Commands
5 | {
6 | public class DiagramCommand
7 | {
8 | protected readonly DiagramViewModel Diagram;
9 | public DiagramCommand(DiagramViewModel diagram)
10 | {
11 | this.Diagram = diagram;
12 | }
13 | public virtual string Description { get; set; }
14 |
15 | public virtual void HandleNodeClick(NodeBaseViewModel node) { }
16 | public virtual void HandleConnectionClick(ConnectionViewModel node) { }
17 | public virtual void HandleDiagramClick(Point location) { }
18 | public virtual void OnSelected() { }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/RaftAlgorithm/LogEntry.cs:
--------------------------------------------------------------------------------
1 | namespace RaftAlgorithm
2 | {
3 | public class LogEntry
4 | {
5 | public LogEntry(int commitIndex, int term, T data)
6 | {
7 | CommitIndex = commitIndex;
8 | Term = term;
9 | Data = data;
10 | }
11 | public override string ToString()
12 | {
13 | return Data.ToString();
14 | }
15 | public T Data
16 | {
17 | get;
18 | set;
19 | }
20 | public int CommitIndex
21 | {
22 | get;
23 | set;
24 | }
25 | public int Term
26 | {
27 | get;
28 | set;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/CaliDiagram/Views/NodeBaseView.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NetworkModel/NetworkNode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel
8 | {
9 | public class NetworkNode
10 | {
11 | public NetworkNode(string name, INetworkModel network)
12 | {
13 | this.Network = network;
14 | this.Name = name;
15 | Init();
16 | }
17 | void Init()
18 | {
19 | Server = Network.CreateServer(Name);
20 | }
21 | INetworkServer Server { get; set; }
22 | INetworkModel Network { get; set; }
23 | public string Name
24 | {
25 | get;
26 | private set;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/RaftDemo/Views/AttachDescriptorFromView.xaml:
--------------------------------------------------------------------------------
1 |
7 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/RaftDemo/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/CaliDiagram/Model/DiagramModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Runtime.Serialization;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace CaliDiagram.Model
9 | {
10 | ///
11 | /// Base diagram model used for saving diagram
12 | ///
13 | [DataContract]
14 | public class DiagramModel
15 | {
16 | public DiagramModel()
17 | {
18 | Nodes = new List();
19 | Edges = new List();
20 | }
21 | [DataMember]
22 | public List Nodes { get; private set; }
23 | [DataMember]
24 | public List Edges { get; private set; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/RaftDemo/Views/LogEntryView.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace RaftDemo.Views
17 | {
18 | ///
19 | /// Interaction logic for LogEntryView.xaml
20 | ///
21 | public partial class LogEntryView : UserControl
22 | {
23 | public LogEntryView()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/RaftDemo/Views/AppView.xaml.cs:
--------------------------------------------------------------------------------
1 | using MahApps.Metro.Controls;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 | using System.Windows.Data;
10 | using System.Windows.Documents;
11 | using System.Windows.Input;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace RaftDemo
18 | {
19 | ///
20 | /// Interaction logic for AppView.xaml
21 | ///
22 | public partial class AppView : MetroWindow
23 | {
24 | public AppView()
25 | {
26 | InitializeComponent();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/RaftDemo/Views/Actors/ClientView.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace RaftDemo.Views.Actors
17 | {
18 | ///
19 | /// Interaction logic for DiagramNodeSmallView.xaml
20 | ///
21 | public partial class ClientView : UserControl
22 | {
23 | public ClientView()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorEvents/MessageReceivedEvent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors.ActorEvents
8 | {
9 | public class MessageReceivedEvent : ActorEventBase
10 | {
11 | public MessageReceivedEvent(ActorChannel channel, object message)
12 | {
13 | Message = message;
14 | Channel = channel;
15 | }
16 |
17 | public override ActorEventType EventType
18 | {
19 | get
20 | {
21 | return ActorEventType.MessageReceived;
22 | }
23 | }
24 | public ActorChannel Channel { get; private set; }
25 | public object Message { get; private set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/RaftDemo/Views/SimulationSettingsView.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace RaftDemo.Views
17 | {
18 | ///
19 | /// Interaction logic for WorldSettingsView.xaml
20 | ///
21 | public partial class SimulationSettingsView : UserControl
22 | {
23 | public SimulationSettingsView()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/RaftDemo/Views/AttachDescriptorToView.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace RaftDemo.Views
17 | {
18 | ///
19 | /// Interaction logic for AttachDescriptorToView.xaml
20 | ///
21 | public partial class AttachDescriptorToView : UserControl
22 | {
23 | public AttachDescriptorToView()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/RaftDemo/Views/Actors/DiagramNodeBrokerView.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace RaftDemo.Views.Actors
17 | {
18 | ///
19 | /// Interaction logic for DiagramNodeBroker.xaml
20 | ///
21 | public partial class DiagramNodeBrokerView : UserControl
22 | {
23 | public DiagramNodeBrokerView()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorBase.VirtualFunctions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NetworkModel.Actors.ActorEvents;
7 |
8 | namespace NetworkModel.Actors
9 | {
10 | public partial class ActorBase
11 | {
12 | protected virtual void OnInitialized() { }
13 | protected virtual void OnDestroyed() { }
14 | protected virtual void OnChannelCreated(ActorChannel channel) { }
15 | protected virtual void OnChannelRemoved(ActorChannel channel) { }
16 | protected virtual void OnMessageReceived(ActorChannel channel, object message) { }
17 | protected virtual void OnCommandReceived(string command) { }
18 |
19 |
20 | public event EventHandler ActorEvent;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/RaftDemo/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/RaftDemo/Views/AttachDescriptorFromView.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace RaftDemo.Views
17 | {
18 | ///
19 | /// Interaction logic for AttachDescriptorFromView.xaml
20 | ///
21 | public partial class AttachDescriptorFromView : UserControl
22 | {
23 | public AttachDescriptorFromView()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/RaftDemo/Views/AttachDescriptorToView.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/CaliDiagram/Commands/RemoveNodeCommand.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.ViewModels;
2 |
3 | namespace CaliDiagram.Commands
4 | {
5 | class RemoveNodeCommand : DiagramCommand
6 | {
7 | public RemoveNodeCommand(DiagramViewModel diagram, string description)
8 | : base(diagram)
9 | {
10 | this.Description = description;
11 | }
12 |
13 | public override void OnSelected()
14 | {
15 | Diagram.HelpText = "Remove any node by clicking it.";
16 | }
17 | public override void HandleNodeClick(NodeBaseViewModel node)
18 | {
19 | Diagram.RemoveNode(node);
20 | }
21 |
22 | public override void HandleConnectionClick(ConnectionViewModel connection)
23 | {
24 | Diagram.RemoveConnection(connection);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/NetworkModel/Actors/ActorState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.Actors
8 | {
9 | public enum ActorState
10 | {
11 | ///
12 | /// Actor is stopped
13 | ///
14 | Stopped,
15 | ///
16 | /// Actor is booting up
17 | ///
18 | Starting,
19 | ///
20 | /// Actor is running
21 | ///
22 | Started,
23 | ///
24 | /// Actor is shutting down
25 | ///
26 | Stopping,
27 | ///
28 | /// Unrecoverable error occured during actor operation
29 | ///
30 | Error
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/RaftDemo/Model/RaftSoundPlayer.cs:
--------------------------------------------------------------------------------
1 | using RaftAlgorithm;
2 | using RaftDemo.Model;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RaftDemo.Model
10 | {
11 | public class RaftSoundPlayer: IRaftEventListener
12 | {
13 | SimulationSettings worldSettings;
14 | public RaftSoundPlayer(SimulationSettings worldSettings)
15 | {
16 | this.worldSettings = worldSettings;
17 | }
18 | public void OnElectionStarted()
19 | {
20 | if (worldSettings.SoundEnabled)
21 | Console.Beep();
22 | }
23 |
24 | public void OnAppendEntries()
25 | {
26 | if(worldSettings.SoundEnabled)
27 | Console.Beep(400, 10);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/CaliDiagram/Commands/AddNodeCommand.cs:
--------------------------------------------------------------------------------
1 | using CaliDiagram.ViewModels;
2 | using System.Windows;
3 |
4 | namespace CaliDiagram.Commands
5 | {
6 | class AddNodeCommand : DiagramCommand
7 | {
8 | NodeTypeBehaviour nodeBehaviour;
9 | public AddNodeCommand(DiagramViewModel diagram, string description, NodeTypeBehaviour nodeTypeBehaviour):base(diagram)
10 | {
11 | this.Description = description;
12 | this.nodeBehaviour = nodeTypeBehaviour;
13 |
14 | }
15 | public override void OnSelected()
16 | {
17 | Diagram.HelpText = Description = string.Format("Add {0} node", nodeBehaviour.Name);
18 | }
19 | public override void HandleDiagramClick(Point location)
20 | {
21 | Diagram.AddNode(nodeBehaviour.CreateNode(location), location);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/RaftDemo/Converters/BooleanToOpacityConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Data;
7 |
8 | namespace RaftDemo.Converters
9 | {
10 | public class BooleanToOpacityConverter:IValueConverter
11 | {
12 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
13 | {
14 | bool boolValue = (bool)value;
15 | if (boolValue == true)
16 | return 1.0;
17 | else
18 | return 0.3;
19 | }
20 |
21 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
22 | {
23 | return null;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/RaftDemo/ViewModels/ClientToServerConnectionViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using CaliDiagram.ViewModels;
8 | using RaftDemo.Model;
9 |
10 | namespace RaftDemo.ViewModels
11 | {
12 | public class ClientToServerConnectionViewModel: ConnectionViewModel
13 | {
14 | public ClientToServerConnectionViewModel(NodeBaseViewModel from, NodeBaseViewModel to, SimulationSettings worldSettings) :
15 | base(from, to)
16 | {
17 | StrokeThickness = 2;
18 | this.worldSettings = worldSettings;
19 | }
20 | SimulationSettings worldSettings;
21 | public override double Latency
22 | {
23 | get
24 | {
25 | return worldSettings.ClientToServerLatency;
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/NetworkModel/InProcNetwork/TaskScheduling/TaskSchedulerTask.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel.InProcNetwork.TaskScheduling
8 | {
9 | public class TaskSchedlulerTask
10 | {
11 | public DateTime SchedluledTime { get; set; }
12 | public TimeSpan ExecuteAfter { get; set; }
13 | public Action Function { get; set; }
14 | ///
15 | /// Get milliseconds from DateTime.Now to task execution
16 | ///
17 | public DateTime RunTime
18 | {
19 | get
20 | {
21 | return SchedluledTime + ExecuteAfter;
22 | }
23 | }
24 | public int RunIn
25 | {
26 | get
27 | {
28 | int runIn = Convert.ToInt32((RunTime - DateTime.Now).TotalMilliseconds);
29 | if (runIn < 0)
30 | runIn = 0;
31 | return runIn;
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/RaftDemo.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RaftDemo.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("RaftDemo.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 |
--------------------------------------------------------------------------------
/RaftDemo/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.0
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace RaftDemo.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/CaliDiagram/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.0
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CaliDiagram.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/RaftAlgorithm/Messages/AppendEntriesResult.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace RaftAlgorithm.Messages
3 | {
4 | public class AppendEntriesResponse : RaftMessageBase
5 | {
6 | public AppendEntriesResponse(int followerTerm, string followerId, bool success)
7 | {
8 | this.FollowerTerm = followerTerm;
9 | this.FollowerId = followerId;
10 | this.Succes = success;
11 | }
12 | public override string ToString()
13 | {
14 | return "OK";
15 | }
16 | ///
17 | /// So leader can know who is message from
18 | ///
19 | ///
20 | public string FollowerId
21 | {
22 | get;
23 | private set;
24 | }
25 | public int FollowerTerm
26 | {
27 | get;
28 | private set;
29 | }
30 | ///
31 | /// true if follower contained entry matching prevLogIndex and prevLogTerm
32 | ///
33 | ///
34 | public bool Succes
35 | {
36 | get;
37 | private set;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/RaftDemo/Model/RaftClient.cs:
--------------------------------------------------------------------------------
1 | using RaftDemo.NodeSoftware;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using NetworkModel;
8 | using NetworkModel.InProcNetwork;
9 |
10 | namespace RaftDemo.Model
11 | {
12 | public class RaftClient: NodeSoftwareBase
13 | {
14 | public RaftClient(INetworkModel networkModel, string clientId) : base(networkModel)
15 | {
16 | this.Id = clientId;
17 | Client = new NetworkClient(networkModel) { MaxConnectAttempts = -1 };
18 | Client.ClientChannel.StateChanged += ClientChannel_StateChanged;
19 | }
20 |
21 | void ClientChannel_StateChanged(object sender, ConnectionState e)
22 | {
23 |
24 | }
25 | public NetworkClient Client
26 | {
27 | get;
28 | private set;
29 | }
30 | public string ServerAddress
31 | {
32 | get { return Client.RemoteAddress; }
33 | set { Client.RemoteAddress = value; }
34 | }
35 |
36 | protected override void OnMessageReceived(INetworkSocket channel, object message)
37 | {
38 | BroadcastExcept(message, channel);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/NetworkModel/INetworkModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetworkModel
8 | {
9 | public interface INetworkModel : IDisposable
10 | {
11 | ///
12 | /// Create network client
13 | ///
14 | /// Address of client, if null will be assigned by network
15 | ///
16 | INetworkSocket CreateClientSocket(string socketAddress = null);
17 |
18 | ///
19 | /// Create network server
20 | ///
21 | ///
22 | INetworkServer CreateServer(string socketAddress, bool startListening = true);
23 |
24 | ///
25 | /// Number of listening sockets in network model instance
26 | ///
27 | int ListeningSocketCount { get; }
28 |
29 | ///
30 | /// Number of connected sockets in network model instance
31 | ///
32 | int ConnectedSocketCount { get; }
33 |
34 | ///
35 | /// Exceptions thrown from other threads
36 | ///
37 | List Exceptions { get; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/RaftDemo/Converters/RaftStateToStyle.cs:
--------------------------------------------------------------------------------
1 | using RaftAlgorithm;
2 | using System;
3 | using System.Globalization;
4 | using System.Windows;
5 | using System.Windows.Data;
6 |
7 | namespace RaftDemo.Converters
8 | {
9 | public class RaftStateToStyle: IValueConverter
10 | {
11 | public Style FollowerStyle
12 | {
13 | get;
14 | set;
15 | }
16 | public Style LeaderStyle
17 | {
18 | get;
19 | set;
20 | }
21 | public Style CandidateStyle
22 | {
23 | get;
24 | set;
25 | }
26 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
27 | {
28 | if (!(value is RaftNodeState))
29 | return null;
30 |
31 | RaftNodeState state = (RaftNodeState)value;
32 |
33 | if (state == RaftNodeState.Follower)
34 | return FollowerStyle;
35 | if (state == RaftNodeState.Leader)
36 | return LeaderStyle;
37 | if (state == RaftNodeState.Candidate)
38 | return CandidateStyle;
39 | return null;
40 | }
41 |
42 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
43 | {
44 | return null;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/CaliDiagram/Views/DiagramView.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 | using CaliDiagram.ViewModels;
16 |
17 | namespace CaliDiagram.Views
18 | {
19 | ///
20 | /// Interaction logic for DiagramView.xaml
21 | ///
22 | public partial class DiagramView : UserControl
23 | {
24 | public DiagramView()
25 | {
26 | InitializeComponent();
27 | diagram.PreviewMouseLeftButtonDown += diagram_PreviewMouseLeftButtonDown;
28 | diagram.MouseDown += diagram_MouseDown;
29 | }
30 |
31 | void diagram_MouseDown(object sender, MouseButtonEventArgs e)
32 | {
33 | var position = e.GetPosition(this);
34 | DiagramViewModel vm = DataContext as DiagramViewModel;
35 |
36 | }
37 |
38 | void diagram_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
39 | {
40 | if (e.ClickCount > 0)
41 | {
42 | //e.Handled = true;
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/CaliDiagram/CaliDiagramHelpers.cs:
--------------------------------------------------------------------------------
1 | using Caliburn.Micro;
2 | using CaliDiagram.ViewModels;
3 | using CaliDiagram.Views;
4 | using System;
5 | using System.Windows;
6 |
7 | namespace CaliDiagram
8 | {
9 | public class CaliDiagramHelpers
10 | {
11 | public void InitViewLocator()
12 | {
13 | OriginalLocateForModel = ViewLocator.LocateForModel;
14 | ViewLocator.LocateForModel = LocateForModel;
15 | }
16 | private Func