internal ControllerAssemblyCompiler(IFileSystem fileSystem, ICompilerBuildCacheSerializer cacheSerializer, ICSharpCompiler compiler, string applicationName, string controllerDir)
 {
     _fileSystem      = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     _cacheSerializer = cacheSerializer ?? throw new ArgumentNullException(nameof(cacheSerializer));
     _compiler        = compiler ?? throw new ArgumentNullException(nameof(compiler));
     ApplicationName  = applicationName ?? throw new ArgumentNullException(nameof(applicationName));
     ControllerDir    = _fileSystem.Path.GetFullPath(controllerDir ?? throw new ArgumentNullException(nameof(controllerDir)));
 }
 public CSharpOptimizer(IBlazorClientConfiguration blazorClientConfiguration, IServiceProvider serviceProvider)
 {
     if (blazorClientConfiguration.CompileLocally)
     {
         _cSharpCompiler = (CSharpCompiler)serviceProvider.GetService(typeof(ICSharpCompiler));
     }
     else
     {
         _cSharpCompiler = (CSharpRemoteCompiler)serviceProvider.GetService(typeof(CSharpRemoteCompiler));
     }
 }
        public CSharpThreadedOptimizer(IBlazorClientConfiguration blazorClientConfiguration, IServiceProvider serviceProvider,
                                       IWorkerFactory workerFactory)
        {
            if (blazorClientConfiguration.CompileLocally)
            {
                _cSharpCompiler = (CSharpCompiler)serviceProvider.GetService(typeof(ICSharpCompiler));
            }
            else
            {
                _cSharpCompiler = (CSharpRemoteCompiler)serviceProvider.GetService(typeof(CSharpRemoteCompiler));
            }

            _workerFactory = workerFactory;
        }
Exemplo n.º 4
0
        protected override void Initialize()
        {
            string            variables;
            bool              variants;
            LocalizableString localizable_question, localizable_rationale;

            xml_drawing.CreateDrawingObjects(game.DrawingObjects);              // Draw objects shared by all variants

            if (game.Variants.Count > 0)
            {
                xml_drawing.CreateDrawingObjects(game.Variants[current.Variant].DrawingObjects);                  // Draw variant specific objects
            }
            compiler = ServiceLocator.Instance.GetService <ICSharpCompiler> ();

            variants = game.Variants.Count > 0;
            SetCheckAttributes();

            if (variants && game.Variants[current.Variant].Variables != null)
            {
                variables = game.Variants[current.Variant].Variables;
            }
            else
            {
                variables = game.Variables;
            }

            if (variants && game.Variants[current.Variant].Question != null)
            {
                localizable_question = game.Variants[current.Variant].Question;
            }
            else
            {
                localizable_question = game.Question;
            }

            if (variants && game.Variants[current.Variant].Rationale != null)
            {
                localizable_rationale = game.Variants[current.Variant].Rationale;
            }
            else
            {
                localizable_rationale = game.Rationale;
            }

            if (String.IsNullOrEmpty(variables) == false)
            {
                compiler.EvaluateCode(variables);

                try {
                    if (String.IsNullOrEmpty(localizable_question.Value) == false)
                    {
                        localizable_question.ValueComputed = Int32.Parse(ReplaceVariables(localizable_question.Value));
                    }

                    if (localizable_rationale != null && String.IsNullOrEmpty(localizable_rationale.Value) == false)
                    {
                        localizable_rationale.ValueComputed = Int32.Parse(ReplaceVariables(localizable_rationale.Value));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("GameXml.Initialize. Error {0}", e);
                }
            }

            if (variants && game.Variants[current.Variant].Question != null)
            {
                question = CatalogGetString(game.Variants[current.Variant].Question);
            }
            else
            {
                question = CatalogGetString(game.Question);
            }

            if (variants && game.Variants[current.Variant].AnswerText != null)
            {
                answer = CatalogGetString(game.Variants[current.Variant].AnswerText);
            }
            else
            {
                answer = CatalogGetString(game.AnswerText);
            }

            if (variants && game.Variants[current.Variant].Rationale != null)
            {
                rationale = CatalogGetString(game.Variants[current.Variant].Rationale);
            }
            else
            {
                rationale = CatalogGetString(game.Rationale);
            }

            if (variants && game.Variants[current.Variant].AnswerShow != null)
            {
                answer_show = CatalogGetString(game.Variants[current.Variant].AnswerShow);
            }
            else
            {
                answer_show = CatalogGetString(game.AnswerShow);
            }

            if (String.IsNullOrEmpty(variables) == false)
            {
                question    = ReplaceVariables(question);
                rationale   = ReplaceVariables(rationale);
                answer      = ReplaceVariables(answer);
                answer_show = ReplaceVariables(answer_show);
            }

            int option_answer = xml_drawing.GetOptionCorrectAnswerIndex();

            if (option_answer != -1)
            {
                Answer.SetMultiOptionAnswer(option_answer, answer);

                // Translators {0}: list of options (A, B, C)
                string answers = String.Format(Translations.GetString("Answer {0}."),
                                               Answer.GetMultiOptionsPossibleAnswers(xml_drawing.Options.Count));
                question = question.Replace(option_answers, answers);
            }
            else
            {
                Answer.Correct = answer;
            }

            SetCheckExpression();
            SetAnswerCorrectShow();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerAssemblyCompiler"/> class.
 /// </summary>
 /// <param name="compiler">The compiler to use.</param>
 /// <param name="applicationName">The application name. This is used in the temp path used to generate the assembly, as to not conflict with other applications that also dynamically compile SilentHunter controllers.</param>
 /// <param name="controllerDir">The path containing controller source files.</param>
 public ControllerAssemblyCompiler(ICSharpCompiler compiler, string applicationName, string controllerDir)
     : this(new FileSystem(), new CompilerBuildCacheJsonSerializer(), compiler, applicationName, controllerDir)
 {
 }
Exemplo n.º 6
0
        protected override void Initialize()
        {
            string variables;
            bool variants;
            LocalizableString localizable_question, localizable_rationale;

            compiler = ServiceLocator.Instance.GetService <ICSharpCompiler> ();

            variants = game.Variants.Count > 0;
            SetCheckAttributes ();

            if (variants && game.Variants[current.Variant].Variables != null)
                variables = game.Variants[current.Variant].Variables;
            else
                variables = game.Variables;

            if (variants && game.Variants[current.Variant].Question != null)
                localizable_question = game.Variants[current.Variant].Question;
            else
                localizable_question = game.Question;

            if (variants && game.Variants[current.Variant].Rationale != null)
                localizable_rationale = game.Variants[current.Variant].Rationale;
            else
                localizable_rationale = game.Rationale;

            if (String.IsNullOrEmpty (variables) == false)
            {
                compiler.EvaluateCode (variables);

                try {

                    if (String.IsNullOrEmpty (localizable_question.Value) == false)
                        localizable_question.ValueComputed = Int32.Parse (ReplaceVariables (localizable_question.Value));

                    if (localizable_rationale != null && String.IsNullOrEmpty (localizable_rationale.Value) == false)
                        localizable_rationale.ValueComputed = Int32.Parse (ReplaceVariables (localizable_rationale.Value));
                }
                catch (Exception e)
                {
                    Console.WriteLine ("GameXml.Initialize. Error {0}", e);
                }
            }

            if (variants && game.Variants[current.Variant].Question != null)
                question = CatalogGetString (game.Variants[current.Variant].Question);
            else
                question = CatalogGetString (game.Question);

            if (variants && game.Variants[current.Variant].AnswerText != null)
                answer = CatalogGetString (game.Variants[current.Variant].AnswerText);
            else
                answer = CatalogGetString (game.AnswerText);

            if (variants && game.Variants[current.Variant].Rationale != null)
                rationale = CatalogGetString (game.Variants[current.Variant].Rationale);
            else
                rationale = CatalogGetString (game.Rationale);

            if (variants && game.Variants[current.Variant].AnswerShow != null)
                answer_show = CatalogGetString (game.Variants[current.Variant].AnswerShow);
            else
                answer_show = CatalogGetString (game.AnswerShow);

            if (String.IsNullOrEmpty (variables) == false)
            {
                question = ReplaceVariables (question);
                rationale = ReplaceVariables (rationale);
                answer = ReplaceVariables (answer);
                answer_show = ReplaceVariables (answer_show);
            }

            if (options != null && options.Count > 0)
            {
                for (int i = 0; i < options.Count; i++)
                {
                    OptionDrawingObject option = options [i];
                    if (option.Correct == true)
                    {
                        Answer.SetMultiOptionAnswer (i, answer);
                        break;
                    }
                }

                // Translators {0}: list of options (A, B, C)
                string answers = String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Answer {0}."),
                    Answer.GetMultiOptionsPossibleAnswers (options.Count));
                question = question.Replace (option_answers, answers);
            }
            else
            {
                Answer.Correct = answer;
            }

            SetCheckExpression ();
            SetAnswerCorrectShow ();
        }
Exemplo n.º 7
0
 public CompilerController(ICSharpCompiler cSharpCompiler)
 {
     _cSharpCompiler = cSharpCompiler;
 }
Exemplo n.º 8
0
 public virtual Task InitializeAsync()
 {
     _sut = CreateSubject(_fileSystem);
     return(Task.CompletedTask);
 }