コード例 #1
0
ファイル: AddInsForm.cs プロジェクト: ivan45654/Gurux.Common
        static public void CheckUpdates(object target)
        {
            AddInsForm  form = target as AddInsForm;
            GXAddInList list = GXUpdateChecker.GetUpdatesOnline(!form.ShowAddins);

            if (list.Count != 0)
            {
                if (form.IsHandleCreated)
                {
                    form.BeginInvoke(new CheckUpdatesEventHandler(form.OnCheckUpdatesDone), list);
                }
            }
        }
コード例 #2
0
ファイル: AddInsForm.cs プロジェクト: ivan45654/Gurux.Common
        /// <summary>
        /// Initializes a new instance of the AddIns form.
        /// </summary>
        public AddInsForm(GXAddInList addIns, bool showAddins, bool onlyNew)
        {
            InitializeComponent();
            //Update resources.
            this.CancelBtn.Text   = Resources.CancelTxt;
            this.NameCH.Text      = Resources.NameTxt;
            this.StateCH.Text     = Resources.State;
            this.InstalledCH.Text = Resources.Installed;
            this.AvailableCH.Text = Resources.Available;
            this.DownloadMnu.Text = Resources.Download;
            this.EnableMnu.Text   = Resources.Enable;
            this.Text             = Resources.AvailableAddIns;

            ShowAddins   = showAddins;
            AddIns       = addIns;
            OnlyNewItems = onlyNew;
            if (onlyNew)
            {
                this.Text = Resources.AvailableUpdatesTxt;
            }
            else
            {
                this.Text = Resources.ProtocolsTxt;
            }
            if (addIns.Count == 0)
            {
                listView1.Items.Add(Resources.FindingProtocols);
                OKBtn.Enabled = listView1.Enabled = false;
            }
            foreach (GXAddIn it in addIns)
            {
                //Show only new AddIns.
                if (onlyNew && (it.State != AddInStates.Available && it.State != AddInStates.Update))
                {
                    continue;
                }
                if (!ShowAddins && it.Type == GXAddInType.AddIn)
                {
                    continue;
                }
                //If installed protocols are shown.
                if (!onlyNew && it.Type == GXAddInType.Application)
                {
                    continue;
                }
                if (it.Type == GXAddInType.Application && string.Compare(it.Name, System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath), true) != 0)
                {
                    continue;
                }
                if (onlyNew && !GXUpdateChecker.IsNewVersion(it.Version, it.InstalledVersion))
                {
                    continue;
                }
                ListViewItem li = listView1.Items.Add(it.Name);
                li.SubItems.Add(it.State.ToString());
                li.SubItems.Add(it.InstalledVersion);
                li.SubItems.Add(it.Version);
                li.Tag = it;
                UpdateState(li, it.State);
            }
            ThreadPool.QueueUserWorkItem(CheckUpdates, this);
        }
コード例 #3
0
ファイル: AddInsForm.cs プロジェクト: ivan45654/Gurux.Common
 private void OKBtn_Click(object sender, EventArgs e)
 {
     try
     {
         bool updatesAvailable = false;
         foreach (ListViewItem it in listView1.Items)
         {
             GXAddIn addIn = it.Tag as GXAddIn;
             if (addIn.State == AddInStates.Available || addIn.State == AddInStates.Update)
             {
                 updatesAvailable = true;
             }
             //If user has select items to download do not notify.
             else if (addIn.State == AddInStates.Download)
             {
                 updatesAvailable = false;
                 break;
             }
         }
         DialogResult res = DialogResult.Yes;
         if (updatesAvailable)
         {
             res = MessageBox.Show(this, Resources.NewProtocolsDownloadTxt, Resources.NewProtocolsAvailableTxt, MessageBoxButtons.YesNoCancel);
             if (res != DialogResult.Yes)
             {
                 this.DialogResult = DialogResult.OK;
                 this.Close();
                 return;
             }
         }
         //Add downloadable items to the list or they are not shown anymore.
         foreach (ListViewItem it in listView1.Items)
         {
             GXAddIn addIn = it.Tag as GXAddIn;
             if (addIn.State == AddInStates.Available ||
                 addIn.State == AddInStates.Download)
             {
                 if (addIn.State == AddInStates.Available)
                 {
                     if (res == DialogResult.Yes)
                     {
                         addIn.State = AddInStates.Download;
                     }
                     else if (res == DialogResult.No)
                     {
                         addIn.State = AddInStates.Disabled;
                     }
                 }
                 //Add new Addins.
                 bool exists = false;
                 foreach (var a in AddIns)
                 {
                     if (a.Name == addIn.Name)
                     {
                         exists = true;
                         break;
                     }
                 }
                 if (!exists)
                 {
                     AddIns.Add(addIn);
                 }
             }
         }
         XmlWriterSettings settings = new XmlWriterSettings();
         settings.Indent          = true;
         settings.Encoding        = System.Text.Encoding.UTF8;
         settings.CloseOutput     = true;
         settings.CheckCharacters = false;
         string path = System.IO.Path.Combine(GXCommon.ProtocolAddInsPath, "updates.xml");
         DataContractSerializer x = new DataContractSerializer(typeof(GXAddInList));
         using (XmlWriter writer = XmlWriter.Create(path, settings))
         {
             x.WriteObject(writer, AddIns);
             writer.Close();
         }
         Gurux.Common.GXFileSystemSecurity.UpdateFileSecurity(path);
         GXUpdateChecker updater = new GXUpdateChecker();
         updater.OnProgress += new GXUpdateChecker.ProgressEventHandler(updater_OnProgress);
         Status              = updater.UpdateProtocols();
         updater.UpdateApplications();
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this, ex);
     }
 }
コード例 #4
0
ファイル: AddInsForm.cs プロジェクト: ivan45654/Gurux.Common
 void OnCheckUpdatesDone(GXAddInList list)
 {
     //If done first time.
     if (!listView1.Enabled)
     {
         listView1.Items.Clear();
         OKBtn.Enabled = listView1.Enabled = true;
         foreach (GXAddIn it in list)
         {
             //Show only new AddIns.
             if (OnlyNewItems && (it.State != AddInStates.Available && it.State != AddInStates.Update))
             {
                 continue;
             }
             if (!ShowAddins && it.Type == GXAddInType.AddIn)
             {
                 continue;
             }
             //If installed protocols are shown.
             if (!OnlyNewItems && it.Type == GXAddInType.Application)
             {
                 continue;
             }
             if (it.Type == GXAddInType.Application && string.Compare(it.Name, System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath), true) != 0)
             {
                 continue;
             }
             if (!GXUpdateChecker.IsNewVersion(it.Version, it.InstalledVersion))
             {
                 continue;
             }
             ListViewItem li = listView1.Items.Add(it.Name);
             li.SubItems.Add(it.State.ToString());
             li.SubItems.Add(it.InstalledVersion);
             li.SubItems.Add(it.Version);
             li.Tag = it;
             UpdateState(li, it.State);
         }
     }
     else //Update exist items...
     {
         foreach (GXAddIn it in list)
         {
             //Show only new AddIns.
             if (OnlyNewItems && it.State != AddInStates.Available)
             {
                 continue;
             }
             if (!ShowAddins && it.Type == GXAddInType.AddIn)
             {
                 continue;
             }
             //If installed protocols are shown.
             if (!OnlyNewItems && it.Type == GXAddInType.Application)
             {
                 continue;
             }
             if (it.Type == GXAddInType.Application && string.Compare(it.Name, System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath), true) != 0)
             {
                 continue;
             }
             if (!GXUpdateChecker.IsNewVersion(it.Version, it.InstalledVersion))
             {
                 continue;
             }
             ListViewItem item = null;
             foreach (ListViewItem li in listView1.Items)
             {
                 if (string.Compare(li.Text, it.Name, true) == 0)
                 {
                     item = li;
                     break;
                 }
             }
             if (item == null)
             {
                 item = listView1.Items.Add(it.Name);
                 item.SubItems.Add(it.InstalledVersion);
                 item.SubItems.Add(it.Version);
                 item.Tag = it;
             }
             else
             {
                 GXAddIn t = item.Tag as GXAddIn;
                 t.State = it.State;
             }
             UpdateState(item, it.State);
         }
     }
 }
コード例 #5
0
ファイル: AddInsForm.cs プロジェクト: giapdangle/Gurux.Common
 private void OKBtn_Click(object sender, EventArgs e)
 {
     try
     {
         bool updatesAvailable = false;
         foreach (ListViewItem it in listView1.Items)
         {
             GXAddIn addIn = it.Tag as GXAddIn;
             if (addIn.State == AddInStates.Available || addIn.State == AddInStates.Update)
             {
                 updatesAvailable = true;                        
             }
             //If user has select items to download do not notify.
             else if (addIn.State == AddInStates.Download)
             {
                 updatesAvailable = false;
                 break;
             }
         }
         DialogResult res = DialogResult.Yes;
         if (updatesAvailable)
         {
             res = MessageBox.Show(this, Resources.NewProtocolsDownloadTxt, Resources.NewProtocolsAvailableTxt, MessageBoxButtons.YesNoCancel);
             if (res != DialogResult.Yes)
             {
                 this.DialogResult = DialogResult.OK;
                 this.Close();
                 return;
             }
         }
         //Add downloadable items to the list or they are not shown anymore.
         foreach (ListViewItem it in listView1.Items)
         {
             GXAddIn addIn = it.Tag as GXAddIn;
             if (addIn.State == AddInStates.Available ||
                 addIn.State == AddInStates.Download)
             {
                 if (addIn.State == AddInStates.Available)
                 {
                     if (res == DialogResult.Yes)
                     {
                         addIn.State = AddInStates.Download;
                     }
                     else if (res == DialogResult.No)
                     {
                         addIn.State = AddInStates.Disabled;
                     }
                 }
                 //Add new Addins.
                 bool exists = false;
                 foreach (var a in AddIns)
                 {
                     if (a.Name == addIn.Name)
                     {
                         exists = true;
                         break;
                     }
                 }
                 if (!exists)
                 {
                     AddIns.Add(addIn);
                 }
             }
         }                
         XmlWriterSettings settings = new XmlWriterSettings();
         settings.Indent = true;
         settings.Encoding = System.Text.Encoding.UTF8;
         settings.CloseOutput = true;
         settings.CheckCharacters = false;
         string path = System.IO.Path.Combine(GXCommon.ProtocolAddInsPath, "updates.xml");
         DataContractSerializer x = new DataContractSerializer(typeof(GXAddInList));
         using (XmlWriter writer = XmlWriter.Create(path, settings))
         {
             x.WriteObject(writer, AddIns);
             writer.Close();
         }
         Gurux.Common.GXFileSystemSecurity.UpdateFileSecurity(path);
         GXUpdateChecker updater = new GXUpdateChecker();
         updater.OnProgress += new GXUpdateChecker.ProgressEventHandler(updater_OnProgress);
         Status = updater.UpdateProtocols();
         updater.UpdateApplications();
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this, ex);
     }
 }