예제 #1
0
        public void Start(bool oneMessage = false)
        {
            object      tokenListLock           = new object();
            List <Task> tokenReceivedEventTasks = new List <Task>();
            bool        end = false;

            do
            {
                Token token = null;

                using (var pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.None))
                {
                    pipeServer.WaitForConnection();

                    token = Received(pipeServer);

                    pipeServer.Close();
                }

                if (token != null)
                {
                    end = token.End;
                    lock (tokenListLock)
                    {
                        tokenReceivedEventTasks.Add(Task.Run(() => TokenReceivedEvent?.Invoke(token)));
                    }
                }
            }while (!end && !oneMessage);

            Task.WaitAll(tokenReceivedEventTasks.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Request token to the entitlement and will use old token if it still valid.
        /// </summary>
        public void RequestToken()
        {
            if (DateTime.UtcNow < expiredDateTime)
            {
                TokenReceivedEvent.Invoke(this.Token);

                return;
            }

            entitlement.GetUserEntitlementOwnershipTokenOnly(this.itemIds, this.appIds, this.skus,
                                                             result =>
            {
                if (result == null || result.IsError)
                {
                    return;
                }

                this.Token = result.Value.ownershipToken;

                UpdateExpiration(this.Token);

                TokenReceivedEvent.Invoke(this.Token);
            });
        }