public Action BuildSearchLogix(RefID query) { Slot logix = mainSlot.AddSlot("Search logix"); Network.GET_String getString = logix.AttachComponent <Network.GET_String>(); StringRegister url = logix.AttachComponent <StringRegister>(); url.Value.Value = "https://better-lightning-crate.glitch.me/"; FormatString formatString = logix.AttachComponent <FormatString>(); ValueField <string> type = logix.AttachComponent <ValueField <string> >(); ValueField <string> format = logix.AttachComponent <ValueField <string> >(); format.Value.Value = "{0}/{1}/{2}"; formatString.Format.Value = format.Value.ReferenceID; formatString.Parameters.Add(); formatString.Parameters.Add(); formatString.Parameters.Add(); formatString.Parameters[0].Value = url.Value.ReferenceID; formatString.Parameters[1].Value = type.Value.ReferenceID; formatString.Parameters[2].Value = query; getString.URL.Value = formatString.Str.ReferenceID; Actions.WriteValueNode <string> writeResponse = logix.AttachComponent <Actions.WriteValueNode <string> >(); StringRegister response = logix.AttachComponent <StringRegister>(); searchResponse = response; writeResponse.Value.Value = getString.Content.ReferenceID; writeResponse.Target.Value = response.Value.ReferenceID; getString.OnResponse.Target = writeResponse.Write; //writeResponse.Target.OwnerNode.RemoveAllLogixBoxes(); //LogixHelper.MoveUnder(writeResponse.Target.OwnerNode, logix, true); //getString.Request(); return(getString.Request); }
private void btnDecrypt_Click(object sender, EventArgs e) { if (CheckTextBox()) { string entryStr = txtEncrypt.Text; string key = txtKey.Text; try { if (cbBase64.Checked) { byte[] bytes = FormatString.FromBase64String(entryStr); txtDecrypt.Text = Encoding.Default.GetString(AES.Decrypt(bytes, key)); } if (cbHex16.Checked) { byte[] bytes = FormatString.Hex_16To2(entryStr); txtDecrypt.Text = Encoding.Default.GetString(AES.Decrypt(bytes, key)); } } catch (Exception ex) { txtDecrypt.Text = ex.Message; } } }
private void button1_Click(object sender, EventArgs e) { if (CheckTextBox()) { var entryStr = txtEncryptStr.Text; string key = txtKey.Text; try { if (cbBase64.Checked) { //返回加密后的base64密文 byte[] bytes = DES.Encrypt(entryStr, key); txtDecryptStr.Text = FormatString.ToBase64String(bytes); } if (cbHex16.Checked) { //返回加密后的16进制密文 byte[] bytes = DES.Encrypt(entryStr, key); txtDecryptStr.Text = FormatString.Hex_2To16(bytes); } } catch (Exception ex) { txtDecryptStr.Text = ex.Message; } } }
} // buttonOk_Click_Implementation #endregion #region 'General' form setup & get data private void InitGeneralData() { // service logo var serviceLogo = AppUiConfiguration.Current.ServiceLogoMappings.FromServiceKey(Task.Channel.ServiceKey); pictureChannelLogo.Image = serviceLogo.GetImage(LogoSize.Size64); // service name labelChannelName.Text = string.Format("{0} {1}", Task.Channel.LogicalNumber, Task.Channel.Name); // program name if (Task.Program != null) { labelProgramDescription.Text = Task.Program.Title; labelProgramSchedule.Text = string.Format("{0} ({1})", FormatString.DateTimeFromToMinutes(Task.Program.LocalStartTime, Task.Program.LocalEndTime, LocalReferenceTime), FormatString.TimeSpanTotalMinutes(Task.Program.Duration, FormatString.Format.Extended)); } else { labelChannelName.Top = pictureChannelLogo.Top; labelChannelName.Height = pictureChannelLogo.Height; labelProgramDescription.Visible = false; labelProgramSchedule.Visible = false; } // if-else } // InitGeneralData
/// <inheritdoc /> public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var formatter = values[0] as INumericFormatter; if (formatter == null) { return("first argument must be a IQuantityFormatter"); } var row = values[0] as Row; if (row == null) { return("first argument must be a Row"); } var oldValueStringFormat = row.OldValueStringFormat; if (!string.IsNullOrEmpty(oldValueStringFormat) && FormatString.IsValidFormat(oldValueStringFormat, out var numberOfArguments, out var anyItemHasFormat)) { if (numberOfArguments == 1 && anyItemHasFormat == false) { var formattedValue = formatter.Format(row.OldValue as IFormattable); return(string.Format(row.OldValueStringFormat, formattedValue)); } return(string.Format(NumericBox.GetCulture(row), oldValueStringFormat, row.OldValue)); } return(oldValueStringFormat); }
public PluralFormatString(FormatString defaultFormat, params FormatString [] pluralFormats) { this.defaultFormat = defaultFormat; this.pluralFormats = pluralFormats; SetDefaultArguments(defaultFormat, pluralFormats); }
protected override T?ConvertTextToValue(string text) { T?result = null; if (String.IsNullOrEmpty(text)) { return(result); } // Since the conversion from Value to text using a FormartString may not be parsable, // we verify that the already existing text is not the exact same value. string currentValueText = ConvertValueToText(); if (object.Equals(currentValueText, text)) { return(this.Value); } //Don't know why someone would format a T as %, but just in case they do. result = FormatString.Contains("P") ? _fromDecimal(ParsePercent(text, CultureInfo)) : _fromText(text, this.ParsingNumberStyle, CultureInfo); if (this.ClipValueToMinMax) { return(this.GetClippedMinMaxValue()); } ValidateDefaultMinMax(result); return(result); }
public void Parse_StroresInnerFormatStringLocationCorrectly(string input, int expectedStart, int expectedEnd) { FormatString ast = Helpers.CreateParser(input).Parse(); Location location = ((SimpleFormat)ast.Items[0]).FormatString.Location; Assert.That(location, Is.EqualTo(new Location(expectedStart, expectedEnd))); }
public async Task <ContextObject> GetValue(ContextObject context, ScopeData scopeData) { await Task.CompletedTask; var c = await context.GetContextForPath(Value, scopeData); if (FormatString != null && FormatString.Any()) { var argList = new List <KeyValuePair <string, object> >(); foreach (var formatterArgument in FormatString) { var value = context.FindNextNaturalContextObject().Clone(); value = await formatterArgument.Item2.GetValue(value, scopeData); if (value == null) { argList.Add(new KeyValuePair <string, object>(formatterArgument.Item1.ArgumentName, null)); } else { await value.EnsureValue(); argList.Add(new KeyValuePair <string, object>(formatterArgument.Item1.ArgumentName, value.Value)); } } //we do NOT await the task here. We await the task only if we need the value context.Value = c.Format(argList.ToArray()); } else { context.Value = c.Format(new KeyValuePair <string, object> [0]); } return(context); }
private void btnDecrypt_Click(object sender, EventArgs e) { if (CheckTextBox()) { string key = txtKey.Text; try { if (cbBase64.Checked) { //将base64转成byte后再解密 byte[] entryBytes = FormatString.FromBase64String(txtEncrypt.Text); byte[] bytes = DES.Decrypt(entryBytes, key); txtDecrypt.Text = Encoding.Default.GetString(bytes); } if (cbHex16.Checked) { //将16进制转成2进制后再解密 byte[] entryBytes = FormatString.Hex_16To2(txtEncrypt.Text); byte[] bytes = DES.Decrypt(entryBytes, key); txtDecrypt.Text = Encoding.Default.GetString(bytes); } } catch (Exception ex) { txtDecrypt.Text = ex.Message; } } }
} // constructor public void DisplayData(UiBroadcastService service, EpgProgram epgProgram, DateTime referenceTime, string caption) { Service = service; EpgProgram = epgProgram; labelProgramCaption.Text = caption; labelProgramCaption.Visible = caption != null; labelProgramTime.Visible = (epgProgram != null); labelProgramDetails.Visible = (epgProgram != null); pictureProgramThumbnail.ImageLocation = null; buttonProgramProperties.Visible = (epgProgram != null); pictureProgramThumbnail.Cursor = (epgProgram != null) ? Cursors.Hand : Cursors.Default; if (EpgProgram == null) { labelProgramTitle.Text = Properties.Texts.EpgNoInformation; pictureProgramThumbnail.Image = Properties.Resources.EpgNoProgramImage; } else { labelProgramTitle.Text = EpgProgram.Title; labelProgramTime.Text = string.Format("{0} ({1})", FormatString.DateTimeFromToMinutes(EpgProgram.LocalStartTime, EpgProgram.LocalEndTime, referenceTime), FormatString.TimeSpanTotalMinutes(EpgProgram.Duration, FormatString.Format.Extended)); labelProgramDetails.Text = string.Format("{0} / {1}", (EpgProgram.Genre != null) ? EpgProgram.Genre.Description : Properties.Texts.EpgNoGenre, (EpgProgram.ParentalRating != null) ? EpgProgram.ParentalRating.Description : Properties.Texts.EpgNoParentalRating); pictureProgramThumbnail.Image = Properties.Resources.EpgLoadingProgramImage; pictureProgramThumbnail.ImageLocation = null; // TODO: EPG // pictureProgramThumbnail.ImageLocation = IpTvProvider.Current.EpgInfo.GetEpgProgramThumbnailUrl(service, EpgProgram, false); } // if-else } // DisplayData
private void btnEncrypt_Click(object sender, EventArgs e) { if (CheckTextBox()) { string entryStr = txtEncrypt.Text; string key = txtKey.Text; try { if (cbBase64.Checked) { byte[] bytes = AES.Encrypt(entryStr, key); txtDecrypt.Text = FormatString.ToBase64String(bytes); } if (cbHex16.Checked) { byte[] bytes = AES.Encrypt(entryStr, key); txtDecrypt.Text = FormatString.Hex_2To16(bytes); } } catch (Exception ex) { txtDecrypt.Text = ex.Message; } } }
/// <summary> /// The Initialize. /// </summary> private void Initialize(DownloadItem downloadItem) { this.FileSize = FormatString.FormatFileSize(downloadItem.TotalBytes); this.Title = downloadItem.SuggestedFileName; this.Url = downloadItem.OriginalUrl; this.UpdateInfo(downloadItem); }
public void EscapedArgument() { Assert.True(FormatString.TryParse("{{{0}}}", out var expressions)); Assert.Equal(3, expressions.Length); Assert.Equal("{", expressions[0].String); Assert.Equal(0, expressions[1].Argument); Assert.Equal("}", expressions[2].String); }
public override string ToString() { if (FormatString != null && FormatString.Any()) { return($"{Type} \"{Value}\" AS ({FormatString.Select(e => e.ToString()).Aggregate((e, f) => e + "," + f)})"); } return($"{Type} {Value}"); }
public void DanglingOpenBracket() { Assert.True(FormatString.TryParse("{0} {", out var expressions)); Assert.Equal(3, expressions.Length); Assert.Equal(0, expressions[0].Argument); Assert.Equal(" ", expressions[1].String); Assert.Equal("{", expressions[2].String); }
public override void DataBind() { base.DataBind(); Text = EditUpdateButton.DataBindValue(this); if (FormatString.HasValue()) { Text = FormatString.Fmt(Text); } }
static string ConvertToSentenceCase(string strParagraph) { FormatString format = RemoveSpace; string formatted = RemoveSpace(strParagraph); FormatString split = Split; var finalString = Split(formatted); return(finalString); }
// (NH4)2SO4 // 000101001 public void TestFormat_Groups() { FormatHelper fh = new FormatHelper(); FormatString actual = fh.FormatInput("(NH4)2SO4"); FormatString expected = new FormatString("(NH4)2SO4", new int[] { 0, 0, 0, 1, 0, 1, 0, 0, 1 }); Assert.AreEqual(expected, actual); }
public void TestFormat_Groups2() { FormatHelper fh = new FormatHelper(); FormatString actual = fh.FormatInput("Co3(Fe(CN)6)2"); FormatString expected = new FormatString("Co3(Fe(CN)6)2", "0010000000101"); Assert.AreEqual(expected, actual); }
public void TestFormat_Groups() { FormatHelper fh = new FormatHelper(); FormatString actual = fh.FormatInput("(NH4)2SO4"); FormatString expected = new FormatString("(NH4)2SO4", new int[] { 0,0,0,1,0,1,0,0,1 }); Assert.AreEqual(expected, actual); }
public void TestFormat_ChargeOnly() { FormatHelper fh = new FormatHelper(); FormatString actual = fh.FormatInput("H+"); FormatString expected = new FormatString("H+", new int[] { 0, 2 }); Assert.AreEqual(expected, actual); }
public void TestFormat_Charge() { FormatHelper fh = new FormatHelper(); FormatString actual = fh.FormatInput("PO4-3"); FormatString expected = new FormatString("PO43-", new int[] { 0, 0, 1, 2, 2 }); Assert.AreEqual(expected, actual); }
public void TestFormat_QuantitiesOnly() { FormatHelper fh = new FormatHelper(); FormatString actual = fh.FormatInput("H2SO4"); FormatString expected = new FormatString("H2SO4", new int[] { 0, 1, 0, 0, 1 }); Assert.AreEqual(expected, actual); }
public override void Run(string[] input) { Thread thread = new Thread(() => Clipboard.SetText(FormatString.InsertArguments(input))); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); MainWindow.GetInstance().HideWindow(); }
public void IsValidFormatWithOutParams(string text, bool expected, int expectedIndex, bool?expectedFormat) { int count; bool?anyItemHasFormat; Assert.AreEqual(expected, FormatString.IsValidFormat(text, out count, out anyItemHasFormat)); Assert.AreEqual(expectedIndex, count); Assert.AreEqual(expectedFormat, anyItemHasFormat); }
private int m_iCacheLine = 0; //Simple字符串起始行 public ScriptLexer(string buffer, string breviary) { Breviary = breviary == null || breviary.Length == 0 ? buffer.Substring(0, Math.Min(BREVIARY_CHAR, buffer.Length)) : breviary; m_FormatString = FormatString.None; m_strBuffer = buffer; m_iLength = buffer.Length; m_Builder = new StringBuilder(); m_listTokens = new List <Token>(); }
public static void ParseReturnsTheCorrectFormatString(string format, params string [] expectedArgumentHoles) { var formatString = FormatString.Parse(format); var argumentHoles = formatString.ArgumentHoles .Select(argumentHole => argumentHole.ToString( )) .ToArray( ); Assert.Equal(expectedArgumentHoles, argumentHoles); }
} // DisplayEpgPrograms private void DisplayEpgProgram(int index) { TimeSpan ellapsed; if ((index < 0) || (index > 3)) { return; } EpgIndex = index; epgProgressBar.Visible = (index == 1); labelEndTime.Visible = (index == 1); labelStartTime.Visible = (index == 1); labelFromTo.Visible = (index != 1); var epgProgram = EpgPrograms?[EpgIndex]; buttonDetails.Enabled = DetailsEnabled && (epgProgram != null) && (!epgProgram.IsBlank); labelProgramTitle.Text = (epgProgram != null) ? epgProgram.Title : Properties.Texts.EpgNoInformation; if (epgProgram == null) { labelFromTo.Text = null; labelStartTime.Text = null; labelEllapsed.Text = null; EnableBackForward(false, false); return; } // if switch (EpgIndex) { case 0: labelFromTo.Text = FormatString.DateTimeFromToMinutes(epgProgram.LocalStartTime, epgProgram.LocalEndTime, LocalReferenceTime); ellapsed = (LocalReferenceTime - epgProgram.LocalEndTime); labelEllapsed.Text = string.Format(Properties.Texts.ProgramEnded, FormatString.TimeSpanTotalMinutes(ellapsed, FormatString.Format.Extended)); EnableBackForward(false, EpgPrograms[1] != null); break; case 1: labelStartTime.Text = string.Format("{0:HH:mm}", epgProgram.LocalStartTime); labelEndTime.Text = string.Format("{0:t}", epgProgram.LocalEndTime); ellapsed = (LocalReferenceTime - epgProgram.LocalStartTime); epgProgressBar.MaximumValue = epgProgram.Duration.TotalMinutes; epgProgressBar.Value = ellapsed.TotalMinutes; labelEllapsed.Text = string.Format(Properties.Texts.ProgramStarted, FormatString.TimeSpanTotalMinutes(ellapsed, FormatString.Format.Extended)); EnableBackForward(EpgPrograms[0] != null, EpgPrograms[2] != null); break; default: labelFromTo.Text = FormatString.DateTimeFromToMinutes(epgProgram.LocalStartTime, epgProgram.LocalEndTime, LocalReferenceTime); ellapsed = (epgProgram.LocalStartTime - LocalReferenceTime); labelEllapsed.Text = string.Format(Properties.Texts.ProgramWillStart, FormatString.TimeSpanTotalMinutes(ellapsed, FormatString.Format.Extended)); EnableBackForward(SafeGetItem(EpgPrograms, EpgIndex - 1) != null, SafeGetItem(EpgPrograms, EpgIndex + 1) != null); break; } // switch } // DisplayEpgProgram
/// <summary> /// Converts the value to formatted text. /// </summary> /// <returns></returns> private string ConvertValueToText() { //Manage FormatString of type "{}{0:N2} °" (in xaml) or "{0:N2} °" in code-behind. if (FormatString.Contains("{0")) { return(string.Format(CultureInfo, FormatString, Value)); } return(Value.ToString(FormatString, CultureInfo)); }
public void MultipleArguments() { Assert.True(FormatString.TryParse("{1} {0}{2} ", out var expressions)); Assert.Equal(5, expressions.Length); Assert.Equal(1, expressions[0].Argument); Assert.Equal(" ", expressions[1].String); Assert.Equal(0, expressions[2].Argument); Assert.Equal(2, expressions[3].Argument); Assert.Equal(" ", expressions[4].String); }
private static int FormatCompounds(string input, FormatString result, int textPointer = 0) { Regex findCompondsAndGroups = new Regex("([A-Z][a-z]?\\d*)|(\\([^()]*(?:\\(.*\\))?[^()]*\\)\\d+)"); MatchCollection matches = findCompondsAndGroups.Matches(input); foreach (Match m2 in matches) { if (m2.Groups[1].Success) //Compound { foreach (char c in m2.Groups[1].Value.ToCharArray()) { if (Char.IsNumber(c)) result.SetFlagAt(textPointer, FormatFlags.Subscript); textPointer++; } } else if (m2.Groups[2].Success) //Group { Regex extractQtyFromInnerText = new Regex("\\((.*)\\)(\\d*)"); Match m3 = extractQtyFromInnerText.Match(m2.Groups[2].Value); string innerText = m3.Groups[1].Value; string qty = ""; if(m3.Groups[2].Success) qty = m3.Groups[2].Value; textPointer++; //to skip "(" textPointer = FormatCompounds(innerText, result, textPointer); textPointer++; //to skip ")" for (int i = 0; i < qty.Length; i++) { result.SetFlagAt(textPointer, FormatFlags.Subscript); textPointer++; } } } return textPointer; }
public FormatString FormatInput(string input) { Regex checkCharge = new Regex("^([^\\+\\- ]*)(\\+\\d?|\\-\\d?)?"); Match m = checkCharge.Match(input); string rawFormula = m.Groups[1].Value; int rawFormulaLength = m.Groups[1].Value.Length; int chargeLength = 0; if(m.Groups[2].Success) chargeLength = m.Groups[2].Value.Length; FormatString result = new FormatString(input); if (chargeLength > 0) result.SetFlagAt(rawFormulaLength, chargeLength, FormatFlags.Superscript); FormatCompounds(rawFormula, result); Regex swapCharge = new Regex("^([^\\+\\- ]*)(([\\+\\-])(\\d))?"); string newContent = swapCharge.Replace(result.Content, "$1$4$3"); return new FormatString(newContent, result.FormatMask); }
public Case(Location location, Expression condition, FormatString formatString) : base(location) { Condition = Utilities.ThrowIfNull(condition, "condition"); FormatString = Utilities.ThrowIfNull(formatString, "formatString"); }