Exemplo n.º 1
0
        protected override void OnStart(string[] args)
        {
            string path = Store.VpnClientPath;

            if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
            {
                path = TryGetDefaultExePath();
            }

            if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
            {
                this.eventLog.WriteEntry(
                    "vpnclient.exe not set and not found in default locations. Is the Cisco VPN Client installed?",
                    EventLogEntryType.Error);

                throw new InvalidOperationException("vpnclient.exe not found.");
            }

            this.client = new VpnClientWrapper(path);

            this.profile = Store.Profile;
            bool success = this.client.Connect(profile, Store.Username, Store.Password);

            if (!success)
            {
                this.eventLog.WriteEntry(
                    "Unable to establish vpn connection. Are profile, username and password set correctly?",
                    EventLogEntryType.Error);

                throw new InvalidOperationException("Unable to establish vpn connection.");
            }
            else
            {
                this.eventLog.WriteEntry(
                    "Established vpn connection: " + this.profile,
                    EventLogEntryType.Information);
            }

            this.timer = new Timer(this.OnTimedAction);
            this.timer.Change(0, BaseIntervallMs);
            this.currentIntervall = BaseIntervallMs;
        }
Exemplo n.º 2
0
        protected override void OnStart(string[] args)
        {
            string path = Store.VpnClientPath;

            if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
                path = TryGetDefaultExePath();

            if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
            {
                this.eventLog.WriteEntry(
                    "vpnclient.exe not set and not found in default locations. Is the Cisco VPN Client installed?",
                    EventLogEntryType.Error);

                throw new InvalidOperationException("vpnclient.exe not found.");
            }

            this.client = new VpnClientWrapper(path);

            this.profile = Store.Profile;
            bool success = this.client.Connect(profile, Store.Username, Store.Password);

            if (!success)
            {
                this.eventLog.WriteEntry(
                    "Unable to establish vpn connection. Are profile, username and password set correctly?",
                    EventLogEntryType.Error);

                throw new InvalidOperationException("Unable to establish vpn connection.");
            }
            else
            {
                this.eventLog.WriteEntry(
                    "Established vpn connection: " + this.profile,
                    EventLogEntryType.Information);
            }

            this.timer = new Timer(this.OnTimedAction);
            this.timer.Change(0, BaseIntervallMs);
            this.currentIntervall = BaseIntervallMs;
        }