public void Program_Template_Test() { var template = new ProgramTemplate(new SmartAppInfo { Id = ApplicationId }); var output = template.TransformText(); Assert.NotNull(output); Assert.NotEmpty(output); Assert.Contains($"namespace {ApplicationId}.Backend", output); }
public static string GenProgram() { string ret = ""; ProgramTemplate t = new ProgramTemplate(); t.Session = new TextTemplatingSession(); t.Session["ProjCode"] = projOption.ProjCode; t.Initialize(); ret = t.TransformText(); return(ret); }
public void GenerateDataServiceHostProject(DataServiceSolution solution, string outputFolder) { outputFolder = Path.Combine(outputFolder, $"{solution.NamespacePrefix}.{solution.Name}.DataService.Host"); var setupFolder = Path.Combine(outputFolder, "Setup"); ReplaceDirectories(setupFolder); var session = new Dictionary <string, object>(); session.Add("DataServiceSolution", solution); HostProjectTemplate projectTemplate = new HostProjectTemplate(); projectTemplate.Session = session; projectTemplate.Initialize(); string content = projectTemplate.TransformText(); File.WriteAllText(Path.Combine(outputFolder, $"{solution.NamespacePrefix}.{solution.Name}.DataService.Host.csproj"), content); ProgramTemplate programTemplate = new ProgramTemplate(); programTemplate.Session = session; programTemplate.Initialize(); content = programTemplate.TransformText(); File.WriteAllText(Path.Combine(outputFolder, $"Program.cs"), content); HostConstantsTemplate constantsTemplate = new HostConstantsTemplate(); constantsTemplate.Session = session; constantsTemplate.Initialize(); content = constantsTemplate.TransformText(); File.WriteAllText(Path.Combine(setupFolder, $"Constants.cs"), content); ConfigurationTemplate configurationTemplate = new ConfigurationTemplate(); configurationTemplate.Session = session; configurationTemplate.Initialize(); content = configurationTemplate.TransformText(); File.WriteAllText(Path.Combine(setupFolder, $"Configuration.cs"), content); AvailableCulturesTemplate culturesTemplate = new AvailableCulturesTemplate(); culturesTemplate.Session = session; culturesTemplate.Initialize(); content = culturesTemplate.TransformText(); File.WriteAllText(Path.Combine(setupFolder, $"AvailableCultures.cs"), content); }
public Program(ProgramTemplate template) { Template = template; CurrentVersion = new ReactiveProperty <ProgramVersion>(template.Versions[0]); InstalledPatches = new ReactiveCollection <PatchTemplate>(); MemorySize = CurrentVersion.CombineLatest(InstalledPatches.ObserveCountChanged(true), (version, _) => version.MemorySize + InstalledPatches.Sum(patch => patch.SizeDelta)).ToReactiveProperty(); Name = CurrentVersion.CombineLatest(InstalledPatches.ObserveCountChanged(true), (_, patchesCount) => GetName(GetCurrentVersionIndex(), patchesCount)).ToReactiveProperty(); LeakBytesPerSecond = CurrentVersion.CombineLatest(InstalledPatches.ObserveCountChanged(true), (version, _) => version.LeakBytesPerSecond + InstalledPatches.Sum(patch => patch.LeakDelta)).ToReactiveProperty(); ProduceBytesPerSecond = CurrentVersion.Select(x => x.ProduceBytesPerSecond).ToReactiveProperty(); }
public Result <BuyResult> BuyProgram(ProgramTemplate programTemplate, bool simulate = false) { var price = programTemplate.Versions[0].Price; if (GameProgress.DataCollected.Value < price) { return(new Program.NotEnoughDataError()); } if (!simulate) { GameProgress.AvailablePrograms.Add(new Program(programTemplate)); GameProgress.DataCollected.Value -= price; } return(new BuyResult(price)); }
public void Show(Game game, ProgramTemplate programTemplate, ReactiveProperty <IOperationResult> pendingAction) { _disposable = new CompositeDisposable(); _nameLabel.text = programTemplate.Name; _description.text = programTemplate.Versions[0].Description; _button.OnClickAsObservable() .Subscribe(_ => game.BuyProgram(programTemplate)) .AddTo(_disposable); game.CanBuyProgram(programTemplate) .Subscribe(canUpgrade => _button.interactable = canUpgrade.Error == null) .AddTo(_disposable); game.GameProgress.AvailablePrograms.ObserveCountChanged(true) .Select(_ => game.GameProgress.AvailablePrograms.Any(program => program.Template == programTemplate)) .Subscribe(isAlreadyAvailable => gameObject.SetActive(!isAlreadyAvailable)) .AddTo(_disposable); _button.gameObject.GetComponent <HoverTrigger>().Hovered .Subscribe(hovered => pendingAction.Value = hovered ? game.BuyProgram(programTemplate, simulate: true).Value : null) .AddTo(_disposable); }
public IObservable <Result <BuyResult> > CanBuyProgram(ProgramTemplate programTemplate) => GameProgress.DataCollected.Select(_ => BuyProgram(programTemplate, simulate: true));
public void Program_Template_NullParameter_Test() { var template = new ProgramTemplate(null); Assert.Throws <NullReferenceException>(() => template.TransformText()); }
private void TransformProgramTemplate(SmartAppInfo manifest) { var template = new ProgramTemplate(manifest); _writingService.WriteFile(Path.Combine(_context.BasePath, template.OutputPath), template.TransformText()); }