Beispiel #1
0
        protected override long RunResolve(Stopwatch sw, ITestCase testCase, object container, int testCasesCount,
                                           RegistrationKind registrationKind)
        {
            try
            {
                if (registrationKind == RegistrationKind.PerThread)
                {
                    if (testCase is PerThreadTestCaseD)
                    {
                        throw new OutOfMemoryException("Process takes more than 20 minutes!");
                    }

                    sw.Start();
                    using (((ServiceContainer)container).BeginScope())
                    {
                        testCase.Resolve(container, testCasesCount);
                    }
                    sw.Stop();
                    return(sw.ElapsedMilliseconds);
                }

                return(base.RunResolve(sw, testCase, container, testCasesCount, registrationKind));
            }
            catch (OutOfMemoryException)
            {
                return(-1);
            }
        }
Beispiel #2
0
    // -----------------------------------------------------------------------
    // Register something with our PM given the specified information.
    // The data passed in is stored directly in our map so the assumption
    // is that we are now owners.
    // ie. don't delete this data object elsewhere!
    // -----------------------------------------------------------------------
    private int RegisterWithPM(String name, String units, String description, RegistrationKind regKind, String sDDML)
    //,Packable* data);
    {
        String ddml = sDDML;

        if (units != "")
        {
            addAttributeToXML(ddml, "unit=\"" + units + "\"");
        }
        if (description != "")
        {
            addAttributeToXML(ddml, "description=\"" + description + "\"");
        }

        // Add new object to our map.
        String fullRegName = name + regKind.ToString();
        Reg    reg         = new Reg();

        reg.data  = new TDDMLValue(sDDML, "");
        reg.kind  = regKind;
        reg.ddml  = ddml;
        reg.regID = nextID();
        regNames.Add(fullRegName, reg);

        SendRegisterMsg(name, ddml, reg.regID, (int)regKind, 0);
        return(reg.regID);
    }
        public object Register(object container, RegistrationKind registrationKind)
        {
            container = _registration.BeforeRegisterCallback(container, registrationKind);

            RegisterClasses(container);

            return(_registration.AfterRegisterCallback(container, registrationKind));
        }
Beispiel #4
0
 private void AppendResults(Dictionary <string, IEnumerable <FinalTestResult> > results, string testCaseName,
                            RegistrationKind registrationKind, StringBuilder sb)
 {
     foreach (var result in results)
     {
         AppendResult(testCaseName, registrationKind, sb, result);
     }
 }
        protected virtual object RunRegister(Stopwatch sw, ITestCase testCase, object container,
                                             RegistrationKind registrationKind)
        {
            sw.Start();
            var newContainer = testCase.Register(container, registrationKind);

            sw.Stop();

            return(newContainer);
        }
Beispiel #6
0
        public void SetRegistrationKind(RegistrationKind kind, string city, string code)
        {
            if (kind == RegistrationKind.RCS)
            {
                Identifier = $"{kind:G} {city.Trim()} {Siret.Substring(0, 9)} ";
            }

            if (kind == RegistrationKind.RM)
            {
                Identifier = $"{kind:G} {Siret.Substring(0, 9)} {code.Trim()}";
            }
        }
Beispiel #7
0
 protected override long RunResolve(Stopwatch sw, ITestCase testCase, object container, int testCasesCount,
                                    RegistrationKind registrationKind)
 {
     try
     {
         return(base.RunResolve(sw, testCase, container, testCasesCount, registrationKind));
     }
     catch (OutOfMemoryException)
     {
         return(-1);
     }
 }
Beispiel #8
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="dllName"></param>
    /// <returns></returns>
    String getDescription(String dllName)
    {
        StringBuilder returnString = new StringBuilder();

        try
        {
            returnString.Append("<describecomp>\n");
            returnString.Append("<executable>" + dllName + "</executable>\n");
            returnString.Append("<class>" + name + "</class>\n");
            returnString.Append("<version>1.0</version>\n");
            returnString.Append("<author>APSRU</author>\n");

            foreach (KeyValuePair <String, Reg> reg in regNames)
            {
                RegistrationKind Kind = reg.Value.kind;
                if (Kind == RegistrationKind.respondToGetReg)
                {
                    returnString.Append(getPropertyDescription(reg, "read"));
                }
                else if (Kind == RegistrationKind.respondToSetReg)
                {
                    returnString.Append(getPropertyDescription(reg, "write"));
                }
                else if (Kind == RegistrationKind.respondToGetSetReg)
                {
                    returnString.Append(getPropertyDescription(reg, "both"));
                }
                else if (Kind == RegistrationKind.respondToEventReg)
                {
                    returnString.Append(getEventDescription(reg, "subscribed"));
                }
                else if (Kind == RegistrationKind.eventReg)
                {
                    returnString.Append(getEventDescription(reg, "published"));
                }
                else if (Kind == RegistrationKind.getReg)
                {
                    returnString.Append("   <driver name=\"");
                    returnString.Append(getRegName(reg));
                    returnString.Append("\">\n");
                    returnString.Append(reg.Value.ddml);
                    returnString.Append("\n</driver>\n");
                }
            }
        }
        catch (Exception err)
        {
            returnString.Append("<ERROR>" + err.Message + "</ERROR>\n");
        }
        returnString.Append("</describecomp>\n");
        return(returnString.ToString());
    }
Beispiel #9
0
        private void AppendResult(string testCaseName, RegistrationKind registrationKind, StringBuilder sb,
                                  KeyValuePair <string, IEnumerable <FinalTestResult> > result)
        {
            var currentValues = GetCurrentValues(testCaseName, registrationKind, result);

            sb.Append(result.Key);
            foreach (var currentValue in currentValues.OrderBy(r => r.TestCasesCount))
            {
                sb.Append(GetValuesAsText(currentValue));
            }
            sb.Append(" \\\\ \\hline");
            sb.AppendLine();
        }
Beispiel #10
0
    /// <summary>
    /// Return a registration id for the specified name. 0 if not found.
    /// </summary>
    /// <param name="name"></param>
    /// <param name="regKind"></param>
    /// <returns>0 if not found</returns>
    private int nameToRegistrationID(String name, RegistrationKind regKind)
    {
        String FullRegName = name + regKind.ToString();

        if (regNames.ContainsKey(FullRegName))
        {
            return(regNames[FullRegName].regID);
        }
        else
        {
            return(0);
        }
    }
        public override object BeforeRegisterCallback(object container, RegistrationKind registrationKind)
        {
            if (registrationKind == RegistrationKind.PerThread)
            {
                var c = (Container)container;

                c.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle();

                return(c);
            }

            return(base.BeforeRegisterCallback(container, registrationKind));
        }
Beispiel #12
0
/*      bool read(const std::string& name, Convertable* value, bool optional);
 *    bool read(const std::string& name, std::vector<Convertable*> values, bool optional);
 *
 *    void publish(const std::string& name, Packable* data);
 *    void subscribe(const std::string& eventName, Packable* handler);
 *    void query(const std::string& pattern, std::vector<QueryMatch>& matches);
 *
 *    void setSearchOrder(const std::vector<std::string> &list) {simSectionsToSearch = list;};
 *    void getSearchOrder(std::vector<std::string> &list) {list = simSectionsToSearch;};
 *    bool readFiltered(const std::string& filterName, std::vector<std::string> &values);
 *    bool readAll(std::vector<std::string> &names, std::vector<std::string> &values);
 *    bool readScripts(std::map<std::string, std::string> &scripts);
 */
    // -----------------------------------------------------------------------
    /// <summary>
    /// Export a variable. The variable passed in is stored directly
    /// in our map so the assumption is that we are now owners.
    /// ie. don't delete this data object elsewhere!
    /// </summary>
    /// <param name="name"></param>
    /// <param name="units"></param>
    /// <param name="description"></param>
    /// <param name="writable"></param>
    // -----------------------------------------------------------------------
    public void expose(String name, String units, String description, Boolean writable, String sDDML)
    //,Packable* variable);
    {
        RegistrationKind kind = RegistrationKind.respondToGetReg;

        if (writable)
        {
            kind = RegistrationKind.respondToGetSetReg;
        }
        if (nameToRegistrationID(name, RegistrationKind.respondToGetReg) == 0)
        {
            RegisterWithPM(name, units, description, kind, sDDML);
        }
    }
 protected virtual long RunResolve(Stopwatch sw, ITestCase testCase, object container, int testCasesCount,
                                   RegistrationKind registrationKind)
 {
     try
     {
         sw.Start();
         testCase.Resolve(container, testCasesCount);
         sw.Stop();
         return(sw.ElapsedMilliseconds);
     }
     catch (OutOfMemoryException)
     {
         return(-1);
     }
 }
        public TestResult RunTest(int count, string testCaseName, RegistrationKind registrationKind)
        {
            var testResult = new TestResult
            {
                TestCaseName     = testCaseName,
                RegistrationKind = registrationKind,
                TestCasesCount   = count
            };
            var sw = new Stopwatch();

            var testCase  = GetTestCase(testCaseName, registrationKind);
            var container = RunRegister(sw, testCase, GetContainer(registrationKind), registrationKind);

            testResult.RegisterTime = sw.ElapsedMilliseconds;

            sw.Reset();
            testResult.ResolveTime = RunResolve(sw, testCase, container, count, registrationKind);

            RunDispose(container);

            return(testResult);
        }
        protected override long RunResolve(Stopwatch sw, ITestCase testCase, object container, int testCasesCount,
                                           RegistrationKind registrationKind)
        {
            try
            {
                if (registrationKind == RegistrationKind.PerThread)
                {
                    sw.Start();
                    using (var scope = ((DependencyInjectionContainer)container).BeginLifetimeScope())
                    {
                        testCase.Resolve(scope, testCasesCount);
                    }
                    sw.Stop();
                    return(sw.ElapsedMilliseconds);
                }

                return(base.RunResolve(sw, testCase, container, testCasesCount, registrationKind));
            }
            catch (OutOfMemoryException)
            {
                return(-1);
            }
        }
 protected override object GetContainer(RegistrationKind registrationKind)
 {
     return(new DependencyInjectionContainer());
 }
Beispiel #17
0
 private string RunTests(string containerName, RegistrationKind registrationKind, string testCase,
                         int testsCount)
 {
     return(ProcessHelper.StartProcess(_processPath,
                                       $"{containerName} -r {(int)registrationKind} -t {testCase} -c {testsCount}"));
 }
 protected abstract object GetContainer(RegistrationKind registrationKind);
Beispiel #19
0
 protected abstract string GetRegistrationKindColumnNameText(RegistrationKind registrationKind);
        internal async Task StartAsync(string configContent, RegistrationKind regKind)
        {
            Logger.LogInfo("Framework starting...");

            // Load and validate configuration data
            var config = new Configuration();

            config.Load(configContent);
            _config = config;

            var clientId = config.DefaultClientId;

            Organization        = config.OAuth.Client.Organization;
            Name                = config.OAuth.Client.ClientName;
            DetailedDescription = config.OAuth.Client.Description;

            Identifier    = config.DefaultClientId.Id;
            Environment   = config.DefaultClientId.Environment;
            RegisteredBy  = config.DefaultClientId.RegisteredBy;
            Scope         = new List <string>(config.DefaultClientId.Scope.Split(' ').Where(s => !string.IsNullOrWhiteSpace(s))).AsReadOnly();
            ScopeAsString = config.DefaultClientId.Scope;
            Status        = config.DefaultClientId.Status;

            RedirectUri = config.DefaultClientId.RedirectUri;

            // Load device and any previous registration info.
            await MASDevice.InitializeAsync(config);

            // Authorization providers not supported yet
            //var response = await MAGRequests.GetAuthorizationProviders(_config, Device);

            // Load client access if client registration is requested
            if (MAS.RegistrationKind == RegistrationKind.Client)
            {
                Client = await MASUser.InitializeAsync(config, MASDevice.Current, true);
            }

            // Load user and any previous access token or idtoken info
            await MASUser.InitializeAsync(config, MASDevice.Current, false);

            if (!MASDevice.Current.IsRegistered)
            {
                switch (regKind)
                {
                case RegistrationKind.Client:
                    if (!config.HasScope(ScopeNames.MssoClientRegister))
                    {
                        ErrorFactory.ThrowError(ErrorCode.DeviceRegistrationAttemptedWithUnregisteredScope);
                    }

                    await MASDevice.Current.RegisterWithClientAsync();

                    // Create a device anonymous user
                    var clientUser = new MASUser(_config, MASDevice.Current);
                    await clientUser.LoginAnonymouslyAsync();

                    Client = clientUser;

                    break;

                case RegistrationKind.User:
                    // Ask for login with user device registration
                    LoginRequested?.Invoke(null, EventArgs.Empty);
                    break;

                default:
                    ErrorFactory.ThrowError(ErrorCode.DeviceRegistrationAttemptedWithUnregisteredScope);
                    break;
                }
            }

            Logger.LogInfo("Framework started");
        }
        protected ITestCase GetTestCase(string testCase, RegistrationKind registrationKind)
        {
            switch (testCase)
            {
            case TestCaseName.A:
                switch (registrationKind)
                {
                case RegistrationKind.Singleton:
                    return(new SingletonTestCaseA(GetRegistration(), GetResolving()));

                case RegistrationKind.Transient:
                    return(new TransientTestCaseA(GetRegistration(), GetResolving()));

                case RegistrationKind.TransientSingleton:
                    return(new TransientSingletonTestCaseA(GetRegistration(), GetResolving()));

                case RegistrationKind.PerThread:
                    return(new PerThreadTestCaseA(GetRegistration(), GetResolving()));

                case RegistrationKind.FactoryMethod:
                    return(new FactoryMethodTestCaseA(GetRegistration(), GetResolving()));

                default:
                    throw new ArgumentOutOfRangeException(nameof(registrationKind), registrationKind, null);
                }

            case TestCaseName.B:
                switch (registrationKind)
                {
                case RegistrationKind.Singleton:
                    return(new SingletonTestCaseB(GetRegistration(), GetResolving()));

                case RegistrationKind.Transient:
                    return(new TransientTestCaseB(GetRegistration(), GetResolving()));

                case RegistrationKind.TransientSingleton:
                    return(new TransientSingletonTestCaseB(GetRegistration(), GetResolving()));

                case RegistrationKind.PerThread:
                    return(new PerThreadTestCaseB(GetRegistration(), GetResolving()));

                case RegistrationKind.FactoryMethod:
                    return(new FactoryMethodTestCaseB(GetRegistration(), GetResolving()));

                default:
                    throw new ArgumentOutOfRangeException(nameof(registrationKind), registrationKind, null);
                }

            case TestCaseName.C:
                switch (registrationKind)
                {
                case RegistrationKind.Singleton:
                    return(new SingletonTestCaseC(GetRegistration(), GetResolving()));

                case RegistrationKind.Transient:
                    return(new TransientTestCaseC(GetRegistration(), GetResolving()));

                case RegistrationKind.TransientSingleton:
                    return(new TransientSingletonTestCaseC(GetRegistration(), GetResolving()));

                case RegistrationKind.PerThread:
                    return(new PerThreadTestCaseC(GetRegistration(), GetResolving()));

                case RegistrationKind.FactoryMethod:
                    return(new FactoryMethodTestCaseC(GetRegistration(), GetResolving()));

                default:
                    throw new ArgumentOutOfRangeException(nameof(registrationKind), registrationKind, null);
                }

            case TestCaseName.D:
                switch (registrationKind)
                {
                case RegistrationKind.Singleton:
                    return(new SingletonTestCaseD(GetRegistration(), GetResolving()));

                case RegistrationKind.Transient:
                    return(new TransientTestCaseD(GetRegistration(), GetResolving()));

                case RegistrationKind.TransientSingleton:
                    return(new TransientSingletonTestCaseD(GetRegistration(), GetResolving()));

                case RegistrationKind.PerThread:
                    return(new PerThreadTestCaseD(GetRegistration(), GetResolving()));

                case RegistrationKind.FactoryMethod:
                    return(new FactoryMethodTestCaseD(GetRegistration(), GetResolving()));

                default:
                    throw new ArgumentOutOfRangeException(nameof(registrationKind), registrationKind, null);
                }

            default:
                throw new ArgumentOutOfRangeException(nameof(registrationKind), registrationKind, null);
            }
        }
 protected override string GetRegistrationKindColumnNameText(RegistrationKind registrationKind)
 {
     return
         ($"{registrationKind};{registrationKind};{registrationKind};{registrationKind};{registrationKind};{registrationKind};");
 }
Beispiel #23
0
 public virtual object BeforeRegisterCallback(object container, RegistrationKind registrationKind)
 {
     return(container);
 }
Beispiel #24
0
 private static IEnumerable <FinalTestResult> GetCurrentValues(string testCaseName,
                                                               RegistrationKind registrationKind, KeyValuePair <string, IEnumerable <FinalTestResult> > result)
 {
     return(result.Value.Where(r => r.TestCaseName == testCaseName &&
                               r.RegistrationKind == registrationKind));
 }
Beispiel #25
0
 private static TestResult RunPerformanceTests(IPerformanceTest performanceTest, int count, string testCase,
                                               RegistrationKind registrationKind)
 {
     WarmUpPerformanceTest(performanceTest, testCase, registrationKind);
     return(performanceTest.RunTest(count, testCase, registrationKind));
 }
Beispiel #26
0
 private static void WarmUpPerformanceTest(IPerformanceTest performanceTest, string testCase,
                                           RegistrationKind registrationKind)
 {
     performanceTest.RunTest(1, testCase, registrationKind);
 }
 public override object AfterRegisterCallback(object container, RegistrationKind registrationKind)
 {
     return(((ContainerBuilder)container).Build());
 }
 protected override object GetContainer(RegistrationKind registrationKind)
 {
     return(registrationKind == RegistrationKind.PerThread
         ? new Container(scopeContext: new ThreadScopeContext())
         : new Container());
 }
Beispiel #29
0
 protected override object GetContainer(RegistrationKind registrationKind)
 {
     return(new Container());
 }
Beispiel #30
0
 protected override object GetContainer(RegistrationKind registrationKind)
 {
     return(new StandardKernel());
 }