/// <summary> /// Flash an error from the message in <paramref name="result"/> if result is not successful. /// </summary> /// <param name="result">The boolean message result</param> public void FlashIfError(BoolMessage result) { if (result != null && !result.Success) { FlashErrors(result.Message); } }
/// <summary> /// Validate all the params and collect all the errors. /// </summary> /// <returns></returns> protected override bool ValidateInternal(ValidationEvent validationEvent) { object target = validationEvent.Target; IValidationResults results = validationEvent.Results; string message = string.Empty; bool success = true; foreach (NamedQueryParam param in _namedQueryParams) { BoolMessage result = ValidateParam(param); if (!result.Success) { success = false; message += Environment.NewLine + result.Message; } } // Don't create instance, return reaon-only singleton. if (success) { return(BoolMessage.True.Success); } return(new BoolMessage(false, message).Success); }
/// <summary> /// Get the authentication data using using the username provided and perform the /// authenctication. /// </summary> /// <param name="ctx">The action context.</param> /// <param name="resources">Resource manager for errors message. /// Can provide the default Resource Manager. /// <see cref="CommonLibrary.LocalizationResourceManagerDefault"/></param> /// <returns></returns> public static BoolMessageItem <IPrincipal> CheckAuthorizationUsingName(IActionContext ctx, ILocalizedResourceManager resources) { // Get the authentication service. ISecurityService securityService = IocContainer.GetObject <ISecurityService>("authenticationService"); if (securityService == null) { return(new BoolMessageItem <IPrincipal>(null, false, resources.GetString("Authentication_NotWorking", "Authorization service is unavailable."))); } // Get the authentication data by username. IPrincipal authData = securityService.GetAuthData(ctx.UserName).Item; string authMessage = authData == null?resources.GetString("Authentication_Failed", "Unable to authenticate user : " + ctx.UserName) : string.Empty; // Authentication failure. if (authData == null) { return(new BoolMessageItem <IPrincipal>(null, false, authMessage)); } // Set the auth data on the context. BoolMessage result = CheckAuthorization(ctx, resources); return(new BoolMessageItem <IPrincipal>(authData, result.Success, result.Message)); }
/// <summary> /// Verify that this is a valid user. /// </summary> /// <param name="userName">"kishore"</param> /// <param name="password">"password"</param> /// <returns></returns> public BoolMessageItem <Account> VerifyUser(string userName, string password) { // Check inputs. BoolMessage inputCheck = Validation.AreNoneNull(new string[] { userName, password }, new string[] { "UserName", "Password" }, null, null); if (!inputCheck.Success) { return(new BoolMessageItem <Account>(null, false, inputCheck.Message)); } IList <Account> accounts = GetByFilter("UserNameLowered = '" + userName.ToLower() + "'").Item; // Check for matching records. if (accounts == null || accounts.Count == 0) { return(new BoolMessageItem <Account>(null, false, "No accounts were found with username: "******"Password supplied does not match"; return(new BoolMessageItem <Account>(accounts[0], isPasswordMatch, message)); }
public ActionResult LogOn(LogOnModel model, bool rememberMe, string returnUrl) { if (ModelState.IsValid) { // This validates the user credentials and returns // a success flag and a string representing the roles of the user. string roles = string.Empty; BoolMessage result = MembershipService.ValidateUser(model.UserName, model.Password, ref roles); if (result.Success) { FormsService.SignIn(model.UserName, roles, rememberMe); if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { if (!Captcha.IsCorrect()) { ModelState.AddModelError("CaptchaUserInput", "Incorrect Verification Code."); return(View(model)); } // Attempt to register the user MembershipCreateStatus createStatus = MembershipCreateStatus.ProviderError; BoolMessage result = MembershipService.CreateUser(model.UserName, model.Password, model.Email, "User", ref createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsService.SignIn(model.UserName, "User", false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } else { string error = createStatus == MembershipCreateStatus.UserRejected ? result.Message : ErrorCodeToString(createStatus); ModelState.AddModelError("", error); } } // If we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Register the user. /// </summary> /// <param name="userName">"kishore"</param> /// <param name="email">"*****@*****.**"</param> /// <param name="password">password</param> /// <param name="confirmPassword">Must be same as password, to confirm password</param> /// <returns></returns> public BoolResult <Account> Create(string userName, string email, string password, string confirmPassword) { // Check inputs. BoolMessage inputCheck = Validation.AreNoneNull( new string[] { userName, email, password, confirmPassword }, new string[] { "UserName", "Email", "Password", "ConfirmPassword" }, null, null); if (!inputCheck.Success) { return(new BoolResult <Account>(null, false, inputCheck.Message, null, null)); } // Check password. BoolMessage passwordCheck = ValidatePasswords(password, confirmPassword); if (!passwordCheck.Success) { return(new BoolResult <Account>(null, false, passwordCheck.Message, null, null)); } Account account = Accounts.New(); account.UserName = userName; account.Email = email; account.Password = password; // Create the user. BoolResult <Account> result = Accounts.Create(account); return(result); }
public static BoolMessage GetBoolMessage(bool value) { if (_boolMessage == null) { _boolMessage = new BoolMessage(); } _boolMessage.value = value; return(_boolMessage); }
public void CanUseSchemaWithCaseSensitivity() { Args args = BuildSampleArgs("-", ":"); string[] commandLineArgs = new string[] { "-Config:prod.xml", "-Dateoffset:2", "-Busdate:${today}", "-DryRun:true", "18" }; BoolMessage result = args.DoParse(commandLineArgs); Assert.IsFalse(result.Success); }
/// <summary> /// Create the user and also return the membership status /// </summary> /// <param name="userName">kishore</param> /// <param name="email">[email protected]</param> /// <param name="password">password</param> /// <param name="roles"></param> /// <param name="status">DuplicateUserName</param> /// <returns>Result of user creation.</returns> public virtual BoolMessageItem <User> Create(string userName, string email, string password, string roles, ref MembershipCreateStatus status) { User user = User.New(); user.UserName = userName; user.IsApproved = true; user.Email = email; user.Roles = roles; BoolMessage result = Create(user, password, ref status); return(new BoolMessageItem <User>(user, result.Success, string.Empty)); }
private BoolMessageItem <IList <T> > InternalImport(ImportExportActionContext <T> ctx) { IEntityService <T> service = EntityRegistration.GetService <T>(); IActionContext actionContext = EntityRegistration.GetContext(typeof(T).FullName); actionContext.Errors = ctx.Errors; actionContext.Messages = ctx.Messages; actionContext.CombineMessageErrors = false; actionContext.Items = ctx.ItemList; actionContext.Args["isImporting"] = true; BoolMessage createResult = service.Create(actionContext); return(new BoolMessageItem <IList <T> >(ctx.ItemList, createResult.Success, createResult.Message)); }
public ActionResult ForgotPassword(FormCollection form) { string email = form["emailaddress"]; string user = form["username"]; BoolMessage result = MembershipService.SendPassword(user, email, true); if (!result.Success) { ModelState.AddModelError("emailaddress", result.Message); return(View("ForgotPassword")); } this.ViewData["Message"] = "Your username/password have been mailed to : " + email; return(View("ForgotPassword")); }
public void CanUseSchemaWithoutFluentAPI() { Args args = BuildSampleArgs("-", ":"); string[] commandLineArgs = new string[] { "-config:prod.xml", "-dateoffset:2", "-busdate:${today}", "-dryrun:true", "18" }; BoolMessage result = args.DoParse(commandLineArgs); Assert.IsTrue(result.Success); Assert.AreEqual(args.Prefix, "-"); Assert.AreEqual(args.Separator, ":"); Assert.AreEqual(args.Named["config"], "prod.xml"); Assert.AreEqual(args.Named["dateoffset"], "2"); Assert.AreEqual(args.Named["dryrun"], "true"); Assert.AreEqual(args.Get <DateTime>("busdate"), DateTime.Today); }
/// <summary> /// Flashes an error or a messages depending on success/fail flag in result. /// </summary> /// <param name="result"></param> public void Flash(BoolMessage result) { if (result == null) { return; } if (result.Success) { FlashMessages(result.Message); } else { FlashErrors(result.Message); } }
public void CanUseSchemaWithCaseSensitivity() { Args args = new Args("-", ":"); args.Schema.AddNamed <string>("config", "config", true, "dev.config", "config file for environment", "dev.xml", "dev.xml | qa.config", false, true, "common", false) .AddNamed <int>("dateoffset", "", true, 0, "business date offset from today", "0", "0 | 1 | -1", false, true, "common", false) .AddNamed <DateTime>("busdate", "", true, DateTime.Today, "business date offset from today", "0", "0 | 1 | -1", true, true, "common", false) .AddNamed <bool>("dryrun", "", true, false, "testing mode", "true", "true | false", false, true, "common", false) .AddPositional <int>(0, true, 5, "Number of categories to display", "5", " 5 | 8 etc.", false, true, "common", false); string[] commandLineArgs = new string[] { "-Config:prod.xml", "-Dateoffset:2", "-Busdate:${today}", "-DryRun:true", "18" }; BoolMessage result = args.DoParse(commandLineArgs); Assert.IsFalse(result.Success); }
public void CanDoParse() { Args args = new Args("-", ":"); string[] argList = new string[] { "-email", "-recurse", "-config:my prod.xml", "100" }; BoolMessage result = args.DoParse(argList); Assert.AreEqual(args.Prefix, "-"); Assert.AreEqual(args.Separator, ":"); Assert.AreEqual(args.Named["config"], "my prod.xml"); Assert.AreEqual(args.Named["email"], "true"); Assert.AreEqual(args.Named["recurse"], "true"); Assert.AreEqual(args.Positional[0], "100"); Assert.IsNotNull(args.Raw); }
public ActionResult RemoveConfirmed(string username) { DashboardLayout(Auth.IsAuthenticated()); BoolMessage result = MembershipService.DeleteUser(username); if (result.Success) { if (!Auth.IsAdmin()) { FormsService.SignOut(); DashboardLayout(false); } return(View("Pages/GeneralMessage", new KeyValuePair <string, string>("Account Removed", "Account : " + username + " has been successfully removed."))); } return(View("Pages/GeneralMessage", new KeyValuePair <string, string>("Account Removed", result.Message))); }
/// <summary> /// Change the current password. /// </summary> /// <param name="userName">username of the account for which the password is being changed.</param> /// <param name="oldPassword">The old password.</param> /// <param name="newPassword">New password</param> /// <returns>Result of password change operation.</returns> public virtual BoolMessage ChangePassword(string userName, string oldPassword, string newPassword) { // Check inputs. BoolMessage inputCheck = Validation.AreNoneNull( new string[] { userName, oldPassword, newPassword }, new string[] { "UserName", "Current Password", "New Password" }, null, null); if (!inputCheck.Success) { return(new BoolMessage(false, inputCheck.Message)); } UserSettings settings = (UserSettings)Settings; // Check password if (!string.IsNullOrEmpty(settings.PasswordRegEx) && !Regex.IsMatch(newPassword, settings.PasswordRegEx)) { return(new BoolMessage(false, "New password is invalid")); } // Check passwords match //if (string.Compare(newPassword, confirmPassword, false) != 0) // return new BoolMessage(false, "Password and confirm password do not match."); // Check user account User user = Get(userName); if (user == null) { return(new BoolMessage(false, "Unable to find account with matching username : "******"Old password supplied does not match whats on file.")); } // Now change password. user.LastPasswordChangedDate = DateTime.Today; user.PasswordPlain = newPassword; Update(user); return(BoolMessage.True); }
/// <summary> /// Update the specific entity with property values specified. /// </summary> /// <param name="entityName">"Category"</param> /// <param name="propValues">List of key value pairs. /// Where the key is the property name, and the value is a string /// representation of the property value.</param> public BoolMessage Create(ScaffoldContext ctx) { BoolMessageItem creationResult = CreateContext(ctx, false, true, true); if (!creationResult.Success) { return(creationResult); } EntityServiceContext entityActionContext = creationResult.Item as EntityServiceContext; // Create the entity using the entity service. EntityManager service = new EntityManager(); BoolMessage result = service.Create(entityActionContext); return(result); }
/// <summary> /// Try logging in to server. /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public BoolMessage LogOn(string userName, string password, bool rememberUser) { // Check inputs. BoolMessage inputCheck = Validation.AreNoneNull(new string[] { userName, password }, new string[] { "UserName", "Password" }, null, null); if (!inputCheck.Success) { return(inputCheck); } BoolMessageItem <Account> result = VerifyUser(userName, password); if (result.Success) { Auth.SignIn(result.Item.UserName, rememberUser); } return(result); }
/// <summary> /// Run the application. /// </summary> public override BoolMessageItem Execute() { ModelContainer models = GetModelContainer(); ModelContext ctx = new ModelContext() { AllModels = models }; IList <ICodeBuilder> builders = new List <ICodeBuilder>() { // This generates the Database tables in SQL - Server. // You connection string in ModelBuilderSettings.Connection must be set. new CodeBuilderDb(ctx.AllModels.Settings.Connection), new CodeBuilderDomain(), }; BoolMessage message = CodeBuilder.Process(ctx, builders); Console.WriteLine("Code generation Sucess : {0} - {1}", message.Success, message.Message); return(BoolMessageItem.True); }
/// <summary> /// Change the current password. /// </summary> /// <param name="userName">username of the account for which the password is being changed.</param> /// <param name="currentPassword">Existing password on file.</param> /// <param name="newPassword">New password</param> /// <param name="confirmPassword">Confirm the password. must be same as new password.</param> /// <returns></returns> public BoolResult <Account> ChangePassword(string userName, string currentPassword, string newPassword, string confirmPassword) { // Check inputs. BoolMessage inputCheck = Validation.AreNoneNull( new string[] { userName, currentPassword, newPassword, confirmPassword }, new string[] { "UserName", "Current Password", "New Password", "Confirm Password" }, null, null); if (!inputCheck.Success) { return(new BoolResult <Account>(null, false, inputCheck.Message, null, null)); } // Check that new password and password confirmation are same. BoolMessage passwordCheck = ValidatePasswords(newPassword, confirmPassword); if (!passwordCheck.Success) { return(new BoolResult <Account>(null, false, passwordCheck.Message, null, null)); } // Get existing account. Account account = Accounts.GetByFilter("UserNameLowered = '" + userName.ToLower() + "'").Item[0]; if (account == null) { return(new BoolResult <Account>(null, false, "Unable to find account with matching username : " + userName, null, null)); } // Check that password supplied matches whats on file. string encryptedPassword = Crypto.Encrypt(currentPassword); passwordCheck = ValidatePasswords(encryptedPassword, account.Password); if (!passwordCheck.Success) { return(new BoolResult <Account>(null, false, passwordCheck.Message, null, null)); } // Now change password. account.SetPassword(newPassword); return(Accounts.Update(account)); }
public void CanUseSchemaWithoutFluentAPI() { Args args = new Args("-", ":"); args.Schema.AddNamed <string>("config", "config", true, "dev.config", "config file for environment", "dev.xml", "dev.xml | qa.config", false, false, "common", false) .AddNamed <int>("dateoffset", "", true, 0, "business date offset from today", "0", "0 | 1 | -1", false, false, "common", false) .AddNamed <DateTime>("busdate", "", true, DateTime.Today, "business date offset from today", "0", "0 | 1 | -1", true, false, "common", false) .AddNamed <bool>("dryrun", "", true, false, "testing mode", "true", "true | false", false, false, "common", false) .AddPositional <int>(0, true, 5, "Number of categories to display", "5", " 5 | 8 etc.", false, false, "common", false); string[] commandLineArgs = new string[] { "-config:prod.xml", "-dateoffset:2", "-busdate:${today}", "-dryrun:true", "18" }; BoolMessage result = args.DoParse(commandLineArgs); Assert.IsTrue(result.Success); Assert.AreEqual(args.Prefix, "-"); Assert.AreEqual(args.Separator, ":"); Assert.AreEqual(args.Named["config"], "prod.xml"); Assert.AreEqual(args.Named["dateoffset"], "2"); Assert.AreEqual(args.Named["dryrun"], "true"); Assert.AreEqual(args.Get <DateTime>("busdate"), DateTime.Today); }
public void CanUseSchemaWithFluentAPI() { Args args = new Args("-", ":"); args.Schema.AddNamed <string>("config").Required.CaseSensitive.DefaultsTo("dev.config").Examples("dev.xml", "dev.xml | qa.config").Describe("Config file for environment") .AddNamed <int>("dateoffset").Optional.CaseInSensitive.DefaultsTo(0).Examples("0", "0 | 1").Describe("business date offset from today") .AddNamed <DateTime>("busdate").Required.CaseSensitive.DefaultsTo(DateTime.Today).Examples("${today}", "${today} | ${t-1}").Interpret .AddNamed <bool>("dryrun").Optional.CaseInSensitive.DefaultsTo(false).Examples("true", "true | false").Describe("Run in test mode") .AddPositional <int>(0).Required.DefaultsTo(5).Examples("5", "5 | 8").Describe("Number of categories to display"); string[] commandLineArgs = new string[] { "-config:prod.xml", "-dateoffset:2", "-busdate:${today}", "-dryrun:true", "18" }; BoolMessage result = args.DoParse(commandLineArgs); Assert.IsTrue(result.Success); Assert.AreEqual(args.Prefix, "-"); Assert.AreEqual(args.Separator, ":"); Assert.AreEqual(args.Named["config"], "prod.xml"); Assert.AreEqual(args.Named["dateoffset"], "2"); Assert.AreEqual(args.Named["dryrun"], "true"); Assert.AreEqual(args.Get <DateTime>("busdate"), DateTime.Today); }
public static BoolMessage ValidateNode(Node node) { var bm = new BoolMessage(); bm.Data = null; try { System.Net.IPAddress address; if (!System.Net.IPAddress.TryParse(node.IP, out address)) { throw new Exception("Invalid IP Address"); } if (string.IsNullOrEmpty(node.AET)) { throw new Exception("Invalid AET"); } if (string.IsNullOrEmpty(node.Description)) { throw new Exception("Invalid Description"); } if (node.Port > 65536 || node.Port < 1) { throw new Exception("Invalid Port"); } if (!ADCM.EchoNode(node)) { throw new Exception("Unable to echo node"); } bm.Success = true; } catch (Exception ex) { bm.Message = ex.Message; bm.Success = false; } return(bm); }
/// <summary> /// Similar to VerifyUser except this updates the "LastLoginDate" if successful login. /// </summary> /// <param name="userName">Name of user.</param> /// <param name="password">User password.</param> /// <param name="rememberUser">True to remember user.</param> /// <returns>Result of logon attempt.</returns> public BoolMessage LogOn(string userName, string password, bool rememberUser) { // Check inputs. BoolMessage inputCheck = Validation.AreNoneNull(new string[] { userName, password }, new string[] { "UserName", "Password" }, null, null); if (!inputCheck.Success) { return(inputCheck); } BoolMessageItem <User> result = VerifyUser(userName, password); if (result.Success) { // An authentication provider should handle this. // Auth.SignIn(result.Item.UserName, rememberUser); // Update the last login date. result.Item.LastLoginDate = DateTime.Today; Update(result.Item); } return(result); }
public static BoolMessage CheckIfOnlySelected(Node node) { var rbm = new BoolMessage(); rbm.Data = null; try { APetaPoco.SetConnectionString("cn1"); var bm = APetaPoco.PpRetrieveOne <Node>("PACS", "[Selected] = 1"); Node currentSelectedNode = null; if (bm.Success) { currentSelectedNode = (Node)bm.Data; } else { return(bm); } if (currentSelectedNode == null || currentSelectedNode == default(Node)) { if (node.Selected) { rbm.Success = true; } else { throw new Exception("There's no selected node in the database"); } } else { if (node.Selected) { if (node.Id == currentSelectedNode.Id) { rbm.Success = true; } else { currentSelectedNode.Selected = false; bm = APetaPoco.PpUpdate(currentSelectedNode); if (bm.Success) { rbm.Success = true; } else { return(bm); } } } else { if (currentSelectedNode.Id != node.Id) { rbm.Success = true; } else { throw new Exception("Can't unselect the only selected node in database"); } } } } catch (Exception ex) { rbm.Success = false; rbm.Message = ex.Message; } return(rbm); }
/// <summary> /// Flashes an error or a messages depending on success/fail flag in result. /// </summary> /// <param name="result"></param> public void Flash(BoolMessage result) { if (result == null) return; if (result.Success) FlashMessages(result.Message); else FlashErrors(result.Message); }
/// <summary> /// Flash an error from the message in <paramref name="result"/> if result is not successful. /// </summary> /// <param name="result">The boolean message result</param> public void FlashIfError(BoolMessage result) { if (result != null && !result.Success) FlashErrors(result.Message); }
public static void InsertNewCase(HttpContext context) { string caseId = ""; var bm = new BoolMessage(); bm.Data = null; try { var upCasePackage = AF.GetObjectFromJSON<UploadPackage>(context); if (upCasePackage == null || upCasePackage == default(UploadPackage)) { throw new Exception("Unable to parse incoming package"); } APetaPoco.SetConnectionString("cn1"); caseId = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + upCasePackage.username; var dCase = new DbCase(); dCase.age = upCasePackage.case_details.age; dCase.body = upCasePackage.case_details.body; dCase.case_id = caseId; dCase.date = DateTime.Now; dCase.diagnostic_certainty_id = upCasePackage.case_details.diagnostic_certainty_id; dCase.presentation = upCasePackage.case_details.presentation; dCase.status = "PENDING"; dCase.status_message = "Inserted via Uploader UI"; dCase.suitable_for_quiz = upCasePackage.case_details.suitable_for_quiz; dCase.system_id = upCasePackage.case_details.system_id; dCase.title = upCasePackage.case_details.title; dCase.username = upCasePackage.username; bm = APetaPoco.PpInsert(dCase); if (!bm.Success) { throw new Exception("Unable to insert case"); } foreach (var st in upCasePackage.studies) { var dcmSt = ADCM.GetStudyFromStudyUid(st.study_uid); var dSt = new DbStudy(); dSt.caption = st.caption; dSt.case_id = caseId; DateTime dt; bool dtp = DateTime.TryParseExact(st.date, "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dt); if (dtp) { dSt.date = dt; } if(dcmSt != null && dcmSt != default(Study)) { dSt.patient_dob = dcmSt.PatientDob; dSt.patient_id = dcmSt.PatientId; dSt.patient_name = dcmSt.PatientSurname.ToUpper() + ", " + dcmSt.PatientFirstname; } dSt.description = st.description; dSt.findings = st.findings; dSt.images = st.images; dSt.modality = st.modality; dSt.position = st.position; dSt.study_uid = st.study_uid; bm = APetaPoco.PpInsert(dSt); if (!bm.Success) { throw new Exception("Unable to insert study"); } foreach (var se in st.series) { var dSe = new DbSeries(); dSe.case_id = caseId; dSe.description = se.description; dSe.images = se.images; dSe.series_uid = se.series_uid; dSe.study_uid = st.study_uid; dSe.crop_h = se.crop_h; dSe.crop_w = se.crop_w; dSe.crop_x = se.crop_x; dSe.crop_y = se.crop_y; dSe.window_wc = se.window_wc; dSe.window_ww = se.window_ww; dSe.end_image = se.end_image; dSe.every_image = se.every_image; dSe.start_image = se.start_image; bm = APetaPoco.PpInsert(dSe); if (!bm.Success) { throw new Exception("Unable to insert series"); } } } InsertEvent("Successfully inserted case into database:\n" + caseId, "WEB", Newtonsoft.Json.JsonConvert.SerializeObject(dCase), dCase.case_id); bm.Success = true; bm.Data = null; bm.Message = "Successfully inserted case into database"; AF.BoolMessageRespond(context, bm); } catch (System.Threading.ThreadAbortException) { return; } catch (Exception ex) { if (!string.IsNullOrEmpty(caseId)) { ClearAllInDbWithCaseId(caseId); } AF.ExceptionRespond(context, ex); } }
/// <summary> /// Test creation of models /// </summary> public void CanCreate() { ModelContainer models = new ModelContainer() { Settings = new ModelBuilderSettings() { ModelCodeLocation = @"C:\dev\MyApp\src\Lib\CommonLibrary.WebModules\Src\Generated", ModelCodeLocationTemplate = @"C:\dev\MyApp\src\Lib\GenericCode\CodeGen\Templates\Default", ModelInstallLocation = @"C:\dev\MyApp\install\", ModelCodeLocationUI = @"C:\dev\MyApp\models\ui\", ModelDbStoredProcTemplates = @"C:\dev\MyApp\src\Lib\GenericCode\CodeGen\Templates\DefaultSql", ModelOrmLocation = @"C:\dev\MyApp\src\Lib\CommonLibrary.WebModules\Config\hbm.xml", DbAction_Create = DbCreateType.DropCreate, Connection = new ConnectionInfo("Server=server1;Database=db1;User=user1;Password=password;", "System.Data.SqlClient"), AssemblyName = "CommonLibrary.WebModules", OrmGenerationDef = new OrmGeneration(true, "<!-- ORM_GEN_START -->", "<!-- ORM_GEN_END -->"), }, ExtendedSettings = new Dictionary <string, object>() { }, // Model definition. AllModels = new List <Model>() { new Model("ModelBase") { NameSpace = "CommonLibrary.WebModules", GenerateCode = false, GenerateTable = false, GenerateOrMap = false, PropertiesSortOrder = 1, Properties = new List <PropertyInfo>() { new PropertyInfo("Id", typeof(int)) { IsRequired = true, ColumnName = "Id", IsKey = true }, new PropertyInfo("CreateDate", typeof(DateTime)) { IsRequired = true }, new PropertyInfo("UpdateDate", typeof(DateTime)) { IsRequired = true }, new PropertyInfo("CreateUser", typeof(string)) { IsRequired = true, MaxLength = "20" }, new PropertyInfo("UpdateUser", typeof(string)) { IsRequired = true, MaxLength = "20" }, new PropertyInfo("UpdateComment", typeof(string)) { IsRequired = false, MaxLength = "150" }, new PropertyInfo("Version", typeof(int)) { IsRequired = true, DefaultValue = 1 }, new PropertyInfo("IsActive", typeof(bool)) { IsRequired = true, DefaultValue = 0 } } }, new Model("RatingPostBase") { NameSpace = "CommonLibrary.WebModules", Inherits = "ModelBase", GenerateCode = false, GenerateTable = false, GenerateOrMap = false, PropertiesSortOrder = 100, Properties = new List <PropertyInfo>() { new PropertyInfo("AverageRating", typeof(double)), new PropertyInfo("TotalLiked", typeof(int)), new PropertyInfo("TotalDisLiked", typeof(int)), new PropertyInfo("TotalBookMarked", typeof(int)), new PropertyInfo("TotalAbuseReports", typeof(int)) } }, new Model("Address") { Properties = new List <PropertyInfo>() { new PropertyInfo("Street", typeof(string)) { MaxLength = "40" }, new PropertyInfo("City", typeof(string)) { MaxLength = "40" }, new PropertyInfo("State", typeof(string)) { MaxLength = "20" }, new PropertyInfo("Country", typeof(string)) { MaxLength = "20", DefaultValue = "U.S." }, new PropertyInfo("Zip", typeof(string)) { MaxLength = "10" }, new PropertyInfo("CityId", typeof(int)), new PropertyInfo("StateId", typeof(int)), new PropertyInfo("CountryId", typeof(int)) } }, new Model("BlogPost") { TableName = "BlogPosts", NameSpace = "CommonLibrary.WebModules.BlogPosts", GenerateTable = true, GenerateCode = true, GenerateTests = true, GenerateUI = true, GenerateRestApi = true, GenerateFeeds = true, GenerateOrMap = true, IsWebUI = true, PropertiesSortOrder = 50, Properties = new List <PropertyInfo>() { new PropertyInfo("Title", typeof(string)) { ColumnName = "Title", MinLength = "10", MaxLength = "150", IsRequired = true }, new PropertyInfo("Summary", typeof(string)) { MaxLength = "200", IsRequired = true }, new PropertyInfo("Description", typeof(StringClob)) { MinLength = "10", MaxLength = "-1", IsRequired = true }, new PropertyInfo("Url", typeof(string)) { MaxLength = "150", RegEx = "" }, new PropertyInfo("AllowComments", typeof(bool)) { DefaultValue = true } }, Inherits = "ModelBase", Includes = new List <Include>() { new Include("RatingPostBase") }, HasMany = new List <Relation>() { new Relation("Comment") }, ExcludeFiles = "Feeds.cs,ImportExport.cs,Serializer.cs" }, new Model("Event") { TableName = "Events", NameSpace = "CommonLibrary.WebModules.Events", GenerateTable = true, GenerateCode = true, GenerateTests = true, GenerateUI = true, GenerateRestApi = true, GenerateFeeds = true, GenerateOrMap = true, IsWebUI = true, PropertiesSortOrder = 50, Properties = new List <PropertyInfo>() { new PropertyInfo("Title", typeof(string)) { ColumnName = "Title", MinLength = "10", MaxLength = "150", IsRequired = true }, new PropertyInfo("Summary", typeof(string)) { MaxLength = "200", IsRequired = true }, new PropertyInfo("Description", typeof(StringClob)) { MinLength = "10", MaxLength = "-1", IsRequired = true }, new PropertyInfo("StartDate", typeof(DateTime)) { IsRequired = true }, new PropertyInfo("EndDate", typeof(DateTime)) { IsRequired = true }, new PropertyInfo("StartTime", typeof(DateTime)), new PropertyInfo("EndTime", typeof(DateTime)), new PropertyInfo("IsOnline", typeof(bool)) { DefaultValue = false }, new PropertyInfo("Email", typeof(string)) { IsRequired = false, MaxLength = "30", RegEx = "RegexPatterns.Email", IsRegExConst = true }, new PropertyInfo("Phone", typeof(string)) { IsRequired = false, MaxLength = "20", RegEx = "RegexPatterns.PhoneUS", IsRegExConst = true }, new PropertyInfo("Url", typeof(string)) { IsRequired = false, MaxLength = "150", RegEx = "RegexPatterns.Url", IsRegExConst = true }, new PropertyInfo("Keywords", typeof(string)) { MaxLength = "100" } }, Inherits = "ModelBase", Includes = new List <Include>() { new Include("RatingPostBase") }, ComposedOf = new List <Composition>() { new Composition("Address") }, Validations = new List <ValidationItem>() { new ValidationItem("Address", typeof(LocationRule)) { IsStatic = false } }, DataMassages = new List <DataMassageItem>() { new DataMassageItem("Address", typeof(LocationDataMassager), Massage.AfterValidation) { IsStatic = true } }, ExcludeFiles = "Feeds.cs,ImportExport.cs,Serializer.cs" }, new Model("Job") { TableName = "Jobs", NameSpace = "CommonLibrary.WebModules.Jobs", GenerateTable = true, GenerateCode = true, GenerateTests = true, GenerateUI = true, GenerateRestApi = true, GenerateFeeds = true, GenerateOrMap = true, IsWebUI = true, PropertiesSortOrder = 50, Properties = new List <PropertyInfo>() { new PropertyInfo("Title", typeof(string)) { ColumnName = "Title", MinLength = "10", MaxLength = "150", IsRequired = true }, new PropertyInfo("Summary", typeof(string)) { MaxLength = "200", IsRequired = true }, new PropertyInfo("Description", typeof(StringClob)) { MinLength = "10", MaxLength = "-1", IsRequired = true }, new PropertyInfo("StartDate", typeof(DateTime)) { IsRequired = true }, new PropertyInfo("EndDate", typeof(DateTime)) { IsRequired = true }, new PropertyInfo("StartTime", typeof(DateTime)), new PropertyInfo("EndTime", typeof(DateTime)), new PropertyInfo("IsOnline", typeof(bool)) { DefaultValue = false }, new PropertyInfo("Email", typeof(string)) { IsRequired = false, MaxLength = "30", RegEx = "RegexPatterns.Email", IsRegExConst = true }, new PropertyInfo("Phone", typeof(string)) { IsRequired = false, MaxLength = "20", RegEx = "RegexPatterns.PhoneUS", IsRegExConst = true }, new PropertyInfo("Url", typeof(string)) { IsRequired = false, MaxLength = "150", RegEx = "RegexPatterns.Url", IsRegExConst = true }, new PropertyInfo("Keywords", typeof(string)) { MaxLength = "100" } }, Inherits = "ModelBase", Includes = new List <Include>() { new Include("RatingPostBase") }, ComposedOf = new List <Composition>() { new Composition("Address") }, Validations = new List <ValidationItem>() { new ValidationItem("Address", typeof(LocationRule)) { IsStatic = false } }, DataMassages = new List <DataMassageItem>() { new DataMassageItem("Address", typeof(LocationDataMassager), Massage.AfterValidation) { IsStatic = true } }, ExcludeFiles = "Feeds.cs,ImportExport.cs,Serializer.cs" } } }; ModelContext ctx = new ModelContext() { AllModels = models }; IList <ICodeBuilder> builders = new List <ICodeBuilder>() { new CodeBuilderWebUI(), new CodeBuilderDb(ctx.AllModels.Settings.Connection), new CodeBuilderORMHibernate(), new CodeBuilderDomain() }; BoolMessage message = CodeBuilder.Process(ctx, builders); }
public static BoolMessage CheckIfOnlySelected(Node node) { var rbm = new BoolMessage(); rbm.Data = null; try { APetaPoco.SetConnectionString("cn1"); var bm = APetaPoco.PpRetrieveOne<Node>("PACS", "[Selected] = 1"); Node currentSelectedNode = null; if (bm.Success) currentSelectedNode = (Node)bm.Data; else return bm; if (currentSelectedNode == null || currentSelectedNode == default(Node)) { if (node.Selected) { rbm.Success = true; } else { throw new Exception("There's no selected node in the database"); } } else { if (node.Selected) { if (node.Id == currentSelectedNode.Id) { rbm.Success = true; } else { currentSelectedNode.Selected = false; bm = APetaPoco.PpUpdate(currentSelectedNode); if (bm.Success) { rbm.Success = true; } else { return bm; } } } else { if (currentSelectedNode.Id != node.Id) { rbm.Success = true; } else { throw new Exception("Can't unselect the only selected node in database"); } } } } catch (Exception ex) { rbm.Success = false; rbm.Message = ex.Message; } return rbm; }
public static BoolMessage ValidateNode(Node node) { var bm = new BoolMessage(); bm.Data = null; try { System.Net.IPAddress address; if (!System.Net.IPAddress.TryParse(node.IP, out address)) { throw new Exception("Invalid IP Address"); } if (string.IsNullOrEmpty(node.AET)) { throw new Exception("Invalid AET"); } if (string.IsNullOrEmpty(node.Description)) { throw new Exception("Invalid Description"); } if (node.Port > 65536 || node.Port < 1) { throw new Exception("Invalid Port"); } if (!ADCM.EchoNode(node)) { throw new Exception("Unable to echo node"); } bm.Success = true; } catch (Exception ex) { bm.Message = ex.Message; bm.Success = false; } return bm; }