public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { ResultsState state = (ResultsState)value; LocalStatus localState = (LocalStatus)Enum.Parse(typeof(LocalStatus), value.ToString()); switch (state) { case (ResultsState.NewPB): if (localState == LocalStatus.NewPB) { return(new SolidColorBrush(Colors.Honeydew)); } break; case (ResultsState.NewSB): if (localState == LocalStatus.NewSB) { return(new SolidColorBrush(Colors.LightCyan)); } break; case (ResultsState.FirstTimer): if (localState == LocalStatus.FirstTimer) { return(new SolidColorBrush(Colors.LemonChiffon)); } break; } return(new SolidColorBrush(Colors.Transparent)); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { FieldUpdatedType state = (FieldUpdatedType)value; LocalStatus localState = (LocalStatus)Enum.Parse(typeof(LocalStatus), value.ToString()); switch (state) { case (FieldUpdatedType.Unchanged): if (localState == LocalStatus.Unchanged) { return(new SolidColorBrush(Colors.Black)); } break; case (FieldUpdatedType.Changed): if (localState == LocalStatus.Changed) { return(new SolidColorBrush(Colors.DarkSeaGreen)); } break; case (FieldUpdatedType.Invalid): if (localState == LocalStatus.Invalid) { return(new SolidColorBrush(Colors.IndianRed)); } break; case (FieldUpdatedType.Disabled): if (localState == LocalStatus.Disabled) { return(new SolidColorBrush(Colors.WhiteSmoke)); } break; } return(new SolidColorBrush(Colors.Gray)); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { StatusType state = (StatusType)value; LocalStatus localState = (LocalStatus)Enum.Parse(typeof(LocalStatus), value.ToString()); switch (state) { case (StatusType.Added): if (localState == LocalStatus.Added) { return(new SolidColorBrush(Colors.Green)); } break; case (StatusType.Deleted): if (localState == LocalStatus.Deleted) { return(new SolidColorBrush(Colors.Red)); } break; case (StatusType.Ok): if (localState == LocalStatus.Ok) { return(new SolidColorBrush(Colors.Black)); } break; case (StatusType.Updated): if (localState == LocalStatus.Updated) { return(new SolidColorBrush(Colors.Blue)); } break; } return(new SolidColorBrush(Colors.Black)); }
private LocalStatus GetLocalStatus(FilePath localPath) { var st = new LocalStatus(); var commit = _coreRepository.Resolve(GitSharp.Core.Constants.HEAD); if (commit != null) st.Revision = commit.ToString(); string relativePath = (localPath.ToRelative(_coreRepository.WorkingDirectory.FullName)).ToString() .Replace('\\', '/'); if (CachedStatus.Untracked.Contains(relativePath)) st.VersionStatus = VersionStatus.Unversioned; if (CachedStatus.Added.Contains(relativePath)) st.VersionStatus = VersionStatus.Versioned | VersionStatus.ScheduledAdd; if (CachedStatus.Removed.Contains(relativePath)) st.VersionStatus = VersionStatus.Versioned | VersionStatus.ScheduledDelete; if (CachedStatus.Modified.Contains(relativePath)) st.VersionStatus = VersionStatus.Versioned | VersionStatus.Modified; if (CachedStatus.Removed.Contains(relativePath)) st.VersionStatus = VersionStatus.Versioned | VersionStatus.ScheduledDelete; // TODO: Missing some version statuses to check. return st; }
public LocalStatusReportReplyEventArgs(Guid connectionId, byte address, LocalStatus localStatus) { ConnectionId = connectionId; Address = address; LocalStatus = localStatus; }
/// <summary> /// Wraps sending messages to the connected descriptor /// </summary> /// <param name="strings">the output</param> /// <returns>success status</returns> public bool SendOutput(IEnumerable <string> strings) { //TODO: Stop hardcoding this but we have literally no sense of injury/self status yet SelfStatus self = new SelfStatus { Body = new BodyStatus { Health = _currentPlayer.CurrentHealth == 0 ? 100 : 100 / (2M * _currentPlayer.CurrentHealth), Stamina = _currentPlayer.CurrentStamina, Overall = OverallStatus.Excellent, Anatomy = new AnatomicalPart[] { new AnatomicalPart { Name = "Arm", Overall = OverallStatus.Good, Wounds = new string[] { "Light scrape" } }, new AnatomicalPart { Name = "Leg", Overall = OverallStatus.Excellent, Wounds = new string[] { } } } }, CurrentActivity = _currentPlayer.CurrentAction, Balance = _currentPlayer.Balance.ToString(), CurrentArt = _currentPlayer.LastAttack?.Name ?? "", CurrentCombo = _currentPlayer.LastCombo?.Name ?? "", CurrentTarget = _currentPlayer.GetTarget() == null ? "" : _currentPlayer.GetTarget() == _currentPlayer ? "Your shadow" : _currentPlayer.GetTarget().GetDescribableName(_currentPlayer), CurrentTargetHealth = _currentPlayer.GetTarget() == null || _currentPlayer.GetTarget() == _currentPlayer ? double.PositiveInfinity : _currentPlayer.GetTarget().CurrentHealth == 0 ? 100 : 100 / (2 * _currentPlayer.CurrentHealth), Position = _currentPlayer.StancePosition.ToString(), Stance = _currentPlayer.Stance, Stagger = _currentPlayer.Stagger.ToString(), Qualities = string.Join("", _currentPlayer.Qualities.Where(quality => quality.Visible).Select(quality => string.Format("<div class='qualityRow'><span>{0}</span><span>{1}</span></div>", quality.Name, quality.Value))), CurrentTargetQualities = _currentPlayer.GetTarget() == null || _currentPlayer.GetTarget() == _currentPlayer ? "" : string.Join("", _currentPlayer.GetTarget().Qualities.Where(quality => quality.Visible).Select(quality => string.Format("<div class='qualityRow'><span>{0}</span><span>{1}</span></div>", quality.Name, quality.Value))), Mind = new MindStatus { Overall = OverallStatus.Excellent, States = new string[] { "Fearful" } } }; IGlobalPosition currentLocation = _currentPlayer.CurrentLocation; IContains currentContainer = currentLocation.CurrentLocation(); IZone currentZone = currentContainer.CurrentLocation.CurrentZone; ILocale currentLocale = currentLocation.CurrentLocale; IRoom currentRoom = currentLocation.CurrentRoom; IGaia currentWorld = currentZone.GetWorld(); IEnumerable <string> pathways = Enumerable.Empty <string>(); IEnumerable <string> inventory = Enumerable.Empty <string>(); IEnumerable <string> populace = Enumerable.Empty <string>(); string locationDescription = string.Empty; LexicalContext lexicalContext = new LexicalContext(_currentPlayer) { Language = _currentPlayer.Template <IPlayerTemplate>().Account.Config.UILanguage, Perspective = NarrativePerspective.SecondPerson, Position = LexicalPosition.Near }; Message toCluster = new Message(currentContainer.RenderToVisible(_currentPlayer)); if (currentContainer != null) { pathways = ((ILocation)currentContainer).GetPathways().Select(data => data.GetDescribableName(_currentPlayer)); inventory = currentContainer.GetContents <IInanimate>().Select(data => data.GetDescribableName(_currentPlayer)); populace = currentContainer.GetContents <IMobile>().Where(player => !player.Equals(_currentPlayer)).Select(data => data.GetDescribableName(_currentPlayer)); locationDescription = toCluster.Unpack(TargetEntity.Actor, lexicalContext); } LocalStatus local = new LocalStatus { ZoneName = currentZone?.TemplateName, LocaleName = currentLocale?.TemplateName, RoomName = currentRoom?.TemplateName, Inventory = inventory.ToArray(), Populace = populace.ToArray(), Exits = pathways.ToArray(), LocationDescriptive = locationDescription }; //The next two are mostly hard coded, TODO, also fix how we get the map as that's an admin thing ExtendedStatus extended = new ExtendedStatus { Horizon = new string[] { "A hillside", "A dense forest" }, VisibleMap = currentLocation.CurrentRoom == null ? string.Empty : currentLocation.CurrentRoom.RenderCenteredMap(3, true) }; string timeOfDayString = string.Format("The hour of {0} in the day of {1} in {2} in the year of {3}", currentWorld.CurrentTimeOfDay.Hour , currentWorld.CurrentTimeOfDay.Day , currentWorld.CurrentTimeOfDay.MonthName() , currentWorld.CurrentTimeOfDay.Year); string sun = "0"; string moon = "0"; string visibilityString = "5"; Tuple <string, string, string[]> weatherTuple = new Tuple <string, string, string[]>("", "", new string[] { }); if (currentZone != null) { Tuple <PrecipitationAmount, PrecipitationType, HashSet <WeatherType> > forecast = currentZone.CurrentForecast(); weatherTuple = new Tuple <string, string, string[]>(forecast.Item1.ToString(), forecast.Item2.ToString(), forecast.Item3.Select(wt => wt.ToString()).ToArray()); visibilityString = currentZone.GetCurrentLuminosity().ToString(); if (currentWorld != null) { IEnumerable <ICelestial> bodies = currentZone.GetVisibileCelestials(_currentPlayer); ICelestial theSun = bodies.FirstOrDefault(cest => cest.Name.Equals("sun", StringComparison.InvariantCultureIgnoreCase)); ICelestial theMoon = bodies.FirstOrDefault(cest => cest.Name.Equals("moon", StringComparison.InvariantCultureIgnoreCase)); if (theSun != null) { ICelestialPosition celestialPosition = currentWorld.CelestialPositions.FirstOrDefault(celest => celest.CelestialObject == theSun); sun = AstronomicalUtilities.GetCelestialLuminosityModifier(celestialPosition.CelestialObject, celestialPosition.Position, currentWorld.PlanetaryRotation , currentWorld.OrbitalPosition, currentZone.Template <IZoneTemplate>().Hemisphere, currentWorld.Template <IGaiaTemplate>().RotationalAngle).ToString(); } if (theMoon != null) { ICelestialPosition celestialPosition = currentWorld.CelestialPositions.FirstOrDefault(celest => celest.CelestialObject == theMoon); moon = AstronomicalUtilities.GetCelestialLuminosityModifier(celestialPosition.CelestialObject, celestialPosition.Position, currentWorld.PlanetaryRotation , currentWorld.OrbitalPosition, currentZone.Template <IZoneTemplate>().Hemisphere, currentWorld.Template <IGaiaTemplate>().RotationalAngle).ToString(); } } } EnvironmentStatus environment = new EnvironmentStatus { Sun = sun, Moon = moon, Visibility = visibilityString, Weather = weatherTuple, Temperature = currentZone.EffectiveTemperature().ToString(), Humidity = currentZone.EffectiveHumidity().ToString(), TimeOfDay = timeOfDayString }; OutputStatus outputFormat = new OutputStatus { Occurrence = EncapsulateOutput(strings), Self = self, Local = local, Extended = extended, Environment = environment }; Send(Utility.SerializationUtility.Serialize(outputFormat)); return(true); }
/// <summary> /// Update the persistent and current local status. This cannot be used /// to set the status to "none". /// </summary> public void UpdatePersistentStatus(LocalStatus newStatus, DateTime observedDate, UInt64 observedID, UInt64 observedSize, byte[] observedHash) { Debug.Assert(observedHash != null); PersistentLocalStatus = CurrentLocalStatus = newStatus; LocalDate = observedDate; LocalID = observedID; LocalSize = observedSize; LocalHash = observedHash; Share.App.SetDirty("UpdatePersistentStatus"); }
/// <summary> /// Update the local status of the file. /// </summary> public void UpdateLocalStatus() { // Note about problematic Office files: // // Some Office programs change the modification date of a file when // they open the file, even though the user did not modify the file yet. // On exit, they restore the previous modification date if the user did not modify // the file. The hash is modified in all cases. Therefore, for the // algorithm to detect these file statuses reliably, we must be careful // to never flush the unmodified date unless the file is provably // modified. Logging.Log("Updating status of " + RelativePath + "."); FileStream stream = null; LocalUpdateFlag = false; LocalError = null; if (CurrentVersion == null) { Debug.Assert(PersistentLocalStatus == LocalStatus.None); Debug.Assert(CurrentLocalStatus == LocalStatus.None); return; } if (PersistentLocalStatus != LocalStatus.None) Debug.Assert(LocalHash != null); try { // If this is a problematic Office file, open the file in write-exclusive mode // to detect the case where the problematic Office application has opened the file. // We can't compute the status in that case. // This operation can be slow because of antivirus scanning. if (IsOfficeProblemFile()) stream = new FileStream(FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None); // Open the file in non-exclusive mode in the general case. else stream = new FileStream(FullPath, FileMode.Open, FileAccess.Read); } catch (Exception ex) { Debug.Assert(stream == null); // The file no longer exist. if (!File.Exists(FullPath)) CurrentLocalStatus = LocalStatus.Absent; // We could not open the file. else { CurrentLocalStatus = LocalStatus.Error; LocalError = ex.Message; Logging.Log("UpdateLocalStatus(): cannot open file " + RelativePath + ": " + LocalError + "."); RequestUpdate(); } return; } try { // Get the file information. UInt64 observedID, observedSize; DateTime observedDate; KfsPath.GetLowLevelFileInfo(stream, out observedID, out observedSize, out observedDate); // If the observed information match the cached information, the // persistent status is current. In the case of problematic Office // applications, always recompute the hash. if (!IsOfficeProblemFile() && PersistentLocalStatus != LocalStatus.None && observedID == LocalID && observedSize == LocalSize && observedDate == LocalDate) { CurrentLocalStatus = PersistentLocalStatus; } // We have to get information about the file using the hash. else { // Compute the hash. If we opened the file in non-exclusive mode, // it is possible, though unlikely, that we compute the hash // incorrectly. Normally, the filesystem watcher should send us an // update event for the file and the modification date should // change, so this is not a problem normally. byte[] observedHash = (new MD5CryptoServiceProvider()).ComputeHash(stream); // The file matches the version we downloaded. The file is // unmodified. if (DownloadVersion != null && Base.ByteArrayEqual(DownloadVersion.Hash, observedHash)) { UpdatePersistentStatus(LocalStatus.Unmodified, observedDate, observedID, observedSize, observedHash); } // The file matches the current version. Make this version the // downloaded version. The file is unmodified. else if (Base.ByteArrayEqual(CurrentVersion.Hash, observedHash)) { UpdateDownloadVersion(CurrentVersion, false); UpdatePersistentStatus(LocalStatus.Unmodified, observedDate, observedID, observedSize, observedHash); } // The file does not match either version. else { // The file is modified. if (!IsOfficeProblemFile()) { UpdatePersistentStatus(LocalStatus.Modified, observedDate, observedID, observedSize, observedHash); } // Apparently, the content of the file has not changed // since we evaluated it. else if (PersistentLocalStatus != LocalStatus.None && observedDate == LocalDate) { UpdatePersistentStatus(PersistentLocalStatus, observedDate, observedID, observedSize, observedHash); } // The file is modified. else { UpdatePersistentStatus(LocalStatus.Modified, observedDate, observedID, observedSize, observedHash); } } } } catch (Exception ex) { CurrentLocalStatus = LocalStatus.Error; LocalError = ex.Message; Logging.Log("UpdateLocalStatus(): cannot compute status of " + RelativePath + ": " + LocalError + "."); RequestUpdate(); } finally { if (stream != null) stream.Close(); Logging.Log("Finished updating"); } }
/// <summary> /// Update the downloaded version of the file and force the refresh of /// the status of the file, if requested. /// </summary> public void UpdateDownloadVersion(KfsServerFileVersion NewDownloadVersion, bool refreshFlag) { DownloadVersion = NewDownloadVersion; if (refreshFlag) { PersistentLocalStatus = LocalStatus.None; CurrentLocalStatus = LocalStatus.None; RequestUpdate(); } Share.App.SetDirty("UpdateDownloadVersion"); }
/// <summary> /// Initialization code common to both the deserialized and /// non-deserialized cases. /// </summary> public void Initialize() { CurrentLocalStatus = LocalStatus.None; LocalUpdateFlag = true; }