Пример #1
0
        private JObject AddFile(FileModel fileModel, string baseFolderPath, IDBService dbProxy, IKeyValueStorage keyValueStorage, Func <string, bool> logger)
        {
            if (fileModel.IsAdded)
            {
                JObject fileData = new JObject();
                var     path     = string.Concat(baseFolderPath, "\\", fileModel.file_paths.First());

                using (var image = ImageGalleryHelper.GetImageBitmapFromFile(path))
                {
                    fileData = ImageGalleryHelper.CreateFileDataJObject(fileModel, path, image, keyValueStorage);
                }

                if (!dbProxy.Write(MYPHOTO_COLLECTION, fileData))
                {
                    throw new Exception("Unable to add data to db");
                }

                Console.WriteLine("Added file" + fileData[FILE_PATHS].ToString());
                fileData.Remove(IMAGE_S_BASE64);
                fileData.Remove(IMAGE_M_BASE64);
                fileData.Remove(IMAGE_L_BASE64);
                _existingFiles.Add(fileModel);
                AddGallery(fileData, dbProxy);
                return(fileData);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        private void AddGallery(JObject fileData, IDBService dbProxy)
        {
            var fileHash = fileData[FILE_HASH].ToString();

            foreach (var item in fileData[TAGS])
            {
                JObject filter = new JObject();
                filter[CommonConst.CommonField.NAME] = item.ToString();
                var gallery = dbProxy.FirstOrDefault(MYPHOTO_GALLERY_COLLECTION, filter.ToString());
                if (gallery == null)
                {
                    gallery = new JObject();
                    gallery[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
                    gallery[DISPLAY_NAME] = gallery[CommonConst.CommonField.NAME] = item;
                    gallery[DESCRIPTION]  = "";
                    gallery[OWNER]        = DEFAULT_OWNER;
                    ImageGalleryHelper.AddDefaultAuthUser(gallery);
                    gallery[GALLERY_THUMBNAIL] = fileHash;
                    gallery[FILE_HASHS]        = new JArray();
                    (gallery[FILE_HASHS] as JArray).Add(fileHash);
                    gallery[FILES_COUNT] = (gallery[FILE_HASHS] as JArray).Count;
                    dbProxy.Write(MYPHOTO_GALLERY_COLLECTION, gallery);
                }
                else
                {
                    if ((gallery[FILE_HASHS] as JArray).FirstOrDefault(f => f.ToString() == fileHash) == null)
                    {
                        (gallery[FILE_HASHS] as JArray).Add(fileHash);
                        gallery[FILES_COUNT] = (gallery[FILE_HASHS] as JArray).Count;
                        dbProxy.Update(MYPHOTO_GALLERY_COLLECTION, filter.ToString(), gallery, false, MergeArrayHandling.Replace);
                    }
                }
            }
        }
Пример #3
0
        private void UpdateFile(FileModel fileModel, IDBService dbProxy, Func <string, bool> logger)
        {
            if (fileModel.IsUpdated)
            {
                JObject filter = new JObject();
                filter[FILE_HASH] = fileModel.file_hash;
                var fileData = new JObject();
                fileData[FILE_HASH]  = fileModel.file_hash;
                fileData[FILE_PATHS] = new JArray();
                foreach (var item in fileModel.file_paths)
                {
                    (fileData[FILE_PATHS] as JArray).Add(item);
                }
                ImageGalleryHelper.AddPath(fileData, fileModel);
                ImageGalleryHelper.AddTags(fileData, fileModel);

                dbProxy.Update(MYPHOTO_COLLECTION, filter.ToString(), fileData, false, MergeArrayHandling.Union);
                AddGallery(fileData, dbProxy);
            }
        }