Beispiel #1
0
        public Joiner(INode i, IReaderWriter readerWriter, IRecon recon, IMessageHub messageHub)
        {
            this.i          = i;
            this.messageHub = messageHub;
            eventHandlers   = new EventHandlerList();
            status          = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle);
            reconStatus     = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle);
            rwStatus        = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle);
            hints           = new ObservableAtomicValue <IEnumerable <INode> >(Enumerable.Empty <INode>());

            preJoinRw = new ObservableCondition(() => status.Get() == NodeStatus.Joining &&
                                                rwStatus.Get() == NodeStatus.Idle,
                                                new[] { status, rwStatus });
            preJoinRecon = new ObservableCondition(() => status.Get() == NodeStatus.Joining &&
                                                   reconStatus.Get() == NodeStatus.Idle,
                                                   new[] { status, reconStatus });
            preJoin    = new ObservableCondition(() => status.Get() == NodeStatus.Joining, new[] { status });
            preJoinAck = new ObservableCondition(() => status.Get() == NodeStatus.Joining &&
                                                 rwStatus.Get() == NodeStatus.Active &&
                                                 reconStatus.Get() == NodeStatus.Active,
                                                 new[] { status, rwStatus, reconStatus });

            this.recon                 = recon;
            this.recon.JoinAck        += JoinAckReaderWriter;
            this.readerWriter          = readerWriter;
            this.readerWriter.JoinAck += JoinAckRecon;

            new Thread(OutJoinRw).Start();
            new Thread(OutJoinRecon).Start();
            new Thread(OutSend).Start();
            new Thread(OutJoinAck).Start();
        }
Beispiel #2
0
        public static ItemData <object> ReadValueEx(this IReaderWriter reader, DeviceAddress address)
        {
            switch (address.VarType)
            {
            case DataType.BOOL:
                var bit = reader.ReadBit(address);
                return(new ItemData <object>(bit.Value, bit.TimeStamp, bit.Quality));

            case DataType.BYTE:
                var bt = reader.ReadByte(address);
                return(new ItemData <object>(bt.Value, bt.TimeStamp, bt.Quality));

            case DataType.WORD:
            case DataType.SHORT:
                var sh = reader.ReadInt16(address);
                return(new ItemData <object>(sh.Value, sh.TimeStamp, sh.Quality));

            case DataType.TIME:
            case DataType.INT:
                var it = reader.ReadInt32(address);
                return(new ItemData <object>(it.Value, it.TimeStamp, it.Quality));

            case DataType.FLOAT:
                var fl = reader.ReadFloat(address);
                return(new ItemData <object>(fl.Value, fl.TimeStamp, fl.Quality));

            case DataType.STR:
                var str = reader.ReadString(address, address.DataSize);
                return(new ItemData <object>(str.Value, str.TimeStamp, str.Quality));
            }
            return(new ItemData <object>(null, 0, QUALITIES.QUALITY_BAD));
        }
Beispiel #3
0
    static void Main(String[] args)
    {
        IReaderWriter readerWriter = null;

        try
        {
            if (Debugger.IsAttached)
            {
                readerWriter = new TestFileReaderWriter();
            }
            else
            {
                // The normal case.
                readerWriter = new ConsoleReaderWriter();
            }

            SolvePuzzle(readerWriter);

            if (Debugger.IsAttached)
            {
                Console.WriteLine("All finished!");
                Console.ReadKey();
            }
        }
        finally
        {
            if (readerWriter != null)
            {
                readerWriter.Dispose();
            }
        }
    }
Beispiel #4
0
        public static int WriteValueEx(this IReaderWriter writer, DeviceAddress address, object value)
        {
            switch (address.VarType)
            {
            case DataType.BOOL:
                return(writer.WriteBit(address, Convert.ToBoolean(value)));

            case DataType.BYTE:
                return(writer.WriteBits(address, Convert.ToByte(value)));

            case DataType.WORD:
            case DataType.SHORT:
                return(writer.WriteInt16(address, Convert.ToInt16(value)));

            case DataType.TIME:
            case DataType.INT:
                return(writer.WriteInt32(address, Convert.ToInt32(value)));

            case DataType.FLOAT:
                return(writer.WriteFloat(address, Convert.ToSingle(value)));

            case DataType.STR:
                return(writer.WriteString(address, value.ToString()));
            }
            return(-1);
        }
Beispiel #5
0
 public Configuration UsingReaderWriter(IReaderWriter <string> readerWriter)
 {
     return(new Configuration(this)
     {
         ReaderWriter = readerWriter
     });
 }
Beispiel #6
0
        public static RWKinds GetKind(this IReaderWriter rw)
        {
            var type = rw.GetType();

            if (type == typeof(BinaryReaderX))
            {
                return(RWKinds.Binary);
            }
            if (type == typeof(BinaryWriterX))
            {
                return(RWKinds.Binary);
            }
            if (type == typeof(XmlReaderX))
            {
                return(RWKinds.Xml);
            }
            if (type == typeof(XmlWriterX))
            {
                return(RWKinds.Xml);
            }
            if (type == typeof(JsonReader))
            {
                return(RWKinds.Json);
            }
            if (type == typeof(JsonWriter))
            {
                return(RWKinds.Json);
            }

            throw new XException("未识别的读写器类型{0}!", type);
        }
Beispiel #7
0
        public static IChangeSet <TObject, TKey> AsInitialUpdates <TObject, TKey>(this IReaderWriter <TObject, TKey> source, Func <TObject, bool> filter = null)
        {
            var filtered     = filter == null ? source.KeyValues : source.KeyValues.Where(kv => filter(kv.Value));
            var initialItems = filtered.Select(i => new Change <TObject, TKey>(ChangeReason.Add, i.Key, i.Value));

            return(new ChangeSet <TObject, TKey>(initialItems));
        }
Beispiel #8
0
 public CommandParameters(DirFinderExecutor dirFinderExecutor, IReaderWriter readerWritter,
                          CommandLineParams clParams, RootDirItem rootItem)
 {
     this.DirFinderExecutor = dirFinderExecutor;
     this.ReaderWriter      = readerWritter;
     this.CLParams          = clParams;
     this.RootItem          = rootItem;
 }
        public void Save(IReaderWriter readerWriter, string path)
        {
            var serializer = new XmlSerializer(typeof(RootDirItem));

            using (var writer = readerWriter.GetWriter(path))
            {
                serializer.Serialize(writer, this);
            }
        }
Beispiel #10
0
    // Implement this method to solve the puzzle. Use readerWriter methods to read input / write output.
    // For local runs:
    //    place input in a file called "input.txt" alongside Program.cs.
    //    optionally, place output in a file called "expectedOutput.txt" -- an error will be thrown as soon as an expected line doesn't match your output.
    //    Make sure the files are copied to the output directory (in properties).

    private static void SolvePuzzle(IReaderWriter readerWriter)
    {
        // Your code goes in this method.
        // Consider using the following snippet if there are T test cases presented on line one.
        int testCases = readerWriter.ReadLineToInt();

        for (int t = 0; t < testCases; t++)
        {
        }
    }
Beispiel #11
0
        public Game(IPlayer player1, IPlayer player2, int size, IReaderWriter readerWriter)
        {
            if (size < 3)
            {
                throw new ArgumentException("Size must be greater than 3");
            }
            _board = new Board(size);

            _player1      = player1;
            _player2      = player2;
            CurrentPlayer = _player1;
            _readerWriter = readerWriter ?? throw new ArgumentException(nameof(readerWriter));
        }
Beispiel #12
0
 private static void Process(IReaderWriter readerWriter, IExpressionInterpreter interpreter)
 {
     foreach (var inputExpression in readerWriter.GetInputExpressions())
     {
         try
         {
             readerWriter.WriteResult(interpreter.Interpret(inputExpression).Normalization());
         }
         catch (IncorrectExpressionException exc)
         {
             Console.WriteLine(exc.Message);
         }
     }
        public ObservableCache(Func <TObject, TKey> keySelector = null)
        {
            _readerWriter = new ReaderWriter <TObject, TKey>(keySelector);

            _disposer = Disposable.Create(() =>
            {
                _changes.OnCompleted();
                if (_countChanged.IsValueCreated)
                {
                    _countChanged.Value.OnCompleted();
                }
            });
        }
        public void Load(IReaderWriter readerWriter, string path)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(RootDirItem));

            using (var reader = readerWriter.GetReader(path))
            {
                var item = (RootDirItem)serializer.Deserialize(reader);
                this.Name        = item.Name;
                this.Files       = item.Files;
                this.Level       = item.Level;
                this.Directories = item.Directories;
            }
        }
Beispiel #15
0
        /// <summary>
        /// Constructs a connection with specified parent application and a connected <see cref="TcpClient"/>. Throws if <paramref name="tcpClient"/> is not connected.
        /// </summary>
        /// <exception cref="Exception"/>
        protected Connection(SpecificApplication application, TcpClient tcpClient)
        {
            if (!tcpClient.Connected)
            {
                throw new Exception("The client provided to the constructor should be connected already.");
            }

            Application    = application;
            this.tcpClient = tcpClient;
            Stream         = new FormatterStream <BinaryFormatter, IPacket>(tcpClient.GetStream());
            thread         = new Thread(Handle);
            thread.Start();
        }
Beispiel #16
0
        /// <summary>读写前设置。每个消息可根据自己需要进行调整</summary>
        /// <param name="rw"></param>
        protected virtual void OnReadWriteSet(IReaderWriter rw)
        {
            var setting = rw.Settings;

            //setting.IsBaseFirst = true;
            //setting.EncodeInt = true;
            setting.UseTypeFullName = false;
            setting.UseObjRef       = true;

            if (setting is BinarySettings)
            {
                var bset = setting as BinarySettings;
                bset.EncodeInt = true;
            }
            else
            {
                //setting.Encoding = new UTF8Encoding(false);
            }
        }
Beispiel #17
0
        public Rambo(INode creator,
                     IMessageHub messageHub,
                     IEnumerable <IConfiguration> initialConfig,
                     IMessageSerializer messageSerializer)
        {
            Contract.Requires(creator != null);
            Contract.Requires(messageHub != null);
            Contract.Requires(messageHub != null);
            Contract.Requires(initialConfig != null && initialConfig.Any());

            Node          = creator;
            eventHandlers = new EventHandlerList();
            readerWriter  = new ReaderWriter(creator, messageHub, initialConfig, messageSerializer);
            recon         = new Recon();

            joiner = new Joiner(creator, readerWriter, recon, messageHub);

            ConfigureService();
        }
Beispiel #18
0
        public ObservableCache(IObservable <IChangeSet <TObject, TKey> > source)
        {
            _readerWriter = new ReaderWriter <TObject, TKey>();

            var loader = source
                         .FinallySafe(_changes.OnCompleted)
                         .Subscribe(changes => _readerWriter.Write(changes)
                                    .Then(InvokeNext, _changes.OnError)
                                    );

            _disposer = Disposable.Create(() =>
            {
                loader.Dispose();
                _changes.OnCompleted();
                if (_countChanged.IsValueCreated)
                {
                    _countChanged.Value.OnCompleted();
                }
            });
        }
Beispiel #19
0
 public void SetUp()
 {
     _entries = new List<string>
                             {
                                "/file1.cs/1.1/Tue Jan  5 15:47:45 2010//",
                                "/file2.cs/1.1/Tue Jan  5 15:47:45 2010//",
                                "/file3.cs/1.3/Thu Jan  7 15:49:20 2010//",
                                "/TestApp.csproj/1.1/Tue Jan  5 15:47:45 2010//",
                                "D/Properties////",
                                "/.gitignore/1.1/Tue Jan  5 15:47:45 2010//",
                                "/AssemblyVersionIncrementor.dll/1.1/Tue Jan  5 15:47:45 2010/-kb/"
                             };
      _mocks = new MockRepository();
      _readerWriter = _mocks.DynamicMock<IReaderWriter>();
      ReaderWriter.Current = _readerWriter;
      DirectoryInfo di = new DirectoryInfo(@"c:\_temp\working\team\mymod");
      _rootModuleFolder = new Folder(di, _connection, _repository, _module);
      _file1 = new Entry("file1.cs", _rootModuleFolder) { EntryLine = _entries[0] };
      _proj = new Entry("TestApp.csproj", _rootModuleFolder) { EntryLine = _entries[3] };
      _props = new Folder("Properties", _rootModuleFolder) { EntryLine = _entries[4] };
      _file = new Entry(".gitignore", _rootModuleFolder) { EntryLine = _entries[5] };
      _binary = new Entry("AssemblyVersionIncrementor.dll", _rootModuleFolder) { EntryLine = _entries[6] };
 }
Beispiel #20
0
 public RdUniversity(IDateProvider <Student> studentsDataProvider, IReaderWriter consoleReaderWriter, IReaderWriter printerWriter)
 {
     _studentsDataProvider = studentsDataProvider;
     _consoleReaderWriter  = consoleReaderWriter;
     _printerWriter        = printerWriter;
 }
Beispiel #21
0
 public Checker(IReaderWriter readerWriter)
 {
     this.readerWriter = readerWriter;
 }
Beispiel #22
0
 public Orchestrator(IGzipWorker[] gzipWorkers, IReaderWriter readerWriter)
 {
     this.readerWriter = readerWriter;
     this.gzipWorkers  = gzipWorkers;
 }
Beispiel #23
0
 public RecordReader(IReaderWriter readerWriter)
 {
     this.readerWriter = readerWriter;
     this.setNumberOfRecords(readerWriter);
 }
Beispiel #24
0
 public UserLoginRepo(IReaderWriter readerWriter, string filePath)
 {
     _readerWriter = readerWriter;
     _filePath     = filePath;
     Load();
 }
 public RuleEngine(IReaderWriter readWrite)
 {
     _console = readWrite;
 }
Beispiel #26
0
 private void setNumberOfRecords(IReaderWriter readerWriter)
 {
     var value = readerWriter.ReadLine().Trim();
     value = Regex.Replace(value, "[^0-9]", "", RegexOptions.None);
     this.numberOfRecords = int.Parse(value);
 }
 public PlannedWorktimeFileRepository(IReaderWriter<IDictionary<IDate, IDailyWorkTimeWeekPlan>> fileReaderWriter)
     : base(fileReaderWriter.Read())
 {
     if (fileReaderWriter == null) throw new ArgumentNullException(nameof(fileReaderWriter));
     _fileReaderWriter = fileReaderWriter;
 }
Beispiel #28
0
        /// <summary>读写前设置。不使用对象引用</summary>
        /// <param name="rw"></param>
        protected override void OnReadWriteSet(IReaderWriter rw)
        {
            base.OnReadWriteSet(rw);

            rw.Settings.UseObjRef = false;
        }
Beispiel #29
0
 public AccountRepo(IReaderWriter readerWriter, string filePath)
 {
     _readerWriter = readerWriter;
     _filePath     = filePath;
     Load();
 }
Beispiel #30
0
 public Player(char symbol, IReaderWriter readerWriter)
 {
     Symbol        = symbol;
     _readerWriter = readerWriter ?? throw new ArgumentException(nameof(readerWriter));
 }
Beispiel #31
0
 public Library(IReaderWriter readerWriter)
 {
     _readerWriter = readerWriter;
 }
Beispiel #32
0
 public Engine(ICommandInterpreter commandInterpreter, IReaderWriter readerWriter)
 {
     this.commandInterpreter = commandInterpreter;
     this.readerWriter       = readerWriter;
 }
 public WorkdayFileRepository(IReaderWriter<IList<IWorkday>> workdaysReaderWriter)
     : base(workdaysReaderWriter.Read())
 {
     if (workdaysReaderWriter == null) throw new ArgumentNullException(nameof(workdaysReaderWriter));
     _workdaysReaderWriter = workdaysReaderWriter;
 }