<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using JsonConfig;
using ServiceStack;
using MattermostCrmService.Wrappers;
using MattermostCrmService.Messages;

namespace MattermostCrmService
{
    public class CRMService : Service
    {
        private static Regex CASRegex = new Regex("\\b(CAS-[0-9]{5}-[A-Z][0-9][A-Z][0-9][A-Z][0-9])\\b");

        private CrmWrapper GetAuthenticatedCrmWrapper(AuthenticatedRequestBase request)
        {
            if (String.IsNullOrEmpty(request.AuthenticationToken))
                throw new ApplicationException("No Auth Token");
            var authInfo = LoginHelper.Instance.ParseToken(request.AuthenticationToken);
            return new CrmWrapper(authInfo.Username, authInfo.Password, Config.MergedConfig.CrmUrl); 
        }

        public IncidentWrapper Any(Incident request)
        {
            return CrmWrapper.Instance.GetIncident(request.CaseNum);
        }

        public string Post(Login request)
        {
            try
            {
                new CrmWrapper(request.Username, request.Password, Config.MergedConfig.CrmUrl);
                return LoginHelper.Instance.GenerateToken(request.Username, request.Password);
            }
            catch
            {
                throw new ApplicationException("Authentication Failure");
            }
        }

        public SlimIncidentWrapper[] Get(BasicIncidentQuery request)
        {
            return CrmWrapper.Instance.SearchIncidents(request.Query).ToArray();
        }

        public object Get(Users request)
        {
            return CrmWrapper.Instance.RunQuery("systemuser", "fullname", new[] {request.Query});
        }

        public object Get(Version request)
        {
            return CrmWrapper.Instance.Version;
        }

        public NoteWrapper Post(UpdateNote request)
        {
            var crm = GetAuthenticatedCrmWrapper(request);
            return crm.UpdateNote(request.NoteId, request.Title, request.Body);
        }

        public void Post(DeleteNote request)
        {
            var crm = GetAuthenticatedCrmWrapper(request);<commit_msg>comment out version<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using JsonConfig;
using ServiceStack;
using MattermostCrmService.Wrappers;
using MattermostCrmService.Messages;

namespace MattermostCrmService
{
    public class CRMService : Service
    {
        private static Regex CASRegex = new Regex("\\b(CAS-[0-9]{5}-[A-Z][0-9][A-Z][0-9][A-Z][0-9])\\b");

        private CrmWrapper GetAuthenticatedCrmWrapper(AuthenticatedRequestBase request)
        {
            if (String.IsNullOrEmpty(request.AuthenticationToken))
                throw new ApplicationException("No Auth Token");
            var authInfo = LoginHelper.Instance.ParseToken(request.AuthenticationToken);
            return new CrmWrapper(authInfo.Username, authInfo.Password, Config.MergedConfig.CrmUrl); 
        }

        public IncidentWrapper Any(Incident request)
        {
            return CrmWrapper.Instance.GetIncident(request.CaseNum);
        }

        public string Post(Login request)
        {
            try
            {
                new CrmWrapper(request.Username, request.Password, Config.MergedConfig.CrmUrl);
                return LoginHelper.Instance.GenerateToken(request.Username, request.Password);
            }
            catch
            {
                throw new ApplicationException("Authentication Failure");
            }
        }

        public SlimIncidentWrapper[] Get(BasicIncidentQuery request)
        {
            return CrmWrapper.Instance.SearchIncidents(request.Query).ToArray();
        }

        public object Get(Users request)
        {
            return CrmWrapper.Instance.RunQuery("systemuser", "fullname", new[] {request.Query});
        }

        /*
        public object Get(Version request)
        {
            return CrmWrapper.Instance.Version;
        }
        */

        public NoteWrapper Post(UpdateNote request)
        {
            var crm = GetAuthenticatedCrmWrapper(request);
            return crm.UpdateNote(request.NoteId, request.Title, request.Body);
        }

        public void Post(DeleteNote request)
        {
            var crm = GetAuthenticatedCrmWrapper(request);
{'fraction_non_alphanumeric': 0.09000900090009001, 'fraction_numerical': 0.004050405040504051, 'mean_word_length': 2.3295880149812733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5483713', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1146, 'n_words': 223}