Ejemplo n.º 1
0
        public static Model.ChargePoint FromDataModel(Core.Data.ChargePoint source, bool loadUserComments, bool loadMediaItems, bool loadMetadataValues, bool isVerboseMode, Model.CoreReferenceData refData)
        {
            if (source == null)
            {
                return(null);
            }

            var poi = new Model.ChargePoint();

            poi.ID   = source.Id;
            poi.UUID = source.Uuid;

            //populate data provider info (full object or id only)
            if (isVerboseMode && source.DataProviderId != null)
            {
                poi.DataProvider   = refData.DataProviders.FirstOrDefault(i => i.ID == source.DataProviderId) ?? DataProvider.FromDataModel(source.DataProvider);
                poi.DataProviderID = source.DataProviderId;
            }
            else
            {
                poi.DataProviderID = source.DataProviderId;
            }

            poi.DataProvidersReference = source.DataProvidersReference;

            //populate Operator (full object or id only)
            if (isVerboseMode && source.OperatorId != null)
            {
                poi.OperatorInfo = refData.Operators.FirstOrDefault(i => i.ID == source.OperatorId) ?? OperatorInfo.FromDataModel(source.Operator);
                poi.OperatorID   = source.OperatorId;
            }
            else
            {
                poi.OperatorID = source.OperatorId;
            }

            poi.OperatorsReference = source.OperatorsReference;

            //populate usage type (full object or id only)
            if (isVerboseMode && source.UsageTypeId != null)
            {
                poi.UsageType   = refData.UsageTypes.FirstOrDefault(i => i.ID == source.UsageTypeId) ?? UsageType.FromDataModel(source.UsageType);
                poi.UsageTypeID = source.UsageTypeId;
            }
            else
            {
                poi.UsageTypeID = source.UsageTypeId;
            }

            poi.UsageCost = source.UsageCost;

            //populate address info
            if (source.AddressInfoId != null || source.AddressInfo != null)
            {
                poi.AddressInfo = AddressInfo.FromDataModel(source.AddressInfo, isVerboseMode);
            }

            poi.NumberOfPoints  = source.NumberOfPoints;
            poi.GeneralComments = source.GeneralComments;

            poi.DatePlanned       = source.DatePlanned;
            poi.DateLastConfirmed = source.DateLastConfirmed;

            //populate status type (full object or id only)
            if (isVerboseMode && source.StatusTypeId != null)
            {
                poi.StatusType   = refData.StatusTypes.FirstOrDefault(i => i.ID == source.StatusTypeId) ?? StatusType.FromDataModel(source.StatusType);
                poi.StatusTypeID = source.StatusTypeId;
            }
            else
            {
                poi.StatusTypeID = source.StatusTypeId;
            }

            poi.DateLastStatusUpdate = source.DateLastStatusUpdate;
            poi.DataQualityLevel     = source.DataQualityLevel;
            poi.DateCreated          = source.DateCreated;

            //populate submission status type (full object or id only)
            if (isVerboseMode && source.SubmissionStatusTypeId != null)
            {
                poi.SubmissionStatus       = refData.SubmissionStatusTypes.FirstOrDefault(i => i.ID == source.SubmissionStatusTypeId) ?? SubmissionStatusType.FromDataModel(source.SubmissionStatusType);
                poi.SubmissionStatusTypeID = source.SubmissionStatusTypeId;
            }
            else
            {
                poi.SubmissionStatusTypeID = source.SubmissionStatusTypeId;
            }

            poi.Connections = new List <Model.ConnectionInfo>();
            foreach (var conn in source.ConnectionInfoes)
            {
                poi.Connections.Add(ConnectionInfo.FromDataModel(conn, isVerboseMode, refData));
            }

            //loadUserComments = true;
            //loadMetadataValues = true;
            //loadMediaItems = true;

            //optionally load user comments
            if (loadUserComments)
            {
                foreach (var comment in source.UserComments.OrderByDescending(cm => cm.DateCreated))
                {
                    if (poi.UserComments == null)
                    {
                        poi.UserComments = new List <Model.UserComment>();
                    }
                    Model.UserComment com = UserComment.FromDataModel(comment, isVerboseMode, refData);
                    poi.UserComments.Add(com);
                }
            }

            if (loadMediaItems)
            {
                foreach (var mediaItem in source.MediaItems.OrderByDescending(cm => cm.DateCreated))
                {
                    if (poi.MediaItems == null)
                    {
                        poi.MediaItems = new List <Model.MediaItem>();
                    }
                    poi.MediaItems.Add(MediaItem.FromDataModel(mediaItem));
                }
            }

            if (loadMetadataValues)
            {
                foreach (var metadataValue in source.MetadataValues)
                {
                    if (poi.MetadataValues == null)
                    {
                        poi.MetadataValues = new List <Model.MetadataValue>();
                    }
                    poi.MetadataValues.Add(MetadataValue.FromDataModel(metadataValue));
                }
            }

            //mapping level of detail (priority level, lower is higher priority)
            poi.LevelOfDetail = source.LevelOfDetail;
            return(poi);
        }
Ejemplo n.º 2
0
        public static Model.ChargePoint FromDataModel(Core.Data.ChargePoint source, bool loadUserComments, bool loadMediaItems, bool loadMetadataValues, bool isVerboseMode)
        {
            if (source == null)
            {
                return(null);
            }

            var poi = new Model.ChargePoint();

            poi.ID   = source.ID;
            poi.UUID = source.UUID;

            //populate data provider info (full object or id only)
            if (isVerboseMode && source.DataProvider != null)
            {
                poi.DataProvider   = DataProvider.FromDataModel(source.DataProvider);
                poi.DataProviderID = source.DataProvider.ID;
            }
            else
            {
                poi.DataProviderID = source.DataProviderID;
            }

            poi.DataProvidersReference = source.DataProvidersReference;

            //populate Operator (full object or id only)
            if (isVerboseMode && source.Operator != null)
            {
                poi.OperatorInfo = OperatorInfo.FromDataModel(source.Operator);
                poi.OperatorID   = source.Operator.ID;
            }
            else
            {
                poi.OperatorID = source.OperatorID;
            }

            poi.OperatorsReference = source.OperatorsReference;

            //populate usage type (full object or id only)
            if (isVerboseMode && source.UsageType != null)
            {
                poi.UsageType   = UsageType.FromDataModel(source.UsageType);
                poi.UsageTypeID = source.UsageType.ID;
            }
            else
            {
                poi.UsageTypeID = source.UsageTypeID;
            }

            poi.UsageCost = source.UsageCost;

            //populate address info
            if (source.AddressInfo != null)
            {
                poi.AddressInfo = AddressInfo.FromDataModel(source.AddressInfo, isVerboseMode);
            }

            poi.NumberOfPoints  = source.NumberOfPoints;
            poi.GeneralComments = source.GeneralComments;

            poi.DatePlanned       = source.DatePlanned;
            poi.DateLastConfirmed = source.DateLastConfirmed;

            //populate status type (full object or id only)
            if (isVerboseMode && source.StatusType != null)
            {
                poi.StatusType   = StatusType.FromDataModel(source.StatusType);
                poi.StatusTypeID = source.StatusType.ID;
            }
            else
            {
                poi.StatusTypeID = source.StatusTypeID;
            }

            poi.DateLastStatusUpdate = source.DateLastStatusUpdate;
            poi.DataQualityLevel     = source.DataQualityLevel;
            poi.DateCreated          = source.DateCreated;

            //populate submission status type (full object or id only)
            if (isVerboseMode && source.SubmissionStatusType != null)
            {
                poi.SubmissionStatus       = SubmissionStatusType.FromDataModel(source.SubmissionStatusType);
                poi.SubmissionStatusTypeID = source.SubmissionStatusType.ID;
            }
            else
            {
                poi.SubmissionStatusTypeID = source.SubmissionStatusTypeID;
            }

            poi.Connections = new List <Model.ConnectionInfo>();
            foreach (var conn in source.Connections)
            {
                poi.Connections.Add(ConnectionInfo.FromDataModel(conn, isVerboseMode));
            }

            //loadUserComments = true;
            //loadMetadataValues = true;
            //loadMediaItems = true;

            //optionally load user comments
            if (loadUserComments)
            {
                foreach (var comment in source.UserComments.OrderByDescending(cm => cm.DateCreated))
                {
                    if (poi.UserComments == null)
                    {
                        poi.UserComments = new List <Model.UserComment>();
                    }
                    Model.UserComment com = UserComment.FromDataModel(comment, isVerboseMode);
                    poi.UserComments.Add(com);
                }
            }

            if (loadMediaItems)
            {
                foreach (var mediaItem in source.MediaItems)
                {
                    if (poi.MediaItems == null)
                    {
                        poi.MediaItems = new List <Model.MediaItem>();
                    }
                    poi.MediaItems.Add(MediaItem.FromDataModel(mediaItem));
                }
            }

            if (loadMetadataValues)
            {
                foreach (var metadataValue in source.MetadataValues)
                {
                    if (poi.MetadataValues == null)
                    {
                        poi.MetadataValues = new List <Model.MetadataValue>();
                    }
                    poi.MetadataValues.Add(MetadataValue.FromDataModel(metadataValue));
                }
            }
            return(poi);
        }
Ejemplo n.º 3
0
        public static Model.ConnectionInfo FromDataModel(Core.Data.ConnectionInfo s, bool isVerboseMode)
        {
            if (s == null)
            {
                return(null);
            }

            var connectionInfo = new Model.ConnectionInfo()
            {
                ID        = s.ID,
                Reference = s.Reference,
                Amps      = s.Amps,
                Voltage   = s.Voltage,
                PowerKW   = s.PowerKW,
                Quantity  = s.Quantity,
                Comments  = s.Comments
            };

            //connection type (full object or id only)
            if (isVerboseMode)
            {
                connectionInfo.ConnectionType   = ConnectionType.FromDataModel(s.ConnectionType);
                connectionInfo.ConnectionTypeID = (s.ConnectionType != null ? s.ConnectionType.ID : s.ConnectionTypeID);
            }
            else
            {
                connectionInfo.ConnectionTypeID = s.ConnectionTypeID;
            }

            //status type (full object or id only)
            if (isVerboseMode && (s.StatusTypeID != null || s.StatusType != null))
            {
                connectionInfo.StatusType   = StatusType.FromDataModel(s.StatusType);
                connectionInfo.StatusTypeID = s.StatusTypeID;
            }
            else
            {
                if (s.StatusTypeID != null)
                {
                    connectionInfo.StatusTypeID = s.StatusTypeID;
                }
            }

            //charging level type (full object or id only)
            if (isVerboseMode && (s.LevelTypeID != null || s.ChargerType != null))
            {
                connectionInfo.Level   = ChargerType.FromDataModel(s.ChargerType);
                connectionInfo.LevelID = s.ChargerType.ID;
            }
            else
            {
                if (s.LevelTypeID != null)
                {
                    connectionInfo.LevelID = s.LevelTypeID;
                }
            }

            if (isVerboseMode && (s.CurrentTypeID != null || s.CurrentType != null))
            {
                connectionInfo.CurrentType   = CurrentType.FromDataModel(s.CurrentType);
                connectionInfo.CurrentTypeID = s.CurrentType.ID;
            }
            else
            {
                if (s.CurrentTypeID != null)
                {
                    connectionInfo.CurrentTypeID = s.CurrentTypeID;
                }
            }

            return(connectionInfo);
        }