private void SetSourceIdObject() { var sensor = client.GetSensors(Property.Id, SourceId).FirstOrDefault(); if (sensor != null) { sourceObj = sensor; sourceObjResolver = GetSensors; return; } var device = client.GetDevices(Property.Id, SourceId).FirstOrDefault(); if (device != null) { sourceObj = device; sourceObjResolver = GetDevices; return; } var group = client.GetGroups(Property.Id, SourceId).FirstOrDefault(); if (group != null) { sourceObj = group; sourceObjResolver = GetGroups; return; } throw new PSArgumentException($"Cannot clone object with ID '{SourceId}' as it is not a sensor, device or group."); }
private PSObject GetNotificationTriggerTypes() { PrtgObject prtgObject = Object; if (prtgObject == null) { prtgObject = client.GetObject(ObjectId); } var types = client.GetNotificationTriggerTypes(prtgObject); var names = Enum.GetValues(typeof(TriggerType)).Cast <TriggerType>().ToList(); var obj = new PSObject(); obj.TypeNames.Insert(0, "PrtgAPI.TriggerTypePSObject"); obj.Properties.Add(new PSNoteProperty("Name", prtgObject.Name)); obj.Properties.Add(new PSNoteProperty("ObjectId", prtgObject.Id)); foreach (var name in names) { obj.Properties.Add(new PSNoteProperty(name.ToString(), types.Contains(name))); } return(obj); }
private void UpdateScenarioProgress_MultipleCmdlets(ProgressStage stage, PrtgObject obj) { if (ProgressManager.ExpectsContainsProgress) { if (stage == ProgressStage.PreLoop) { ProgressManager.RemovePreviousOperation(); } else if (stage == ProgressStage.BeforeEach) { if (!ProgressManager.PipeFromPrtgCmdletPostProcessMode) { ProgressManager.UpdateRecordsProcessed(ProgressManager.CurrentRecord, obj); } } else //PostLoop { ProgressManager.CompleteProgress(); } } if (stage == ProgressStage.PostLoop) { ProgressManager.MaybeCompletePreviousProgress(); } }
internal string GetSingleOperationProgressMessage(PrtgObject obj, int[] ids, string action, string typeDescription, string operationDescription = null) { if (obj == null && ids.Length == 0) { throw new ArgumentException($"{nameof(ids)} must be specified when {nameof(obj)} is null."); } string str; //e.g. Acknowledging sensor 'Ping' forever if (obj != null) { str = $"{action} {typeDescription} '{obj.Name}' (ID: {obj.Id})"; } else { str = $"{action} {typeDescription} {("ID".Plural(ids))} {(string.Join(", ", ids))}"; } if (operationDescription != null) { str += $" {operationDescription}"; } return(str); }
private void ExecuteOperation(PrtgObject obj, string url) { var server = PrtgRequestMessage.AddUrlPrefix(client.Server); if (ShouldProcess($"'{obj}' (ID: {obj.Id}, Type: {obj.Type})")) { ExecuteOperation(() => Process.Start($"{server}{url}"), $"Opening {obj.GetTypeDescription()} '{obj.Name}'"); } }
internal string TypeDescriptionOrDefault(PrtgObject obj, string @default = "object") { if (obj == null) { return(@default); } return(obj.GetTypeDescription().ToLower()); }
internal int[] GetSingleOperationId(PrtgObject obj, int[] id) { if (obj != null) { return new[] { obj.Id } } ; return(id); }
/// <summary> /// If <see cref="Batch"/> is true, queues the object for processing after all items have been identified. Otherwise, executes this cmdlet's action immediately. /// </summary> /// <param name="obj">The object to process.</param> /// <param name="progressMessage">The progress message to display.</param> protected void ExecuteOrQueue(PrtgObject obj, string progressMessage) { if (Batch.IsPresent) { ExecuteQueueOperation(obj, progressMessage); } else { PerformSingleOperation(); } }
public void Tree_Builds_UntypedObject() { var probe = new PrtgObject { Id = 1001 }; var response = new TreeRequestResponse(TreeRequestScenario.ContainerWithChild); var client = BaseTest.Initialize_Client(response); AssertEx.Throws <NotSupportedException>( () => client.GetTree(probe), "Cannot process value" ); }
internal static IEnumerable <IGrouping <int, NotificationAction> > GroupActionSchedules(List <NotificationAction> actions) { var actionsWithSchedules = actions .GroupBy(a => PrtgObject.GetId(a.lazyScheduleStr)).ToList(); foreach (var group in actionsWithSchedules) { if (group.Key == -1) { foreach (var action in group) { action.schedule = new LazyValue <Schedule>(action.lazyScheduleStr, () => new Schedule(action.lazyScheduleStr)); } } else { yield return(group); } } }
internal string GetShouldProcessMessage(PrtgObject obj, int[] ids, string details = null) { if (obj == null && ids.Length == 0) { throw new ArgumentException($"{nameof(ids)} must be specified when {nameof(obj)} is null."); } if (obj != null) { var str = $"'{obj.Name}' (ID: {obj.Id}"; if (details != null) { str += $", {details})"; } else { str += ")"; } return(str); } string idStr; if (ids.Length == 1) { idStr = $"ID {ids[0]}"; } else { idStr = $"{("ID".Plural(ids))} {(string.Join(", ", ids))}"; } if (details != null) { idStr += $" ({details})"; } return(idStr); }
internal static TProperty Get <TProperty>(this PrtgObject obj, Func <TProperty> getValue) { if (obj is ILazy) { var lazy = (ILazy)obj; lock (lazy.LazyLock) { if (lazy.LazyInitialized == false) { if (lazy.LazyXml != null) { XmlDeserializer <PrtgObject> .UpdateType(lazy.LazyXml.Value, obj); } lazy.LazyInitialized = true; } } } return(getValue()); }
private void ExecuteOperation(PrtgObject obj, string url) { var server = PrtgUrl.AddUrlPrefix(client.Server); ExecuteOperation(() => Process.Start($"{server}{url}"), $"Opening {PrtgProgressCmdlet.GetTypeDescription(obj)} '{obj.Name}'"); }
/// <summary> /// Queues an object for execution after all objects have been identified. /// </summary> /// <param name="obj">The object to queue.</param> /// <param name="progressMessage">The progress message to display.</param> private void ExecuteQueueOperation(PrtgObject obj, string progressMessage) { ExecuteOperation(() => QueueObject(obj), progressMessage); }
private void QueueObject(PrtgObject obj) { objects.Add(obj); }
private void ExecuteOperation(PrtgObject obj, string url) { var server = PrtgRequestMessage.AddUrlPrefix(client.Server); ExecuteOperation(() => Process.Start($"{server}{url}"), $"Opening {obj.GetTypeDescription()} '{obj.Name}'"); }
private CloneCmdletConfig GetCmdletConfig() { CloneCmdletConfig parameters; switch (ParameterSetName) { case ParameterSet.SensorToDestination: parameters = new CloneCmdletConfig( Sensor, Name ?? Sensor.Name, GetSensors ); break; case ParameterSet.DeviceToDestination: parameters = new CloneCmdletConfig( Device, string.IsNullOrEmpty(Name) ? $"Clone of {Device.Name}" : Name, Host ?? Device.Host, GetDevices ); break; case ParameterSet.GroupToDestination: parameters = new CloneCmdletConfig( Group, Name ?? Group.Name, GetGroups ); break; case ParameterSet.TriggerToDestination: parameters = new CloneCmdletConfig(Trigger, null, null); break; case ParameterSet.TargetForSource: DestinationId = Destination.Id; parameters = new CloneCmdletConfig(sourceObj, sourceObj.Name, sourceObjResolver); break; case ParameterSet.Manual: sourceObj = client.GetObject(SourceId); if (!MyInvocation.BoundParameters.ContainsKey(nameof(DestinationId))) { DestinationId = sourceObj.ParentId; } parameters = new CloneCmdletConfig(sourceObj, Name ?? $"Clone of {sourceObj.Name}", GetObjects); break; default: throw new UnknownParameterSetException(ParameterSetName); } if (ParameterSetName != ParameterSet.TriggerToDestination) { parameters.AllowBasic = true; } return(parameters); }
private void UpdateScenarioProgress_VariableToMultipleCmdlet(ProgressStage stage, PrtgObject obj) { if (stage == ProgressStage.PreLoop) { if (ProgressManager.PipelineContainsOperation) { if (!ProgressManager.LastInChain) { SetObjectSearchProgress(ProcessingOperation.Processing); } if (ProgressManager.ExpectsContainsProgress) { ProgressManager.RemovePreviousOperation(); } } } else if (stage == ProgressStage.BeforeEach) { //When a variable to cmdlet chain contains an operation, responsibility of updating the number of records processed //"resets", and we become responsible for updating our own count again. If that operation was a multi operation cmdlet //operating in both batch and paass through mode however, we're still acting as if we've piped from a variable if (ProgressManager.PipelineContainsOperation && ProgressManager.ExpectsContainsProgress && !ProgressManager.PipeFromPrtgCmdletPostProcessMode) { ProgressManager.UpdateRecordsProcessed(ProgressManager.CurrentRecord, obj); } } else //PostLoop { UpdateScenarioProgress_VariableToSingleCmdlet(stage); } }