Exemplo n.º 1
0
        public static bool FilterByVersion(ExperimentRequest item)
        {
            var pass           = true;
            var revision       = DeviceMessageCache.Instance.ExtendedStatusUpdate?.Revision ?? 0;
            var currentVersion =
                new Version(Assembly.GetEntryAssembly()?.GetName().Version?.ToString() ?? string.Empty);

            if (item.MinimumRevision != null && revision < item.MinimumRevision)
            {
                pass = false;
            }
            if (item.MaximumRevision != null && revision > item.MaximumRevision)
            {
                pass = false;
            }
            if (item.MinimumAppVersion != null && currentVersion < new Version(item.MinimumAppVersion))
            {
                pass = false;
            }
            if (item.MaximumAppVersion != null && currentVersion > new Version(item.MaximumAppVersion))
            {
                pass = false;
            }

            return(pass);
        }
Exemplo n.º 2
0
        public static bool FilterByEnvironment(ExperimentRequest item)
        {
#if DEBUG
            return(item.Environment != Environment.ProductionOnly);
#else
            return(item.Environment != Environment.Internal);
#endif
        }
Exemplo n.º 3
0
        private void LaunchExperiment(ExperimentRequest e)
        {
            if (_activeExperiment != null)
            {
                Log.Warning($"ExperimentRuntime: Skipped. Another experiment (#{_activeExperiment?.Id}) is already running.");
                return;
            }

            if (string.IsNullOrEmpty(e.Script))
            {
                Log.Warning($"ExperimentRuntime: Experiment #{_activeExperiment?.Id} has an empty script.");
                return;
            }

            _activeExperiment = e;

            _experimentTimeLimit = new Timer
            {
                Interval  = (e.TimeConstraint ?? 60) * 1000,
                AutoReset = false
            };
            _experimentTimeLimit.Elapsed += (sender, args) =>
            {
                Log.Warning($"ExperimentRuntime: Experiment #{e.Id} cancelled. Time constraint of {_experimentTimeLimit.Interval / 1000} seconds exceeded");
                ReportResult(new ExperimentRuntimeResult(-2, string.Empty, $"TIMEOUT ({_experimentTimeLimit.Interval / 1000}s)"));
            };
            _experimentTimeLimit.Start();

            Log.Debug($"ExperimentRuntime: Launching experiment id #{e.Id} ({e.Name})");
            try
            {
                try
                {
                    _activeExperimentHook           = (IExperimentBase)CSScript.Evaluator.LoadCode(e.Script);
                    _activeExperimentHook.Finished += ReportResult;

                    Log.Debug($"ExperimentRuntime: Experiment #{e.Id} hooked");

                    ScriptManager.Instance.RegisterHook(_activeExperimentHook);
                }
                catch (CompilerException ex)
                {
                    Log.Error($"ScriptManager.RegisterHook: Compiler error: {ex.Message}");
                    ReportResult(new ExperimentRuntimeResult(-3, ex.Message, $"COMPILER_ERROR"));
                }
            }
            catch (Exception ex)
            {
                Log.Error($"ExperimentRuntime: Failed to execute #{e.Id}. Reason: {ex.Message}; Source: {ex.Source}; ({ex})");
                ReportResult(new ExperimentRuntimeResult(-1, $"{ex.Message} (Source: {ex.Source}; Type: {ex.GetType()})", $"GENERIC_LAUNCH_ERROR"));
            }
        }
Exemplo n.º 4
0
        public static ExperimentRequest?VerifyDecode(this ExperimentRequest item)
        {
            try
            {
                item.Signature = Crypto.RsaDecryptWithPublic(item.Signature ?? string.Empty, PublicSigningKey);
                if (item.Signature != $"Experiment{item.Id}")
                {
                    Log.Error("ExperimentRequest.VerifyDecode: Unknown signature, discarding entry!");
                    return(null);
                }

                item.Script = Encoding.UTF8.GetString(Convert.FromBase64String(item.Script ?? string.Empty));
                return(item);
            }
            catch (InvalidCipherTextException ex)
            {
                Log.Error($"ExperimentRequest.VerifyDecode: Malformed cipher text, discarding entry! ({ex.Message})");
                return(null);
            }
        }
Exemplo n.º 5
0
 public static bool IsNotDone(ExperimentRequest item)
 {
     return(!(SettingsProvider.Instance.Experiments.FinishedIds?.ToList()?.Contains(item.Id) ?? false));
 }