Exemple #1
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;
        }
Exemple #2
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));
            }
        }
Exemple #3
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));
            }
        }
Exemple #4
0
 private int GetImagesCount()
 {
     int imagesCount = 0;
     try
     {
         imagesCount = (new List<FileInfo>(GetAllImageFiles())).Count;
     }
     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));
     }
     return imagesCount;
 }