コード例 #1
0
        void query(object state)
        {
            Tuple <string, MachineInfo.Files_Bytes> tuple = (Tuple <string, MachineInfo.Files_Bytes>)state;
            string machine = tuple.Item1;

            MachineInfo.Files_Bytes total_cb = tuple.Item2;
            List <object[]>         new_rows = new List <object[]>();

            try
            {
                if (!MachineInfo.isReachableAndValidNetbios(machine))
                {
                    new_rows.Add(new object[] { machine, MachineInfo.NOTREACHABLE });
                    worker.ReportProgress(REPORT_NEWROWS_ERROR, new_rows);
                }
                else
                {
                    Dictionary <string, Tuple <int, long, DateTime, Dictionary <string, long> > > ret = MachineInfo.GetProfilesSize(machine, total_cb);

                    bool            aborted   = total_cb.aborted;
                    string          retString = MachineInfo.GetProfilesSizeAsString(ret, 100);
                    List <object[]> retArrays = MachineInfo.GetProfilesSizeAsObjectArrayList(ret, machine);

                    if (!aborted)
                    {
                        Console.WriteLine(retString);
                        if (retArrays.Count == 0)
                        {
                            new_rows.Add(new object[] { machine, MachineInfo.NOPROFILEFOUND });
                            worker.ReportProgress(REPORT_NEWROWS, new_rows);
                        }
                        else
                        {
                            new_rows.AddRange(retArrays);
                            worker.ReportProgress(REPORT_NEWROWS, new_rows);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Aborted.");
                        new_rows.Add(new object[] { machine, Value_Batsu + (total_cb.markers.Count == 0 ? MachineInfo.NOPROFILEFOUND : total_cb.markers.Aggregate((x, y) => x + "+" + y)) });
                        worker.ReportProgress(REPORT_NEWROWS_ERROR, new_rows);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(machine + " - Processing error: " + e.Message
                                  //+ "\n" + e.ToString()
                                  );
            }

            active.Remove(tuple);
        }
コード例 #2
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            normSearch1();
            foreach (DataGridViewRow row in table.Rows)
            {
                row.Selected = false;
            }
            while (active.Count > 0)
            {
                foreach (var tuple in active.ToArray())
                {
                    MachineInfo.Files_Bytes total_cb = tuple.Item2;
                    if (worker.CancellationPending)
                    {
                        total_cb.aborted = true;
                    }

                    //periodic table updates
                    string machine = tuple.Item1;
                    foreach (DataGridViewRow row in table.Rows)
                    {
                        string row_machine  = "" + row.Cells[0].Value;
                        string row_username = "" + row.Cells[1].Value;
                        if (row_machine == machine &&
                            (row_username == Value_Question ||
                             (row_username + row.Cells[1].Value).StartsWith(Value_Batsu) ||
                             (row_username + row.Cells[1].Value).StartsWith(Value_Dots)
                            ))
                        {
                            row.SetValues(new object[] { machine,
                                                         (total_cb.aborted ? Value_Batsu : Value_Dots)
                                                         + (!total_cb.connected ? TRYINGTOREACH :
                                                            (total_cb.markers.Count == 0 ? MachineInfo.NOPROFILEFOUND : total_cb.markers.Aggregate((x, y) => x + "+" + y))),
                                                         total_cb.scandate.ToString("yyyy/MM/dd"), total_cb.files, total_cb.bytes / (1024 * 1024) });
                            row.DefaultCellStyle.BackColor = Color.LightYellow;
                        }
                    }
                }

                if (worker.CancellationPending)
                {
                    Console.WriteLine("Stop requested. Waiting remainder to abort..." + active.Count);
                }
                else
                {
                    Console.WriteLine("All tasks were queued. Waiting remainder to finish..." + active.Count);
                }
                //worker.ReportProgress(REPORT_COMPLETE, null);
                Thread.Sleep(5000);
            }
        }