コード例 #1
0
ファイル: App.xaml.cs プロジェクト: VRDate/MIoT
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            this.mqttClient?.Dispose();
            this.mqttClient = null;

            this.sampleTimer?.Dispose();
            this.sampleTimer = null;

            if (this.arduino != null)
            {
                this.arduino.digitalWrite(13, PinState.LOW);
                this.arduino.pinMode(13, PinMode.INPUT);                     // Onboard LED.
                this.arduino.pinMode(9, PinMode.INPUT);                      // Relay.

                this.arduino.Dispose();
                this.arduino = null;
            }

            if (this.arduinoUsb != null)
            {
                this.arduinoUsb.end();
                this.arduinoUsb.Dispose();
                this.arduinoUsb = null;
            }

            db?.Stop()?.Wait();
            db?.Flush()?.Wait();

            Log.Terminate();

            deferral.Complete();
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: charithmadhuranga/MIoT
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            if (instance == this)
            {
                instance = null;
            }

            this.chatServer?.Dispose();
            this.chatServer = null;

            this.bobClient?.Dispose();
            this.bobClient = null;

            this.sensorServer?.Dispose();
            this.sensorServer = null;

            this.xmppClient?.Dispose();
            this.xmppClient = null;

            this.minuteTimer?.Dispose();
            this.minuteTimer = null;

#if GPIO
            this.gpioPin.Dispose();
            this.gpioPin = null;
#else
            if (this.arduino != null)
            {
                this.arduino.digitalWrite(13, PinState.LOW);
                this.arduino.pinMode(13, PinMode.INPUT);                     // Onboard LED.
                this.arduino.pinMode(9, PinMode.INPUT);                      // Relay.

                this.arduino.Dispose();
                this.arduino = null;
            }

            if (this.arduinoUsb != null)
            {
                this.arduinoUsb.end();
                this.arduinoUsb.Dispose();
                this.arduinoUsb = null;
            }
#endif
            db?.Stop()?.Wait();
            db?.Flush()?.Wait();

            Log.Terminate();

            deferral.Complete();
        }
コード例 #3
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (!this.MainView.CheckSaved())
            {
                e.Cancel = true;
                return;
            }

            Registry.SetValue(registryKey, "WindowLeft", (int)this.Left, RegistryValueKind.DWord);
            Registry.SetValue(registryKey, "WindowTop", (int)this.Top, RegistryValueKind.DWord);
            Registry.SetValue(registryKey, "WindowWidth", (int)this.Width, RegistryValueKind.DWord);
            Registry.SetValue(registryKey, "WindowHeight", (int)this.Height, RegistryValueKind.DWord);
            Registry.SetValue(registryKey, "ConnectionTreeWidth", (int)this.MainView.ConnectionsGrid.ColumnDefinitions[0].Width.Value, RegistryValueKind.DWord);
            Registry.SetValue(registryKey, "WindowState", this.WindowState.ToString(), RegistryValueKind.String);
            Registry.SetValue(registryKey, "FileName", this.MainView.FileName, RegistryValueKind.String);

            Log.Terminate();

            databaseProvider.Stop();
            databaseProvider.Flush();
        }
コード例 #4
0
ファイル: App.xaml.cs プロジェクト: VRDate/MIoT
		/// <summary>
		/// Invoked when application execution is being suspended.  Application state is saved
		/// without knowing whether the application will be terminated or resumed with the contents
		/// of memory still intact.
		/// </summary>
		/// <param name="sender">The source of the suspend request.</param>
		/// <param name="e">Details about the suspend request.</param>
		private void OnSuspending(object sender, SuspendingEventArgs e)
		{
			var deferral = e.SuspendingOperation.GetDeferral();

			this.subscription?.Unsubscribe();
			this.subscription = null;

			this.registryClient?.Dispose();
			this.registryClient = null;

			this.chatServer?.Dispose();
			this.chatServer = null;

			this.bobClient?.Dispose();
			this.bobClient = null;

			this.sensorServer?.Dispose();
			this.sensorServer = null;

			this.sensorClient?.Dispose();
			this.sensorClient = null;

			this.controlClient?.Dispose();
			this.controlClient = null;

			this.xmppClient?.Dispose();
			this.xmppClient = null;

			this.secondTimer?.Dispose();
			this.secondTimer = null;

			db?.Stop()?.Wait();
			db?.Flush()?.Wait();

			Log.Terminate();

			deferral.Complete();
		}
コード例 #5
0
ファイル: Program.cs プロジェクト: Trust-Anchor-Group/ComSim
        private static async Task <bool> Run(XmlDocument ModelXml, TaskCompletionSource <bool> Done,
                                             string SnifferFolder, string SnifferTransformFileName, string MarkdownOutputFileName, string XmlOutputFileName,
                                             string CommandLine, IEnumerable <string> Master, IEnumerable <string> Css, bool EmitDots,
                                             string ProgramDataFolder, int BlockSize, int BlobBlockSize, Encoding Encoding, bool Encryption)
        {
            using (FilesProvider DB = await FilesProvider.CreateAsync(ProgramDataFolder, "Default", BlockSize, 10000, BlobBlockSize, Encoding, 3600000, Encryption, false))
            {
                try
                {
                    Console.Out.WriteLine("Starting database...");
                    Database.Register(DB);
                    await DB.RepairIfInproperShutdown(null);

                    await Database.Clear("EventLog");

                    Log.Register(new PersistedEventLog(int.MaxValue));

                    Console.Out.WriteLine("Starting modules...");
                    await Types.StartAllModules(60000);

                    Console.Out.WriteLine("Running simulation...");
                    Model Model = (Model)await Factory.Create(ModelXml.DocumentElement, null, null);

                    Model.CommandLine              = CommandLine;
                    Model.SnifferFolder            = SnifferFolder;
                    Model.SnifferTransformFileName = SnifferTransformFileName;
                    Model.OnGetKey         += Model_OnGetKey;
                    Model.OnGetThreadCount += Model_OnGetThreadCount;

                    bool Result = await Model.Run(Done, EmitDots);

                    if (!string.IsNullOrEmpty(MarkdownOutputFileName))
                    {
                        Console.Out.WriteLine("Generating Markdown report: " + MarkdownOutputFileName);

                        string Folder = Path.GetDirectoryName(MarkdownOutputFileName);
                        if (!string.IsNullOrEmpty(Folder) && !Directory.Exists(Folder))
                        {
                            Directory.CreateDirectory(Folder);
                        }

                        using (StreamWriter Output = File.CreateText(MarkdownOutputFileName))
                        {
                            foreach (string s in Master)
                            {
                                Output.Write("Master: ");
                                Output.WriteLine(s);
                            }

                            foreach (string s in Css)
                            {
                                Output.Write("CSS: ");
                                Output.WriteLine(s);
                            }

                            await Model.ExportMarkdown(Output);
                        }
                    }

                    if (!string.IsNullOrEmpty(XmlOutputFileName))
                    {
                        Console.Out.WriteLine("Generating XML report: " + XmlOutputFileName);

                        XmlWriterSettings Settings = new XmlWriterSettings()
                        {
                            Encoding                = Encoding.UTF8,
                            Indent                  = true,
                            IndentChars             = "\t",
                            NewLineChars            = "\r\n",
                            NewLineOnAttributes     = false,
                            WriteEndDocumentOnClose = true
                        };

                        string Folder = Path.GetDirectoryName(XmlOutputFileName);
                        if (!string.IsNullOrEmpty(Folder) && !Directory.Exists(Folder))
                        {
                            Directory.CreateDirectory(Folder);
                        }

                        using (XmlWriter Output = XmlWriter.Create(XmlOutputFileName, Settings))
                        {
                            Output.WriteStartDocument();
                            Output.WriteStartElement("Report", "http://trustanchorgroup.com/Schema/ComSimReport.xsd");

                            await Model.ExportXml(Output);

                            Output.WriteEndElement();
                        }
                    }

                    return(Result);
                }
                finally
                {
                    Console.Out.WriteLine("Stopping modules...");
                    await Types.StopAllModules();

                    await DB.Flush();

                    Log.Terminate();
                }
            }
        }