/// <summary> /// Click event. /// </summary> /// <param name="sender">The Sender.</param> /// <param name="e">The EventArgs.</param> protected void ButtonOk_Click(object sender, EventArgs e) { // Validate this.Validate(); if (!this.IsValid) { return; } // We are valid // Register the database using (SPLongOperation operation = new SPLongOperation(this)) { operation.LeadingHTML = HttpContext.GetGlobalResourceObject("ClubCloud.Service.ServiceAdminResources", "UsersSettingsCreateOperationLeadingHtml", CultureInfo.CurrentCulture).ToString(); operation.TrailingHTML = HttpContext.GetGlobalResourceObject("ClubCloud.Service.ServiceAdminResources", "UsersSettingsCreateOperationTrailingHtml", CultureInfo.CurrentCulture).ToString(); operation.Begin(); var name = fup_package.PostedFile.FileName.Split('\\').Last(); string[] parts = name.Split('_'); string applicationName = parts[0]; string verion = parts[1]; string cpu = parts[2]; ClubCloud.Model.ApplicationInfo applicationInfo = ServiceClient.GetApplicationInfoByName(applicationName); if (applicationInfo == null) { applicationInfo = new Model.ApplicationInfo { ApplicationName = applicationName, MajorVersion = verion, CreationDate = DateTime.Now, OperationDate = DateTime.Now, Status = ApplicationStatus.Published }; } else { applicationInfo.MajorVersion = verion; applicationInfo.OperationDate = DateTime.Now; } Stream uploadstream = fup_package.PostedFile.InputStream; fup_package.PostedFile.InputStream.Seek(0, SeekOrigin.Begin); byte[] fileData = new byte[fup_package.PostedFile.ContentLength]; uploadstream.Read(fileData, 0, fup_package.PostedFile.ContentLength); byte[] package = null; byte[] certificate = null; byte[] symbols = null; ApplicationVersion applicationVersion = new ApplicationVersion(); ApplicationProcessorArchitecture applicationProcessorArchitecture = new ApplicationProcessorArchitecture(); using (ZipArchive archive = new ZipArchive(uploadstream, ZipArchiveMode.Read)) { foreach (ZipArchiveEntry entry in archive.Entries) { byte[] buffer = null; using (BinaryReader reader = new BinaryReader(entry.Open())) { buffer = reader.ReadBytes((int)entry.Length); } if (entry.FullName.EndsWith("appx")) { package = buffer; PackageAnalyzeResult result = PackageAnalyzer.GetPackageInfo(entry.Open()); applicationVersion = result.ApplicationVersion; applicationProcessorArchitecture = result.ApplicationProcessorArchitecture; } if (entry.FullName.EndsWith("cer")) { certificate = buffer; } if (entry.FullName.EndsWith("appxsym")) { symbols = buffer; } } } applicationProcessorArchitecture.Certificate = certificate; applicationProcessorArchitecture.Package = package; applicationProcessorArchitecture.Symbols = symbols; //applicationVersion.ApplicationProcessorArchitectures.Add(applicationProcessorArchitecture); //applicationInfo.ApplicationVersions.Add(applicationVersion); applicationInfo = ServiceClient.SetApplicationInfo(applicationInfo); applicationVersion.ApplicationInfoId = applicationInfo.Id; applicationVersion = ServiceClient.SetApplicationVersion(applicationInfo.Id, applicationVersion); applicationProcessorArchitecture.ApplicationVersionId = applicationVersion.Id; applicationProcessorArchitecture = ServiceClient.SetApplicationProcessorArchitecture(applicationVersion.Id, applicationProcessorArchitecture); operation.End("/_admin/ClubCloud.Service/ManagePackage.aspx");//string.Format(CultureInfo.InvariantCulture, "/_admin/ClubCloud.Service/ManageApplication.aspx?id={0}", SPHttpUtility.UrlKeyValueEncode(this.ServiceApplication.Id))); } }
public static PackageAnalyzeResult GetPackageInfo(Stream packageStream) { PackageAnalyzeResult result = new PackageAnalyzeResult(); result.ApplicationVersion = new ApplicationVersion(); result.ApplicationProcessorArchitecture = new ApplicationProcessorArchitecture(); using (ZipArchive archive = new ZipArchive(packageStream, ZipArchiveMode.Read)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName == "AppxManifest.xml") { var stream = entry.Open(); XElement root = XElement.Load(stream); var ns = "http://schemas.microsoft.com/appx/2010/manifest"; // for windows store 8.0 and 8.1 var ns80 = "http://schemas.microsoft.com/developer/appx/2012/build"; var ns81 = "http://schemas.microsoft.com/appx/2013/manifest"; bool is80package = root.Attributes().Where(a => a.Value == ns80).Count() > 0; bool is81package = root.Attributes().Where(a => a.Value == ns81).Count() > 0; //app manifest error, can't find manifest schema if (root.Attributes().Where(a => a.Value == ns).Count() <= 0) { return(null); } System.Xml.XmlNamespaceManager nsmgr = new System.Xml.XmlNamespaceManager(new System.Xml.NameTable()); nsmgr.AddNamespace("ns", ns); XElement identity = root.XPathSelectElement(@"//ns:Identity", nsmgr); string name = identity.Attribute("Name").Value; string version = identity.Attribute("Version").Value; string publisher = identity.Attribute("Publisher").Value; string displayName = root.XPathSelectElement(@"//ns:DisplayName", nsmgr).Value; string publisherDisplayName = root.XPathSelectElement(@"//ns:PublisherDisplayName", nsmgr).Value; string description = root.XPathSelectElement(@"//ns:Description", nsmgr).Value; var protocolElement = root.XPathSelectElement(@"//ns:Extension[@Category='windows.protocol']/ns:Protocol", nsmgr); string protocol = protocolElement == null ? null : (protocolElement == null ? null : protocolElement.Attribute("Name").Value); result.ApplicationVersion = new ApplicationVersion() { IdentityName = name, Version = version, Publisher = publisher, DisplayName = displayName, Description = description, PublisherDisplayName = publisherDisplayName, ProtocolUrl = protocol, OperationDate = DateTime.Now }; string _processorArchitecture = identity.Attribute("ProcessorArchitecture").Value; ClubCloud.Model.ProcessorArchitecture architecture = ClubCloud.Model.ProcessorArchitecture.Unknown; switch (_processorArchitecture) { case "arm": architecture = ClubCloud.Model.ProcessorArchitecture.ARM; break; case "x86": architecture = ClubCloud.Model.ProcessorArchitecture.x86; break; case "x64": architecture = ClubCloud.Model.ProcessorArchitecture.x64; break; case "neutral": architecture = ClubCloud.Model.ProcessorArchitecture.Neutual; break; } result.ApplicationProcessorArchitecture = new ApplicationProcessorArchitecture() { ProcessorArchitecture = architecture, UploadDate = DateTime.Now, Version = version }; /* * applicationVersion.ApplicationProcessorArchitectures.Add(new ApplicationProcessorArchitecture() * { * ProcessorArchitecture = architecture * }); */ /* * string logoUrl_Store = string.Empty; * string logoUrl_150x150 = string.Empty; * string logoUrl_30x30 = string.Empty; * string logoUrl_310x150 = string.Empty; * string logoUrl_310x310 = string.Empty; * string logoUrl_70x70 = string.Empty; * * if (is81package) * { * nsmgr.AddNamespace("ns2", ns81); * logoUrl_Store = root.XPathSelectElement(@"//ns:Logo", nsmgr).Value; * * XElement visualElements = root.XPathSelectElement(@"//ns2:VisualElements", nsmgr); * if (visualElements != null) * { * logoUrl_150x150 = visualElements.Attribute("Square150x150Logo") == null ? * string.Empty : visualElements.Attribute("Square150x150Logo").Value; * logoUrl_30x30 = visualElements.Attribute("Square30x30Logo") == null ? * string.Empty : visualElements.Attribute("Square30x30Logo").Value; * } * * XElement defaultTile = root.XPathSelectElement(@"//ns2:DefaultTile", nsmgr); * if (defaultTile != null) * { * logoUrl_310x150 = defaultTile.Attribute("Wide310x150Logo") == null ? * string.Empty : defaultTile.Attribute("Wide310x150Logo").Value; * logoUrl_310x310 = defaultTile.Attribute("Square310x310Logo") == null ? * string.Empty : defaultTile.Attribute("Square310x310Logo").Value; * logoUrl_70x70 = defaultTile.Attribute("Square70x70Logo") == null ? * string.Empty : defaultTile.Attribute("Square70x70Logo").Value; * } * * * } * else if (is80package) * { * logoUrl_Store = root.XPathSelectElement(@"//ns:Logo", nsmgr).Value; * * XElement visualElements = root.XPathSelectElement(@"//ns:VisualElements", nsmgr); * if (visualElements != null) * { * logoUrl_150x150 = visualElements.Attribute("Logo") == null ? * string.Empty : visualElements.Attribute("Logo").Value; * logoUrl_30x30 = visualElements.Attribute("SmallLogo") == null ? * string.Empty : visualElements.Attribute("SmallLogo").Value; * } * * XElement defaultTile = root.XPathSelectElement(@"//ns:DefaultTile", nsmgr); * if (defaultTile != null) * { * logoUrl_310x150 = defaultTile.Attribute("WideLogo") == null ? * string.Empty : defaultTile.Attribute("WideLogo").Value; * } * } * * applicationVersion.LogoUrl_Store = logoUrl_Store; * applicationVersion.LogoUrl_30x30 = logoUrl_30x30; * applicationVersion.LogoUrl_150x150 = logoUrl_150x150; * applicationVersion.LogoUrl_310x150 = logoUrl_310x150; * applicationVersion.LogoUrl_310x310 = logoUrl_310x310; * applicationVersion.LogoUrl_70x70 = logoUrl_70x70; */ } } /* * PropertyInfo[] properties = applicationVersion.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); * * foreach (PropertyInfo pi in properties) * { * if (pi.Name.StartsWith("LogoUrl_")) * { * var path = pi.GetValue(applicationVersion).ToString().Replace(@"\", @"/"); * var logoEntry = archive.GetEntry(path); * * if (logoEntry == null) * { * pi.SetValue(applicationVersion, string.Empty); * } * else * { * var logoStream = new MemoryStream(); * var zipedStream = logoEntry.Open(); * zipedStream.CopyTo(logoStream); * * PropertyInfo p = typeof(PackageAnalyzeResult).GetProperty(pi.Name + "_Stream"); * p.SetValue(result, logoStream); * } * } * } */ } //result.ApplicationVersion = applicationVersion; //result.ApplicationProcessorArchitecture = applicationProcessorArchitecture; return(result); }