public void UpdateEvaluation(Evaluation evaluation) { ServiceErrorHandler.Handle(() => { Log.Info(string.Format("Attempting to update evaluation with ID {0}", evaluation.Id)); var dao = this.evaluationDaoBuilder.Create(); var id = evaluation.Id; if (!dao.EvaluationExists(id)) { throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {id}"); } if (evaluation.CreationDate != null) { throw new InvalidItemServiceException("Bad arguments, cannot update existing evaluation Creation Date"); } else if (evaluation.EditDate != null) { throw new InvalidItemServiceException("Bad arguments, cannot update existing evaluation Edit Date"); } evaluation.EditDate = DateTime.Now.ToUniversalTime(); dao.UpdateEvaluation(evaluation); }); }
public EvaluationScore CreateAnswers(Guid idEvaluation, EvaluationAnswer answersList) { return(ServiceErrorHandler.Handle(() => { Log.Info($"Checking if evaluation with id {idEvaluation} exists"); var answersDao = this.answersDaoBuilder.Create(); var evaluationsDao = this.evaluationsDaoBuilder.Create(); var templatesDao = this.templatesDaoBuilder.Create(); if (!evaluationsDao.EvaluationExists(idEvaluation)) { throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {idEvaluation}"); } var evaluation = evaluationsDao.GetEvaluation(idEvaluation); var template = templatesDao.GetTemplate(evaluation.IdTemplate); var evaluationTemplate = EvaluationScoreHelpers.GenerateEvaluationTemplate(template, evaluation); evaluationTemplate.AppendAnswers(answersList); var scoreService = ServicesFacade.Instance.GetScoreService(); var caluculatedEvaluation = scoreService.CalculateScore(evaluationTemplate); Log.Info($"Creating answers for evaluation {idEvaluation}"); caluculatedEvaluation.IdEvaluation = idEvaluation; caluculatedEvaluation.Date = DateTime.Now.ToUniversalTime(); EvaluationScore newAnswers = answersDao.CreateAnswers(caluculatedEvaluation); Log.Info($"Evaluation answers created succesfully, Id {newAnswers.Id}"); return newAnswers; })); }
// Creates the services protected virtual IEnumerable <ServiceHost> CreateServersCore( List <Type> serviceImplTypes, Func <Type, string> serviceNameResolver, Func <Type, Type> contractTypeResolver, string serviceBaseNS, int port, Action <object, Exception> errorHandler, Action <string> errorLogger = null, Action <string> warningLogger = null, Action <string> infoLogger = null, bool autoHost = true) { var eh = new ServiceErrorHandler(errorHandler); foreach (var serviceImplType in serviceImplTypes) { var contractType = contractTypeResolver(serviceImplType); var serviceName = serviceNameResolver(serviceImplType); var host = HostService( serviceImplType, serviceName, contractType, serviceBaseNS, port, eh, errorHandler, errorLogger, warningLogger, infoLogger, autoHost); yield return(host); } }
// Creates the host protected virtual ServiceHost CreateHost( Type serviceImplType, Uri uri, ServiceErrorHandler eh) { return(new ServiceHost(serviceImplType, uri)); }
// Hosts service protected virtual ServiceHost HostService( Type serviceImplType, string serviceName, Type contractType, string serviceBaseNS, int port, ServiceErrorHandler eh, Action <object, Exception> errorHandler, Action <string> errorLogger = null, Action <string> warningLogger = null, Action <string> infoLogger = null, bool autoHost = true) { var uri = CreateEndpointUri(serviceName, serviceBaseNS, Environment.MachineName, port); var host = CreateHost(serviceImplType, uri, eh); var binding = CreateBinding(); host.AddServiceEndpoint(contractType, binding, uri); if (autoHost) { try { host.Open(); host.Faulted += (sender, e) => { if (errorHandler != null) { errorHandler(host, null); } }; } catch (AddressAccessDeniedException aade) { var msgText = string.Format("{1}\r\n{0} ", aade.Message, "The process doesn't have privilege to register WCF service namespaces."); errorLogger(msgText); Console.WriteLine(msgText); throw; } catch (Exception ex) { var msgText = "Failed to host service " + ": " + host.Description.Name; msgText += Environment.NewLine + ex.Message; errorLogger(msgText); Console.WriteLine(msgText); throw; } } return(host); }
public PaginatedList <Evaluation> GetEvaluations(QueryParameters queryParameters) { return(ServiceErrorHandler.Handle(() => { Log.Info("Getting the paginated evaluations"); var dao = this.evaluationDaoBuilder.Create(); return dao.GetEvaluations(queryParameters); })); }
public IList <Evaluation> GetEvaluations() { return(ServiceErrorHandler.Handle(() => { Log.Info("Getting the evaluations"); var dao = this.evaluationDaoBuilder.Create(); return dao.GetEvaluations(); })); }
public void UpdateTemplate(Template template) { ServiceErrorHandler.Handle(() => { Log.Info(string.Format("Attemping to update template with ID {0}", template.Id)); var dao = this.templateDaoBuilder.Create(); dao.UpdateTemplate(template); }); }
public void DeleteTemplate(Guid id) { ServiceErrorHandler.Handle(() => { Log.Info(string.Format("Attempting to delete Template with ID: {0}", id)); var dao = this.templateDaoBuilder.Create(); dao.DeleteTemplate(id); }); }
public Template GetTemplate(Guid id) { return(ServiceErrorHandler.Handle(() => { var dao = this.templateDaoBuilder.Create(); var template = dao.GetTemplate(id); Log.Info(string.Format("Template found with id: {0}", template.Id)); return template; })); }
public IList <Template> GetTemplates() { return(ServiceErrorHandler.Handle(() => { var dao = this.templateDaoBuilder.Create(); var templatelist = dao.GetTemplates(); Log.Info(string.Format("Found {0} templates", templatelist.Count)); return templatelist; })); }
public EvaluationScore CalculateScore(EvaluationScore evaluationScore) { return(ServiceErrorHandler.Handle(() => { var calculator = new MathParserCalculator(evaluationScore); var calculated = calculator.Calculate(); this.CalculateQualification(calculated); return calculated; })); }
public IList <EvaluationScore> GetAnswers(Guid idEvaluation) { return(ServiceErrorHandler.Handle(() => { Log.Info(string.Format("Getting the list of answers for the evaluation with ID {0}", idEvaluation)); var dao = this.answersDaoBuilder.Create(); IList <EvaluationScore> evaluationAnswers = dao.GetAnswers(idEvaluation); Log.Info(string.Format("List of answers for evaluation : {0}", evaluationAnswers)); return evaluationAnswers; })); }
public Template CreateTemplate(Template template) { return(ServiceErrorHandler.Handle(() => { Log.Info("Creating the Template"); ITemplatesDao dao = this.templateDaoBuilder.Create(); Template newTemplate = dao.CreateTemplate(template); return newTemplate; })); }
public void DeleteEvaluation(Guid id) { ServiceErrorHandler.Handle(() => { Log.Info(string.Format("Attemping to delete Evaluation with ID {0}", id)); var dao = this.evaluationDaoBuilder.Create(); if (!dao.EvaluationExists(id)) { throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {id}"); } dao.DeleteEvaluation(id); }); }
public Evaluation GetEvaluation(Guid id) { return(ServiceErrorHandler.Handle(() => { Log.Info(string.Format("Getting the evaluation with ID {0}", id)); var dao = this.evaluationDaoBuilder.Create(); if (!dao.EvaluationExists(id)) { throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {id}"); } var evaluation = dao.GetEvaluation(id); Log.Info(string.Format("Evaluation: {0}", evaluation)); return evaluation; })); }
public EvaluationScore GetAnswer(Guid idAnswer) { return(ServiceErrorHandler.Handle(() => { Log.Info($"Getting answers with ID {idAnswer}"); var dao = this.answersDaoBuilder.Create(); if (!dao.AnswersExist(idAnswer)) { throw new ItemNotFoundServiceException($"Unable to find answers with id {idAnswer}"); } var evaluationAnswers = dao.GetAnswer(idAnswer); Log.Info($"Answers with ID {evaluationAnswers.Id} retrieved"); return evaluationAnswers; })); }
public ApplicationHealthInfo GetServiceHealth() { return(ServiceErrorHandler.Handle(() => { Log.Info("Getting the application health information"); var dao = this.appInfoDaoBuilder.CreateFromFile(ApplicationInfoFile); var appInfo = dao.GetAppInfo(); var info = new ApplicationHealthInfo() { Application = appInfo, Status = ApplicationHealthStatus.Up }; Log.Info(string.Format("ApplicationHealthInfo: {0}", info)); return info; })); }
public Evaluation CreateEvaluation(Evaluation evaluation) { return(ServiceErrorHandler.Handle(() => { Log.Info("Creating the Evaluation"); IEvaluationsDao dao = this.evaluationDaoBuilder.Create(); evaluation.CreationDate = DateTime.Now.ToUniversalTime(); evaluation.EditDate = DateTime.Now.ToUniversalTime(); var template = ServicesFacade.Instance.GetTemplatesService().GetTemplate(evaluation.IdTemplate); EvaluationValidator.Validate(evaluation, template); Evaluation newEvaluation = dao.CreateEvaluation(evaluation); Log.Info($"Evaluation Created Succesfully, Id {newEvaluation.Id}"); return newEvaluation; })); }
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { if (serviceDescription == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceDescription"); } if (serviceHostBase == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase"); } if (serviceDescription.Endpoints == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("serviceDescription", SR2.GetString(SR2.NoEndpoints)); } PersistenceProviderBehavior providerBehavior = null; if (serviceDescription.Behaviors != null) { providerBehavior = serviceDescription.Behaviors.Find <PersistenceProviderBehavior>(); } if (providerBehavior == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException( SR2.GetString( SR2.NonNullPersistenceProviderRequired, typeof(PersistenceProvider).Name, typeof(DurableServiceAttribute).Name))); } if (providerBehavior.PersistenceProviderFactory == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException( SR2.GetString( SR2.NonNullPersistenceProviderRequired, typeof(PersistenceProvider).Name, typeof(DurableServiceAttribute).Name))); } providerBehavior.PersistenceProviderFactory.Open(); serviceHostBase.Closed += new EventHandler( delegate(object sender, EventArgs args) { Fx.Assert(sender is ServiceHostBase, "The sender should be serviceHostBase."); // We have no way of knowing whether the service host closed or aborted // so we err on the side of abort for right now. providerBehavior.PersistenceProviderFactory.Abort(); } ); DurableInstanceContextProvider instanceContextProvider = new ServiceDurableInstanceContextProvider( serviceHostBase, false, serviceDescription.ServiceType, providerBehavior.PersistenceProviderFactory, this.saveStateInOperationTransaction, this.unknownExceptionAction, new DurableRuntimeValidator(this.saveStateInOperationTransaction, this.unknownExceptionAction), providerBehavior.PersistenceOperationTimeout); DurableInstanceContextProvider singleCallInstanceContextProvider = null; IInstanceProvider instanceProvider = new DurableInstanceProvider(instanceContextProvider); bool includeExceptionDetails = false; if (serviceDescription.Behaviors != null) { ServiceBehaviorAttribute serviceBehavior = serviceDescription.Behaviors.Find <ServiceBehaviorAttribute>(); if (serviceBehavior != null) { includeExceptionDetails |= serviceBehavior.IncludeExceptionDetailInFaults; } ServiceDebugBehavior serviceDebugBehavior = serviceDescription.Behaviors.Find <ServiceDebugBehavior>(); if (serviceDebugBehavior != null) { includeExceptionDetails |= serviceDebugBehavior.IncludeExceptionDetailInFaults; } } IErrorHandler errorHandler = new ServiceErrorHandler(includeExceptionDetails); foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers) { ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher; if (channelDispatcher != null && channelDispatcher.HasApplicationEndpoints()) { if (this.unknownExceptionAction == UnknownExceptionAction.AbortInstance) { channelDispatcher.ErrorHandlers.Add(errorHandler); } foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints) { if (endpointDispatcher.IsSystemEndpoint) { continue; } ServiceEndpoint serviceEndPoint = serviceDescription.Endpoints.Find(new XmlQualifiedName(endpointDispatcher.ContractName, endpointDispatcher.ContractNamespace)); if (serviceEndPoint != null) { if (serviceEndPoint.Contract.SessionMode != SessionMode.NotAllowed) { endpointDispatcher.DispatchRuntime.InstanceContextProvider = instanceContextProvider; } else { if (singleCallInstanceContextProvider == null) { singleCallInstanceContextProvider = new ServiceDurableInstanceContextProvider( serviceHostBase, true, serviceDescription.ServiceType, providerBehavior.PersistenceProviderFactory, this.saveStateInOperationTransaction, this.unknownExceptionAction, new DurableRuntimeValidator(this.saveStateInOperationTransaction, this.unknownExceptionAction), providerBehavior.PersistenceOperationTimeout); } endpointDispatcher.DispatchRuntime.InstanceContextProvider = singleCallInstanceContextProvider; } endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new DurableMessageDispatchInspector(serviceEndPoint.Contract.SessionMode)); endpointDispatcher.DispatchRuntime.InstanceProvider = instanceProvider; WorkflowServiceBehavior.SetContractFilterToIncludeAllOperations(endpointDispatcher, serviceEndPoint.Contract); } } } } foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints) { if (!endpoint.InternalIsSystemEndpoint(serviceDescription)) { foreach (OperationDescription opDescription in endpoint.Contract.Operations) { if (!opDescription.Behaviors.Contains(typeof(DurableOperationAttribute))) { opDescription.Behaviors.Add(DurableOperationAttribute.DefaultInstance); } } } } }