private void updateAlternativeSelection(CompoundGroupSelection snapshotCompoundGroupSelection, ModelCompoundProperties compoundProperties)
        {
            var compoundGroupSelection = compoundProperties.CompoundGroupSelections.Find(x => x.GroupName == snapshotCompoundGroupSelection.GroupName);

            if (compoundGroupSelection == null)
            {
                _logger.AddError(PKSimConstants.Error.CompoundGroupNotFoundFor(snapshotCompoundGroupSelection.GroupName, compoundProperties.Compound.Name));
                return;
            }

            var alternativeGroup = compoundProperties.Compound.ParameterAlternativeGroup(snapshotCompoundGroupSelection.GroupName);

            if (alternativeGroup == null)
            {
                _logger.AddError(PKSimConstants.Error.CompoundGroupNotFoundFor(snapshotCompoundGroupSelection.GroupName, compoundProperties.Compound.Name));
                return;
            }

            var alternative = alternativeGroup.AlternativeByName(snapshotCompoundGroupSelection.AlternativeName);

            if (alternative == null)
            {
                _logger.AddError(PKSimConstants.Error.CompoundAlternativeNotFoundFor(snapshotCompoundGroupSelection.AlternativeName, alternativeGroup.DefaultAlternative?.Name, snapshotCompoundGroupSelection.GroupName, compoundProperties.Compound.Name));
                return;
            }
            compoundGroupSelection.AlternativeName = snapshotCompoundGroupSelection.AlternativeName;
        }
Exemple #2
0
        private IDescriptorCondition descriptorConditionFrom(SnapshotDescriptorCondition snapshot)
        {
            var tag = snapshot.Tag;

            switch (snapshot.Type)
            {
            case Constants.IN_CONTAINER:
                return(new InContainerCondition(tag));

            case Constants.ALL_TAG:
                return(new MatchAllCondition());

            case MATCH_TAG:
                return(new MatchTagCondition(tag));

            case Constants.NOT_IN_CONTAINER:
                return(new NotInContainerCondition(tag));

            case Constants.NOT:
                return(new NotMatchTagCondition(tag));
            }

            //This should never happen
            _logger.AddError(PKSimConstants.Error.CannotCreateDescriptorFromSnapshotFor(snapshot.Type));
            return(null);
        }
Exemple #3
0
        private async Task <string> downloadRemoteFile(string url, string locationInTempFolder, string type)
        {
            _logger.AddDebug($"Downloading {type.ToLower()} file from {url}...");
            var downloadFolder = Path.Combine(_runOptions.TempFolder, locationInTempFolder);

            DirectoryHelper.CreateDirectory(downloadFolder);

            using (var wc = new WebClient())
            {
                try
                {
                    var fileName     = new Uri(url).Segments.Last();
                    var fileFullPath = Path.Combine(downloadFolder, fileName);

                    await wc.DownloadFileTaskAsync(url, fileFullPath);

                    _logger.AddDebug($"{type} file downloaded from {url} to {fileFullPath}");
                    return(fileFullPath);
                }
                catch (Exception e)
                {
                    //Exception is thrown for example if the given url does not exist or if internet access is not possible etc..
                    _logger.AddError(e.Message);
                    return(url);
                }
            }
        }
Exemple #4
0
        private async Task <IEnumerable <Model.Simulation> > allSmulationsFrom(Simulation[] snapshots, ModelProject project)
        {
            var simulations = new List <Model.Simulation>();

            if (snapshots == null)
            {
                return(simulations);
            }

            //do not run tasks in parallel as the same mapper instance may be used concurrently to load two different snapshots
            foreach (var snapshot in snapshots)
            {
                try
                {
                    var simulation = await _simulationMapper.MapToModel(snapshot, project);

                    simulations.Add(simulation);
                }
                catch (Exception e)
                {
                    _logger.AddException(e);
                    _logger.AddError(PKSimConstants.Error.CannotLoadSimulation(snapshot.Name));
                }
            }

            return(simulations);
        }
Exemple #5
0
        private void showException(Exception ex)
        {
            var message    = ex.FullMessage();
            var stackTrace = ex.FullStackTrace();

            _exceptionView.Display(message, stackTrace, clipboardContentFrom(message, stackTrace));
            _logger.AddError(message);
        }
 public static void AddException(this ILogger logger, Exception exception, string categoryName = null)
 {
     //Info message only => Should be shown as warning in log
     if (exception.IsInfoException())
     {
         logger.AddWarning(exception.ExceptionMessage(addContactSupportInfo: false), categoryName);
     }
     // Not an info message but an exception thrown by the suite. Error without stack trace
     else if (exception.IsOSPSuiteException())
     {
         logger.AddError((exception.ExceptionMessage(addContactSupportInfo: false)), categoryName);
     }
     // this is bad => Stack trace
     else
     {
         logger.AddError(exception.ExceptionMessageWithStackTrace(false), categoryName);
     }
 }
 public static void AddException(this ILogger logger, Exception exception, string categoryName = null)
 {
     if (exception.IsInfoException())
     {
         logger.AddWarning(exception.ExceptionMessage(), categoryName);
     }
     else
     {
         logger.AddError(exception.ExceptionMessageWithStackTrace(), categoryName);
     }
 }
        public bool Validate(IObjectBase objectToValidate)
        {
            var validationResult = _entityValidator.Validate(objectToValidate);

            if (validationResult.ValidationState == ValidationState.Valid)
            {
                return(true);
            }

            var error = Error.EntityIsInvalid(_executionContext.TypeFor(objectToValidate), objectToValidate.Name);

            _logger.AddError(error);
            return(false);
        }
        public override Task <ObserverSetMapping> MapToModel(ObserverSetSelection snapshot, PKSimProject project)
        {
            var observerSet = project.BuildingBlockByName <Model.ObserverSet>(snapshot.Name);

            if (observerSet == null)
            {
                _logger.AddError(PKSimConstants.Error.CannotFindObserverSetForMapping(snapshot.Name));
                return(null);
            }

            var observerSetMapping = new ObserverSetMapping {
                TemplateObserverSetId = observerSet.Id ?? string.Empty
            };

            return(Task.FromResult(observerSetMapping));
        }
Exemple #10
0
        private IObserverBuilder createObserverFrom(SnapshotObserver snapshot)
        {
            if (string.IsNullOrEmpty(snapshot.Type))
            {
                return(null);
            }

            switch (snapshot.Type)
            {
            case AMOUNT_OBSERVER:
                return(_objectBaseFactory.Create <AmountObserverBuilder>());

            case CONTAINER_OBSERVER:
                return(_objectBaseFactory.Create <ContainerObserverBuilder>());
            }

            _logger.AddError(PKSimConstants.Error.CannotCreateObserverFromSnapshot(snapshot.Type));
            return(null);
        }
Exemple #11
0
        private async Task <bool> ConnectAsync()
        {
            string url; string login; string password;

            _dataProtect.GetPulxerParams(out url, out login, out password);

            var res = await _socket.ConnectAsync(url, login, password);

            if (!res.IsSuccess)
            {
                _logger.AddError("LpClientApp", "Pulxer connection error: " + res.Message);
                return(false);
            }

            _core.Initialize(_sysPipe, "Leech Agent");
            _logger.AddInfo("LpClientApp", "Pulxer connection successful.");

            return(true);
        }
        private async Task <ModelCompoundProcess> retrieveProcessFrom(SnapshotCompoundProcess snapshot)
        {
            var template = _compoundProcessRepository.ProcessByName(snapshot.InternalName);

            if (template == null)
            {
                _logger.AddError(PKSimConstants.Error.SnapshotProcessNameNotFound(snapshot.InternalName));
                return(null);
            }

            var process = _cloner.Clone(template);

            process.DataSource = snapshot.DataSource;

            if (process.IsAnImplementationOf <ISpeciesDependentCompoundProcess>())
            {
                updateSpeciesDependentParameter(process, snapshot);
            }

            await UpdateParametersFromSnapshot(snapshot, process, process.InternalName);

            return(process);
        }
Exemple #13
0
 public void MessageBoxError(string message)
 {
     _logger.AddError(message);
 }
Exemple #14
0
        public void Load()
        {
            _logger.AddInfo("BotsConfiguration", "Loading bots configuration ...");
            _key_botconf.Clear();

            try
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(_config.GetBotsConfigPath());

                foreach (XmlNode xn in xDoc.DocumentElement.ChildNodes)
                {
                    if (xn.Name != "Bot")
                    {
                        _logger.AddInfo("BotsConfiguration", "Skip node: " + xn.Name);
                        continue;
                    }

                    var xa_key = xn.Attributes["Key"];
                    if (xa_key == null)
                    {
                        _logger.AddError("BotsConfiguration", "Key attribute not found.");
                        continue;
                    }
                    string key = xa_key.Value;

                    var xa_assembly = xn.Attributes["Assembly"];
                    if (xa_assembly == null)
                    {
                        _logger.AddError("BotsConfiguration", "Assembly attribute not found.");
                        continue;
                    }
                    string assembly = xa_assembly.Value;
                    if (!Path.IsPathRooted(assembly))
                    {
                        assembly = Path.Combine(_config.GetBotsPath(), assembly);
                    }

                    var xa_class = xn.Attributes["Class"];
                    if (xa_class == null)
                    {
                        _logger.AddError("BotsConfiguration", "Class attribute not found.");
                        continue;
                    }
                    string cls = xa_class.Value;

                    var    xa_initdata = xn.Attributes["InitData"];
                    string initdata    = "";
                    if (xa_initdata != null)
                    {
                        initdata = xa_initdata.Value;
                    }
                    else
                    {
                        _logger.AddInfo("BotsConfiguration", "InitData attribute not found. Empty string used.");
                    }

                    if (_key_botconf.ContainsKey(key))
                    {
                        _logger.AddError("BotsConfiguration", "Duplicate key: " + key);
                        continue;
                    }

                    _key_botconf.Add(key, new BotConfig()
                    {
                        Assembly = assembly,
                        Class    = cls,
                        InitData = initdata,
                        Key      = key
                    });
                    _logger.AddInfo("BotsConfiguration",
                                    string.Format("Bot config load: Key={0}, Assembly={1}, Class={2}", key, assembly, cls));
                }
            }
            catch (FileNotFoundException ex)
            {
                _logger.AddError("BotsConfiguration", "Bots config file not found");
            }
            catch (Exception ex)
            {
                _logger.AddException("BotsConfiguration", ex);
            }
        }