Example #1
0
        /// <summary>
        /// Validate
        /// </summary>
        /// <param name="pIsUpdate"></param>
        /// <returns></returns>
        public bool Validate(bool pIsUpdate)
        {
            if (String.IsNullOrEmpty(ContentModuleId))
            {
                return(false);
            }

            if (String.IsNullOrEmpty(UserID))
            {
                return(false);
            }

            if (!pIsUpdate)
            {
                if (DateTime.MinValue.CompareTo(DateOfStart) > 0)
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(CompletionStatus.ToString()))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Runs the given Build Stage
        /// </summary>
        /// <returns></returns>
        public bool Execute()
        {
            try {
                // Start stage timer
                _stopwatch = Stopwatch.StartNew();

                Console.ForegroundColor = Color.WhiteSmoke;

                Misc.WriteMainHeader("SlugCI::  " + Name);


                // Set log level to std.  Let the process override if necessary.
                Logger.LogLevel = LogLevel.Normal;


                if (ShouldSkip)
                {
                    AOT_Warning("Stage skipped due to skip stage setting being set.");
                    CompletionStatus = StageCompletionStatusEnum.Skipped;
                    _stopwatch.Stop();
                    return(true);
                }

                CompletionStatus = StageCompletionStatusEnum.InProcess;
                Finished(ExecuteProcess());


                string finalMsg = String.Format("Stage Result:  {0}", CompletionStatus.ToString());

                Color lineColor = CompletionStatus switch
                {
                    StageCompletionStatusEnum.Success => Color.Green,
                    StageCompletionStatusEnum.Skipped => Color.Cyan,
                    StageCompletionStatusEnum.Warning => Color.Yellow,
                    _ => Color.Red,
                };
                AOT_Normal(finalMsg, lineColor);


                // Return success / Failure result
                if (CompletionStatus >= StageCompletionStatusEnum.Warning)
                {
                    return(true);
                }
            }
            catch (ProcessException p) {
                CompletionStatus = StageCompletionStatusEnum.Failure;
                AOT_Error(p);
                //Logger.Error(p,true);
            }
            catch (Exception e) {
                CompletionStatus = StageCompletionStatusEnum.Failure;
                AOT_Error(e);
                //Logger.Error(e);
            }
            return(false);
        }
Example #3
0
        private async void RunComplexButton_Click(object sender, RoutedEventArgs e)
        {
            if (Validate())
            {
                string           Src    = SourceTextBox.Text;
                string           Dst    = DestinationTextBox.Text;
                CompletionStatus Result = await Task.Run(() => ExecuteComplex(Src, Dst));

                MessageBox.Show(Result.ToString(), "Encoding Result");
            }
        }
        public override bool Execute()
        {
            if (string.IsNullOrEmpty(_applicationName))
            {
                base.Log.LogError("Application property must be set");
                return(false);
            }

            int  resumedServiceCount = 0;
            bool success             = true;
            bool resumeAll           = (_applicationName.Trim() == "*");

            base.Log.LogMessage(
                MessageImportance.Normal,
                "Attempting to resume all service instances for BizTalk app '{0}'...", resumeAll ? "[ALL APPS]" : _applicationName);

            using (BizTalkOperations operations = new BizTalkOperations())
            {
                // Get all service instances in the message box.
                // This is terribly inefficient -- BizTalkOperations has a way to directly query and filter by app, but the classes are Internal.
                // Could use reflection to call it anyway, but risks compatibility across BizTalk releases.
                foreach (Instance instance in operations.GetServiceInstances())
                {
                    MessageBoxServiceInstance mbsi = instance as MessageBoxServiceInstance;

                    if (mbsi != null)
                    {
                        // Only resume if the application matches the one we are interested in.  "*" will match all apps.
                        bool resumeThisInstance = (resumeAll || (string.Compare(mbsi.Application, _applicationName, true) == 0));
                        bool suspended          = ((mbsi.InstanceStatus & InstanceStatus.SuspendedAll) != InstanceStatus.None);

                        if (resumeThisInstance && suspended)
                        {
                            CompletionStatus status = operations.ResumeInstance(mbsi.ID);

                            if (status != CompletionStatus.Succeeded)
                            {
                                this.Log.LogWarning("Could not resume instance {0}.  Status is {1}.", mbsi.ID, status.ToString());
                                success = false;
                            }
                            else
                            {
                                resumedServiceCount++;
                            }

                            if (resumedServiceCount % 5000 == 0)
                            {
                                base.Log.LogMessage(
                                    MessageImportance.Normal,
                                    "Resumed {0} service instances for BizTalk app '{1}'.", resumedServiceCount, resumeAll ? "[ALL APPS]" : _applicationName);
                            }
                        }
                    }
                }
            }

            base.Log.LogMessage(
                MessageImportance.Normal,
                "Finished resuming {0} service instances for BizTalk app '{1}'.", resumedServiceCount, resumeAll ? "[ALL APPS]" : _applicationName);

            return(success);
        }
Example #5
0
        public static void ProcessCharacter(
            Interactor intr,
            TaskQueue queue
            )
        {
            var  currentTask = queue.NextTask;
            uint charIdx     = currentTask.CharIdx;
            //string charLabel = intr.AccountSettings.CharNode(charIdx).GetAttribute("name");
            string charLabel = intr.AccountSettings.CharNames[(int)charIdx];
            //string charLabel = queue.NextTask.CharIdxLabel;
            int  invokesToday    = intr.AccountStates.GetCharStateOr(charIdx, "invokesToday", 0);
            bool skipInvocation  = false;
            bool skipMaintInven  = false;
            bool skipProfessions = false;

            DateTime invokesCompletedForDay = intr.AccountStates.GetCharStateOr(charIdx,
                                                                                "invokesCompleteFor", Global.Default.SomeOldDate);

            if (invokesCompletedForDay == TaskQueue.TodaysGameDate)
            {
                // Skip invocation if it's already done.
                skipInvocation = true;
            }
            else if (invokesCompletedForDay < TaskQueue.TodaysGameDate && invokesToday < 2 &&
                     currentTask.Kind == TaskKind.Invocation)
            {
                // Skip professions for the first few invokes of the day.
                intr.Log(LogEntryType.Info, "Skipping profession processing this round.");
                skipProfessions = true;
            }

            // Skip inventory processing for the first two invokes [0, 1] and every non invoke task:
            if (invokesToday < 2 || currentTask.Kind != TaskKind.Invocation)
            {
                intr.Log(LogEntryType.Info, "Skipping inventory processing this round.");
                skipMaintInven = true;
            }


            CompletionStatus invocationStatus     = CompletionStatus.None;
            CompletionStatus professionsStatus    = CompletionStatus.None;
            CompletionStatus maintStatus          = CompletionStatus.None;
            bool             processingIncomplete = false;

            intr.Log("Starting processing for " + charLabel + " ...");

            // Reset `invokesToday` if `invokesCompletedOn` is
            if (invokesToday >= 6)
            {
                if (currentTask.Kind == TaskKind.Invocation)
                {
                    if (invokesCompletedForDay == TaskQueue.TodaysGameDate)
                    {
                        intr.Log(LogEntryType.Info, charLabel +
                                 " has already invoked 6 times today. Queuing invocation for tomorrow");
                        queue.AdvanceInvocationTask(intr, charIdx, invokesToday, false);
                        skipInvocation = true;
                        skipMaintInven = true;
                        //queue.QueueSubsequentInvocationTask(intr, charIdx, invokesToday);
                        return;
                    }
                    else if (invokesCompletedForDay < TaskQueue.TodaysGameDate)
                    {
                        intr.Log(LogEntryType.Info, charLabel + ": Resetting InvokesToday to 0.");
                        invokesToday = 0;
                        intr.AccountStates.SaveCharState(invokesToday, charIdx, "invokesToday");
                    }
                    else
                    {
                        var errMsg = charLabel + ": Internal error. `invokesCompletedOn` is in the future.";
                        intr.Log(LogEntryType.Fatal, errMsg);
                        throw new Exception(errMsg);
                    }
                }
            }

            // CHECK TO SEE IF THERE ARE ANY UPCOMING TASKS FOR CHARACTER IN THE NEXT 29:59 MINUTES
            // IF SO -> CHECK TO SEE IF THERE ARE ANY TASKS IN THE 29:59 (TOTAL 59:59) MINUTES AFTER THAT
            //	IF NOT -> MERGE TASKS
            //	IF SO -> CONTINUE

            if (!ProduceClientState(intr, ClientState.CharSelect, 0))
            {
                return;
            }

            intr.Log(LogEntryType.Info, "ProcessCharacter(): Selecting " + charLabel + " ...");

            if (!SelectCharacter(intr, charIdx, ENTER_WORLD))
            {
                return;
            }

            // [DO NOT REMOVE]:
            //
            //int selectAttemptCount = 0;

            //while (!SelectCharacter(intr, charIdx, ENTER_WORLD)) {
            //	// Determine if login has been a success:
            //	if (!intr.WaitUntil(90, ClientState.InWorld, Game.IsClientState, CharSelectFailure, 0)) {
            //		ProduceClientState(intr, ClientState.CharSelect, attemptCount);
            //		SelectCharacter(intr, charIdx, enterWorld, attemptCount);
            //		//return false;
            //	}
            //	ClearDialogues(intr);

            //	selectAttemptCount += 1;

            //	if (selectAttemptCount >= SELECT_ATTEMPTS_MAX) {
            //		intr.Log("ProcessCharacter(): Fatal error selecting " + charLabel + ".", LogEntryType.Fatal);
            //		return;
            //	}
            //}

            // NEW PLAN:
            // SelectCharacter()
            // Determine if client state is still ClientState.CharSelect
            //    If so, FatalWithScreenShot
            //    If not, start the 'Verification' loop which will look for signs of the 'World'
            //
            //
            // END [DO NOT REMOVE]

            if (!ENTER_WORLD)
            {
                                #pragma warning disable CS0162 // Unreachable code detected
                queue.AdvanceInvocationTask(intr, charIdx, invokesToday, false);
                                #pragma warning restore CS0162 // Unreachable code detected
                return;
            }

            // ################################## CLEAR AND MOVE ##################################
            intr.Wait(1500);
            ClearDialogues(intr);
            MoveAround(intr);

            // ############################### INVENTORY MAINTENANCE ##############################
            if (!skipMaintInven)
            {
                intr.Log(LogEntryType.Info, "ProcessCharacter(): Maintaining inventory for " + charLabel + " ...");
                maintStatus = MaintainInventory(intr, charIdx);
                intr.Log(LogEntryType.Info, "ProcessCharacter(): Inventory maintenance status: " + maintStatus.ToString());
            }

            // #################################### INVOCATION ####################################
            if (!skipInvocation)
            {
                intr.Log(LogEntryType.Info, "ProcessCharacter(): Invoking for " + charLabel + " ...");
                invocationStatus = Invoke(intr, charIdx);
                intr.Log(LogEntryType.Info, "ProcessCharacter(): Invocation status: " + invocationStatus.ToString());
            }

            // ################################### PROFESSIONS ####################################
            var professionTasksProcessed = new List <ProfessionTaskResult>(9);

            if (!skipProfessions)
            {
                intr.Log(LogEntryType.Info, "ProcessCharacter(): Maintaining profession tasks for " + charLabel + " ...");
                professionsStatus = MaintainProfs(intr, charIdx, professionTasksProcessed);
                intr.Log(LogEntryType.Info, "ProcessCharacter(): Professions status: " + professionsStatus.ToString());
            }


            // ##################################### LOG OUT ######################################
            LogOut(intr);

            // ########################### INVOCATION QUEUE AND SETTINGS ##########################
            if (invocationStatus == CompletionStatus.Complete)
            {
                intr.Log(LogEntryType.Normal, "Invocation task for " + charLabel + ": Complete.");
                queue.AdvanceInvocationTask(intr, charIdx, invokesToday, true);
            }
            else if (invocationStatus == CompletionStatus.DayComplete)
            {
                intr.Log(LogEntryType.Normal, "Daily invocations for " + charLabel + ": Complete for day.");
                queue.AdvanceInvocationTask(intr, charIdx, 6, true);
            }
            else if (invocationStatus == CompletionStatus.Immature && currentTask.Kind == TaskKind.Invocation)
            {
                intr.Log(LogEntryType.Normal, "Invocation task for " + charLabel + ": Immature.");
                intr.Log(LogEntryType.Info, "Re-queuing task for " + charLabel + ".");
                queue.AdvanceInvocationTask(intr, charIdx, invokesToday, false);
            }
            else if (invocationStatus == CompletionStatus.Failed && currentTask.Kind == TaskKind.Invocation)
            {
                intr.Log(LogEntryType.Normal, "Invocation task for " + charLabel + ": Failed.");
                queue.AdvanceInvocationTask(intr, charIdx, invokesToday, false);
                //processingIncomplete = true;
            }
            else if (invocationStatus == CompletionStatus.Cancelled && currentTask.Kind == TaskKind.Invocation)
            {
                intr.Log(LogEntryType.Normal, "Invocation task for " + charLabel + ": Cancelled.");
                //processingIncomplete = true;
            }

            // ######################### PROFESSIONS QUEUE AND SETTINGS ###########################
            intr.Log(LogEntryType.Normal, "Profession task for " + charLabel + ": " + professionsStatus.ToString()
                     + ", items complete: " + professionTasksProcessed.Count);
            if (professionsStatus == CompletionStatus.Complete)
            {
                foreach (ProfessionTaskResult taskResult in professionTasksProcessed)
                {
                    queue.AdvanceProfessionsTask(intr, charIdx, taskResult.TaskId, taskResult.BonusFactor);
                }
            }
            else if (professionsStatus == CompletionStatus.Stuck && currentTask.Kind == TaskKind.Profession)
            {
                // I guess we have to do this to progress a task which is stuck:
                queue.AdvanceProfessionsTask(intr, currentTask.CharIdx, currentTask.TaskId, currentTask.BonusFactor);
            }
            else if (professionsStatus == CompletionStatus.Immature && currentTask.Kind == TaskKind.Profession)
            {
                // Pretty sure we still need this:
                queue.AdvanceProfessionsTask(intr, currentTask.CharIdx, currentTask.TaskId, currentTask.BonusFactor);
            }
            else if (currentTask.Kind == TaskKind.Profession)
            {
                // IF the status was NOT `CompletionStatus.Complete` AND the next task is a profession task for this character:
                processingIncomplete = true;
                // CANCELLED OR FAILED
                //queue.AdvanceTask(intr, currentTask.CharIdx, TaskKind.Profession, currentTask.TaskId);		// SAME
            }

            //// EVALUATE WHETHER OR NOT TO BRING THIS BACK:
            //if (!processingIncomplete && !skipProfessions && !skipInvocation) {
            //	intr.Log(LogEntryType.Normal, "Advancing all matured tasks for character {0}.", charIdx.ToString());
            //	queue.AdvanceMatured(intr, charIdx);
            //}

            if (processingIncomplete)
            {
                intr.Log(LogEntryType.Normal, "Processing incomplete for " + charLabel + ".");
            }
            else
            {
                intr.Log(LogEntryType.Normal, "Processing complete for " + charLabel + ".");
            }
        }
        public override bool Execute()
        {
            if (string.IsNullOrEmpty(_applicationName))
            {
                base.Log.LogError("Application property must be set");
                return(false);
            }

            const int MaxRetries = 3;

            bool success = true;
            int  terminatedServiceCount = 0;
            bool removeAll = (_applicationName.Trim() == "*");

            base.Log.LogMessage(
                MessageImportance.Normal,
                "Attempting to terminate all service instances for BizTalk app '{0}'...", removeAll ? "[ALL APPS]" : _applicationName);

            for (int retryCount = 0; retryCount < MaxRetries; retryCount++)
            {
                success = true;

                // Create a new BizTalkOperations instance each time to avoid potential caching issues
                using (BizTalkOperations operations = new BizTalkOperations())
                {
                    // Get all service instances in the message box.
                    // This is terribly inefficient -- BizTalkOperations has a way to directly query and filter by app, but the classes are Internal.
                    // Could use reflection to call it anyway, but risks compatibility across BizTalk releases.
                    foreach (Instance instance in operations.GetServiceInstances())
                    {
                        MessageBoxServiceInstance mbsi = instance as MessageBoxServiceInstance;

                        if (mbsi == null)
                        {
                            continue;
                        }

                        // Only terminate if the application matches the one we are interested in.  "*" will match all apps.
                        bool removeThisInstance = (removeAll || (string.Compare(mbsi.Application, _applicationName, true) == 0));
                        bool running            = ((mbsi.InstanceStatus & InstanceStatus.RunningAll) != InstanceStatus.None);
                        bool suspended          = ((mbsi.InstanceStatus & InstanceStatus.SuspendedAll) != InstanceStatus.None);

                        if (removeThisInstance && (running || suspended))
                        {
                            CompletionStatus status = operations.TerminateInstance(mbsi.ID);

                            if (status != CompletionStatus.Succeeded)
                            {
                                if (instance.Class == ServiceClass.RoutingFailure)
                                {
                                    this.Log.LogMessage(MessageImportance.Low, "Could not terminate routing failure {0}.  It was probably terminated by a linked instance.", mbsi.ID);
                                }
                                else
                                {
                                    if (retryCount == MaxRetries - 1)
                                    {
                                        this.Log.LogError("Could not terminate instance {0}.  Status is {1}.", mbsi.ID, status.ToString());
                                    }
                                    success = false;
                                }
                            }
                            else
                            {
                                terminatedServiceCount++;
                            }
                        }
                    }
                }

                if (success)
                {
                    break;
                }
            }

            base.Log.LogMessage(
                MessageImportance.Normal,
                "Terminated {0} service instances for BizTalk app '{1}'.", terminatedServiceCount, removeAll ? "[ALL APPS]" : _applicationName);

            return(success);
        }