Beispiel #1
0
        //_________________________________________________________________________________________________
        //_________________________________________________________________________________________________
        protected void myWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            changes = false;
            BackgroundWorker sendingWorker = (BackgroundWorker)sender; //Capture the BackgroundWorker that fired the event
            FIMServer        FIMSrv        = (FIMServer)e.Argument;    //Collect the array of objects the we recived from the main thread

            int           maxValue = (int)FIMSrv.num;                  //Get the numeric value from inside the objects array, don't forget to cast
            StringBuilder sb       = new StringBuilder();              //Declare a new string builder to store the result.
            // Conect to servers
            string sMsg = "Connecting " + FIMSrv.label + ": " + WmiHelper.ConnectServer(FIMSrv);

            sb.Append(string.Format("{0}{1}", sMsg, Environment.NewLine));
            Log(sb.ToString());

            ResultProfile result = new ResultProfile();

            result.r = "success";
            // Clear logs
            WmiHelper.ClearRuns(FIMSrv);
            // Execute profiles
            for (int i = 1; i <= maxValue && result.r == "success"; i++) //Start a for loop
            {
                if (!sendingWorker.CancellationPending)                  //At each iteration of the loop, check if there is a cancellation request pending
                {
                    result = PerformHeavyOperation(FIMSrv);
                    sMsg   = Environment.NewLine + "Result: " + FIMSrv.label + " [" + FIMSrv.lastRun + "]: " + result.r + result.desc + Environment.NewLine;
                    //if (sMsg.Contains("error")) e.Result = "Error";
                    sb.Append(sMsg);                 //Append the result to the string builder
                    sendingWorker.ReportProgress(i); //Report our progress to the main thread
                    Log(sb.ToString(), result.changes);
                    System.Threading.Tasks.Task.Delay(5000);
                }
                else
                {
                    e.Cancel = true; //If a cancellation request is pending,assgine this flag a value of true
                    break;           // If a cancellation request is pending, break to exit the loop
                }
                changes |= (result.changes > 0);
            }

            e.Result = sb.ToString();// Send our result to the main thread!
        }
Beispiel #2
0
        //_________________________________________________________________________________________________
        //_________________________________________________________________________________________________
        private ResultProfile PerformHeavyOperation(FIMServer FIMSrv)
        {
            ResultProfile r = new ResultProfile();

            r.r = "success";
            if (FIMSrv.runPf == "DJ")
            {
                for (int i = 0; i < FIMSrv.MAs.Count && r.r == "success"; i++)
                {
                    r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflEDIS);
                }
            }
            if (FIMSrv.runPf == "FJ")
            {
                for (int i = 0; i < FIMSrv.MAs.Count && r.r == "success"; i++)
                {
                    r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflEFIS);
                }
            }
            if (FIMSrv.runPf == "DS")
            {
                for (int i = 0; i < FIMSrv.MAs.Count && r.r == "success"; i++)
                {
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflE);
                    }
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflDI);
                    }
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflDS);
                    }
                }
            }
            if (FIMSrv.runPf == "FS")
            {
                for (int i = 0; i < FIMSrv.MAs.Count && r.r == "success"; i++)
                {
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflE);
                    }
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflFI);
                    }
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflFS);
                    }
                }
            }
            if (FIMSrv.runPf == "DSNOE")
            {
                for (int i = 0; i < FIMSrv.MAs.Count && r.r == "success"; i++)
                {
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflDI);
                    }
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflDS);
                    }
                }
            }
            if (FIMSrv.runPf == "FSNOE")
            {
                for (int i = 0; i < FIMSrv.MAs.Count && r.r == "success"; i++)
                {
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflFI);
                    }
                    if (r.r == "success")
                    {
                        r = WmiHelper.RunProfile(FIMSrv, i, FIMSrv.MAs[i].pflFS);
                    }
                }
            }
            return(r);
        }