示例#1
0
        public List <RemoteWorker> UpdateWorkersWithSavedData(RemoteWorkerFactory workerFactory, List <RemoteWorker> workers)
        {
            List <RemoteWorker> deserializedWorkers = LoadWorkers(workerFactory);

            //
            // If no workers were saved, there is no information to update, so just use the original
            // list of workers.
            //

            if (deserializedWorkers == null)
            {
                return(workers);
            }

            List <RemoteWorker> updatedWorkersInfo = new List <RemoteWorker>();

            foreach (RemoteWorker worker in workers)
            {
                RemoteWorker updatedWorker = FindMatchingWorker(deserializedWorkers, worker);

                if (updatedWorker != null)
                {
                    updatedWorkersInfo.Add(updatedWorker);
                }
                else
                {
                    updatedWorkersInfo.Add(worker);
                }
            }

            return(updatedWorkersInfo);
        }
        private RemoteWorker RemoteWorkerFromStream(RemoteWorkerFactory workerFactory, Stream serializedWorker)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            string   id            = ((string)formatter.Deserialize(serializedWorker));
            string   remoteAddress = ((string)formatter.Deserialize(serializedWorker));
            DateTime lastPullTime  = ((DateTime)formatter.Deserialize(serializedWorker));

            return(workerFactory.CreateRemoteWorker(id, remoteAddress, lastPullTime));
        }
        public List <RemoteWorker> DeserializeWorkers(RemoteWorkerFactory workerFactory, Stream serializedWorkerInfoList)
        {
            List <RemoteWorker> deserialized = new List <RemoteWorker>();

            while (serializedWorkerInfoList.Position < serializedWorkerInfoList.Length)
            {
                deserialized.Add(RemoteWorkerFromStream(workerFactory, serializedWorkerInfoList));
            }

            return(deserialized);
        }
示例#4
0
        public CommandProcessor(CommandLineOptions options)
        {
            IConnectionManager connectionManager = CreateConnectionManager(options.ServerCertFile, options.ClientCertFile);

            _workerFactory = new RemoteWorkerFactory(connectionManager, options.Password);

            _destinationFolder = options.DestinationFolder;

            _serverPassword = options.Password;

            string workerSaveFile = GetSerializedWorkerPath(_destinationFolder);

            _savedWorkerManager = new SavedWorkerManager(workerSaveFile);

            _workers = WorkersFromCommandLineOptions(options);
        }
示例#5
0
        private List <RemoteWorker> LoadWorkers(RemoteWorkerFactory workerFactory)
        {
            List <RemoteWorker> savedWorkers;

            if (!File.Exists(_workerSaveFile))
            {
                return(null);
            }

            try
            {
                using (Stream savedInfoStream = File.OpenRead(_workerSaveFile))
                {
                    savedWorkers = _workerSerializer.DeserializeWorkers(workerFactory, savedInfoStream);
                }
            }
            catch (IOException)
            {
                return(null);
            }

            return(savedWorkers);
        }