Пример #1
0
        private bool UpdateCustomContentData(JObject contentCustomData, UserModel user, string data, JObject updateFilter)
        {
            JObject updateFilterExistingData = new JObject();

            updateFilterExistingData[CommonConst.CommonField.FILE_PATH]   = contentCustomData[CommonConst.CommonField.FILE_PATH].ToString();
            updateFilterExistingData[CommonConst.CommonField.IS_OVERRIDE] = false;

            var updateData = new JObject();

            updateData[CommonConst.CommonField.OVERRIDE_BY] = _contentUpdateModuleName;
            updateData[CommonConst.CommonField.IS_OVERRIDE] = true;

            DBProxy.Update(CommonConst.Collection.STATIC_CONTECT, updateFilterExistingData.ToString(), updateData);

            var     existingData = contentCustomData[CommonConst.CommonField.DATA];
            JObject history      = new JObject();

            history[CommonConst.CommonField.DATA]              = existingData;
            history[CommonConst.CommonField.UPDATED_BY]        = user.user_id;
            history[CommonConst.CommonField.UPDATED_DATE_TIME] = CommonUtility.GetUnixTimestamp(DateTime.Now);
            (contentCustomData[_contentHistory] as JArray).Add(history);
            contentCustomData[CommonConst.CommonField.DATA] = data;
            if (DBProxy.Update(CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString(), contentCustomData) != 1)
            {
                Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "error updating contentCustomData"));
                return(false);
            }
            return(true);
        }
Пример #2
0
        public JObject Update()
        {
            try
            {
                JObject request = HttpProxy.GetRequestBody <JObject>();
                if (request == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                if (request[CommonConst.CommonField.DISPLAY_ID] == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                JObject filter = new JObject();
                filter[CommonConst.CommonField.DISPLAY_ID] = request[CommonConst.CommonField.DISPLAY_ID].ToString();

                var dbresponse = DBProxy.Update(CommonConst.Collection.APP_SETTING, filter.ToString(), request, true, MergeArrayHandling.Replace);
                if (dbresponse == 0)
                {
                    Logger.Error(string.Format("Error in  SettingController.update: {0}, collection {1}", "Error in updating data in db", CommonConst.Collection.APP_SETTING));
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }
                return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS));
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("SettingController.Get {0}", ex.Message), ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Пример #3
0
        public JObject Bookmark()
        {
            try
            {
                var fileHash  = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH);
                var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID);

                if (string.IsNullOrEmpty(fileHash) || string.IsNullOrEmpty(galleryId))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }

                if (!ImageGalleryHelper.HasAccess(DBProxy, SessionProvider, galleryId, fileHash))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED));
                }
                var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);

                var filter = new JObject();
                filter[CommonConst.CommonField.USER_ID] = user.user_id;

                var bookmarkData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_IMAGE_BOOKMARK_COLLECTION, filter.ToString());
                if (bookmarkData == null)
                {
                    bookmarkData = new JObject();
                    bookmarkData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
                    bookmarkData[CommonConst.CommonField.USER_ID]    = user.user_id;
                    bookmarkData[ImageProcessor.IMAGES] = new JArray();
                }

                JObject bookmarrkResponse = new JObject();
                var     bookmarkFile      = (bookmarkData[ImageProcessor.IMAGES] as JArray).FirstOrDefault(f => f[ImageProcessor.FILE_HASH].ToString() == fileHash);
                Logger.Debug("Get Bookmark data");
                if (bookmarkFile != null)
                {
                    (bookmarkData[ImageProcessor.IMAGES] as JArray).Remove(bookmarkFile);
                    bookmarrkResponse[ImageProcessor.COUNT] = -1;
                    Logger.Debug("Removed");
                }
                else
                {
                    bookmarkFile = new JObject();
                    bookmarkFile[ImageProcessor.FILE_HASH]  = fileHash;
                    bookmarkFile[ImageProcessor.GALLERY_ID] = galleryId;
                    (bookmarkData[ImageProcessor.IMAGES] as JArray).Add(bookmarkFile);
                    bookmarrkResponse[ImageProcessor.COUNT] = +1;
                    Logger.Debug("Adding");
                }

                DBProxy.Update(ImageProcessor.MYPHOTO_IMAGE_BOOKMARK_COLLECTION, filter.ToString(), bookmarkData, true, MergeArrayHandling.Replace);

                return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, bookmarrkResponse));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Пример #4
0
        public JObject Like()
        {
            try
            {
                var fileHash  = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH);
                var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID);

                if (string.IsNullOrEmpty(fileHash) || string.IsNullOrEmpty(galleryId))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }

                if (!ImageGalleryHelper.HasAccess(DBProxy, SessionProvider, galleryId, fileHash))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED));
                }
                var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);

                var filter = new JObject();
                filter[ImageProcessor.FILE_HASH] = fileHash;

                var likeData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_IMAGE_LIKE_COLLECTION, filter.ToString());
                if (likeData == null)
                {
                    likeData = new JObject();
                    likeData[ImageProcessor.USERS]               = new JArray();
                    likeData[ImageProcessor.FILE_HASH]           = fileHash;
                    likeData[ImageProcessor.COUNT]               = 0;
                    likeData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
                }

                var totalCount = 0;
                int.TryParse(likeData[ImageProcessor.COUNT].ToString(), out totalCount);
                JObject like     = new JObject();
                var     likeUser = (likeData[ImageProcessor.USERS] as JArray).FirstOrDefault(f => f.ToString() == user.user_id);
                if (likeUser != null)
                {
                    (likeData[ImageProcessor.USERS] as JArray).Remove(likeUser);
                    totalCount--;
                    like[ImageProcessor.COUNT] = -1;
                }
                else
                {
                    (likeData[ImageProcessor.USERS] as JArray).Add(user.user_id);
                    totalCount++;
                    like[ImageProcessor.COUNT] = +1;
                }
                likeData[ImageProcessor.COUNT] = (likeData[ImageProcessor.USERS] as JArray).Count;

                DBProxy.Update(ImageProcessor.MYPHOTO_IMAGE_LIKE_COLLECTION, filter.ToString(), likeData, true, MergeArrayHandling.Replace);
                return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, like));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Пример #5
0
        public JObject AdminUpdate()
        {
            try
            {
                Logger.Debug("Enter to UpdateUserInfo.AdminUpdate");
                JObject request = HttpProxy.GetRequestBody <JObject>();
                if (request == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                string userId = string.Empty;
                if (request[CommonConst.CommonField.USER_ID] != null)
                {
                    userId = request[CommonConst.CommonField.USER_ID].ToString();
                }
                if (string.IsNullOrEmpty(userId))
                {
                    Logger.Error(string.Format("Error in  UpdateUserInfo.AdminUpdate: {0}", "User id empty"));
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }

                JObject updateFilter = new JObject();
                updateFilter[CommonConst.CommonField.USER_ID] = userId;

                if (request[ModuleAppConsts.Field.USER_INFO] != null && (request[ModuleAppConsts.Field.USER_INFO] as JArray).Count > 0)
                {
                    var userInfo = request[ModuleAppConsts.Field.USER_INFO][0] as JObject;
                    Logger.Debug("Updating User Info", userInfo);
                    var dbresponse = DBProxy.Update(CommonConst.Collection.USER_INFO, updateFilter.ToString(), userInfo, true, MergeArrayHandling.Replace);
                    if (dbresponse == 0)
                    {
                        Logger.Error(string.Format("Error in  UpdateUserInfo.AdminUpdate: {0}, collection {1}", "Error in updating data in db", CommonConst.Collection.USER_INFO));
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }
                }

                JObject userdata = new JObject();
                userdata[CommonConst.CommonField.PHONE] = request[CommonConst.CommonField.PHONE];
                userdata[CommonConst.CommonField.EMAIL] = request[CommonConst.CommonField.EMAIL];
                userdata[CommonConst.CommonField.NAME]  = request[CommonConst.CommonField.NAME];

                Logger.Debug("Updating User", userdata);
                if (DBProxy.Write(CommonConst.Collection.USERS, userdata, updateFilter.ToString(), false, MergeArrayHandling.Union))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, updateFilter));
                }
                else
                {
                    Logger.Error(string.Format("Error in  UpdateUserInfo.AdminUpdate: {0}, collection {1}", "Error in updating data in db", CommonConst.Collection.USERS));
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error in  UpdateUserInfo.AdminUpdate: {0}", ex.Message), ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Пример #6
0
        private string  UploadFile(string galleryId, UserModel user, string fileName, IKeyValueStorage keyValueStorage)
        {
            FileInfo fi = new FileInfo(fileName);

            Logger.Debug(string.Format("Getting File Data"));

            byte[] fileData = _fileUploader.GetFileData(fileName);
            using (Bitmap image = ImageGalleryHelper.GetImageBitmapFromByte(fileData))
            {
                Logger.Debug(string.Format("Getting file Hash"));
                var fileModel = new FileModel()
                {
                    file_hash = Hashing.GetFileHash(fileData), file_paths = new List <string>()
                };
                JObject fileFilter = new JObject();
                fileFilter[ImageProcessor.FILE_HASH] = fileModel.file_hash;
                if (DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_COLLECTION, fileFilter.ToString()) == null)
                {
                    Logger.Debug(string.Format("CreateFileDataJObject"));
                    var imageJObjectData = ImageGalleryHelper.CreateFileDataJObject(fileModel, string.Empty, image, keyValueStorage);
                    imageJObjectData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
                    imageJObjectData[ImageProcessor.OWNER] = user.user_id;
                    DBProxy.Write(ImageProcessor.MYPHOTO_COLLECTION, imageJObjectData);
                }

                var filter = new JObject();
                filter[CommonConst.CommonField.DISPLAY_ID] = galleryId;
                Logger.Debug(string.Format("Getting gallery "));
                var galleryData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString());
                if (galleryData == null)
                {
                    galleryData = new JObject();
                    galleryData[ImageProcessor.FILE_HASHS] = new JArray();
                    (galleryData[ImageProcessor.FILE_HASHS] as JArray).Add(fileModel.file_hash);
                    galleryData[ImageProcessor.GALLERY_THUMBNAIL] = fileModel.file_hash;
                    galleryData[ImageProcessor.OWNER]             = user.user_id;
                    galleryData[ImageProcessor.AUTH_USERS]        = new JArray();
                    (galleryData[ImageProcessor.AUTH_USERS] as JArray).Add(user.user_id);
                }
                else
                {
                    if (galleryData[ImageProcessor.FILE_HASHS] == null)
                    {
                        galleryData[ImageProcessor.FILE_HASHS] = new JArray();
                    }
                    Logger.Debug(string.Format("Adding file to collection "));
                    (galleryData[ImageProcessor.FILE_HASHS] as JArray).Insert(0, fileModel.file_hash);
                }
                galleryData[ImageProcessor.FILES_COUNT] = (galleryData[ImageProcessor.FILE_HASHS] as JArray).Count;

                DBProxy.Update(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString(), galleryData, false, MergeArrayHandling.Replace);

                return(fileModel.file_hash);
            }
        }
Пример #7
0
        public JObject UpdateAlbum()
        {
            try
            {
                var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID);

                var requestBody = HttpProxy.GetRequestBody <JObject>();
                if (requestBody == null || string.IsNullOrEmpty(galleryId))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                if (!ImageGalleryHelper.IsOwner(DBProxy, SessionProvider, galleryId))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED));
                }
                var filter = new JObject();
                filter[CommonConst.CommonField.DISPLAY_ID] = galleryId;

                var data = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString());

                if (data == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                if (requestBody[ImageProcessor.DISPLAY_NAME] != null)
                {
                    data[ImageProcessor.DISPLAY_NAME] = requestBody[ImageProcessor.DISPLAY_NAME].ToString();
                }
                if (requestBody[ImageProcessor.DESCRIPTION] != null)
                {
                    data[ImageProcessor.DESCRIPTION] = requestBody[ImageProcessor.DESCRIPTION].ToString();
                }
                if (requestBody[ImageProcessor.GALLERY_THUMBNAIL] != null)
                {
                    data[ImageProcessor.GALLERY_THUMBNAIL] = requestBody[ImageProcessor.GALLERY_THUMBNAIL].ToString();
                }
                if (requestBody[ImageProcessor.AUTH_USERS] != null)
                {
                    data[ImageProcessor.AUTH_USERS] = requestBody[ImageProcessor.AUTH_USERS];
                }

                if (DBProxy.Update(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString(), data, false, MergeArrayHandling.Replace) != 1)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }
                return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Пример #8
0
        public JObject DeleteImage()
        {
            try
            {
                var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID);
                var fileHash  = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH);


                var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);
                if (string.IsNullOrEmpty(galleryId) || string.IsNullOrEmpty(galleryId))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                if (!ImageGalleryHelper.IsOwner(DBProxy, SessionProvider, galleryId))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED));
                }
                var filter = new JObject();
                filter[CommonConst.CommonField.DISPLAY_ID] = galleryId;
                var galleryData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString());
                if (galleryData == null)
                {
                    Logger.Error(string.Format("Gallery Not found :  Gallery: {0} ", galleryId));

                    return(ResponseBuilder.CreateReponse(CommonConst._404_RESOURCE_NOT_FOUND));
                }
                if (galleryData[ImageProcessor.FILE_HASHS] == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }
                var filehashData = (galleryData[ImageProcessor.FILE_HASHS] as JArray).FirstOrDefault(f => f.ToString() == fileHash);
                if (filehashData != null)
                {
                    (galleryData[ImageProcessor.FILE_HASHS] as JArray).Remove(filehashData);
                    DBProxy.Update(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString(), galleryData, false, MergeArrayHandling.Replace);
                    JObject responseData = new JObject();
                    responseData[ImageProcessor.FILE_HASH] = fileHash;
                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, responseData));
                }
                else
                {
                    Logger.Error(string.Format("File Hash Not found : FileHash: {0} Gallery: {1} ", fileHash, galleryId));
                    return(ResponseBuilder.CreateReponse(CommonConst._404_RESOURCE_NOT_FOUND));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Пример #9
0
        public static void Main(string[] args)
        {
            // 定义文件数据库的存放目录,为软件运行相对目录下的 test_db 目录
            string path = Environment.CurrentDirectory + "/test_db";
            // 定义文件数据库的拆分数量
            int dbCount = 100;

            Console.WriteLine(String.Format("准备用:{0}, {1} 初始化数据库", path, dbCount));

            System.IO.Directory.CreateDirectory(path);

            // 几个计时变量,用于统计程序不同阶段的运行时间
            long t1, t2, t3;

            // 创建数据库哈希代理对象,用于后续的一系列操作
            using (var proxy = new DBProxy(path, dbCount))
            {
                Random random = new Random(DateTime.Now.Ticks.GetHashCode());

                t1 = DateTime.Now.Ticks;

                // 随机插入模拟数据(本想20亿条,后因运行时间太长,无奈改为20万条)
                for (long i = 0, m = 200000L; i < m; i++)
                {
                    string kv1   = RandomStr(random);
                    string kv2   = RandomStr(random);
                    int    value = random.Next(1000);

                    proxy.Update(kv1, kv2, value);
                }

                t2 = DateTime.Now.Ticks;

                // 进行 1 万次查询
                for (int i = 0; i < 10000; i++)
                {
                    string kv1   = RandomStr(random);
                    string kv2   = RandomStr(random);
                    int    value = proxy.Query(kv1, kv2);
                }

                t3 = DateTime.Now.Ticks;
            }

            // 统计并输出运行时间
            var ts1 = new TimeSpan(t2 - t1);
            var ts2 = new TimeSpan(t3 - t2);
            var ts3 = new TimeSpan(t3 - t1);

            Console.WriteLine(String.Format("消耗时间:{0}, {1}, {2} (毫秒)", ts1.TotalMilliseconds, ts2.TotalMilliseconds, ts3.TotalMilliseconds));
        }
Пример #10
0
        public JObject Rotate()
        {
            try
            {
                var fileHash  = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH);
                var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID);

                if (string.IsNullOrEmpty(fileHash) || string.IsNullOrEmpty(galleryId))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }

                if (!ImageGalleryHelper.IsOwner(DBProxy, SessionProvider, galleryId))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED));
                }

                var fileData = ImageGalleryHelper.GetImage(DBProxy, fileHash);

                if (fileHash == null)
                {
                    Logger.Error(string.Format("File not found ::{0}", fileHash));
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }


                var path           = string.Empty;
                var baseFolderPath = AppSettingService.GetAppSettingData("my_photo_path");
                if (string.IsNullOrEmpty(baseFolderPath))
                {
                    throw new KeyNotFoundException("my_photo_path");
                }
                if (fileData[ImageProcessor.FILE_PATHS] == null)
                {
                    throw new KeyNotFoundException(ImageProcessor.FILE_PATHS);
                }

                Logger.Debug(string.Format("Getting file info BasePath  : {0}", baseFolderPath));
                foreach (var item in fileData[ImageProcessor.FILE_PATHS])
                {
                    if (File.Exists(string.Concat(baseFolderPath, "\\", item.ToString())))
                    {
                        path = string.Concat(baseFolderPath, "\\", item.ToString());
                        break;
                    }
                }
                if (!File.Exists(path))
                {
                    throw new FileNotFoundException(path);
                }

                var changesetNo = 0;
                if (fileData[ImageProcessor.CHANGESET_NO] != null)
                {
                    Logger.Debug(string.Format("changesetNo value from  fileData {0}", fileData[ImageProcessor.CHANGESET_NO].ToString()));
                    int.TryParse(fileData[ImageProcessor.CHANGESET_NO].ToString(), out changesetNo);
                }
                else
                {
                    Logger.Debug(string.Format("changesetNo is null in fileData"));
                }

                Logger.Debug(string.Format("Image  file path info BasePath  : {0} File Name :{1}", baseFolderPath, path));

                using (var image = ImageGalleryHelper.GetImageBitmapFromFile(path))
                {
                    Logger.Debug(string.Format("Processing Image BasePath  : {0} File Name :{1}", baseFolderPath, path));

                    int rotate = 90;
                    if (fileData[ImageProcessor.IMAGE_ROTATE] != null && int.TryParse(fileData[ImageProcessor.IMAGE_ROTATE].ToString(), out rotate))
                    {
                        rotate += 90;
                        if (rotate >= 360)
                        {
                            rotate = 0;
                        }
                    }
                    switch (rotate)
                    {
                    case 90:
                        ImageGalleryHelper.ProcessImage(fileData, image, KeyValueStorage, RotateFlipType.Rotate90FlipNone);
                        Logger.Debug(string.Format("Rotate image to {0}. {1}", rotate, RotateFlipType.Rotate90FlipNone.ToString()));
                        break;

                    case 180:
                        ImageGalleryHelper.ProcessImage(fileData, image, KeyValueStorage, RotateFlipType.Rotate180FlipNone);
                        Logger.Debug(string.Format("Rotate image to {0}. {1}", rotate, RotateFlipType.Rotate180FlipNone.ToString()));
                        break;

                    case 270:
                        ImageGalleryHelper.ProcessImage(fileData, image, KeyValueStorage, RotateFlipType.Rotate270FlipNone);
                        Logger.Debug(string.Format("Rotate image to {0}. {1}", rotate, RotateFlipType.Rotate270FlipNone.ToString()));
                        break;

                    default:
                        ImageGalleryHelper.ProcessImage(fileData, image, KeyValueStorage, RotateFlipType.RotateNoneFlipNone);
                        Logger.Debug(string.Format("Rotate image to {0}. {1}", rotate, RotateFlipType.RotateNoneFlipNone.ToString()));
                        break;
                    }

                    fileData[ImageProcessor.IMAGE_ROTATE] = rotate;
                }

                Logger.Debug(string.Format("changesetNo : {0}. FileHash: {1}", changesetNo, fileHash));

                fileData[ImageProcessor.CHANGESET_NO] = (changesetNo + 1);

                JObject filter = new JObject();
                filter[ImageProcessor.FILE_HASH] = fileHash;
                DBProxy.Update(ImageProcessor.MYPHOTO_COLLECTION, filter.ToString(), fileData, true, MergeArrayHandling.Replace);

                fileData.Remove(ImageProcessor.IMAGE_L_BASE64);
                fileData.Remove(ImageProcessor.IMAGE_M_BASE64);
                fileData.Remove(ImageProcessor.IMAGE_S_BASE64);

                return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, fileData));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Пример #11
0
        public JObject Update()
        {
            try
            {
                Logger.Debug(string.Format("Enter to UpdateContent.Update, SessionProvider:{0}", (SessionProvider == null ? "null" : "OK")));
                UserModel user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);

                if (user == null)
                {
                    Logger.Info(string.Format("Error in UpdateContent.Update: {0}", "user session is null"));
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }
                JObject request = HttpProxy.GetRequestBody <JObject>();
                if (request == null)
                {
                    Logger.Info(string.Format("Error in UpdateContent.Update: {0}", "request object is null"));
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                string id         = string.Empty;
                string data       = string.Empty;
                string moduleName = string.Empty;
                if (request[CommonConst.CommonField.DISPLAY_ID] != null &&
                    request[CommonConst.CommonField.DATA] != null &&
                    request[CommonConst.CommonField.MODULE_NAME] != null

                    )
                {
                    id         = request[CommonConst.CommonField.DISPLAY_ID].ToString();
                    data       = request[CommonConst.CommonField.DATA].ToString();
                    moduleName = request[CommonConst.CommonField.MODULE_NAME].ToString();
                }

                if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(data) || string.IsNullOrEmpty(moduleName))
                {
                    Logger.Error(string.Format("Error in UpdateContent.Update: {0}", " id/data/moduleName empty"));
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                Logger.Debug("Get   data for UpdateContent.Update", request);

                JObject updateFilter = new JObject();
                updateFilter[CommonConst.CommonField.DISPLAY_ID] = id;
                if (moduleName != _contentUpdateModuleName)
                {
                    var originalData = DBProxy.FirstOrDefault(CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString());
                    if (originalData == null)
                    {
                        Logger.Error(string.Format("Error in UpdateContent.Update: {0}, collection{1}, filter {2}", "originalData is null", CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString()));
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }
                    //bool isOverride = true;
                    //bool.TryParse(originalData[CommonConst.CommonField.IS_OVERRIDE].ToString(), out isOverride);
                    //if (isOverride)
                    //{
                    //    Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "isOverride parameter is true in the oroginal data"));
                    //    return ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR);
                    //}
                    originalData[CommonConst.CommonField.IS_OVERRIDE] = true;
                    originalData[CommonConst.CommonField.OVERRIDE_BY] = _contentUpdateModuleName;

                    if (DBProxy.Update(CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString(), originalData) != 1)
                    {
                        Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "error updating originalData"));
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }

                    originalData[CommonConst.CommonField.DISPLAY_ID]  = CommonUtility.GetNewID();
                    originalData[CommonConst.CommonField.IS_OVERRIDE] = false;
                    originalData[CommonConst.CommonField.OVERRIDE_BY] = _contentUpdateModuleName;
                    originalData[CommonConst.CommonField.DATA]        = data;
                    originalData[_contentHistory] = new JArray();

                    JObject filterFindExistingCustomization = new JObject();
                    filterFindExistingCustomization[CommonConst.CommonField.MODULE_NAME] = _contentUpdateModuleName;
                    filterFindExistingCustomization[CommonConst.CommonField.FILE_PATH]   = originalData[CommonConst.CommonField.FILE_PATH].ToString();
                    var existingData = DBProxy.FirstOrDefault(CommonConst.Collection.STATIC_CONTECT, filterFindExistingCustomization.ToString());
                    if (existingData == null)
                    {
                        if (!DBProxy.Write(CommonConst.Collection.STATIC_CONTECT, originalData))
                        {
                            Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "error adding  new data"));
                            return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                        }
                    }
                    else
                    {
                        if (!UpdateCustomContentData(existingData, user, data, filterFindExistingCustomization))
                        {
                            return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                        }
                    }
                    return(ReturnSuccess(originalData));
                }
                else
                {
                    var contentCustomData = DBProxy.FirstOrDefault(CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString());
                    if (contentCustomData == null)
                    {
                        Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "contentCustomData  is null"));
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }
                    if (!UpdateCustomContentData(contentCustomData, user, data, updateFilter))
                    {
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }
                    return(ReturnSuccess(contentCustomData));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error in  UpdateContent.Update: {0}", ex.Message), ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Пример #12
0
        private void AddToUserView(string galleryId, string fileHash)
        {
            Logger.Debug("Adding UserViews");

            var filter = new JObject();

            filter[ImageProcessor.FILE_HASH] = fileHash;
            var viewData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_IMAGE_VIEW_COLLECTION, filter.ToString());

            if (viewData == null)
            {
                viewData = new JObject();
                viewData[ImageProcessor.USERS] = new JArray();
                viewData[ImageProcessor.COUNT] = 0;
                viewData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
            }
            var viewCount = 0;

            viewData[ImageProcessor.FILE_HASH] = fileHash;
            Logger.Debug("Getting existing Count");
            if (viewData[ImageProcessor.COUNT] != null)
            {
                int.TryParse(viewData[ImageProcessor.COUNT].ToString(), out viewCount);
            }

            viewData[ImageProcessor.COUNT] = viewCount + 1;
            Logger.Debug("Getting Session User ");
            var    user   = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);
            string userId = "-1";

            if (user != null)
            {
                userId = user.user_id;
            }

            Logger.Debug("Getting UserData", viewData);
            JToken userData = null;

            if (viewData[ImageProcessor.USERS] != null)
            {
                userData = (viewData[ImageProcessor.USERS] as JArray).FirstOrDefault(f => { return(f[CommonConst.CommonField.USER_ID] != null && f[CommonConst.CommonField.USER_ID].ToString() == userId); });
            }
            if (userData == null)
            {
                userData = new JObject();
                userData[CommonConst.CommonField.USER_ID] = userId;
                userData[ImageProcessor.COUNT]            = 0;
                if (viewData[ImageProcessor.USERS] == null)
                {
                    viewData[ImageProcessor.USERS] = new JArray();
                }
                (viewData[ImageProcessor.USERS] as JArray).Add(userData);
            }
            var userViewCount = 0;

            Logger.Debug("Getting existing user Count");
            if (userData[ImageProcessor.COUNT] != null)
            {
                int.TryParse(userData[ImageProcessor.COUNT].ToString(), out userViewCount);
            }

            userData[ImageProcessor.COUNT] = userViewCount + 1;

            DBProxy.Update(ImageProcessor.MYPHOTO_IMAGE_VIEW_COLLECTION, filter.ToString(), viewData, true, MergeArrayHandling.Replace);
        }
Пример #13
0
        public JObject AdminChangeUserImage()
        {
            var user_id = HttpProxy.GetQueryString(CommonConst.CommonField.USER_ID);

            if (string.IsNullOrEmpty(user_id))
            {
                return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
            }

            Logger.Debug(string.Format("File Count {0}", _fileUploader.GetFiles().Count));
            if (_fileUploader.GetFiles().Count > 0)
            {
                var path = string.Format("/frontend/{0}/{1}", "userpic", user_id);

                FileInfo fi = new FileInfo(_fileUploader.GetFiles()[0]);
                Logger.Debug(string.Format("Getting File Data"));

                byte[] fileData = _fileUploader.GetFileData(_fileUploader.GetFiles()[0]);

                JObject uploadReponse = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, Convert.ToBase64String(fileData));
                Logger.Debug(string.Format("Uploaded default file"), uploadReponse);

                JObject uploadReponseS = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetSmallImage(fileData));
                Logger.Debug(string.Format("Uploaded small file"), uploadReponseS);

                JObject uploadReponseM = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetMediumImage(fileData));
                Logger.Debug(string.Format("Uploaded medium file"), uploadReponseM);

                JObject uploadReponseL = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetLargeImage(fileData));
                Logger.Debug(string.Format("Uploaded large file"), uploadReponseL);

                if (uploadReponse != null && uploadReponseS != null && uploadReponseM != null && uploadReponseL != null)
                {
                    var filePath  = uploadReponse[CommonConst.CommonField.FILE_PATH].ToString();
                    var filePathS = uploadReponseS[CommonConst.CommonField.FILE_PATH].ToString();
                    var filePathM = uploadReponseM[CommonConst.CommonField.FILE_PATH].ToString();
                    var filePathL = uploadReponseL[CommonConst.CommonField.FILE_PATH].ToString();

                    JObject updateFilter = new JObject();
                    updateFilter[CommonConst.CommonField.USER_ID] = user_id;

                    JObject userdata = new JObject();
                    userdata[ModuleAppConsts.Field.USER_PIC]   = filePath;
                    userdata[ModuleAppConsts.Field.USER_PIC_S] = filePathS;
                    userdata[ModuleAppConsts.Field.USER_PIC_M] = filePathM;
                    userdata[ModuleAppConsts.Field.USER_PIC_L] = filePathL;
                    userdata[CommonConst.CommonField.USER_ID]  = user_id;
                    Logger.Debug("Updating User AdminChangeUserImage", userdata);
                    var updateCount = DBProxy.Update(CommonConst.Collection.USER_INFO, updateFilter.ToString(), userdata, true);
                    Logger.Debug(string.Format("AdminChangeUserImage UpdateCount:{0}", userdata));

                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, userdata));
                }
                else
                {
                    Logger.Error(string.Format("Error while uploading image AdminChangeUserImage"));
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR, uploadReponse));
                }
            }
            else
            {
                return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
            }
        }