Esempio n. 1
0
    /// <summary>
    ///
    /// </summary>
    public void BuildOptions()
    {
        string NewTextureForamt = ConvertTexturesList.SelectedItem.Value;
        string NewModelFormat   = ModelTypeDropDownList.SelectedItem.Value;
        int    NewTextureSize   = System.Convert.ToInt32(ResizeTexturesList.SelectedItem.Value);
        bool   bConvertTextures = ConvertTextures.Checked;
        bool   bResizeTextures  = ResizeTextures.Checked;
        bool   bReducePolys     = ReducePolys.Checked;
        bool   bConvert         = ConvertFormat.Checked;
        float  PolygonThresh    = System.Convert.ToSingle(Threshold.Text);

        if (!bConvert)
        {
            NewModelFormat = ".dae";
        }

        Utility_3D.ConverterOptions opts = new Utility_3D.ConverterOptions();
        if (bConvertTextures)
        {
            opts.EnableTextureConversion(NewTextureForamt);
        }
        if (bResizeTextures)
        {
            opts.EnableScaleTextures(NewTextureSize);
        }
        if (bReducePolys)
        {
            opts.EnablePolygonReduction(PolygonThresh);
        }
        HttpContext.Current.Session["options"] = opts;
        HttpContext.Current.Session["format"]  = NewModelFormat;
    }
Esempio n. 2
0
    /// <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);
    }
Esempio n. 3
0
    public static FileStatus Convert()
    {
        Utility_3D.Model_Packager pack = new Utility_3D.Model_Packager();
        Utility_3D _3d = new Utility_3D();

        _3d.Initialize(Website.Config.ConversionLibarayLocation);

        Utility_3D.ConvertedModel   model    = null;
        Utility_3D.ConverterOptions cOptions = new Utility_3D.ConverterOptions();
        cOptions.EnableTextureConversion(Utility_3D.ConverterOptions.PNG);
        cOptions.EnableScaleTextures(Website.Config.MaxTextureDimension);

        FileStatus status = (FileStatus)HttpContext.Current.Session["fileStatus"];

        if (status == null)
        {
            HttpContext.Current.Response.StatusCode = 500;
            return(new FileStatus("error", "error"));
        }
        using (FileStream stream = new FileStream(HttpContext.Current.Server.MapPath("~/App_data/" + status.hashname), FileMode.Open))
        {
            ContentObject tempFedoraObject = (ContentObject)HttpContext.Current.Session["contentObject"];
            try //convert the model
            {
                model = pack.Convert(stream, status.hashname, cOptions);

                HttpContext.Current.Session["contentTextures"]        = model.textureFiles;
                HttpContext.Current.Session["contentMissingTextures"] = model.missingTextures;

                Utility_3D.Parser.ModelData mdata = model._ModelData;
                tempFedoraObject.NumPolygons = mdata.VertexCount.Polys;
                tempFedoraObject.NumTextures = mdata.ReferencedTextures.Length;

                if (model._ModelData.VertexCount.Polys == 0 && model._ModelData.VertexCount.Verts == 0)
                {
                    status.converted = "false";
                    status.type      = FormatType.RECOGNIZED;
                }
                else
                {
                    status.converted = "true";
                    status.type      = FormatType.VIEWABLE;
                }


                HttpContext.Current.Session["fileStatus"] = status;

                tempFedoraObject.UpAxis = mdata.TransformProperties.UpAxis;
                if (mdata.TransformProperties.UnitMeters != 0)
                {
                    tempFedoraObject.UnitScale = System.Convert.ToString(mdata.TransformProperties.UnitMeters);
                }
                else
                {
                    tempFedoraObject.UnitScale = "1.0";
                }

                HttpContext.Current.Session["contentObject"] = tempFedoraObject;


                //Save the O3D file for the viewer into a temporary directory
                var tempfile = HttpContext.Current.Server.MapPath("~/App_Data/viewerTemp/" + status.hashname).Replace(".skp", ".zip");
                using (System.IO.FileStream savefile = new FileStream(tempfile, FileMode.Create))
                {
                    byte[] filedata = new Byte[model.data.Length];
                    model.data.CopyTo(filedata, 0);
                    savefile.Write(model.data, 0, (int)model.data.Length);
                }
                ConvertFileToO3D(HttpContext.Current, tempfile);
                if (!File.Exists(HttpContext.Current.Server.MapPath("~/App_Data/viewerTemp/" + status.hashname).Replace(".skp", ".zip").Replace(".zip", ".o3d")))
                {
                    status.converted = "false";
                    status.type      = FormatType.RECOGNIZED;
                }
                var rootDir  = HttpContext.Current.Server.MapPath("~/App_Data/converterTemp/");
                var fileName = Path.Combine(rootDir, status.hashname.Replace(".skp", ".zip"));
                if (!Directory.Exists(rootDir))
                {
                    Directory.CreateDirectory(rootDir);
                }
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                File.Move(tempfile, fileName);
            }
            catch (Exception e) //Error while converting
            {
                stream.Close();
                //FileStatus.converted is set to false by default, no need to set


                status.msg = FileStatus.ConversionFailedMessage;  //Add the conversion failed message
                deleteTempFile(status.hashname);
                HttpContext.Current.Session["fileStatus"] = null; //Reset the FileStatus for another upload attempt
            }
        }
        return(status);
    }
Esempio n. 4
0
    protected void Step1NextButton_Click(object sender, EventArgs e)
    {
        //update
        if (IsModelUpload)
        {

            vwarDAL.IDataRepository dal = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy(); ;

            if (this.IsNew)
            {
                //create new & add to session
                ContentObject co = new ContentObject(dal);
                co.Title = this.TitleTextBox.Text.Trim();
                co.UploadedDate = DateTime.Now;
                co.LastModified = DateTime.Now;
                co.Views = 0;
                co.SubmitterEmail = Context.User.Identity.Name.Trim();
                dal.InsertContentObject(co);
                FedoraContentObject = co;
                this.ContentObjectID = co.PID;

            }
            else
            {
                FedoraContentObject.Title = TitleTextBox.Text.Trim();
            }

            if (this.FedoraContentObject != null)
            {

                //asset type
                this.FedoraContentObject.AssetType = "Model";
                string newFileName = TitleTextBox.Text.ToLower().Replace(' ', '_') + Path.GetExtension(this.ContentFileUpload.PostedFile.FileName);
                //model upload
                Utility_3D.ConvertedModel model = null;
                if (this.ContentFileUpload.HasFile)
                {

                    string newOriginalFileName = "original_" + newFileName;

                    if (IsNew)
                    {
                        using (MemoryStream stream = new MemoryStream())
                        {
                            stream.Write(this.ContentFileUpload.FileBytes, 0, this.ContentFileUpload.FileBytes.Length);
                            FedoraContentObject.OriginalFileId = dal.SetContentFile(stream, FedoraContentObject.PID, newOriginalFileName);
                        }
                    }
                    else
                    {

                        //Update the original file
                        dal.UpdateFile(this.ContentFileUpload.FileBytes, FedoraContentObject.PID, FedoraContentObject.OriginalFileName, newOriginalFileName);

                    }
                    FedoraContentObject.OriginalFileName = newOriginalFileName;

                    Utility_3D.Model_Packager pack = new Utility_3D.Model_Packager();
                    Utility_3D _3d = new Utility_3D();
                    Utility_3D.ConverterOptions cOptions = new Utility_3D.ConverterOptions();
                    cOptions.EnableTextureConversion(Utility_3D.ConverterOptions.PNG);
                    cOptions.EnableScaleTextures(Website.Config.MaxTextureDimension);
                    _3d.Initialize(Website.Config.ConversionLibarayLocation);

                    string UploadedFilename = newFileName;
                    if (Path.GetExtension(UploadedFilename) != ".zip")
                        UploadedFilename = Path.ChangeExtension(newFileName, ".zip");

                    try
                    {
                        model = pack.Convert(this.ContentFileUpload.PostedFile.InputStream, this.ContentFileUpload.PostedFile.FileName, cOptions);
                    }
                    catch
                    {
                        Response.Redirect(Page.ResolveClientUrl("~/Public/Model.aspx?ContentObjectID=" + this.ContentObjectID));
                    }

                    var displayFilePath = "";
                    string convertedFileName = newFileName.Replace(Path.GetExtension(newFileName).ToLower(), ".zip");
                    if (this.ContentFileUpload.HasFile)
                    {
                        using (Stream stream = new MemoryStream())
                        {
                            stream.Write(model.data, 0, model.data.Length);
                            stream.Seek(0, SeekOrigin.Begin);
                            FedoraContentObject.Location = UploadedFilename;
                            //FedoraContentObject.DisplayFileId =
                            dal.SetContentFile(stream, FedoraContentObject, UploadedFilename);
                        }
                    }
                    else
                    {
                        using (MemoryStream stream = new MemoryStream())
                        {

                            stream.Write(model.data, 0, model.data.Length);
                            stream.Seek(0, SeekOrigin.Begin);
                            dal.SetContentFile(stream, FedoraContentObject, UploadedFilename);
                            FedoraContentObject.Location = UploadedFilename;
                        }
                    }
                    FedoraContentObject.Location = convertedFileName;

                    if (model.type != "UNKNOWN")
                    {
                        string optionalPath = (newFileName.LastIndexOf("o3d", StringComparison.CurrentCultureIgnoreCase) != -1) ? "viewerTemp/" : "converterTemp/";
                        string pathToTempFile = "~/App_Data/" + optionalPath;

                        string destPath = Path.Combine(Context.Server.MapPath(pathToTempFile), newFileName);

                        System.IO.FileStream savefile = new FileStream(destPath, FileMode.OpenOrCreate);
                        byte[] filedata = new Byte[model.data.Length];
                        model.data.CopyTo(filedata, 0);
                        savefile.Write(model.data, 0, (int)model.data.Length);
                        savefile.Close();

                        string outfilename = Context.Server.MapPath("~/App_Data/viewerTemp/") + newFileName.Replace(".zip", ".o3d");
                        string convertedtempfile = ConvertFileToO3D(destPath,outfilename);

                        displayFilePath = FedoraContentObject.DisplayFile;
                        string o3dFileName = newFileName.Replace(Path.GetExtension(newFileName).ToLower(), ".o3d");
                        if (this.ContentFileUpload.HasFile)
                        {
                            using (FileStream stream = new FileStream(convertedtempfile, FileMode.Open))
                            {
                                FedoraContentObject.DisplayFileId = dal.SetContentFile(stream, FedoraContentObject, o3dFileName);
                            }
                        }
                        else
                        {
                            using (MemoryStream stream = new MemoryStream())
                            {
                                stream.Write(filedata, 0, filedata.Length);
                                stream.Seek(0, SeekOrigin.Begin);
                                dal.SetContentFile(stream, FedoraContentObject, UploadedFilename);
                                FedoraContentObject.DisplayFile = Path.GetFileName(FedoraContentObject.DisplayFile);
                            }
                        }
                        FedoraContentObject.DisplayFile = o3dFileName;

                    }
                    else
                    {
                        FedoraContentObject.DisplayFile = string.Empty;
                    }

                    FedoraContentObject.UnitScale = model._ModelData.TransformProperties.UnitMeters.ToString();
                    FedoraContentObject.UpAxis = model._ModelData.TransformProperties.UpAxis;
                    FedoraContentObject.NumPolygons = model._ModelData.VertexCount.Polys;
                    FedoraContentObject.NumTextures = model._ModelData.ReferencedTextures.Length;

                    PopulateValidationViewMetadata(FedoraContentObject);

                }

                //upload thumbnail
                if (this.ThumbnailFileUpload.HasFile)
                {
                    int length = (int)this.ThumbnailFileUpload.PostedFile.InputStream.Length;

                    if (IsNew || FedoraContentObject.ScreenShot == "")// order counts here have to set screenshot id after the update so we can find the correct dsid
                        this.FedoraContentObject.ScreenShot = "screenshot.png";

                    FedoraContentObject.ScreenShotId = dal.SetContentFile(this.ThumbnailFileUpload.PostedFile.InputStream, this.FedoraContentObject, FedoraContentObject.ScreenShot);

                    string ext = new FileInfo(ThumbnailFileUpload.PostedFile.FileName).Extension.ToLower();
                    System.Drawing.Imaging.ImageFormat format;

                    if (ext == ".png")
                        format = System.Drawing.Imaging.ImageFormat.Png;
                    else if (ext == ".jpg")
                        format = System.Drawing.Imaging.ImageFormat.Jpeg;
                    else if (ext == ".gif")
                        format = System.Drawing.Imaging.ImageFormat.Gif;
                    else
                    {
                        ScreenshotValidator.Visible = true;
                        ScreenshotValidator.Text = "Nice job generating a POST request without the interface. Don't you feel special?";
                        return;
                    }

                    //Avoid wasting space by removing old thumbnails
                    if (!String.IsNullOrEmpty(FedoraContentObject.ThumbnailId))
                        File.Delete("~/thumbnails/" + FedoraContentObject.ThumbnailId);

                    //Use the original file bytes to remain consistent with the new file upload ID creation for thumbnails
                    FedoraContentObject.ThumbnailId = Website.Common.GetFileSHA1AndSalt(ThumbnailFileUpload.PostedFile.InputStream) + ext;

                    using (FileStream outFile = new FileStream(HttpContext.Current.Server.MapPath("~/thumbnails/" + FedoraContentObject.ThumbnailId), FileMode.Create))
                        Website.Common.GenerateThumbnail(ThumbnailFileUpload.PostedFile.InputStream, outFile, format);

                }

                //creative commons license url
                if (this.CCLicenseDropDownList.SelectedItem != null && this.CCLicenseDropDownList.SelectedValue != "None")
                {
                    this.FedoraContentObject.CreativeCommonsLicenseURL = this.CCLicenseDropDownList.SelectedValue.Trim();
                }

                //Require Resubmit Checkbox
                FedoraContentObject.RequireResubmit = this.RequireResubmitCheckbox.Checked;

                //developer logo
                this.UploadDeveloperLogo(dal, this.FedoraContentObject);

                //developer name
                if (!string.IsNullOrEmpty(this.DeveloperNameTextBox.Text))
                {
                    this.FedoraContentObject.DeveloperName = this.DeveloperNameTextBox.Text.Trim();
                }

                //sponsor logo
                this.UploadSponsorLogo(dal, this.FedoraContentObject);

                //sponsor name
                if (!string.IsNullOrEmpty(this.SponsorNameTextBox.Text))
                {
                    this.FedoraContentObject.SponsorName = this.SponsorNameTextBox.Text.Trim();
                }

                //artist name
                if (!string.IsNullOrEmpty(this.ArtistNameTextBox.Text))
                {
                    this.FedoraContentObject.ArtistName = this.ArtistNameTextBox.Text.Trim();
                }

                //format
                if (!string.IsNullOrEmpty(this.FormatTextBox.Text))
                {
                    this.FedoraContentObject.Format = this.FormatTextBox.Text.Trim();
                }

                //description
                if (!string.IsNullOrEmpty(this.DescriptionTextBox.Text))
                {
                    this.FedoraContentObject.Description = this.DescriptionTextBox.Text.Trim();
                }

                //more information url
                if (!string.IsNullOrEmpty(this.MoreInformationURLTextBox.Text))
                {
                    this.FedoraContentObject.MoreInformationURL = this.MoreInformationURLTextBox.Text.Trim();

                }

                //keywords
                string cleanTags = "";
                foreach (string s in KeywordsTextBox.Text.Split(','))
                {
                    cleanTags += s.Trim() + ",";
                }
                cleanTags = HttpContext.Current.Server.HtmlEncode(cleanTags.Trim(','));
                this.FedoraContentObject.Keywords = cleanTags;
            }

            dal.UpdateContentObject(FedoraContentObject);
            if (IsNew)
            {
                PermissionsManager perm = new PermissionsManager();
                perm.SetModelToGroupLevel(System.Configuration.ConfigurationManager.AppSettings["DefaultAdminName"], FedoraContentObject.PID, vwarDAL.DefaultGroups.AllUsers, ModelPermissionLevel.Fetchable);
                perm.SetModelToGroupLevel(System.Configuration.ConfigurationManager.AppSettings["DefaultAdminName"], FedoraContentObject.PID, vwarDAL.DefaultGroups.AnonymousUsers, ModelPermissionLevel.Searchable);
                perm.Dispose();
            }
            SetModelDisplay();
            this.PopulateValidationViewMetadata(FedoraContentObject);
            this.MultiView1.SetActiveView(this.ValidationView);
            var admins = UserProfileDB.GetAllAdministrativeUsers();
            foreach (DataRow row in admins.Rows)
            {
                var url = Request.Url.OriginalString.Replace(Request.Url.PathAndQuery, this.ResolveUrl(Website.Pages.Types.FormatModel(this.ContentObjectID)));
                Website.Mail.SendModelUploaded(FedoraContentObject);
            }
            dal.Dispose();
        }
    }
Esempio n. 5
0
    protected void Step1NextButton_Click(object sender, EventArgs e)
    {
        //update
        if (IsModelUpload)
        {
            vwarDAL.IDataRepository dal = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();;


            if (this.IsNew)
            {
                //create new & add to session
                ContentObject co = new ContentObject(dal);
                co.Title          = this.TitleTextBox.Text.Trim();
                co.UploadedDate   = DateTime.Now;
                co.LastModified   = DateTime.Now;
                co.Views          = 0;
                co.SubmitterEmail = Context.User.Identity.Name.Trim();
                dal.InsertContentObject(co);
                FedoraContentObject  = co;
                this.ContentObjectID = co.PID;
            }
            else
            {
                FedoraContentObject.Title = TitleTextBox.Text.Trim();
            }


            if (this.FedoraContentObject != null)
            {
                //asset type
                this.FedoraContentObject.AssetType = "Model";
                string newFileName = TitleTextBox.Text.ToLower().Replace(' ', '_') + Path.GetExtension(this.ContentFileUpload.PostedFile.FileName);
                //model upload
                Utility_3D.ConvertedModel model = null;
                if (this.ContentFileUpload.HasFile)
                {
                    string newOriginalFileName = "original_" + newFileName;

                    if (IsNew)
                    {
                        using (MemoryStream stream = new MemoryStream())
                        {
                            stream.Write(this.ContentFileUpload.FileBytes, 0, this.ContentFileUpload.FileBytes.Length);
                            FedoraContentObject.OriginalFileId = dal.SetContentFile(stream, FedoraContentObject.PID, newOriginalFileName);
                        }
                    }
                    else
                    {
                        //Update the original file
                        dal.UpdateFile(this.ContentFileUpload.FileBytes, FedoraContentObject.PID, FedoraContentObject.OriginalFileName, newOriginalFileName);
                    }
                    FedoraContentObject.OriginalFileName = newOriginalFileName;

                    Utility_3D.Model_Packager pack = new Utility_3D.Model_Packager();
                    Utility_3D _3d = new Utility_3D();
                    Utility_3D.ConverterOptions cOptions = new Utility_3D.ConverterOptions();
                    cOptions.EnableTextureConversion(Utility_3D.ConverterOptions.PNG);
                    cOptions.EnableScaleTextures(Website.Config.MaxTextureDimension);
                    _3d.Initialize(Website.Config.ConversionLibarayLocation);

                    string UploadedFilename = newFileName;
                    if (Path.GetExtension(UploadedFilename) != ".zip")
                    {
                        UploadedFilename = Path.ChangeExtension(newFileName, ".zip");
                    }

                    try
                    {
                        model = pack.Convert(this.ContentFileUpload.PostedFile.InputStream, this.ContentFileUpload.PostedFile.FileName, cOptions);
                    }
                    catch
                    {
                        Response.Redirect(Page.ResolveClientUrl("~/Public/Model.aspx?ContentObjectID=" + this.ContentObjectID));
                    }


                    var    displayFilePath   = "";
                    string convertedFileName = newFileName.Replace(Path.GetExtension(newFileName).ToLower(), ".zip");
                    if (this.ContentFileUpload.HasFile)
                    {
                        using (Stream stream = new MemoryStream())
                        {
                            stream.Write(model.data, 0, model.data.Length);
                            stream.Seek(0, SeekOrigin.Begin);
                            FedoraContentObject.Location = UploadedFilename;
                            //FedoraContentObject.DisplayFileId =
                            dal.SetContentFile(stream, FedoraContentObject, UploadedFilename);
                        }
                    }
                    else
                    {
                        using (MemoryStream stream = new MemoryStream())
                        {
                            stream.Write(model.data, 0, model.data.Length);
                            stream.Seek(0, SeekOrigin.Begin);
                            dal.SetContentFile(stream, FedoraContentObject, UploadedFilename);
                            FedoraContentObject.Location = UploadedFilename;
                        }
                    }
                    FedoraContentObject.Location = convertedFileName;

                    if (model.type != "UNKNOWN")
                    {
                        string optionalPath   = (newFileName.LastIndexOf("o3d", StringComparison.CurrentCultureIgnoreCase) != -1) ? "viewerTemp/" : "converterTemp/";
                        string pathToTempFile = "~/App_Data/" + optionalPath;

                        string destPath = Path.Combine(Context.Server.MapPath(pathToTempFile), newFileName);

                        System.IO.FileStream savefile = new FileStream(destPath, FileMode.OpenOrCreate);
                        byte[] filedata = new Byte[model.data.Length];
                        model.data.CopyTo(filedata, 0);
                        savefile.Write(model.data, 0, (int)model.data.Length);
                        savefile.Close();

                        string outfilename       = Context.Server.MapPath("~/App_Data/viewerTemp/") + newFileName.Replace(".zip", ".o3d");
                        string convertedtempfile = ConvertFileToO3D(destPath, outfilename);



                        displayFilePath = FedoraContentObject.DisplayFile;
                        string o3dFileName = newFileName.Replace(Path.GetExtension(newFileName).ToLower(), ".o3d");
                        if (this.ContentFileUpload.HasFile)
                        {
                            using (FileStream stream = new FileStream(convertedtempfile, FileMode.Open))
                            {
                                FedoraContentObject.DisplayFileId = dal.SetContentFile(stream, FedoraContentObject, o3dFileName);
                            }
                        }
                        else
                        {
                            using (MemoryStream stream = new MemoryStream())
                            {
                                stream.Write(filedata, 0, filedata.Length);
                                stream.Seek(0, SeekOrigin.Begin);
                                dal.SetContentFile(stream, FedoraContentObject, UploadedFilename);
                                FedoraContentObject.DisplayFile = Path.GetFileName(FedoraContentObject.DisplayFile);
                            }
                        }
                        FedoraContentObject.DisplayFile = o3dFileName;
                    }
                    else
                    {
                        FedoraContentObject.DisplayFile = string.Empty;
                    }


                    FedoraContentObject.UnitScale   = model._ModelData.TransformProperties.UnitMeters.ToString();
                    FedoraContentObject.UpAxis      = model._ModelData.TransformProperties.UpAxis;
                    FedoraContentObject.NumPolygons = model._ModelData.VertexCount.Polys;
                    FedoraContentObject.NumTextures = model._ModelData.ReferencedTextures.Length;

                    PopulateValidationViewMetadata(FedoraContentObject);
                }

                //upload thumbnail
                if (this.ThumbnailFileUpload.HasFile)
                {
                    int length = (int)this.ThumbnailFileUpload.PostedFile.InputStream.Length;

                    if (IsNew || FedoraContentObject.ScreenShot == "")// order counts here have to set screenshot id after the update so we can find the correct dsid
                    {
                        this.FedoraContentObject.ScreenShot = "screenshot.png";
                    }

                    FedoraContentObject.ScreenShotId = dal.SetContentFile(this.ThumbnailFileUpload.PostedFile.InputStream, this.FedoraContentObject, FedoraContentObject.ScreenShot);

                    string ext = new FileInfo(ThumbnailFileUpload.PostedFile.FileName).Extension.ToLower();
                    System.Drawing.Imaging.ImageFormat format;

                    if (ext == ".png")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Png;
                    }
                    else if (ext == ".jpg")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Jpeg;
                    }
                    else if (ext == ".gif")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Gif;
                    }
                    else
                    {
                        ScreenshotValidator.Visible = true;
                        ScreenshotValidator.Text    = "Nice job generating a POST request without the interface. Don't you feel special?";
                        return;
                    }

                    //Avoid wasting space by removing old thumbnails
                    //if (!String.IsNullOrEmpty(FedoraContentObject.ThumbnailId))
                    //   File.Delete("~/thumbnails/" + FedoraContentObject.ThumbnailId);

                    //Use the original file bytes to remain consistent with the new file upload ID creation for thumbnails
                    FedoraContentObject.ThumbnailId = Website.Common.GetFileSHA1AndSalt(ThumbnailFileUpload.PostedFile.InputStream) + ext;

                    //using (FileStream outFile = new FileStream(HttpContext.Current.Server.MapPath("~/thumbnails/" + FedoraContentObject.ThumbnailId), FileMode.Create))
                    //   Website.Common.GenerateThumbnail(ThumbnailFileUpload.PostedFile.InputStream, outFile, format);
                }

                //creative commons license url
                if (this.CCLicenseDropDownList.SelectedItem != null && this.CCLicenseDropDownList.SelectedValue != "None")
                {
                    this.FedoraContentObject.CreativeCommonsLicenseURL = this.CCLicenseDropDownList.SelectedValue.Trim();
                }

                //Require Resubmit Checkbox
                FedoraContentObject.RequireResubmit = this.RequireResubmitCheckbox.Checked;

                //developer logo
                this.UploadDeveloperLogo(dal, this.FedoraContentObject);

                //developer name
                if (!string.IsNullOrEmpty(this.DeveloperNameTextBox.Text))
                {
                    this.FedoraContentObject.DeveloperName = this.DeveloperNameTextBox.Text.Trim();
                }

                //sponsor logo
                this.UploadSponsorLogo(dal, this.FedoraContentObject);


                //sponsor name
                if (!string.IsNullOrEmpty(this.SponsorNameTextBox.Text))
                {
                    this.FedoraContentObject.SponsorName = this.SponsorNameTextBox.Text.Trim();
                }

                //artist name
                if (!string.IsNullOrEmpty(this.ArtistNameTextBox.Text))
                {
                    this.FedoraContentObject.ArtistName = this.ArtistNameTextBox.Text.Trim();
                }

                //format
                if (!string.IsNullOrEmpty(this.FormatTextBox.Text))
                {
                    this.FedoraContentObject.Format = this.FormatTextBox.Text.Trim();
                }


                //description
                if (!string.IsNullOrEmpty(this.DescriptionTextBox.Text))
                {
                    this.FedoraContentObject.Description = this.DescriptionTextBox.Text.Trim();
                }

                //more information url
                if (!string.IsNullOrEmpty(this.MoreInformationURLTextBox.Text))
                {
                    this.FedoraContentObject.MoreInformationURL = this.MoreInformationURLTextBox.Text.Trim();
                }

                //keywords
                string cleanTags = "";
                foreach (string s in KeywordsTextBox.Text.Split(','))
                {
                    cleanTags += s.Trim() + ",";
                }
                cleanTags = HttpContext.Current.Server.HtmlEncode(cleanTags.Trim(','));
                this.FedoraContentObject.Keywords = cleanTags;
            }

            dal.UpdateContentObject(FedoraContentObject);
            if (IsNew)
            {
                PermissionsManager perm = new PermissionsManager();
                perm.SetModelToGroupLevel(System.Configuration.ConfigurationManager.AppSettings["DefaultAdminName"], FedoraContentObject.PID, vwarDAL.DefaultGroups.AllUsers, ModelPermissionLevel.Fetchable);
                perm.SetModelToGroupLevel(System.Configuration.ConfigurationManager.AppSettings["DefaultAdminName"], FedoraContentObject.PID, vwarDAL.DefaultGroups.AnonymousUsers, ModelPermissionLevel.Searchable);
                perm.Dispose();
            }
            SetModelDisplay();
            this.PopulateValidationViewMetadata(FedoraContentObject);
            this.MultiView1.SetActiveView(this.ValidationView);
            var admins = UserProfileDB.GetAllAdministrativeUsers();
            foreach (DataRow row in admins.Rows)
            {
                var url = Request.Url.OriginalString.Replace(Request.Url.PathAndQuery, this.ResolveUrl(Website.Pages.Types.FormatModel(this.ContentObjectID)));
                Website.Mail.SendModelUploaded(FedoraContentObject);
            }
            dal.Dispose();
        }
    }
Esempio n. 6
0
    public static FileStatus Convert()
    {
        Utility_3D.Model_Packager pack = new Utility_3D.Model_Packager();
        Utility_3D _3d = new Utility_3D();
        _3d.Initialize(Website.Config.ConversionLibarayLocation);

        Utility_3D.ConvertedModel model = null;
        Utility_3D.ConverterOptions cOptions = new Utility_3D.ConverterOptions();
        cOptions.EnableTextureConversion(Utility_3D.ConverterOptions.PNG);
        cOptions.EnableScaleTextures(Website.Config.MaxTextureDimension);

        FileStatus status = (FileStatus)HttpContext.Current.Session["fileStatus"];

        if (status == null)
        {
            HttpContext.Current.Response.StatusCode = 500;
            return new FileStatus("error", "error");
        }
        using (FileStream stream = new FileStream(HttpContext.Current.Server.MapPath("~/App_data/" + status.hashname), FileMode.Open))
        {

            ContentObject tempFedoraObject = (ContentObject)HttpContext.Current.Session["contentObject"];
            try //convert the model
            {
                model = pack.Convert(stream, status.hashname, cOptions);

                HttpContext.Current.Session["contentTextures"] = model.textureFiles;
                HttpContext.Current.Session["contentMissingTextures"] = model.missingTextures;

                Utility_3D.Parser.ModelData mdata = model._ModelData;
                tempFedoraObject.NumPolygons = mdata.VertexCount.Polys;
                tempFedoraObject.NumTextures = mdata.ReferencedTextures.Length;

                if (model._ModelData.VertexCount.Polys == 0 && model._ModelData.VertexCount.Verts == 0)
                {
                    status.converted = "false";
                    status.type = FormatType.RECOGNIZED;
                }
                else
                {
                    status.converted = "true";
                    status.type = FormatType.VIEWABLE;
                }

                HttpContext.Current.Session["fileStatus"] = status;

                tempFedoraObject.UpAxis = mdata.TransformProperties.UpAxis;
                if (mdata.TransformProperties.UnitMeters != 0)
                {
                    tempFedoraObject.UnitScale = System.Convert.ToString(mdata.TransformProperties.UnitMeters);
                }
                else
                {
                    tempFedoraObject.UnitScale = "1.0";
                }

                HttpContext.Current.Session["contentObject"] = tempFedoraObject;

                //Save the O3D file for the viewer into a temporary directory
                var tempfile = HttpContext.Current.Server.MapPath("~/App_Data/viewerTemp/" + status.hashname).Replace(".skp", ".zip");
                using (System.IO.FileStream savefile = new FileStream(tempfile, FileMode.Create))
                {
                    byte[] filedata = new Byte[model.data.Length];
                    model.data.CopyTo(filedata, 0);
                    savefile.Write(model.data, 0, (int)model.data.Length);
                }
                ConvertFileToO3D(HttpContext.Current, tempfile);
                if (!File.Exists(HttpContext.Current.Server.MapPath("~/App_Data/viewerTemp/" + status.hashname).Replace(".skp", ".zip").Replace(".zip", ".o3d")))
                {
                    status.converted = "false";
                    status.type = FormatType.RECOGNIZED;
                }
                var rootDir = HttpContext.Current.Server.MapPath("~/App_Data/converterTemp/");
                var fileName = Path.Combine(rootDir, status.hashname.Replace(".skp", ".zip"));
                if (!Directory.Exists(rootDir))
                {
                    Directory.CreateDirectory(rootDir);
                }
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                File.Move(tempfile, fileName);
            }
            catch (Exception e) //Error while converting
            {
                stream.Close();
                //FileStatus.converted is set to false by default, no need to set

                status.msg = FileStatus.ConversionFailedMessage; //Add the conversion failed message
                deleteTempFile(status.hashname);
                HttpContext.Current.Session["fileStatus"] = null; //Reset the FileStatus for another upload attempt

            }
        }
        return status;
    }
Esempio n. 7
0
    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);
    }
Esempio n. 8
0
        //Get the content for a model
        public Stream GetModel(string pid, string format, string options, string key)
        {
            SetCorsHeaders();

            if (!CheckKey(key))
                return null;
            pid = pid.Replace('_', ':');

            //Get the content object
            vwarDAL.ContentObject co = GetRepo().GetContentObjectById(pid, false);

            //Check permissions
            if (!DoValidate(Security.TransactionType.Access, pid))
            {
                ReleaseRepo();
                return null;
            }

            if (options == "uncompressed")
            {
                //check the cache!
                byte[] uncompresseddata = null;
                if (format == "dae")
                    uncompresseddata = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.DAE));
                if (format == "fbx")
                    uncompresseddata = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.FBX));
                if (format == "3ds")
                    uncompresseddata = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE._3DS));
                if (format == "obj")
                    uncompresseddata = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.OBJ));
                if (format == "json")
                    uncompresseddata = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.JSON));

                MemoryStream ms2 = null;

                if (uncompresseddata != null)
                {
                    ms2 = new MemoryStream(uncompresseddata);
                    SetResponseHeaders(GetMimeType("" + format + "." + format), (int)ms2.Length, "attachment; filename=" + co.Title + "." + format);
                    ReleaseRepo();
                    return ms2;
                }
            }

            //check the cache!
            byte[] data = null;
            if (format == "dae")
                data = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.CompressedDAE));
            if (format == "fbx")
                data = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.CompressedFBX));
            if (format == "3ds")
                data = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.Compressed3DS));
            if (format == "obj")
                data = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.CompressedOBJ));
            if (format == "json")
                data = CacheManager.CheckCache<byte[]>(new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.CompressedJSON));

            MemoryStream ms = null;

            if (data != null)
            {
                ms = new MemoryStream(data);
                SetResponseHeaders(GetMimeType("" + format + "." + "zip"), (int)ms.Length, "attachment; filename=" + co.Title + "_" + format + "." + "zip");
                ReleaseRepo();
            }
            else
            {
                //Check that this content object actually has a content file
                if (co.Location != "")
                {

                    //If they want the dae file, they can get just the contnet file
                    if (format.ToLower() == "dae" || format.ToLower() == "collada")
                    {
                        ms = (MemoryStream)co.GetContentFile();

                        SetResponseHeaders(GetMimeType(co.Location), (int)ms.Length, "attachment; filename=" + co.Location);
                        //return ms as Stream;
                    }
                    //note that if the options string is anything, then the cached display file is not the one the client needs
                    else if ((format.ToLower() == "o3d" || format.ToLower() == "o3dtgz") && options == "")
                    {
                        ms = (MemoryStream)GetRepo().GetCachedContentObjectTransform(co, "o3d");

                        SetResponseHeaders(GetMimeType(co.DisplayFile), (int)ms.Length, "attachment; filename=" + co.DisplayFile);
                        //no point following on to try to uncompress this - it's already uncompressed
                        ReleaseRepo();
                        return ms as Stream;
                    }
                    //If they want any type other than the ones above, do the conversion
                    else
                    {
                        //Get the base content file
                        Stream unconvertedData = co.GetContentFile();
                        //setup the conversion system
                        Utility_3D _3d = new Utility_3D();
                        _3d.Initialize(ConfigurationManager.AppSettings["LibraryLocation"]);
                        Utility_3D.Model_Packager converter = new Utility_3D.Model_Packager();
                        Utility_3D.ConverterOptions opts = new Utility_3D.ConverterOptions();
                        //No need to gather metadata during this conversion, which slows down the conversion significantly
                        //opts.DisableMetadataGathering();

                        //Try to convert the model to the requested format
                        Utility_3D.ConvertedModel model;
                        try
                        {
                            model = converter.Convert(unconvertedData, co.Location, format, opts);
                        }
                        catch (Utility_3D.ConversionException e)
                        {
                            throw new System.Net.WebException(e.what());
                        }

                        //Looks like the conversion worked.
                        SetResponseHeaders(GetMimeType(co.DisplayFile + "." + format), (int)model.data.Length, "attachment; filename=" + co.Location);
                        //Return the new data
                        ms = new MemoryStream(model.data);

                        if (format == "dae")
                            CacheManager.Cache<byte[]>(ref model.data, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.CompressedDAE));
                        if (format == "fbx")
                            CacheManager.Cache<byte[]>(ref model.data, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.CompressedFBX));
                        if (format == "3ds")
                            CacheManager.Cache<byte[]>(ref model.data, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.Compressed3DS));
                        if (format == "obj")
                            CacheManager.Cache<byte[]>(ref model.data, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.CompressedOBJ));
                        if (format == "json")
                            CacheManager.Cache<byte[]>(ref model.data, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.CompressedJSON));

                        //return ms as Stream;
                        GetRepo().IncrementDownloads(co.PID);
                        ReleaseRepo();
                    }
                }
            }
            //
            if (options == "uncompressed")
            {
                ms.Seek(0, SeekOrigin.Begin);
                Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(ms);
                foreach (Ionic.Zip.ZipEntry ze in zip)
                {
                    if ("." + format == (Path.GetExtension(ze.FileName.ToLower())))
                    {
                        MemoryStream model = new MemoryStream();
                        ze.Extract(model);

                        //Cache it!
                        byte[] tocache = new byte[model.Length];
                        model.Seek(0, SeekOrigin.Begin);
                        model.Read(tocache, 0, (int)model.Length);
                        model.Seek(0, SeekOrigin.Begin);

                        if (format == "dae")
                            CacheManager.Cache<byte[]>(ref tocache, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.DAE));
                        if (format == "fbx")
                            CacheManager.Cache<byte[]>(ref tocache, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.FBX));
                        if (format == "3ds")
                            CacheManager.Cache<byte[]>(ref tocache, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE._3DS));
                        if (format == "obj")
                            CacheManager.Cache<byte[]>(ref tocache, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.OBJ));
                        if (format == "json")
                            CacheManager.Cache<byte[]>(ref tocache, new CacheIdentifier(pid, "", CacheIdentifier.FILETYPE.JSON));

                        SetResponseHeaders(GetMimeType(ze.FileName.ToLower()), (int)model.Length, "attachment; filename=" + ze.FileName.ToLower());
                        model.Seek(0, SeekOrigin.Begin);
                        ReleaseRepo();
                        return model as Stream;
                    }
                }
            }
            //There is no content for this content object

            return ms;
        }
Esempio n. 9
0
        //Upload a new content object. Returns the pid of the uploaded file
        public string UploadFile(byte[] data, string pid, string key)
        {
            if (!CheckKey(key))
                return null;

            //Check permissions
            if (!DoValidate(Security.TransactionType.Create, null))
                return "Not authorized";

            vwarDAL.ContentObject co = null;
            //Create a new object
            if (pid == "")
            {
                co = GetRepo().GetNewContentObject();
                co.Revision = 0;
                //Setup some default values
                co.Title = "tempupload";
                co.Views = 0;
            }
            if (pid != "")
            {
                co = GetRepo().GetContentObjectById(pid, false);
                if (co == null)
                {
                    ReleaseRepo();
                    return "PID does not exist";
                }
                co.Revision = co.Revision + 1;
            }

            co.UploadedDate = DateTime.Now;
            co.LastModified = DateTime.Now;

            //The owner of this content is the person whose credentials were used to upload it
            co.SubmitterEmail = GetUserEmail();

            Utility_3D.ConvertedModel model;
            try
            {
                //Setup the conversion library
                Utility_3D _3d = new Utility_3D();
                _3d.Initialize(ConfigurationManager.AppSettings["LibraryLocation"]);
                Utility_3D.Model_Packager converter = new Utility_3D.Model_Packager();
                Utility_3D.ConverterOptions opts = new Utility_3D.ConverterOptions();

                //We do want metadata gathered with this conversion
                opts.EnableMetadataGathering();
                opts.EnableScaleTextures(512);
                opts.EnableTextureConversion("png");

                //Try to convert the model package into a dae
                //Note that the system might allow you to input an skp, so this should probably take a filename
                //The conversion needs to be told that the input is skp, and currently it's hardcoded to show it as a zip

                model = converter.Convert(new MemoryStream(data), "content.zip", "dae", opts);
            }
            catch (Utility_3D.ConversionException e)
            {
                model = null;
            }
            catch (System.Exception e)
            {
                model = null;
            }

            if (model != null)
            {
                //Copy the data gathered by the converter to the metadata
                co.NumPolygons = model._ModelData.VertexCount.Polys;
                co.NumTextures = model.textureFiles.Count;
                co.UpAxis = model._ModelData.TransformProperties.UpAxis;
                co.UnitScale = model._ModelData.TransformProperties.UnitMeters.ToString();
                co.LastModified = System.DateTime.Now;

                co.Views = 0;
            }

            co.UploadedDate = System.DateTime.Now;
            //Place this new object in the repo
            if (pid != "")
            {
                GetRepo().InsertContentRevision(co);
            }
            else
            {
                GetRepo().InsertContentObject(co);
            }

            if (model != null)
            {
                //Set the stream from the conversion to the content of this object
                co.SetContentFile(new MemoryStream(model.data), "content.zip");
                //Set the display file
                Stream displayfile = ConvertFileToO3D(new MemoryStream(model.data));
                if (displayfile != null)
                    co.SetDisplayFile(displayfile, "content.o3d");

                //Add the references to textrues discovered by the converter to the database
                foreach (string i in model._ModelData.ReferencedTextures)
                    co.AddTextureReference(i.ToLower(), "Diffuse", 0);

                //Add the references to missing textures to the database
                foreach (string i in model.missingTextures)
                    co.AddMissingTexture(i.ToLower(), "Diffuse", 0);
            }

            //set the original file data
            co.OriginalFileName = "OriginalUpload.zip";
            co.OriginalFileId = GetRepo().SetContentFile(new MemoryStream(data), co.PID, co.OriginalFileName);
            co.CommitChanges();

            //setup the default permissions
            vwarDAL.PermissionsManager perm = new vwarDAL.PermissionsManager();
            perm.SetModelToGroupLevel(GetUserEmail(), co.PID, vwarDAL.DefaultGroups.AllUsers, vwarDAL.ModelPermissionLevel.Fetchable);
            perm.SetModelToGroupLevel(GetUserEmail(), co.PID, vwarDAL.DefaultGroups.AnonymousUsers, vwarDAL.ModelPermissionLevel.Searchable);

            perm.Dispose();
            ReleaseRepo();
            //return the pid of this new object
            return co.PID;
        }
    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);
    }
    /// <summary>
    /// 
    /// </summary>
    public void BuildOptions()
    {
        string NewTextureForamt = ConvertTexturesList.SelectedItem.Value;
        string NewModelFormat = ModelTypeDropDownList.SelectedItem.Value;
        int NewTextureSize = System.Convert.ToInt32(ResizeTexturesList.SelectedItem.Value);
        bool bConvertTextures = ConvertTextures.Checked;
        bool bResizeTextures = ResizeTextures.Checked;
        bool bReducePolys = ReducePolys.Checked;
        bool bConvert = ConvertFormat.Checked;
        float PolygonThresh = System.Convert.ToSingle(Threshold.Text);

        if (!bConvert)
            NewModelFormat = ".dae";

        Utility_3D.ConverterOptions opts = new Utility_3D.ConverterOptions();
        if (bConvertTextures)
            opts.EnableTextureConversion(NewTextureForamt);
        if (bResizeTextures)
            opts.EnableScaleTextures(NewTextureSize);
        if (bReducePolys)
            opts.EnablePolygonReduction(PolygonThresh);
        HttpContext.Current.Session["options"] = opts;
        HttpContext.Current.Session["format"] = NewModelFormat;
    }