Exemplo n.º 1
0
        public IItJakubService GetMainServiceClient()
        {
            if (!IsUserLoggedIn())
            {
                return(m_communication.GetUnsecuredClient());
            }

            var username = GetUserName();
            var password = GetCommunicationToken();

            return(m_communication.GetAuthenticatedClient(username, password));
        }
Exemplo n.º 2
0
        private void ProcessFile(FileModel file, string username, string password, Action <string, Exception> callback)
        {
            var session = Guid.NewGuid().ToString();

            using (var client = m_communicationProvider.GetStreamingClientAuthenticated(username, password))
            {
                file.CurrentState = FileStateType.Uploading;
                using (var dataStream = GetDataStream(file.FullPath))
                {
                    try
                    {
                        var contract = new UploadResourceContract
                        {
                            FileName  = file.FileName,
                            Data      = dataStream,
                            SessionId = session
                        };

                        client.AddResource(contract);
                    }
                    catch (Exception)
                    {
                        file.CurrentState = FileStateType.Error;
                        return;
                        //throw;
                    }
                }
            }

            file.CurrentState = FileStateType.Processing;

            using (var client = m_communicationProvider.GetAuthenticatedClient(username, password))
            {
                try
                {
                    client.ProcessSession(session, DefaultUploadMessage);
                    file.CurrentState = FileStateType.Done;
                }
                catch (FaultException ex)
                {
                    file.ErrorMessage = ex.Message;
                    file.CurrentState = FileStateType.Error;
                    return;
                }
                catch (Exception)
                {
                    file.CurrentState = FileStateType.Error;
                    return;
                }
            }

            callback(file.FullPath, null);
        }
Exemplo n.º 3
0
        public override async Task <ClaimsPrincipal> CreateAsync(ApplicationUser user)
        {
            var principal = await base.CreateAsync(user);

            var claimsIdentity = (ClaimsIdentity)principal.Identity;

            claimsIdentity.AddClaim(new Claim(CustomClaimType.CommunicationToken, user.CommunicationToken));

            using (var authenticatedClient = m_communication.GetAuthenticatedClient(user.UserName, user.CommunicationToken))
            {
                var specialPermissions = authenticatedClient.GetSpecialPermissionsForUserByType(SpecialPermissionCategorizationEnumContract.Action);
                var roleClaims         = GetClaimsFromSpecialPermissions(specialPermissions);
                claimsIdentity.AddClaims(roleClaims);
            }

            return(principal);
        }