private void CheckEmptyFieldPackageInfo(PackageInfo packageInfo, string fieldName) { string fieldValue = (string)packageInfo.GetType().GetProperty(fieldName).GetValue(packageInfo); if (string.IsNullOrWhiteSpace(fieldValue)) { throw new InvalidOperationException( $"Field: '{fieldName}' mast be is not empty in package descriptor: '{packageInfo.PackageDescriptorPath}'"); } }
public string Save(string workingDirectory, PackageInfo package) { Console.WriteLine(""); Console.WriteLine("Saving package..."); Console.WriteLine(""); var filePath = FileNamer.CreateInfoFilePath(workingDirectory, package.Name, package.GroupName); Console.WriteLine("File path:"); Console.WriteLine(filePath); if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } using (StreamWriter writer = File.CreateText(filePath)) { var serializer = new XmlSerializer(package.GetType()); serializer.Serialize(writer, package); } return(filePath); }
public ActionResult Save(PackageSettingsDto packageSettings) { ActionResult actionResult = new ActionResult(); try { PackageInfo package = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == packageSettings.PackageId); if (package == null) { actionResult.AddError("SavePackageSettings.PackageNotFound", Localization.GetString("SavePackageSettings.PackageNotFound", Components.Constants.ExtensionSharedResources)); return(actionResult); } if (UserInfo.IsSuperUser) { AuthenticationInfo authService = AuthenticationController.GetAuthenticationServiceByPackageID(package.PackageID); bool isReadOnly = authService != null && authService.AuthenticationType == Components.Constants.DnnAuthTypeName; if (isReadOnly) { actionResult.AddError("ReadOnlyPackage.SaveErrorMessage", Localization.GetString("ReadOnlyPackage.SaveErrorMessage", Components.Constants.ExtensionSharedResources)); return(actionResult); } Type type = package.GetType(); bool needUpdate = false; foreach (KeyValuePair <string, string> kvp in packageSettings.Settings) { PropertyInfo property = type.GetProperty(kvp.Key, BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public); if (property != null && property.CanWrite) { string value = kvp.Value; object propValue = property.GetValue(package); if (propValue == null || propValue.ToString() != value) { object nativeValue = property.PropertyType == typeof(Version) ? new Version(value) : Convert.ChangeType(value, property.PropertyType); property.SetValue(package, nativeValue); needUpdate = true; } } } if (needUpdate) { PackageController.Instance.SaveExtensionPackage(package); } } Dnn.PersonaBar.Extensions.Components.Editors.IPackageEditor packageEditor = PackageEditorFactory.GetPackageEditor(package.PackageType); if (packageEditor != null) { packageEditor.SavePackageSettings(packageSettings, out string error); if (!string.IsNullOrEmpty(error)) { actionResult.AddError("error", error); return(actionResult); } } PackageInfoDto packageDetail = packageEditor?.GetPackageDetail(packageSettings.PortalId, package) ?? new PackageInfoDto(packageSettings.PortalId, package); actionResult.Data = packageDetail; actionResult.IsSuccess = true; return(actionResult); } catch (Exception ex) { actionResult.AddError("", "", ex); return(actionResult); } }