/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomVersionDetailSerializer">A delegate to serialize custom version detail JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <VersionDetail> CustomVersionDetailSerializer = null) { var JSON = JSONObject.Create( new JProperty("version", VersionId.ToString()), new JProperty("endpoints", new JArray(Endpoints.SafeSelect(endpoint => endpoint.ToJSON()))) ); return(CustomVersionDetailSerializer != null ? CustomVersionDetailSerializer(this, JSON) : JSON); }
/// <summary> /// Binds the storage. /// </summary> private void BindStorage() { //show current path if (VersionId != -2) { lbPath.Text = CurrentFolder.Substring(1).Replace(ArchivePath.Substring(1) + VersionId.ToString() + "/", "/Repository/Private/"); } else { lbPath.Text = CurrentFolder.Substring(1).Replace(ArchivePath.Substring(1) + Membership.GetUser().UserName + "/", "/Repository/Private/"); } DataTable dt = CreateDataTable(); DirectoryInfo dir = SelectDirectory(); DataRow dr; #region Create back/private folder icon //add folder icon StringBuilder url = new StringBuilder(); url.Append("Browser.aspx"); url.Append("?PageVersionId=" + VersionId.ToString()); url.Append("&RepositoryPath=" + RepositoryPath); url.Append("&ArchivePath=" + ArchivePath); url.Append("&TempPath=" + TempPath); url.Append("&Mode=" + Request.QueryString["Mode"]); dr = dt.NewRow(); dr["Weight"] = 0; dr["Icon"] = string.Empty; dr["sortName"] = string.Empty; dr["ActionEdit"] = string.Empty; dr["ActionVS"] = string.Empty; dr["sortSize"] = 0; dr["ModifiedDate"] = string.Empty; dr["sortModified"] = DateTime.Now; dr["Modifier"] = string.Empty; dr["sortModifier"] = string.Empty; dr["CanDelete"] = false; dr["Size"] = string.Empty; //add back icon if (CurrentFolder != RepositoryPath) { //get parent directory url DirectoryInfo currentDir = new DirectoryInfo(MapPath(CurrentFolder)); string parentPath = currentDir.Parent.FullName.Replace(MapPath(Request.ApplicationPath), "").Replace("\\", "/"); if (!parentPath.EndsWith("/")) { parentPath += "/"; } if (!parentPath.StartsWith("/")) { parentPath = "/" + parentPath; } if (!parentPath.StartsWith("~")) { parentPath = "~" + parentPath; } //if parent folder is resource folder // then set current folder to RepositoryPath if (parentPath == TempPath || parentPath == ArchivePath) { url.Append("&CurrentFolder=" + RepositoryPath); } else { url.Append("&CurrentFolder=" + parentPath); } dr["Name"] = "<a id='divId__a' href='" + url.ToString() + "'>[..]</a>";; dr["BigIcon"] = "<a href='" + url.ToString() + "'><img src='" + Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/back.gif") + "' align='absmiddle' border='0' /></a>"; } //add icon for user or version resource else { if (VersionId == -2) { url.Append("&CurrentFolder=" + ArchivePath + Membership.GetUser().UserName + "/"); } else { url.Append("&CurrentFolder=" + ArchivePath + VersionId.ToString() + "/"); } dr["Name"] = "<a id='divId__a' href='" + url.ToString() + "'><b>Private</b></a>";; dr["BigIcon"] = "<a href='" + url.ToString() + "'><img src='" + Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/private.gif") + "' align='absmiddle' border='0' /></a>"; } dt.Rows.Add(dr); #endregion #region Get Folders DirectoryInfo[] dirs = dir.GetDirectories(); foreach (DirectoryInfo d in dirs) { url = new StringBuilder(); url.Append("Browser.aspx"); url.Append("?PageVersionId=" + VersionId.ToString()); url.Append("&RepositoryPath=" + RepositoryPath); url.Append("&ArchivePath=" + ArchivePath); url.Append("&TempPath=" + TempPath); url.Append("&Mode=" + Request.QueryString["Mode"]); url.Append("&CurrentFolder=" + CurrentFolder + d.Name + "/"); url.Append("&ParentFolder=" + CurrentFolder); dr = dt.NewRow(); dr["Id"] = d.FullName.Replace("\\", "").Replace(".", "").Replace(" ", "").Replace(":", ""); dr["FullPath"] = d.FullName; dr["Weight"] = 1; dr["Icon"] = string.Empty; dr["BigIcon"] = String.Format("<a id={2} href=\"{0}\"><img src='{1}' align='absmiddle' border='0' /></a>", url.ToString(), Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/folder1.gif"), "divId_" + (string)dr["Id"] + "_a"); dr["Name"] = String.Format("<a href=\"{0}\">{1}</a>", url.ToString(), d.Name); dr["sortName"] = string.Empty; dr["ActionVS"] = string.Empty; dr["ActionEdit"] = string.Empty; dr["sortSize"] = 0; dr["ModifiedDate"] = d.LastWriteTime.ToShortDateString(); dr["sortModified"] = d.LastWriteTime; dr["Modifier"] = string.Empty; dr["sortModifier"] = string.Empty; dr["CanDelete"] = true; dr["Size"] = string.Empty; dt.Rows.Add(dr); } #endregion #region Get Files //fill datatable FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { if (!IsImage(file.Extension) && Mode == ViewMode.ImageOnly) { continue; } if (!IsFlash(file.Extension) && Mode == ViewMode.FlashOnly) { continue; } string fileUrl = string.Empty; string resUrl = string.Empty; string appPath = MapPath(Request.ApplicationPath); fileUrl = Request.ApplicationPath + file.FullName.Replace(appPath, "").Replace("\\", "/"); if (!CurrentFolder.StartsWith(RepositoryPath)) { string patt = CurrentFolder.Substring(1); if (VersionId != -2) { resUrl = fileUrl.Replace(ArchivePath.Substring(1) + VersionId.ToString() + "/", "/Repository/Private/"); } else { resUrl = fileUrl.Replace(ArchivePath.Substring(1) + Membership.GetUser().UserName + "/", "/Repository/Private/"); } } else { resUrl = fileUrl; } dr = dt.NewRow(); dr["Id"] = file.FullName.Replace("\\", "").Replace(".", "").Replace(" ", "").Replace(":", ""); dr["FullPath"] = file.FullName; dr["Weight"] = 2; dr["Icon"] = string.Empty; //add preview or type icon if (IsImage(file.Extension)) { //add preview dr["BigIcon"] = String.Format("<a href=\"{0}\"><img src='{1}' align='absmiddle' border='0' " + ImageResize(fileUrl, 90, 90) + "/></a>", "javascript:window.opener.SetUrl('" + resUrl.ToLower() + "');window.close();", fileUrl); } else { //add type icon if (File.Exists(MapPath("~/images/filetype/") + file.Extension.Replace(".", "") + ".gif")) { dr["BigIcon"] = String.Format("<a href=\"{0}\" style='height:48px;width:48px;overflow:hidden;'><img src='{1}' align='absmiddle' border='0'/></a>", "javascript:window.opener.SetUrl('" + resUrl.ToLower() + "');window.close();", Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/filetype/" + file.Extension.Replace(".", "") + ".gif")); } else { dr["BigIcon"] = String.Format("<a href=\"{0}\" style='height:48px;width:48px;overflow:hidden;'><img src='{1}' align='absmiddle' border='0'/></a>", "javascript:window.opener.SetUrl('" + resUrl.ToLower() + "');window.close();", Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath("/images/filetype/unknown.gif")); } } dr["Name"] = String.Format("<a id={2} href=\"{0}\">{1}</a>", "javascript:window.opener.SetUrl('" + resUrl.ToLower() + "');window.close();", file.Name, "divId_" + (string)dr["Id"] + "_aa"); dr["sortName"] = string.Empty; dr["ActionVS"] = string.Empty; dr["ActionEdit"] = string.Empty; dr["sortSize"] = 0; dr["ModifiedDate"] = file.LastWriteTime.ToShortDateString(); dr["sortModified"] = file.LastWriteTime; dr["Modifier"] = string.Empty; dr["sortModifier"] = string.Empty; dr["CanDelete"] = true; dr["Size"] = FormatBytes((long)file.Length); dt.Rows.Add(dr); } #endregion DataView dv = dt.DefaultView; repThumbs.DataSource = dv; repThumbs.DataBind(); }