4using System.Threading.Tasks;
51 using (StreamReader rd =
new StreamReader(State.
From))
53 Cssx = await rd.ReadToEndAsync();
58 byte[] Data = Utf8WithBOM.GetBytes(Css);
59 await State.
To.WriteAsync(Data, 0, Data.Length);
60 State.ToContentType +=
"; charset=utf-8";
74 return Convert(Cssx, Session, FileName,
true);
86 internal static async Task<string>
Convert(
string Cssx,
Variables Session,
string FileName,
bool LockSession)
91 throw new ArgumentNullException(
"No session defined.", nameof(Session));
106 StringBuilder Result =
new StringBuilder();
116 j = Cssx.IndexOf(
'¤', i);
121 Result.Append(Cssx.Substring(i, j - i));
123 k = Cssx.IndexOf(
'¤', j + 1);
127 Script = Cssx.Substring(j + 1, k - j - 1);
131 if (Value is SKColor Color)
133 if (Color.Alpha == 255)
136 Result.Append(Color.Red.ToString(
"X2"));
137 Result.Append(Color.Green.ToString(
"X2"));
138 Result.Append(Color.Blue.ToString(
"X2"));
142 Result.Append(
"rgba(");
143 Result.Append(Color.Red.ToString());
145 Result.Append(Color.Green.ToString());
147 Result.Append(Color.Blue.ToString());
153 else if (Value is
string s)
162 Result.Append(Cssx.Substring(i));
164 return Result.ToString();
178 internal static readonly System.Text.Encoding Utf8WithBOM =
new UTF8Encoding(
true);
Contains the state of a content conversion process.
Variables Session
Session states.
Stream To
Stream pointing to where binary representation of content is to be sent.
string FromFileName
If the content is coming from a file, this parameter contains the name of that file....
Stream From
Stream pointing to binary representation of content.
Converts CSSX-files to CSS, by evaluating emebedded script and replacing it with results.
async Task< bool > ConvertAsync(ConversionState State)
Performs the actual conversion.
string[] ToContentTypes
Converts content to these content types.
static Task< string > Convert(string Cssx, Variables Session, string FileName)
Converts CSSX to CSS, using the current theme
CssxToCss()
Converts CSSX-files to CSS, by evaluating emebedded script and replacing it with results.
string[] FromContentTypes
Converts content from these content types.
Grade ConversionGrade
How well the content is converted.
static ThemeDefinition GetCurrentTheme(Variables Variables)
Gets the current theme definition, based on the host information available in the session varaibles.
Contains properties for a theme.
void Prepare(Variables Variables)
Prepares a collection of variables for transforming content based on a theme.
Class managing a script expression.
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
virtual void Push()
Pushes the current set of variables to the stack. This state is restored by calling Pop....
virtual void Pop()
Pops a previously stored set of variables from the stack. Variables are stored on the stack by callin...
Task LockAsync()
Locks the collection. The collection is by default thread safe. But if longer transactions require un...
void Release()
Releases the collection, previously locked through a call to Lock().
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...