Classifier PropertyContextHead(List <string> path, string selfName, Classifier declaredPropertyType, out VariableDeclaration selfOut, out Property property) { if (path.Count < 2) { // error selfOut = null; property = null; Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_PropertyContextHead_Incorrect_context_declaration___0___Class_and_operation_name_expected_1, path.ConcatWithSeparator("::")))); EnvironmentStack.Push(ErrorEnvironment.Instance); EnvironmentStack.Push(ErrorEnvironment.Instance); return(null); } string propertyName = path.Last(); IModelElement element = Environment.LookupPathName(path.Take(path.Count - 1)); if (element is Classifier == false) { // error selfOut = null; property = null; Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_ClassifierContextHead_ClassifierNotFound_1, path.Take(path.Count - 1).ConcatWithSeparator(@"::")))); EnvironmentStack.Push(ErrorEnvironment.Instance); EnvironmentStack.Push(ErrorEnvironment.Instance); return(null); } Classifier contextClassifier = element as Classifier; property = contextClassifier.LookupProperty(propertyName); if (property == null) { // error selfOut = null; Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_PropertyContextHead_PropertyNotFound_2, propertyName, contextClassifier))); EnvironmentStack.Push(ErrorEnvironment.Instance); EnvironmentStack.Push(ErrorEnvironment.Instance); return(null); } if (property.Type != declaredPropertyType) { // error selfOut = null; Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_PropertyContextHead_TypeMismatch_3, property.Name, property.Type, declaredPropertyType))); EnvironmentStack.Push(ErrorEnvironment.Instance); EnvironmentStack.Push(ErrorEnvironment.Instance); return(null); } VariableDeclaration varSelf = new VariableDeclaration(selfName, contextClassifier, null);// tady by to chtelo doplnit initValue selfOut = varSelf; Environment classifierEnv = Environment.CreateFromClassifier(contextClassifier, varSelf); EnvironmentStack.Push(classifierEnv); Environment self = Environment.AddElement(selfName, contextClassifier, varSelf, true); EnvironmentStack.Push(self); return(contextClassifier); }
VariableDeclaration LetDecl(IToken letToken, VariableDeclarationBag varBag) { if (TestNull(letToken, varBag, varBag != null ? varBag.Type : null)) { return(new VariableDeclaration("", Library.Invalid, new AST.ErrorExp(Library.Invalid))); } if (Environment.Lookup(varBag.Name) != null) { Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_LetDecl_The_variable_name_must_be_unique_in_the_current_scope, letToken, letToken)); return(null); } Classifier type = varBag.Type ?? varBag.Expression.Type; if (varBag.Expression.Type.ConformsTo(varBag.Type) == false) { Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_LetDecl_Variable_type_does_not_conform_to_variable_expression_type, letToken, letToken)); } VariableDeclaration var = new VariableDeclaration(varBag.Name, varBag.Type, varBag.Expression); EnvironmentStack.Push(Environment.AddElement(var.Name, var.PropertyType, var, true)); return(var); }
Classifier ClassifierContextHead(List <IToken> tokenPath, string selfName, out VariableDeclaration selfOut) { List <string> path = tokenPath.ToStringList(); IModelElement element = Environment.LookupPathName(path); if (element is Classifier == false) { // error selfOut = null; Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_ClassifierContextHead_ClassifierNotFound_1, path.ConcatWithSeparator(@"::")))); EnvironmentStack.Push(ErrorEnvironment.Instance); EnvironmentStack.Push(ErrorEnvironment.Instance); return(null); } Classifier contextClassifier = element as Classifier; VariableDeclaration varSelf = new VariableDeclaration(selfName, contextClassifier, null);// tady by to chtelo doplnit initValue selfOut = varSelf; Environment classifierEnv = Environment.CreateFromClassifier(contextClassifier, varSelf); EnvironmentStack.Push(classifierEnv); Environment self = Environment.AddElement(selfName, contextClassifier, varSelf, true); EnvironmentStack.Push(self); return(contextClassifier); }
public async Task <IActionResult> ChangePassword(RegistrationViewModel userRegVM) { try { //Find user var user = await _userManager.FindByIdAsync(userRegVM.ID); string oldPassword = userRegVM.Password; string newPassword = userRegVM.PasswordRaw; IdentityResult result = await _userManager.ChangePasswordAsync(user, oldPassword, newPassword); //update Raw Pwd var origionalData = _unitOfWork.Employee.GetSingleOrDefault(u => u.Id == user.Id); if (origionalData != null) { origionalData.PasswordRaw = newPassword; _unitOfWork.Employee.Update(origionalData); } await _unitOfWork.CompleteAsync(); } catch (Exception Ex) { return(new BadRequestObjectResult(Errors.AddError(Ex, ModelState))); } return(Ok(userRegVM)); }
AST.OclExpression ResolveImplicitOperation(List <IToken> tokenPath, bool isPre, List <AST.OclExpression> callArgs) { if (TestNull(tokenPath, callArgs)) { return(new AST.ErrorExp(Library.Invalid)); } var codeSource = new CodeSource(tokenPath[0]); List <string> path = tokenPath.ToStringList(); if (path.Count == 1) { // simple name //35 d,f ImplicitOperationData operation = Environment.LookupImplicitOperation(path[0], callArgs.Select(arg => arg.Type)); if (operation == null) { Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_ResolveImplicitOperation_Operation_not_found_1, path[0]))); return(new AST.ErrorExp(Library.Any)); } //self problem // tady by melo byt vyreseno self AST.VariableExp operationSource = new AST.VariableExp(operation.Source) .SetCodeSource(codeSource); return(new AST.OperationCallExp(operationSource, isPre, operation.Operation, callArgs, Environment) .SetCodeSource(codeSource)); } else { //path // 35 g // lookupPathName neresi pretizeni nazvu => a nezohlednuje operace s ruznymi signaturami throw new NotSupportedException(); } }
/// <summary> /// Performs question-type-specific update operations. /// </summary> protected sealed override async Task UpdateQuestionImplAsync() { var tests = Question.GetTests().ToList(); if (tests == null || tests.Count == 0) { Errors.AddError("Tests", "At least one test is required."); return; } UpdateTests(tests); UpdateCodeConstraints(Question.CodeConstraints); DbContext.RemoveUnwantedObjects ( DbContext.ImportedClasses, importedClass => importedClass.Id, importedClass => importedClass.CodeQuestionId == Question.Id, Question.ImportedClasses ); DbContext.RemoveUnwantedObjects ( DbContext.CodeConstraints, constraint => constraint.Id, constraint => constraint.CodeQuestionId == Question.Id, Question.CodeConstraints ); await UpdateCodeQuestionImplAsync(); }
/// <summary> /// Performs code-question-type-specific update operations. /// </summary> protected override Task UpdateCodeQuestionImplAsync() { if (!Question.FileTemplate.Contains(ClassQuestion.SubmissionPlaceholder)) { Errors.AddError ( "FileTemplate", $"The file template must contain the string '{ClassQuestion.SubmissionPlaceholder}'." ); } DbContext.RemoveUnwantedObjects ( DbContext.ClassQuestionTests, test => test.Id, test => test.ClassQuestionId == Question.Id, Question.Tests ); DbContext.RemoveUnwantedObjects ( DbContext.RequiredMethods, method => method.Id, method => method.ClassQuestionId == Question.Id, Question.RequiredMethods ); return(Task.CompletedTask); }
public async Task <IActionResult> EditHoliday(HolidayViewModel holidayVM) { try { //Update Holiday var HolidayData = _unitOfWork.Holiday.GetSingleOrDefault(d => d.Id == holidayVM.ID); if (HolidayData != null) { HolidayData.FestivalName = holidayVM.FestivalName; HolidayData.FestivalDate = Utilities.FormatDateTimeByZone(holidayVM.FestivalDate); HolidayData.FestivalDay = Utilities.FormatDateTimeByZone(holidayVM.FestivalDate).ToString("dddd"); HolidayData.FestivalDescription = holidayVM.FestivalDescription; HolidayData.IsNationalFestival = holidayVM.IsNationalFestival; HolidayData.BelongToCommunity = holidayVM.BelongToCommunity; } _unitOfWork.Holiday.Update(HolidayData); await _unitOfWork.CompleteAsync(); } catch (Exception Ex) { return(new BadRequestObjectResult(Errors.AddError(Ex, ModelState))); } return(new OkObjectResult(holidayVM)); }
AST.OclExpression CollectionLiteralExp(CollectionKind kind, CommonTree token, Classifier type, List <AST.CollectionLiteralPart> parts) { if (TestNull(token, type, parts)) { return(new AST.ErrorExp(Library.Invalid)); } if (kind == CollectionKind.Collection) { Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_CollectionLiteralExp_CollectionIsAbstract, token.Token, token.Token)); } var collType = CreateCollectionType(kind, type); // check type foreach (var part in parts) { if (part.Type.ConformsTo(collType.ElementType) == false) { Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_CollectionLiteralExp_Incorrects_mishmash_type_in_collection_literal, token.Token, token.Token)); } } return(new AST.CollectionLiteralExp(collType, parts) .SetCodeSource(new CodeSource(token))); }
TupleType CreateTupleType(IToken rootToken, List <VariableDeclarationBag> variables) { if (TestNull(rootToken, variables)) { TupleType tupleType = new TupleType(TypesTable, new List <Property>()); TypesTable.RegisterType(tupleType); return(tupleType); } Dictionary <string, Property> tupleParts = new Dictionary <string, Property>(); foreach (var variable in variables) { if (tupleParts.Keys.Contains(variable.Name)) // Kontrola nad ramec specifikace { Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_CreateTupleLiteral_Name_repeated_1, variable.Name), rootToken, rootToken)); continue; } Classifier propertyType = variable.Type; if (variable.Type == null) { propertyType = Library.Invalid; } tupleParts.Add(variable.Name, new Property(variable.Name, PropertyType.One, propertyType)); } TupleType tuple = new TupleType(TypesTable, tupleParts.Values); TypesTable.RegisterType(tuple); return(tuple); }
public async Task <IActionResult> DeleteDoctor(DoctorViewModel docVM, string action) { try { var origionalData = _unitOfWork.AuditableEntity.GetSingleOrDefault(e => e.RefTableId == docVM.ID && e.RefTableName == ReferenceTableNames.DOCTOR); if (origionalData != null) { if (action.Equals("delete")) { origionalData.IsActive = false; } else { origionalData.IsActive = true; } _unitOfWork.AuditableEntity.Update(origionalData); await _unitOfWork.CompleteAsync(); } } catch (Exception Ex) { return(new BadRequestObjectResult(Errors.AddError(Ex, ModelState))); } return(Ok(docVM)); }
AST.OclExpression ProcessPropertyCall(AST.OclExpression expr, List <IToken> tokenPath, bool isPre) { if (TestNull(expr, tokenPath)) { return(new AST.ErrorExp(Library.Invalid)); } List <string> path = tokenPath.ToStringList(); if (expr.Type is CollectionType) { Classifier sourceType = ((CollectionType)expr.Type).ElementType; Property property = sourceType.LookupProperty(path[0]); if (property != null) { return(CreateImplicitPropertyIterator(expr, tokenPath[0], sourceType, property)); } } else { Property property = expr.Type.LookupProperty(path[0]); if (property != null) { //36a return(CheckAmbiguous(new AST.PropertyCallExp(expr, isPre, null, null, property)) .SetCodeSource(new CodeSource(tokenPath[0]))); } } Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_ProcessPropertyCall_PropertyNotExists_1, path[0]), tokenPath.First(), tokenPath.Last())); return(new AST.ErrorExp(Library.Invalid)); }
AST.OclExpression ResolvePath(List <IToken> tokenPath, bool isPre) { if (TestNull(tokenPath)) { return(new AST.ErrorExp(Library.Invalid)); } var codeSource = new CodeSource(tokenPath[0]); List <string> path = tokenPath.ToStringList(); if (path.Count == 1) { // simpleName IModelElement element = Environment.Lookup(path[0]); //Variable if (element is VariableDeclaration) { if (isPre) { Errors.AddError(new ErrorItem(CompilerErrors.OCLAst_ResolvePath_Modifikator__pre_se_nepoji_s_promenou)); } return(new AST.VariableExp((VariableDeclaration)element) .SetCodeSource(codeSource)); } //Property 36B ImplicitPropertyData implProperty = Environment.LookupImplicitAttribute(path[0]); if (implProperty != null) { // self problem AST.VariableExp propertySource = new AST.VariableExp(implProperty.Source) .SetCodeSource(codeSource); return(CheckAmbiguous(new AST.PropertyCallExp(propertySource, isPre, null, null, implProperty.Property)) .SetCodeSource(codeSource)); } // chyby naky to pravidlo // JM > type exp if (element is Classifier) { return(new AST.TypeExp((Classifier)element, Library.Type) .SetCodeSource(codeSource)); } } else { // path IModelElement element = Environment.LookupPathName(path); //Chyby enum !!!!!!!!!!!!!!!!!!!!!!!! if (element is Classifier) { return(new AST.TypeExp((Classifier)element, Library.Type) .SetCodeSource(codeSource)); } // Chyby 36C } Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_ResolvePath_Chyba_nebo_nepodporovane_pravidlo, tokenPath.First(), tokenPath.Last())); return(new AST.ErrorExp(Library.Invalid)); }
AST.PropertyCallExp CheckAmbiguous(AST.PropertyCallExp prop) { if (prop.ReferredProperty.IsAmbiguous) { Errors.AddError(new ErrorItem(String.Format(CompilerErrors.AmbiguousNavigation, prop.Source.Type.Name, prop.ReferredProperty.Name))); } return(prop); }
public void ShowError(string description) { if (!string.IsNullOrEmpty(description)) { Errors.AddError(description, true); NotifyOfPropertyChange(() => Error); NotifyOfPropertyChange(() => HasErrors); } }
public void UpdateProperty1(string value) { //validation if (string.IsNullOrEmpty(value)) { //Null would likley be validated in the Dto but this is to show an example. Errors.AddError(ErrorCode.InvalidName, "You must supply a value."); } Property1 = value; }
AST.OclExpression ProcessIteratorCall(AST.OclExpression expr, List <IToken> tokenPath, List <VariableDeclaration> decls, List <AST.OclExpression> args) { if (TestNull(expr, tokenPath, decls, args)) { return(new AST.ErrorExp(Library.Invalid)); } // apply oclAsSet opretion on not collect type if (expr.Type is CollectionType == false) { Operation asSetOp = expr.Type.LookupOperation(Library.OclAsSet, new Classifier[0]); if (asSetOp == null) { Errors.AddError(new ErrorItem(String.Format(CompilerErrors.OCLParser_OperationNotFound_1, Library.OclAsSet))); return(new AST.ErrorExp(Library.Invalid)); } expr = new AST.OperationCallExp(expr, false, asSetOp, new List <AST.OclExpression>(), Environment) .SetCodeSource(new CodeSource(tokenPath[0])); } List <string> path = tokenPath.ToStringList(); if (path.Count != 1) { Errors.AddError(new CodeErrorItem(string.Format(CompilerErrors.OCLAst_ProcessIteratorCall_Unknow_iterator_operation), tokenPath.First(), tokenPath.Last())); return(new AST.ErrorExp(Library.Invalid)); } if (args.Count > 1) { Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_ProcessIteratorCall_Iterator_ma_jenom_jedno_tělo_výrazu, tokenPath.First(), tokenPath.Last())); } string name = path[0]; IteratorOperation iteratorOperation = ((CollectionType)(expr.Type)).LookupIteratorOperation(name); // Iterator variable muze byt NULL -> pak se pouziji defaultni nazvy ... neni implementovano if (iteratorOperation != null) { // Pozadovany typ na telo iteratoru, podle pouzite funkce Classifier bodyType = iteratorOperation.BodyType(expr.Type as CollectionType, args[0].Type, TypesTable); if (args[0].Type.ConformsTo(bodyType) == false) { Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_ProcessIteratorCall_Body_type_inconsistency, tokenPath.First(), tokenPath.Last())); } //Navratovy typ iteratoru podle pouzite operace Classifier returnType = iteratorOperation.ExpressionType(expr.Type as CollectionType, args[0].Type, TypesTable); return(new AST.IteratorExp(expr, args[0], name, decls, returnType) .SetCodeSource(new CodeSource(tokenPath[0]))); } Errors.AddError(new CodeErrorItem(string.Format(CompilerErrors.OCLAst_ProcessIteratorCall_Bad_iterator_operation_1, name), tokenPath.First(), tokenPath.Last())); return(new AST.ErrorExp(Library.Invalid)); }
AST.TupleLiteralExp CreateTupleLiteral(IToken rootToken, List <VariableDeclarationBag> vars) { if (TestNull(rootToken, vars)) { TupleType tupleTypeErr = new TupleType(TypesTable, new List <Property>()); TypesTable.RegisterType(tupleTypeErr); return(new AST.TupleLiteralExp(new Dictionary <string, AST.TupleLiteralPart>(), tupleTypeErr) .SetCodeSource(new CodeSource(rootToken))); } Dictionary <string, AST.TupleLiteralPart> parts = new Dictionary <string, AST.TupleLiteralPart>(); List <Property> tupleParts = new List <Property>(); foreach (var var in vars) { if (parts.ContainsKey(var.Name)) { Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_CreateTupleLiteral_Name_repeated_1, var.Name), rootToken, rootToken)); continue; } AST.OclExpression expr = var.Expression; if (var.Expression == null) { expr = new AST.ErrorExp(Library.Invalid); } Classifier type = var.Type; if (type == null) { type = expr.Type; } if (expr.Type.ConformsTo(type) == false) { Errors.AddError(new ErrorItem(CompilerErrors.OCLAst_CreateTupleLiteral_Type_does_not_comform_to_declared_type)); } //hodnota var newProterty = new Property(var.Name, PropertyType.One, type); var newPart = new AST.TupleLiteralPart(newProterty, expr); parts.Add(var.Name, newPart); //typ tupleParts.Add(newProterty); } TupleType tupleType = new TupleType(TypesTable, tupleParts); TypesTable.RegisterType(tupleType); return(new AST.TupleLiteralExp(parts, tupleType) .SetCodeSource(new CodeSource(rootToken)));; }
/// <summary> /// Adds the bound item. /// </summary> /// <param name="token">The token.</param> /// <param name="binding">The binding.</param> public void AddBoundItem(IIntellisenseResult token, IBinaryDataListEntry binding) { if (binding == null) { Errors.AddError("Could not evaluate { " + token.Option.DisplayValue + " }"); return; } _internalKeyMap[token] = binding; }
bool TestNull(params object[] objs) { if (objs.Any(o => o == null)) { System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(); var callingMethod = st.GetFrame(1).GetMethod(); Errors.AddError(new ErrorItem(String.Format(CompilerErrors.OCLAst_TestNull_Compiler_panic_in_method_1, callingMethod.Name))); return(true); } return(false); }
/// <summary> /// Processes the error tokens. /// </summary> /// <param name="tokens">The tokens.</param> public void ProcessErrorTokens(IEnumerable <IIntellisenseResult> tokens) { if (tokens == null) { return; } foreach (var err in tokens) { Errors.AddError(err.Message); } }
bool _Error(string s, int from, int to) { if (!_flags.Has(EMPFlags.ForCodeInfo)) { Errors.AddError(_fn, _code, from, "error in meta: " + s); } else if (_fn == Panels.Editor.ZActiveDoc.ZFile) { CodeInfo._diag.AddMetaError(from, to, s); } return(false); }
public async Task <IActionResult> AddChemist(ChemistViewModel chemistVM) { try { //Add Chemist string chemistTableID = Guid.NewGuid().ToString(); var chemist = mapper.Map <Chemist>(chemistVM); chemist.Id = chemistTableID; _unitOfWork.Chemist.Add(chemist); //Add Comman CommonResourceViewModel commonVM = chemistVM.Common; commonVM.ID = Guid.NewGuid().ToString(); commonVM.RefTableId = chemistTableID; commonVM.ContactPersonDateOfBirth = Utilities.FormatDateTimeByZone(chemistVM.Common.ContactPersonDateOfBirth.Value); commonVM.ContactPersonDateOfAnniversary = Utilities.FormatDateTimeByZone(chemistVM.Common.ContactPersonDateOfAnniversary.Value); var chemCommon = mapper.Map <CommonResourceViewModel, Data.ChemistStockistResourse>(commonVM); _unitOfWork.CommonResourse.Add(chemCommon); //Add Contact ContactResourseViewModel contactVM = chemistVM.Contact; contactVM.ID = Guid.NewGuid().ToString(); contactVM.RefTableId = chemistTableID; contactVM.Area = contactVM.Area; contactVM.EmailId = contactVM.EmailId; var chemContact = mapper.Map <ContactResourseViewModel, Data.ContactResourse>(contactVM); _unitOfWork.ContactResource.Add(chemContact); //Add Auditable Entity AuditableEntityViewModel auditVM = chemistVM.AuditableEntity; auditVM.ID = Guid.NewGuid().ToString(); auditVM.RefTableId = chemistTableID; auditVM.CreateDate = DateTime.Now; if (chemistVM.AuditableEntity.FoundationDay != null) { auditVM.FoundationDay = Utilities.FormatDateTimeByZone(chemistVM.AuditableEntity.FoundationDay.Value); } else { auditVM.FoundationDay = null; } var chemAudit = mapper.Map <AuditableEntityViewModel, Data.AuditableEntity>(auditVM); _unitOfWork.AuditableEntity.Add(chemAudit); await _unitOfWork.CompleteAsync(); } catch (Exception Ex) { return(new BadRequestObjectResult(Errors.AddError(Ex, ModelState))); } return(new OkObjectResult(chemistVM)); }
AST.ClassLiteralExp CreateClassLiteral(IToken rootToken, List <VariableDeclarationBag> vars, List <IToken> tokenPath) { Classifier createdClass = ResolveTypePathName(tokenPath); if (createdClass == null || createdClass == Library.Invalid) { Errors.AddError(new CodeErrorItem(String.Format("Unable to create type '{0}'.", tokenPath.ConcatWithSeparator(@"::")), rootToken, rootToken)); } Dictionary <string, AST.TupleLiteralPart> parts = new Dictionary <string, AST.TupleLiteralPart>(); List <Property> classParts = new List <Property>(); foreach (var var in vars) { if (parts.ContainsKey(var.Name)) { Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_CreateTupleLiteral_Name_repeated_1, var.Name), rootToken, rootToken)); continue; } AST.OclExpression expr = var.Expression; if (var.Expression == null) { expr = new AST.ErrorExp(Library.Invalid); } Classifier type = var.Type; if (type == null) { type = expr.Type; } if (expr.Type.ConformsTo(type) == false) { Errors.AddError(new ErrorItem(CompilerErrors.OCLAst_CreateTupleLiteral_Type_does_not_comform_to_declared_type)); } //hodnota var newProterty = new Property(var.Name, PropertyType.One, type); var newPart = new AST.TupleLiteralPart(newProterty, expr); parts.Add(var.Name, newPart); //typ classParts.Add(newProterty); } return(new AST.ClassLiteralExp(parts, createdClass) .SetCodeSource(new CodeSource(rootToken))); }
AST.OclExpression ProcessOperationCall(AST.OclExpression expr, List <IToken> tokenPath, bool isPre, List <AST.OclExpression> args) { if (TestNull(expr, tokenPath)) { return(new AST.ErrorExp(Library.Invalid)); } // v pripade ze funkce ma nula argumentu neprovedese vytvoreni prazdneho listu v gramatice if (args == null) { args = new List <AST.OclExpression>(); } List <string> path = tokenPath.ToStringList(); if (path.Count == 1) { if (expr.Type is CollectionType) { //25b Classifier sourceType = ((CollectionType)expr.Type).ElementType; Operation op = sourceType.LookupOperation(path[0], args.Select(arg => arg.Type)); if (op != null) { return(CreateImplicitCollectIterator(expr, tokenPath[0], args, sourceType, op)); } } // JM 2.5. 2012 if (expr is AST.TypeExp) { Operation op = (((AST.TypeExp)expr).ReferredType).LookupOperation(path[0], args.Select(arg => arg.Type)); if (op != null) { return(new AST.OperationCallExp(expr, isPre, op, args, Environment) .SetCodeSource(new CodeSource(tokenPath[0]))); } } else { //35eg IEnumerable <Classifier> parameterTypes = args.Select(arg => arg.Type); Operation op = expr.Type.LookupOperation(path[0], parameterTypes); if (op != null) { return(new AST.OperationCallExp(expr, isPre, op, args, Environment) .SetCodeSource(new CodeSource(tokenPath[0]))); } } } Errors.AddError(new CodeErrorItem(string.Format(CompilerErrors.OCLAst_ProcessOperationCall_OperationNotExists_1, path.First()), tokenPath.First(), tokenPath.Last())); return(new AST.ErrorExp(Library.Invalid)); }
public async Task <IActionResult> DeleteHoliday(int ID) { try { var holidayData = _unitOfWork.Holiday.GetSingleOrDefault(h => h.Id == ID); if (holidayData != null) { _unitOfWork.Holiday.Remove(holidayData); await _unitOfWork.CompleteAsync(); } return(Ok(holidayData)); } catch (Exception Ex) { return(new BadRequestObjectResult(Errors.AddError(Ex, ModelState))); } }
public async Task <IActionResult> UploadPhoto(string userID, IFormFile formFile) { //Fetch User var userData = _unitOfWork.Employee.GetSingleOrDefault(u => u.Id == userID); try { if (formFile.Length > MAX_BYTES) { return(BadRequest(Errors.AddError("Max file size is 2 MB", ModelState))); } if (!ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(formFile.FileName))) { return(BadRequest(Errors.AddError("Only *.jpg,*.jpeg & *.png type files are allowed", ModelState))); } //UploadFile if (userData != null) { var uploadFolderPath = Path.Combine(_host.WebRootPath, "Uploads"); if (!Directory.Exists(uploadFolderPath)) { Directory.CreateDirectory(uploadFolderPath); } var fileName = userData.UserName + "_" + Guid.NewGuid().ToString("N") + Path.GetExtension(formFile.FileName); var filePath = Path.Combine(uploadFolderPath, fileName); using (var stream = new FileStream(filePath, FileMode.Create)) { await formFile.CopyToAsync(stream); } //Update URL to User userData.PictureUrl = $"/Uploads/{ fileName}"; _unitOfWork.Employee.Update(userData); await _unitOfWork.CompleteAsync(); } } catch (Exception Ex) { return(new BadRequestObjectResult(Errors.AddError(Ex, ModelState))); } return(Ok(userData)); }
AST.OclExpression ProcessCollectionOperationCall(AST.OclExpression expr, List <IToken> tokenPath, List <AST.OclExpression> args) { if (TestNull(expr, tokenPath)) { return(new AST.ErrorExp(Library.Invalid)); } // v pripade ze funkce ma nula argumentu neprovedese vytvoreni prazdneho listu v gramatice if (args == null) { args = new List <AST.OclExpression>(); } List <string> path = tokenPath.ToStringList(); if (path.Count != 1) { Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_ProcessIteratorCall_Unknow_iterator_operation, tokenPath.First(), tokenPath.Last())); return(new AST.ErrorExp(Library.Invalid)); } string name = path[0]; // apply oclAsSet opretion on not collect type if (expr.Type is CollectionType == false) { Operation asSetOp = expr.Type.LookupOperation(Library.OclAsSet, new Classifier[0]); if (asSetOp == null) { Errors.AddError(new ErrorItem(String.Format(CompilerErrors.OCLParser_OperationNotFound_1, Library.OclAsSet))); return(new AST.ErrorExp(Library.Invalid)); } expr = new AST.OperationCallExp(expr, false, asSetOp, new List <AST.OclExpression>(), Environment) .SetCodeSource(new CodeSource(tokenPath[0])); } Operation collectionOperation = expr.Type.LookupOperation(name, args.Select(arg => arg.Type)); if (collectionOperation != null) // 36b { return(new AST.OperationCallExp(expr, false, collectionOperation, args, Environment) .SetCodeSource(new CodeSource(tokenPath[0]))); } Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_ProcessCollectionOperationCall_Unknown_collection_operation, name), tokenPath.First(), tokenPath.Last())); return(new AST.ErrorExp(Library.Invalid)); }
AST.OclExpression UnaryOperation(IToken name, AST.OclExpression exp1) { if (TestNull(name, exp1)) { return(new AST.ErrorExp(Library.Invalid)); } Operation op = exp1.Type.LookupOperation(name.Text, new Classifier[] { }); if (op == null) { Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_InfixOperation_NotDefined_2, exp1.Type, name), name, name)); return(new AST.ErrorExp(Library.Any)); } return(new AST.OperationCallExp(exp1, false, op, new List <AST.OclExpression>(new AST.OclExpression[] { }), Environment) .SetCodeSource(new CodeSource(name))); }
void ResolveVersion(string versionName) { Schema targetSchema = this.Bridge.Schema; VersionManager versionManager = this.Bridge.Schema.Project.VersionManager; Version sourceVersion = versionManager.Versions.SingleOrDefault(v => v.Label == versionName); if (sourceVersion == null) { Errors.AddError(new ErrorItem(string.Format("Source version `{0}` not found in the project.", versionName))); } SourceVersion = sourceVersion; if (!targetSchema.ExistsInVersion(sourceVersion)) { Errors.AddError(new ErrorItem(string.Format("Schema '{0}' does not exist in version `{1}`.", targetSchema, versionName))); } Schema sourceSchema = targetSchema.GetInVersion(sourceVersion); this.Bridge.TranslateSchema(sourceSchema, true); foreach (Component componentT in targetSchema.SchemaComponents) { if (componentT.ExistsInVersion(SourceVersion) && (componentT is PIMClass || componentT is PSMClass || componentT is PSMContentModel)) { Component componentS = componentT.GetInVersion(SourceVersion); { Classifier classifierT = Bridge.Find(componentT); Classifier classifierS = Bridge.Find(componentS); Operation prevOp = new Operation(@"prev", true, classifierS); prevOp.Tag = new PrevOperationTag() { SourceVersionClassifier = classifierS, TargetVersionClassifier = classifierT }; classifierT.Operations.Add(prevOp); Operation nextOp = new Operation(@"next", true, classifierT); nextOp.Tag = new NextOperationTag() { SourceVersionClassifier = classifierS, TargetVersionClassifier = classifierT }; classifierS.Operations.Add(nextOp); } } } }