public void UvssCompiler_ReadsCultureDirective_WhenMultipleDirectivesExist() { GivenAnUltravioletApplicationInServiceMode() .OnFrame(0, app => { UsingCulture("en-US", () => { var tree = UvssParser.Parse( "$culture { ru-RU }\r\n" + "$culture { fr-FR }\r\n" + "@foo { target { animation Width { keyframe 0 { 100.0 } } } }"); var document = UvssCompiler.Compile(app.Ultraviolet, tree); var keyframe = document? .StoryboardDefinitions?.FirstOrDefault()? .Targets?.FirstOrDefault()? .Animations?.FirstOrDefault()? .Keyframes?.FirstOrDefault(); TheResultingObject(keyframe) .ShouldNotBeNull() .ShouldSatisfyTheCondition(x => x.Value.Culture.Name == "fr-FR"); }); }) .RunForOneFrame(); }
/// <summary> /// Compiles an Ultraviolet Style Sheet (UVSS) document from the specified source text. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="source">The source text from which to compile the document.</param> /// <returns>A new instance of <see cref="UvssDocument"/> that represents the compiled data.</returns> public static UvssDocument Compile(UltravioletContext uv, String source) { Contract.Require(uv, nameof(uv)); Contract.Require(source, nameof(source)); var document = UvssParser.Parse(source); return(Compile(uv, document)); }
/// <inheritdoc/> public override void ExportPreprocessed(ContentManager manager, IContentProcessorMetadata metadata, BinaryWriter writer, String input, Boolean delete) { const Int32 FileVersion = 1; writer.Write(FileVersion); var ast = UvssParser.Parse(input); SyntaxSerializer.ToStream(writer, ast, FileVersion); }
/// <summary> /// Compiles an Ultraviolet Style Sheet (UVSS) document from the specified stream. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="stream">The <see cref="Stream"/> that contains the document to compile.</param> /// <returns>A new instance of <see cref="UvssDocument"/> that represents the compiled data.</returns> public static UvssDocument Compile(UltravioletContext uv, Stream stream) { Contract.Require(uv, nameof(uv)); Contract.Require(stream, nameof(stream)); using (var reader = new StreamReader(stream)) { var source = reader.ReadToEnd(); var document = UvssParser.Parse(source); return(Compile(uv, document)); } }
public void UvssCompiler_DefaultsToInvariantCulture() { GivenAnUltravioletApplicationInServiceMode() .OnFrame(0, app => { UsingCulture("ru-RU", () => { var tree = UvssParser.Parse("@foo { target { animation Width { keyframe 0 { 100.0 } } } }"); var document = UvssCompiler.Compile(app.Ultraviolet, tree); var keyframe = document? .StoryboardDefinitions?.FirstOrDefault()? .Targets?.FirstOrDefault()? .Animations?.FirstOrDefault()? .Keyframes?.FirstOrDefault(); TheResultingObject(keyframe) .ShouldNotBeNull() .ShouldSatisfyTheCondition(x => x.Value.Culture.Name == String.Empty); }); }) .RunForOneFrame(); }
/// <summary> /// Gets a task which produces a UVSS document for the specified text snapshot. /// </summary> /// <param name="snapshot">The snapshot for which to return a task.</param> /// <param name="mostRecentDocument">The most recent fully-parsed document for the buffer.</param> /// <returns>The task that was retrieved for the specified snapshot.</returns> public Task <UvssTextParserResult> GetParseTask(ITextSnapshot snapshot, out UvssTextParserResult mostRecentDocument) { lock (syncObject) { var requestedVersion = snapshot.Version; if (versionComplete != null && versionComplete.VersionNumber >= requestedVersion.VersionNumber) { mostRecentDocument = this.mostRecentDocument; return(taskComplete); } if (versionProcessing != null && versionProcessing.VersionNumber >= requestedVersion.VersionNumber) { mostRecentDocument = this.mostRecentDocument; return(taskProcessing); } if (taskQueued != null) { mostRecentDocument = this.mostRecentDocument; return(taskQueued); } } var task = default(Task <UvssTextParserResult>); task = new Task <UvssTextParserResult>(() => { ITextVersion version; lock (syncObject) { version = buffer.CurrentSnapshot.Version; versionProcessing = version; } var currentSnapshot = buffer.CurrentSnapshot; var source = currentSnapshot.GetText(); var document = UvssParser.Parse(source); var result = new UvssTextParserResult(currentSnapshot, document); lock (syncObject) { this.mostRecentDocument = result; versionComplete = version; versionProcessing = null; taskComplete = task; taskProcessing = null; if (taskQueued != null) { taskProcessing = taskQueued; taskQueued = null; taskProcessing.Start(); } } RaiseDocumentParsed(new UvssTextParserEventArgs(result)); return(result); }); lock (syncObject) { if (taskProcessing == null) { taskProcessing = task; taskProcessing.Start(); } else { taskQueued = new Task <UvssTextParserResult>(() => { Task.Delay(QueuedTaskDelay).Wait(); task.Start(); return(task.Result); }); } } mostRecentDocument = this.mostRecentDocument; return(task); }