private static void AddAppUpdateListItem(List<AppUpdateListItemView> appUpdateListItems, AppProject appProject, App app, AppUpdateListItemView appView, AppVersion currentVersion) { appView.Id = app.Id; appView.AppNo = appProject.AppNo; appView.DownloadUrl = FILE_PREFIX + currentVersion.FileUrl; appView.Drive = app.Drive; appView.IsHide = app.IsHide; appView.StorageName = app.StorageName; appView.UpdateTip = currentVersion.Tip; appView.UpdateType = currentVersion.UpdateTypeId; appView.Version = currentVersion.Id; appView.VersionName = currentVersion.VersionName; appView.ApkName = appProject.PackageName; appView.FileSize = currentVersion.FileSize; appUpdateListItems.Add(appView); }
public void get_tag_list_test_normal() { #region Generate Data string lcd = "320x480"; #region app and tags var sortedTags = new List<Tag>(); var tag1 = new Tag() { Id = "1", Name = "工具", OrderNumber = 4 }; var tag2 = new Tag() { Id = "2", Name = "娱乐", OrderNumber = 6 }; var tagIds = new List<string>{ "1", "2" }; var tagIdsSortedByOrderNumber = new List<string> { "2", "1" }; sortedTags.Add(tag2); sortedTags.Add(tag1); App app1 = new App() { AppNo = "1", AppProjectId = "1", //ClientLogos="", CurrentVer = "1", Id = "1", Name = "app1", Price = 0.0, Rank = 3, ReviewCount = 3 }; App app2 = new App() { AppNo = "2", AppProjectId = "2", //ClientLogos="", CurrentVer = "2", Id = "2", Name = "app2", Price = 0.0, Rank = 4, ReviewCount = 4 }; App app3 = new App() { AppNo = "3", AppProjectId = "3", //ClientLogos="", CurrentVer = "3", Id = "3", Name = "app3", Price = 0.0, Rank = 4, ReviewCount = 4 }; App app4 = new App() { AppNo = "4", AppProjectId = "4", //ClientLogos="", CurrentVer = "4", Id = "4", Name = "app4", Price = 0.0, Rank = 5, ReviewCount = 5 }; App app5 = new App() { AppNo = "5", AppProjectId = "5", //ClientLogos="", CurrentVer = "5", Id = "5", Name = "app5", Price = 0.0, Rank = 5, ReviewCount = 1 }; App app6 = new App() { AppNo = "6", AppProjectId = "6", //ClientLogos="", CurrentVer = "6", Id = "6", Name = "app6", Price = 0.0, Rank = 2, ReviewCount = 4 }; #endregion var AppIds = new List<string>() { "1","2","3","4","5","6" }; var topThreeAppIdsForT1 = new List<string>() { "1","2","3" }; var topThreeAppIdsForT2 = new List<string>() { "4","5","6" }; var apps = new List<App>(); apps.Add(app1); apps.Add(app2); apps.Add(app3); #region Version var version1 = new AppVersion() { Id = "1", VersionName = "v1", FileSize = 5, FileUrl = "FileUrl1", }; var version2 = new AppVersion() { Id = "2", VersionName = "v2", FileSize = 5, FileUrl = "FileUrl2", }; var version3 = new AppVersion() { Id = "3", VersionName = "v3", FileSize = 5, FileUrl = "FileUrl3", }; var version4 = new AppVersion() { Id = "4", VersionName = "v4", FileSize = 5, FileUrl = "FileUrl4", }; var version5 = new AppVersion() { Id = "5", VersionName = "v5", FileSize = 5, FileUrl = "FileUrl5", }; var version6 = new AppVersion() { Id = "6", VersionName = "v6", FileSize = 5, FileUrl = "FileUrl6", }; #endregion #region App Project var appProject1 = new AppProject() { AppNo = "1", Id = "1", LogoFile = "LogoFile1", Name = "app project1", Rate = 1, ReviewCount = 1 }; var appProject2 = new AppProject() { AppNo = "2", Id = "2", LogoFile = "LogoFile2", Name = "app project2", Rate = 2, ReviewCount = 2 }; var appProject3 = new AppProject() { AppNo = "3", Id = "3", LogoFile = "LogoFile3", Name = "app project3", Rate = 3, ReviewCount = 3 }; var appProject4 = new AppProject() { AppNo = "4", Id = "4", LogoFile = "LogoFile4", Name = "app project4", Rate = 4, ReviewCount = 4 }; var appProject5 = new AppProject() { AppNo = "5", Id = "5", LogoFile = "LogoFile5", Name = "app project5", Rate = 5, ReviewCount = 5 }; var appProject6 = new AppProject() { AppNo = "6", Id = "6", LogoFile = "LogoFile6", Name = "app project6", Rate = 6, ReviewCount = 6 }; #endregion #endregion //_appStoreUIServiceMock.Setup(s => s.GetTagsByTagCategory(It.IsAny<string>())).Returns(tags); _appStoreUIServiceMock.Setup(s => s.GetAppIdsByTag("1")).Returns(AppIds); _appStoreUIServiceMock.Setup(s => s.GetAppIdsByTag("2")).Returns(AppIds); _appStoreUIServiceMock.Setup(s => s.GetAppIdsByTag("3")).Returns(AppIds); _redisServiceMock2.Setup(s => s.GetSortedIdsByProperty<App>(It.IsAny<List<string>>(), It.IsAny<string>(), 1, 3, true)).Returns(topThreeAppIdsForT2); _redisServiceMock.Setup(s => s.GetValuesByIds<App>(It.IsAny<List<string>>(), false)).Returns(apps); _redisServiceMock.Setup(s => s.GetValuesByIds<Element>(It.IsAny<List<string>>(), false)).Returns(new List<Element>()); _redisServiceMock.Setup(s => s.Get<AppProject>("1")).Returns(appProject1); _redisServiceMock.Setup(s => s.Get<AppProject>("2")).Returns(appProject2); _redisServiceMock.Setup(s => s.Get<AppProject>("3")).Returns(appProject3); _redisServiceMock.Setup(s => s.GetAllSubModelIdsByType<TagCategory, TagInTagCategory>("2")).Returns(tagIds); _redisServiceMock2.Setup(s => s.GetSortedIdsByProperty<Tag>(tagIds, "OrderNumber", 0, 0, true)).Returns(tagIdsSortedByOrderNumber); _redisServiceMock.Setup(s => s.GetValuesByIds<Tag>(tagIdsSortedByOrderNumber, false)).Returns(sortedTags); _redisServiceMock2.Setup(s => s.GetIntersectIdsByPropertyFromSets(It.IsAny<List<string>>(), It.IsAny<List<string>>())).Returns(AppIds); _appStoreUIServiceMock.Setup(s => s.GetTagIdByName("Valid")).Returns("1"); _appStoreUIServiceMock.Setup(s => s.GetAppIdsByTag("1")).Returns(AppIds); _redisServiceMock2.Setup(s => s.GetFilteredIdsByPropertyFromSets<App>(It.IsAny<List<string>>(), It.IsAny<string>())).Returns(AppIds); _appStoreUIServiceMock.Setup(s => s.GetCurrentVersionForApp("1")).Returns(version1); _appStoreUIServiceMock.Setup(s => s.GetCurrentVersionForApp("2")).Returns(version2); _appStoreUIServiceMock.Setup(s => s.GetCurrentVersionForApp("3")).Returns(version3); _appStoreUIServiceMock.Setup(s => s.GetAppIdsByTagNames(It.IsAny<List<string>>())).Returns(topThreeAppIdsForT1); List<WapTagListItem> resultList = appStoresWapUIService.GetTagList(lcd,"2"); Assert.Equal(resultList.Count, 2); Assert.Equal(resultList[1].TagId, "1"); Assert.Equal(resultList[0].TagAppList.Count, 3); Assert.Equal(resultList[0].TagName, "娱乐"); }
public override ActionResult NewVersionUpload(AppVersion model, HttpPostedFileBase appFile) { return base.NewVersionUpload(model, appFile); }
private void SetVersionInfoForApp(AppView appView, AppVersion appVersion, MobileParam mobileParams) { appView.PublishTime = appVersion.PublishDateTime; appView.FileSize = appVersion.FileSize; appView.VersionName = appVersion.VersionName; //appView.DownloadUrl = GetAppDownloadUrl(appView.AppNo, mobileParams, 0); }
public void App_Version_Test() { App app1 = new App(); app1.Id = "10001"; app1.Name = "App1"; app1.Price = 25.88; app1.CreateDateTime = new DateTime(2011, 12, 1, 1, 1, 1); Service.Add<App>(app1); #region App Version AppVersion appVer = new AppVersion(); appVer.Id = "10000"; appVer.FileUrl = "C:\a"; appVer.PublishDateTime = DateTime.Now; AppStoreSvc.AddAppVersion("10001", appVer); appVer.FileUrl = "E:\\"; AppStoreSvc.AddAppVersion("10001", appVer); App app = new App(); app.Id = "10002"; app.Name = "App2"; app.Price = 10.55; app.CreateDateTime = new DateTime(2011, 11, 23, 1, 1, 1); var appCopy = CloneHelper.DeepClone<App>(app); app.Name = "App3"; Service.UpdateWithRebuildIndex<App>(appCopy, app); #endregion }
public void AppStoreIntergrationTest() { Redis.AddItemToQueue<string>("qlist1", "task"); var waitResult = Redis.RetrieveItemFromQueue<string>("qlist1"); Console.WriteLine(waitResult); #region App Add & Get App app = new App(); app.Id = "10002"; app.Name = "App2"; app.Price = 10.55; app.CreateDateTime = new DateTime(2011, 11, 23, 1, 1, 1); App app1 = new App(); app1.Id = "10001"; app1.Name = "App1"; app1.Price = 25.88; app1.CreateDateTime = new DateTime(2011, 12, 1, 1, 1, 1); Redis.Add<App>(app); PrintDebug("app id:10001 added"); Redis.Add<App>(app1); PrintDebug("app id:10002 added"); PrintDebug("Get app info for id:10001 : " + Redis.Get<App>("10001").Name); Console.WriteLine("Get one page of app : " + Redis.GetValuesByIds<App>(Redis.GetPagedModelIds<App>(1, 2)).Count); Console.WriteLine("Get one page of app sorted by price: " + Redis.GetValuesByIds<App>(Redis.GetPagedModelIds<App>(1, 2, "Price", true)).Count); #endregion #region App Element settings Element ele = new Element(); ele.Id = "1"; ele.Name = "分辨率"; ele.Type = (int)ElementType.多选列表; Redis.Add<Element>(ele); ElementDetail eleDetl = new ElementDetail(); eleDetl.Id = "2"; eleDetl.Value = "176x220"; eleDetl.ElementId = "1"; Redis.Add<ElementDetail>(eleDetl); ElementDetail eleDetl1 = new ElementDetail(); eleDetl1.Id = "3"; eleDetl1.Value = "240x320"; eleDetl1.ElementId = "1"; Redis.Add<ElementDetail>(eleDetl1); ElementDetail eleDetl2 = new ElementDetail(); eleDetl2.Id = "4"; eleDetl2.Value = "240x400"; eleDetl2.ElementId = "1"; Redis.Add<ElementDetail>(eleDetl2); var collection = Redis.GetValuesByIds<Element>(Redis.GetAllActiveModelIds<Element>()); PrintDebug("Element count: " + collection.Count + " " + Redis.GetAllCount<Element>()); if (collection.Count > 0) { PrintDebug("Element name: " + collection[0].Name); } var collection2 = AppStoreSvc.GetElementDetailList("1"); PrintDebug("ElementDetail count for Element[1]: " + collection2.Count); var originModel = CloneHelper.DeepClone<Element>(ele); ele.Name = "resolution"; Redis.UpdateWithRebuildIndex<Element>(originModel, ele); PrintDebug("Element name: " + Redis.Get<Element>("1").Name); if (Redis.Get<Element>("1") == null) { PrintDebug("Element[1] deleted."); } #endregion #region App Dynamic Property #region Element Settings Element ele2 = new Element(); ele2.Id = "2"; ele2.Name = "CustomProperty"; ele2.Type = (int)ElementType.多选列表; ele2.IsQueriable = true; Redis.Add<Element>(ele2); Element ele5 = new Element(); ele5.Id = "3"; ele5.Name = "Resolution"; ele5.Type = (int)ElementType.多选列表; ele5.IsQueriable = true; Redis.Add<Element>(ele5); Element ele4 = new Element(); ele4.Id = "4"; ele4.Name = "IsTouchable"; ele4.Type = (int)ElementType.输入框; ele4.IsQueriable = true; Redis.Add<Element>(ele4); ElementDetail elementDetail1 = new ElementDetail(); elementDetail1.ElementId = "2"; elementDetail1.Value = "CustomPropertyValue1"; ElementDetail elementDetail2 = new ElementDetail(); elementDetail2.ElementId = "2"; elementDetail2.Value = "CustomPropertyValue2"; Element ele3= new Element(); ele3.Id = "3"; ele3.Name = "IntCustomProperty"; ele3.Type = (int)ElementType.输入框; ele3.IsQueriable = true; Redis.Add<Element>(ele3); ElementDetail elementDetail3 = new ElementDetail(); elementDetail3.ElementId = "3"; elementDetail3.Value = 3.6; #endregion // Set up dynamic value for App CustomProperty customProperty = new CustomProperty(); customProperty.Id = ele2.Name; customProperty.Value = new List<string>() { elementDetail1.Value.ToString(), elementDetail2.Value.ToString() }; customProperty.IsQueriable = ele2.IsQueriable; CustomProperty customProperty2 = new CustomProperty(); customProperty2.Id = ele3.Name; customProperty2.Value = elementDetail3.Value; customProperty2.IsQueriable = ele3.IsQueriable; CustomProperty customProperty3 = new CustomProperty(); customProperty3.Id = ele3.Name; customProperty3.Value = elementDetail3.Value; customProperty3.IsQueriable = ele3.IsQueriable; CustomProperty resolutionProperty = new CustomProperty(); resolutionProperty.Id = ele5.Name; resolutionProperty.Value = new List<string>() { "240*320","320*480"}; CustomProperty isTouchableProperty = new CustomProperty(); isTouchableProperty.Id = ele4.Name; isTouchableProperty.Value = true; Redis.AddCustomPropertyFor<App, CustomProperty>("10001", customProperty); Redis.AddCustomPropertyFor<App, CustomProperty>("10001", customProperty2); Redis.AddCustomPropertyFor<App, CustomProperty>("10001", resolutionProperty); Redis.AddCustomPropertyFor<App, CustomProperty>("10001", isTouchableProperty); resolutionProperty.Value = new List<string>() { "320*480" }; Redis.AddCustomPropertyFor<App, CustomProperty>("10002", resolutionProperty); isTouchableProperty.Value = false; Redis.AddCustomPropertyFor<App, CustomProperty>("10002", isTouchableProperty); PrintDebug("add App's custom property: " + Redis.GetCustomPropertyFrom<App, CustomProperty>("10001", "CustomProperty").Id); Dictionary<string, string> newConditions = new Dictionary<string, string>(); newConditions.Add("Resolution", "320*480"); newConditions.Add("IsTouchable", bool.TrueString); newConditions.Add("CustomProperty", "CustomPropertyValue2"); PrintDebug("found app by dynamic property : " + Redis.FindIdsByConditions<App>(newConditions).Count); PrintDebug("found app by dynamic property (double value) : " + Redis.FindIdsByValueRange<App>("IntCustomProperty", 3.58, 3.62).Count); PrintDebug("find Custom Properties count for app[10001] : " + Redis.GetModelWithCustomProperties<App, CustomProperty>("10001").CustomProperties.Count); var originalCustomProperty = CloneHelper.DeepClone<CustomProperty>(customProperty); customProperty.IsQueriable = false; Redis.UpdateCustomPropertyFor<App, CustomProperty>("10001", originalCustomProperty, customProperty); PrintDebug("found app by dynamic property [CustomProperty:CustomPropertyValue2] after set IsQueriable to false : " + Redis.FindIdsByConditions<App>(newConditions).Count); //AppStoreSvc.DeleteCustomPropertyForApp("10001", customProperty); //PrintDebug("delete App's CustomProperty: " + (AppStoreSvc.GetCustomPropertyForApp("10001", "CustomProperty") == null)); #endregion #region Find app By a certain Value Range List<App> apps = Redis.GetValuesByIds<App>(Redis.FindIdsByValueRange<App>("Price", 10.56, 25.88)); PrintDebug("found app num by 10.56<= Price <=25.88 : " + apps.Count); apps = Redis.GetValuesByIds<App>(Redis.FindIdsByValueRange<App>("CreateDateTime", new DateTime(2011, 11, 23, 1, 1, 1), new DateTime(2011, 12, 1, 1, 1, 1))); PrintDebug("found app num by CreateDate : " + apps.Count); #endregion #region Fuzzy Find App apps = Redis.GetValuesByIds <App>(Redis.FuzzyFindIdsByCondition<App>("N*e", "App?")); PrintDebug("found app num by N*e like App? " + apps.Count); #endregion #region Complex Find App List<string> appIdsByValueRange = Redis.FindIdsByValueRange<App>("Price", 10.55, 25.88); List<string> appIdsByDateValueRange = Redis.FindIdsByValueRange<App>("CreateDateTime", new DateTime(2011, 11, 23, 1, 1, 1), new DateTime(2011, 12, 1, 1, 1, 1)); // Intersect means AND, Union mean OR List<App> finalResult = Redis.GetValuesByIds<App>((appIdsByValueRange.Intersect<string>(appIdsByDateValueRange).ToList())); PrintDebug("found app num by complex conditions " + finalResult.Count); #endregion #region App Version AppVersion appVer = new AppVersion(); appVer.Id = "10000"; appVer.FileUrl = "C:\a"; appVer.PublishDateTime = DateTime.Now; AppStoreSvc.AddAppVersion("10001", appVer); appVer.FileUrl = "E:\\"; AppStoreSvc.AddAppVersion("10001", appVer); AppStoreSvc.SetAppCurrentTestVersion("10001", "10000"); PrintDebug("added version num : " + AppStoreSvc.GetCurrentTestVersionForApp("10001").Id); PrintDebug("app current version : " + Redis.Get<App>("10001").CurrentTestVersion); var appCopy = CloneHelper.DeepClone<App>(app); app.Name = "App3"; Redis.UpdateWithRebuildIndex<App>(appCopy, app); PrintDebug("App name updated to " + Redis.Get<App>("10002").Name); #endregion #region Category Category c1 = new Category(); c1.Id = "1"; c1.Name = "游戏"; c1.ParentId = "0"; c1.status = "1"; Redis.Add<Category>(c1); Category csub1 = new Category(); csub1.Id = "2"; csub1.Name = "益智游戏"; csub1.ParentId = "1"; csub1.status = "1"; Redis.Add<Category>(csub1); PrintDebug("Sub Category count for Category[0] : " + AppStoreSvc.GetCategoryList("0").Count); #endregion #region App list AppList applist1 = new AppList(); applist1.Name = "10010"; applist1.Id = "10010"; applist1.CreateDateTime = DateTime.Now.AddSeconds(-3); applist1.CurrentVersion = 10010; AppList applist2 = new AppList(); applist2.Name = "10020"; applist2.Id = "10020"; applist2.CreateDateTime = DateTime.Now.AddDays(3); applist2.CurrentVersion = 10011; Redis.Add<AppList>(applist1); Redis.Add<AppList>(applist2); PrintDebug("two app lists added."); customProperty.IsQueriable = true; Redis.AddCustomPropertyFor<AppList, CustomProperty>(applist1.Id, customProperty); Dictionary<string, string> applistConditions = new Dictionary<string, string>(); applistConditions.Add("CustomProperty", "CustomPropertyValue2"); PrintDebug("found applist by dynamic property : " + Redis.FindIdsByConditions<AppList>(applistConditions).Count); var applist1Origin = CloneHelper.DeepClone<AppList>(applist1); applist1.CreateDateTime = DateTime.Now.AddDays(1); applist1.CurrentVersion++; // make sure bump version number when upate applist Redis.UpdateWithRebuildIndex<AppList>(applist1Origin, applist1); PrintDebug("app list updated :" + Redis.Get<AppList>("10010").Name); AppSettingsForAppList customApp1 = new AppSettingsForAppList(); customApp1.Id = app1.Id; customApp1.ScoreForSort = 2; customApp1.CustomProperties = new Dictionary<string, object>(); customApp1.CustomProperties.Add("Name", "NewApp1"); customApp1.CustomProperties.Add("Price", 2.3); customApp1.CustomProperties.Add("CustomProperty", "newValueFromAppListSettings"); AppSettingsForAppList customApp2 = new AppSettingsForAppList(); customApp2.Id = app.Id; customApp2.ScoreForSort = 1; customApp2.CustomProperties = new Dictionary<string, object>(); customApp2.CustomProperties.Add("Name", "NewApp2"); customApp2.CustomProperties.Add("Price", 3.2); AppStoreSvc.SetAppForAppList<AppList>("10010", customApp1); AppStoreSvc.SetAppForAppList<AppList>("10010", customApp2); var appsFromList1 = AppStoreSvc.GetAppsFromAppList<AppList>("10010"); PrintDebug("App count for AppList[10010] : " + appsFromList1.Count); var app1FromAppList1 = AppStoreSvc.GetAppFromAppList<AppList>("10010", "10001"); PrintDebug("Get App[10001]'s price From AppList[10010] : " + app1FromAppList1.Price); PrintDebug("Get App[10001]'s CustomProperty From AppList[10010] : " + app1FromAppList1.CustomProperties["CustomProperty"]); NameValueCollection headers = new NameValueCollection(); headers.Add("Resolution", "240*320"); headers.Add("IsTouchable", "1"); RequestHeadersMock.Setup(s => s.Header).Returns(headers); MobileParam requestParams = new MobileParam(RequestHeadersMock.Object); var matchedApp = AppStoreSvc.GetMatchedAppByRequest<AppList>("10010", requestParams); //PrintDebug("Matched app in applist[10010]: " + matchedApp.Id); AppSettingsForAppList customApp3 = new AppSettingsForAppList(); customApp3.Id = "10001"; customApp3.CustomProperties = new Dictionary<string, object>(); AppStoreSvc.SetAppForAppList<AppList>("10020", customApp3); List<string> appIdsUnion = AppStoreSvc.GetAppIdsByUnionAppList<AppList>("10010", "10020"); PrintDebug("Union applist1 and applist2, App count : " + appIdsUnion.Count); List<string> appIdsDiff = AppStoreSvc.GetAppIdsByDiffAppList<AppList>("10010", "10020"); PrintDebug("Diff applist1 and applist2, App count : " + appIdsDiff.Count); #endregion #region Device Model DeviceModel tyd1 = new DeviceModel() { Id = "天奕达HWQP", ModelName = "天奕达HWQP", CreateDateTime = DateTime.Now }; Redis.Add<DeviceModel>(tyd1); CustomProperty criteria1 = new CustomProperty() { Id = "Resolution", Value = "240*320", IsQueriable = false }; CustomProperty criteria2 = new CustomProperty() { Id = "IsTouchable", Value = true, IsQueriable = false }; PrintDebug("add device model : " + tyd1.ModelName); Redis.AddCustomPropertyFor<DeviceModel, CustomProperty>(tyd1.Id, criteria1); Redis.AddCustomPropertyFor<DeviceModel, CustomProperty>(tyd1.Id, criteria2); PrintDebug("add search criterias for device model : " + tyd1.ModelName); tyd1 = Redis.GetModelWithCustomProperties<DeviceModel, CustomProperty>("天奕达HWQP"); PrintDebug("search by DeviceModel[天奕达HWQP]: " + AppStoreSvc.GetAppsForDeviceModel(tyd1).Count); //PrintDebug("Get Device Model By Request parameters : " + AppStoreSvc.GetDeviceModelByRequest(requestParams).ModelName); #endregion #region Clean up Redis.DeleteWithCustomProperties<App, CustomProperty>("10001"); Redis.DeleteWithCustomProperties<App, CustomProperty>("10002"); Redis.DeleteWithCustomProperties<AppList, CustomProperty>(applist1.Id); Redis.DeleteWithCustomProperties<AppList, CustomProperty>(applist2.Id); Redis.Delete<Category>(c1); Redis.Delete<Category>(csub1); Redis.Delete<Element>(ele); Redis.Delete<Element>(ele2); Redis.Delete<Element>(ele3); Redis.Delete<Element>(ele4); Redis.Delete<Element>(ele5); Redis.Delete<ElementDetail>(eleDetl); Redis.Delete<ElementDetail>(eleDetl1); Redis.Delete<ElementDetail>(eleDetl2); Redis.Delete<DeviceModel>(tyd1); if (Redis.KeyFuzzyFind("*").Count == 0) { PrintDebug("App Count: " + Redis.GetAllCount<App>()); PrintDebug("All cleaned up."); } else { PrintDebug("Still useless keys left."); } #endregion }
public override ActionResult NewVersionUpload(AppVersion model, HttpPostedFileBase appFile) { return NewVersionUploadForNAppProject(model, appFile); }
public ActionResult NewVersionUploadForNAppProject(AppVersion model, HttpPostedFileBase appFile) { if (appFile == null) { TempData["errorMsg"] = "AppFile Required"; return RedirectToAction("NewVersionUpload", new { AppId = Request.Form["AppId"], appProjectId = Request.Form["appProjectId"], IsUpdate = Request.Form["IsUpdate"], originalVersionId = Request.Form["originalVersionId"] }); } var appId = Request.Form["AppId"]; var appProjectId = Request.Form["appProjectId"]; var app = RedisService.Get<App>(appId); var allAppVersion = RedisService.GetAllSubModelsByType<App, AppVersion>(app.Id); allAppVersion.Sort(delegate(AppVersion a, AppVersion b) { long result = (b.CreateDateTime.Ticks - a.CreateDateTime.Ticks); if (result > 0) { return 1; } else if (result == 0) { return 0; } else { return -1; } }); var newVersionNum = "1"; if (allAppVersion != null && allAppVersion.Count > 0) { newVersionNum = (allAppVersion[0].Id.ToInt32() + 1).ToString(); } var appFilePath = SaveResourceFile("AppFiles", ResourcesFilePathHelper.AppFilePath, appFile, string.Format("{0}_{1}_{2}_{3}_{4}", appProjectId, appId, Guid.NewGuid().ToString(), app.AppNo, Path.GetExtension(appFile.FileName)).NormalzieFileName()); AndroidPackageView androidPackageView = new AndroidPackageView(); string versionNum = GetVersionInfoFromAppFile(appFilePath, app.PlatformType, out androidPackageView); if (TempData["errorMsg"] != null && !string.IsNullOrWhiteSpace(TempData["errorMsg"].ToString())) { return RedirectToAction("NewVersionUpload", new { AppId = appId, appProjectId = appProjectId }); } if (!string.IsNullOrEmpty(androidPackageView.PackageName)) { versionNum = androidPackageView.VersionCode; var appProject = RedisService.Get<NAppProject>(appProjectId); var originalAppProject = CloneHelper.DeepClone<NAppProject>(appProject); if (!CanUploadPackage(androidPackageView, appProject.Id)) { TempData["errorMsg"] = string.Format("PackageName为{0}的包已存在,不能上传相同 PackageName 的软件包!", androidPackageView.PackageName); return RedirectToAction("NewVersionUpload", new { AppId = appId, appProjectId = appProjectId }); } if (!androidPackageView.PackageName.EqualsOrdinalIgnoreCase(appProject.PackageName)) { TempData["errorMsg"] = "Warning: APK package name was changed to " + androidPackageView.PackageName; } appProject.PackageName = androidPackageView.PackageName; RedisService.UpdateWithRebuildIndex<NAppProject>(originalAppProject, appProject); } model.CreateDateTime = DateTime.Now; model.FileSize = appFile.ContentLength; model.Status = 1; model.VersionName = androidPackageView == null ? string.Empty : androidPackageView.VersionName; model.Id = string.IsNullOrWhiteSpace(versionNum) ? model.Id : versionNum.ToString(); if (string.IsNullOrEmpty(model.Id)) { model.Id = newVersionNum; } var newFileName = string.Format("{0}_{1}_{2}_{3}_{4}_{5}", appProjectId, appId, model.Id, Guid.NewGuid().ToString(), app.AppNo, Path.GetExtension(appFile.FileName)).NormalzieFileName(); var newFilePath = Path.Combine(Path.GetDirectoryName(appFilePath), newFileName); if (FileService.RenameFile(appFilePath, newFilePath)) { model.FileUrl = newFileName; } else { model.FileUrl = Path.GetFileName(appFilePath); } var existedVer = RedisService.GetSubModel<App, AppVersion>(appId, model.Id.MakeSureNotNull()); if (existedVer != null) { model.PublishDateTime = existedVer.PublishDateTime; } UIService.AddAppVersion(appId, model); if (!string.IsNullOrEmpty(androidPackageView.PackageName)) { androidPackageView.Id = model.Id; RedisService.SetSubModel<App, AndroidPackageView>(model.Id, androidPackageView); } return RedirectToAction("AppDetails", new { appProjectId = appProjectId, appId = appId }); }
private ActionResult AppUploadForNAppProject(App model, HttpPostedFileBase appFile, HttpPostedFileBase appLogo) { if (appFile == null && string.IsNullOrEmpty(Request.Form["IsUpdate"])) { TempData["errorMsg"] = "AppFile Required"; return RedirectToAction("AppUpload", new { AppId = model.Id, appProjectId = model.AppProjectId }); } var originalApp = RedisService.Get<App>(model.Id); model.ScreenShot = originalApp.ScreenShot; model.Logo = originalApp.Logo; model.ClientLogos = originalApp.ClientLogos; model.AppProjectId = originalApp.AppProjectId; model.AppNo = originalApp.AppNo; //var CategoryId = model.CategoryName; //model.CategoryId = CategoryId; model.CategoryName = ((CategoryForApp)model.CategoryId.ToInt32()).ToString(); for (int i = 0; i < Request.Files.Count; i++) { if (Request.Files.AllKeys[i].EqualsOrdinalIgnoreCase("screenshot") && !string.IsNullOrWhiteSpace(Request.Files[i].FileName)) { var appScreenshotPath = SaveResourceFile("Screenshots", ResourcesFilePathHelper.AppScreenshotPath, Request.Files[i], string.Format("{0}_{1}_{2}", model.Id, Guid.NewGuid().ToString(), Path.GetExtension(Request.Files[i].FileName)).NormalzieFileName()); ImageInfo img = new ImageInfo() { BelongsToAppId = model.Id, FileUrl = appScreenshotPath }; RedisService.Add<ImageInfo>(img); model.ScreenShot.Add(img); } } if (appLogo != null) { var appLogoPath = SaveResourceFile("AppLogos", ResourcesFilePathHelper.AppLogoPath, appLogo, string.Format("{0}_{1}_{2}", model.Id, Guid.NewGuid().ToString(), Path.GetExtension(appLogo.FileName)).NormalzieFileName()); ImageInfo img = new ImageInfo() { BelongsToAppId = model.Id, FileUrl = appLogoPath, }; RedisService.Add<ImageInfo>(img); model.Logo = img; } model.CreateDateTime = DateTime.Now; //model.PermittedIMEIs = originalApp.PermittedIMEIs; if (!string.IsNullOrWhiteSpace(model.Summary)) { //FullTextSearchService.BuildIndexForApp(model.Id, model.Summary); } RedisService.UpdateWithRebuildIndex<App>(originalApp, model); if (model.Status > 0) { UIService.AddTagForApp(TYD.Mobile.Infrastructure.Domain.Services.AppStoreService.STATUS_VALID, model.Id); } else { UIService.DeleteTagForApp(UIService.GetTagIdByName(TYD.Mobile.Infrastructure.Domain.Services.AppStoreService.STATUS_VALID), model.Id); } if (string.IsNullOrEmpty(Request.Form["IsUpdate"])) { string versionNum = string.Empty; var appFilePath = SaveResourceFile("AppFiles", ResourcesFilePathHelper.AppFilePath, appFile, string.Format("{0}_{1}_{2}_{3}_{4}", model.AppProjectId, model.Id, Guid.NewGuid().ToString(), model.AppNo, Path.GetExtension(appFile.FileName)).NormalzieFileName()); AndroidPackageView androidPackageView = new AndroidPackageView(); versionNum = GetVersionInfoFromAppFile(appFilePath, model.PlatformType, out androidPackageView); if (TempData["errorMsg"] != null && !string.IsNullOrWhiteSpace(TempData["errorMsg"].ToString())) { return RedirectToAction("AppUpload", new { AppId = model.Id }); } if (!string.IsNullOrEmpty(androidPackageView.PackageName)) { versionNum = androidPackageView.VersionCode; var appProject = RedisService.Get<NAppProject>(model.AppProjectId); var originalAppProject = CloneHelper.DeepClone<NAppProject>(appProject); if (!CanUploadPackage(androidPackageView, appProject.Id)) { TempData["errorMsg"] = string.Format("PackageName为{0}的包已存在,不能上传相同 PackageName 的软件包!", androidPackageView.PackageName); return RedirectToAction("AppUpload", new { AppId = model.Id, appProjectId = model.AppProjectId }); } appProject.PackageName = androidPackageView.PackageName; RedisService.UpdateWithRebuildIndex<NAppProject>(originalAppProject, appProject); } AppVersion version = new AppVersion(); version.CreateDateTime = DateTime.Now; version.Id = string.IsNullOrEmpty(versionNum) ? string.IsNullOrEmpty(Request.Form["NewVersion"]) ? "10000" : Request.Form["NewVersion"] : versionNum; var newFileName = string.Format("{0}_{1}_{2}_{3}_{4}_{5}", model.AppProjectId, model.Id, version.Id, Guid.NewGuid().ToString(), model.AppNo, Path.GetExtension(appFile.FileName)).NormalzieFileName(); var newFilePath = Path.Combine(Path.GetDirectoryName(appFilePath), newFileName); if (FileService.RenameFile(appFilePath, newFilePath)) { version.FileUrl = newFileName; } else { version.FileUrl = Path.GetFileName(appFilePath); } version.FileSize = appFile.ContentLength; //version.PublishDateTime = version.CreateDateTime; version.UpdateTypeId = Request.Form["UpdateTypes"].ToInt32(); version.Tip = Request.Form["Tip"]; version.VersionName = androidPackageView == null ? string.Empty : androidPackageView.VersionName; RedisService.SetSubModel<App, AppVersion>(model.Id, version); if (!string.IsNullOrEmpty(androidPackageView.PackageName)) { androidPackageView.Id = version.Id; RedisService.SetSubModel<App, AndroidPackageView>(model.Id, androidPackageView); } } return RedirectToAction("AppDetails", new { appProjectId = model.AppProjectId, appId = model.Id }); }
private ActionResult NewVersionUploadForNAppProject(string AppId, string appProjectId, bool? IsUpdate, string originalVersionId = "") { ViewData["appProjectId"] = appProjectId; ViewData["AppId"] = AppId; ViewData["UpdateTypes"] = EnumHelper.GetSelectListFromEnumType(typeof(UpdateType)); var versions = this.UIService.GetAppsFromAppList<NAppProject>(appProjectId); ViewData["Visions"] = new SelectList(versions, "Name", "Name", versions.Count < 1 ? versions[0].Id : "0"); var app = RedisService.Get<NAppProject>(appProjectId); ViewData["AppName"] = app.Name; var model = new AppVersion(); if (IsUpdate.GetValueOrDefault()) { model = RedisService.GetSubModel<App, AppVersion>(AppId, originalVersionId); ViewData["OriginalVersionId"] = originalVersionId; } ViewData["IsUpdate"] = IsUpdate.GetValueOrDefault(); return View(model); }
public void GetAppDownloadUrl_return_redirectUrl_to_client_successfully() { AppProject appProj = new AppProject() { Id = "1", AppNo = "1", Name = "New APP 1", }; _appStoreUIServiceMock.Setup(m => m.GetAppProjectByAppNo("1")).Returns(appProj); var namevalues = new NameValueCollection(); namevalues[MobileParam.Key_Resolution] = "240x320"; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); MobileParam mobileParam = new MobileParam(requestRepo); App app = new App() { Id = "1", Name = "APP1", AppProjectId = "1", CurrentVer = "1", Status = 1 }; _appStoreUIServiceMock.Setup(m => m.GetMatchedAppByRequest<AppProject>("1", mobileParam)).Returns(app); _redisServiceMock.Setup(s => s.Get<App>("1")).Returns(app); AppVersion version = new AppVersion { Id = "1", FileSize = 123, PublishDateTime = DateTime.Now.AddDays(-1) }; _appStoreUIServiceMock.Setup(m => m.GetCurrentVersionForApp("1")).Returns(version); AppStoreService appStoreService = new AppStoreService(fileService, redisService, appStoreUIService, new FullTextSearchService(redisService), new IMEICacheService(redisService)); string slver = string.Empty; EntityMapping.Config(); var result = appStoreService.GetAppDownloadUrl("1", mobileParam, 0); Assert.NotEmpty(result); }
public void CheckAppList_return_data_to_client_successfully() { var columns = new Dictionary<string, string>(); columns.Add("1", "1"); Dictionary<string, object> customProperties = new Dictionary<string, object>(); customProperties["7"] = "240x320"; var deviceModel = new DeviceModel() { ModelName = "MTK_6252", CustomProperties = customProperties, Columns = columns }; AppProject appProj = new AppProject() { Id = "1", AppNo = "1", Name = "New APP 1" }; var namevalues = new NameValueCollection(); namevalues[MobileParam.Key_Resolution] = "240x320"; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); MobileParam mobileParam = new MobileParam(requestRepo); _appStoreUIServiceMock.Setup(m => m.GetDeviceModelByRequest(mobileParam)).Returns(deviceModel); App app = new App() { Id = "1", Name = "APP1", AppProjectId = "1", CurrentVer = "1" }; _appStoreUIServiceMock.Setup(m => m.GetAppsFromAppList<AppColumn>("1")).Returns(new List<App> { app }); _redisServiceMock.Setup(m => m.Get<AppProject>("1")).Returns(appProj); AppVersion version = new AppVersion { Id = "1", FileSize = 123 }; _appStoreUIServiceMock.Setup(m => m.GetCurrentVersionForApp("1")).Returns(version); AppColumn column = new AppColumn() { Id = "1", ClientId = 1, CurrentVersion = 1, Name = "Applications" }; _redisServiceMock.Setup<List<AppColumn>>(m => m.GetValuesByIds<AppColumn>(new List<string>() { "1" }, true)).Returns(new List<AppColumn>() { column }); AppStoreService appStoreService = new AppStoreService(fileService, redisService, appStoreUIService, new FullTextSearchService(redisService),new IMEICacheService(redisService)); var result = appStoreService.CheckAppList("1~0", mobileParam); Assert.Equal(1, result.Count); }
public void AppList_return_data_to_client_successfully() { var columns = new Dictionary<string, string>(); columns.Add("1", "1"); Dictionary<string, object> customProperties = new Dictionary<string, object>(); customProperties["7"] = "240x320"; var deviceModel = new DeviceModel() { ModelName = "MTK_6252", CustomProperties = customProperties, Columns = columns }; AppProject appProj = new AppProject() { Id = "1", AppNo = "1", Name = "New APP 1" }; var namevalues = new NameValueCollection(); namevalues[MobileParam.Key_Resolution] = "240x320"; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); MobileParam mobileParam = new MobileParam(requestRepo); _appStoreUIServiceMock.Setup(m => m.GetDeviceModelByRequest(mobileParam)).Returns(deviceModel); App app = new App() { Id = "1", Name = "APP1", AppProjectId = "1", CurrentVer = "1", Status = 1 }; _appStoreUIServiceMock.Setup(m => m.GetAppsFromAppList<AppColumn>("1")).Returns(new List<App> { app }); _redisServiceMock.Setup(m => m.Get<AppProject>("1")).Returns(appProj); var settings = new AppSettingsForAppList(); settings.CustomProperties = new Dictionary<string, object>(); settings.CustomProperties.Add("Name", "testName"); _redisServiceMock.Setup(m => m.GetSubModel<AppColumn, AppSettingsForAppList>(It.IsAny<string>(), It.IsAny<string>(), false)).Returns(settings); AppVersion version = new AppVersion { Id = "1", FileSize = 123, PublishDateTime = DateTime.Now.AddDays(-1) }; _appStoreUIServiceMock.Setup(m => m.GetCurrentVersionForApp("1")).Returns(version); AppColumn column = new AppColumn() { Id = "1", ClientId = 1, CurrentVersion = 1, Name = "Applications" }; _redisServiceMock.Setup<List<AppColumn>>(m => m.GetValuesByIds<AppColumn>(new List<string>() { "1" }, true)).Returns(new List<AppColumn>() { column }); AppStoreService appStoreService = new AppStoreService(fileService, redisService, appStoreUIService, new FullTextSearchService(redisService), new IMEICacheService(redisService)); string slver = string.Empty; int totalCount = 0; var result = appStoreService.AppList(mobileParam, 1, 1, 0, 0, "0", out slver, out totalCount); Assert.Equal(1, result.Count); Assert.Equal("testName", result[0].Name); }
public void AppListByTags_return_data_to_client_successfully() { var columns = new Dictionary<string, string>(); columns.Add("1", "1"); Dictionary<string, object> customProperties = new Dictionary<string, object>(); customProperties["7"] = "240x320"; AppProject appProj = new AppProject() { Id = "1", AppNo = "1", Name = "New APP 1" }; var namevalues = new NameValueCollection(); namevalues[MobileParam.Key_Resolution] = "240x320"; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); MobileParam mobileParam = new MobileParam(requestRepo); App app = new App() { Id = "1", Name = "APP1", AppProjectId = "1", CurrentVer = "1", Status = 1, DownloadTimes = 8 }; App app2 = new App() { Id = "2", Name = "APP2", AppProjectId = "1", CurrentVer = "1", Status = 1, DownloadTimes = 10, Summary = "Top" }; _appStoreUIServiceMock.Setup(m => m.GetAppsFromAppList<AppColumn>("1")).Returns(new List<App> { app }); _redisServiceMock.Setup(m => m.Get<AppProject>("1")).Returns(appProj); _redisServiceMock.Setup(m => m.GetValuesByIds<App>(It.IsAny<List<string>>(), false)).Returns(new List<App>()); AppVersion version = new AppVersion { Id = "1", FileSize = 123, PublishDateTime = DateTime.Now.AddDays(-1) }; _appStoreUIServiceMock.Setup(m => m.GetCurrentVersionForApp("1")).Returns(version); AppVersion version2 = new AppVersion { Id = "2", FileSize = 321, PublishDateTime = DateTime.Now.AddDays(-1) }; _appStoreUIServiceMock.Setup(m => m.GetCurrentVersionForApp("2")).Returns(version2); _appStoreUIServiceMock.Setup(m => m.GetAppIdsByTagNames(It.IsAny<List<string>>())).Returns(new List<string> { app.Id, app2.Id }); _redisServiceMock2.Setup(m => m.GetSortedIdsByProperty<App>(It.IsAny<List<string>>(), "DownloadTimes", 0, 0, true)).Returns(new List<string> { app2.Id, app.Id }); AppStoreService appStoreService = new AppStoreService(fileService, redisService, appStoreUIService, new FullTextSearchService(redisService),new IMEICacheService(redisService)); string slver = string.Empty; int totalCount = 0; var result = appStoreService.GetAppListByTags(mobileParam, 0, 0, out totalCount, "a;b;c;Live"); Assert.Equal(2, totalCount); }
//[RedisFact] public void search_applist_by_app_name_test() { AppProject appProj = new AppProject() { Id = "201", AppNo = "452", Name = "New APP sanguo" }; redis.Add<AppProject>(appProj); App app = new App(); app.Id = "100052"; app.Name = "三国"; app.Price = 10.55; app.Status = 1; app.AppProjectId = "201"; app.AppNo = "452"; app.CurrentVer = "14"; app.CreateDateTime = new DateTime(2011, 11, 23, 1, 1, 1); redis.Add<App>(app); var namevalues = new NameValueCollection(); namevalues[MobileParam.Key_Resolution] = "240x320"; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); MobileParam mobileParam = new MobileParam(requestRepo); AppVersion version = new AppVersion { Id = "14", FileSize = 123 }; redis.SetSubModel<App, AppVersion>("100052", version); var elementD = new ElementDetail(); elementD.ElementId = "4"; elementD.Value = "Android"; elementD.Status = 1; redis.Add<ElementDetail>(elementD); CustomProperty c = new CustomProperty(); c.Id = "4"; c.Value = "Android"; redis.AddCustomPropertyFor<App, CustomProperty>("100052", c); _fullTextSearchServiceMock.Setup(s => s.SearchAppIdsByDesc("三国")).Returns(new List<string>()); appStoreUIRealService.AddTagForApp("Live", "100052"); appStoreUIRealService.AddTagForApp("Valid", "100052"); int totalCount = 0; var returnResult = appStoreRealService.SearchAndroidAppListByName(mobileParam, 0, 1, out totalCount, "三国"); Assert.Equal(returnResult[0].Name, "New APP sanguo"); }