Пример #1
0
        /// <summary>
        /// Download missing medias.
        /// </summary>
        static void DownloadMedias(object sender, GXAsyncWork work, object[] parameters)
        {
            string[] list    = (string[])parameters[0];
            string   initDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GXDLMSDirector");
            string   medias  = Path.Combine(initDir, "Medias");

            foreach (string it in list)
            {
                IGXUpdater updater = null;
                string     path    = Path.Combine(medias, Path.GetFileName(it));
                Assembly   asm     = null;
                //Check is there new version from the media.
                if (File.Exists(path))
                {
                    asm = Assembly.LoadFile(path);
                    foreach (Type type in asm.GetTypes())
                    {
                        if (!type.IsAbstract && type.IsClass && typeof(IGXUpdater).IsAssignableFrom(type))
                        {
                            updater = Activator.CreateInstance(type) as IGXUpdater;
                            break;
                        }
                    }
                    if (updater != null && GXExternalMediaForm.CheckUpdates(updater, asm))
                    {
                        //TODO: Show that there are new updates.
                    }
                }
                else
                {
                    //If external media is missing.
                    GXExternalMediaForm.DownLoadMedia(it);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Download media updates.
        /// </summary>
        static void DownloadMediaUpdates(object sender, GXAsyncWork work, object[] parameters)
        {
            IGXUpdater updater = (IGXUpdater)parameters[0];
            Assembly   asm     = (Assembly)parameters[1];

            GXExternalMediaForm.CheckUpdates(updater, asm);
        }
Пример #3
0
 /// <summary>
 /// Add new media.
 /// </summary>
 private void AddBtn_Click(object sender, EventArgs e)
 {
     try
     {
         GXExternalMediaForm dlg = new GXExternalMediaForm();
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             if (GXExternalMediaForm.IsDownloaded(dlg.FileName))
             {
                 if (GXExternalMediaForm.DownLoadMedia(dlg.FileName))
                 {
                     if (MessageBox.Show(this, "You need to restart application. Do you want to do it now?", Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                     {
                         AddMedia(dlg.FileName);
                         OKBtn_Click(null, null);
                         Application.Restart();
                     }
                 }
             }
             AddMedia(dlg.FileName);
         }
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(this, Ex);
     }
 }
Пример #4
0
        private void AddMedia(string it)
        {
            Assembly     asm = null;
            ListViewItem li;

            if (GXExternalMediaForm.IsDownloaded(it))
            {
                //If file is downloaded from the web.
                asm = Assembly.GetExecutingAssembly();
                string path = Path.Combine(Path.GetDirectoryName(asm.Location), "Medias");
                path = Path.Combine(path, Path.GetFileName(it));
                li   = MediaList.Items.Add(Path.GetFileName(it));
                asm  = Assembly.LoadFile(path);
                li.SubItems.Add(asm.GetName().Version.ToString());
                li.SubItems.Add(it);
                li.Tag = asm;
                return;
            }
            if (File.Exists(it))
            {
                asm = Assembly.LoadFile(it);
                li  = MediaList.Items.Add(asm.GetName().Name);
                li.SubItems.Add(asm.GetName().Version.ToString());
                li.SubItems.Add(asm.Location.ToString());
                li.Tag = asm;
            }
        }
Пример #5
0
        private void AddMedia(string it)
        {
            string       initDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GXDLMSDirector");
            Assembly     asm     = null;
            ListViewItem li;

            if (GXExternalMediaForm.IsDownloaded(it))
            {
                //If file is downloaded from the web.
                asm = Assembly.GetExecutingAssembly();
                string path = Path.Combine(initDir, "Medias");
                path = Path.Combine(path, Path.GetFileName(it));
                li   = MediaList.Items.Add(Path.GetFileName(it));
                asm  = Assembly.LoadFile(path);
                li.SubItems.Add(asm.GetName().Version.ToString());
                li.SubItems.Add(it);
                li.Tag = asm;
                return;
            }
            if (File.Exists(it))
            {
                asm = Assembly.LoadFile(it);
                li  = MediaList.Items.Add(asm.GetName().Name);
                li.SubItems.Add(asm.GetName().Version.ToString());
                li.SubItems.Add(asm.Location.ToString());
                li.Tag = asm;
            }
        }
Пример #6
0
 /// <summary>
 /// Download missing medias.
 /// </summary>
 static void DownloadMedias(object sender, GXAsyncWork work, object[] parameters)
 {
     string[] list = (string[])parameters[0];
     foreach (string it in list)
     {
         GXExternalMediaForm.DownLoadMedia(it);
     }
 }
Пример #7
0
        void CheckUpdates(object sender, GXAsyncWork work, object[] parameters)
        {
            IGXUpdater updater = (IGXUpdater)parameters[0];
            Assembly   asm     = (Assembly)parameters[1];

            if (!GXExternalMediaForm.CheckUpdates(updater, asm))
            {
                // There's nothing to update
                MessageBox.Show(Properties.Resources.ExternalMediaNoUpdates, Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.OK);
            }
            else
            {
                if (MessageBox.Show("You need to restart application. Do you want to do it now?", Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Application.Restart();
                }
            }
        }
Пример #8
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);
                }
            }
        }
Пример #9
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);
                }
            }
        }