private void validateXap(FileStream fileStream, EventHandler <ValidationCompleteEventArgs> onComplete, object userState) { List <string> errors = new List <string>(); List <string> warnings = new List <string>(); ObservableCollection <string> assemblyNames = null; List <System.Reflection.Assembly> extensionAssemblies = new List <System.Reflection.Assembly>(); if (fileStream != null) { StreamResourceInfo xapStreamInfo = new StreamResourceInfo(fileStream, null); IEnumerable <AssemblyPart> deploymentParts = getAssemblyParts(xapStreamInfo, out assemblyNames); foreach (AssemblyPart part in deploymentParts) { StreamResourceInfo resourceStream = Application.GetResourceStream(xapStreamInfo, new Uri(part.Source, UriKind.Relative)); if (resourceStream == null) { continue; } try { System.Reflection.Assembly assembly = part.Load(resourceStream.Stream); string assemblyName = assembly.FullName.Split(',')[0]; if (AssemblyManager.IsBuiltInAssembly(assemblyName)) { warnings.Add(string.Format(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.AssemblyAlreadyIncludeInTheApplication, assemblyName, System.Environment.NewLine)); } extensionAssemblies.Add(assembly); } catch (Exception ex) { ReflectionTypeLoadException refEx = ex as ReflectionTypeLoadException; if (refEx != null && refEx.LoaderExceptions != null) { foreach (Exception e in refEx.LoaderExceptions) { if (!string.IsNullOrWhiteSpace(e.Message) && !errors.Contains(e.Message)) { errors.Add(e.Message); } } } else if (!errors.Contains(ex.Message)) { errors.Add(ex.Message); } } } fileStream.Close(); } if (errors.Count == 0) //only if there have been no errors loading the assemblies attempt to add to the catalog { try { foreach (System.Reflection.Assembly assem in extensionAssemblies) { AssemblyManager.AddAssembly(assem); } } catch (Exception ex) { if (!errors.Contains(ex.Message)) { errors.Add(ex.Message); } } } if (errors.Count < 1 && warnings.Count < 1) { // No errors or warnings if (onComplete != null) { onComplete(this, new ValidationCompleteEventArgs() { UserState = userState, AssemblyNames = assemblyNames }); } } else { ExtensionUploadWarningDialog warningDialog = new ExtensionUploadWarningDialog(errors, warnings) { Tag = new object[] { userState, assemblyNames } }; warningDialog.OkClicked += new EventHandler(warningDialog_OkClicked); warningDialog.CancelClicked += new EventHandler(warningDialog_CancelClicked); BuilderApplication.Instance.ShowWindow(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.Errors, warningDialog, true); } }
private void validateXap(FileStream fileStream, EventHandler<ValidationCompleteEventArgs> onComplete, object userState) { List<string> errors = new List<string>(); List<string> warnings = new List<string>(); ObservableCollection<string> assemblyNames = null; List<System.Reflection.Assembly> extensionAssemblies = new List<System.Reflection.Assembly>(); if (fileStream != null) { StreamResourceInfo xapStreamInfo = new StreamResourceInfo(fileStream, null); IEnumerable<AssemblyPart> deploymentParts = getAssemblyParts(xapStreamInfo, out assemblyNames); foreach (AssemblyPart part in deploymentParts) { StreamResourceInfo resourceStream = Application.GetResourceStream(xapStreamInfo, new Uri(part.Source, UriKind.Relative)); if (resourceStream == null) continue; try { System.Reflection.Assembly assembly = part.Load(resourceStream.Stream); string assemblyName = assembly.FullName.Split(',')[0]; if (AssemblyManager.IsBuiltInAssembly(assemblyName)) { warnings.Add(string.Format(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.AssemblyAlreadyIncludeInTheApplication, assemblyName, System.Environment.NewLine)); } extensionAssemblies.Add(assembly); } catch (Exception ex) { ReflectionTypeLoadException refEx = ex as ReflectionTypeLoadException; if (refEx != null && refEx.LoaderExceptions != null) { foreach (Exception e in refEx.LoaderExceptions) if (!string.IsNullOrWhiteSpace(e.Message) && !errors.Contains(e.Message)) errors.Add(e.Message); } else if (!errors.Contains(ex.Message)) errors.Add(ex.Message); } } fileStream.Close(); } if (errors.Count == 0) //only if there have been no errors loading the assemblies attempt to add to the catalog { try { foreach (System.Reflection.Assembly assem in extensionAssemblies) AssemblyManager.AddAssembly(assem); } catch (Exception ex) { if (!errors.Contains(ex.Message)) errors.Add(ex.Message); } } if (errors.Count < 1 && warnings.Count < 1) { // No errors or warnings if (onComplete != null) onComplete(this, new ValidationCompleteEventArgs() { UserState = userState, AssemblyNames = assemblyNames }); } else { ExtensionUploadWarningDialog warningDialog = new ExtensionUploadWarningDialog(errors, warnings) { Tag = new object[] { userState, assemblyNames } }; warningDialog.OkClicked += new EventHandler(warningDialog_OkClicked); warningDialog.CancelClicked += new EventHandler(warningDialog_CancelClicked); BuilderApplication.Instance.ShowWindow(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.Errors, warningDialog, true); } }