public override void Apply(T ruleContext) { Assert.ArgumentNotNull(ruleContext, nameof(ruleContext)); if (string.IsNullOrWhiteSpace(FromPath) || string.IsNullOrWhiteSpace(ToPath)) { return; } if (FromPath.Equals(ToPath)) { return; } // normalize input, no trailing slash FromPath = StringUtil.EnsurePrefix('/', FromPath.TrimEnd('/')); ToPath = StringUtil.EnsurePrefix('/', ToPath.TrimEnd('/')); // Use all renderings of selected device var renderings = ruleContext.SelectedRenderings; // Handle Special case (target lives inside broader source) // Solution: flatten in-between problem paths to be FromPath if (ToPath.TrimStart('/').StartsWith(FromPath.TrimStart('/'))) { var segments = ToPath.Split(new[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries); // For each problem path, backwards, between FROM and TO.. (ie given /A/B/C/D => /A/B/C, /A/B) for (var s = segments.Length - 1; s > 1; s--) // 3 .. 2 => 3, 2 { string problemPath = string.Empty; for (var i = 0; i < s; i++) // 0, 1, 2; 0, 1; { problemPath = string.Concat(problemPath, "/", segments[i]); } // Set to FROM path foreach (var r in renderings) { if (r.Placeholder.Equals(problemPath)) { r.Placeholder = FromPath; } } } } // Move to new placeholder (maintaining nested structure) foreach (var r in renderings) { if (TryReplacePath(r, FromPath, ToPath)) { ruleContext.HasLayoutChange = true; } } }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (SelectedSource != null ? SelectedSource.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (FromPath != null ? FromPath.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ToPath != null ? ToPath.GetHashCode() : 0); hashCode = (hashCode * 397) ^ OverWriteMode.GetHashCode(); hashCode = (hashCode * 397) ^ AddMode.GetHashCode(); return(hashCode); } }
public async void Action() { try { ApplyButton.Enabled = false; Model.Update(); File.Copy(FromPath, ToPath, true); File.Copy(FromPath.Replace(".dll", ".pdb"), ToPath.Replace(".dll", ".pdb"), true); await Task.Delay(100); ApplyButton.BackColor = Color.LightGreen; Model.Update(); await Task.Delay(200); } finally { ApplyButton.ResetBackColor(); ApplyButton.Enabled = true; Model.Update(); } }
/// <summary> /// /// </summary> /// <returns></returns> public string GetBackupFolderPath() { var fromPathName = FromPath.Substring(FromPath.LastIndexOf('/')); return(BackupPath + fromPathName + $"_{DateTime.Now:dd_MM_yyyy_hh_mm_ss}"); }
public override int GetHashCode() { return(Name.GetHashCode() ^ Kind.GetHashCode() ^ FromPath.GetHashCode() ^ FromRevision.GetHashCode() ^ Actions.GetHashCode()); }