public static string DeleteModel(string pid) { pid = HttpContext.Current.Server.UrlDecode(pid); string response = "0"; var factory = new DataAccessFactory(); IDataRepository dal = factory.CreateDataRepositorProxy(); ContentObject co = dal.GetContentObjectById(pid, false); if (co != null && HttpContext.Current.User.Identity.IsAuthenticated && (co.SubmitterEmail.Equals(HttpContext.Current.User.Identity.Name, StringComparison.InvariantCultureIgnoreCase) || Website.Security.IsAdministrator())) { try { dal.DeleteContentObject(co); response = "1"; } catch { } } else if (!HttpContext.Current.User.Identity.IsAuthenticated) { HttpContext.Current.Response.StatusCode = 403; } dal.Dispose(); return response; }
/// <summary> /// /// </summary> /// <param name="PID"></param> /// <returns></returns> public static Utility_3D.ConvertedModel GetAndConvertModel(String PID) { Utility_3D.ConverterOptions opts = (Utility_3D.ConverterOptions)HttpContext.Current.Session["options"]; string NewModelFormat = (string)HttpContext.Current.Session["format"]; DataAccessFactory factory = new vwarDAL.DataAccessFactory(); vwarDAL.IDataRepository vd = factory.CreateDataRepositorProxy(); ContentObject co = vd.GetContentObjectById(PID, false, false); byte[] filedata = vd.GetContentFileData(PID, co.Location); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AppendHeader("content-disposition", "attachment; filename=" + co.Location); HttpContext.Current.Response.ContentType = vwarDAL.DataUtils.GetMimeType(co.Location); Utility_3D _3d = new Utility_3D(); _3d.Initialize(Website.Config.ConversionLibarayLocation); Utility_3D.Model_Packager pack = new Utility_3D.Model_Packager(); Utility_3D.ConvertedModel model = pack.Convert(new System.IO.MemoryStream(filedata), "temp.zip", NewModelFormat, opts); vd.Dispose(); return(model); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { //load my models - by User.Id.Name if (!Page.IsPostBack) { vwarDAL.ISearchProxy srch = new vwarDAL.DataAccessFactory().CreateSearchProxy(Context.User.Identity.Name); MyModelsDataList.DataSource = srch.GetContentObjectsBySubmitterEmail(Context.User.Identity.Name.Trim()); MyModelsDataList.DataBind(); srch.Dispose(); } }
public static ContentObject AddDefaultObject() { IDataRepository dal = new DataAccessFactory().CreateDataRepositorProxy(); ContentObject dco = Default3drContentObject; dal.InsertContentObject(dco); using (FileStream fs = new FileStream(contentPath + "screenshot.png", FileMode.Open)) { dco.ScreenShotId = dal.SetContentFile(fs, dco.PID, dco.ScreenShot); } using (FileStream fs = new FileStream(contentPath + "devlogo.jpg", FileMode.Open)) { dco.DeveloperLogoImageFileNameId = dal.SetContentFile(fs, dco.PID, dco.DeveloperLogoImageFileName); } using (FileStream fs = new FileStream(contentPath + "sponsorlogo.jpg", FileMode.Open)) { dco.SponsorLogoImageFileNameId = dal.SetContentFile(fs, dco.PID, dco.SponsorLogoImageFileName); } using (FileStream fs = new FileStream(contentPath + "original_test.zip", FileMode.Open)) { dco.OriginalFileId = dal.SetContentFile(fs, dco.PID, dco.OriginalFileName); } using (FileStream fs = new FileStream(contentPath + "test.o3d", FileMode.Open)) { dco.DisplayFileId = dal.SetContentFile(fs, dco.PID, dco.DisplayFile); } using (FileStream fs = new FileStream(contentPath + "test.zip", FileMode.Open)) { dal.SetContentFile(fs, dco.PID, dco.Location); } dal.UpdateContentObject(dco); return dco; }
/// <summary> /// /// </summary> /// <param name="c"></param> protected void BindViewData(Control c) { PermissionsManager permManager = new PermissionsManager(); string username = HttpContext.Current.User.Identity.Name; //You gotta love how FindControl isn't recursive... DataList list = (DataList)c.FindControl("RotatorLayoutTable") .FindControl("RotatorListViewRow") .FindControl("RotatorListViewColumn") .FindControl("RotatorListView"); ISearchProxy permissionsHonoringProxy = new DataAccessFactory().CreateSearchProxy(HttpContext.Current.User.Identity.Name); switch (c.ID) { case "HighestRatedRotator": list.DataSource = permissionsHonoringProxy.GetByRating(4); break; case "MostPopularRotator": list.DataSource = permissionsHonoringProxy.GetByViews(4); break; case "RecentlyUpdatedRotator": list.DataSource = permissionsHonoringProxy.GetByLastUpdated(4); break; case "RandomRotator": list.DataSource = permissionsHonoringProxy.GetByRandom(4); break; default: throw new Exception("No control '" + c.ID + "' could be found to bind data to."); } list.DataBind(); permissionsHonoringProxy.Dispose(); permManager.Dispose(); }
private void DoSubmitAll() { vwarDAL.DataAccessFactory df = new DataAccessFactory(); vwarDAL.IDataRepository dal = df.CreateDataRepositorProxy(); IEnumerable<ContentObject> objects = dal.GetAllContentObjects(); int total = 0; int current = 0; foreach (ContentObject co in objects) { total++; } progressBar1.Maximum = total; progressBar2.Maximum = 4; foreach (ContentObject co in objects) { current++; progressBar1.Value = current; progressBar2.Value = 0; AllowUIToUpdate(); textBlock1.Text = LR_3DR_Bridge.ModelDownloadedInternal(co); progressBar2.Value = 1; AllowUIToUpdate(); ContentObject co2 = dal.GetContentObjectById(co.PID, false, true); textBlock1.Text = LR_3DR_Bridge.ModelRatedInternal(co2); progressBar2.Value = 2; AllowUIToUpdate(); textBlock1.Text = LR_3DR_Bridge.ModelUploadedInternal(co); progressBar2.Value = 3; AllowUIToUpdate(); textBlock1.Text = LR_3DR_Bridge.ModelViewedInternal(co); progressBar2.Value = 4; AllowUIToUpdate(); } }
/// <summary> /// /// </summary> /// <param name="PID"></param> /// <returns></returns> public static Utility_3D.ConvertedModel GetAndConvertModel(String PID) { Utility_3D.ConverterOptions opts = (Utility_3D.ConverterOptions)HttpContext.Current.Session["options"]; string NewModelFormat = (string)HttpContext.Current.Session["format"]; DataAccessFactory factory = new vwarDAL.DataAccessFactory(); vwarDAL.IDataRepository vd = factory.CreateDataRepositorProxy(); ContentObject co = vd.GetContentObjectById(PID, false, false); byte[] filedata = vd.GetContentFileData(PID, co.Location); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AppendHeader("content-disposition", "attachment; filename=" + co.Location); HttpContext.Current.Response.ContentType = vwarDAL.DataUtils.GetMimeType(co.Location); Utility_3D _3d = new Utility_3D(); _3d.Initialize(Website.Config.ConversionLibarayLocation); Utility_3D.Model_Packager pack = new Utility_3D.Model_Packager(); Utility_3D.ConvertedModel model = pack.Convert(new System.IO.MemoryStream(filedata), "temp.zip", NewModelFormat, opts); vd.Dispose(); return model; }
protected void NumResultsPerPageChanged(object sender, EventArgs e) { vwarDAL.ISearchProxy _SearchProxy = new DataAccessFactory().CreateSearchProxy(Context.User.Identity.Name); _ResultsPerPage = System.Convert.ToInt32(ResultsPerPageDropdown.SelectedValue); IEnumerable<ContentObject> co = GetSearchResults(); if (co != null) BindPageNumbers(_Presorted ? _SearchProxy.GetContentObjectCount() : co.Count()); ApplySearchResults(co); _SearchProxy.Dispose(); }
private IEnumerable<ContentObject> GetSearchResults() { IEnumerable<ContentObject> co = null; vwarDAL.ISearchProxy _SearchProxy = new DataAccessFactory().CreateSearchProxy(Context.User.Identity.Name); SearchMethod method; string methodParam = Request.QueryString["Method"]; if (!String.IsNullOrEmpty(methodParam) && methodParam.ToLowerInvariant() == "and") method = SearchMethod.AND; else method = SearchMethod.OR; if (!String.IsNullOrEmpty(Request.QueryString["Search"])) { string searchTerm = Request.QueryString["Search"]; if (!String.IsNullOrEmpty(searchTerm)) { SearchTextBox.Text = Server.UrlDecode(searchTerm); if (SearchTextBox.Text.Contains(',')) { var terms = SearchTextBox.Text.Split(','); co = _SearchProxy.QuickSearch(terms, method); } else { co = _SearchProxy.QuickSearch(SearchTextBox.Text); } } } else if (!String.IsNullOrEmpty(Request.QueryString["Group"])) { /* Here, we are getting "everything" (limit NumResultsPerPage) by a grouping. By doing a little processing ahead of time, we can avoid having to use ApplySort when unnecessary, as well as reduce the size of the data returned from MySQL. */ string[] sortParams = SortInfo.Split('-'); if (sortParams.Length == 2) //Make sure it's in the right format! { SortOrder order = (sortParams[1].ToLowerInvariant() == "low") ? SortOrder.Ascending : SortOrder.Descending; int start = (_PageNumber - 1) * _ResultsPerPage; switch (sortParams[0].ToLowerInvariant()) { case "views": co = _SearchProxy.GetByViews(_ResultsPerPage, start, order); break; case "updated": co = _SearchProxy.GetByLastUpdated(_ResultsPerPage, start, order); break; case "viewed": co = _SearchProxy.GetByLastViewed(_ResultsPerPage, start, order); break; case "rating": default: co = _SearchProxy.GetByRating(_ResultsPerPage, start, order); break; } _Presorted = true; } } else //We're searching by field { System.Collections.Specialized.NameValueCollection fieldsToSearch = new System.Collections.Specialized.NameValueCollection(); string[] searchableFields = { "Title", "Description", "ArtistName", "SponsorName", "DeveloperName", "Keywords" }; foreach (string field in searchableFields) if (!String.IsNullOrEmpty(Request.QueryString[field])) fieldsToSearch[field] = Server.UrlDecode(Request.QueryString[field]); co = _SearchProxy.SearchByFields(fieldsToSearch, method); } _SearchProxy.Dispose(); return co; }
protected void Page_Load(object sender, EventArgs e) { vwarDAL.ISearchProxy _SearchProxy = new DataAccessFactory().CreateSearchProxy(Context.User.Identity.Name); _ResultsPerPage = System.Convert.ToInt32(ResultsPerPageDropdown.SelectedValue); string tempUrl = ""; string[] acceptableArray = {"Search", "Keywords", "DeveloperName", "ArtistName", "SponsorName"}; for (int i = 0; i < acceptableArray.Length; i++) { if (Context.Request.QueryString[acceptableArray[i]] != null) { tempUrl = (acceptableArray[i] == "Keywords") ? "Keywords;" + Context.Request.QueryString[acceptableArray[i]] : Context.Request.QueryString[acceptableArray[i]]; break; } } APILink.NavigateUrl = "https://" + ConfigurationManager.AppSettings["LR_Integration_APIBaseURL"] + "/Search/" + Server.UrlEncode(tempUrl) + "/json?id=00-00-00"; //Search if (!IsPostBack) { SetInitialSortValue(); IEnumerable<ContentObject> co = GetSearchResults(); if (co != null && co.Count() > 0) { //If it's presorted, we cannot rely on the number of items in the returned collection //to get the true number of objects matching the specified search query int totalResults = (_Presorted) ? _SearchProxy.GetContentObjectCount() : co.Count(); BindPageNumbers(totalResults); ApplySearchResults(co); } else { NoneFoundLabel.Visible = true; if(Membership.GetUser() == null) NoneFoundLabel.Text = "No models found. It's possible that some models are hidden by their owners. Try logging in for more results. <br />"; else NoneFoundLabel.Text = "No models found. It's possible that some models are hidden by their owners. <br />"; SearchList.Visible = false; } } _SearchProxy.Dispose(); }
protected void PageNumberChanged(object sender, EventArgs e) { vwarDAL.ISearchProxy _SearchProxy = new DataAccessFactory().CreateSearchProxy(Context.User.Identity.Name); //Get the page number from the value displayed to the user LinkButton btn = (LinkButton)sender; _PageNumber = System.Convert.ToInt32(btn.CommandArgument); IEnumerable<ContentObject> co = GetSearchResults(); ApplySearchResults(co); BindPageNumbers(_Presorted ? _SearchProxy.GetContentObjectCount() : co.Count()); _SearchProxy.Dispose(); }
public static JsonWrappers.AdvancedDownloadPreviewSettings ViewButton_Click(string PID, bool bConvert, bool bConvertTextures, bool bResizeTextures, bool bReducePolys, string NewModelFormat, string NewTextureFormat, int NewTextureSize, float PolygonThresh, bool Smoothing, bool IgnoreBoundry, float MaxError, float MaxEdgeLength, string mode) { if (!bConvert) NewModelFormat = ".dae"; Utility_3D.ConverterOptions opts = new Utility_3D.ConverterOptions(); if (bConvertTextures) opts.EnableTextureConversion(NewTextureFormat); if (bResizeTextures) opts.EnableScaleTextures(NewTextureSize); if (bReducePolys) opts.EnablePolygonReduction(PolygonThresh); opts.SetPolygonReductionSmoothing(Smoothing); opts.SetPolygonReductionMaxLength(MaxEdgeLength); opts.SetPolygonReductionMaxError(MaxError); if (mode == "Simple") opts.SetPolygonReductionModeSimple(); else opts.SetPolygonReductionModeComplex(); HttpContext.Current.Session["options"] = opts; HttpContext.Current.Session["format"] = NewModelFormat; // string PID = HttpContext.Current.Request.QueryString["ContentObjectID"]; DataAccessFactory factory = new vwarDAL.DataAccessFactory(); vwarDAL.IDataRepository vd = factory.CreateDataRepositorProxy(); ContentObject co = vd.GetContentObjectById(PID, false, false); JsonWrappers.AdvancedDownloadPreviewSettings jsReturnParams = new JsonWrappers.AdvancedDownloadPreviewSettings(); jsReturnParams.FlashLocation = co.Location; Utils.FileStatus currentStatus = new Utils.FileStatus("", Utils.FormatType.UNRECOGNIZED); //tempFedoraCO.DisplayFile = currentStatus.filename.Replace("zip", "o3d").Replace("skp", "o3d"); currentStatus.filename = co.Location; currentStatus.hashname = co.Location; jsReturnParams.IsViewable = true; jsReturnParams.BasePath = "../Public/"; jsReturnParams.BaseContentUrl = "Model.ashx?temp=true&file="; jsReturnParams.O3DLocation = currentStatus.hashname.ToLower().Replace("zip", "o3d").Replace("skp", "o3d"); jsReturnParams.FlashLocation = currentStatus.hashname; jsReturnParams.ShowScreenshot = true; jsReturnParams.UpAxis = co.UpAxis; jsReturnParams.UnitScale = co.UnitScale; string optionalPath = (co.Location.LastIndexOf("o3d", StringComparison.CurrentCultureIgnoreCase) != -1) ? "viewerTemp/" : "converterTemp/"; string pathToTempFile = "~/App_Data/" + optionalPath + co.Location; using (FileStream stream = new FileStream(HttpContext.Current.Server.MapPath(pathToTempFile), FileMode.Create, FileAccess.Write)) { Utility_3D.ConvertedModel model = GetAndConvertModel(PID); byte[] data = model.data; Utility_3D.ConvertedModel model2 = (new Utility_3D.Model_Packager()).Convert(new MemoryStream(model.data), "test.zip"); jsReturnParams.Polygons = model2._ModelData.VertexCount.Polys; stream.Write(data, 0, data.Length); stream.Close(); } HttpContext.Current.Session["contentObject"] = co; vd.Dispose(); return jsReturnParams; // HttpContext.Current.Response.BinaryWrite(GetAndConvertModel().data); }
public static JsonWrappers.UploadDetailDefaults Step2_Submit(string ScaleValue, string UpAxis) { HttpContext context = HttpContext.Current; HttpServerUtility server = context.Server; FileStatus currentStatus = (FileStatus)context.Session["fileStatus"]; var factory = new DataAccessFactory(); IDataRepository dal = factory.CreateDataRepositorProxy(); ContentObject tempCO = (ContentObject)context.Session["contentObject"]; tempCO.UpAxis = server.HtmlEncode(UpAxis); tempCO.UnitScale = server.HtmlEncode(ScaleValue); //dal.UpdateContentObject(tempCO); context.Session["contentObject"] = tempCO; //Bind the JsonWrappers.UploadDetailDefaults jsReturnParams = new JsonWrappers.UploadDetailDefaults(); if (HttpContext.Current.User.Identity.IsAuthenticated) { UserProfile p = null; try { p = UserProfileDB.GetUserProfileByUserName(context.User.Identity.Name); } catch { } if (p != null) { jsReturnParams.HasDefaults = true; jsReturnParams.DeveloperName = p.DeveloperName; jsReturnParams.ArtistName = p.ArtistName; jsReturnParams.DeveloperUrl = p.WebsiteURL; jsReturnParams.SponsorName = p.SponsorName; string tempImagePath = context.Server.MapPath("~/App_Data/imageTemp/"); if (p.DeveloperLogo != null) { string extension = p.DeveloperLogoContentType.Substring(p.DeveloperLogoContentType.LastIndexOf("/") + 1); string tempDevLogoFilename = "devlogo_" + currentStatus.hashname.Replace("zip", extension); using (FileStream stream = new FileStream(tempImagePath + tempDevLogoFilename, FileMode.Create)) { stream.Write(p.DeveloperLogo, 0, p.DeveloperLogo.Length); } jsReturnParams.DeveloperLogoFilename = tempDevLogoFilename; } if (p.SponsorLogo != null) { string extension = p.SponsorLogoContentType.Substring(p.SponsorLogoContentType.LastIndexOf("/") + 1); string tempSponsorLogoFilename = "sponsorlogo_" + currentStatus.hashname.Replace("zip", extension); using (FileStream stream = new FileStream(tempImagePath + tempSponsorLogoFilename, FileMode.Create)) { stream.Write(p.SponsorLogo, 0, p.SponsorLogo.Length); } jsReturnParams.SponsorLogoFilename = tempSponsorLogoFilename; } } } dal.Dispose(); return jsReturnParams; }
protected void Page_Load(object sender, EventArgs e) { vwarDAL.ISearchProxy _SearchProxy = new DataAccessFactory().CreateSearchProxy(Context.User.Identity.Name); _ResultsPerPage = System.Convert.ToInt32(ResultsPerPageDropdown.SelectedValue); //Search if (!IsPostBack) { SetInitialSortValue(); IEnumerable<ContentObject> co = GetSearchResults(); if (co != null && co.Count() > 0) { //If it's presorted, we cannot rely on the number of items in the returned collection //to get the true number of objects matching the specified search query int totalResults = (_Presorted) ? _SearchProxy.GetContentObjectCount() : co.Count(); BindPageNumbers(totalResults); ApplySearchResults(co); } else { NoneFoundLabel.Visible = true; NoneFoundLabel.Text = "No models found. <br />"; SearchList.Visible = false; } } _SearchProxy.Dispose(); }
public static JsonWrappers.AdvancedDownloadPreviewSettings ViewButton_Click(string PID, bool bConvert, bool bConvertTextures, bool bResizeTextures, bool bReducePolys, string NewModelFormat, string NewTextureFormat, int NewTextureSize, float PolygonThresh, bool Smoothing, bool IgnoreBoundry, float MaxError, float MaxEdgeLength, string mode) { if (!bConvert) { NewModelFormat = ".dae"; } Utility_3D.ConverterOptions opts = new Utility_3D.ConverterOptions(); if (bConvertTextures) { opts.EnableTextureConversion(NewTextureFormat); } if (bResizeTextures) { opts.EnableScaleTextures(NewTextureSize); } if (bReducePolys) { opts.EnablePolygonReduction(PolygonThresh); } opts.SetPolygonReductionSmoothing(Smoothing); opts.SetPolygonReductionMaxLength(MaxEdgeLength); opts.SetPolygonReductionMaxError(MaxError); if (mode == "Simple") { opts.SetPolygonReductionModeSimple(); } else { opts.SetPolygonReductionModeComplex(); } HttpContext.Current.Session["options"] = opts; HttpContext.Current.Session["format"] = NewModelFormat; // string PID = HttpContext.Current.Request.QueryString["ContentObjectID"]; DataAccessFactory factory = new vwarDAL.DataAccessFactory(); vwarDAL.IDataRepository vd = factory.CreateDataRepositorProxy(); ContentObject co = vd.GetContentObjectById(PID, false, false); JsonWrappers.AdvancedDownloadPreviewSettings jsReturnParams = new JsonWrappers.AdvancedDownloadPreviewSettings(); jsReturnParams.FlashLocation = co.Location; Utils.FileStatus currentStatus = new Utils.FileStatus("", Utils.FormatType.UNRECOGNIZED); //tempFedoraCO.DisplayFile = currentStatus.filename.Replace("zip", "o3d").Replace("skp", "o3d"); currentStatus.filename = co.Location; currentStatus.hashname = co.Location; jsReturnParams.IsViewable = true; jsReturnParams.BasePath = "../Public/"; jsReturnParams.BaseContentUrl = "Model.ashx?temp=true&file="; jsReturnParams.O3DLocation = currentStatus.hashname.ToLower().Replace("zip", "o3d").Replace("skp", "o3d"); jsReturnParams.FlashLocation = currentStatus.hashname; jsReturnParams.ShowScreenshot = true; jsReturnParams.UpAxis = co.UpAxis; jsReturnParams.UnitScale = co.UnitScale; string optionalPath = (co.Location.LastIndexOf("o3d", StringComparison.CurrentCultureIgnoreCase) != -1) ? "viewerTemp/" : "converterTemp/"; string pathToTempFile = "~/App_Data/" + optionalPath + co.Location; using (FileStream stream = new FileStream(HttpContext.Current.Server.MapPath(pathToTempFile), FileMode.Create, FileAccess.Write)) { Utility_3D.ConvertedModel model = GetAndConvertModel(PID); byte[] data = model.data; Utility_3D.ConvertedModel model2 = (new Utility_3D.Model_Packager()).Convert(new MemoryStream(model.data), "test.zip"); jsReturnParams.Polygons = model2._ModelData.VertexCount.Polys; stream.Write(data, 0, data.Length); stream.Close(); } HttpContext.Current.Session["contentObject"] = co; vd.Dispose(); return(jsReturnParams); // HttpContext.Current.Response.BinaryWrite(GetAndConvertModel().data); }
public static vwar.service.host.Review CreateReview(ContentObject co, int rating, string submitter, string text) { IDataRepository dal = new DataAccessFactory().CreateDataRepositorProxy(); vwar.service.host.Review r = new vwar.service.host.Review(); r.Rating = rating; r.Submitter = submitter; r.ReviewText = text; dal.InsertReview(r.Rating, r.ReviewText, r.Submitter, co.PID); return r; }
/// <summary> /// Adds a content object with the same model data as default, but with randomized searchable parameters /// </summary> /// <returns>Newly inserted ContentObject</returns> public static ContentObject AddRandomObject() { IDataRepository dal = new DataAccessFactory().CreateDataRepositorProxy(); ContentObject rco = AddDefaultObject(); Random r = new Random(); rco.Title = r.Next().ToString(); rco.Description = r.Next().ToString(); StringBuilder sb = new StringBuilder(); for(int i = 0; i < 3; i++) sb.Append(r.Next().ToString()); rco.Keywords = sb.ToString().Trim(','); dal.UpdateContentObject(rco); return rco; }
public static string SubmitUpload(string DeveloperName, string ArtistName, string DeveloperUrl, string SponsorName, string LicenseType, bool RequireResubmit) { HttpServerUtility server = HttpContext.Current.Server; ContentObject tempCO = (ContentObject)HttpContext.Current.Session["contentObject"]; try { FileStatus status = (FileStatus)HttpContext.Current.Session["fileStatus"]; var factory = new DataAccessFactory(); IDataRepository dal = factory.CreateDataRepositorProxy(); dal.InsertContentObject(tempCO); tempCO.DeveloperName = server.HtmlEncode(DeveloperName); tempCO.ArtistName = server.HtmlEncode(ArtistName); tempCO.MoreInformationURL = server.HtmlEncode(DeveloperUrl); tempCO.RequireResubmit = RequireResubmit; tempCO.SponsorName = server.HtmlEncode(SponsorName); vwarDAL.PermissionsManager perMgr = new PermissionsManager(); var groupSetReturnCode = perMgr.SetModelToGroupLevel(HttpContext.Current.User.Identity.Name, tempCO.PID, vwarDAL.DefaultGroups.AllUsers, ModelPermissionLevel.Fetchable); groupSetReturnCode = perMgr.SetModelToGroupLevel(HttpContext.Current.User.Identity.Name, tempCO.PID, vwarDAL.DefaultGroups.AnonymousUsers, ModelPermissionLevel.Searchable); string pid = tempCO.PID; //tempCO.SponsorURL = SponsorUrl; !missing SponsorUrl metadata in ContentObject if (LicenseType == "publicdomain") { tempCO.CreativeCommonsLicenseURL = "http://creativecommons.org/publicdomain/mark/1.0/"; } else { tempCO.CreativeCommonsLicenseURL = String.Format(ConfigurationManager.AppSettings["CCBaseUrl"], LicenseType); } //Upload the thumbnail and logos string filename = status.hashname; string basehash = filename.Substring(0, filename.LastIndexOf(".") - 1); foreach (FileInfo f in new DirectoryInfo(HttpContext.Current.Server.MapPath("~/App_Data/imageTemp")).GetFiles("*" + basehash + "*")) { using (FileStream fstream = f.OpenRead()) { string type = f.Name.Substring(0, f.Name.IndexOf('_')); switch (type) { case ImagePrefix.DEVELOPER_LOGO: tempCO.DeveloperLogoImageFileName = "developer_logo" + f.Extension; tempCO.DeveloperLogoImageFileNameId = dal.SetContentFile(fstream, tempCO.PID, tempCO.DeveloperLogoImageFileName); break; case ImagePrefix.SPONSOR_LOGO: tempCO.SponsorLogoImageFileName = "sponsor_logo" + f.Extension; tempCO.SponsorLogoImageFileNameId = dal.SetContentFile(fstream, tempCO.PID, tempCO.SponsorLogoImageFileName); break; case ImagePrefix.SCREENSHOT: tempCO.ScreenShot = "screenshot" + f.Extension; tempCO.ScreenShotId = dal.SetContentFile(fstream, tempCO.PID, tempCO.ScreenShot); System.Drawing.Imaging.ImageFormat fmt = System.Drawing.Imaging.ImageFormat.Png; if (f.Extension == ".png") fmt = System.Drawing.Imaging.ImageFormat.Png; else if (f.Extension == ".jpg") fmt = System.Drawing.Imaging.ImageFormat.Jpeg; else if (f.Extension == ".gif") fmt = System.Drawing.Imaging.ImageFormat.Gif; else throw new Exception("Invalid screenshot format"); tempCO.ThumbnailId = Website.Common.GetFileSHA1AndSalt(fstream) + f.Extension; using (FileStream outFile = new FileStream(HttpContext.Current.Server.MapPath("~/thumbnails/" + tempCO.ThumbnailId), FileMode.Create)) Website.Common.GenerateThumbnail(fstream, outFile, fmt); break; default: break; } } } string dataPath = HttpContext.Current.Server.MapPath("~/App_Data/"); if (status.type == FormatType.VIEWABLE) { //Upload the original file using (FileStream s = new FileStream(dataPath + status.hashname, FileMode.Open)) { tempCO.OriginalFileId = dal.SetContentFile(s, pid, "original_" + status.filename); tempCO.OriginalFileName = "original_" + status.filename; } using (FileStream s = new FileStream(Path.Combine(dataPath, "converterTemp/" + status.hashname.ToLower().Replace("skp", "zip")),FileMode.Open,FileAccess.Read)) { tempCO.DisplayFileId = dal.SetContentFile(s, pid, status.filename.ToLower().Replace("skp", "zip")); } using (FileStream s = new FileStream(Path.Combine(dataPath, "viewerTemp/" + status.hashname.ToLower().Replace("skp", "o3d").Replace("zip", "o3d")), FileMode.Open)) { dal.SetContentFile(s, pid, status.filename.ToLower().Replace("skp", "o3d").Replace("zip", "o3d")); } } else if (status.type == FormatType.RECOGNIZED) { using (FileStream s = new FileStream(dataPath + status.hashname, FileMode.Open)) { tempCO.OriginalFileName = "original_" + status.filename; tempCO.OriginalFileId = dal.SetContentFile(s, pid, tempCO.OriginalFileName); } } tempCO.Enabled = true; tempCO.UploadedDate = DateTime.Now; ///////////////////////////////////////// //TO DO: Real Cert Time tempCO.Date_Certification = DateTime.Now; tempCO.Date_Copyright = DateTime.Now; tempCO.Date_Modification = DateTime.Now; ///////////////////////////////////////// //TO DO: Real data tempCO.CommunityURL = ""; tempCO.ContributorsURL = ""; tempCO.CertificationURL = ""; tempCO.Copyright = ""; tempCO.RightsHolder = ""; Dictionary<String, Object> metadataroot = HttpContext.Current.Session["metadata"] as Dictionary<String, Object>; tempCO.JSONMetadata = metadataroot; if (metadataroot != null) { Dictionary<String, Object> metadata = null; if(metadataroot.ContainsKey("ImmersiveEducationInitiative")) metadata = metadataroot["ImmersiveEducationInitiative"] as Dictionary<String, Object>; if (metadata != null) { if (metadata.ContainsKey("COMMUNITY")) tempCO.CommunityURL = metadata["COMMUNITY"].ToString(); if (metadata.ContainsKey("CONTRIBUTORS")) tempCO.ContributorsURL = metadata["CONTRIBUTORS"].ToString(); if (metadata.ContainsKey("CERTIFICATION")) tempCO.CertificationURL = metadata["CERTIFICATION"].ToString(); if (metadata.ContainsKey("COPYRIGHT")) tempCO.Copyright = metadata["COPYRIGHT"].ToString(); if (metadata.ContainsKey("RIGHTSHOLDER")) tempCO.RightsHolder = metadata["RIGHTSHOLDER"].ToString(); if (metadata.ContainsKey("TITLE")) tempCO.Title = metadata["TITLE"].ToString(); if (metadata.ContainsKey("DESCRIPTION")) tempCO.Description = metadata["DESCRIPTION"].ToString(); DateTime tempdate; if (metadata.ContainsKey("DATE_COPYRIGHT")) { DateTime.TryParse(metadata["DATE_COPYRIGHT"].ToString(), out tempdate); tempCO.Date_Copyright = tempdate; } if (metadata.ContainsKey("DATE_CERTIFICATION")) { DateTime.TryParse(metadata["DATE_CERTIFICATION"].ToString(), out tempdate); tempCO.Date_Certification = tempdate; } if (metadata.ContainsKey("DATE_MODIFICATION")) { DateTime.TryParse(metadata["DATE_MODIFICATION"].ToString(), out tempdate); tempCO.Date_Modification = tempdate; } if (metadata.ContainsKey("ARTIST")) { tempCO.ArtistName = ArrayOrStringToString(metadata["ARTIST"]); } if (metadata.ContainsKey("CREATOR")) { tempCO.DeveloperName = ArrayOrStringToString(metadata["CREATOR"]); } if (metadata.ContainsKey("KEYWORDS")) { string[] Keywords = metadata["KEYWORDS"].ToString().Split(new char[] {','}); for (int i = 0; i < Keywords.Length; i++) Keywords[i] = Keywords[i].Trim(); tempCO.Keywords = String.Join(",", Keywords); } if (metadata.ContainsKey("LICENSE")) { tempCO.CreativeCommonsLicenseURL = metadata["LICENSE"].ToString(); } } } dal.UpdateContentObject(tempCO); UploadReset(status.hashname); List<string> textureReferences = HttpContext.Current.Session["contentTextures"] as List<string>; List<string> textureReferenceMissing = HttpContext.Current.Session["contentMissingTextures"] as List<string>; if (textureReferences != null) { foreach (string tex in textureReferences) { tempCO.SetParentRepo(dal); tempCO.AddTextureReference(tex, "unknown", 0); } } if (textureReferenceMissing != null) { foreach (string tex in textureReferenceMissing) { tempCO.SetParentRepo(dal); tempCO.AddMissingTexture(tex, "unknown", 0); } } if (LR_3DR_Bridge.LR_Integration_Enabled()) LR_3DR_Bridge.ModelUploaded(tempCO); Website.Mail.SendModelUploaded(tempCO); dal.Dispose(); perMgr.Dispose(); return tempCO.PID; } catch (Exception e) { #if DEBUG return String.Format("fedoraError|" + e.Message + "<br /><br />" + e.StackTrace); #else return "fedoraError|" + ConfigurationManager.AppSettings["UploadPage_FedoraError"]; #endif } }
public static void DownloadButton_Click_Impl(string format, string ContentObjectID) { var factory = new DataAccessFactory(); IDataRepository vd = factory.CreateDataRepositorProxy(); var co = vd.GetContentObjectById(ContentObjectID, false); if (LR_3DR_Bridge.LR_Integration_Enabled()) LR_3DR_Bridge.ModelDownloaded(co); vd.IncrementDownloads(ContentObjectID); try { if (String.IsNullOrEmpty(format)) { string clientFileName = (!String.IsNullOrEmpty(co.OriginalFileName)) ? co.OriginalFileName : co.Location; var data = vd.GetContentFile(co.PID, clientFileName); Website.Documents.ServeDocument(data, clientFileName); } else { var data = vd.GetContentFile(co.PID, co.Location); if (format == ".dae") { Website.Documents.ServeDocument(data, co.Location); } else if (format != ".O3Dtgz") { Website.Documents.ServeDocument(data, co.Location, null, format); } else { var displayFile = vd.GetContentFile(co.PID, co.DisplayFile); Website.Documents.ServeDocument(displayFile, co.DisplayFile); } } } catch (System.Threading.ThreadAbortException tabexc) { } catch (Exception f) { } vd.Dispose(); }
public static bool SendAccessRequest(string pid, string message) { if (Membership.GetUser() == null || !Membership.GetUser().IsApproved) { return false; } var factory = new DataAccessFactory(); IDataRepository vd = factory.CreateDataRepositorProxy(); var co = vd.GetContentObjectById(pid, false); MessageManager manager = new MessageManager(); message = Westwind.Web.Utilities.HtmlSanitizer.SanitizeHtml(message,null); manager.SendMessage(Membership.GetUser().UserName, co.SubmitterEmail, "Requesting Access to Model: " + co.Title + " (" + pid + ")", "A request has been sent from " + Membership.GetUser().UserName + " for access to model " + co.Title + " (" + pid + "). Please review this request and decide on the proper action. Click here to access the model: <a href='/public/model.aspx?ContentObjectID=" + pid +"'>"+pid+"</a> The user sent this message in the request: \n\n" + message + "<br/><div class='accessbutton' onclick='GrantOrDenyRequest(\"" + Membership.GetUser().UserName + "\",\"Grant\",\"" + pid + "\");'>Grant Access</div><div class='accessbutton' onclick='GrantOrDenyRequest(\"" + Membership.GetUser().UserName + "\",\"Deny\",\"" + pid + "\");'>Deny Request</div>" , Membership.GetUser().UserName); return true; }
public static string SubmitUpload(string DeveloperName, string ArtistName, string DeveloperUrl, string SponsorName, string LicenseType, bool RequireResubmit) { HttpServerUtility server = HttpContext.Current.Server; ContentObject tempCO = (ContentObject)HttpContext.Current.Session["contentObject"]; try { FileStatus status = (FileStatus)HttpContext.Current.Session["fileStatus"]; var factory = new DataAccessFactory(); IDataRepository dal = factory.CreateDataRepositorProxy(); dal.InsertContentObject(tempCO); tempCO.DeveloperName = server.HtmlEncode(DeveloperName); tempCO.ArtistName = server.HtmlEncode(ArtistName); tempCO.MoreInformationURL = server.HtmlEncode(DeveloperUrl); tempCO.RequireResubmit = RequireResubmit; tempCO.SponsorName = server.HtmlEncode(SponsorName); vwarDAL.PermissionsManager perMgr = new PermissionsManager(); var groupSetReturnCode = perMgr.SetModelToGroupLevel(HttpContext.Current.User.Identity.Name, tempCO.PID, vwarDAL.DefaultGroups.AllUsers, ModelPermissionLevel.Fetchable); groupSetReturnCode = perMgr.SetModelToGroupLevel(HttpContext.Current.User.Identity.Name, tempCO.PID, vwarDAL.DefaultGroups.AnonymousUsers, ModelPermissionLevel.Searchable); string pid = tempCO.PID; //tempCO.SponsorURL = SponsorUrl; !missing SponsorUrl metadata in ContentObject if (LicenseType == "publicdomain") { tempCO.CreativeCommonsLicenseURL = "http://creativecommons.org/publicdomain/mark/1.0/"; } else { tempCO.CreativeCommonsLicenseURL = String.Format(ConfigurationManager.AppSettings["CCBaseUrl"], LicenseType); } //Upload the thumbnail and logos string filename = status.hashname; string basehash = filename.Substring(0, filename.LastIndexOf(".") - 1); foreach (FileInfo f in new DirectoryInfo(HttpContext.Current.Server.MapPath("~/App_Data/imageTemp")).GetFiles("*" + basehash + "*")) { using (FileStream fstream = f.OpenRead()) { string type = f.Name.Substring(0, f.Name.IndexOf('_')); switch (type) { case ImagePrefix.DEVELOPER_LOGO: tempCO.DeveloperLogoImageFileName = "developer_logo" + f.Extension; tempCO.DeveloperLogoImageFileNameId = dal.SetContentFile(fstream, tempCO.PID, tempCO.DeveloperLogoImageFileName); break; case ImagePrefix.SPONSOR_LOGO: tempCO.SponsorLogoImageFileName = "sponsor_logo" + f.Extension; tempCO.SponsorLogoImageFileNameId = dal.SetContentFile(fstream, tempCO.PID, tempCO.SponsorLogoImageFileName); break; case ImagePrefix.SCREENSHOT: tempCO.ScreenShot = "screenshot" + f.Extension; tempCO.ScreenShotId = dal.SetContentFile(fstream, tempCO.PID, tempCO.ScreenShot); System.Drawing.Imaging.ImageFormat fmt = System.Drawing.Imaging.ImageFormat.Png; if (f.Extension == ".png") fmt = System.Drawing.Imaging.ImageFormat.Png; else if (f.Extension == ".jpg") fmt = System.Drawing.Imaging.ImageFormat.Jpeg; else if (f.Extension == ".gif") fmt = System.Drawing.Imaging.ImageFormat.Gif; else throw new Exception("Invalid screenshot format"); tempCO.ThumbnailId = Website.Common.GetFileSHA1AndSalt(fstream) + f.Extension; using (FileStream outFile = new FileStream(HttpContext.Current.Server.MapPath("~/thumbnails/" + tempCO.ThumbnailId), FileMode.Create)) Website.Common.GenerateThumbnail(fstream, outFile, fmt); break; default: break; } } } string dataPath = HttpContext.Current.Server.MapPath("~/App_Data/"); if (status.type == FormatType.VIEWABLE) { //Upload the original file using (FileStream s = new FileStream(dataPath + status.hashname, FileMode.Open)) { tempCO.OriginalFileId = dal.SetContentFile(s, pid, "original_" + status.filename); tempCO.OriginalFileName = "original_" + status.filename; } using (FileStream s = new FileStream(Path.Combine(dataPath, "converterTemp/" + status.hashname.ToLower().Replace("skp", "zip")),FileMode.Open,FileAccess.Read)) { tempCO.DisplayFileId = dal.SetContentFile(s, pid, status.filename.ToLower().Replace("skp", "zip")); } using (FileStream s = new FileStream(Path.Combine(dataPath, "viewerTemp/" + status.hashname.ToLower().Replace("skp", "o3d").Replace("zip", "o3d")), FileMode.Open)) { dal.SetContentFile(s, pid, status.filename.ToLower().Replace("skp", "o3d").Replace("zip", "o3d")); } } else if (status.type == FormatType.RECOGNIZED) { using (FileStream s = new FileStream(dataPath + status.hashname, FileMode.Open)) { tempCO.OriginalFileName = "original_" + status.filename; tempCO.OriginalFileId = dal.SetContentFile(s, pid, tempCO.OriginalFileName); } } tempCO.Enabled = true; tempCO.UploadedDate = DateTime.Now; dal.UpdateContentObject(tempCO); UploadReset(status.hashname); List<string> textureReferences = HttpContext.Current.Session["contentTextures"] as List<string>; List<string> textureReferenceMissing = HttpContext.Current.Session["contentMissingTextures"] as List<string>; if (textureReferences != null) { foreach (string tex in textureReferences) { tempCO.SetParentRepo(dal); tempCO.AddTextureReference(tex, "unknown", 0); } } if (textureReferenceMissing != null) { foreach (string tex in textureReferenceMissing) { tempCO.SetParentRepo(dal); tempCO.AddMissingTexture(tex, "unknown", 0); } } if (LR_3DR_Bridge.LR_Integration_Enabled()) LR_3DR_Bridge.ModelUploaded(tempCO); Website.Mail.SendModelUploaded(tempCO); dal.Dispose(); perMgr.Dispose(); return tempCO.PID; } catch (Exception e) { #if DEBUG return String.Format("fedoraError|" + e.Message + "<br /><br />" + e.StackTrace); #else return "fedoraError|" + ConfigurationManager.AppSettings["UploadPage_FedoraError"]; #endif } }
public void TestChangeAllFields() { if (!UserLoggedIn) { Login(); } ContentObject testCO = FedoraControl.AddDefaultObject(); selenium.Open("/Users/Edit.aspx?ContentObjectID=" + testCO.PID); selenium.WaitForPageToLoad("30000"); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_TitleTextBox")).SendKeys(EditDefaults.Title); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_ContentFileUpload")).SendKeys(editedContentPath + EditDefaults.FileName); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_RequireResubmitCheckbox")).Click(); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_DeveloperLogoRadioButtonList_1")).Click(); System.Threading.Thread.Sleep(5000); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_DeveloperLogoFileUpload")).SendKeys(editedContentPath + EditDefaults.DevlogoName); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_DeveloperNameTextBox")).SendKeys(EditDefaults.DeveloperName); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_ArtistNameTextBox")).SendKeys(EditDefaults.ArtistName); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_SponsorLogoRadioButtonList_1")).Click(); System.Threading.Thread.Sleep(5000); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_SponsorLogoFileUpload")).SendKeys(editedContentPath + EditDefaults.SponsorlogoName); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_SponsorNameTextBox")).SendKeys(EditDefaults.SponsorName); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_DescriptionTextBox")).SendKeys(EditDefaults.Description); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_MoreInformationURLTextBox")).SendKeys(EditDefaults.DevUrl); //Delete the text in the textbox and replace it with the new tags selenium.GetEval("window.jQuery('#ctl00_ContentPlaceHolder1_EditControl_KeywordsTextBox').val('')"); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_KeywordsTextBox")).SendKeys(EditDefaults.Tags); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_Step1NextButton")).Click(); selenium.WaitForPageToLoad("1200000"); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_EditControl_ValidationViewSubmitButton")).Click(); selenium.WaitForPageToLoad("1200000"); IDataRepository dal = new DataAccessFactory().CreateDataRepositorProxy(); ContentObject newCO = dal.GetContentObjectById(testCO.PID, false); Exception rethrow = null; try { Assert.True(newCO.Title == EditDefaults.Title); Assert.True(newCO.Keywords == EditDefaults.Tags.Replace(" ", "")); Assert.True(newCO.Description == EditDefaults.Description); Assert.True(newCO.ArtistName == EditDefaults.ArtistName); Assert.True(newCO.DeveloperName == EditDefaults.DeveloperName); Assert.True(newCO.MoreInformationURL == EditDefaults.DevUrl); //TODO: Determine if this is desired or non-desired behavior //string newfilename_base = EditDefaults.Title.ToLower().Replace(' ', '_') + ".zip"; //Assert.True(newCO.OriginalFileName == "original_" + newfilename_base); //Assert.True(newCO.Location == newfilename_base); //Assert.True(newCO.DisplayFile == newfilename_base.Replace(".zip", ".o3d")); } catch (Exception e) { rethrow = e; } finally { dal.DeleteContentObject(newCO); //We have to rethrow to let NUnit know the test failed if (rethrow != null) { throw rethrow; } } }