protected void UploadOnClick(Object source, CommandEventArgs args) { if (fileStore != null && uploader.HasFile) { string fname = uploader.FileName; fileStore.AddUpdateFile("", fname, uploader.FileContent); ListDataBind(); } }
private string GetFilestoreCssPath() { ICentralizedFile file = InlineContentStore.GetFile("css", "inlinecontent.css"); if (file == null) { using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(Css))) { file = InlineContentStore.AddUpdateFile("css", "inlinecontent.css", stream); } } return(file.GetDownloadUrl()); }
private ICentralizedFile WriteFileToCfs(StringBuilder buffer, string path, string filename) { ICentralizedFileStorageProvider fs = CentralizedFileStorage.GetFileStore(Constants.FILESTOREKEY); using (MemoryStream ms = new MemoryStream()) { using (StreamWriter wr = new StreamWriter(ms)) { wr.Write(buffer); wr.Flush(); ms.Seek(0, SeekOrigin.Begin); return(fs.AddUpdateFile(path, filename, ms)); } } }
private AppData GetOrExtractAppData(ICentralizedFile sourceFile, ICentralizedFileStorageProvider targetFileStore, string targetPath) { var appDataFile = targetFileStore.GetFile(targetPath, "appdata"); if (appDataFile != null) { using (Stream appDataStream = appDataFile.OpenReadStream()) { byte[] data = new byte[appDataStream.Length]; appDataStream.Read(data, 0, data.Length); var qs = System.Web.HttpUtility.ParseQueryString(Encoding.UTF8.GetString(data)); return(new AppData { Name = qs["name"] ?? sourceFile.FileName, ApplicationId = qs["appid"] ?? string.Empty, Image = string.IsNullOrEmpty(qs["image"]) ? null : targetFileStore.GetFile(targetPath, qs["image"]), IsDirectlyInstallable = string.IsNullOrEmpty(qs["installable"]) || qs["installable"] == "true", AppType = (AppType)Enum.Parse(typeof(AppType), qs["apptype"] ?? "Unknown", true), File = sourceFile }); } } AppData appData = new AppData(); appData.File = sourceFile; appData.AppType = AppType.Unknown; appData.IsDirectlyInstallable = false; using (var inStream = sourceFile.OpenReadStream()) { using (var archive = new ZipArchive(inStream, ZipArchiveMode.Read, false)) { var imageEntry = GetImageEntry(archive, ImageSearchPaths); if (imageEntry != null) { using (var imageStream = imageEntry.Open()) { byte[] data = new byte[imageEntry.Length]; imageStream.Read(data, 0, data.Length); using (var tempStream = new MemoryStream(data)) { tempStream.Seek(0, SeekOrigin.Begin); appData.Image = targetFileStore.AddUpdateFile(targetPath, "icon.png", tempStream); } } } if (string.Compare(Path.GetExtension(sourceFile.FileName), ".apk", StringComparison.OrdinalIgnoreCase) == 0) { appData.AppType = AppType.Android; appData.IsDirectlyInstallable = true; } else if (string.Compare(Path.GetExtension(sourceFile.FileName), ".ipa", StringComparison.OrdinalIgnoreCase) == 0) { appData.AppType = AppType.iOS; appData.IsDirectlyInstallable = false; var iTunesEntry = archive.GetEntry(@"iTunesMetadata.plist"); if (iTunesEntry != null) { using (var iTunesStream = iTunesEntry.Open()) { byte[] data = new byte[iTunesEntry.Length]; iTunesStream.Read(data, 0, data.Length); using (var tempStream = new MemoryStream(data)) { tempStream.Seek(0, SeekOrigin.Begin); var iTunesData = (Dictionary <string, object>)PlistCS.Plist.readPlist(tempStream, PlistCS.plistType.Auto); object d; if (iTunesData.TryGetValue("softwareVersionBundleId", out d)) { appData.ApplicationId = d.ToString(); } if (iTunesData.TryGetValue("playlistName", out d)) { appData.Name = d.ToString(); } } } } else { // this is not packaged for iTunes, check the Payload for developer/enterprise-deployment details foreach (var entry in archive.Entries.Where(x => x.FullName.StartsWith(@"Payload/", StringComparison.OrdinalIgnoreCase) && x.FullName.EndsWith(@"/Info.plist", StringComparison.OrdinalIgnoreCase))) { var appFolder = entry.FullName.Substring(8, entry.FullName.Length - 19); if (!appFolder.Contains(@"/")) { using (var plistStream = entry.Open()) { byte[] data = new byte[entry.Length]; plistStream.Read(data, 0, data.Length); using (var tempStream = new MemoryStream(data)) { tempStream.Seek(0, SeekOrigin.Begin); var plistData = (Dictionary <string, object>)PlistCS.Plist.readPlist(tempStream, PlistCS.plistType.Auto); object d; if (plistData.TryGetValue("CFBundleIdentifier", out d)) { appData.ApplicationId = d.ToString(); } if (plistData.TryGetValue("CFBundleName", out d)) { appData.Name = d.ToString(); } } } imageEntry = GetImageEntry(archive, new string[] { string.Concat(@"Payload/", appFolder, @"/icon-320.png"), string.Concat(@"Payload/", appFolder, @"/[email protected]"), string.Concat(@"Payload/", appFolder, @"/[email protected]"), string.Concat(@"Payload/", appFolder, @"/[email protected]"), string.Concat(@"Payload/", appFolder, @"/[email protected]"), string.Concat(@"Payload/", appFolder, @"/icon.png") }); if (imageEntry != null) { using (var imageStream = imageEntry.Open()) { byte[] data = new byte[imageEntry.Length]; imageStream.Read(data, 0, data.Length); using (var tempStream = new MemoryStream(data)) { tempStream.Seek(0, SeekOrigin.Begin); using (var uncrushedStream = new MemoryStream()) { PNGDecrush.PNGDecrusher.Decrush(tempStream, uncrushedStream); uncrushedStream.Seek(0, SeekOrigin.Begin); appData.Image = targetFileStore.AddUpdateFile(targetPath, "icon.png", uncrushedStream); } } } } var provisionEntry = archive.GetEntry(string.Concat(@"Payload/", appFolder, @"/embedded.mobileprovision")); if (provisionEntry != null) { appData.IsDirectlyInstallable = true; } } } } } } } if (string.IsNullOrEmpty(appData.Name)) { appData.Name = sourceFile.FileName.Substring(0, sourceFile.FileName.LastIndexOf('.')); } if (appData.ApplicationId == null) { appData.ApplicationId = ""; } StringBuilder qstr = new StringBuilder(); qstr.Append("name="); qstr.Append(Uri.EscapeDataString(appData.Name)); qstr.Append("&appid="); qstr.Append(Uri.EscapeDataString(appData.ApplicationId)); qstr.Append("&image="); qstr.Append(appData.Image == null ? "" : Uri.EscapeDataString(appData.Image.FileName)); qstr.Append("&installable="); qstr.Append(appData.IsDirectlyInstallable ? "true" : "false"); qstr.Append("&apptype="); qstr.Append(Uri.EscapeDataString(appData.AppType.ToString())); using (var appDataStream = new MemoryStream(Encoding.UTF8.GetBytes(qstr.ToString()))) { appDataStream.Seek(0, SeekOrigin.Begin); targetFileStore.AddUpdateFile(targetPath, "appdata", appDataStream); } return(appData); }