public StoredInfo DocumentToStoredInfo (Document doc) { int count = 0; StoredInfo info = new StoredInfo (); info.Uri = GetUriFromDocument (doc); foreach (Field f in doc.Fields ()) { Property prop = GetPropertyFromDocument (f, doc, false); if (prop == null) continue; switch (prop.Key) { case "fixme:indexDateTime": info.LastIndex = StringFu.StringToDateTime (prop.Value); count++; break; case "fixme:fullyIndexed": info.FullyIndexed = Convert.ToBoolean (prop.Value); count++; break; } if (count == 2) break; } return info; }
private void Start() { Console.TreatControlCAsInput = true; StoredInfo stored = new StoredInfo(); ConsoleKeyInfo key; while (!stored.Close) { Console.WriteLine("Press Escape to exit the program\n\n"); Console.WriteLine($"menu index: {stored.Menus.Count - 1}\n0) Previous Menu\n"); stored.CurrentMenu.Show(); key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.Escape: return; case ConsoleKey.D0: stored.GotoPreviousMenu(); break; default: stored.CurrentMenu.Action(key, stored); break; } Console.Clear(); } }
public void Action(ConsoleKeyInfo key, StoredInfo stored) { switch (key.Key) { case ConsoleKey.D1: stored.SetCurrentMenu(new StoreMenu()); break; } }
public void Action(ConsoleKeyInfo key, StoredInfo stored) { switch (key.Key) { case ConsoleKey.D1: stored.TotalCost += 1.30; Console.Clear(); Console.WriteLine("Bought 1 pack of gum\n\npress any key to continue..."); Console.ReadKey(true); break; } }
/// <summary> /// 添加Job信息 /// </summary> /// <param name="entity"></param> /// <returns></returns> public virtual async Task <long> InsertAndGetId(StoredInfo <long> entity) { return(await this.ExecuteAsync(async conn => { var store = new RetryStore { CreationTime = DateTime.Now, ExecutedNumber = entity.ExecutedNumber, JobStatus = entity.JobStatus, JobTypeName = this.GetTypeName(entity.JobType), LastModificationTime = DateTime.Now, PreviousFireTime = entity.PreviousFireTimeUtc.HasValue ? entity.PreviousFireTimeUtc.Value.LocalDateTime : DateTime.Now, DeathTime = entity.DeathTimeUtc.HasValue ? entity.DeathTimeUtc.Value.LocalDateTime : DateTime.MaxValue, UsedRuleName = entity.UsedRuleName ?? string.Empty, }; using (var trans = conn.BeginTransaction()) { try { var retryId = await conn.ExecuteScalarAsync <long>(this.InsertAndGetIdSqlWithRetryStore, store, trans).ConfigureAwait(false); if (retryId > 0) { var datas = this.Serializer(retryId, entity.JobMap); if (datas != null && datas.Any()) { if (await conn.ExecuteAsync(this.InsertSqlWithRetryStoreData, datas, trans).ConfigureAwait(false) == 0) { throw new Exception("Insert Fail"); } } trans.Commit(); return retryId; } throw new Exception("Insert Fail"); } catch { trans.Rollback(); throw; } } }).ConfigureAwait(false)); }
public StoredInfo GetStoredInfo(Uri uri) { StoredInfo info = new StoredInfo(); LNS.Query query = UriQuery("Uri", uri); SingletonCollector collector = new SingletonCollector(); LNS.IndexSearcher searcher = LuceneCommon.GetSearcher(PrimaryStore); searcher.Search(query, null, collector); if (collector.MatchId != -1) { Document doc = searcher.Doc(collector.MatchId); info = DocumentToStoredInfo(doc); } LuceneCommon.ReleaseSearcher(searcher); return(info); }
public StoredInfo DocumentToStoredInfo(Document doc) { int count = 0; StoredInfo info = new StoredInfo(); info.Uri = GetUriFromDocument(doc); foreach (Field f in doc.Fields()) { Property prop = GetPropertyFromDocument(f, doc, false); if (prop == null) { continue; } switch (prop.Key) { case "fixme:indexDateTime": info.LastIndex = StringFu.StringToDateTime(prop.Value); count++; break; case "fixme:fullyIndexed": info.FullyIndexed = Convert.ToBoolean(prop.Value); count++; break; } if (count == 2) { break; } } return(info); }
public Hashtable GetStoredUriStrings(string server, string file) { Hashtable uris = new Hashtable(); Term term = new Term(PropertyToFieldName(PropertyType.Keyword, "fixme:file"), file); LNS.QueryFilter filter = new LNS.QueryFilter(new LNS.TermQuery(term)); term = new Term(PropertyToFieldName(PropertyType.Keyword, "fixme:account"), server); LNS.TermQuery query = new LNS.TermQuery(term); LNS.IndexSearcher searcher = LuceneCommon.GetSearcher(PrimaryStore); LNS.Hits hits = searcher.Search(query, filter); for (int i = 0; i < hits.Length(); i++) { StoredInfo info = DocumentToStoredInfo(hits.Doc(i)); uris.Add(info.Uri.ToString(), info.FullyIndexed); } LuceneCommon.ReleaseSearcher(searcher); return(uris); }
public void Action(ConsoleKeyInfo key, StoredInfo stored) { switch (key.Key) { case ConsoleKey.D0: Console.Clear(); Console.WriteLine($"Your total is {stored.TotalCost.ToString("C")}"); Console.ReadKey(true); stored.Close = true; break; case ConsoleKey.D1: stored.SetCurrentMenu(new BuyMenu()); break; case ConsoleKey.D2: Console.Clear(); Console.Write("Enter Discount Amount: "); if (double.TryParse(Console.ReadLine(), out var discount)) { stored.TotalCost -= stored.TotalCost * discount; Console.WriteLine("\nNew total is " + stored.TotalCost); } else { Console.WriteLine("\nYou must enter a valid discount value"); } Console.ReadKey(true); break; case ConsoleKey.D3: Console.WriteLine($"Current Cost: {stored.TotalCost.ToString("C")}"); Console.ReadKey(true); break; } }
protected override void ProcessRecord() { try { string preselectedPrincipalAndRoleARN = null; NetworkCredential networkCredential = null; if (this.Credential != null) { base.WriteVerbose(Lang.UseGivenNetworkCredentials); networkCredential = this.Credential.GetNetworkCredential(); } bool hasPrinARN = this.ParameterWasBound(nameof(PrincipalARN)) && !string.IsNullOrWhiteSpace(this.PrincipalARN); bool hasRoleARN = this.ParameterWasBound(nameof(RoleARN)) && !string.IsNullOrWhiteSpace(this.RoleARN); if (hasPrinARN != hasRoleARN) { this.ThrowExecutionError(Lang.PrincipalRequiredWithRole, this); } if (hasPrinARN & hasRoleARN) { preselectedPrincipalAndRoleARN = $"{this.RoleARN},{this.PrincipalARN}"; } ServicePointManager.SecurityProtocol = this.SecurityProtocol; IbmIam2AwsSamlScreenScrape ibm2Aws = new IbmIam2AwsSamlScreenScrape(this) { ErrorClass = this.ErrorClass, ErrorElement = this.ErrorElement, Proxy = this.GetWebProxy(), Credentials = networkCredential, Logger = (m, t) => { switch (t) { case LogType.Debug: this.WriteVerbose(m); break; case LogType.Info: this.Host.UI.WriteLine(m); //_cmdlet.WriteInformation(new InformationRecord(m, "")); break; case LogType.Warning: this.WriteWarning(m); break; case LogType.Error: this.WriteError(new ErrorRecord(new Exception(m), "5000", ErrorCategory.NotSpecified, this)); break; } } }; var assertion = ibm2Aws.RetrieveSAMLAssertion(IbmIamEndpoint); var roles = ibm2Aws.GetRolesFromAssertion(); if (this.StoreAllRoles) { if (AwsAccountId != null && AwsAccountId.Length > 0) { roles = roles.Where(r => AwsAccountId.Contains(r.PrincipalArn.AccountId, StringComparer.OrdinalIgnoreCase)).ToArray(); } foreach (var role in roles) { this.WriteVerbose($"Getting [{role.PrincipalArn}] tokens using [{role.RoleArn}]"); try { var aRole = this.ExecuteCmdletInPipeline <dynamic>("Use-STSRoleWithSAML", new { SAMLAssertion = ibm2Aws.Assertion, RoleArn = role.RoleArn.OriginalString, PrincipalArn = role.PrincipalArn.OriginalString, DurationInSeconds = 60 * this.TokenDurationInMinutes }).FirstOrDefault(); this.WriteObject(new StoredInfo { AssertionDoc = assertion, Expires = aRole.Credentials.Expiration, PrincipalArn = role.PrincipalArn, RoleArn = role.RoleArn, StoreAs = this.StoreAs ?? role.RoleArn.Resource }); base.WriteVerbose($"Saving role '{role.Value}' to profile '{role.RoleArn.Resource}'."); var home = this.GetVariableValue("HOME") as string; _ = this.ExecuteCmdletInPipeline("Set-AWSCredential", new { ProfileLocation = Path.Combine(home, ".aws", "credentials"), AccessKey = aRole.Credentials.AccessKeyId, SecretKey = aRole.Credentials.SecretAccessKey, aRole.Credentials.SessionToken, StoreAs = role.RoleArn.Resource }); } //catch (ExpiredTokenException ex) //{ // this.WriteVerbose($"Could not Assume Role: {role.RoleArn.Resource}"); // this.WriteVerbose("Attempting to Refresh Token"); // // Updating Assertion Document // sAMLAssertion = _awsAuthController.GetSAMLAssertion(endpoint.EndpointUri.ToString(), networkCredential, endpoint.AuthenticationType.ToString()); // this.WriteVerbose("Retrying this operation"); // creds = AssumeRole(sts, config, role.RoleArn.Resource, sAMLAssertion, role, this.TokenDurationInMinutes); // this.WriteVerbose($"RetryResult: {creds}"); //} catch (Exception ex) { this.WriteError(new ErrorRecord(ex, "5000", ErrorCategory.NotSpecified, this)); } } } else { StoredInfo sendToPipeline = this.SelectAndStoreProfileForRole(assertion, roles, preselectedPrincipalAndRoleARN); base.WriteObject(sendToPipeline); } } catch (IbmIamErrorException ex) { base.WriteError(new ErrorRecord(ex, ex.ErrorCode, ErrorCategory.NotSpecified, this)); } catch (IbmIamPasswordExpiredException ex) { base.WriteError(new ErrorRecord(ex, "PasswordExpired", ErrorCategory.AuthenticationError, this)); } catch (Exception ex) { base.WriteError(new ErrorRecord(new ArgumentException("Unable to set credentials: " + ex.Message, ex), "ArgumentException", ErrorCategory.InvalidArgument, this)); } }
public static StoredInfo loadOrGetDataSet(string name, ImageTracker QCARImageTracker) { StoredInfo info = null; if (LoadedDataSets.TryGetValue(name, out info)) { return info; } else { DataSet dataSet = QCARImageTracker.CreateDataSet(); if (!DataSet.Exists(name) || !dataSet.Load(name)) return null; else { info = new StoredInfo(name, dataSet); LoadedDataSets.Add(name, info); return info; } } }
public StoredInfo GetStoredInfo (Uri uri) { StoredInfo info = new StoredInfo (); LNS.Query query = UriQuery ("Uri", uri); SingletonCollector collector = new SingletonCollector (); LNS.IndexSearcher searcher = LuceneCommon.GetSearcher (PrimaryStore); searcher.Search (query, null, collector); if (collector.MatchId != -1) { Document doc = searcher.Doc (collector.MatchId); info = DocumentToStoredInfo (doc); } LuceneCommon.ReleaseSearcher (searcher); return info; }
} //Time of storing the information #endregion public override string ToString() { return(" " + StoredInfo.ToString() + " at " + StoringTime.ToString() + "\n"); }