コード例 #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,
                Enabled = value.Enabled,
                IotHub  = new SimulationIotHub(value.IotHubConnectionString)
            };

            // 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);
            }

            result.DeviceModels = SimulationDeviceModelRef.FromServiceModel(value.DeviceModels);
            result.version      = value.Version;
            result.created      = value.Created;
            result.modified     = value.Modified;

            return(result);
        }
コード例 #2
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);
        }
コード例 #3
0
        // Map service model to API model
        public static SimulationApiModel FromServiceModel(
            Simulation value,
            IServicesConfig servicesConfig,
            IDeploymentConfig deploymentConfig,
            IIotHubConnectionStringManager connectionStringManager,
            ISimulationRunner simulationRunner,
            IRateLimiting rateReporter)
        {
            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,
                StartTime   = value.StartTime.ToString(),
                EndTime     = value.EndTime.ToString(),
                StoppedTime = value.StoppedTime.ToString(),
                IotHubs     = new List <SimulationIotHub>()
            };

            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   = SimulationStatistics.FromServiceModel(value.Statistics);
            result.created      = value.Created;
            result.modified     = value.Modified;

            result.AppendHubPropertiesAndStatistics(servicesConfig, deploymentConfig, connectionStringManager, simulationRunner, rateReporter);

            return(result);
        }