示例#1
0
        private async Task CopyTopics(ProgressDialogController controller)
        {
            var topicsToUpdate = _fromManager.Topics.Where(a => _toManager.Topics.Select(b => b.Path).Contains(a.Path)).ToList();

            foreach (var topic in topicsToUpdate)
            {
                controller.SetMessage(string.Format("Updating: {0}", topic.Path));
                await Task.Run(() =>
                {
                    _toManager.UpdateTopic(topic);

                    // Add missing subscription
                    foreach (var subscription in _fromManager.GetSubscriptions(topic).Where(a => !_toManager.GetSubscriptions(topic).Select(b => b.Name).Contains(a.Name)))
                    {
                        _toManager.AddSubscription(subscription);
                    }
                });
            }

            var topicsToAdd = _fromManager.Topics.Except(_toManager.Topics, new LambdaComparer <TopicDescription>((a, b) => a.Path == b.Path, a => 1)).ToList();

            foreach (var topic in topicsToAdd)
            {
                controller.SetMessage(string.Format("Adding: {0}", topic.Path));
                await Task.Run(() =>
                {
                    _toManager.CreateTopic(topic);

                    // Add missing subscription
                    foreach (var subscription in _fromManager.GetSubscriptions(topic))
                    {
                        _toManager.AddSubscription(subscription);
                    }
                });
            }
        }
        public void AddSubscription()
        {
            try
            {
                var subscription = new SubscriptionDescription(Instance.Path, SubscriptionName);
                subscription = _manager.AddSubscription(subscription);

                _manager.UpdateTopic(Instance);

                Subscriptions.Add(subscription);

                NotifyOfPropertyChange(() => Instance);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Add subscription failed", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }