Пример #1
0
        // Map service model to API model
        public static SimulationApiModel FromServiceModel(
            Simulation value)
        {
            if (value == null)
            {
                return(null);
            }

            var result = new SimulationApiModel
            {
                ETag                            = value.ETag,
                Id                              = value.Id,
                Name                            = value.Name,
                Description                     = value.Description,
                Enabled                         = value.Enabled,
                Running                         = value.ShouldBeRunning,
                ActiveNow                       = value.IsActiveNow,
                DeleteDevicesOnce               = value.DeleteDevicesOnce,
                DevicesDeletionComplete         = value.DevicesDeletionComplete,
                DeleteDevicesWhenSimulationEnds = value.DeleteDevicesWhenSimulationEnds,
                IotHubs                         = new List <SimulationIotHub>(),
                ReplayFileId                    = value.ReplayFileId,
                ReplayFileIndefinitely          = value.ReplayFileRunIndefinitely
            };

            foreach (var iotHubConnectionString in value.IotHubConnectionStrings)
            {
                var iotHub = new SimulationIotHub {
                    ConnectionString = iotHubConnectionString
                };
                result.IotHubs.Add(iotHub);
            }

            // Ignore the date if the simulation doesn't have a start time
            if (value.StartTime.HasValue && !value.StartTime.Value.Equals(DateTimeOffset.MinValue))
            {
                result.StartTime = value.StartTime?.ToString(DATE_FORMAT);
            }

            // Ignore the date if the simulation doesn't have an end time
            if (value.EndTime.HasValue && !value.EndTime.Value.Equals(DateTimeOffset.MaxValue))
            {
                result.EndTime = value.EndTime?.ToString(DATE_FORMAT);
            }

            // Ignore the date if the simulation doesn't have an end time
            if (value.StoppedTime.HasValue && !value.StoppedTime.Value.Equals(DateTimeOffset.MaxValue))
            {
                result.StoppedTime = value.StoppedTime?.ToString(DATE_FORMAT);
            }

            result.DeviceModels = SimulationDeviceModelRef.FromServiceModel(value.DeviceModels);
            result.Statistics   = GetSimulationStatistics(value);
            result.RateLimits   = SimulationRateLimits.FromServiceModel(value.RateLimits);

            result.created  = value.Created;
            result.modified = value.Modified;

            return(result);
        }
        // Default constructor used by web service requests
        public SimulationApiModel()
        {
            this.Id          = string.Empty;
            this.Name        = string.Empty;
            this.Description = string.Empty;

            // When unspecified, a simulation is enabled
            this.Enabled = true;
            this.Running = false;
            this.DeleteDevicesWhenSimulationEnds = false;
            this.ActiveNow = false;
            this.DevicesDeletionComplete = false;
            this.IotHubs      = new List <SimulationIotHub>();
            this.StartTime    = null;
            this.EndTime      = null;
            this.StoppedTime  = null;
            this.DeviceModels = new List <SimulationDeviceModelRef>();
            this.RateLimits   = new SimulationRateLimits();
        }