コード例 #1
0
 private void DiscoverMnu_Click(object sender, EventArgs e)
 {
     try
     {
         if (media.IsOpen)
         {
             ScanWork.Cancel();
             media.Close();
         }
         else
         {
             ClearMnu_Click(null, null);
             media.Open();
             ScanWork = new GXAsyncWork(this, OnAsyncStateChange, DiscoverMeters, OnError, null, new object[] { sender });
             ScanWork.Start();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
 private void OnMediaStateChange(object sender, MediaStateEventArgs e)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new MediaStateChangeEventHandler(OnMediaStateChange), sender, e);
     }
     else
     {
         try
         {
             if (e.State == Gurux.Common.MediaState.Open)
             {
                 ScanBtn.Checked          = true;
                 MediaSettingsBtn.Enabled = MediaMnu.Enabled = settingsToolStripMenuItem.Enabled = false;
                 ProgressTb.Text          = "";
                 TraceView.Text           = "";
                 ScanMnu.Text             = "Stop";
                 UpdateStatus("Scanning");
                 ScanWork = new GXAsyncWork(this, OnAsyncStateChange, FindSettings, OnError, null, new object[] { sender });
                 ScanWork.Start();
             }
             else if (e.State == Gurux.Common.MediaState.Closed)
             {
                 ScanBtn.Checked          = false;
                 MediaSettingsBtn.Enabled = MediaMnu.Enabled = settingsToolStripMenuItem.Enabled = true;
                 ScanMnu.Text             = "Scan";
                 UpdateStatus("Ready.");
                 if (ScanWork != null)
                 {
                     ScanWork.Cancel();
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
コード例 #3
0
        static void Main()
        {
            //Allow only one instance.
            bool first;

            try
            {
                first = mutex.WaitOne(TimeSpan.Zero, true);
            }
            catch (AbandonedMutexException)
            {
                first = true;
            }
            if (first)
            {
                try
                {
                    //Update previous installed settings.
                    //If file is corrupted it's found from:
                    //%USERPROFILE%\AppData\Local\Gurux_Ltd\
                    //This might happen if Windows is not closed correctly.
                    if (Properties.Settings.Default.UpdateSettings)
                    {
                        Properties.Settings.Default.Upgrade();
                        Properties.Settings.Default.UpdateSettings = false;
                        Properties.Settings.Default.Save();
                        Gurux.DLMS.UI.GXDlmsUi.Upgrade();
                    }
#if (NET46)
                    //This is needed to make Gurux.MQTT visible.
                    try
                    {
                        new Gurux.MQTT.GXMqtt();
                        //Make AMI visible.
                        new Gurux.DLMS.AMI.UI.GXDlmsAmi();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
#endif

                    string initDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GXDLMSDirector");
                    if (!Directory.Exists(initDir))
                    {
                        Directory.CreateDirectory(initDir);
                    }
                    string updates = Path.Combine(initDir, "Updates");
                    string medias  = Path.Combine(initDir, "Medias");
                    if (Directory.Exists(updates))
                    {
                        if (!Directory.Exists(medias))
                        {
                            Directory.CreateDirectory(medias);
                        }
                        DirectoryInfo di = new DirectoryInfo(updates);
                        foreach (string it in Properties.Settings.Default.ExternalMedias.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            FileInfo fi = new FileInfo(Path.Combine(updates, Path.GetFileName(it)));
                            if (fi.Exists)
                            {
                                try
                                {
                                    File.Copy(fi.FullName, Path.Combine(medias, fi.Name), true);
                                    File.Delete(fi.FullName);
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Debug.WriteLine(ex.Message);
                                }
                            }
                        }
                    }

                    try
                    {
                        SetAddRemoveProgramsIcon();
                        Directory.SetCurrentDirectory(initDir);
                        //Load external medias.
                        List <string> missingMedias    = new List <string>();
                        List <string> downloadedMedias = new List <string>();
                        foreach (string it in Properties.Settings.Default.ExternalMedias.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (GXExternalMediaForm.IsDownloaded(it))
                            {
                                FileInfo fi = new FileInfo(Path.Combine(medias, Path.GetFileName(it)));
                                if (!fi.Exists)
                                {
                                    missingMedias.Add(it);
                                }
                                else
                                {
                                    downloadedMedias.Add(it);
                                }
                            }
                            else if (File.Exists(it))
                            {
                                Assembly assembly = Assembly.LoadFile(it);
                            }
                        }
                        if (missingMedias.Count != 0)
                        {
                            //Download media again if not found.
                            GXAsyncWork checkUpdates = new GXAsyncWork(null, OnAsyncStateChange, DownloadMedias, OnError, null, new object[] { missingMedias.ToArray() });
                            checkUpdates.Start();
                        }
                        if (downloadedMedias.Count != 0)
                        {
                            //Download media again if not found.
                            GXAsyncWork checkUpdates = new GXAsyncWork(null, OnAsyncStateChange, DownloadMedias, OnError, null, new object[] { downloadedMedias.ToArray() });
                            checkUpdates.Start();
                        }
                    }
                    catch (Exception)
                    {
                    }
                    MainForm.InitMain();
                }
                catch (Exception Ex)
                {
                    GXDLMS.Common.Error.ShowError(null, Ex);
                }
                mutex.ReleaseMutex();
            }
            else
            {
                foreach (Process p in Process.GetProcessesByName("GXDLMSDirector"))
                {
                    Gurux.Win32.SetForegroundWindow(p.MainWindowHandle);
                }
            }
        }
コード例 #4
0
        static void Main()
        {
            //Allow only one instance.
            bool first;

            try
            {
                first = mutex.WaitOne(TimeSpan.Zero, true);
            }
            catch (AbandonedMutexException)
            {
                first = true;
            }
            if (first)
            {
                try
                {
                    //Update previous installed settings.
                    if (Properties.Settings.Default.UpdateSettings)
                    {
                        Properties.Settings.Default.Upgrade();
                        Properties.Settings.Default.UpdateSettings = false;
                        Properties.Settings.Default.Save();
                    }

                    Assembly asm     = Assembly.GetExecutingAssembly();
                    string   updates = Path.Combine(Path.GetDirectoryName(asm.Location), "Updates");
                    string   medias  = Path.Combine(Path.GetDirectoryName(asm.Location), "Medias");
                    if (Directory.Exists(updates))
                    {
                        if (!Directory.Exists(medias))
                        {
                            Directory.CreateDirectory(medias);
                        }
                        DirectoryInfo di = new DirectoryInfo(updates);
                        foreach (FileInfo it in di.GetFiles("*.dll"))
                        {
                            try
                            {
                                File.Copy(it.FullName, Path.Combine(medias, it.Name), true);
                                File.Delete(it.FullName);
                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Debug.WriteLine(ex.Message);
                            }
                        }
                    }

                    string initDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GXDLMSDirector");
                    try
                    {
                        if (!Directory.Exists(initDir))
                        {
                            Directory.CreateDirectory(initDir);
                        }
                        SetAddRemoveProgramsIcon();
                        Directory.SetCurrentDirectory(initDir);
                        LoadMedias(new DirectoryInfo(medias));
                        //Load external medias.
                        List <string> missingMedias    = new List <string>();
                        List <string> downloadedMedias = new List <string>();
                        foreach (string it in Properties.Settings.Default.ExternalMedias.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (GXExternalMediaForm.IsDownloaded(it))
                            {
                                FileInfo fi = new FileInfo(Path.Combine(medias, Path.GetFileName(it)));
                                if (!fi.Exists)
                                {
                                    missingMedias.Add(it);
                                }
                                else
                                {
                                    downloadedMedias.Add(it);
                                }
                            }
                            else if (File.Exists(it))
                            {
                                Assembly assembly = Assembly.LoadFile(it);
                            }
                        }
                        if (missingMedias.Count != 0)
                        {
                            //Download media again if not found.
                            GXAsyncWork checkUpdates = new GXAsyncWork(null, OnAsyncStateChange, DownloadMedias, OnError, null, new object[] { missingMedias.ToArray() });
                            checkUpdates.Start();
                        }
                        if (downloadedMedias.Count != 0)
                        {
                            //Download media again if not found.
                            GXAsyncWork checkUpdates = new GXAsyncWork(null, OnAsyncStateChange, DownloadMedias, OnError, null, new object[] { downloadedMedias.ToArray() });
                            checkUpdates.Start();
                        }
                    }
                    catch (Exception)
                    {
                    }
                    MainForm.InitMain();
                }
                catch (Exception Ex)
                {
                    GXDLMS.Common.Error.ShowError(null, Ex);
                }
                mutex.ReleaseMutex();
            }
            else
            {
                foreach (Process p in Process.GetProcessesByName("GXDLMSDirector"))
                {
                    Gurux.Win32.SetForegroundWindow(p.MainWindowHandle);
                }
            }
        }