public bool IsMet(Tasks.IUpdateTask task) { if (FileSize <= 0) { return(true); } var localPath = !string.IsNullOrEmpty(LocalPath) ? LocalPath : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string; // local path is invalid, we can't check for anything so we will return as if the condition was met if (string.IsNullOrEmpty(localPath)) { return(true); } long localFileSize = 0; if (File.Exists(localPath)) { var fi = new FileInfo(localPath); localFileSize = fi.Length; } switch (ComparisonType) { case "above": return(FileSize < localFileSize); case "is": return(FileSize == localFileSize); } return(FileSize > localFileSize); }
public bool IsMet(Tasks.IUpdateTask task) { if (FileSize <= 0) { return(true); } string localPath = !string.IsNullOrEmpty(LocalPath) ? LocalPath : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string; if (string.IsNullOrEmpty(localPath) || !File.Exists(localPath)) { return(true); } FileInfo fi = new FileInfo(localPath); switch (ComparisonType) { case "above": return(FileSize < fi.Length); case "is": return(FileSize == fi.Length); } return(FileSize > fi.Length); }
public bool IsMet(Tasks.IUpdateTask task) { string localPath = !string.IsNullOrEmpty(LocalPath) ? LocalPath : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string; if (string.IsNullOrEmpty(localPath) || !File.Exists(localPath)) { return(true); } var versionInfo = FileVersionInfo.GetVersionInfo(localPath); if (versionInfo.FileVersion == null) { return(true); // perform the update if no version info is found } string versionString = versionInfo.FileVersion.Replace(", ", "."); Version localVersion = new Version(versionString); Version updateVersion = Version != null ? new Version(Version) : new Version(); switch (ComparisonType) { case "above": return(updateVersion < localVersion); case "is": return(updateVersion == localVersion); default: return(updateVersion > localVersion); } }
public bool IsMet(Tasks.IUpdateTask task) { string localPath = !string.IsNullOrEmpty(LocalPath) ? LocalPath : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string; if (string.IsNullOrEmpty(localPath)) { return(true); } return(File.Exists(localPath)); }
public bool IsMet(Tasks.IUpdateTask task) { if (Timestamp == DateTime.MinValue) { return(true); } string localPath = !string.IsNullOrEmpty(LocalPath) ? LocalPath : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string; // local path is invalid, we can't check for anything so we will return as if the condition was met if (string.IsNullOrEmpty(localPath)) { return(true); } var fullPath = FileSystem.GetFullPath(localPath); // if the file doesn't exist it has a null timestamp, and therefore the condition result depends on the ComparisonType if (!File.Exists(fullPath)) { return(ComparisonType.Equals("older", StringComparison.InvariantCultureIgnoreCase)); } // File timestamps seem to be off by a little bit (conversion rounding?), so the code below // gets around that var dt = File.GetLastWriteTime(fullPath); var localPlus = dt.AddSeconds(2).ToFileTimeUtc(); var localMinus = dt.AddSeconds(-2).ToFileTimeUtc(); var remoteFileDateTime = Timestamp.ToFileTimeUtc(); bool result; switch (ComparisonType) { case "newer": result = localMinus > remoteFileDateTime; break; case "is": result = localMinus <= remoteFileDateTime && remoteFileDateTime <= localPlus; break; default: result = localPlus < remoteFileDateTime; break; } return(result); }
public bool IsMet(Tasks.IUpdateTask task) { if (ChildConditions == null) { return(true); } // perform the update if Passed == true // otherwise, do not perform the update bool passed = true, firstRun = true; foreach (ConditionItem item in ChildConditions) { // If after the first iteration, accept as fulfilled if we are at an OR clause and the conditions // before this checked OK (i.e. update needed) if (!firstRun) { if (passed && item.HasConditionType(ConditionType.OR)) { return(true); } } else { firstRun = false; } // Skip all ANDed conditions if some of them failed, until we consume all the conditions // or we hit an OR'ed one if (!passed) { if (item.HasConditionType(ConditionType.OR)) { var checkResult = item.Condition.IsMet(task); passed = item.HasConditionType(ConditionType.NOT) ? !checkResult : checkResult; } } else { var checkResult = item.Condition.IsMet(task); passed = item.HasConditionType(ConditionType.NOT) ? !checkResult : checkResult; } } return(passed); }
public bool IsMet(Tasks.IUpdateTask task) { var localPath = !string.IsNullOrEmpty(LocalPath) ? LocalPath : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string; // local path is invalid, we can't check for anything so we will return as if the condition was met if (string.IsNullOrEmpty(localPath)) { return(true); } var fullPath = FileSystem.GetFullPath(localPath); // if the file doesn't exist it has a null version, and therefore the condition result depends on the ComparisonType if (!File.Exists(fullPath)) { return(ComparisonType.Equals("below", StringComparison.InvariantCultureIgnoreCase)); } var versionInfo = FileVersionInfo.GetVersionInfo(fullPath); if (versionInfo.FileVersion == null) { return(true); // perform the update if no version info is found } var localVersion = new Version(versionInfo.FileMajorPart, versionInfo.FileMinorPart, versionInfo.FileBuildPart, versionInfo.FilePrivatePart); var updateVersion = Version != null ? new Version(Version) : new Version(); switch (ComparisonType) { case "above": return(updateVersion < localVersion); case "is": return(updateVersion == localVersion); default: return(updateVersion > localVersion); } }
public bool IsMet(Tasks.IUpdateTask task) { if (Timestamp == DateTime.MinValue) { return(true); } string localPath = !string.IsNullOrEmpty(LocalPath) ? LocalPath : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string; if (string.IsNullOrEmpty(localPath) || !File.Exists(localPath)) { return(true); } // File timestamps seem to be off by a little bit (conversion rounding?), so the code below // gets around that DateTime dt = File.GetLastWriteTime(localPath); long localPlus = dt.AddSeconds(2).ToFileTimeUtc(); long localMinus = dt.AddSeconds(-2).ToFileTimeUtc(); long remoteFileDateTime = Timestamp.ToFileTimeUtc(); bool result; switch (ComparisonType) { case "newer": result = localMinus > remoteFileDateTime; break; case "is": result = localMinus <= remoteFileDateTime && remoteFileDateTime <= localPlus; break; default: result = localPlus < remoteFileDateTime; break; } return(result); }
// TODO: Work with enums on code and Attributes to get a proper and full OS version comparison // use http://stackoverflow.com/questions/545666/how-to-translate-ms-windows-os-version-numbers-into-product-names-in-net // and http://msdn.microsoft.com/en-us/library/ms724429(VS.85).aspx public bool IsMet(Tasks.IUpdateTask task) { var is64Bit = Is64BitOperatingSystem(); if (OsBits == 32 && OsBits != 64) { return(true); } // OS bitness check, if requested if (OsBits == 32 && is64Bit) { return(false); } if (OsBits == 64 && !is64Bit) { return(false); } return(true); }