Beispiel #1
0
        /// <summary>
        /// Заполнение меню связанное с выбором языка
        /// </summary>
        private void FillMenuLanguage()
        {
            //очистим список элементов
            languageCurrent.DropDownItems.Clear();

            //В меню добавим языки, которые доступны в файле
            foreach (LanguageDescription languageString in TranslateInterface.GetAvaibleLanguages())
            {
                ToolStripItem tsi = languageCurrent.DropDownItems.Add(languageString.Name, languageString.img);
                tsi.Tag = "_language_";
                tsi.Name = languageString.Key;
                tsi.Click += LangClick;
            }

            //// В меню добавим вызов окна перевода данных
            //ToolStripItem tsi2 = languageCurrent.DropDownItems.Add(@"RESTART MODULE");
            //tsi2.Tag = "_RestartTranslater_";
            //tsi2.Name = @"RESTARTMODULE";
            //tsi2.Text = @"RESTART MODULE";
            //tsi2.Click += TranslateReset;

            // Узнаем какой язык по умолчанию использовать
            string sKeyLang = Settings.Default.LanguageCode;

            LanguageDescription ls = TranslateInterface.GetFromKey(sKeyLang);

            if (ls != null)
            {
                // только при условии что язык с указаным кодом существует
                languageCurrent.Text = ls.Name;
                languageCurrent.Image = ls.img;
            }
        }
Beispiel #2
0
        private static void AddLanguage(MyLanguagesEnum id, string cultureName, string subcultureName = null, string displayName = null, float guiTextScale = 1f, bool isCommunityLocalized = true)
        {
            var language = new LanguageDescription(id, displayName, cultureName, subcultureName, guiTextScale, isCommunityLocalized);

            m_languageIdToLanguage.Add((int)id, language);
            m_cultureToLanguageId.Add(language.FullCultureName, (int)id);
        }
Beispiel #3
0
        /// <summary>
        /// Provides very basic workbook parsing and shunting of code cells
        /// into the evaluation service. Does not display non-code-cell contents
        /// but does evaluate a workbook from top-to-bottom. Restores nuget
        /// packages from the workbook's manifest.
        /// </summary>
        static async Task <int> WorkbookPlayerMain(InteractiveSession session, ClientSessionUri sessionUri)
        {
            var path = new FilePath(sessionUri.WorkbookPath);

            if (!path.FileExists)
            {
                Error.WriteLine($"File does not exist: {path}");
                return(1);
            }

            // load the workbook file
            var workbook = new WorkbookPackage(path);
            await workbook.Open(
                quarantineInfo => Task.FromResult(true),
                path);

            #pragma warning disable 0618
            // TODO: WorkbookDocumentManifest needs to eliminate AgentType like we've done on web
            // to avoid having to use the the flavor mapping in AgentIdentity.
            var targetPlatformIdentifier = AgentIdentity.GetFlavorId(workbook.PlatformTargets [0]);
            #pragma warning restore 0618

            // initialize the session based on manifest metadata from the workbook file
            language = workbook.GetLanguageDescriptions().First();
            await session.InitializeAsync(new InteractiveSessionDescription (
                                              language,
                                              targetPlatformIdentifier,
                                              new EvaluationEnvironment(Environment.CurrentDirectory)));

            // restore NuGet packages
            await session.PackageManagerService.RestoreAsync(
                workbook.Pages.SelectMany(page => page.Packages));

            // insert and evaluate cells in the workbook
            foreach (var cell in workbook.IndexPage.Contents.OfType <CodeCell> ())
            {
                var buffer = cell.CodeAnalysisBuffer.Value;

                lastCodeCellId = await session.EvaluationService.InsertCodeCellAsync(
                    buffer,
                    lastCodeCellId);

                ForegroundColor = ConsoleColor.DarkYellow;
                Write(GetPrompt());
                ResetColor();

                WriteLine(buffer);

                await session.EvaluationService.EvaluateAsync(lastCodeCellId);

                if (lastCellEvaluationStatus != CodeCellEvaluationStatus.Success)
                {
                    break;
                }
            }

            return(0);
        }
Beispiel #4
0
 public InteractiveSessionDescription(
     LanguageDescription languageDescription,
     string targetPlatformIdentifier,
     EvaluationEnvironment evaluationEnvironment = default)
 {
     LanguageDescription      = languageDescription;
     TargetPlatformIdentifier = targetPlatformIdentifier;
     EvaluationEnvironment    = evaluationEnvironment;
 }
Beispiel #5
0
        //private void TranslateReset(object sender, EventArgs e)
        //{
        //    TranslateRestart();
        //}

        private void Translate()
        {
            LanguageDescription ls = TranslateInterface.GetFromKey(Settings.Default.LanguageCode);

            if (ls == null) return;

            TranslateInterface.Translate(this, ls);

            // заголовок программы по своему сделаем
            Text = TranslateInterface.Translate((string)Tag, ls) + @" (" + Application.ProductVersion + @")";
        }
Beispiel #6
0
        public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
        {
            string input = trigger.Text.NextWord();
            RaceId result;

            if (EnumUtil.TryParse <RaceId>(input, out result))
            {
                trigger.Args.Target.Race = result;
                if (!(trigger.Args.Target is Character))
                {
                    return;
                }
                LanguageDescription languageDescByRace = LanguageHandler.GetLanguageDescByRace(result);
                ((Character)trigger.Args.Target).AddLanguage(languageDescByRace);
            }
            else
            {
                trigger.Reply("Invalid Race: " + input);
            }
        }
Beispiel #7
0
        internal static void Initialize()
        {
            TierReader =
                new MappedDBCReader <SkillTiers, SkillTierConverter>(
                    RealmServerConfiguration.GetDBCFile("SkillTiers.dbc"));
            foreach (SkillLine skillLine in new MappedDBCReader <SkillLine, SkillLineConverter>(
                         RealmServerConfiguration.GetDBCFile("SkillLine.dbc")).Entries.Values)
            {
                ById[(uint)skillLine.Id] = skillLine;
                if (skillLine.Category == SkillCategory.Language)
                {
                    LanguageDescription languageDescBySkillType =
                        LanguageHandler.GetLanguageDescBySkillType(skillLine.Id);
                    if (languageDescBySkillType != null)
                    {
                        skillLine.Language = languageDescBySkillType.Language;
                    }
                }
            }

            RaceClassReader =
                new MappedDBCReader <SkillRaceClassInfo, SkillRaceClassInfoConverter>(
                    RealmServerConfiguration.GetDBCFile("SkillRaceClassInfo.dbc"));
            MappedDBCReader <SkillAbility, SkillAbilityConverter> mappedDbcReader =
                new MappedDBCReader <SkillAbility, SkillAbilityConverter>(
                    RealmServerConfiguration.GetDBCFile("SkillLineAbility.dbc"));

            List <SkillAbility>[] arr = new List <SkillAbility> [2000];
            foreach (SkillAbility skillAbility in mappedDbcReader.Entries.Values)
            {
                if (skillAbility.Spell != null)
                {
                    skillAbility.Spell.Ability = skillAbility;
                }
                if (skillAbility.NextSpellId > SpellId.None)
                {
                    Spell spell = SpellHandler.Get(skillAbility.NextSpellId);
                    if (spell != null)
                    {
                        skillAbility.NextAbility = spell.Ability;
                        if (spell.Ability != null)
                        {
                            spell.Ability.PreviousAbility = skillAbility;
                        }
                    }
                }

                List <SkillAbility> val = arr.Get((uint)skillAbility.Skill.Id);
                if (val == null)
                {
                    val = new List <SkillAbility>();
                    ArrayUtil.Set(ref arr, (uint)skillAbility.Skill.Id, val);
                }

                val.Add(skillAbility);
            }

            for (int index = 0; index < arr.Length; ++index)
            {
                if (arr[index] != null)
                {
                    AbilitiesBySkill[index] = arr[index].ToArray();
                }
            }
        }
Beispiel #8
0
 public Task <CodeAnalysis.IWorkspaceService> CreateNew(
     LanguageDescription languageDescription,
     WorkspaceConfiguration workspaceConfiguration,
     CancellationToken cancellationToken)
 => Task.FromResult <CodeAnalysis.IWorkspaceService> (
     new RoslynCompilationWorkspace(workspaceConfiguration));
Beispiel #9
0
        /// <summary>
        /// Hosts an interactive REPL against a supported Workbooks target platform.
        /// This is analogous to 'csharp' or 'csi' or any other REPL on the planet.
        /// </summary>
        static async Task <int> ReplPlayerMain()
        {
            // As an exercise to the reader, this puppy should take an optional
            // workbook flavor ID to know what platform you want to REPL and find
            // it in the list of installed and available ones...
            // For now we'll just pick the first available option 😺
            var workbookTarget = WorkbookAppInstallation.All.FirstOrDefault();

            if (workbookTarget == null)
            {
                RenderError("No workbook target platforms could be found.");
                return(1);
            }

            // We do not currently expose a list of available language descriptions
            // for the given build/installation, but if we did, this is when
            // you'd want to pick one. Just assume 'csharp' for now. Stay tuned.
            language = "csharp";

            // A session description combines just enough info for the entire
            // EvaluationService to get itself in order to do your bidding.
            var sessionDescription = new InteractiveSessionDescription(
                language,
                workbookTarget.Id,
                new EvaluationEnvironment(Environment.CurrentDirectory));

            // Now create and get ready to deal with the session; a more complete
            // client should handle more than just OnNext from the observer.
            var session = InteractiveSession.CreateWorkbookSession();

            session.Events.Subscribe(new Observer <InteractiveSessionEvent> (OnSessionEvent));

            // And initialize it with all of our prerequisites...
            // Status events raised within this method will be posted to the
            // observable above ("starting agent", "initializing workspace", etc).
            await session.InitializeAsync(sessionDescription);

            // At this point we have the following in order, ready to serve:
            //
            //   1. a connected agent ready to execute code
            //   2. a workspace that can perform compliation, intellisense, etc
            //   3. an evaluation service that is ready to deal with (1) and (2)
            //
            // It's at this point that a full UI would allow the user to actually
            // run code. This is the "User Experience main()"...
            //
            // This is the REPL you're looking for...
            while (true)
            {
                // append a new cell (no arguments here imply append)
                var cellId = await session.EvaluationService.InsertCodeCellAsync();

                // render the initial/top-level prompt
                WriteReplPrompt();

                while (true)
                {
                    var deltaBuffer    = ReadLine();
                    var existingBuffer = await session.EvaluationService.GetCodeCellBufferAsync(cellId);

                    await session.EvaluationService.UpdateCodeCellAsync(
                        cellId,
                        existingBuffer.Value + deltaBuffer);

                    if (session.WorkspaceService.IsCellComplete(cellId))
                    {
                        break;
                    }

                    WriteReplPrompt(secondaryPrompt: true);
                }

                await session.EvaluationService.EvaluateAsync(cellId);
                await EvaluationServiceRaceBug();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Provides very basic workbook parsing and shunting of code cells
        /// into the evaluation service. Does not display non-code-cell contents
        /// but does evaluate a workbook from top-to-bottom. Restores nuget
        /// packages from the workbook's manifest.
        /// </summary>
        static async Task <int> WorkbookPlayerMain(string workbookPath)
        {
            var path = new FilePath(workbookPath);

            if (!path.FileExists)
            {
                Error.WriteLine($"File does not exist: {path}");
                return(1);
            }

            // load the workbook file
            var workbook = new WorkbookPackage(path);
            await workbook.Open(
                quarantineInfo => Task.FromResult(true),
                path);

            // create and get ready to deal with the session; a more complete
            // client should handle more than just OnNext from the observer.
            var session = InteractiveSession.CreateWorkbookSession();

            session.Events.Subscribe(new Observer <InteractiveSessionEvent> (OnSessionEvent));

            #pragma warning disable 0618
            // TODO: WorkbookDocumentManifest needs to eliminate AgentType like we've done on web
            // to avoid having to use the the flavor mapping in AgentIdentity.
            var targetPlatformIdentifier = AgentIdentity.GetFlavorId(workbook.PlatformTargets [0]);
            #pragma warning restore 0618

            // initialize the session based on manifest metadata from the workbook file
            language = workbook.GetLanguageDescriptions().First();
            await session.InitializeAsync(new InteractiveSessionDescription (
                                              language,
                                              targetPlatformIdentifier,
                                              new EvaluationEnvironment(Environment.CurrentDirectory)));

            // restore NuGet packages
            await session.PackageManagerService.RestoreAsync(
                workbook.Pages.SelectMany(page => page.Packages));

            // insert and evaluate cells in the workbook
            foreach (var cell in workbook.IndexPage.Contents.OfType <CodeCell> ())
            {
                var buffer = cell.CodeAnalysisBuffer.Value;

                lastCodeCellId = await session.EvaluationService.InsertCodeCellAsync(
                    buffer,
                    lastCodeCellId);

                WriteReplPrompt();
                WriteLine(buffer);

                await session.EvaluationService.EvaluateAsync(lastCodeCellId);
                await EvaluationServiceRaceBug();

                if (lastCellEvaluationStatus != CodeCellEvaluationStatus.Success)
                {
                    break;
                }
            }

            return(0);
        }
Beispiel #11
0
 public static async Task <IWorkspaceService> CreateWorkspaceServiceAsync(LanguageDescription languageDescription, WorkspaceConfiguration configuration, CancellationToken cancellationToken = default(CancellationToken));
Beispiel #12
0
 private static void AddLanguage(MyLanguagesEnum id, string cultureName, string subcultureName = null, string displayName = null, float guiTextScale = 1f, bool isCommunityLocalized = true)
 {
     var language = new LanguageDescription(id, displayName, cultureName, subcultureName, guiTextScale, isCommunityLocalized);
     m_languageIdToLanguage.Add((int)id, language);
     m_cultureToLanguageId.Add(language.FullCultureName, (int)id);
 }
Beispiel #13
0
        /// <summary>
        /// Hosts an interactive REPL against a supported Workbooks target platform.
        /// This is analogous to 'csharp' or 'csi' or any other REPL on the planet.
        /// </summary>
        static async Task <int> ReplPlayerMain(InteractiveSession session)
        {
            // As an exercise to the reader, this puppy should take an optional
            // workbook flavor ID to know what platform you want to REPL and find
            // it in the list of installed and available ones...
            // For now we'll just pick the first available option 😺
            var workbookTarget = WorkbookAppInstallation.All.FirstOrDefault();

            if (workbookTarget == null)
            {
                RenderError("No workbook target platforms could be found.");
                return(1);
            }

            // We do not currently expose a list of available language descriptions
            // for the given build/installation, but if we did, this is when
            // you'd want to pick one. Just assume 'csharp' for now. Stay tuned.
            language = "csharp";

            // A session description combines just enough info for the entire
            // EvaluationService to get itself in order to do your bidding.
            var sessionDescription = new InteractiveSessionDescription(
                language,
                workbookTarget.Id,
                new EvaluationEnvironment(Environment.CurrentDirectory));

            // And initialize it with all of our prerequisites...
            // Status events raised within this method will be posted to the
            // observable above ("starting agent", "initializing workspace", etc).
            await session.InitializeAsync(sessionDescription);

            CodeCellId cellId = default;

            var editor = new LineEditor("xic");

            editor.BeforeRenderPrompt = () => ForegroundColor = ConsoleColor.Yellow;
            editor.AfterRenderPrompt  = () => ResetColor();

            // At this point we have the following in order, ready to serve:
            //
            //   1. a connected agent ready to execute code
            //   2. a workspace that can perform compliation, intellisense, etc
            //   3. an evaluation service that is ready to deal with (1) and (2)
            //
            // It's at this point that a full UI would allow the user to actually
            // run code. This is the "User Experience main()"...
            //
            // This is the REPL you're looking for...
            while (true)
            {
                // append a new cell (no arguments here imply append)
                cellId = await session.EvaluationService.InsertCodeCellAsync();

                for (int i = 0; true; i++)
                {
                    var deltaBuffer = editor.Edit(
                        GetPrompt(i > 0),
                        null);

                    var existingBuffer = await session.EvaluationService.GetCodeCellBufferAsync(cellId);

                    await session.EvaluationService.UpdateCodeCellAsync(
                        cellId,
                        existingBuffer.Value + deltaBuffer);

                    if (session.WorkspaceService.IsCellComplete(cellId))
                    {
                        break;
                    }
                }

                var finishedEvent = await session.EvaluationService.EvaluateAsync(cellId);

                // if the evaluation was not successful, remove the cell so it's not internally
                // re-evaluated (which would continue to yield the same failures)
                if (finishedEvent.Status != CodeCellEvaluationStatus.Success)
                {
                    await session.EvaluationService.RemoveCodeCellAsync(finishedEvent.CodeCellId);
                }
            }
        }
Beispiel #14
0
 public static string NativeName(this LanguageDescription source)
 {
     return(source != null ? source.NativeName : null);
 }
Beispiel #15
0
 public static string EnglishName(this LanguageDescription source)
 {
     return(source != null ? source.EnglishName : null);
 }
 public InteractiveSessionDescription(LanguageDescription languageDescription, string targetPlatformIdentifier, EvaluationEnvironment evaluationEnvironment = default(EvaluationEnvironment));