/// <summary>
        /// Handles exceptions based upon the indicated behavior and rethrows the Exception
        /// </summary>
        /// <param name="exception"></param>
        /// <param name="exceptionBehavior"></param>
        /// <param name="log"></param>
        /// <param name="msg"></param>
        /// <param name="parameters"></param>
        public static void Handle(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
                                  string msg = "", params object[] parameters)
        {
            var caller = GetCaller();

            if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
            {
                ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);

                if (string.IsNullOrEmpty(msg))
                {
                    logger.Error(exception);
                }
                else
                {
                    logger.Error(String.Format(msg, parameters), exception);
                }
            }

            if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow ||
                exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
            {
                throw exception;
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        public object ExecuteScalar(IDbConnection connection, string storedProcedureName,
                                    List <IDataParameter> parameters, string errorMessage = "")
        {
            ValidateArguments(connection, storedProcedureName);

            object result = null;

            try
            {
                using (var cmd = connection.CreateCommand())
                {
                    SetupDbCommand(connection, cmd, storedProcedureName, parameters);

                    cmd.Connection.Open();
                    result = cmd.ExecuteScalar();
                }
            }
            catch (DbException ex)
            {
                _log.Error(string.IsNullOrEmpty(errorMessage)
                              ? $"{storedProcedureName} threw an Exception: {ex.Message}"
                    : errorMessage, ex);
            }
            finally
            {
                connection?.Dispose();
            }

            return(result);
        }
        public virtual Emotion[] Recognize(Stream stream)
        {
            try {
                var result = Task.Run(async() => await EmotionRepository.RecognizeAsync(stream)).Result;

                return(result);
            } catch (Exception ex) {
                Logger.Error("SentimentService.GetSentiment failed", this, ex);
            }

            return(null);
        }
        public virtual SpeechToTextResponse SpeechToText(Stream audioStream, ScenarioOptions scenario, BingSpeechLocaleOptions locale, SpeechOsOptions os, Guid fromDeviceId, int maxnbest = 1, int profanitycheck = 1)
        {
            try {
                var result = SpeechRepository.SpeechToText(audioStream, scenario, locale, os, fromDeviceId, maxnbest, profanitycheck);

                return(result);
            } catch (Exception ex) {
                Logger.Error("SpeechService.SpeechToText failed", this, ex);
            }

            return(null);
        }
Example #5
0
        public virtual LanguageResponse GetLanguages(LanguageRequest request)
        {
            try {
                var result = TextAnalyticsRepository.GetLanguages(request);

                return(result);
            } catch (Exception ex) {
                Logger.Error("LanguageService.GetLanguages failed", this, ex);
            }

            return(null);
        }
Example #6
0
        public virtual NewsSearchCategoryResponse CategorySearch(NewsCategoryOptions category)
        {
            try {
                var result = Task.Run(async() => await NewsSearchRepository.CategorySearchAsync(category)).Result;

                return(result);
            } catch (Exception ex) {
                Logger.Error("AutoSuggestService.CategorySearch failed", this, ex);
            }

            return(null);
        }
Example #7
0
        public virtual Emotion[] Recognize(Stream stream)
        {
            try {
                var result = EmotionRepository.Recognize(stream);

                return(result);
            } catch (Exception ex) {
                Logger.Error("EmotionService.Recognize failed", this, ex);
            }

            return(null);
        }
        public VideoSearchResponse VideoSearch(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off)
        {
            try {
                var result = VideoSearchRepository.VideoSearch(text, countOffset, languageCode, safeSearch);

                return(result);
            } catch (Exception ex) {
                Logger.Error("VideoSearchService.VideoSearch failed", this, ex);
            }

            return(null);
        }
Example #9
0
        public virtual POSTagsTextAnalysisResponse GetPOSTagsTextAnalysis(TextAnalysisRequest request)
        {
            try {
                var result = LinguisticRepository.GetPOSTagsTextAnalysis(request);

                return(result);
            } catch (Exception ex) {
                Logger.Error("LinguisticService.GetPOSTagsTextAnalysis failed", this, ex);
            }

            return(null);
        }
        public virtual async Task <VideoOperation> FaceDetectionAndTrackingAsync(string videoUrl)
        {
            try {
                var result = await VideoRepository.FaceDetectionAndTrackingAsync(videoUrl);

                return(result);
            } catch (Exception ex) {
                Logger.Error("VideoService.FaceDetectionAndTrackingAsync failed", this, ex);
            }

            return(null);
        }
        public virtual POSTagsTextAnalysisResponse GetPOSTagsTextAnalysis(TextAnalysisRequest request)
        {
            try {
                var result = Task.Run(async() => await LinguisticRepository.GetPOSTagsTextAnalysisAsync(request)).Result;

                return(result);
            } catch (Exception ex) {
                Logger.Error("SentimentService.GetSentiment failed", this, ex);
            }

            return(null);
        }
        public OperationResult <List <DataSource> > GetAllFinancialDataSources(string url)
        {
            try
            {
                var web = new HtmlWeb {
                    AutoDetectEncoding = false, OverrideEncoding = Encoding.UTF8,
                };
                var doc = web.Load(url);

                var node = doc.GetElementbyId("Financial-Data");

                if (node != null)
                {
                    var table = node.NextSibling.NextSibling.ChildNodes.Nodes();
                    var list  = new List <DataSource>();

                    foreach (var row in table)
                    {
                        if (row.Name == "tr" && row.ParentNode.Name != "thead")
                        {
                            var dataSource = new DataSource();

                            var splitted = row.InnerText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                            dataSource.Name        = splitted[0];
                            dataSource.Count       = Convert.ToInt32(splitted[1].Replace(",", ""));
                            dataSource.Description = splitted[2];
                            dataSource.Code        = splitted[4];

                            list.Add(dataSource);
                        }
                    }

                    if (list.Any())
                    {
                        return(new OperationResult <List <DataSource> >(list));
                    }
                    else
                    {
                        return(new OperationResult <List <DataSource> >(false, "No data found"));
                    }
                }
                else
                {
                    return(new OperationResult <List <DataSource> >(false, "Can't load data sources list from web site"));
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                throw new QuandlProviderException(ex.Message, ex);
            }
        }
        public async Task <ModelSummary> Get(Guid id)
        {
            try
            {
                var result = await ModelRepository.Get(id);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("ModelService.Get failed", this, ex);
            }

            return(null);
        }
        public async Task <ViewDefinitionList> List(ViewQuery viewQuery = null)
        {
            try
            {
                var result = await ViewRepository.List(viewQuery);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("ViewService.List failed", this, ex);
            }

            return(null);
        }
        public ToneAnalysis Tone(ToneInput toneInput, string contentType, bool?sentences = null, List <string> tones = null, string contentLanguage = null, string acceptLanguage = null)
        {
            try
            {
                var result = ToneAnalyzerRepository.Tone(toneInput, contentType, sentences, tones, contentLanguage, acceptLanguage);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("ToneAnalyzerService.Tone failed", this, ex);
            }

            return(null);
        }
        public virtual Operation CreateOperation(Stream video, VideoOperationSettings operationSettings)
        {
            try
            {
                var result = Task.Run(async() => await VideoRepository.CreateOperationAsync(video, operationSettings)).Result;

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("VideoService.CreateOperation failed", this, ex);
            }

            return(null);
        }
Example #17
0
        public virtual List <QueryItem> GetQueries(string configId = null)
        {
            try
            {
                var result = QueryRepository.GetQueries(configId);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("QueryRepository.GetQueries failed", this, ex);
            }

            return(null);
        }
Example #18
0
        public virtual int SendCollection(CollectionRequest collection, string configId = null, string jobId = null)
        {
            try
            {
                var result = CollectionRepository.SendCollection(collection, configId, jobId);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("CollectionRepository.SendCollection failed", this, ex);
            }

            return(-1);
        }
        public virtual List <SentimentPhraseItem> GetSentimentPhrases(string configId = null)
        {
            try
            {
                var result = SentimentPhraseRepository.GetSentimentPhrases(configId);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("SentimentPhraseRepository.GetSentimentPhrases failed", this, ex);
            }

            return(null);
        }
        public virtual ClassifyTopLevelMultiple Classify(string url, string[] classifierIDs = null, string[] owners = null, float threshold = 0, string acceptLanguage = "en")
        {
            try
            {
                var result = VisualRecognitionRepository.Classify(url, classifierIDs, owners, threshold, acceptLanguage);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("VisualRecognitionService.Classify failed", this, ex);
            }

            return(null);
        }
Example #21
0
        public virtual HistogramResult CalcHistogram(string expression, AcademicModelOptions model, string attributes = "", int count = 10, int offset = 0)
        {
            try
            {
                var result = Task.Run(async() => await AcademicSearchRepository.CalcHistogramAsync(expression, model, attributes, count, offset)).Result;

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("AcademicSearchService.CalcHistogram failed", this, ex);
            }

            return(null);
        }
Example #22
0
        public async Task <ImportDetailList> List(ImportDetailQuery query = null)
        {
            try
            {
                var result = await ImportRepository.List(query);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("AccountService.GetAccountBalance failed", this, ex);
            }

            return(null);
        }
Example #23
0
        public virtual BreakIntoWordsResponse BreakIntoWords(WebLMModelOptions model, string text, int order = 5, int maxNumOfCandidatesReturned = 5)
        {
            try
            {
                var result = Task.Run(async() => await WebLanguageModelRepository.BreakIntoWordsAsync(model, text, order, maxNumOfCandidatesReturned)).Result;

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("WebLanguageModelService.BreakIntoWords failed", this, ex);
            }

            return(null);
        }
Example #24
0
        public virtual ClassifyResponse Classify(string classifier_id, string text)
        {
            try
            {
                var result = NaturalLanguageClassifierRepository.Classify(classifier_id, text);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("NaturalLanguageClassifierService.Classify failed", this, ex);
            }

            return(null);
        }
        public virtual Face[] Detect(Stream stream, bool returnFaceId = true, bool returnFaceLandmarks = false, IEnumerable <FaceAttributeType> returnFaceAttributes = null)
        {
            try
            {
                var result = FaceRepository.Detect(stream, returnFaceId, returnFaceLandmarks, returnFaceAttributes);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("FaceService.Detect failed", this, ex);
            }

            return(null);
        }
Example #26
0
        public virtual Task <ContestResponse> GetContest(Guid sessionId)
        {
            try
            {
                var result = ContestRepository.GetContest(sessionId);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("ContestService.GetContest failed", this, ex);
            }

            return(null);
        }
        public virtual int SendDocument(DocumentRequest doc, string configId = null)
        {
            try
            {
                var result = DocumentRepository.SendDocument(doc, configId);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("DocumentRepository.SendDocument failed", this, ex);
            }

            return(-1);
        }
Example #28
0
        public virtual List <ServiceStatus> GetStatus()
        {
            try
            {
                var result = AccountRepository.GetStatus();

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("AccountService.GetStatus failed", this, ex);
            }

            return(null);
        }
        public virtual List <BlacklistItem> ListBlacklist(string configId = null)
        {
            try
            {
                var result = BlacklistRepository.ListBlacklist(configId);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("BlacklistService.ListBlacklist failed", this, ex);
            }

            return(null);
        }
        public virtual List <ConfigurationDefinition> ListConfigurations()
        {
            try
            {
                var result = ConfigurationRepository.ListConfigurations();

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("ConfigurationRepository.ListConfigurations failed", this, ex);
            }

            return(null);
        }