Esempio n. 1
0
        private async Task <ModelProtocol> createAdvancedProtocolFrom(SnapshotProtocol snapshotProtocol)
        {
            var advancedProtocol = _protocolFactory.Create(ProtocolMode.Advanced).DowncastTo <AdvancedProtocol>();

            advancedProtocol.RemoveAllSchemas();
            advancedProtocol.TimeUnit = _dimensionRepository.Time.UnitOrDefault(snapshotProtocol.TimeUnit);

            if (snapshotProtocol.Schemas == null)
            {
                return(advancedProtocol);
            }

            advancedProtocol.AddChildren(await _schemaMapper.MapToModels(snapshotProtocol.Schemas));
            return(advancedProtocol);
        }
Esempio n. 2
0
 private void ProtocolMessage(byte[] bytes)
 {
     try
     {
         do
         {
             IProtocol protocolServices = _protocolFactory.Create(bytes);
             if (protocolServices == null)
             {
                 //没有找到对应解析数据对象时,判断数据中校验位字符串数量,大于1的情况,对一个校验位后面的数据再次循环解析
                 //如果校验位字符串为0或者1,说明数据已经不正确了,退出本次解析任务
                 if (bytes.Count(r => r == ConstDefine.CheckUserId) > 1)
                 {
                     bytes = bytes.Skip(Array.IndexOf(bytes, ConstDefine.CheckUserId) + 1).ToArray();
                 }
                 else
                 {
                     break;
                 }
             }
             else
             {
                 bytes = protocolServices.Receive(bytes);
             }
         } while (bytes.Length > 0);
     }
     catch (Exception exception)
     {
         _logger.LogError(exception.InnerException?.Message ?? exception.Message);
     }
 }
Esempio n. 3
0
        public void CalculateBioavailabilityFor(Simulation simulation, string compoundName)
        {
            var individualSimulation = simulation as IndividualSimulation;

            if (individualSimulation == null)
            {
                return;
            }

            var compound = simulation.Compounds.FindByName(compoundName);

            //BA calculated with a Simple IV with 15 min infusion
            var simpleIvProtocol = _protocolFactory.Create(ProtocolMode.Simple, ApplicationTypes.Intravenous)
                                   .WithName("Simple IV for Bioavailability")
                                   .DowncastTo <SimpleProtocol>();

            simpleIvProtocol.Parameter(Constants.Parameters.INFUSION_TIME).Value = 15;

            var simulationSingleDosingItem = singleDosingItem(simulation, compound);

            simpleIvProtocol.Dose.DisplayUnit = simulationSingleDosingItem.Dose.DisplayUnit;
            simpleIvProtocol.Dose.Value       = simulationSingleDosingItem.Dose.Value;
            simpleIvProtocol.StartTime.Value  = simulationSingleDosingItem.StartTime.Value;

            var ivSimulation     = _globalPKAnalysisRunner.RunForBioavailability(simpleIvProtocol, individualSimulation, compound);
            var venousBloodCurve = ivSimulation.DataRepository.VenousBloodColumn(compoundName);
            var pkVenousBlood    = _pkAnalysisTask.CalculateFor(ivSimulation, venousBloodCurve).PKAnalysis;

            individualSimulation.CompoundPKFor(compoundName).AucIV = pkParameterValue(pkVenousBlood, Constants.PKParameters.AUC_inf);
        }
Esempio n. 4
0
        public ICache <Species, IParameter> VSSPhysChemFor(Compound compound)
        {
            var cache    = new Cache <Species, IParameter>();
            var protocol = _protocolFactory.Create(ProtocolMode.Simple);

            _speciesRepository.All().Each(species =>
            {
                var defaultIndividual = _defaultIndividualRetriever.DefaultIndividualFor(species);
                var simulation        = _simulationFactory.CreateForVSS(protocol, defaultIndividual, compound);
                cache[species]        = VSSPhysChemFor(simulation, compound.Name);
            });
            return(cache);
        }
Esempio n. 5
0
        void IConnector.Bind(IReactor dispatcher, IProtocolFactory factory, IPEndPoint localEP, int bufferSize)
        {
            _udpClient = new UdpClient(localEP);
            _udpClient.Client.ReceiveBufferSize = bufferSize;

            var protocol = factory.Create();

            var connection = new DatagramConnection(dispatcher, protocol, _udpClient);
            connection.Start(true);

            protocol.Bind(connection);
            protocol.Connected();
        }
Esempio n. 6
0
        private void ClientAcceptCallback(IAsyncResult ar)
        {
            var tcpClient = ((TcpListener)ar.AsyncState).EndAcceptTcpClient(ar);
            var protocol  = _factory.Create();

            var connection = new StreamConnection(_dispatcher, protocol, tcpClient, _bufferSize);

            connection.Start(true);

            protocol.Bind(connection);
            protocol.Connected();

            this.StartAccept();
        }
Esempio n. 7
0
        void IConnector.Bind(IReactor dispatcher, IProtocolFactory factory, IPEndPoint localEP, int bufferSize)
        {
            _udpClient = new UdpClient(localEP);
            _udpClient.Client.ReceiveBufferSize = bufferSize;

            var protocol = factory.Create();

            var connection = new DatagramConnection(dispatcher, protocol, _udpClient);

            connection.Start(true);

            protocol.Bind(connection);
            protocol.Connected();
        }
Esempio n. 8
0
        private void PeerConnectCallback(IAsyncResult ar)
        {
            var tcpClient = ((TcpClient)ar.AsyncState);

            tcpClient.EndConnect(ar);

            var protocol = _factory.Create();

            var connection = new StreamConnection(_dispatcher, protocol, tcpClient, _bufferSize);

            protocol.Bind(connection);
            protocol.Connected();

            connection.Start(false);
        }
Esempio n. 9
0
        protected override void Context()
        {
            _context         = A.Fake <IExecutionContext>();
            _protocolUpdater = A.Fake <IProtocolUpdater>();
            _protocolFactory = A.Fake <IProtocolFactory>();
            _project         = A.Fake <PKSimProject>();
            _oldProtocol     = A.Fake <Protocol>();
            _oldProtocolMode = ProtocolMode.Simple;
            _newProtocolMode = ProtocolMode.Advanced;

            A.CallTo(() => _context.CurrentProject).Returns(_project);
            A.CallTo(() => _context.Resolve <IProtocolUpdater>()).Returns(_protocolUpdater);
            A.CallTo(() => _context.Resolve <IProtocolFactory>()).Returns(_protocolFactory);

            _newProtocol = A.Fake <Protocol>();
            A.CallTo(() => _protocolFactory.Create(_newProtocolMode)).Returns(_newProtocol);
            sut = new SetProtocolModeCommand(_oldProtocol, _oldProtocolMode, _newProtocolMode, _context);
        }
        protected override void Context()
        {
            _view                      = A.Fake <ICreateProtocolView>();
            _propertiesMapper          = A.Fake <IBuildingBlockPropertiesMapper>();
            _simpleProtocolPresenter   = A.Fake <ISimpleProtocolPresenter>();
            _protocolFactory           = A.Fake <IProtocolFactory>();
            _propertiesDTOMapper       = A.Fake <IProtocolToProtocolPropertiesDTOMapper>();
            _advancedProtocolPresenter = A.Fake <IAdvancedProtocolPresenter>();
            _protocolUpdater           = A.Fake <IProtocolUpdater>();
            _protocolChartPresenter    = A.Fake <IProtocolChartPresenter>();
            _subPresenterManager       = A.Fake <ISubPresenterItemManager <IProtocolItemPresenter> >();
            _dialogCreator             = A.Fake <IDialogCreator>();
            A.CallTo(() => _protocolFactory.Create(ProtocolMode.Simple)).Returns(new SimpleProtocol());
            A.CallTo(() => _subPresenterManager.AllSubPresenters).Returns(new IProtocolItemPresenter[] { _simpleProtocolPresenter, _advancedProtocolPresenter });
            sut = new CreateProtocolPresenter(_view, _subPresenterManager, _propertiesMapper,
                                              _protocolChartPresenter, _protocolFactory, _protocolUpdater, _propertiesDTOMapper, _dialogCreator);

            sut.Initialize();
        }
Esempio n. 11
0
        public Protocol MapFrom(ApplicationProtocol batchProtocol)
        {
            var applicationType  = ApplicationTypes.ByName(batchProtocol.ApplicationType);
            var dosingIntervalId = EnumHelper.ParseValue <DosingIntervalId>(batchProtocol.DosingInterval);
            var simpleProtocol   = _protocolFactory.Create(ProtocolMode.Simple, applicationType).DowncastTo <SimpleProtocol>();

            simpleProtocol.Name = batchProtocol.Name ?? "Protocol";
            simpleProtocol.EndTimeParameter.Value = batchProtocol.EndTime;
            simpleProtocol.Dose.DisplayUnit       = simpleProtocol.Dose.Dimension.Unit(batchProtocol.DoseUnit);
            simpleProtocol.Dose.Value             = simpleProtocol.Dose.Dimension.UnitValueToBaseUnitValue(simpleProtocol.Dose.DisplayUnit, batchProtocol.Dose);
            simpleProtocol.DosingInterval         = DosingIntervals.ById(dosingIntervalId);

            _logger.AddDebug($"Application Type = {applicationType.Name}");
            _logger.AddDebug($"Dosing Interval = {simpleProtocol.DosingInterval.DisplayName}");
            _logger.AddDebug($"Application Dose = {simpleProtocol.Dose.Value} [{simpleProtocol.Dose.DisplayUnit}]");
            _logger.AddDebug($"Application End Time = {simpleProtocol.EndTime}");

            return(simpleProtocol);
        }
Esempio n. 12
0
 public void DoSomething()
 {
     ProtocolBaseClass protocol = _factory.Create();