public CachedImage(string id, Image image) { Id = id; FileLocations.CreateStorageDirectory(); try { string filename = System.IO.Path.ChangeExtension(Id, ".image"); Path = System.IO.Path.Combine(FileLocations.Storage, filename); image.Save(Path); } catch (Exception ex) { Logger.Log("Error Adding Image to Cache :: " + ex.Message, LogLineType.Error); } }
public CachedImage(string id, Image image) { Id = id; FileLocations.CreateStorageDirectory(); try { string filename = System.IO.Path.ChangeExtension(Id, ".image"); Path = System.IO.Path.Combine(FileLocations.Storage, filename); if (!File.Exists(Path)) { image.Save(Path); } } catch (Exception ex) { logger.Error(ex); } }
private void UploadDeviceImage_Worker(object o) { if (o != null) { var info = (ImageInfo)o; string fileId = null; if (info.UserConfig != null) { string contentType = null; try { string ext = Path.GetExtension(info.FileId); if (ext == "jpg" || ext == ".jpg") { contentType = "image/jpeg"; } else if (ext == "png" || ext == ".png") { contentType = "image/png"; } else if (ext == "gif" || ext == ".gif") { contentType = "image/gif"; } var img = System.Drawing.Image.FromFile(info.FileId); if (img != null) { if (img.Width > img.Height) { img = Image_Functions.SetImageSize(img, 300, 300); } else { img = Image_Functions.SetImageSize(img, 0, 150); } string tempPath = Path.ChangeExtension(String_Functions.RandomString(20), ext); tempPath = Path.Combine(FileLocations.TrakHoundTemp, tempPath); // Make sure Temp directory exists FileLocations.CreateTempDirectory(); img.Save(tempPath); img.Dispose(); var fileData = new HTTP.FileContentData("uploadImage", tempPath, contentType); var fileInfos = Files.Upload(currentUser, fileData); if (fileInfos != null && fileInfos.Length > 0) { fileId = fileInfos[0].Id; } } } catch (Exception ex) { logger.Error(ex); } } else { string filename = Path.ChangeExtension(Guid.NewGuid().ToString(), ".image"); string destinationPath = Path.Combine(FileLocations.Storage, filename); FileLocations.CreateStorageDirectory(); File.Copy(info.FileId, destinationPath); fileId = filename; } Dispatcher.BeginInvoke(new Action <string>(UploadDeviceImage_GUI), System.Windows.Threading.DispatcherPriority.Background, new object[] { fileId }); } }