public static void DeletePhoto(string tmpDirName)
        {
            lock (locker)
            {
                var photoDirectory = BuildFileTmpDirectory(tmpDirName);
                var store          = Global.GetStore();

                if (store.IsDirectory(photoDirectory))
                {
                    store.DeleteFiles(photoDirectory, "*", false);
                }
            }
        }
Exemplo n.º 2
0
        private static String ResizeToBigSize(byte[] imageData, int contactID)
        {
            var resizeWorkerItem = new ResizeWorkerItem
            {
                ContactID       = contactID,
                RequireFotoSize = new[] { _bigSize },
                ImageData       = imageData,
                DataStore       = Global.GetStore()
            };

            ExecResizeImage(resizeWorkerItem);

            return(FromCache(contactID, _bigSize));
        }
        public static void DeletePhoto(bool recursive)
        {
            var photoDirectory = BuildFileDirectory();
            var store          = Global.GetStore();

            lock (_synchronizedObj)
            {
                if (store.IsDirectory(photoDirectory))
                {
                    store.DeleteFiles(photoDirectory, "*", recursive);
                    if (recursive)
                    {
                        store.DeleteDirectory(photoDirectory);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public ImportDataOperation(EntityType entityType, String CSVFileURI, String importSettingsJSON)
        {
            _CSVFileURI = CSVFileURI;
            _dataStore  = Global.GetStore();
            _tenantID   = TenantProvider.CurrentTenantID;
            _daoFactory = Global.DaoFactory;
            _entityType = entityType;

            Id = String.Format("{0}_{1}", TenantProvider.CurrentTenantID, (int)_entityType);

            _log = LogManager.GetLogger("ASC.CRM");

            if (!String.IsNullOrEmpty(importSettingsJSON))
            {
                _importSettings = new ImportCSVSettings(importSettingsJSON);
            }
        }
        public static void TryUploadPhotoFromTmp(int contactID, bool isNewContact, string tmpDirName)
        {
            var directoryTmpPath = String.IsNullOrEmpty(tmpDirName) ? BuildFileTmpDirectory(contactID) : BuildFileTmpDirectory(tmpDirName);
            var directoryPath    = BuildFileDirectory(contactID);
            var dataStore        = Global.GetStore();

            if (!dataStore.IsDirectory(directoryTmpPath))
            {
                return;
            }

            try
            {
                if (dataStore.IsDirectory(directoryPath))
                {
                    DeletePhoto(contactID, false, null, false);
                }
                foreach (var photoSize in new[] { _bigSize, _mediumSize, _smallSize })
                {
                    var photoTmpPath = FromDataStoreRelative(isNewContact ? 0 : contactID, photoSize, true, tmpDirName);

                    var imageExtension = Path.GetExtension(photoTmpPath);

                    var photoPath = String.Concat(directoryPath, BuildFileName(contactID, photoSize), imageExtension).TrimStart('/');

                    byte[] data;
                    using (var photoTmpStream = dataStore.GetReadStream(photoTmpPath))
                    {
                        data = Global.ToByteArray(photoTmpStream);
                    }
                    using (var fileStream = new MemoryStream(data))
                    {
                        var photoUri = dataStore.Save(photoPath, fileStream).ToString();
                        photoUri = String.Format("{0}?cd={1}", photoUri, DateTime.UtcNow.Ticks);
                        ToCache(contactID, photoUri, photoSize);
                    }
                }
                DeletePhoto(contactID, true, tmpDirName, true);
            }
            catch (Exception ex)
            {
                log4net.LogManager.GetLogger("ASC.CRM").ErrorFormat("TryUploadPhotoFromTmp for contactID={0} failed witth error: {1}", contactID, ex);
                return;
            }
        }
        private static String FromDataStore(Size photoSize, String tmpDirName)
        {
            var directoryPath = BuildFileTmpDirectory(tmpDirName);

            if (!Global.GetStore().IsDirectory(directoryPath))
            {
                return(String.Empty);
            }

            var filesURI = Global.GetStore().ListFiles(directoryPath, BuildFileName(0, photoSize) + "*", false);

            if (filesURI.Length == 0)
            {
                return(String.Empty);
            }

            return(filesURI[0].ToString());
        }
        public ImportDataOperation(EntityType entityType, String CSVFileURI, String importSettingsJSON)
        {
            _CSVFileURI = CSVFileURI;
            _dataStore  = Global.GetStore();
            _tenantID   = TenantProvider.CurrentTenantID;
            _entityType = entityType;
            _author     = SecurityContext.CurrentAccount;

            _notifyClient = NotifyClient.Instance;

            Id = String.Format("{0}_{1}", TenantProvider.CurrentTenantID, (int)_entityType);

            _log = LogManager.GetLogger("ASC.CRM");

            if (!String.IsNullOrEmpty(importSettingsJSON))
            {
                _importSettings = new ImportCSVSettings(importSettingsJSON);
            }
        }
        private static PhotoData FromDataStore(Size photoSize, String tmpDirName)
        {
            var directoryPath = BuildFileTmpDirectory(tmpDirName);

            if (!Global.GetStore().IsDirectory(directoryPath))
            {
                return(null);
            }

            var filesURI = Global.GetStore().ListFiles(directoryPath, BuildFileName(0, photoSize) + "*", false);

            if (filesURI.Length == 0)
            {
                return(null);
            }

            return(new PhotoData {
                Url = filesURI[0].ToString(), Path = tmpDirName
            });
        }
        private static String FromDataStoreRelative(int contactID, Size photoSize, Boolean isTmpDir, String tmpDirName)
        {
            var directoryPath = !isTmpDir
                                    ? BuildFileDirectory(contactID)
                                    : (String.IsNullOrEmpty(tmpDirName) ? BuildFileTmpDirectory(contactID) : BuildFileTmpDirectory(tmpDirName));

            var filesPaths = Global.GetStore().ListFilesRelative("", directoryPath, BuildFileName(contactID, photoSize) + "*", false);

            if (filesPaths.Length == 0 && photoSize == _bigSize)
            {
                filesPaths = Global.GetStore().ListFilesRelative("", directoryPath, BuildFileName(contactID, _oldBigSize) + "*", false);
            }

            if (filesPaths.Length == 0)
            {
                return(String.Empty);
            }

            return(Path.Combine(directoryPath, filesPaths[0]));
        }
Exemplo n.º 10
0
        private static void ExecGenerateThumbnail(byte[] imageData, int contactID)
        {
            var resizeWorkerItem = new ResizeWorkerItem
            {
                ContactID       = contactID,
                RequireFotoSize = new[] { _mediumSize, _smallSize },
                ImageData       = imageData,
                DataStore       = Global.GetStore()
            };

            if (!ResizeQueue.GetItems().Contains(resizeWorkerItem))
            {
                ResizeQueue.Add(resizeWorkerItem);
            }

            if (!ResizeQueue.IsStarted)
            {
                ResizeQueue.Start(ExecResizeImage);
            }
        }
Exemplo n.º 11
0
        public FileUploadResult ProcessUploadFake(string fileTemp, string importSettingsJSON)
        {
            var fileUploadResult = new FileUploadResult();

            if (String.IsNullOrEmpty(fileTemp) || String.IsNullOrEmpty(importSettingsJSON))
            {
                return(fileUploadResult);
            }

            if (!Global.GetStore().IsFile("temp", fileTemp))
            {
                return(fileUploadResult);
            }

            JObject jObject;

            //Read contents
            using (Stream storeStream = Global.GetStore().GetReadStream("temp", fileTemp))
            {
                using (var CSVFileStream = new MemoryStream())
                {
                    //Copy
                    var buffer = new byte[4096];
                    int readed;
                    while ((readed = storeStream.Read(buffer, 0, 4096)) != 0)
                    {
                        CSVFileStream.Write(buffer, 0, readed);
                    }
                    CSVFileStream.Position = 0;

                    jObject = ImportFromCSV.GetInfo(CSVFileStream, importSettingsJSON);
                }
            }

            jObject.Add("assignedPath", fileTemp);

            fileUploadResult.Success = true;
            fileUploadResult.Data    = Global.EncodeTo64(jObject.ToString());

            return(fileUploadResult);
        }
        public static void DeletePhoto(int contactID, bool isTmpDir, string tmpDirName, bool recursive)
        {
            if (contactID == 0)
            {
                throw new ArgumentException();
            }

            lock (locker)
            {
                ResizeQueue.GetItems().Where(item => item.ContactID == contactID)
                .All(item =>
                {
                    ResizeQueue.Remove(item);
                    return(true);
                });

                var photoDirectory = !isTmpDir
                                         ? BuildFileDirectory(contactID)
                                         : (String.IsNullOrEmpty(tmpDirName) ? BuildFileTmpDirectory(contactID) : BuildFileTmpDirectory(tmpDirName));

                var store = Global.GetStore();

                if (store.IsDirectory(photoDirectory))
                {
                    store.DeleteFiles(photoDirectory, "*", recursive);
                    if (recursive)
                    {
                        store.DeleteDirectory(photoDirectory);
                    }
                }

                if (!isTmpDir)
                {
                    RemoveFromCache(contactID);
                }
            }
        }
        public static String UploadLogo(byte[] imageData, ImageFormat imageFormat)
        {
            var photoPath = BuildFilePath("." + Global.GetImgFormatName(imageFormat));

            return(ExecResizeImage(imageData, OrganisationLogoSize, Global.GetStore(), photoPath));
        }