示例#1
0
        public void RegisterSession(RegisterSessionRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request", "No request object provided.");
            }
            if (request.Session == null)
            {
                throw new ArgumentException("No session object in request was provided. Need object '{ \"Session\":{...} }' in root.");
            }
            if (request.Session.SessionGuid == Guid.Empty)
            {
                throw new ArgumentException("No valid session guid provided.");
            }
            if (string.IsNullOrEmpty(request.Session.ClientToken))
            {
                throw new ArgumentException("No ClientToken provided.");
            }
            if (request.Session.Application == null)
            {
                throw new ArgumentException("No application object in request was provided. Need object '{ \"Application\":{...} }' in session.");
            }
            if (string.IsNullOrEmpty(request.Session.Application.Name))
            {
                throw new ArgumentException("No name provided for application.");
            }
            if (request.Session.User == null)
            {
                throw new ArgumentException("No user object in request was provided. Need object '{ \"User\":{...} }' in session.");
            }
            if (request.Session.Machine == null)
            {
                throw new ArgumentException("No machine object in request was provided. Need object '{ \"Machine\":{...} }' in session.");
            }

            var callerIp = _membershipAgent.GetUserHostAddress();

            var fingerprint = _applicationVersionBusiness.AssureApplicationFingerprint(request.Session.Application.Fingerprint, request.Session.Application.Version, request.Session.Application.SupportToolkitNameVersion, request.Session.Application.BuildTime, request.Session.Application.Name, request.Session.ClientToken);

            IApplication application;

            try
            {
                application = _initiativeBusiness.RegisterApplication((ClientToken)request.Session.ClientToken, request.Session.Application.Name, request.Session.Application.Fingerprint);
            }
            catch (FingerprintException)
            {
                throw new ArgumentException("No value for application fingerprint provided. A globally unique identifier should be provided, perhaps a machine sid or a hash of unique data that does not change.");
            }

            var applicationVersion = _applicationVersionBusiness.RegisterApplicationVersionUsage(fingerprint, application.Id, request.Session.Application.Version, request.Session.Application.SupportToolkitNameVersion, request.Session.Application.BuildTime, request.Session.Environment);

            if (applicationVersion.Ignore)
            {
                return;
            }

            try
            {
                _userBusiness.RegisterUser((Fingerprint)request.Session.User.Fingerprint, request.Session.User.UserName);
            }
            catch (FingerprintException)
            {
                throw new ArgumentException("No value for user fingerprint provided. A globally unique identifier should be provided, perhaps a username and domain or a hash of unique data that does not change.");
            }

            try
            {
                _machineBusiness.RegisterMachine((Fingerprint)request.Session.Machine.Fingerprint, request.Session.Machine.Name, request.Session.Machine.Data);
            }
            catch (FingerprintException)
            {
                throw new ArgumentException("No value for machine fingerprint provided. A globally unique identifier should be provided, perhaps a DeviceId, SID or a hash of unique data that does not change.");
            }

            RegisterSession(request.Session.ToSession(applicationVersion.Id, application.Id, DateTime.UtcNow, null, null, callerIp));
        }
示例#2
0
        public RegisterIssueResponse RegisterIssue(RegisterIssueRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request", "No request object provided.");
            }
            if (request.Session == null)
            {
                throw new ArgumentException("No session object in request was provided. Need object '{ \"Session\":{...} }' in root.");
            }
            if (request.Session.SessionGuid == Guid.Empty)
            {
                throw new ArgumentException("No valid session guid provided.");
            }
            if (string.IsNullOrEmpty(request.Session.ClientToken))
            {
                throw new ArgumentException("No ClientToken provided.");
            }
            if (request.IssueType == null)
            {
                throw new ArgumentException("No IssueType object in request was provided. Need object '{ \"IssueType\":{...} }' in root.");
            }
            if (string.IsNullOrEmpty(request.IssueType.Message))
            {
                throw new ArgumentException("No message in issue type provided.");
            }
            if (string.IsNullOrEmpty(request.IssueType.IssueLevel))
            {
                throw new ArgumentException("No issue level in issue type provided.");
            }

            var callerIp = _membershipAgent.GetUserHostAddress();

            ISession session = null;

            if (request.Session.Application == null)
            {
                session = GetSession(request.Session.SessionGuid);
                if (session == null)
                {
                    throw new ArgumentException("Cannot find session with provided session id.").AddData("SessionGuid", request.Session.SessionGuid);
                }
            }

            var ad = GetApplicationData(request, session);

            var fingerprint = _applicationVersionBusiness.AssureApplicationFingerprint(ad.Fingerprint, ad.Version, ad.SupportToolkitNameVersion, ad.BuildTime, ad.Name, request.Session.ClientToken);

            IApplication application;

            try
            {
                application = _initiativeBusiness.RegisterApplication((ClientToken)request.Session.ClientToken, ad.Name, ad.Fingerprint);
            }
            catch (FingerprintException)
            {
                throw new ArgumentException("No value for application fingerprint provided. A globally unique identifier should be provided, perhaps a machine sid or a hash of unique data that does not change.");
            }

            var applicationVersion = _applicationVersionBusiness.RegisterApplicationVersionUsage(fingerprint, application.Id, ad.Version, ad.SupportToolkitNameVersion, ad.BuildTime, request.Session.Environment);

            if (applicationVersion.Ignore)
            {
                return(new RegisterIssueResponse {
                    IssueTypeTicket = null, IssueInstanceTicket = null, ResponseMessage = applicationVersion.ResponseMessage, IsOfficial = applicationVersion.IsOfficial,
                });
            }

            if (session == null)
            {
                if (request.Session.User.Fingerprint == null)
                {
                    throw new ArgumentException("No user fingerprint provided.");
                }
                session = request.Session.ToSession(applicationVersion.Id, application.Id, DateTime.UtcNow, null, null, callerIp);
            }

            _sessionBusiness.RegisterSession(session);

            var ud = GetUserData(request, session);

            _userBusiness.RegisterUser((Fingerprint)session.UserFingerprint, ud.UserName);

            var md = GetMachineData(request, session);

            _machineBusiness.RegisterMachine((Fingerprint)md.Fingerprint, md.Name, md.Data);

            int    issueTypeTicket;
            int    issueTicket;
            string issueTypeResponseMessage;

            var mutex = new Mutex(false, application.Id.ToString());

            try
            {
                mutex.WaitOne();

                var applicationVersions = _applicationVersionBusiness.GetApplicationVersions(application.Id).ToArray();

                var issueType = applicationVersion.IssueTypes.FirstOrDefault(x => request.IssueType.AreEqual(x));
                if (issueType == null)
                {
                    var issueTypes          = applicationVersions.SelectMany(x => x.IssueTypes).ToArray();
                    var lastIssueTypeTicket = issueTypes.Any() ? issueTypes.Max(x => x.Ticket) : 0;
                    issueTypeTicket = lastIssueTypeTicket + 1;
                    var inner = ToInnerIssueType(request.IssueType.Inner);

                    issueType = new Quilt4.BusinessEntities.IssueType(request.IssueType.ExceptionTypeName, request.IssueType.Message, request.IssueType.StackTrace ?? string.Empty, request.IssueType.IssueLevel.ToIssueLevel(), inner, new List <IIssue>(), issueTypeTicket, null);
                    applicationVersion.Add(issueType);
                }
                else
                {
                    issueTypeTicket = issueType.Ticket;
                }

                issueTypeResponseMessage = issueType.ResponseMessage;

                var issues          = applicationVersions.SelectMany(x => x.IssueTypes).SelectMany(x => x.Issues).ToArray();
                var lastIssueTicket = issues.Any() ? issues.Max(x => x.Ticket) : 0;
                issueTicket = lastIssueTicket + 1;

                var issue = new Issue(request.Id, request.ClientTime, DateTime.UtcNow, request.VisibleToUser, request.Data, request.IssueThreadGuid, request.UserHandle, request.UserInput, issueTicket, session.Id);
                issueType.Add(issue);

                UpdateApplicationVersion(applicationVersion);
            }
            finally
            {
                mutex.ReleaseMutex();
            }

            var response = new RegisterIssueResponse
            {
                IssueTypeTicket     = application.TicketPrefix + _settingsBusiness.GetIssueTypeTicketPrefix() + issueTypeTicket,
                IssueInstanceTicket = application.TicketPrefix + _settingsBusiness.GetIssueTicketPrefix() + issueTicket,
                ResponseMessage     = applicationVersion.ResponseMessage ?? issueTypeResponseMessage,
                IsOfficial          = applicationVersion.IsOfficial
            };

            return(response);
        }