示例#1
0
        static ChannelConfiguration BuildCloudChannel(ChannelConfig channel)
        {
            var instance = BuildLocalChannel(channel);

            instance.IsConnected = true;
            instance.ChannelKey = channel.ChannelKey;

            return instance;
        }
示例#2
0
        static ChannelConfiguration BuildLocalChannel(ChannelConfig channel)
        {
            var configuration = AvailableChannels.First(c => c.DisplayName == channel.DisplayName).Clone();

            configuration.DisplayEnabled = true;
            configuration.ChannelId = channel.ChannelConfigId.Value;
            configuration.IsDefault = channel.IsDefault;

            if (configuration.DisplayStyle == DisplayStyle.Other ||
                channel.IsManuallyCustomized)
            {
                configuration.IsCustomized = channel.IsManuallyCustomized;

                ChannelBuilder.SetChannelAuthentication(channel.Username, channel.Password,
                    configuration.InputChannel,
                    configuration.ContactsChannel,
                    configuration.CalendarChannel,
                    configuration.StatusUpdatesChannel);

                configuration.InputChannel.Hostname = channel.Hostname;
                configuration.InputChannel.TypeSurrogate = channel.Type;
                configuration.InputChannel.Port = channel.Port ?? 0;
                configuration.InputChannel.IsSecured = channel.SSL;

                ChannelBuilder.SetChannelAuthentication(
                    channel.OutgoingUsername, channel.OutgoingPassword, configuration.OutputChannel);

                configuration.OutputChannel.Hostname = channel.OutgoingHostname;
                configuration.OutputChannel.Port = channel.OutgoingPort ?? 0;
                configuration.OutputChannel.IsSecured = channel.OutgoingSSL;
            }
            else if (configuration.DisplayStyle == DisplayStyle.Advanced)
            {
                ChannelBuilder.SetChannelHostname(channel.Hostname, configuration.InputChannel,
                    configuration.OutputChannel, configuration.ContactsChannel,
                    configuration.CalendarChannel, configuration.StatusUpdatesChannel);

                ChannelBuilder.SetChannelAuthentication(channel.Username, channel.Password,
                    configuration.InputChannel,
                    configuration.OutputChannel, configuration.ContactsChannel,
                    configuration.CalendarChannel,
                    configuration.StatusUpdatesChannel);
            }
            else
            {
                ChannelBuilder.SetChannelAuthentication(channel.Username, channel.Password,
                    configuration.InputChannel,
                    configuration.OutputChannel, configuration.ContactsChannel,
                    configuration.CalendarChannel,
                    configuration.StatusUpdatesChannel);
            }

            return configuration;
        }
        /// <summary>
        /// Updates the channel.
        /// </summary>
        void UpdateChannel()
        {
            var config = new ChannelConfig
            {
                ChannelConfigId = ChannelConfiguration.ChannelId,
                DisplayName = ChannelConfiguration.DisplayName,
                Hostname = ChannelConfiguration.InputChannel.Hostname,
                Port = ChannelConfiguration.InputChannel.Port,
                Username = ChannelConfiguration.InputChannel.Authentication.Username,
                Password = ChannelConfiguration.InputChannel.Authentication.Password,
                SSL = ChannelConfiguration.InputChannel.IsSecured,
                Type = ChannelConfiguration.InputChannel.TypeSurrogate,
                IsVisible = true,
                IsDefault = ChannelConfiguration.IsDefault,
                IsManuallyCustomized = IsManuallyCustomized,
                DateModified = DateTime.Now
            };

            if (ChannelConfiguration.OutputChannel != null)
            {
                config.OutgoingUsername = ChannelConfiguration.OutputChannel.Authentication.Username;
                config.OutgoingPassword = ChannelConfiguration.OutputChannel.Authentication.Password;
                config.OutgoingHostname = ChannelConfiguration.OutputChannel.Hostname;
                config.OutgoingPort = ChannelConfiguration.OutputChannel.Port;
                config.OutgoingSSL = ChannelConfiguration.OutputChannel.IsSecured;
            }

            ChannelConfiguration.IsCustomized = IsManuallyCustomized;

            ClientState.Current.DataService.Update(config);

            // Ovverride the existing configuration in the channelsmanager
            var instance = ChannelsManager.Channels.First(c => c.Configuration.ChannelId == config.ChannelConfigId);
            instance.OverrideConfiguration(ChannelConfiguration);
        }
        /// <summary>
        /// Saves the channel.
        /// </summary>
        /// <param name="values">The values.</param>
        void SaveChannel(Dictionary<string, object> values)
        {
            var config = new ChannelConfig
            {
                DisplayName = ChannelConfiguration.DisplayName,
                Hostname = ChannelConfiguration.InputChannel.Hostname,
                Port = ChannelConfiguration.InputChannel.Port,
                Username = ChannelConfiguration.InputChannel.Authentication.Username,
                Password = ChannelConfiguration.InputChannel.Authentication.Password,
                SSL = ChannelConfiguration.InputChannel.IsSecured,
                Type = ChannelConfiguration.InputChannel.TypeSurrogate,
                IsVisible = true,
                IsDefault = ChannelConfiguration.IsDefault,
                IsManuallyCustomized = IsManuallyCustomized,
                DateCreated = DateTime.Now
            };

            if (ChannelConfiguration.OutputChannel != null)
            {
                config.OutgoingUsername = ChannelConfiguration.OutputChannel.Authentication.Username;
                config.OutgoingPassword = ChannelConfiguration.OutputChannel.Authentication.Password;
                config.OutgoingHostname = ChannelConfiguration.OutputChannel.Hostname;
                config.OutgoingPort = ChannelConfiguration.OutputChannel.Port;
                config.OutgoingSSL = ChannelConfiguration.OutputChannel.IsSecured;
            }

            config.ChannelConnection = ChannelConnection.Local;

            ClientState.Current.DataService.Save(config);

            // Replace ChannelConfiguration with new channel instance
            ChannelConfiguration = ChannelFactory.Create(config);

            // Save temporary settings to channelcontext
            var context = new ChannelClientContext(ClientState.Current.Context, ChannelConfiguration);
            values.Keys.ForEach(key => context.SaveSetting(key, values[key]));

            var instance = ChannelsManager.Add(ChannelConfiguration);

            if (instance.StatusUpdatesChannel != null)
                EventBroker.Publish(AppEvents.RequestDockChannel, instance);
        }
示例#5
0
 public static ChannelConfiguration Create(ChannelConfig channel)
 {
     return channel.ChannelConnection == ChannelConnection.Local ?
         BuildLocalChannel(channel) : BuildCloudChannel(channel);
 }