예제 #1
0
        private PriorityQueueItem <TValue, TPriority> RemoveAt(Int32 index)
        {
            PriorityQueueItem <TValue, TPriority> o = items[index];

            --numItems;
            // move the last item to fill the hole
            PriorityQueueItem <TValue, TPriority> tmp = items[numItems];

            // If you forget to clear this, you have a potential memory leak.
            items[numItems] = default(PriorityQueueItem <TValue, TPriority>);
            if (numItems > 0 && index != numItems)
            {
                // If the new item is greater than its parent, bubble up.
                int i      = index;
                int parent = (i - 1) / 2;
                while (compareFunc(tmp.Priority, items[parent].Priority) > 0)
                {
                    items[i] = items[parent];
                    i        = parent;
                    parent   = (i - 1) / 2;
                }

                // if i == index, then we didn't move the item up
                if (i == index)
                {
                    // bubble down ...
                    while (i < (numItems) / 2)
                    {
                        int j = (2 * i) + 1;
                        if ((j < numItems - 1) && (compareFunc(items[j].Priority, items[j + 1].Priority) < 0))
                        {
                            ++j;
                        }
                        if (compareFunc(items[j].Priority, tmp.Priority) <= 0)
                        {
                            break;
                        }
                        items[i] = items[j];
                        i        = j;
                    }
                }
                // Be sure to store the item in its place.
                items[i] = tmp;
            }
            //if (!VerifyQueue())
            //{
            //    Console.WriteLine("ERROR: Queue out of order!");
            //}
            return(o);
        }
예제 #2
0
        public void Enqueue(PriorityQueueItem <TValue, TPriority> newItem)
        {
            if (numItems == capacity)
            {
                // need to increase capacity
                // grow by 50 percent
                SetCapacity((3 * Capacity) / 2);
            }

            int i = numItems;

            ++numItems;
            while ((i > 0) && (compareFunc(items[(i - 1) / 2].Priority, newItem.Priority) < 0))
            {
                items[i] = items[(i - 1) / 2];
                i        = (i - 1) / 2;
            }
            items[i] = newItem;
            //if (!VerifyQueue())
            //{
            //    Console.WriteLine("ERROR: Queue out of order!");
            //}
        }
예제 #3
0
        private void rozpocznijBackup()
        {
            if (InvokeRequired)
            {
                BeginInvoke(new rozpoczlijBackupDelegate(this.rozpocznijBackup));
                return;
            }
            try
            {
                this.Hide();

                string sSciezka = String.Empty;

                applicationConfig oApplication = new applicationConfig();
                oApplication.sPathToConfigFile = Application.StartupPath + @"\settings.xml";
                oApplication.ReadBinary();

                if (oApplication.aUstawienia.aUstawienia.ContainsKey("sciezka"))
                {
                    sSciezka = Convert.ToString(oApplication.aUstawienia.aUstawienia["sciezka"]);
                }
                else
                {
                    sSciezka = Application.StartupPath;
                }

                this.getListServers();

                _iAllCnt = aListSerwerow.Count;
                int iCnt;
                progressBar1.Maximum = _iAllCnt;

                for (iCnt = 0; iCnt < _iAllCnt; iCnt++)
                {
                    if (aListSerwerow[iCnt]["type"] == "mysql")
                    {
                        pq.Enqueue(new MySqlBackup(
                                       aListSerwerow[iCnt]["host"],
                                       aListSerwerow[iCnt]["baza"],
                                       aListSerwerow[iCnt]["haslo"],
                                       aListSerwerow[iCnt]["login"],
                                       sSciezka), Convert.ToInt32(aListSerwerow[iCnt]["priorytet"]));
                    }
                }

                progressBar1.Value = 0;
                iCnt = 1;
                while (pq.Count > 0)
                {
                    PriorityQueueItem <Backup, int> item = pq.Dequeue();

                    sStripStatus.Text = "Tworzenie kopi bazy: " + item.Value.sBazaDanych;

                    int iStep = (int)(iCnt / _iAllCnt);

                    string sTxt;
                    if (sStripStatus.Text.Length > 60)
                    {
                        sTxt = sStripStatus.Text.Substring(1, 60);
                    }
                    else
                    {
                        sTxt = sStripStatus.Text;
                    }

                    notifyIcon.Text = sTxt + "...";
                    notifyIcon.ShowBalloonTip(_iTimeShowBaloon, "Tworznie kopi bazy danych", sTxt, ToolTipIcon.Info);

                    item.Value.makeBackup();

                    if (!item.Value.sBaseState)
                    {
                        notifyIcon.Text = "Błąd tworzenia kopi bazy: " + item.Value.sBazaDanych + "...";
                        notifyIcon.ShowBalloonTip(_iTimeShowBaloon, "Tworznie kopi bazy danych", notifyIcon.Text, ToolTipIcon.Error);
                        System.Threading.Thread.Sleep(1000);
                    }
                }

                pq.Clear();
            }
            catch (Win32Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "Win32 Error!!!");
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "IO Error");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "Critical Error");
            }
        }