public GetServersResult GetServers(GetServersRequest request)
        {
            using (var context = new DataAccessContext())
            {
                List <Device> devices;
                if (!String.IsNullOrEmpty(request.Name))
                {
                    var device = context.GetDeviceBroker().GetDeviceByName(request.Name);
                    devices = new List <Device> ();
                    if (device != null)
                    {
                        devices.Add(device);
                    }
                }
                else if (!String.IsNullOrEmpty(request.AETitle))
                {
                    devices = context.GetDeviceBroker().GetDevicesByAETitle(request.AETitle);
                }
                else
                {
                    devices = context.GetDeviceBroker().GetDevices();
                }

                var converted = devices.Select(d => d.ToDataContract()).ToList();
                return(new GetServersResult {
                    ServerEntries = converted
                });
            }
        }
 public DeleteAllServersResult DeleteAllServers(DeleteAllServersRequest request)
 {
     using (var scope = new DataAccessContext())
     {
         var broker = scope.GetDeviceBroker();
         broker.DeleteAllDevices();
         scope.Commit();
         return(new DeleteAllServersResult());
     }
 }
        public DeleteServerResult DeleteServer(DeleteServerRequest request)
        {
            using (var context = new DataAccessContext())
            {
                var broker   = context.GetDeviceBroker();
                var existing = broker.GetDeviceByName(request.ServerEntry.Server.Name);
                if (existing == null)
                {
                    throw new ArgumentException();
                }

                broker.DeleteDevice(existing);

                context.Commit();
                return(new DeleteServerResult());
            }
        }
        public AddServerResult AddServer(AddServerRequest request)
        {
            using (var context = new DataAccessContext())
            {
                var broker = context.GetDeviceBroker();

                var existing = broker.GetDeviceByName(request.ServerEntry.Server.Name);
                if (existing != null)
                {
                    throw new ArgumentException(); // TODO (CR Jun 2012): Should set the message, but it's just re-interpreted as a Fault.
                }
                var device = request.ServerEntry.ToDevice();
                broker.AddDevice(device);

                context.Commit();

                return(new AddServerResult {
                    ServerEntry = device.ToDataContract()
                });
            }
        }
        public UpdateServerResult UpdateServer(UpdateServerRequest request)
        {
            using (var context = new DataAccessContext())
            {
                var broker = context.GetDeviceBroker();

                var existing = broker.GetDeviceByName(request.ServerEntry.Server.Name);
                if (existing == null)
                {
                    throw new ArgumentException();
                }

                var ae = request.ServerEntry.Server;

                existing.AETitle        = ae.AETitle;
                existing.HostName       = ae.ScpParameters.HostName;
                existing.Port           = ae.ScpParameters.Port;
                existing.Location       = ae.Location;
                existing.Description    = ae.Description;
                existing.IsPriorsServer = request.ServerEntry.IsPriorsServer;

                if (ae.StreamingParameters != null)
                {
                    existing.StreamingHeaderPort = ae.StreamingParameters.HeaderServicePort;
                    existing.StreamingImagePort  = ae.StreamingParameters.WadoServicePort;
                }
                else
                {
                    existing.StreamingHeaderPort = null;
                    existing.StreamingImagePort  = null;
                }

                existing.ExtensionData = request.ServerEntry.Data == null
                                            ? null : Serializer.SerializeServerExtensionData(request.ServerEntry.Data);
                context.Commit();
                return(new UpdateServerResult {
                    ServerEntry = existing.ToDataContract()
                });
            }
        }