private ConflictHelper GetConflictHelper(Type type) { var attribute = type.GetAttributes <SavableMonobehaviourAttribute>(false).Single(); var helper = new ConflictHelper { Type = type, FieldNumber = attribute.FieldNumber }; return(helper); }
private void FillDashboardDetails(DbDashboard existingDashboard, CreateDashboardRequest request) { if (request.Feedbacks == null) { request.Feedbacks = new List <CreateBotRequestFeedback>(); } if (request.Feedbacks.GroupBy(f => f.Id).Any(g => g.Count() > 1)) { throw new HttpStatusException(HttpStatusCode.BadRequest, "Duplicate feedback ids"); } if (request.ConflictExceptions == null) { request.ConflictExceptions = new List <CreateBotRequestExceptions>(); } if (request.ConflictExceptions.GroupBy(f => f.Id).Any(g => g.Count() > 1)) { throw new HttpStatusException(HttpStatusCode.BadRequest, "Duplicate conflict exception ids"); } ConflictHelper.AssertUniqueConflictFeedbacks(request.ConflictExceptions.Select(c => c.BotResponseConflictFeedbacks)); existingDashboard.BotName = request.BotName; existingDashboard.DashboardName = request.DashboardName; existingDashboard.Description = request.Description; if (!string.IsNullOrWhiteSpace(request.Secret)) { existingDashboard.Secret = BCrypt.Net.BCrypt.HashPassword(request.Secret); } if (request.OwnerAccountId.HasValue && User.HasClaim(Scopes.SCOPE_ADMIN)) { existingDashboard.OwnerAccountId = request.OwnerAccountId.Value; } existingDashboard.FavIcon = request.FavIcon; existingDashboard.Homepage = request.Homepage; existingDashboard.LogoUrl = request.LogoUrl; existingDashboard.TabTitle = request.TabTitle; existingDashboard.RequiredFeedback = request.RequiredFeedback; existingDashboard.RequiredFeedbackConflicted = request.RequiredFeedbackConflicted; var createdFeedbacks = new Dictionary <int, DbFeedback>(); CollectionUpdater.UpdateCollection( existingDashboard.Feedbacks.ToDictionary(f => f.Id, f => f), request.Feedbacks.ToDictionary(f => f.Id, f => f), newFeedback => { var dbFeedbackType = new DbFeedback { Dashboard = existingDashboard, Name = newFeedback.Name, Colour = newFeedback.Colour, Icon = newFeedback.Icon, IsActionable = newFeedback.IsActionable, IsEnabled = newFeedback.IsEnabled }; existingDashboard.Feedbacks.Add(dbFeedbackType); _dbContext.Feedbacks.Add(dbFeedbackType); createdFeedbacks.Add(newFeedback.Id, dbFeedbackType); }, (existingFeedback, newFeedback) => { existingFeedback.Name = newFeedback.Name; existingFeedback.Colour = newFeedback.Colour; existingFeedback.Icon = newFeedback.Icon; existingFeedback.IsActionable = newFeedback.IsActionable; existingFeedback.IsEnabled = newFeedback.IsEnabled; }, existingFeedback => { } ); if (existingDashboard.Feedbacks.GroupBy(f => f.Name, StringComparer.OrdinalIgnoreCase).Any(g => g.Count() > 1)) { throw new HttpStatusException(HttpStatusCode.BadRequest, "Feedback names must be unique"); } CollectionUpdater.UpdateCollection( existingDashboard.ConflictExceptions.ToDictionary(ce => ce.Id, ce => ce), request.ConflictExceptions.ToDictionary(ce => ce.Id, ce => ce), newConflict => { var dbConflictException = new DbConflictException { Dashboard = existingDashboard, IsConflict = newConflict.IsConflict, RequiresAdmin = newConflict.RequiresAdmin, RequiredFeedback = newConflict.RequiredFeedback }; foreach (var conflictFeedbackId in newConflict.BotResponseConflictFeedbacks) { var newConflictException = new DbConflictExceptionFeedback { ConflictException = dbConflictException }; if (conflictFeedbackId < 0) { if (createdFeedbacks.ContainsKey(conflictFeedbackId)) { newConflictException.Feedback = createdFeedbacks[conflictFeedbackId]; } else { throw new HttpStatusException(HttpStatusCode.BadRequest, "Invalid FeedbackId for conflict"); } } else { newConflictException.FeedbackId = conflictFeedbackId; } _dbContext.ConflictExceptionFeedbacks.Add(newConflictException); } existingDashboard.ConflictExceptions.Add(dbConflictException); _dbContext.ConflictExceptions.Add(dbConflictException); }, (existingConflict, newConflict) => { existingConflict.IsConflict = newConflict.IsConflict; existingConflict.RequiresAdmin = newConflict.RequiresAdmin; existingConflict.RequiredFeedback = newConflict.RequiredFeedback; CollectionUpdater.UpdateCollection( existingConflict.ConflictExceptionFeedbacks.ToDictionary(d => d.FeedbackId, d => d), newConflict.BotResponseConflictFeedbacks.ToDictionary(d => d, d => d), newConflictFeedbackId => { var newConflictException = new DbConflictExceptionFeedback { ConflictException = existingConflict }; if (newConflictFeedbackId < 0) { if (createdFeedbacks.ContainsKey(newConflictFeedbackId)) { newConflictException.Feedback = createdFeedbacks[newConflictFeedbackId]; } else { throw new HttpStatusException(HttpStatusCode.BadRequest, "Invalid FeedbackId for conflict"); } } else { newConflictException.FeedbackId = newConflictFeedbackId; } _dbContext.ConflictExceptionFeedbacks.Add(newConflictException); }, (existingConflictFeedback, newConflictFeedback) => { }, existingConflictFeedback => { _dbContext.ConflictExceptionFeedbacks.Remove(existingConflictFeedback); } ); }, existingConflict => { _dbContext.ConflictExceptions.Remove(existingConflict); } ); }
public Positioner() { this.PositionHelper = new PositionHelper(); this.ConflictHelper = new ConflictHelper(); }
/// <summary> /// This method writes the LoadCollection method for a DataTable. /// </summary> /// <param name="dataTable"></param> private void WriteLoadCollectionMethod(DataTable dataTable) { // Write Blank Line WriteLine(); // Write BeginRegion BeginRegion("LoadCollection(DataTable dataTable)"); // Write Load Collection Summary WriteLoadCollectionSummary(dataTable); // get objectName string className = dataTable.ClassName; // get collection return type string collectionReturnType = "List<" + className + ">"; // if there is a conflict with this class name if (ConflictHelper.CheckForConflict(className)) { // resolve the conflict collectionReturnType = ConflictHelper.ResolveConflict(collectionReturnType, dataTable.ObjectNameSpaceName); } // get the return variable name string returnVariableName = CapitalizeFirstChar(className, true); // fix any pluralization issues returnVariableName = PluralWordHelper.GetPluralName(className, true); // Create loadMethodLine string loadMethodLine = "public static " + collectionReturnType + " LoadCollection(DataTable dataTable)"; // Write LoadMethodLine WriteLine(loadMethodLine); // Write Open Bracket WriteOpenBracket(); // Increase Indent Indent++; // Write Comment For Initial Value WriteComment("Initial Value"); // Create Object Line string objectLine = CreateCollectionObjectLine(collectionReturnType, returnVariableName); // Write Object Line WriteLine(objectLine); // Write Blank Line WriteLine(); // Write try WriteLine("try"); // Write Open Bracket WriteOpenBracket(); // Increase Indent Indent++; // Write Comment Load Each row In dataTable WriteComment("Load Each row In DataTable"); // Now Write For Each Line WriteLine("foreach (DataRow row in dataTable.Rows)"); // Write Open Bracket WriteOpenBracket(); // Incrase Indent Indent++; // Write the comment to create object from data row WriteComment("Create '" + dataTable.ClassName + "' from rows"); // get the single variable name string singleVariableName = CapitalizeFirstChar(className, true); // if this object ends in "s" it can't be singular if (singleVariableName.EndsWith("s")) { // remove the last s singleVariableName = singleVariableName.Substring(0, singleVariableName.Length - 1); } // Write Line To Load This Object string line = dataTable.ClassName + " " + singleVariableName + " = Load(row);"; // write this line WriteLine(line); // Write Blank Line WriteLine(); // Write Comment add this object to collection WriteComment("Add this object to collection"); // Write addToCollection Line string addToCollection = returnVariableName + ".Add(" + singleVariableName + ");"; // write line WriteLine(addToCollection); // Decrease Indent Indent--; // Write Close Bracket WriteLine("}"); // Decrease Indent Indent--; // Write Close Bracket WriteLine("}"); // Write catch WriteLine("catch"); // Write Open Bracket WriteOpenBracket(); // Write Close Bracket WriteLine("}"); // Write Blank Line WriteLine(); // write Comment For Return Value WriteComment("return value"); // Write Return Value string returnValue = "return " + returnVariableName + ";"; WriteLine(returnValue); // Decrease Indent Indent--; // Write Close Bracket WriteLine("}"); // Write end Region WriteLine("#endregion"); // Write Blank Line WriteLine(); }
/// <summary> /// This method creates the FetchAll proc for a DataTabe /// </summary> /// <param name="dataTable"></param> /// <param name="nameSpace"></param> private void CreateFetchAllMethod(DataTable dataTable) { // get dataType variable string dataType = "List<" + dataTable.ClassName + ">"; // local string variableName = dataTable.ClassName + "Collection"; // create the name for the data object (must be set before the conflict is fixed) string dataObject = this.CapitalizeFirstChar(variableName, true); // if there is a conflict with this name if (ConflictHelper.CheckForConflict(dataTable.ClassName)) { // fix the conflict dataType = ConflictHelper.ResolveConflict(dataType, dataTable.ObjectNameSpaceName); } // get a variable for className string className = PluralWordHelper.GetPluralName(dataTable.ClassName, false); // local string queryType = "procedure"; // get procName & procType string procName = "fetchAll" + className + "Proc"; string procType = "FetchAll" + className + "StoredProcedure"; // Write Blank Line WriteLine(); // Begin Region BeginRegion("FetchAll" + className + "()"); // Write FetchAll Summary WriteLine("/// <summary>"); WriteLine("/// This method fetches a '" + dataType + "' object."); WriteLine("/// This method uses the '" + className + "_FetchAll' " + queryType + "."); WriteLine("/// </summary>"); WriteLine("/// <returns>A '" + dataType + "'</returns>"); WriteLine("/// </summary>"); // get class declaration line string classLine = "public " + dataType + " FetchAll" + className + "(" + procType + " " + procName + ", DataConnector databaseConnector)"; // Write class line WriteLine(classLine); // Write Open Bracket WriteOpenBracket(true); // Write Comment Initial Value WriteComment("Initial Value"); // Write line to set initial value string initialValue = dataType + " " + dataObject + " = null;"; WriteLine(initialValue); // Write Blank Line WriteLine(); // Write Comment Verify database connection is connected WriteComment("Verify database connection is connected"); // get line to test connection string ifConnected = "if ((databaseConnector != null) && (databaseConnector.Connected))"; // Write ifConnected WriteLine(ifConnected); // Write Open Bracket WriteOpenBracket(true); // Write Comment First Get Dataset WriteComment("First Get Dataset"); // get line to get data set string dataSetName = "all" + className + "DataSet"; string dataSetLine = "DataSet " + dataSetName + " = this.DataHelper.LoadDataSet(" + procName + ", databaseConnector);"; // Write set dataSetLine WriteLine(dataSetLine); // Write Blank Line WriteLine(); // Write Comment Verify DataSet Exists WriteComment("Verify DataSet Exists"); // line to test if DataSet exists string ifDataSetExists = "if(" + dataSetName + " != null)"; WriteLine(ifDataSetExists); // Write Open Bracket WriteOpenBracket(true); // Write Comment Get DataTable From DataSet WriteComment("Get DataTable From DataSet"); // get line to get first table out of data set string dataTableLine = "DataTable table = this.DataHelper.ReturnFirstTable(" + dataSetName + ");"; WriteLine(dataTableLine); // Write Blank Line WriteLine(); // Write Comment if table exists WriteComment("if table exists"); // now write line to test if table exists WriteLine("if(table != null)"); // Write Open Bracket WriteOpenBracket(true); // Write Comment Load Collection WriteComment("Load Collection"); // get reader name string readerName = dataTable.ClassName + "Reader"; // get line to load collection string loadCollection = dataObject + " = " + readerName + ".LoadCollection(table);"; // Write loadCollection WriteLine(loadCollection); // Write Close Bracket WriteCloseBracket(true); // WRite Close Bracket WriteCloseBracket(true); // Write Close Bracket WriteCloseBracket(true); // Write Blank Line WriteLine(); // Write Comment Return Value WriteComment("return value"); // Write Return Value WriteLine("return " + dataObject + ";"); // Write Close Bracket WriteCloseBracket(true); // Write EndRegion for DeleteMethod EndRegion(); // Write Blank Line WriteLine(); }