Пример #1
0
 internal LinkNetwork(LinkClient client)
 {
     this.client = client;
     generator   = client.Generator;
     operation   = client.Operation;
     environment = client.Environment;
     Debug.Assert(generator != null);
     Debug.Assert(operation != null);
     Debug.Assert(environment != null);
 }
Пример #2
0
        public LinkClient(LinkSettings settings, TaskScheduler scheduler)
        {
            this.scheduler = scheduler;
            var environment = settings.Environment;

            CancellationToken = cancellation.Token;

            void changed(object sender, PropertyChangedEventArgs e)
            {
                Debug.Assert(sender == Profile);
                if (e.PropertyName == nameof(LinkProfile.Name))
                {
                    environment.ClientName = Profile.Name;
                }
                else if (e.PropertyName == nameof(LinkProfile.Text))
                {
                    environment.ClientText = Profile.Text;
                }
                else if (e.PropertyName == nameof(LinkProfile.ImageHash))
                {
                    environment.ClientImageHash = Profile.ImageHash;
                }
            }

            Settings    = settings;
            Environment = environment;
            Operation   = new LinkOperation(this);
            Network     = new LinkNetwork(this);
            Contracts   = new LinkContracts(this);
            Cache       = new LinkCache(this);

            var imageHash = environment.ClientImageHash;
            var imagePath = string.Empty;
            var exists    = !string.IsNullOrEmpty(imageHash) && Cache.Exists(imageHash, out imagePath);

            Profile = new LinkProfile(environment.ClientId, LinkProfileType.Client)
            {
                Name      = environment.ClientName,
                Text      = environment.ClientText,
                ImageHash = exists ? imageHash : string.Empty,
                ImagePath = exists ? imagePath : string.Empty,
                Address   = IPAddress.Loopback,
            };
            Profile.PropertyChanged += changed;
        }