Esempio n. 1
0
        /// <summary>
        /// Save the settings file
        /// </summary>
        internal static void Save(Settings settings)
        {
            var filePath = GetSettingsFile();

            if (!Directory.Exists(Path.GetDirectoryName(filePath)))
            {
                var dir = Path.GetDirectoryName(filePath);
                if (!string.IsNullOrEmpty(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }

            using var sw = new StreamWriter(filePath, false);
            sw.Write(JsonConvert.SerializeObject(settings, Formatting.Indented));
            var tc = new TrayCallback();

            tc.OnSettingChange(settings);
        }
Esempio n. 2
0
        /// <summary>
        /// Connect to WCF service
        /// </summary>
        private void Connect()
        {
            //Create a NetTcp binding to the service and set some appropriate timeouts.
            //Use reliable connection so we know when we have been disconnected
            var plexServiceBinding = new NetTcpBinding
            {
                OpenTimeout     = _timeOut,
                CloseTimeout    = _timeOut,
                SendTimeout     = _timeOut,
                ReliableSession =
                {
                    Enabled           = true,
                    InactivityTimeout = TimeSpan.FromMinutes(1)
                }
            };
            //Generate the endpoint from the local settings
            var plexServiceEndpoint = new EndpointAddress(_address);

            TrayCallback callback = new TrayCallback();

            callback.Stopped += (s, e) => _stopped.Set();
            var client = new TrayInteractionClient(callback, plexServiceBinding, plexServiceEndpoint);

            //Make a channel factory so we can create the link to the service
            //var plexServiceChannelFactory = new ChannelFactory<PlexServiceCommon.Interface.ITrayInteraction>(plexServiceBinding, plexServiceEndpoint);

            _plexService = null;

            try
            {
                _plexService = client.ChannelFactory.CreateChannel();

                _plexService.Subscribe();
                //If we lose connection to the service, set the object to null so we will know to reconnect the next time the tray icon is clicked
                ((ICommunicationObject)_plexService).Faulted += (s, e) => _plexService = null;
                ((ICommunicationObject)_plexService).Closed  += (s, e) => _plexService = null;
            }
            catch
            {
                _plexService = null;
            }
        }