/// <summary> /// Store ScopeName-ScopeId pair into database. /// To prevent duplication, do not add if the ScopeId already exists. /// </summary> /// <param name="db">An instance of <see cref="OnboardingDbContext"/>.</param> public static void AddOrUpdateScopes(OnboardingDbContext db) { Logger.Debug("Updating Scopes by retrieving from source depot..."); SystemHelpers.SyncDepot(); var xmlDoc = new XmlDocument(); xmlDoc.Load(Constants.RbacpolicyPath + Constants.ScopesFilename); var nameList = xmlDoc.GetElementsByTagName("DisplayName"); var idList = xmlDoc.GetElementsByTagName("ScopeId"); if (nameList != null) { for (var i = 0; i < nameList.Count; i++) { var entity = new Scope { ScopeName = nameList[i].InnerText, ScopeId = idList[i].InnerText }; if (db.Scopes.Any(e => e.ScopeId == entity.ScopeId)) { db.Scopes.Attach(entity); db.Entry(entity).State = EntityState.Modified; } else { db.Scopes.Add(entity); } } } var num = db.SaveChanges(); Logger.Debug(num + " Scopes have been updated in database"); }
private static void HandleCreated(OnboardingRequest request) { if (request.Type == RequestType.CreateSPT || request.Type == RequestType.UpdateSPT) { SystemHelpers.SaveXmlToDisk(request); SystemHelpers.AddFileToDepotAndPack(SystemHelpers.GenerateFilename(request)); // Create a code review. var codeFlowId = CodeFlowHelpers.CreateReview(_rClient, request.CreatedBy, MembershipCheckHelpers.GetName(request.CreatedBy), MembershipCheckHelpers.GetEmailAddress(request.CreatedBy), SystemHelpers.GenerateReivewName(request), Constants.ProjectShortName); // Assign ReviewId to the corresponding field in OnboardingRequest request.CodeFlowId = codeFlowId; // Create a code package and add it to the review CodeFlowHelpers.AddCodePackage(_rClient, request.CodeFlowId, CodeFlowHelpers.CreateCodePackage("testing pack", request.CreatedBy, request.CreatedBy, CodePackageFormat.SourceDepotPack, new Uri(Constants.DepotPath + SystemHelpers.GenerateFilename(request) + ".dpk"))); // Add reviewers to the review CodeFlowHelpers.AddReviewers(_rClient, request.CodeFlowId, new Reviewer[] { CodeFlowHelpers.CreateReviewer(request.CreatedBy, MembershipCheckHelpers.GetName(request.CreatedBy), MembershipCheckHelpers.GetEmailAddress(request.CreatedBy), true) }); // Publish the review CodeFlowHelpers.PublishReview(_rClient, request.CodeFlowId, "meesage from author"); Logger.Info("Code review with id [" + request.CodeFlowId + "] has been published"); // Change State from "Created" to "PendingReview" request.State = RequestState.PendingReview; Logger.Info("Change the state of request with id [" + request.RequestId + "] to [PendingReview]"); // Revert file to clean the changelist SystemHelpers.RevertFile(SystemHelpers.GenerateFilename(request)); } }
private Uri GenerateCallbackUri(string providerName, Uri basePath) { return(SystemHelpers.CreateCallBackUri(providerName, Request.Url, Url.RouteUrl(SimpleAuthenticationRouteConfig.CallbackRouteName), basePath)); }
private Uri GenerateCallbackUri(string providerName, Uri basePathOverride) { return(SystemHelpers.CreateCallBackUri(providerName, Request.Url, Request.Url.BasePath + CallbackRoute, basePathOverride)); }
//// public override void NetReceive(Item item, BinaryReader reader) { if (this.NeedsSaving(item)) { this.TimestampInSeconds = SystemHelpers.TimeStampInSeconds() - reader.ReadInt32(); } }
/// <summary> /// Store name-description pair into database. /// Change source xml to update description at request creation page. /// </summary> /// <param name="db">An instance of <see cref="OnboardingDbContext"/>.</param> public static void AddOrUpdateDescriptions(OnboardingDbContext db) { Logger.Debug("Updating descriptions by retrieving from source depot..."); SystemHelpers.SyncDepot(); var xmlDoc = new XmlDocument(); xmlDoc.Load(Constants.DescriptionFilePath); var list = xmlDoc.GetElementsByTagName("Descriptions")[0].ChildNodes; for (var i = 0; i < list.Count; i++) { var entity = new Description { Name = list[i].Name, Content = list[i].InnerText }; if (db.Descriptions.Any(e => e.Name == entity.Name)) { db.Descriptions.Attach(entity); db.Entry(entity).State = EntityState.Modified; } else { db.Descriptions.Add(entity); } } var num = db.SaveChanges(); Logger.Debug(num + " descriptions have been updated in database"); }
public override void NetSend(Item item, BinaryWriter writer) { if (this.NeedsSaving(item)) { writer.Write((Int32)SystemHelpers.TimeStampInSeconds() - this.TimestampInSeconds); } }
public void app_scanner_shall_find_some_well_known_applications(string appNamePartial) { var apps = SystemHelpers.GetInstalledApplications().ToArray(); var comparator = new StringContainsComparator(appNamePartial); apps.Select(app => app.Name).ShouldContain(s => comparator.IsSimilarTo(s)); }
public override TagCompound Save() { return(new TagCompound { { "stack", this.StoredItemStackSize }, { "type", this.StoredItemType }, { "duration", (int)(SystemHelpers.TimeStampInSeconds() - this.TimestampInSeconds) } }); }
public void SaveXmlToDiskTest() { var filePath = Constants.DepotPath + SystemHelpers.GenerateFilename(_request); Assert.IsFalse(File.Exists(filePath)); SystemHelpers.SaveXmlToDisk(_request); Assert.IsTrue(File.Exists(filePath)); File.Delete(filePath); }
//////////////// /// <param name="theme">Appearance style.</param> /// <param name="label">Display text.</param> /// <param name="url">URL.</param> /// <param name="hoverUrl">Indicates if the current element handles its own mouse hover URL display behavior.</param> /// <param name="scale">Size multiplier of display text.</param> /// <param name="large">'Large' state of display text.</param> public UIWebUrl(UITheme theme, string label, string url, bool hoverUrl = true, float scale = 0.85f, bool large = false) : base(theme, true) { this.IsVisited = false; this.Url = url; this.WillDrawOwnHoverUrl = hoverUrl; this.Scale = scale; this.Large = large; this.TextElem = new UIText(label, scale, large); this.TextElem.TextColor = theme.UrlColor; this.Append(this.TextElem); this.LineElem = UIWebUrl.GetLineElement(label, scale, large); this.LineElem.TextColor = theme.UrlColor; this.Append(this.LineElem); CalculatedStyle labelSize = this.TextElem.GetDimensions(); this.Width.Set(labelSize.Width, 0f); this.Height.Set(labelSize.Height, 0f); UIText textElem = this.TextElem; UIText lineElem = this.LineElem; this.OnMouseOver += delegate(UIMouseEvent evt, UIElement fromElem) { if (textElem.TextColor != theme.UrlVisitColor) { textElem.TextColor = theme.UrlLitColor; textElem.TextColor = theme.UrlLitColor; } }; this.OnMouseOut += delegate(UIMouseEvent evt, UIElement fromElem) { if (textElem.TextColor != theme.UrlVisitColor) { textElem.TextColor = theme.UrlColor; textElem.TextColor = theme.UrlColor; } }; this.OnClick += delegate(UIMouseEvent evt, UIElement fromElem) { try { SystemHelpers.OpenUrl(this.Url); //System.Diagnostics.Process.Start( this.Url ); this.IsVisited = true; textElem.TextColor = theme.UrlVisitColor; lineElem.TextColor = theme.UrlVisitColor; } catch (Exception e) { Main.NewText(e.Message); } }; this.RefreshTheme(); }
//////////////// public void SetTimeLeftByPercent(int maxElapsedSeconds, float timeLeftPercent) { float elapsedPercent = 1f - timeLeftPercent; int elapsedTicks = (int)((float)maxElapsedSeconds * elapsedPercent); int elapsedSeconds = elapsedTicks / 60; long now = SystemHelpers.TimeStampInSeconds(); this.TimestampInSeconds = now - elapsedSeconds; }
protected override void ReceiveWithClient() { var now = (long)SystemHelpers.TimeStamp().TotalMilliseconds; this.EndTime = now; this.SendToServer(false); HamstarHelpersMod.Instance.NetHelpers.UpdatePing((int)(now - this.StartTime)); }
public override TagCompound Save(Item item) { if (this.NeedsSaving(item)) { return(new TagCompound { { "duration", (int)(SystemHelpers.TimeStampInSeconds() - this.TimestampInSeconds) } }); } return(new TagCompound()); }
//////////////// public void ResetTimestampAndMaxStackSize(Item item) { if (this.NeedsSaving(item)) { item.maxStack = 1; if (this.TimestampInSeconds == 0) { this.TimestampInSeconds = SystemHelpers.TimeStampInSeconds(); } } }
//////////////// public override void Load(TagCompound tag) { if (!tag.ContainsKey("stack")) { return; } this.StoredItemStackSize = tag.GetInt("stack"); this.StoredItemType = tag.GetInt("type"); this.TimestampInSeconds = SystemHelpers.TimeStampInSeconds() - tag.GetInt("duration"); }
public override void Load(Item item, TagCompound tags) { if (this.NeedsSaving(item)) { this.TimestampInSeconds = SystemHelpers.TimeStampInSeconds(); if (tags.ContainsKey("duration")) { this.TimestampInSeconds -= tags.GetInt("duration"); } } }
public UIWebUrl(UITheme theme, string label, string url, bool hover_url = true, float scale = 0.85f, bool large = false) : base() { this.Theme = theme; this.WillDrawOwnHoverUrl = hover_url; this.Url = url; this.TextElem = new UIText(label, scale, large); this.TextElem.TextColor = theme.UrlColor; this.Append(this.TextElem); CalculatedStyle label_size = this.TextElem.GetDimensions(); float underscore_len = Main.fontMouseText.MeasureString("_").X; float text_len = Main.fontMouseText.MeasureString(label).X; int line_len = (int)Math.Max(1f, Math.Round(text_len / (underscore_len - 2))); this.LineElem = new UIText(new String('_', line_len), scale, large); this.LineElem.TextColor = theme.UrlColor; this.Append(this.LineElem); this.Width.Set(label_size.Width, 0f); this.Height.Set(label_size.Height, 0f); UIText text_elem = this.TextElem; UIText line_elem = this.LineElem; this.OnMouseOver += delegate(UIMouseEvent evt, UIElement from_elem) { if (text_elem.TextColor != theme.UrlVisitColor) { text_elem.TextColor = theme.UrlLitColor; text_elem.TextColor = theme.UrlLitColor; } }; this.OnMouseOut += delegate(UIMouseEvent evt, UIElement from_elem) { if (text_elem.TextColor != theme.UrlVisitColor) { text_elem.TextColor = theme.UrlColor; text_elem.TextColor = theme.UrlColor; } }; this.OnClick += delegate(UIMouseEvent evt, UIElement from_elem) { try { SystemHelpers.OpenUrl(this.Url); //System.Diagnostics.Process.Start( this.Url ); text_elem.TextColor = theme.UrlVisitColor; line_elem.TextColor = theme.UrlVisitColor; } catch (Exception e) { Main.NewText(e.Message); } }; }
public void get_MSI_details() { var apps = SystemHelpers.GetInstalledApplications().ToList(); var vsApps = apps.Where(app => app.Name.Contains("Visual Studio") || app.Name.Contains("Build Tools")).ToArray(); foreach (var appInfo in vsApps) { var path = MsiHelper.GetProductInfo(appInfo.Id.ToString("B")); if (!string.IsNullOrWhiteSpace(path)) { } } }
public void InitializeCreatedRequest() { byte[] blob = SystemHelpers.GenerateBlobFromString(DummyXml); _request = new OnboardingRequest { RequestId = 15, RequestSubject = "CreatedRequest", CreatedBy = @"REDMOND\t-chehu", State = RequestState.Created, Type = RequestType.CreateSPT, Blob = blob }; }
private static void CheckWindowsArguments(string[] args) { if (SystemHelpers.IsWindows()) { _isConsole = args.Any(x => x.ToLower() == "--console"); if (_isConsole) { // make a kernel32.dll call to detach application from console // this will allow it to run in the background, even after closing // instance of console it was called from _hasConsole = AllocConsole(); } } }
public bool ComputeElapsedTicks(out int elapsedTicks) { if (this.StoredItemStackSize == 0) { elapsedTicks = 0; return(false); } var mymod = (StarvationMod)this.mod; long now = SystemHelpers.TimeStampInSeconds(); int elapsedSeconds = (int)(now - this.TimestampInSeconds); elapsedTicks = elapsedSeconds * 60; //float elapsedTicksScaled = (float)elapsedTicks * mymod.Config.TupperwareSpoilageRateScale; return(true); }
public override void Load() { //ErrorLogger.Log( "Loading Mod Helpers. Ensure you have .NET Framework v4.6+ installed, if you're having problems." ); if (Environment.Version < new Version(4, 0, 30319, 42000)) { SystemHelpers.OpenUrl("https://dotnet.microsoft.com/download/dotnet-framework-runtime"); throw new FileNotFoundException("Mod Helpers " + this.Version + " requires .NET Framework v4.6+ to work."); } this.LoadInner(); InboxMessages.SetMessage("ModHelpers:ControlPanelTags", "Mod tag lists have now been added to the Control Panel. Mod tags can be modified in the Mod Info menu page via. the main menu.", false ); }
//////////////// public bool SetTimeLeftByPercent(Item item, float timeLeftPercent) { int maxElapsedTicks; if (!this.ComputeMaxElapsedTicks(item, out maxElapsedTicks)) { throw new ModHelpersException("Could not compute max elapsed ticks."); } float elapsedPercent = 1f - timeLeftPercent; int elapsedTicks = (int)((float)maxElapsedTicks * elapsedPercent); int elapsedSeconds = elapsedTicks / 60; long now = SystemHelpers.TimeStampInSeconds(); this.TimestampInSeconds = now - elapsedSeconds; return(true); }
private static void DoWorkToValidateServer(ServerBrowserEntry server_data, string hash) { string hash_base = ""; bool found = false; for (int i = 0; i < 1000000; i++) { hash_base = i + ""; string test_hash = SystemHelpers.ComputeSHA256Hash(hash_base); if (hash == test_hash) { found = true; break; } } if (!found) { LogHelpers.Log("Server browser processing failed; no matching hash."); return; } var output_obj = new ServerBrowserWorkProof { ServerIP = server_data.ServerIP, Port = server_data.Port, WorldName = server_data.WorldName, HashBase = hash_base }; string json_str = JsonConvert.SerializeObject(output_obj, Formatting.None); byte[] json_bytes = Encoding.UTF8.GetBytes(json_str); Thread.Sleep(1500); NetHelpers.NetHelpers.MakePostRequestAsync(ServerBrowserReporter.URL, json_bytes, delegate(string output) { LogHelpers.Log("Server browser processing complete."); }, delegate(Exception e, string output) { LogHelpers.Log("Server browser reply returned error: " + e.ToString()); }); ServerBrowserReporter.LastSendTimestamp = SystemHelpers.TimeStampInSeconds(); }
/// <summary> /// Store filename-xml pair into database. /// </summary> /// <param name="db">An instance of <see cref="OnboardingDbContext"/>.</param> public static void AddOrUpdateExistingSpts(OnboardingDbContext db) { Logger.Debug("Updating ExistingSpts by retrieving from source depot..."); SystemHelpers.SyncDepot(); foreach (var file in Directory.EnumerateFiles(Constants.ProductCatalogPath, "*.xml")) { var xmlDoc = new XmlDocument(); xmlDoc.Load(file); var dirObjs = xmlDoc.GetElementsByTagName("DirectoryChanges")[0].ChildNodes; XmlNode targetObj = null; for (var i = 0; i < dirObjs.Count; i++) { if (XmlHelpers.IsValidSpt(dirObjs[i].OuterXml)) { targetObj = dirObjs[i]; } } if (targetObj != null) { var tempDoc = new XmlDocument(); tempDoc.LoadXml(targetObj.OuterXml); var entity = new ExistingSpt { Name = XmlHelpers.GetFileNameFromPath(file), XmlContent = targetObj.OuterXml, ServiceType = tempDoc.GetElementsByTagName("ServiceType")[0].InnerText }; if (db.ExistingSpts.Any(e => e.Name == entity.Name)) { db.ExistingSpts.Attach(entity); db.Entry(entity).State = EntityState.Modified; } else { db.ExistingSpts.Add(entity); } } } var num = db.SaveChanges(); Logger.Debug(num + " ExistingSpts have been updated in database"); }
public void AddFileToDepotAndPackTest() { var xmlPath = Constants.DepotPath + SystemHelpers.GenerateFilename(_request); var dpkPath = Constants.DepotPath + SystemHelpers.GenerateFilename(_request) + ".dpk"; Assert.IsFalse(File.Exists(dpkPath)); SystemHelpers.SaveXmlToDisk(_request); SystemHelpers.AddFileToDepotAndPack(SystemHelpers.GenerateFilename(_request)); Assert.IsTrue(File.Exists(dpkPath)); while (true) { if (File.Exists(xmlPath) && File.Exists(dpkPath)) { File.Delete(xmlPath); File.Delete(dpkPath); break; } } SystemHelpers.RevertFile(SystemHelpers.GenerateFilename(_request)); }
//////////////// /// <param name="theme">Appearance style.</param> /// <param name="image">Display image.</param> /// <param name="url">URL.</param> /// <param name="hoverUrl">Indicates if the current element handles its own mouse hover URL display behavior.</param> public UIImageUrl(UITheme theme, Texture2D image, string url, bool hoverUrl = true) : base(theme, true) { this.IsVisited = false; this.Url = url; this.WillDrawOwnHoverUrl = hoverUrl; this.ImageElement = new UIImageButton(image); this.ImageElement.SetVisibility(1f, 0.75f); this.Append(this.ImageElement); this.Width.Pixels = this.ImageElement.Width.Pixels; this.Width.Percent = this.ImageElement.Width.Percent; this.Height.Pixels = this.ImageElement.Height.Pixels; this.Height.Percent = this.ImageElement.Height.Percent; this.OnMouseOver += (evt, __) => { if (!this.ImageElement.IsMouseHovering) { this.ImageElement.MouseOver(evt); } }; this.OnMouseOut += (evt, __) => { if (this.ImageElement.IsMouseHovering) { this.ImageElement.MouseOut(evt); } }; this.OnClick += (_, __) => { try { SystemHelpers.OpenUrl(this.Url); //System.Diagnostics.Process.Start( this.Url ); this.IsVisited = true; } catch (Exception e) { Main.NewText(e.Message); } }; this.RefreshTheme(); }
//////////////// public bool ComputeElapsedTicks(Item item, out int elapsedTicks) { if (!this.NeedsSaving(item)) { elapsedTicks = 0; return(false); } if (this.TimestampInSeconds == 0) { elapsedTicks = 0; return(false); } var mymod = (StarvationMod)this.mod; long now = SystemHelpers.TimeStampInSeconds(); int elapsedSeconds = (int)(now - this.TimestampInSeconds); elapsedTicks = (int)elapsedSeconds * 60; return(true); }
public WikipediaApp(ITester t) { Tester = t; SystemHelpers = new SystemHelpers(t); // Log version of all required models LogSwModelVersion(); SystemHelpers.LogEnvironmentModelVersion(); BaseModelHelpers.LogBaseModelVersion(t); // Initialize Application Settings AppSettings = new Dictionary <string, string>(); // Set this to the culture of the environment that will be used SutLocale = new SutLocale(t, SystemHelpers, "en-CH"); Browser = new Browser(t, SystemHelpers); Browser.Activate(); InitScreens(); }