Esempio n. 1
0
        public ImageFileData GetImageByName(string request_file_name)
        {
            Log("GetImageByName");
            try
            {
                if (string.IsNullOrEmpty(request_file_name))
                    throw new ArgumentException("Invalid requested file name!", request_file_name);

                IEnumerable<FileInfo> allImageFilesList = GetAllImageFiles();
                FileInfo requestedImageFile = null;
                requestedImageFile = allImageFilesList.SingleOrDefault(f => f.Name == request_file_name);
                if (requestedImageFile == null)
                    throw new ArgumentException("File that you has requested doesn't exist!", request_file_name);

                ImageFileData imageFileData = new ImageFileData() { FileName = requestedImageFile.Name, LastDateModified = requestedImageFile.LastWriteTime };
                byte[] imageBytes = File.ReadAllBytes(requestedImageFile.FullName);
                imageFileData.ImageData = imageBytes;
                return imageFileData;
            }
            catch (Exception e)
            {
                ServerFault fault = new ServerFault();
                fault.FriendlyDiscription = "Some problems just has been occured on service host!";
                fault.Discription = e.Message;
                throw new FaultException<ServerFault>(fault, new FaultReason(fault.Discription));
            }
        }
Esempio n. 2
0
        public IEnumerable<ImageFileData> GetAllImagesList(bool withFilesData)
        {
            Log("GetAllImagesList");
            List<ImageFileData> images_collection = new List<ImageFileData>();
            try
            {
                foreach (FileInfo fileInfo in GetAllImageFiles())
                {
                    ImageFileData imageFileData = new ImageFileData() { FileName = fileInfo.Name, LastDateModified = fileInfo.LastWriteTime };
                    byte[] imageBytes = null;
                    if (withFilesData)
                        imageBytes = File.ReadAllBytes(fileInfo.FullName);
                    imageFileData.ImageData = imageBytes;
                    images_collection.Add(imageFileData);
                }
            }
            catch (Exception e)
            {
                ServerFault fault = new ServerFault();
                fault.FriendlyDiscription = "Some problems just has been occured on server!";
                fault.Discription = e.Message;
                throw new FaultException<ServerFault>(fault, new FaultReason(fault.Discription));
            }

            AddUpdateToSessionTable(images_collection.Count);
            return images_collection;
        }
        public ImageFileData GetImageByName(string request_file_name)
        {
            Log("GetImageByName");
            try
            {
                if (string.IsNullOrEmpty(request_file_name))
                    throw new FaultException<InvalidFileName>(new InvalidFileName { InvalidName = request_file_name }, new FaultReason (string.Empty));

                IEnumerable<FileInfo> allImageFilesList = GetAllImageFiles();
                FileInfo requestedImageFile = null;
                requestedImageFile = allImageFilesList.SingleOrDefault(f => f.Name == request_file_name);
                if (requestedImageFile == null)
                    throw new FaultException<FileNotFound>(new FileNotFound { FileName = request_file_name }, new FaultReason(string.Empty));

                ImageFileData imageFileData = new ImageFileData() { FileName = requestedImageFile.Name, LastDateModified = requestedImageFile.LastWriteTime };
                byte[] imageBytes = File.ReadAllBytes(requestedImageFile.FullName);
                imageFileData.ImageData = imageBytes;
                return imageFileData;
            }

            catch (FaultException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                HostStorageException fault = new HostStorageException();
                fault.Description = "Prodlems with images storage on host";
                throw new FaultException<HostStorageException>(fault, new FaultReason(string.Empty));
            }
        }
        public IEnumerable<ImageFileData> GetAllImagesList(bool withFilesData)
        {
            Log("GetAllImagesList");
            List<ImageFileData> images_collection = new List<ImageFileData>();
            try
            {
                IEnumerable<FileInfo> allImageFiles = GetAllImageFiles();
                if (allImageFiles == null)
                    return null;

                foreach (FileInfo fileInfo in allImageFiles)
                {
                    ImageFileData imageFileData = new ImageFileData() { FileName = fileInfo.Name, LastDateModified = fileInfo.LastWriteTime };
                    byte[] imageBytes = null;
                    if (withFilesData)
                        imageBytes = File.ReadAllBytes(fileInfo.FullName);
                    imageFileData.ImageData = imageBytes;
                    images_collection.Add(imageFileData);
                }
            }
            catch (Exception)
            {
                HostStorageException fault = new HostStorageException();
                fault.Description = "Prodlems with images storage on host";
                throw new FaultException<HostStorageException>(fault, new FaultReason (string.Empty));
            }
            return images_collection;
        }
        public void UploadImage(byte[] imageData, string imageName)
        {
            IEnumerable<ImageFileData> allImagesFileData = GetAllImagesInfo(false);
            if (allImagesFileData == null)
                return;
            if (allImagesFileData.SingleOrDefault(p => p.FileName == imageName) != null)
                faultProcessor.ProcessMessage("Image with the same name already exists");

            ImageFileData data = new ImageFileData() { FileName = imageName, LastDateModified = DateTime.Now, ImageData = imageData };
            try
            {
                ImageServiceProxy.UploadImage(data);
            }
            catch (Exception ex)
            {
                faultProcessor.ProcessException(ex);
                return;
            }
        }
Esempio n. 6
0
        public void UploadImage(ImageFileData uploading_image)
        {
            Log("UploadImage");
            try
            {
                if (string.IsNullOrEmpty(uploading_image.FileName))
                    throw new ArgumentException("Invalid upldoading file name", uploading_image.FileName);

                if (uploading_image.ImageData == null || uploading_image.ImageData.Length == 0)
                    throw new ArgumentException("Uploaded file-data is empty!");

                string newImageFileName = uploading_image.FileName;
                string uploadFolder = ConfigurationManager.AppSettings["UploadFolder"];
                string newImageFilePath = Path.Combine(uploadFolder, newImageFileName);

                try
                {
                    using (Stream targetStream = new FileStream(newImageFilePath, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        targetStream.Write(uploading_image.ImageData, 0, uploading_image.ImageData.Length);
                    }
                }
                catch (IOException)
                {
                    throw new IOException("Error writing new file or overwriting existed file");
                }
            }
            catch (Exception e)
            {
                ServerFault fault = new ServerFault();
                fault.FriendlyDiscription = "Some problems just has been occured on service host!";
                fault.Discription = e.Message;
                throw new FaultException<ServerFault>(fault, new FaultReason(fault.Discription));
            }
        }
        public void UploadImage(ImageFileData uploading_image)
        {
            Log("UploadImage");
            try
            {
                if (string.IsNullOrEmpty(uploading_image.FileName))
                    throw new ArgumentException("Invalid upldoading file name", uploading_image.FileName);

                if (uploading_image.ImageData == null || uploading_image.ImageData.Length == 0)
                    throw new ArgumentException("Uploaded file-data is empty!");

                string newImageFileName = uploading_image.FileName;
                string uploadFolder = ConfigurationManager.AppSettings["UploadFolder"];
                string newImageFilePath = Path.Combine(uploadFolder, newImageFileName);

                if (File.Exists(newImageFilePath))
                    throw new FaultException<FileAlreadyExists>(new FileAlreadyExists { FileName = newImageFileName }, new FaultReason(string.Empty));

                using (Stream targetStream = new FileStream(newImageFilePath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    targetStream.Write(uploading_image.ImageData, 0, uploading_image.ImageData.Length);
                }
            }

            catch (FaultException e)
            {
                throw e;
            }
            catch (Exception)
            {
                HostStorageException fault = new HostStorageException();
                fault.Description = "Prodlems with images storage on host";
                throw new FaultException<HostStorageException>(fault, new FaultReason(fault.Description));
            }
        }
        public void UploadImage(byte[] imageData, string imageName)
        {
            IEnumerable<ImageFileData> allImagesFileData = GetAllImagesInfo(false);
            if (allImagesFileData == null)
                return;

            ImageFileData data = new ImageFileData() { FileName = imageName, LastDateModified = DateTime.Now, ImageData = imageData };
            try
            {
                ImageServiceProxy.UploadImage(data);
            }
            catch (Exception ex)
            {
                faultProcessor.ProcessException(ex);
                return;
            }
        }