コード例 #1
0
        public void Connection()
        {
            CommunationPlugs plugs = Env.Current.CommunicationPlugins;

            Assert.IsFalse(plugs.IsConnected);
            Assert.IsTrue(plugs.Connect());
            Assert.IsTrue(plugs.IsConnected);
            plugs.Disconnect();
            Assert.IsFalse(plugs.IsConnected);
        }
コード例 #2
0
ファイル: App.cs プロジェクト: trigrass2/IndustrialAutomation
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            var splash = new SplashScreen("splash.jpg");

            splash.Show(true);


            MainWindow window = new MainWindow();

            // Create the ViewModel to which
            // the main window binds.

            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

            Env.Initialize(window, new Commands(), FreeSCADA.Interfaces.EnvironmentMode.Runtime);
            string appPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            Directory.SetCurrentDirectory(appPath);


            Env.Current.Project.Load("project.fs2");

            FreeSCADA.Archiver.ArchiverMain.Current.Start();

            CommunationPlugs plugs = Env.Current.CommunicationPlugins;

            if (plugs.Connect() == false)
            {
                Env.Deinitialize();
                return;
            }

            MainWindowViewModel.LoginModel.Login("Гість", "0");
            _viewModel = new MainWindowViewModel();

            // When the ViewModel asks to be closed,
            // close the window.
            EventHandler handler = null;

            handler = delegate
            {
                _viewModel.RequestClose -= handler;
                window.Close();
            };

            // Force a reload of the changed section.
            // This makes the new values available for reading.

            /*
             * GsmLoggerSettings settings = (GsmLoggerSettings)System.Configuration.ConfigurationManager.GetSection("gsmsettings");
             * try
             * {
             *  _gsmLogger = new GsmLogger(Env.Current.EventsSummary, settings);
             * }
             * catch (Exception ex)
             * {
             *  //Env.Current.Logger (string.Format("Unable to start Gsm Logger. {0}", ex.Message));
             * }
             */

            window.DataContext = _viewModel;
            window.AddHandler(Mouse.PreviewMouseDownEvent, new MouseButtonEventHandler(MousePressed));
            _timer          = new System.Timers.Timer(600000);
            _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed);



            window.Show();
        }
コード例 #3
0
        static int Main(string[] args)
        {
            Options options = new Options();

            Plossum.CommandLine.CommandLineParser parser = new Plossum.CommandLine.CommandLineParser(options);
            parser.Parse();
            Console.WriteLine(parser.UsageInfo.GetHeaderAsString(78));

            if (options.Help)
            {
                Console.WriteLine(parser.UsageInfo.GetOptionsAsString(20, 56));
                return(0);
            }
            else if (parser.HasErrors)
            {
                Console.WriteLine(parser.UsageInfo.GetErrorsAsString(78));
                Console.WriteLine("type --help for list of available options.");
                return(-1);
            }

            Console.Write("Initializing communication plugins... ");
            Env.Initialize(null, new Commands(), FreeSCADA.Interfaces.EnvironmentMode.Runtime);
            Env.Current.Project.Load(options.ProjectFile);
            CommunationPlugs plugs = Env.Current.CommunicationPlugins;

            if (plugs.Connect() == false)
            {
                Env.Deinitialize();
                return(-1);
            }
            Console.WriteLine("Done.");

            Uri         baseAddress = new Uri(string.Format("http://{0}:{1}/", System.Windows.Forms.SystemInformation.ComputerName, options.Port));
            ServiceHost host        = new ServiceHost(typeof(Service), baseAddress);

            try
            {
                host.AddServiceEndpoint(typeof(IChannelInformationRetriever), new WSDualHttpBinding(WSDualHttpSecurityMode.None), "ChannelInformationRetriever");
                host.AddServiceEndpoint(typeof(IDataRetriever), new WSDualHttpBinding(WSDualHttpSecurityMode.None), "DataRetriever");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                host.Description.Behaviors.Add(smb);

                ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
                throttlingBehavior.MaxConcurrentCalls     = Int32.MaxValue;
                throttlingBehavior.MaxConcurrentInstances = Int32.MaxValue;
                throttlingBehavior.MaxConcurrentSessions  = Int32.MaxValue;
                host.Description.Behaviors.Add(throttlingBehavior);

                host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;
                host.Open();

                Console.WriteLine("Server address {0}", baseAddress.AbsoluteUri);
                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();
                Console.WriteLine("Terminating. Please wait...");

                host.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("Error occured: {0}", cex.Message);
                host.Abort();
            }

            plugs.Disconnect();
            Env.Deinitialize();

            return(0);
        }