Example #1
0
        public IEnumerable <ModuleScienceExperiment> FindDMAnimateGenericsForExperiment(string experimentId)
        {
            if (_DMModuleScienceAnimateGenerics != null && _DMModuleScienceAnimateGenerics.Count > 0)
            {
                DMModuleScienceAnimateGeneric NewDMagicInstance = _parent.DMagic.GetDMModuleScienceAnimateGeneric();
                if (NewDMagicInstance != null)
                {
                    return(_DMModuleScienceAnimateGenerics.Where(x => x.experimentID == experimentId));
                }
            }

            return(null);
        }
Example #2
0
        public DMagicFactory( )
        {
            _logger = new Logger(this);
            _logger.Debug("DMagic API Start");
            _isInstalled = false;



            _tDMAPI = getType("DMagic.DMAPI");
            _tDMModuleScienceAnimate        = getType("DMagic.Part_Modules.DMModuleScienceAnimate");
            _tDMModuleScienceAnimateGeneric = getType("DMagic.Part_Modules.DMModuleScienceAnimateGeneric");
            _tDMBasicScienceModule          = getType("DMagic.Part_Modules.DMBasicScienceModule");



            if (_tDMAPI != null)
            {
                _logger.Debug("DMAPI Available");
                _isInstalled = true;
                _DMAPI       = new DMAPI(_tDMAPI);
            }

            if (_tDMModuleScienceAnimate != null)              // Don't actually sem to be using this one
            {
                _logger.Debug("DMModuleScienceAnimate Available");
            }

            if (_tDMModuleScienceAnimateGeneric != null)
            {
                _logger.Debug("DMModuleScienceAnimateGeneric Available");
                _isInstalled = true;
                _DMModuleScienceAnimateGeneric = new DMModuleScienceAnimateGeneric(_tDMModuleScienceAnimateGeneric);
            }

            if (_tDMBasicScienceModule != null)              // Don't actually sem to be using this one
            {
                _logger.Debug("DMBasicScienceModule Available");
            }

            if (_isInstalled)
            {
                _logger.Debug("DMagic API Installed");
            }
            else
            {
                _logger.Debug("DMagic API Not Found");
            }
        }
Example #3
0
        public bool CanRunExperiment(ScienceInstance s, bool runSingleUse = true)
        {
            bool IsAvailable = false;

            if (_availableScienceExperiments.ContainsKey(s.ScienceExperiment.id))
            {
                return(_availableScienceExperiments[s.ScienceExperiment.id]);
            }

            IEnumerable <ModuleScienceExperiment> dlm = FindDMAnimateGenericsForExperiment(s.ScienceExperiment.id);

            if (dlm != null && dlm.Any())
            {
                DMModuleScienceAnimateGeneric NewDMagicInstance = _parent.DMagic.GetDMModuleScienceAnimateGeneric();
                IsAvailable = dlm.Any(x =>
                                      (int)x.Fields.GetValue("experimentsLimit") > 1 ? NewDMagicInstance.canConduct(x) : NewDMagicInstance.canConduct(x) &&
                                      (x.rerunnable || runSingleUse));

                _availableScienceExperiments[s.ScienceExperiment.id] = IsAvailable;
                return(IsAvailable);
            }

            if (_moduleScienceExperiments != null && _moduleScienceExperiments.Count > 0)
            {
                IEnumerable <ModuleScienceExperiment> lm = _moduleScienceExperiments.Where(x => (
                                                                                               x.experimentID == s.ScienceExperiment.id &&
                                                                                               !(x.GetScienceCount() > 0) &&
                                                                                               (x.rerunnable || runSingleUse) &&
                                                                                               !x.Inoperable
                                                                                               ));

                IsAvailable = lm.Count( ) != 0;
                _availableScienceExperiments[s.ScienceExperiment.id] = IsAvailable;
            }
            return(IsAvailable);
        }
Example #4
0
        public void RunExperiment(ScienceInstance s, bool runSingleUse = true)
        {
            //_logger.Trace( "Finding Module for Science Report: " + s.ScienceExperiment.id );
            ModuleScienceExperiment m = null;



            // If possible run with DMagic new API
            IEnumerable <ModuleScienceExperiment> lm = FindDMAnimateGenericsForExperiment(s.ScienceExperiment.id);

            if (lm != null && lm.Any())
            {
                DMModuleScienceAnimateGeneric NewDMagicInstance = _parent.DMagic.GetDMModuleScienceAnimateGeneric( );
                m = lm.FirstOrDefault(x =>
                                      (int)x.Fields.GetValue("experimentsLimit") > 1 ? NewDMagicInstance.canConduct(x) : NewDMagicInstance.canConduct(x) &&
                                      (x.rerunnable || runSingleUse));

                if (m != null)
                {
                    _logger.Debug("Running DMModuleScienceAnimateGenerics Experiment " + m.experimentID + " on part " + m.part.partInfo.name);
                    NewDMagicInstance.gatherScienceData(m, !_parent.Config.ShowResultsWindow);
                }

                return;
            }



            // If possible run with DMagic DMAPI
            if (_DMModuleScienceAnimates != null && _DMModuleScienceAnimates.Count > 0)
            {
                DMAPI DMAPIInstance = _parent.DMagic.GetDMAPI( );
                if (DMAPIInstance != null)
                {
                    IEnumerable <ModuleScienceExperiment> lm2 = _DMModuleScienceAnimates.Where(x => x.experimentID == s.ScienceExperiment.id);
                    if (lm2.Any())
                    {
                        m = lm2.FirstOrDefault(x =>
                        {
                            return(!x.Inoperable &&
                                   ((int)x.Fields.GetValue("experimentLimit") > 1 ? DMAPIInstance.experimentCanConduct(x) : DMAPIInstance.experimentCanConduct(x) &&
                                    (x.rerunnable || runSingleUse)));
                        });

                        if (m != null)
                        {
                            //_logger.Trace("Running DMModuleScienceAnimates Experiment " + m.experimentID + " on part " + m.part.partInfo.name);
                            DMAPIInstance.deployDMExperiment(m, !_parent.Config.ShowResultsWindow);
                        }

                        return;
                    }
                }
            }



            // Do stock run
            m = FindExperiment(s, runSingleUse);
            if (m != null)
            {
                //_logger.Trace( "Running Experiment " + m.experimentID + " on part " + m.part.partInfo.name );
                RunStandardModuleScienceExperiment(m);
                return;
            }
        }