Esempio n. 1
0
 public ImageProfileController()
 {
     _imageProfileService = new ServiceImageProfile();
     _auditLogService     = new ServiceAuditLog();
     _userId = Convert.ToInt32(((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == "user_id")
                               .Select(c => c.Value).SingleOrDefault());
 }
Esempio n. 2
0
 public CreateTaskArguments(EntityComputer computer, ImageProfileWithImage imageProfile, string direction)
 {
     _computer             = computer;
     _imageProfile         = imageProfile;
     _direction            = direction;
     _activeTaskArguments  = new StringBuilder();
     _imageProfileServices = new ServiceImageProfile();
 }
Esempio n. 3
0
        public HttpResponseMessage GetImagingFile(DtoImageFileRequest fileRequest)
        {
            var guid          = ConfigurationManager.AppSettings["ComServerUniqueId"];
            var thisComServer = new ServiceClientComServer().GetServerByGuid(guid);

            if (thisComServer == null)
            {
                Logger.Error($"Com Server With Guid {guid} Not Found");
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            var profile = new ServiceImageProfile().ReadProfile(fileRequest.profileId);

            if (profile == null)
            {
                Logger.Error($"Image Profile Not Found: {fileRequest.profileId}");
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            var maxBitRate = thisComServer.ImagingMaxBps;
            var basePath   = thisComServer.LocalStoragePath;

            var fullPath = Path.Combine(basePath, "images", profile.Image.Name, $"hd{fileRequest.hdNumber}",
                                        fileRequest.fileName);

            if (File.Exists(fullPath))
            {
                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                try
                {
                    var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
                    if (maxBitRate == 0)
                    {
                        result.Content = new StreamContent(stream);
                    }
                    else
                    {
                        Stream throttledStream = new ThrottledStream(stream, maxBitRate);
                        result.Content = new StreamContent(throttledStream);
                    }

                    result.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
                    result.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("inline");
                    result.Content.Headers.ContentDisposition.FileName = fileRequest.fileName;
                    return(result);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.Message);
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.NotFound));
        }
Esempio n. 4
0
        public string Upload(int taskId, string fileName, int profileId, int userId, string hdNumber)
        {
            //no need to find and call com server, client should already be directly communicating with the correct imaging server
            var guid = ConfigurationManager.AppSettings["ComServerUniqueId"];

            _thisComServer = new ServiceClientComServer().GetServerByGuid(guid);

            if (_thisComServer == null)
            {
                log.Error($"Com Server With Guid {guid} Not Found");
                return("0");
            }

            var appPath = Path.Combine(HttpContext.Current.Server.MapPath("~"), "private", "apps");

            var task = new ServiceActiveImagingTask().GetTask(taskId);

            if (task == null)
            {
                return("0");
            }

            var imageProfile = new ServiceImageProfile().ReadProfile(profileId);

            var uploadPort = new ServicePort().GetNextPort(task.ComServerId);

            var path = _thisComServer.LocalStoragePath;


            try
            {
                var dir = Path.Combine(path, "images", imageProfile.Image.Name, $"hd{ hdNumber}");
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            catch (Exception ex)
            {
                log.Error("Could Not Create Directory");
                log.Error(ex.Message);
                return("0");
            }

            path = Path.Combine(path, "images", imageProfile.Image.Name, $"hd{hdNumber}", fileName);
            string arguments    = " /c \"";
            var    receiverPath = Path.Combine(appPath, "udp-receiver.exe");

            arguments += $"{receiverPath}\" --portbase {uploadPort}";
            arguments += $" --interface {_thisComServer.ImagingIp} --file {path}";

            var pid = StartReceiver(arguments, imageProfile.Image.Name);
            //use multicast session even though it's not a multicast, uploads still use udpcast
            var activeMulticast = new EntityActiveMulticastSession();

            if (pid != 0)
            {
                activeMulticast.ImageProfileId = imageProfile.Id;
                activeMulticast.Name           = imageProfile.Image.Name;
                activeMulticast.Pid            = pid;
                activeMulticast.Port           = uploadPort;
                activeMulticast.ComServerId    = _thisComServer.Id;
                activeMulticast.UserId         = userId;
                activeMulticast.UploadTaskId   = task.Id;

                var result = new ServiceActiveMulticastSession().AddActiveMulticastSession(activeMulticast);
                if (result)
                {
                    return(uploadPort.ToString());
                }
            }
            return("0");
        }