protected override void ExecuteCmdlet() { string[] lines; if (ParameterSetName == "File") { if (!System.IO.Path.IsPathRooted(Path)) { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); } lines = File.ReadAllLines(Path); } else { lines = Terms; } lines = lines.Where(line => !string.IsNullOrWhiteSpace(line)).ToArray(); if (!string.IsNullOrEmpty(TermStoreName)) { var taxSession = TaxonomySession.GetTaxonomySession(ClientContext); var termStore = taxSession.TermStores.GetByName(TermStoreName); ClientContext.Site.ImportTerms(lines, Lcid, termStore, Delimiter, SynchronizeDeletions); } else { ClientContext.Site.ImportTerms(lines, Lcid, Delimiter, SynchronizeDeletions); } }
public void Start() { if (File.Exists("playersToNotify.txt")) { try { var lines = File.ReadAllLines("playersToNotify.txt").Select(x => { if (long.TryParse(x, out var id)) { return((long?)id); } return(null); }); foreach (var line in lines.Where(x => x.HasValue).Cast <long>()) { _playersToNotify.Add(line); } } catch (Exception e) { Console.WriteLine(e); } } var key = File.ReadAllText("botkey.key"); _botClient = new TelegramBotClient(key); _botClient.OnMessage += Bot_OnMessage; _botClient.StartReceiving(); }
public static InflectionProcess[] FromFile(string path) { var lines = File.ReadAllLines(path).Where(line => !line.StartsWith("#")); var columns = lines.Select(line => line.Split('\t')); return(columns.Select(line => new InflectionProcess(line[0], line[1])).ToArray()); }
public void Start(CancellationToken cancellationToken) { botClient.StartReceiving(cancellationToken: cancellationToken); if (File.Exists(CHATS_FILE_NAME)) { _logger.LogInformation("Adding chats"); chatIds.AddRange(File.ReadAllLines(CHATS_FILE_NAME).Select(c => long.Parse(c))); } }
private static Dictionary <string, string> LoadData(string path) { if (File.Exists(path)) { return(File.ReadAllLines(path) .Select(ParseLine) .Where(dataLine => dataLine != null) .ToDictionary(dataLine => dataLine.Value.key, dataLine => dataLine.Value.value)); } return(new Dictionary <string, string> { { "LastMsgId", "0" } }); }
static Inflection() { Inflections = InflectionProcess.FromFile(DataFiles.PathTo("Inflections", "Regular nouns")); foreach (var entry in File.ReadAllLines(DataFiles.PathTo("Inflections", "Irregular nouns"))) { var split = entry.Split('\t'); var singular = split[0]; var plural = split[1]; IrregularPlurals[singular] = plural; IrregularSingulars[plural] = singular; } IrregularVerbs = new Spreadsheet(DataFiles.PathTo( "Inflections", "Irregular verbs", ".csv"), "Base form"); }
} //Format static void CreateTemplate(out StringList before, out StringList after) { var templateFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), DefinitionSet.templateFile); string[] templateLines = File.ReadAllLines(templateFileName); before = new StringList(); after = new StringList(); var activeList = before; foreach (var line in templateLines) { if (line.Contains(DefinitionSet.templatePlaceholder)) { activeList = after; } else { activeList.Add(line); } } } //CreateTemplate
protected override void ExecuteCmdlet() { string[] lines; if (ParameterSetName == "File") { lines = File.ReadAllLines(Path); } else { lines = Terms; } if (!string.IsNullOrEmpty(TermStoreName)) { var taxSession = TaxonomySession.GetTaxonomySession(ClientContext); var termStore = taxSession.TermStores.GetByName(TermStoreName); ClientContext.Site.ImportTerms(lines, Lcid, termStore, Delimiter, SynchronizeDeletions); } else { ClientContext.Site.ImportTerms(lines, Lcid, Delimiter, SynchronizeDeletions); } }
public SavedSettings() { _savedChatIds = new List <long>(); _savedAdmins = new List <string> { "diverofdark" }; try { var text = File.ReadAllText("/data/chats.bot"); _savedChatIds = text.Split(" ").Select(long.Parse).ToList(); } catch (Exception ex) { } try { var admins = File.ReadAllLines("/data/admins.bot"); _savedAdmins = admins.Select(v => v.Trim()).ToList(); } catch (Exception ex) { } }
public DeviceShopController() { var deviceDataFile = FileInput.ReadAllLines(@"D:\Projects\learn_csharp\Shoping\Devices.txt"); _deviceShop = new DeviceShop(deviceDataFile); }
public string[] FileLines(string path) { return(SysFiles.Exists(path) ? SysFiles.ReadAllLines(path) : _empty); }
/** Load a vocab file {@code <vocabName>.tokens} and return mapping. */ public virtual IDictionary <string, int> Load() { IDictionary <string, int> tokens = new LinkedHashMap <string, int>(); int maxTokenType = -1; string fullFile = GetImportedVocabFile(); AntlrTool tool = g.tool; string vocabName = g.GetOptionString("tokenVocab"); try { Regex tokenDefPattern = new Regex("([^\n]+?)[ \\t]*?=[ \\t]*?([0-9]+)"); string[] lines; if (tool.grammarEncoding != null) { lines = File.ReadAllLines(fullFile, Encoding.GetEncoding(tool.grammarEncoding)); } else { lines = File.ReadAllLines(fullFile); } for (int i = 0; i < lines.Length; i++) { string tokenDef = lines[i]; int lineNum = i + 1; Match matcher = tokenDefPattern.Match(tokenDef); if (matcher.Success) { string tokenID = matcher.Groups[1].Value; string tokenTypeS = matcher.Groups[2].Value; int tokenType; if (!int.TryParse(tokenTypeS, out tokenType)) { tool.errMgr.ToolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION, " bad token type: " + tokenTypeS, lineNum); tokenType = TokenTypes.Invalid; } tool.Log("grammar", "import " + tokenID + "=" + tokenType); tokens[tokenID] = tokenType; maxTokenType = Math.Max(maxTokenType, tokenType); lineNum++; } else { if (tokenDef.Length > 0) // ignore blank lines { tool.errMgr.ToolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION, " bad token def: " + tokenDef, lineNum); } } } } catch (FileNotFoundException) { GrammarAST inTree = g.ast.GetOptionAST("tokenVocab"); string inTreeValue = inTree.Token.Text; if (vocabName.Equals(inTreeValue)) { tool.errMgr.GrammarError(ErrorType.CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR, g.fileName, inTree.Token, fullFile); } else // must be from -D option on cmd-line not token in tree { tool.errMgr.ToolError(ErrorType.CANNOT_FIND_TOKENS_FILE_GIVEN_ON_CMDLINE, fullFile, g.name); } } catch (Exception e) { tool.errMgr.ToolError(ErrorType.ERROR_READING_TOKENS_FILE, e, fullFile, e.Message); } return(tokens); }
protected override void BuildBody(StringBuilder page, PaymentRequest paymentRequest) { // create client string apiKey = paymentRequest.PaymentMethod.DynamicProperty <string>().PublicKey; string apiSecret = paymentRequest.PaymentMethod.DynamicProperty <string>().SecretKey; string acceptUrl = paymentRequest.PaymentMethod.DynamicProperty <string>().AcceptUrl; var client = new StripeClient(apiSecret); var paymentIntentService = new PaymentIntentService(client); var createIntent = new PaymentIntentCreateOptions() { Currency = paymentRequest.Amount.CurrencyIsoCode, Amount = Convert.ToInt64(paymentRequest.Amount.Value * 100) }; var paymentIntent = paymentIntentService.Create(createIntent); string paymentFormTemplate = paymentRequest.PaymentMethod.DynamicProperty <string>().PaymentFormTemplate; var allLines = File.ReadAllLines(HttpContext.Current.Server.MapPath(paymentFormTemplate)); foreach (var line in allLines) { page.AppendLine(line); } var billingDetails = new ChargeBillingDetails() { Name = $"{paymentRequest.PurchaseOrder.BillingAddress.FirstName} {paymentRequest.PurchaseOrder.BillingAddress.LastName}", Address = new s.Address() { Line1 = paymentRequest.PurchaseOrder.BillingAddress.Line1, Line2 = paymentRequest.PurchaseOrder.BillingAddress.Line2, City = paymentRequest.PurchaseOrder.BillingAddress.City, State = paymentRequest.PurchaseOrder.BillingAddress.State, PostalCode = paymentRequest.PurchaseOrder.BillingAddress.PostalCode, Country = paymentRequest.PurchaseOrder.BillingAddress.Country.TwoLetterISORegionName } }; page.Replace("##STRIPE:PUBLICKEY##", apiKey); page.Replace("##STRIPE:PAYMENTINTENT##", JsonConvert.SerializeObject(paymentIntent)); page.Replace("##STRIPE:BILLINGDETAILS##", JsonConvert.SerializeObject(billingDetails)); page.Replace("##PROCESSURL##", $"/{paymentRequest.PaymentMethod.PaymentMethodId}/{paymentRequest.Payment["paymentGuid"]}/PaymentProcessor.axd"); page.Replace("##ACCEPTURL##", acceptUrl); PaymentProperty paymentIntentProp; if (paymentRequest.Payment.PaymentProperties.Any(p => p.Key == PaymentIntentKey)) { var allProps = paymentRequest.Payment.PaymentProperties.Where(p => p.Key == PaymentIntentKey).ToList(); foreach (var prop in allProps) { paymentRequest.Payment.PaymentProperties.Remove(prop); } paymentRequest.Payment.Save(); } paymentIntentProp = new PaymentProperty() { Guid = Guid.NewGuid(), Key = PaymentIntentKey, Value = paymentIntent.Id }; paymentRequest.Payment.AddPaymentProperty(paymentIntentProp); paymentRequest.Payment.Save(); }
public IEnumerable <Build> GetBuilds() { var hostname = ConfigurationManager.AppSettings["teamcity-hostname"]; var username = ConfigurationManager.AppSettings["teamcity-username"]; var password = ConfigurationManager.AppSettings["teamcity-password"]; var ssl = bool.Parse(ConfigurationManager.AppSettings["teamcity-usessl"]); var client = new TeamCityClient(hostname, ssl); if (!string.IsNullOrEmpty(username)) { client.Connect(username, password); } else { client.ConnectAsGuest(); } var buildIdsSource = ConfigurationManager.AppSettings["buildids-source"]; var buildIds = string.IsNullOrEmpty(buildIdsSource) ? client.BuildConfigs.All().Select(s => s.Id) : File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + buildIdsSource).ToList(); foreach (var buildId in buildIds) { if (buildId.StartsWith("#")) { continue; } if (buildId.Trim() == "") { continue; } Build build; try { build = client.Builds.LastBuildByBuildConfigId(buildId); if (build == null) { continue; } build.BuildConfig = client.BuildConfigs.ByConfigurationId(buildId); } catch (Exception) { build = new Build { Status = "ERROR", BuildConfig = new BuildConfig { Project = new Project { Name = "Error" }, Name = $"Could not load build with id {buildId}" } }; } yield return(build); } }