public ReplicationDetailInfo GetReplicationInfo(string vmId) { if (ReplicaMode != ReplicaMode.ReplicationEnabled) throw new Exception("Server does not allow replication by settings"); ReplicationDetailInfo replica = null; var vm = GetVirtualMachine(vmId); Command cmd = new Command("Measure-VMReplication"); cmd.Parameters.Add("VmName", vm.Name); Collection<PSObject> result = PowerShell.Execute(cmd, true); if (result != null && result.Count > 0) { replica = new ReplicationDetailInfo(); replica.AverageLatency = result[0].GetProperty<TimeSpan?>("AverageReplicationLatency") ?? new TimeSpan(); replica.AverageSize = result[0].GetMb("AverageReplicationSize"); replica.Errors = result[0].GetInt("ReplicationErrors"); replica.FromTime = result[0].GetProperty<DateTime>("MonitoringStartTime"); replica.Health = result[0].GetEnum<ReplicationHealth>("ReplicationHealth"); replica.HealthDetails = string.Join(" ", result[0].GetProperty<string[]>("ReplicationHealthDetails")); replica.LastSynhronizedAt = result[0].GetProperty<DateTime?>("LastReplicationTime") ?? new DateTime(); replica.MaximumSize = result[0].GetMb("MaximumReplicationSize"); replica.Mode = result[0].GetEnum<VmReplicationMode>("ReplicationMode"); replica.PendingSize = result[0].GetMb("PendingReplicationSize"); replica.PrimaryServerName = result[0].GetString("PrimaryServerName"); replica.ReplicaServerName = result[0].GetString("CurrentReplicaServerName"); replica.State = result[0].GetEnum<ReplicationState>("ReplicationState"); replica.SuccessfulReplications = result[0].GetInt("SuccessfulReplicationCount"); replica.MissedReplicationCount = result[0].GetInt("MissedReplicationCount"); replica.ToTime = result[0].GetProperty<DateTime>("MonitoringEndTime"); } return replica; }
private void BindDetailsPopup(ReplicationDetailInfo vmReplicaInfo) { labDetailsState.Text = vmReplicaInfo.State.ToString(); labDetailsMode.Text = vmReplicaInfo.Mode.ToString(); labDetailsPrimary.Text = vmReplicaInfo.PrimaryServerName; labDetailsReplica.Text = vmReplicaInfo.ReplicaServerName; labDetailsHealth.Text = vmReplicaInfo.Health.ToString(); labDetailsHealthDetails.Text = vmReplicaInfo.HealthDetails; // statistic StatisticCollapsiblePanel.Text = GetLocalizedString("secStatisticPanel.Text") + ToReadableString(vmReplicaInfo.ToTime - vmReplicaInfo.FromTime); labFromTime.Text = vmReplicaInfo.FromTime.ToString(DateFormat); labToTime.Text = vmReplicaInfo.ToTime.ToString(DateFormat); labAverageSize.Text = vmReplicaInfo.AverageSize; labMaximumSize.Text = vmReplicaInfo.MaximumSize; labAverageLatency.Text = vmReplicaInfo.AverageLatency.ToString("c"); labErrorsEncountered.Text = vmReplicaInfo.Errors.ToString(); var totalCycles = vmReplicaInfo.SuccessfulReplications + vmReplicaInfo.MissedReplicationCount; if (totalCycles > 0) labSuccessfulReplicationCycles.Text = string.Format(cyclesTemplate, vmReplicaInfo.SuccessfulReplications, totalCycles, Convert.ToInt32(100*vmReplicaInfo.SuccessfulReplications/totalCycles)); else labSuccessfulReplicationCycles.Text = na; // pending replication labSizeData.Text = vmReplicaInfo.PendingSize; labLastSyncro.Text = vmReplicaInfo.LastSynhronizedAt == DateTime.MinValue ? na : vmReplicaInfo.LastSynhronizedAt.ToString(DateFormat); }