示例#1
0
        //used by the "generic" part of the code (not advanced).
        //this returns a string representation of the listview item data in the given column, for comparison.
        private Object GetCompareValue_Default(GenericListViewSorter Sorter, String ColumnName, ListViewItem Item)
        {
            //default just returns the String, for now. Later, add special conditions that detect when something is a valid date. Or something...
            int indexuse = Sorter.OurListView.Columns[ColumnName].Index;

            return(Item.SubItems[indexuse].Text);
        }
示例#2
0
        // public delegate Object GetCompareValue(GenericListViewSorter Sorter, String ColumnName, ListViewItem Item);
        public Object CompareValue(GenericListViewSorter pSorter, String ColumnName, ListViewItem Item)
        {
            Object oTag = Item.Tag;

            if (oTag == null) /*hrrrm....*/ return {
                (null);
            }
            String propname = FieldNameIndex[ColumnName];
            var    ttype    = oTag.GetType();

            foreach (FieldInfo fi in ttype.GetFields())
            {
                if (fi.Name.Equals(propname, StringComparison.OrdinalIgnoreCase))
                {
                    return(fi.GetValue(oTag));
                }
            }
            foreach (PropertyInfo pi in ttype.GetProperties())
            {
                if (pi.Name.Equals(propname, StringComparison.OrdinalIgnoreCase))
                {
                    return(pi.GetValue(oTag, null));
                }
            }

            return(null);
        }
示例#3
0
        private void frmUpdates_Load(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Debug.Print("frmUpdates Loaded");
                switch (mUpdateMode)
                {
                case EUpdateMode.Update_Full:


                    grpBasicUpdate.Visible = false;
tryagain:
                    updateobj = new BCUpdate();
                    lvwUpdates.Items.Clear();
                    lvwUpdates.Columns.Clear();
                    lvwUpdates.Columns.Add("NAME", "Name");
                    lvwUpdates.Columns.Add("INSTALLEDVER", "Installed");
                    lvwUpdates.Columns.Add("VERSION", "Version");
                    lvwUpdates.Columns.Add("PROGRESS", "Download Progress", 128);
                    lvwUpdates.Columns.Add("SIZE", "Size", 128);
                    lvwUpdates.Columns.Add("PATCH", "Patch For", 128);
                    lsorter = new GenericListViewSorter(lvwUpdates, sortproc);
                    lookupinfo.Clear();

                    //queued delegates to call after all other elements are added.
                    //this is used for adding patches last.
                    Queue <Action> DeferPatchItems = new Queue <Action>();
                    var            Typelookup      = new Dictionary <int, BCUpdate.UpdateInfo>();
                    try
                    {
                        foreach (BCUpdate.UpdateInfo looper in updateobj.LoadedUpdates)
                        {
                            var loopupdate = looper;
                            //we copy to a local variable because otherwise how a foreach control variable
                            //is closed over can be compiler specific.
                            Dictionary <int, BCUpdate.UpdateInfo> typelookup = Typelookup;
                            loopupdate.Tag = new DrawItemData("", null, null);

                            Action loopbody = (() =>
                            {
                                Color useForeColor = SystemColors.WindowText;
                                String usepatchString = "";
                                if (loopupdate.DownloadFor > 0)
                                {
                                    if (!typelookup.ContainsKey(loopupdate.DownloadFor))
                                    {
                                        usepatchString = "<Unknown>";
                                    }
                                    else
                                    {
                                        var appliedto = typelookup[loopupdate.DownloadFor];
                                        usepatchString = appliedto.DlName;
                                        if (updateobj.getinstalledVersion(appliedto.dlID) == "")
                                        {
                                            useForeColor = SystemColors.GrayText;
                                            usepatchString = "<" + appliedto.DlName + " Not Installed>";
                                        }
                                    }
                                }
                                string[] createdstrings = new string[] { loopupdate.DlName, updateobj.getinstalledVersion(loopupdate.dlID), loopupdate.UpdateVersion, "0", ByteSizeFormatter.FormatSize(loopupdate.FileSize), usepatchString };

                                ListViewItem newitem = new ListViewItem(createdstrings);
                                ((DrawItemData)loopupdate.Tag).lvwitem = newitem;
                                newitem.Tag = loopupdate;
                                newitem.ForeColor = useForeColor;
                                lookupinfo.Add(loopupdate, newitem);
                                lvwUpdates.Items.Add(newitem);
                                typelookup.Add(loopupdate.dlID, loopupdate);
                            });

                            //if we need to defer it, add it to the queue. Otherwise, call it now.
                            if (loopupdate.DownloadFor == 0)
                            {
                                loopbody();
                            }
                            else
                            {
                                DeferPatchItems.Enqueue(loopbody);
                            }
                        }

                        while (DeferPatchItems.Any())
                        {
                            DeferPatchItems.Dequeue()();
                        }
                    }
                    catch (Exception except)
                    {
                        switch (
                            MessageBox.Show(
                                "The Following Exception occured trying to retrieve update information:\n" +
                                except.ToString(), "Unexpected Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)
                            )
                        {
                        case DialogResult.Retry:
                            goto tryagain;

                        case DialogResult.Cancel:
                            Close();
                            break;
                        }
                    }
                    break;

                case EUpdateMode.Update_Immediate:
                    //resize to Grp
                    Debug.Print("Immediate Update...");
                    //grpBasicUpdate.Location = new Point(ClientRectangle.Left, ClientRectangle.Top);
                    ClientSize = grpBasicUpdate.Size;
                    fraavailupdates.Hide();
                    MinimizeBox            = true;
                    terminateonupdate      = true;
                    grpBasicUpdate.Visible = true;
                    grpBasicUpdate.BringToFront();
                    this.Invalidate();
                    grpBasicUpdate.Invalidate();
                    grpBasicUpdate.Update();
                    this.Invalidate();
                    this.Update();
                    Debug.Print("grpBasicUpdate.Visible=" + grpBasicUpdate.Visible);
                    immediateupdate.CancelDownload();

                    String downloadresult = immediateupdate.DownloadUpdate(progressroutine, completionroutine);
                    if (updatingItems == null)
                    {
                        updatingItems = new List <BCUpdate.UpdateInfo>();
                    }
                    updatingItems.Add(immediateupdate);



                    break;
                }

                Cursor.Current = Cursors.Default;
            }
            catch (Exception exx)
            {
                panRefreshing.Visible = true;
                panRefreshing.BringToFront();
                panRefreshing.Location = new Point(0, 0);
                panRefreshing.Size     = new Size(ClientSize.Width, panLower.Top);
                lblrefreshing.Text     = "An Exception occured retrieving update information.";
                txtException.Text      = exx.ToString();

                btnDownload.Visible = false;
            }
        }