Exemple #1
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);
    }
    private void UploadSponsorLogo(vwarDAL.IDataRepository dal, ContentObject co)
    {
        if (this.SponsorLogoRadioButtonList.SelectedItem != null)
        {
            switch (this.SponsorLogoRadioButtonList.SelectedValue.Trim())
            {
            case "0":     //use profile logo

                //use profile logo if use current and there's an empty file name otherwise don't change
                if (string.IsNullOrEmpty(co.SponsorLogoImageFileName))
                {
                    DataTable dt = UserProfileDB.GetUserProfileSponsorLogoByUserName(Context.User.Identity.Name);

                    if (dt != null && dt.Rows.Count > 0)
                    {
                        DataRow dr = dt.Rows[0];

                        if (dr["Logo"] != System.DBNull.Value && dr["LogoContentType"] != System.DBNull.Value && !string.IsNullOrEmpty(dr["LogoContentType"].ToString()))
                        {
                            var data = (byte[])dr["Logo"];
                            using (MemoryStream s = new MemoryStream())
                            {
                                s.Write(data, 0, data.Length);
                                s.Position = 0;

                                //filename
                                co.SponsorLogoImageFileName = "sponsor.jpg";


                                if (!string.IsNullOrEmpty(dr["FileName"].ToString()))
                                {
                                    co.SponsorLogoImageFileName = dr["FileName"].ToString();
                                }
                                FedoraContentObject.SponsorLogoImageFileNameId =
                                    dal.SetContentFile(s, co, co.SponsorLogoImageFileName);
                            }
                        }
                    }
                }



                break;

            case "1":     //Upload logo
                if (this.SponsorLogoFileUpload.FileContent.Length > 0 && !string.IsNullOrEmpty(this.SponsorLogoFileUpload.FileName))
                {
                    co.SponsorLogoImageFileName     = this.SponsorLogoFileUpload.FileName;
                    co.DeveloperLogoImageFileNameId = dal.SetContentFile(this.SponsorLogoFileUpload.FileContent, co, this.SponsorLogoFileUpload.FileName);
                }

                break;

            case "2":     //none
                break;
            }
        }
    }
    public string UpdateThumbnailCache(string pid)
    {
        vwarDAL.IDataRepository dal = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();

        APIWrapper api = null;

        if (Membership.GetUser() != null && Membership.GetUser().IsApproved)
        {
            api = new APIWrapper(Membership.GetUser().UserName, null);
        }
        else
        {
            api = new APIWrapper(vwarDAL.DefaultUsers.Anonymous[0], null);
        }

        foreach (vwarDAL.ContentObject co in allpids)
        {
            if (co.PID == pid)
            {
                try
                {
                    System.IO.Stream screenshotdata = api.GetScreenshot(co.PID, "00-00-00");
                    if (screenshotdata != null)
                    {
                        int length = (int)screenshotdata.Length;

                        if (length != 0)
                        {
                            byte[] data = new byte[screenshotdata.Length];
                            screenshotdata.Seek(0, SeekOrigin.Begin);
                            screenshotdata.Read(data, 0, length);
                            api.UploadScreenShot(data, co.PID, co.ScreenShot, "00-00-00");
                        }
                        else
                        {
                            dal.Dispose();
                            return("No screenshot data");
                        }
                    }
                    else
                    {
                        dal.Dispose();
                        return("No screenshot data");
                    }
                }
                catch (System.Exception ex)
                {
                    return(ex.Message);
                }
            }
        }
        dal.Dispose();
        return("OK");
    }
Exemple #4
0
    public ArrayList GetAllPIDS()
    {
        vwarDAL.IDataRepository dal = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();
        allpids = dal.GetAllContentObjects();
        ArrayList list = new ArrayList();

        foreach (vwarDAL.ContentObject co in allpids)
        {
            list.Add(co.PID);
        }
        dal.Dispose();
        return(list);
    }
Exemple #5
0
 protected void ContentObjectFormView_ItemCommand(object sender, FormViewCommandEventArgs e)
 {
     switch (e.CommandName)
     {
     case "DownloadZip":
         Label IDLabel              = (Label)FindControl("IDLabel");
         Label LocationLabel        = (Label)FindControl("LocationLabel");
         vwarDAL.IDataRepository vd = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();;
         vd.IncrementDownloads(ContentObjectID);
         string filePath       = Website.Common.FormatZipFilePath(IDLabel.Text.Trim(), LocationLabel.Text.Trim());
         string clientFileName = System.IO.Path.GetFileName(filePath);
         Website.Documents.ServeDocument(vd.GetContentFile(ContentObjectID, clientFileName), clientFileName);
         vd.Dispose();
         vd = null;
         break;
     }
 }
    private void BindThumbnail()
    {
        this.ThumbnailFileImage.Visible = false;

        if (!this.IsNew && this.FedoraContentObject != null && !string.IsNullOrEmpty(this.FedoraContentObject.ScreenShot))
        {
            try
            {
                vwarDAL.IDataRepository vd = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();
                this.ThumbnailFileImage.ImageUrl = String.Format("http://{0}:{1}/json/Screenshot/{1}", Request.Url.Host, Request.Url.Port, this.FedoraContentObject.PID);
                this.ThumbnailFileImage.Visible  = true;
                vd.Dispose();
                return;
            }
            catch
            {
            }
        }
    }
    protected void ValidationViewSubmitButton_Click(object sender, EventArgs e)
    {
        /* if (this.FedoraContentObject == null || String.IsNullOrEmpty(this.FedoraContentObject.PID))
         * {
         *   FedoraContentObject = DAL.GetContentObjectById(ContentObjectID, false, false); ;
         * }*/
        vwarDAL.IDataRepository dal = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();;
        FedoraContentObject = dal.GetContentObjectById(ContentObjectID, false, false);



        if (!string.IsNullOrEmpty(this.UnitScaleTextBox.Text))
        {
            this.FedoraContentObject.UnitScale = this.UnitScaleTextBox.Text.Trim();
        }

        this.FedoraContentObject.UpAxis = this.UpAxisRadioButtonList.SelectedValue.Trim();

        //polygons
        int numPolys = 0;

        if (int.TryParse(NumPolygonsTextBox.Text, out numPolys))
        {
            FedoraContentObject.NumPolygons = numPolys;
        }
        int numTextures = 0;

        if (int.TryParse(NumTexturesTextBox.Text, out numTextures))
        {
            FedoraContentObject.NumTextures = numTextures;
        }

        FedoraContentObject.Enabled = true;
        dal.UpdateContentObject(this.FedoraContentObject);

        //redirect
        Response.Redirect(Website.Pages.Types.FormatModel(this.ContentObjectID));
        dal.Dispose();
    }
    protected void Rating_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(ratingText.Text))
        {
            vwarDAL.IDataRepository vd = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();;

            var ratingValue = rating.CurrentRating;
            vd.InsertReview(ratingValue, ratingText.Text.Length > 255 ? ratingText.Text.Substring(0, 255)
                : ratingText.Text, Context.User.Identity.Name, ContentObjectID);
            ViewState[RATINGKEY] = null;
            Response.Redirect(Request.RawUrl);

            ContentObject co = vd.GetContentObjectById(ContentObjectID, false);

            if (LR_3DR_Bridge.LR_Integration_Enabled())
            {
                LR_3DR_Bridge.ModelRated(co);
            }
            vd.Dispose();
            vd = null;
        }
    }
Exemple #9
0
        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();
            }
        }
Exemple #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //maintain scroll position

        if (this.Page.Master.FindControl("SearchPanel") != null)
        {
            //hide the search panel
            this.Page.Master.FindControl("SearchPanel").Visible = false;
        }

        try { FedoraContentObject = CachedFedoraContentObject; }
        catch {
            if (!String.IsNullOrEmpty(ContentObjectID))
            {
                vwarDAL.IDataRepository vd = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();
                FedoraContentObject = vd.GetContentObjectById(ContentObjectID, false);
                vd.Dispose();
            }
        }
        //redirect if user is not authenticated
        if (!Context.User.Identity.IsAuthenticated)
        {
            Response.Redirect(Website.Pages.Types.Default);
        }

        if (!Page.IsPostBack)
        {
            IsNew = true;
            var id = ContentObjectID;

            this.MultiView1.ActiveViewIndex = 0;
            this.BindCCLHyperLink();
            this.BindContentObject();

            ContentFileUploadRequiredFieldValidator.Enabled = IsNew;
        }
    }
Exemple #11
0
    protected void MissingTextureViewNextButton_Click(object sender, EventArgs e)
    {
        //get a reference to the model
        Utility_3D.ConvertedModel model = null;// GetModel();
        foreach (Control c in MissingTextureArea.Controls)
        {
            if (c is Controls_MissingTextures)
            {
                //loop over each dialog and find out if the user uploaded a file
                Utility_3D.Model_Packager pack = new Utility_3D.Model_Packager();
                var uploadfile = (Controls_MissingTextures)c;
                //if they uploaded a file, push the file and model into the dll which will add the file
                if (uploadfile.FileName != "")
                {
                    pack.AddTextureToModel(ref model, uploadfile.FileContent, uploadfile.FileName);
                }
            }
        }
        //save the changes to the model
        //SetModel(model);
        //Get the DAL

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

        //Get the content object for this model
        ContentObject contentObj = dal.GetContentObjectById(ContentObjectID, false);

        using (MemoryStream stream = new MemoryStream())
        {
            //upload the modified datastream to the dal
            stream.Write(model.data, 0, model.data.Length);
            stream.Seek(0, SeekOrigin.Begin);
            dal.SetContentFile(stream, contentObj, contentObj.Location);
        }
        this.MultiView1.SetActiveView(this.ValidationView);
        dal.Dispose();
    }
Exemple #12
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();
        }
    }
Exemple #13
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);
    }
    private void BindModelDetails()
    {
        if (String.IsNullOrEmpty(ContentObjectID))
        {
            Response.Redirect("~/Default.aspx");
        }
        PermissionsManager prm = new PermissionsManager();



        ModelPermissionLevel Permission = prm.GetPermissionLevel(Context.User.Identity.Name, ContentObjectID);

        prm.Dispose();
        prm = null;
        if (Permission < ModelPermissionLevel.Searchable)
        {
            Response.StatusCode = (int)HttpStatusCode.Unauthorized;
            return;
        }


        APILink.NavigateUrl = "https://" + ConfigurationManager.AppSettings["LR_Integration_APIBaseURL"] + "/" + ContentObjectID + "/Metadata/json?id=00-00-00";
        var uri = Request.Url;

        //string proxyTemplate = "Model.ashx?pid={0}&file={1}&fileid={2}";

        vwarDAL.IDataRepository vd = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();
        vwarDAL.ContentObject   co = vd.GetContentObjectById(ContentObjectID, !IsPostBack, true);
        vd.Dispose();
        vd = null;
        //model screenshot
        if (co != null)
        {
            if (LR_3DR_Bridge.LR_Integration_Enabled())
            {
                LR_3DR_Bridge.ModelViewed(co);
            }
            DownloadButton.Enabled = Permission >= ModelPermissionLevel.Fetchable;

            DownloadButton.Visible = Permission >= ModelPermissionLevel.Fetchable;
            if ("Model".Equals(co.AssetType, StringComparison.InvariantCultureIgnoreCase) || true)
            {
                //if the content object file is null, dont' try to display
                if (co.DisplayFile != string.Empty && co.Location != string.Empty && Permission > ModelPermissionLevel.Searchable)
                {
                    Page.ClientScript.RegisterClientScriptBlock(GetType(), "vload", string.Format("vLoader = new ViewerLoader('{0}', '{1}', '{2}', '{3}', {4});", Page.ResolveClientUrl("~/Public/Serve.ashx?mode=PreviewModel"),
                                                                                                  (co.UpAxis != null) ? co.UpAxis : "",
                                                                                                  (co.UnitScale != null) ? co.UnitScale : "", co.NumPolygons, "\"" + co.PID.Replace(':', '_') + "\""), true);

                    BodyTag.Attributes["onunload"] += "vLoader.DestroyViewer();";
                }
                if (String.IsNullOrWhiteSpace(co.ScreenShot) && String.IsNullOrWhiteSpace(co.ScreenShotId))
                {
                    ScreenshotImage.ImageUrl = Page.ResolveUrl("~/styles/images/nopreview_icon.png");
                }
                else
                {
                    ScreenshotImage.ImageUrl = String.Format("Serve.ashx?pid={0}&mode=GetScreenshot", co.PID);
                }
                AddHeaderTag("link", "og:image", ScreenshotImage.ImageUrl);
            }
            else if ("Texture".Equals(co.AssetType, StringComparison.InvariantCultureIgnoreCase))
            {
                ScreenshotImage.ImageUrl = String.Format("Serve.ashx?pid={0}&mode=GetScreenshot", co.PID, co.Location);
            }

            IDLabel.Text    = co.PID;
            TitleLabel.Text = co.Title;
            AddHeaderTag("meta", "og:title", co.Title);
            //show hide edit link

            if (Permission >= ModelPermissionLevel.Editable)
            {
                editLink.Visible        = true;
                PermissionsLink.Visible = true;
                DeleteLink.Visible      = true;
                //editLink.NavigateUrl = "~/Users/Edit.aspx?ContentObjectID=" + co.PID;
            }
            else
            {
                EditorButtons.Visible = false;
            }

            if (Permission >= ModelPermissionLevel.Fetchable)
            {
                //show and hide requires resubmit checkbox
                if (co.RequireResubmit)
                {
                    RequiresResubmitCheckbox.Visible = true;
                    RequiresResubmitCheckbox.Enabled = true;
                    RequiresResubmitLabel.Visible    = true;
                }
                submitRating.Visible = true;
            }
            else
            {
                string returnUrlParam = "?ReturnUrl=" + Page.ResolveUrl("~/Public/Model.aspx?ContentObjectID=" + co.PID);
                LoginLink.NavigateUrl            += returnUrlParam;
                ReveiwLoginHyperLink.NavigateUrl += returnUrlParam;
                if (User.Identity.IsAuthenticated)
                {
                    RequestAccessLabel.Visible = true;
                }
                else
                {
                    LoginToDlLabel.Visible = true;
                }
                submitRating.Visible = false;
            }

            //rating
            int rating = Website.Common.CalculateAverageRating(co.Reviews);
            ir.CurrentRating           = rating;
            this.NotRatedLabel.Visible = (rating == 0);

            //description
            DescriptionLabel.Text = String.IsNullOrEmpty(co.Description) ? "No description available." : co.Description;
            AddHeaderTag("meta", "og:description", co.Description);
            upAxis.Value    = co.UpAxis;
            unitScale.Value = co.UnitScale;
            //keywords
            var keywordsList = string.IsNullOrEmpty(co.Keywords) ? new String[0] : co.Keywords.Split(new char[] { ',' });
            foreach (var keyword in keywordsList)
            {
                HyperLink link = new HyperLink()
                {
                    Text        = keyword,
                    NavigateUrl = "~/Public/Results.aspx?ContentObjectID=" + ContentObjectID + "&Keywords=" + Server.UrlEncode(keyword.Trim()),
                    CssClass    = "Hyperlink"
                };
                keywords.Controls.Add(link);
                keywords.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
            }


            //more details
            this.MoreDetailsHyperLink.NavigateUrl = co.MoreInformationURL;
            this.MoreDetailsHyperLink.Text        = co.MoreInformationURL;


            string submitterFullName = Website.Common.GetFullUserName(co.SubmitterEmail);
            if (co.UploadedDate != null)
            {
                UploadedDateLabel.Text = "Uploaded by: " + submitterFullName + " on " + co.UploadedDate.ToString();
            }


            //sponsor logo
            if (!string.IsNullOrEmpty(co.SponsorLogoImageFileName))
            {
                this.SponsorLogoImage.ImageUrl = String.Format("Serve.ashx?pid={0}&mode=GetSponsorLogo", co.PID);
            }


            this.SponsorNameLabel.Text = co.SponsorName;



            //developr logo
            if (!string.IsNullOrEmpty(co.DeveloperLogoImageFileName))
            {
                this.DeveloperLogoImage.ImageUrl = String.Format("Serve.ashx?pid={0}&mode=GetDeveloperLogo", co.PID);
            }


            //this.DeveloperLogoRow.Visible = !string.IsNullOrEmpty(co.DeveloperLogoImageFileName);

            //developer name
            this.DeveloperNameHyperLink.NavigateUrl = "~/Public/Results.aspx?ContentObjectID=" + ContentObjectID + "&DeveloperName=" + Server.UrlEncode(co.DeveloperName);
            this.DeveloperNameHyperLink.Text        = co.DeveloperName;

            if (String.IsNullOrEmpty(co.ArtistName))
            {
            }
            else
            {
                this.ArtistNameHyperLink.NavigateUrl = "~/Public/Results.aspx?ContentObjectID=" + ContentObjectID + "&ArtistName=" + Server.UrlEncode(co.ArtistName);
                this.ArtistNameHyperLink.Text        = co.ArtistName;
            }

            //this.DeveloperRow.Visible = !string.IsNullOrEmpty(co.DeveloperName);

            this.FormatLabel.Text = ((string.IsNullOrEmpty(co.Format)) ? "Unknown" : co.Format);

            //num polygons
            this.NumPolygonsLabel.Text = co.NumPolygons.ToString();


            //num textures
            this.NumTexturesLabel.Text = co.NumTextures.ToString();


            //cclrow

            this.CCLHyperLink.NavigateUrl = co.CreativeCommonsLicenseURL;


            if (!string.IsNullOrEmpty(co.CreativeCommonsLicenseURL))
            {
                switch (co.CreativeCommonsLicenseURL.ToLower().Trim())
                {
                case "http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode":
                    this.CCLHyperLink.ImageUrl = "../styles/images/by-nc-sa.png";
                    this.CCLHyperLink.ToolTip  = "by-nc-sa";
                    break;

                case "http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode":
                    this.CCLHyperLink.ImageUrl = "../styles/images/by-nc-nd.png";
                    this.CCLHyperLink.ToolTip  = "by-nc-nd";
                    break;

                case "http://creativecommons.org/licenses/by-nc/3.0/legalcode":
                    this.CCLHyperLink.ImageUrl = "../styles/images/by-nc.png";
                    this.CCLHyperLink.ToolTip  = "by-nc";
                    break;

                case "http://creativecommons.org/licenses/by-nd/3.0/legalcode":
                    this.CCLHyperLink.ImageUrl = "../styles/images/by-nd.png";
                    this.CCLHyperLink.ToolTip  = "by-nd";
                    break;

                case "http://creativecommons.org/licenses/by-sa/3.0/legalcode":
                    this.CCLHyperLink.ImageUrl = "../styles/images/by-sa.png";
                    this.CCLHyperLink.ToolTip  = "by-sa";
                    break;

                case "http://creativecommons.org/publicdomain/mark/1.0/":
                    this.CCLHyperLink.ImageUrl = "../styles/images/publicdomain.png";
                    this.CCLHyperLink.ToolTip  = "Public Domain";
                    break;

                case "http://creativecommons.org/licenses/by/3.0/legalcode":
                    this.CCLHyperLink.ImageUrl = "../styles/images/by.png";
                    this.CCLHyperLink.ToolTip  = "by";
                    break;
                }
            }

            //downloads
            DownloadsLabel.Text       = co.Downloads.ToString();
            this.DownloadsRow.Visible = !string.IsNullOrEmpty(co.Downloads.ToString());

            //views
            ViewsLabel.Text       = co.Views.ToString();
            this.ViewsRow.Visible = !string.IsNullOrEmpty(co.Views.ToString());

            //download buton
            //this.DownloadButton.Visible = Context.User.Identity.IsAuthenticated;


            this.CommentsGridView.DataSource = co.Reviews;
            this.CommentsGridView.DataBind();

            //SupportingFileGrid.DataSource = co.SupportingFiles;
            //if(Permission < ModelPermissionLevel.Fetchable)
            //    ((ButtonField)SupportingFileGrid.Columns[2]).ImageUrl = "../styles/images/icons/expand_disabled.jpg";
            //SupportingFileGrid.DataBind();

            //SupportingFileGrid.Enabled = Permission >= ModelPermissionLevel.Fetchable;
            EditKeywords.Text = co.Keywords;
            EditDistributionDeterminationDate.Text = co.Distribution_Determination_Date.ToString();
            EditDistributionOffice.Text            = co.Distribution_Contolling_Office;
            EditDistributionReasonLabel.Text       = co.Distribution_Reason;
            EditDistributionRegulation.Text        = co.Distribution_Regulation;
            DistributionLabel.Text = Enum.GetName(typeof(DistributionGrade), co.Distribution_Grade);
            DistributionStatementText.InnerText = GetDistributionText(co);
        }
    }
Exemple #15
0
    public string UpdateThumbnailCache(string pid)
    {
        vwarDAL.IDataRepository dal = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();
        foreach (vwarDAL.ContentObject co in allpids)
        {
            if (co.PID == pid)
            {
                try
                {
                    System.IO.Stream screenshotdata = dal.GetContentFile(co.PID, co.ScreenShot);
                    if (screenshotdata != null)
                    {
                        int length = (int)screenshotdata.Length;

                        if (length != 0)
                        {
                            string ext = new FileInfo(co.ScreenShot).Extension.ToLower();
                            System.Drawing.Imaging.ImageFormat format;
                            format = System.Drawing.Imaging.ImageFormat.Png;
                            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;
                            }



                            //Use the original file bytes to remain consistent with the new file upload ID creation for thumbnails
                            co.ThumbnailId = Website.Common.GetFileSHA1AndSalt(screenshotdata) + ext;
                            dal.UpdateContentObject(co);

                            try
                            {
                                File.Delete(HttpContext.Current.Server.MapPath("~/thumbnails/" + co.ThumbnailId));
                            }
                            catch (System.IO.FileNotFoundException t)
                            {
                            }

                            using (FileStream outFile = new FileStream(HttpContext.Current.Server.MapPath("~/thumbnails/" + co.ThumbnailId), FileMode.Create))
                                Website.Common.GenerateThumbnail(screenshotdata, outFile, format);
                        }
                        else
                        {
                            dal.Dispose();
                            return("No screenshot data");
                        }
                    }
                    else
                    {
                        dal.Dispose();
                        return("No screenshot data");
                    }
                }
                catch (System.Exception ex)
                {
                    return(ex.Message);
                }
            }
        }
        dal.Dispose();
        return("OK");
    }
Exemple #16
0
        public static void WriteContentFileToResponse(string Pid, string filename, HttpContext context, vwarDAL.IDataRepository vd)
        {
            Stream data = null;//= vd.GetContentFile(Pid, co.DisplayFileId);

            if (data == null)
            {
                data = vd.GetContentFile(Pid, filename);
            }
            context.Response.ContentType = "application/octet-stream";

            byte[] buffer = new byte[data.Length];
            data.Seek(0, SeekOrigin.Begin);
            data.Read(buffer, 0, (int)data.Length);
            context.Response.BinaryWrite(buffer);
        }