public void 登録する(チップ種別 chipType, int subChipId, VariablePath サウンドファイルパス) { if (File.Exists(サウンドファイルパス.数なしパス)) { lock (this._Sound利用権) { // すでに辞書に存在してるなら、解放して削除する。 if (this._チップtoコンテキスト.ContainsKey((chipType, subChipId))) { this._チップtoコンテキスト[(chipType, subChipId)]?.Dispose(); this._チップtoコンテキスト.Remove((chipType, subChipId)); } // コンテキストを作成する。 var context = new Cコンテキスト(this._多重度); // サウンドファイルを読み込んでデコードする。 context.SampleSource = SampleSourceFactory.Create(App.サウンドデバイス, サウンドファイルパス); // 多重度分のサウンドを生成する。 for (int i = 0; i < context.Sounds.Length; i++) { context.Sounds[i] = new Sound(App.サウンドデバイス, context.SampleSource); } // コンテキストを辞書に追加する。 this._チップtoコンテキスト.Add((chipType, subChipId), context); Log.Info($"ドラムサウンドを生成しました。[({chipType.ToString()},{subChipId}) = {サウンドファイルパス.変数付きパス}]"); } }
private void _ユーザデータベースを初期化する() { // 利用者を終了する。 App進行描画.ユーザ管理?.Dispose(); // ファイルを削除する。 var vpath = UserDB.ユーザDBファイルパス; try { File.Delete(vpath.数なしパス); // ファイルがない場合には例外は出ない } catch (Exception e) { Log.ERROR($"ユーザデータベースファイルの削除に失敗しました。[{vpath.変数付きパス}][{VariablePath.絶対パスをフォルダ変数付き絶対パスに変換して返す( e.Message )}]"); } // 再生成する。 App進行描画.ユーザ管理を再構築する(); App進行描画.ユーザ管理.ユーザリスト.SelectItem((user) => (user.ユーザID == "AutoPlayer")); // ひとまずAutoPlayerを選択。 }
public Ast LookupVariable(VariablePath variablePath) { Ast variabledefinition; _variableTable.TryGetValue(variablePath.UserPath, out variabledefinition); return(variabledefinition); }
/// <summary> /// set.def ファイルに保存する。 /// </summary> public void 保存する(VariablePath SetDefファイルパス) { using var sw = new StreamWriter(SetDefファイルパス.数なしパス); foreach (var block in this.Blocks) { sw.WriteLine($"#TITLE: {block.Title}"); if (block.FontColor != Color.White) { sw.WriteLine($"#FONTCOLOR: #{block.FontColor.R:X2}{block.FontColor.G:X2}{block.FontColor.B:X2}"); } for (int i = 0; i < block.File.Length; i++) { if (!string.IsNullOrEmpty(block.File[i]) && !string.IsNullOrEmpty(block.Label[i])) { sw.WriteLine(""); sw.WriteLine($"L{i + 1}LABEL: {( string.IsNullOrEmpty( block.Label[ i ] ) ? デフォルトのラベル[ i ] : block.Label[ i ] )}"); sw.WriteLine($"L{i + 1}FILE: {block.File[ i ]}"); } } } }
/// <summary> /// Derived classes override this method to return their /// particular type of scoped item. /// </summary> /// <param name="scope"> /// The scope to look the item up in. /// </param> /// <param name="name"> /// The name of the item to retrieve. /// </param> /// <param name="alias"> /// The scope item that the derived class should return. /// </param> /// <returns> /// True if the scope item was found or false otherwise. /// </returns> protected override bool GetScopeItem( SessionStateScope scope, VariablePath name, out AliasInfo alias) { Diagnostics.Assert(name is not FunctionLookupPath, "name was scanned incorrect if we get here and it is a FunctionLookupPath"); bool result = true; alias = scope.GetAlias(name.QualifiedName); // If the alias is private and the lookup scope // isn't the current scope, claim that the alias // doesn't exist so that the lookup continues. if (alias == null || ((alias.Options & ScopedItemOptions.Private) != 0 && scope != sessionState.CurrentScope)) { result = false; } return(result); }
protected override void On活性化() { using (Log.Block(FDKUtilities.現在のメソッド名)) { var 設定ファイルパス = new VariablePath(@"$(System)images\演奏\レーンフラッシュBASIC.yaml"); var yaml = File.ReadAllText(設定ファイルパス.数なしパス); var deserializer = new YamlDotNet.Serialization.Deserializer(); var yamlMap = deserializer.Deserialize <YAMLマップ>(yaml); this._レーンフラッシュの矩形リスト = new Dictionary <string, RectangleF>(); foreach (var kvp in yamlMap.矩形リスト) { if (4 == kvp.Value.Length) { this._レーンフラッシュの矩形リスト[kvp.Key] = new RectangleF(kvp.Value[0], kvp.Value[1], kvp.Value[2], kvp.Value[3]); } } this._レーンtoレーンContext = new Dictionary <表示レーン種別, レーンContext>(); foreach (表示レーン種別 lane in Enum.GetValues(typeof(表示レーン種別))) { this._レーンtoレーンContext.Add(lane, new レーンContext() { 開始位置dpx = new Vector2( x: レーンフレーム.領域.X + レーンフレーム.現在のレーン配置.表示レーンの左端位置dpx[lane], y: レーンフレーム.領域.Bottom), 転送元矩形 = this._レーンフラッシュの矩形リスト[lane.ToString()], アニメカウンタ = new Counter(), }); } } }
public UserDB() { try { this.Open(ユーザDBファイルパス, VERSION); } catch (Exception e) { Log.WARNING($"エラーが発生しました。新しく作り直します。[{e.Message}]"); #region " DBファイルを削除 " //---------------- try { File.Delete(ユーザDBファイルパス.数なしパス); // ファイルがない場合には例外は出ない } catch (Exception e2) { var msg = $"ユーザデータベースファイルの削除に失敗しました。[{ユーザDBファイルパス.変数付きパス}][{VariablePath.絶対パスをフォルダ変数付き絶対パスに変換して返す( e.Message )}]"; Log.ERROR(msg); throw new Exception(msg, e2); // どうしようもないので例外発出 } //---------------- #endregion this.Open(ユーザDBファイルパス, VERSION); } }
private void button選択_Click(object sender, EventArgs e) { // フォルダ選択ダイアログを生成する。 using (var dialog = new CommonOpenFileDialog("曲読み込みフォルダの選択") { IsFolderPicker = true, // ファイルじゃなくフォルダを開く EnsureReadOnly = true, AllowNonFileSystemItems = false, }) { // ダイアログを表示。 if (dialog.ShowDialog(this.Handle) == CommonFileDialogResult.Ok) { // 選択されたフォルダを曲読み込みフォルダリストに追加する。 foreach (var name in dialog.FileNames) { var vpath = new VariablePath(name); this.listViewフォルダ一覧.Items.Add(new ListViewItem($"{vpath.変数なしパス}")); Log.Info($"曲読み込みフォルダを追加しました。[{vpath.変数付きパス}]"); } this.listViewフォルダ一覧.Refresh(); } } }
private void VisitParameters(ReadOnlyCollection <ParameterAst> parameters) { foreach (ParameterAst ast in parameters) { VariablePath variablePath = ast.Name.VariablePath; if (variablePath.IsAnyLocal()) { VariableAnalysisDetails details; string unaliasedVariableName = VariableAnalysis.GetUnaliasedVariableName(variablePath); if (this._variables.TryGetValue(unaliasedVariableName, out details)) { object obj2; details.Type = ast.StaticType; if (!Compiler.TryGetDefaultParameterValue(ast.StaticType, out obj2)) { details.LocalTupleIndex = -2; } } else { this.NoteVariable(unaliasedVariableName, -1, ast.StaticType, false, false); } } } }
/// <summary> /// 複数譜面(set.def)から生成する。 /// </summary> public Song(SetDef.Block block, VariablePath setDefのあるフォルダの絶対パス) { for (int i = 0; i < 5; i++) { if (string.IsNullOrEmpty(block.File[i])) { continue; } var socre_path = Path.Combine(setDefのあるフォルダの絶対パス.数なしパス, block.File[i] !); this.譜面リスト[i] = new Score() { 難易度ラベル = block.Label[i] ?? SetDef.デフォルトのラベル[i], // LABEL は省略可 譜面 = new ScoreDBRecord() { //Title = "(new song!)", Title = Path.GetFileName(socre_path), ScorePath = socre_path, }, 譜面の属性 = null, 最高記録 = null, }; } }
protected override void On活性化() { using (Log.Block(FDKUtilities.現在のメソッド名)) { var 設定ファイルパス = new VariablePath(@"$(System)images\演奏\チップ光.yaml"); var yaml = File.ReadAllText(設定ファイルパス.数なしパス); var deserializer = new YamlDotNet.Serialization.Deserializer(); var yamlMap = deserializer.Deserialize <YAMLマップ>(yaml); this._放射光の矩形リスト = new Dictionary <表示レーン種別, RectangleF>(); foreach (var kvp in yamlMap.矩形リスト) { if (4 == kvp.Value.Length) { this._放射光の矩形リスト[kvp.Key] = new RectangleF(kvp.Value[0], kvp.Value[1], kvp.Value[2], kvp.Value[3]); } } this._レーンtoステータス = new Dictionary <表示レーン種別, 表示レーンステータス>() { { 表示レーン種別.Unknown, new 表示レーンステータス(表示レーン種別.Unknown) }, { 表示レーン種別.LeftCymbal, new 表示レーンステータス(表示レーン種別.LeftCymbal) }, { 表示レーン種別.HiHat, new 表示レーンステータス(表示レーン種別.HiHat) }, { 表示レーン種別.Foot, new 表示レーンステータス(表示レーン種別.Foot) }, { 表示レーン種別.Snare, new 表示レーンステータス(表示レーン種別.Snare) }, { 表示レーン種別.Bass, new 表示レーンステータス(表示レーン種別.Bass) }, { 表示レーン種別.Tom1, new 表示レーンステータス(表示レーン種別.Tom1) }, { 表示レーン種別.Tom2, new 表示レーンステータス(表示レーン種別.Tom2) }, { 表示レーン種別.Tom3, new 表示レーンステータス(表示レーン種別.Tom3) }, { 表示レーン種別.RightCymbal, new 表示レーンステータス(表示レーン種別.RightCymbal) }, }; } }
public FunctionScopeItemSearcher( SessionStateInternal sessionState, VariablePath lookupPath, CommandOrigin origin) : base(sessionState, lookupPath) { _origin = origin; }
private void CheckLHSAssign(ExpressionAst lhs, BitArray assignedBitArray) { ConvertExpressionAst ast = lhs as ConvertExpressionAst; Type convertType = null; if (ast != null) { lhs = ast.Child; convertType = ast.StaticType; } VariableExpressionAst item = lhs as VariableExpressionAst; VariablePath variablePath = item.VariablePath; if (variablePath.IsAnyLocal()) { string unaliasedVariableName = GetUnaliasedVariableName(variablePath); if ((convertType == null) && (unaliasedVariableName.Equals("foreach", StringComparison.OrdinalIgnoreCase) || unaliasedVariableName.Equals("switch", StringComparison.OrdinalIgnoreCase))) { convertType = typeof(object); } VariableAnalysisDetails details = this.CheckLHSAssignVar(unaliasedVariableName, assignedBitArray, convertType); details.AssociatedAsts.Add(item); item.TupleIndex = details.LocalTupleIndex; item.Automatic = details.Automatic; } else { item.TupleIndex = -2; } }
// 再生と停止 /// <summary> /// サウンドファイルの再生を予約する。 /// </summary> /// <remarks> /// 予約されたサウンドは、500ミリ秒後に生成され、再生される。 /// </remarks> public void 再生を予約する(VariablePath 音声ファイルの絶対パス) { CancellationTokenSource cancelTokenSource; CancellationToken cancelToken; lock (this._CancelTokenSources排他) { // 既存のすべてのタスクをキャンセルする。 foreach (var source in this._CanscellationTokenSources) { source.Cancel(); } // 新しいタスク用のキャンセルトークンソースを生成する。 cancelTokenSource = new CancellationTokenSource(); cancelToken = cancelTokenSource.Token; this._CanscellationTokenSources.Add(cancelTokenSource); } // 新しいタスクを開始する。 Task.Run(() => { // 500ミリ秒待つ。 Thread.Sleep(500); if (cancelToken.IsCancellationRequested) { return; // キャンセルされた } // ファイルからサウンドを生成する。 var sound = this._サウンドを生成する(音声ファイルの絶対パス); if (sound is null) { Log.ERROR($"サウンドの生成に失敗しました。[{音声ファイルの絶対パス}]"); return; // 失敗した } if (cancelToken.IsCancellationRequested) { sound.Dispose(); return; // キャンセルされた } // サウンドを再生する。 sound.Play(0, ループ再生する: true); // キャンセルされるまでブロック。 cancelToken.WaitHandle.WaitOne(); // サウンドを解放する。 sound.Dispose(); }, cancelToken).ContinueWith((t) => { // タスクが終了したらトークンソースを解放。 lock (this._CancelTokenSources排他) { this._CanscellationTokenSources.Remove(cancelTokenSource); cancelTokenSource.Dispose(); } }); }
private static string _ファイルのハッシュを算出して返す(VariablePath 曲ファイルパス) { var sha512 = new SHA512CryptoServiceProvider(); byte[] hash = null; try { using (var fs = new FileStream(曲ファイルパス.数なしパス, FileMode.Open, FileAccess.Read)) hash = sha512.ComputeHash(fs); var hashString = new StringBuilder(); foreach (byte b in hash) { hashString.Append(b.ToString("X2")); } return(hashString.ToString()); } catch (Exception e) { Log.ERROR($"ファイルからのハッシュの作成に失敗しました。({e})[{曲ファイルパス.変数付きパス}]"); throw; } }
/// <summary> /// 指定したAVI番号に動画ファイルを登録する。 /// </summary> public void 登録する(int AVI番号, VariablePath 動画ファイルの絶対パス, double 再生速度 = 1.0) { #region " パラメータチェック " //---------------- if (0 > AVI番号 || 36 * 36 <= AVI番号) { throw new ArgumentOutOfRangeException($"AVI番号が範囲(0~1295)を超えています。[{AVI番号}]"); } if (!(File.Exists(動画ファイルの絶対パス.数なしパス))) { Log.WARNING($"動画ファイルが存在しません。[{動画ファイルの絶対パス.変数付きパス}]"); return; } //---------------- #endregion // すでに登録済みなら解放する。 if (this._動画リスト.ContainsKey(AVI番号)) { this._動画リスト[AVI番号].Dispose(); } // 新しいVideoを生成して登録する。 this._動画リスト[AVI番号] = new Video(動画ファイルの絶対パス, 再生速度); }
public Image(VariablePath imagePath, Vector2?位置dpx = null, Vector2?拡大率 = null) { this.位置dpx = 位置dpx ?? Vector2.Zero; this.拡大率 = 拡大率 ?? Vector2.One; this.子Activityを追加する(this._画像 = new 描画可能画像(imagePath)); }
protected override void On活性化() { using (Log.Block(FDKUtilities.現在のメソッド名)) { var 設定ファイルパス = new VariablePath(@"$(System)images\演奏\ドラムキットとヒットバー.yaml"); var yaml = File.ReadAllText(設定ファイルパス.数なしパス); var deserializer = new YamlDotNet.Serialization.Deserializer(); var yamlMap = deserializer.Deserialize <YAMLマップ>(yaml); this._パーツ画像の矩形リスト = new Dictionary <パーツ, RectangleF>(); foreach (var kvp in yamlMap.矩形リスト) { if (4 == kvp.Value.Length) { this._パーツ画像の矩形リスト[kvp.Key] = new RectangleF(kvp.Value[0], kvp.Value[1], kvp.Value[2], kvp.Value[3]); } } this._パーツ画像の中心位置 = new Dictionary <パーツ, (float X, float Y)>(); foreach (var kvp in yamlMap.中心位置) { if (2 == kvp.Value.Length) { this._パーツ画像の中心位置[kvp.Key] = (kvp.Value[0], kvp.Value[1]); } } this._振動パラメータ = new Dictionary <表示レーン種別, 振動パラメータ>(); foreach (表示レーン種別 lane in Enum.GetValues(typeof(表示レーン種別))) { this._振動パラメータ[lane] = new 振動パラメータ(); } } }
protected override void On活性化() { using (Log.Block(FDKUtilities.現在のメソッド名)) { { var 設定ファイルパス = new VariablePath(@"$(System)images\演奏\ドラムチップ.yaml"); var yaml = File.ReadAllText(設定ファイルパス.数なしパス); var deserializer = new YamlDotNet.Serialization.Deserializer(); var yamlMap = deserializer.Deserialize <YAMLマップ_ドラムチップ>(yaml); this._ドラムチップの縦方向中央位置 = yamlMap.縦方向中央位置; this._ドラムチップの矩形リスト = new Dictionary <string, RectangleF>(); foreach (var kvp in yamlMap.矩形リスト) { if (4 == kvp.Value.Length) { this._ドラムチップの矩形リスト[kvp.Key] = new RectangleF(kvp.Value[0], kvp.Value[1], kvp.Value[2], kvp.Value[3]); } } } this._小節線色 = new SolidColorBrush(グラフィックデバイス.Instance.D2DDeviceContext, Color.White); this._拍線色 = new SolidColorBrush(グラフィックデバイス.Instance.D2DDeviceContext, Color.LightGray); this._ドラムチップアニメ = new LoopCounter(0, 200, 3); this._プレイヤー名表示.前 = App.ユーザ管理.ログオン中のユーザ.ユーザ名; レーンフレーム.レーン配置を設定する(App.ユーザ管理.ログオン中のユーザ.レーン配置); //this._フェードインカウンタ = new Counter( 0, 100, 10 ); //this._演奏状態を初期化する(); this._ビュアーモード時にドラムサウンドを発声する = true; this.現在のフェーズ = フェーズ.クリア; } }
// 生成と終了 public static v002_システム設定 読み込む(VariablePath path) { using var _ = new LogBlock(Log.現在のメソッド名); // (1) 読み込み or 新規作成 var yaml = File.ReadAllText(path.数なしパス); var deserializer = new YamlDotNet.Serialization.Deserializer(); var config = deserializer.Deserialize <v002_システム設定>(yaml); if (2 != config.Version) { throw new Exception("バージョンが違います。"); } // (2) 読み込み後の処理 // パスの指定がなければ、とりあえず exe のあるフォルダを検索対象にする。 if (0 == config.曲検索フォルダ.Count) { config.曲検索フォルダ.Add(@"$(Exe)"); } return(config); }
// 生成と終了 public コンボ表示() { using (Log.Block(FDKUtilities.現在のメソッド名)) { this._コンボ文字画像 = new 画像(@"$(System)images\演奏\コンボ文字.png"); this._前回表示した値 = 0; this._前回表示した数字 = " "; var 設定ファイルパス = new VariablePath(@"$(System)images\演奏\コンボ文字.yaml"); var yaml = File.ReadAllText(設定ファイルパス.数なしパス); var deserializer = new YamlDotNet.Serialization.Deserializer(); var yamlMap = deserializer.Deserialize <YAMLマップ>(yaml); this._コンボ文字の矩形リスト = new Dictionary <string, RectangleF>(); foreach (var kvp in yamlMap.矩形リスト) { if (4 == kvp.Value.Length) { this._コンボ文字の矩形リスト[kvp.Key] = new RectangleF(kvp.Value[0], kvp.Value[1], kvp.Value[2], kvp.Value[3]); } } this._各桁のアニメ = new 各桁のアニメ[4]; for (int i = 0; i < this._各桁のアニメ.Length; i++) { this._各桁のアニメ[i] = new 各桁のアニメ(); } this._百ごとのアニメ = new 百ごとのアニメ(); } }
/// <summary> /// Derived classes override this method to return their /// particular type of scoped item. /// </summary> /// <param name="scope"> /// The scope to look the item up in. /// </param> /// <param name="name"> /// The name of the item to retrieve. /// </param> /// <param name="variable"> /// The scope item that the derived class should return. /// </param> /// <returns> /// True if the scope item was found or false otherwise. /// </returns> protected override bool GetScopeItem( SessionStateScope scope, VariablePath name, out PSVariable variable) { Diagnostics.Assert(name is not FunctionLookupPath, "name was scanned incorrect if we get here and it is a FunctionLookupPath"); bool result = true; variable = scope.GetVariable(name.QualifiedName, _origin); // If the variable is private and the lookup scope // isn't the current scope, claim that the variable // doesn't exist so that the lookup continues. if (variable == null || (variable.IsPrivate && scope != sessionState.CurrentScope)) { result = false; } return(result); }
public void TestInitialize() { var exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); VariablePath.フォルダ変数を追加または更新する("Exe", $@"{exePath}\"); VariablePath.フォルダ変数を追加または更新する("System", Path.Combine(exePath, @"System\")); VariablePath.フォルダ変数を追加または更新する("AppData", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create), @"DTXMania2\")); }
/// <summary> /// box.def ファイルからBOXノードを生成する。 /// </summary> public BoxNode(VariablePath BOX定義ファイルパス, Node 親ノード) : this() { var box = BoxDef.復元する(BOX定義ファイルパス); this.タイトル = box.TITLE; this.親ノード = 親ノード; }
internal static bool IsAnyLocal(this VariablePath variablePath) { if (!variablePath.IsUnscopedVariable && !variablePath.IsLocal) { return(variablePath.IsPrivate); } return(true); }
public override AstVisitAction VisitVariableExpression(VariableExpressionAst variableExpressionAst) { VariablePath variablePath = variableExpressionAst.VariablePath; if ((!this._allVariablesAreAllowed && !this._allowedVariables.Contains <string>(variablePath.UserPath, StringComparer.OrdinalIgnoreCase)) && ((!this._allowEnvironmentVariables || !variablePath.IsDriveQualified) || !variablePath.DriveName.Equals("env", StringComparison.OrdinalIgnoreCase))) { this.ReportError(variableExpressionAst, () => ParserStrings.VariableReferenceNotSupportedInDataSection, new object[0]); } return(AstVisitAction.Continue); }
public static VariableExpressionAst Update( this VariableExpressionAst ast, VariablePath variablePath = null, bool?splatted = null) { return(new VariableExpressionAst( ast.Extent, variablePath ?? ast.VariablePath, splatted ?? ast.Splatted)); }
/// <summary> /// WAVファイルを登録する。 /// </summary> /// <param name="wav番号">登録する番号。0~1295。すでに登録されている場合は上書き更新される。</param> /// <param name="サウンドファイル">登録するサウンドファイルのパス。</param> public void 登録する(SoundDevice device, int wav番号, VariablePath サウンドファイル, bool 多重再生する) { #region " パラメータチェック。" //---------------- if (null == device) { throw new ArgumentNullException(); } if ((0 > wav番号) || (1295 < wav番号)) { throw new ArgumentOutOfRangeException($"WAV番号が範囲を超えています。[{wav番号}]"); } if (!(File.Exists(サウンドファイル.数なしパス))) { Log.WARNING($"サウンドファイルが存在しません。[{サウンドファイル.変数付きパス}]"); return; } //---------------- #endregion // 先に SampleSource を生成する。 var sampleSource = (ISampleSource)null; try { sampleSource = SampleSourceFactory.Create(device, サウンドファイル.数なしパス); } catch { Log.WARNING($"サウンドのデコードに失敗しました。[{サウンドファイル.変数付きパス}"); return; } // すでに登録済みなら解放する。 if (this._WavContexts.ContainsKey(wav番号)) { this._WavContexts[wav番号].Dispose(); this._WavContexts.Remove(wav番号); } // 新しいContextを生成して登録する。 var context = new WavContext(wav番号, (多重再生する) ? this._既定の多重度 : 1); context.SampleSource = sampleSource; for (int i = 0; i < context.Sounds.Length; i++) { context.Sounds[i] = new Sound(device, context.SampleSource); } this._WavContexts.Add(wav番号, context); Log.Info($"サウンドを読み込みました。[{サウンドファイル.変数付きパス}]"); }
// 生成と終了(static) public static void 初期化する() { using (Log.Block(FDKUtilities.現在のメソッド名)) { // レーン配置フォルダから、レーン配置に適合する設定ファイルを検索。 var root = new VariablePath(@"$(System)images\演奏\レーン配置"); レーン配置リスト = new Dictionary <string, レーン配置>(); foreach (var fileInfo in new DirectoryInfo(root.数なしパス).GetFiles("Type*.yaml", SearchOption.TopDirectoryOnly)) { var 拡張子なしのファイル名 = Path.GetFileNameWithoutExtension(fileInfo.Name); レーン配置リスト[拡張子なしのファイル名] = new レーン配置 { 配置名 = 拡張子なしのファイル名 }; } // 各設定ファイルから設定を読み込む。 foreach (var kvp in レーン配置リスト) { var 設定ファイルパス = new VariablePath(Path.Combine(root.数なしパス, kvp.Key + ".yaml")); try { var yaml = File.ReadAllText(設定ファイルパス.数なしパス); var deserializer = new Deserializer(); var yamlMap = deserializer.Deserialize <YAMLマップ>(yaml); kvp.Value.表示レーンの左端位置dpx = yamlMap.左端位置; kvp.Value.表示レーンの幅dpx = yamlMap.幅; kvp.Value.レーンライン = new RectangleF[yamlMap.レーンライン.Length]; for (int i = 0; i < yamlMap.レーンライン.Length; i++) { if (4 == yamlMap.レーンライン[i].Length) { kvp.Value.レーンライン[i] = new RectangleF(yamlMap.レーンライン[i][0], yamlMap.レーンライン[i][1], yamlMap.レーンライン[i][2], yamlMap.レーンライン[i][3]); } } kvp.Value.レーン色 = new Color4(Convert.ToUInt32(yamlMap.レーン色, 16)); kvp.Value.レーンライン色 = new Color4(Convert.ToUInt32(yamlMap.レーンライン色, 16)); Log.Info($"{設定ファイルパス.変数付きパス} ... 完了"); } catch (Exception e) { Log.Info($"{設定ファイルパス.変数付きパス} ... 失敗 [{Folder.絶対パスをフォルダ変数付き絶対パスに変換して返す( e.Message )}]"); } } レーン配置を設定する("TypeA"); } }
public void PathMustStartWithKey() { // arrange const string path = "variables.1.foo.bar"; // act void Parse() => VariablePath.Parse(path); // assert Assert.Throws <InvalidOperationException>(Parse); }
internal static string GetUnaliasedVariableName(VariablePath varPath) { return GetUnaliasedVariableName(varPath.UnqualifiedPath); }
internal VariableToken(InternalScriptExtent scriptExtent, VariablePath path, TokenFlags tokenFlags, bool splatted) : base(scriptExtent, splatted ? TokenKind.SplattedVariable : TokenKind.Variable, tokenFlags) { VariablePath = path; }
private Expression GenerateIteratorStatement(VariablePath iteratorVariablePath, Func<Expression> generateMoveNextUpdatePosition, int iteratorTupleIndex, LabeledStatementAst stmt, Action<List<Expression>, Expression> generateBody) { // We convert: // foreach ($x in $enumerable) {} // Into: // try // { // $oldforeach = $foreach // $enumerable = condition // $foreach = GetEnumerator $enumerable // if ($foreach == $null && $enumerable != $null) // { // $foreach = (new object[] { $enumerable }).GetEnumerator() // } // if ($foreach != $null) // { // while ($foreach.MoveNext()) // { // $x = $foreach.Current // } // } // } // finally // { // $foreach = $oldforeach // } // The translation for switch is similar. var temps = new List<ParameterExpression>(); var exprs = new List<Expression>(); var avs = new AutomaticVarSaver(this, iteratorVariablePath, iteratorTupleIndex); bool generatingForeach = stmt is ForEachStatementAst; exprs.Add(avs.SaveAutomaticVar()); // $enumerable = condition // $foreach/$switch = GetEnumerator $enumerable var enumerable = NewTemp(typeof(object), "enumerable"); temps.Add(enumerable); if (generatingForeach) { exprs.Add(UpdatePosition(stmt.Condition)); } exprs.Add( Expression.Assign(enumerable, GetRangeEnumerator(stmt.Condition.GetPureExpression()) ?? CaptureStatementResults(stmt.Condition, CaptureAstContext.Enumerable).Convert(typeof(object)))); var iteratorTemp = NewTemp(typeof(IEnumerator), iteratorVariablePath.UnqualifiedPath); temps.Add(iteratorTemp); exprs.Add(Expression.Assign(iteratorTemp, DynamicExpression.Dynamic(PSEnumerableBinder.Get(), typeof(IEnumerator), enumerable))); // In a foreach, generate: // if ($foreach == $null && $enumerable != $null) // { // $foreach = (new object[] { $enumerable }).GetEnumerator() // } // In a switch, generate: // if ($switch == $null) // { // $switch = (new object[] { $enumerable }).GetEnumerator() // } var testNeedScalarToEnumerable = generatingForeach ? Expression.AndAlso( Expression.Equal(iteratorTemp, ExpressionCache.NullConstant), Expression.NotEqual(enumerable, ExpressionCache.NullConstant)) : Expression.Equal(iteratorTemp, ExpressionCache.NullConstant); var scalarToEnumerable = Expression.Assign(iteratorTemp, Expression.Call(Expression.NewArrayInit(typeof(object), Expression.Convert(enumerable, typeof(object))), CachedReflectionInfo.IEnumerable_GetEnumerator)); exprs.Add(Expression.IfThen(testNeedScalarToEnumerable, scalarToEnumerable)); exprs.Add(avs.SetNewValue(iteratorTemp)); var moveNext = Expression.Block( generateMoveNextUpdatePosition(), Expression.Call(iteratorTemp, CachedReflectionInfo.IEnumerator_MoveNext)); var loop = GenerateWhileLoop(stmt.Label, () => moveNext, (loopBody, breakTarget, continueTarget) => generateBody(loopBody, Expression.Property(iteratorTemp, CachedReflectionInfo.IEnumerator_Current))); // With a foreach, the enumerator may never get assigned, in which case we skip the loop entirely. // Generate that test. // With a switch, the switch body is never skipped, so skip generating that test, and skip creating // target block. if (generatingForeach) { exprs.Add(Expression.IfThen(Expression.NotEqual(iteratorTemp, ExpressionCache.NullConstant), loop)); } else { exprs.Add(loop); } return Expression.Block( temps.Concat(avs.GetTemps()), Expression.TryFinally(Expression.Block(exprs), avs.RestoreAutomaticVar())); }
private ExpressionAst CheckUsingVariable(VariableToken variableToken, bool withMemberAccess) { var variablePath = variableToken.VariablePath; if (variablePath.IsDriveQualified && variablePath.DriveName.Equals("using", StringComparison.OrdinalIgnoreCase) && variablePath.UnqualifiedPath.Length > 0) { var realVariablePath = new VariablePath(variablePath.UnqualifiedPath); ExpressionAst childExpr = new VariableExpressionAst(variableToken.Extent, realVariablePath, (variableToken.Kind == TokenKind.SplattedVariable)); if (withMemberAccess) { childExpr = CheckPostPrimaryExpressionOperators(NextMemberAccessToken(true), childExpr); } return new UsingExpressionAst(childExpr.Extent, childExpr); } return new VariableExpressionAst(variableToken); }
public Ast LookupVariable(VariablePath variablePath) { Ast variabledefinition; _variableTable.TryGetValue(variablePath.UserPath, out variabledefinition); return variabledefinition; }
public Ast LookupVariable(VariablePath variablePath) { Ast result = null; for (int i = _scopes.Count - 1; i >= 0; i--) { result = _scopes[i].LookupVariable(variablePath); if (result != null) break; } return result; }
internal AutomaticVarSaver(Compiler compiler, VariablePath autoVarPath, int automaticVar) { _compiler = compiler; _autoVarPath = autoVarPath; _automaticVar = automaticVar; }
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) { string varName = arguments as string; if (varName != null) { if (varName.StartsWith("+", StringComparison.Ordinal)) { varName = varName.Substring(1); } VariablePath silp = new VariablePath(varName); if (!silp.IsVariable) { throw new ValidationMetadataException( "ArgumentNotValidVariableName", null, Metadata.ValidateVariableName, varName); } } }