예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncOperation"/> class.
 /// </summary>
 internal AsyncOperation(ulong operationId, string name)
 {
     this.Id     = operationId;
     this.Name   = name;
     this.Status = AsyncOperationStatus.None;
     this.Type   = AsyncOperationType.Start;
 }
예제 #2
0
        public static string GetItemText(object type, object status, object displayName, object percentComplete, object originalExtAttributes)
        {
            AsyncOperationType   type2   = (AsyncOperationType)type;
            AsyncOperationStatus status2 = (AsyncOperationStatus)status;

            switch (type2)
            {
            case AsyncOperationType.ImportPST:
            case AsyncOperationType.ExportPST:
                if (originalExtAttributes != DBNull.Value)
                {
                    KeyValuePair <string, LocalizedString>[] source       = (KeyValuePair <string, LocalizedString>[])originalExtAttributes;
                    KeyValuePair <string, LocalizedString>   keyValuePair = source.FirstOrDefault((KeyValuePair <string, LocalizedString> x) => x.Key == "Mailbox");
                    if (keyValuePair.Key == "Mailbox")
                    {
                        displayName = keyValuePair.Value.ToString();
                    }
                }
                return(NotificationService.GetItemTextForProcessingPST(type2, status2, displayName, percentComplete));

            case AsyncOperationType.Migration:
                return(NotificationService.GetItemTextForMigration(type2, status2, displayName, originalExtAttributes));

            case AsyncOperationType.CertExpiry:
                return(NotificationService.GetItemTextForCertExpiry(status2, displayName, originalExtAttributes));
            }
            return(NotificationService.GetItemTextDefault(type2, status2, displayName, percentComplete));
        }
예제 #3
0
        private static string GetDescription(AsyncOperationType type)
        {
            string description;

            switch (type)
            {
            case AsyncOperationType.LoadCatalog:
                description = "Подождите, идет формирование страницы прайс листа";
                break;

            case AsyncOperationType.LoadBrands:
                description = "Подождите, идет формирование списка брендов";
                break;

            case AsyncOperationType.LoadDirectories:
                description = "Подождите, идет формирование списка каталогов";
                break;

            default:
                description = "Подождите, идет загрузка данных";
                break;
            }

            return(description);
        }
예제 #4
0
        /// <summary>
        /// Schedules the next enabled operation, which can include the currently executing operation.
        /// </summary>
        /// <param name="type">Type of the operation.</param>
        /// <param name="isYielding">True if the current operation is yielding, else false.</param>
        /// <param name="hashArray">Hash Array for Locls, Semaphore or Synchronized Block.</param>
        /// <remarks>
        /// An enabled operation is one that is not blocked nor completed.
        /// </remarks>
        internal void ScheduleNextOperation(AsyncOperationType type = AsyncOperationType.Default, bool isYielding = false, int[] hashArray = null)
        {
            lock (this.SyncObject)
            {
                int?taskId = Task.CurrentId;

                // TODO: figure out if this check is still needed.
                // If the caller is the root task, then return.
                if (taskId != null && taskId == this.Runtime.RootTaskId)
                {
                    return;
                }

                AsyncOperation current = this.ScheduledOperation;
                this.ThrowExecutionCanceledExceptionIfDetached();
                if (current.Status != AsyncOperationStatus.Completed)
                {
                    // Checks if the current operation is controlled by the runtime.
                    if (ExecutingOperation.Value is null)
                    {
                        ThrowUncontrolledTaskException();
                    }
                }

                // Checks if the scheduling steps bound has been reached.
                this.CheckIfSchedulingStepsBoundIsReached();

                current.SetType(type);
                if (this.Configuration.IsProgramStateHashingEnabled)
                {
                    // Update the current operation with the hashed program state.
                    current.HashedProgramState = this.Runtime.GetHashedProgramState();

                    current.DefaultHashedState    = this.Runtime.GetProgramState("default", hashArray);
                    current.InboxOnlyHashedState  = this.Runtime.GetProgramState("inboxonly", hashArray);
                    current.CustomHashedState     = this.Runtime.GetProgramState("custom", hashArray);
                    current.CustomOnlyHashedState = this.Runtime.GetProgramState("custom-only", hashArray);
                }

                // Choose the next operation to schedule, if there is one enabled.
                if (!this.TryGetNextEnabledOperation(current, isYielding, out AsyncOperation next))
                {
                    IO.Debug.WriteLine("<ScheduleDebug> Schedule explored.");
                    this.HasFullyExploredSchedule = true;
                    this.Detach();
                }

                IO.Debug.WriteLine($"<ScheduleDebug> Scheduling the next operation of '{next.Name}'.");
                this.ScheduleTrace.AddSchedulingChoice(next.Id);
                if (current != next)
                {
                    // Pause the currently scheduled operation, and enable the next one.
                    this.ScheduledOperation = next;
                    this.PauseOperation(current);
                }
            }
        }
예제 #5
0
        private static string GetItemTextImp(AsyncOperationType type, AsyncOperationStatus status, object displayNameObj, object percentComplete, Func <string, string, LocalizedString> asyncProcessQueued, Func <string, string, string, LocalizedString> asyncProcessInProgressWithPercentage, Func <string, string, LocalizedString> asyncProcessInProgress, Func <string, string, LocalizedString> asyncProcessSuspended, Func <string, string, LocalizedString> asyncProcessCompleted, Func <string, string, LocalizedString> asyncProcessFailed, Func <string, string, LocalizedString> asyncProcessWaitingFinalization, Func <string, string, LocalizedString> asyncProcessCreated = null, Func <string, string, LocalizedString> asyncProcessCompleting = null, Func <string, string, LocalizedString> asyncProcessRemoving = null)
        {
            string arg    = (displayNameObj as string) ?? string.Empty;
            string result = string.Empty;
            string arg2   = DDIUtil.EnumToLocalizedString(type);

            switch (status)
            {
            case AsyncOperationStatus.Queued:
                result = asyncProcessQueued(arg2, arg);
                break;

            case AsyncOperationStatus.InProgress:
                result = ((percentComplete != DBNull.Value) ? asyncProcessInProgressWithPercentage(arg2, arg, percentComplete.ToString()) : asyncProcessInProgress(arg2, arg));
                break;

            case AsyncOperationStatus.Suspended:
                result = asyncProcessSuspended(arg2, arg);
                break;

            case AsyncOperationStatus.Completed:
                result = asyncProcessCompleted(arg2, arg);
                break;

            case AsyncOperationStatus.Failed:
                result = asyncProcessFailed(arg2, arg);
                break;

            case AsyncOperationStatus.WaitingForFinalization:
                result = asyncProcessWaitingFinalization(arg2, arg);
                break;

            case AsyncOperationStatus.Created:
                if (asyncProcessCreated != null)
                {
                    result = asyncProcessCreated(arg2, arg);
                }
                break;

            case AsyncOperationStatus.Completing:
                if (asyncProcessCompleting != null)
                {
                    result = asyncProcessCompleting(arg2, arg);
                }
                break;

            case AsyncOperationStatus.Removing:
                if (asyncProcessRemoving != null)
                {
                    result = asyncProcessRemoving(arg2, arg);
                }
                break;
            }
            return(result);
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskEntry"/> class.
 /// </summary>
 public TaskEntry(int id, bool enabled, AsyncOperationType opType, AsyncOperationTarget target, int targetId, int sendStepIndex)
 {
     this.Id            = id;
     this.Enabled       = enabled;
     this.Sleep         = false;
     this.Backtrack     = false;
     this.OpType        = opType;
     this.OpTarget      = target;
     this.TargetId      = targetId;
     this.SendStepIndex = sendStepIndex;
 }
예제 #7
0
        /// <summary>
        /// Transitions an <see cref="IAsyncResult"/> instance to a completed state.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies an invocation.</param>
        /// <param name="operationType">The expected operation type.</param>
        /// <param name="cancel">Boolean indicating whether or not the operation has been canceled.</param>
        /// <returns>A <see cref="DomainClientAsyncResult"/> reference.</returns>
        /// <exception cref="ArgumentNullException"> if <paramref name="asyncResult"/> is null.</exception>
        /// <exception cref="ArgumentException"> if <paramref name="asyncResult"/> is for another operation or was not created by this <see cref="DomainClient"/> instance.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/> has been canceled.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/>'s End* method has already been invoked.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/> has not completed.</exception>
        private DomainClientAsyncResult EndAsyncResult(IAsyncResult asyncResult, AsyncOperationType operationType, bool cancel)
        {
            DomainClientAsyncResult domainClientResult = asyncResult as DomainClientAsyncResult;

            if ((domainClientResult != null) && (!object.ReferenceEquals(this, domainClientResult.DomainClient) || domainClientResult.AsyncOperationType != operationType))
            {
                throw new ArgumentException(Resources.WrongAsyncResult, "asyncResult");
            }

            return(AsyncResultBase.EndAsyncOperation <DomainClientAsyncResult>(asyncResult, cancel));
        }
        /// <summary>
        /// Initializes a new <see cref="DomainClientAsyncResult"/> instance used for Query operations.
        /// </summary>
        /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
        /// <param name="callback">Optional <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        protected DomainClientAsyncResult(DomainClient domainClient, AsyncCallback callback, object asyncState)
            : base(callback, asyncState)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }

            this._asyncOperationType = AsyncOperationType.Query;
            this._domainClient = domainClient;
        }
예제 #9
0
        /// <summary>
        /// Initializes a new <see cref="DomainClientAsyncResult"/> instance used for Query operations.
        /// </summary>
        /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
        /// <param name="callback">Optional <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        protected DomainClientAsyncResult(DomainClient domainClient, AsyncCallback callback, object asyncState)
            : base(callback, asyncState)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }

            this._asyncOperationType = AsyncOperationType.Query;
            this._domainClient       = domainClient;
        }
        /// <summary>
        /// Initializes a new <see cref="DomainClientAsyncResult"/> instance used for Submit operations.
        /// </summary>
        /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
        /// <param name="entityChangeSet">The Submit operation <see cref="EntityChangeSet"/>.</param>
        /// <param name="callback">Optional <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        protected DomainClientAsyncResult(DomainClient domainClient, EntityChangeSet entityChangeSet, AsyncCallback callback, object asyncState)
            : base(callback, asyncState)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }

            this._asyncOperationType = AsyncOperationType.Submit;
            this._domainClient = domainClient;
            this._entityChangeSet = entityChangeSet;
        }
예제 #11
0
        /// <summary>
        /// Initializes a new <see cref="DomainClientAsyncResult"/> instance used for Submit operations.
        /// </summary>
        /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
        /// <param name="entityChangeSet">The Submit operation <see cref="EntityChangeSet"/>.</param>
        /// <param name="callback">Optional <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        protected DomainClientAsyncResult(DomainClient domainClient, EntityChangeSet entityChangeSet, AsyncCallback callback, object asyncState)
            : base(callback, asyncState)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }

            this._asyncOperationType = AsyncOperationType.Submit;
            this._domainClient       = domainClient;
            this._entityChangeSet    = entityChangeSet;
        }
예제 #12
0
        internal static object GetAsyncOperationType(IPropertyBag propertyPag)
        {
            AsyncOperationType asyncOperationType = AsyncOperationType.Unknown;
            string             text = (string)propertyPag[EwsStoreObjectSchema.ItemClass];

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            if (text.StartsWith("IPM.Notification."))
            {
                Enum.TryParse <AsyncOperationType>(text.Substring("IPM.Notification.".Length), true, out asyncOperationType);
            }
            return(asyncOperationType);
        }
예제 #13
0
        /// <summary>
        /// Adds an operation that cannot be cancelled.
        /// </summary>
        /// <param name="operation">The operation to add to the stack.</param>
        /// <param name="operationType">A classification of the operation.</param>
        public void PushOperation(Task operation, AsyncOperationType operationType)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            if (HasTaskInProgress())
            {
                throw new InvalidOperationException("Cannot add a task, one is still running.");
            }

            CurrentTask     = new NotifyTaskCompletion(operation);
            this.currentCts = null;
            CurrentTaskType = operationType;
        }
예제 #14
0
        /// <summary>
        /// Initializes a new <see cref="DomainClientAsyncResult"/> instance used for Invoke operations.
        /// </summary>
        /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
        /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
        /// <param name="callback">The <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        protected DomainClientAsyncResult(DomainClient domainClient, InvokeArgs invokeArgs, AsyncCallback callback, object asyncState)
            : base(callback, asyncState)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }
            if (invokeArgs == null)
            {
                throw new ArgumentNullException("invokeArgs");
            }

            this._asyncOperationType = AsyncOperationType.Invoke;
            this._domainClient       = domainClient;
            this._invokeArgs         = invokeArgs;
        }
예제 #15
0
        public static string GetStartedByText(object type, object status, object startedBy, object startTime)
        {
            AsyncOperationType   asyncOperationType   = (AsyncOperationType)type;
            AsyncOperationStatus asyncOperationStatus = (AsyncOperationStatus)status;
            string             result = Strings.ProcessStartedBy((startedBy as string) ?? string.Empty, (string)startTime);
            AsyncOperationType asyncOperationType2 = asyncOperationType;

            if (asyncOperationType2 != AsyncOperationType.Migration)
            {
                if (asyncOperationType2 == AsyncOperationType.CertExpiry)
                {
                    result = string.Empty;
                }
            }
            else if (asyncOperationStatus == AsyncOperationStatus.Created || asyncOperationStatus == AsyncOperationStatus.Removing)
            {
                result = string.Empty;
            }
            return(result);
        }
예제 #16
0
        public void PerformAsyncOperation <T, TResult>(
            AsyncOperationType type,
            Func <T, TResult> func,
            T param,
            Action <Exception, TResult> completeAction)
        {
            OperationStarted?.Invoke(this, new PriceEventArgs <AsyncOperationType>(type));
            var task = new Task <TResult>(() => func(param));

            if (taskScheduler == null)
            {
                task.ContinueWith(t => ProcessTaskResult(t, completeAction, type));
            }
            else
            {
                task.ContinueWith(t => ProcessTaskResult(t, completeAction, type), taskScheduler);
            }

            task.Start(TaskScheduler.Default);
        }
예제 #17
0
        public static string GetDetailPageId(object type, object status)
        {
            AsyncOperationType   asyncOperationType   = (AsyncOperationType)type;
            AsyncOperationStatus asyncOperationStatus = (AsyncOperationStatus)status;
            string             result = null;
            AsyncOperationType asyncOperationType2 = asyncOperationType;

            if (asyncOperationType2 != AsyncOperationType.Migration)
            {
                if (asyncOperationType2 == AsyncOperationType.CertExpiry)
                {
                    result = "Certificates";
                }
            }
            else
            {
                result = "MigrationBatches";
            }
            return(result);
        }
예제 #18
0
        private static string GetItemTextForMigration(AsyncOperationType type, AsyncOperationStatus status, object displayName, object originalExtAttributes)
        {
            string empty  = string.Empty;
            string empty2 = string.Empty;
            string empty3 = string.Empty;

            if (originalExtAttributes != DBNull.Value)
            {
                KeyValuePair <string, LocalizedString>[] source = (KeyValuePair <string, LocalizedString>[])originalExtAttributes;
                Dictionary <string, string> dictionary          = source.ToDictionary((KeyValuePair <string, LocalizedString> item) => item.Key.ToString(), (KeyValuePair <string, LocalizedString> item) => item.Value.ToString());
                dictionary.TryGetValue(AsyncNotificationAdapter.TotalSyncedCount, out empty);
                dictionary.TryGetValue(AsyncNotificationAdapter.TotalItemCount, out empty2);
                dictionary.TryGetValue(AsyncNotificationAdapter.TotalFailedCount, out empty3);
            }
            int totalSyncedCount;

            int.TryParse(empty, out totalSyncedCount);
            int totalItemCount;

            int.TryParse(empty2, out totalItemCount);
            int totalFailedCount;

            int.TryParse(empty3, out totalFailedCount);
            return(NotificationService.GetItemTextImp(type, status, displayName, DBNull.Value, new Func <string, string, LocalizedString>(Strings.AsyncProcessQueued), new Func <string, string, string, LocalizedString>(Strings.AsyncProcessInProgressWithPercentage), delegate(string operation, string name)
            {
                if (totalFailedCount > 0)
                {
                    return Strings.MigrationInProgressWithFailedCount(operation, name, totalSyncedCount, totalItemCount, totalFailedCount);
                }
                if (totalItemCount > 0)
                {
                    return Strings.MigrationInProgressWithSyncedCount(operation, name, totalSyncedCount, totalItemCount);
                }
                return Strings.AsyncProcessInProgress(operation, name);
            }, new Func <string, string, LocalizedString>(Strings.AsyncProcessSuspended), new Func <string, string, LocalizedString>(Strings.AsyncProcessCompleted), new Func <string, string, LocalizedString>(Strings.AsyncProcessFailed), new Func <string, string, LocalizedString>(Strings.AsyncProcessWaitingFinalization), new Func <string, string, LocalizedString>(Strings.AsyncProcessCreated), new Func <string, string, LocalizedString>(Strings.AsyncProcessCompleting), new Func <string, string, LocalizedString>(Strings.AsyncProcessRemoving)));
        }
예제 #19
0
 public void SetWaitMessage(AsyncOperationType type)
 {
     SetWaitScreenMessage?.Invoke(GetDescription(type));
 }
예제 #20
0
 private static bool IsPartialOrderOperation(AsyncOperationType type) => type != AsyncOperationType.Send;
예제 #21
0
        private void ProcessTaskResult <TResult>(Task <TResult> task, Action <Exception, TResult> completeAction, AsyncOperationType type)
        {
            if (task.IsFaulted && task.Exception != null)
            {
                // TODO: move this code into OperationCompleted registered by a Form to isolate it from UTing.
                ShowExceptionCarefully(task.Exception);
            }

            try
            {
                OperationCompleted?.Invoke(this, new PriceEventArgs <AsyncOperationType>(type));
                completeAction?.Invoke(task.Exception, task.Exception == null ? task.Result : default(TResult));
            }
            catch (Exception e)
            {
                ShowExceptionCarefully(e);
            }
        }
 public static void CreateNotification(OrganizationId organizationId, string id, AsyncOperationType type, AsyncOperationStatus status, LocalizedString displayName, ADRecipientOrAddress owner, KeyValuePair <string, LocalizedString>[] extendedAttributes, bool throwOnError)
 {
     if (AsyncOperationNotificationDataProvider.IsAsyncNotificationDisabled())
     {
         ExTraceGlobals.StorageTracer.TraceWarning(0L, "DisableAsyncNotification is set in registry, no notification will be created.");
         return;
     }
     if (string.IsNullOrEmpty(id))
     {
         throw new ArgumentNullException("id", "id is mandatory.");
     }
     try
     {
         AsyncOperationNotificationDataProvider asyncOperationNotificationDataProvider = new AsyncOperationNotificationDataProvider(organizationId);
         if (asyncOperationNotificationDataProvider.FindItemByAlternativeId(id) != null)
         {
             throw new StoragePermanentException(ServerStrings.ErrorNotificationAlreadyExists);
         }
         asyncOperationNotificationDataProvider.Save(new AsyncOperationNotification
         {
             AlternativeId      = id,
             ExtendedAttributes = extendedAttributes,
             StartedByValue     = owner,
             DisplayName        = displayName,
             Type   = type,
             Status = status
         });
     }
     catch (Exception ex)
     {
         string printableId = AsyncOperationNotificationDataProvider.GetPrintableId(organizationId, id);
         ExTraceGlobals.StorageTracer.TraceError <string, string>(0L, "AsyncOperationNotificationDataProvider::CreateNotification failed: {0}, message: {1}", printableId, ex.Message);
         StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_ErrorCreateNotification, printableId, new object[]
         {
             printableId,
             ex
         });
         if (throwOnError)
         {
             throw;
         }
     }
 }
 public static void CreateNotification(OrganizationId organizationId, string id, AsyncOperationType type, LocalizedString displayName, ADRecipientOrAddress owner, KeyValuePair <string, LocalizedString>[] extendedAttributes, bool throwOnError)
 {
     AsyncOperationNotificationDataProvider.CreateNotification(organizationId, id, type, AsyncOperationStatus.Queued, displayName, owner, extendedAttributes, throwOnError);
 }
예제 #24
0
 private static string GetItemTextDefault(AsyncOperationType type, AsyncOperationStatus status, object displayName, object percentComplete)
 {
     return(NotificationService.GetItemTextImp(type, status, displayName, percentComplete, new Func <string, string, LocalizedString>(Strings.AsyncProcessQueued), new Func <string, string, string, LocalizedString>(Strings.AsyncProcessInProgressWithPercentage), new Func <string, string, LocalizedString>(Strings.AsyncProcessInProgress), new Func <string, string, LocalizedString>(Strings.AsyncProcessSuspended), new Func <string, string, LocalizedString>(Strings.AsyncProcessCompleted), new Func <string, string, LocalizedString>(Strings.AsyncProcessFailed), new Func <string, string, LocalizedString>(Strings.AsyncProcessWaitingFinalization), null, null, null));
 }
        /// <summary>
        /// Transitions an <see cref="IAsyncResult"/> instance to a completed state.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies an invocation.</param>
        /// <param name="operationType">The expected operation type.</param>
        /// <param name="cancel">Boolean indicating whether or not the operation has been canceled.</param>
        /// <returns>A <see cref="DomainClientAsyncResult"/> reference.</returns>
        /// <exception cref="ArgumentNullException"> if <paramref name="asyncResult"/> is null.</exception>
        /// <exception cref="ArgumentException"> if <paramref name="asyncResult"/> is for another operation or was not created by this <see cref="DomainClient"/> instance.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/> has been canceled.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/>'s End* method has already been invoked.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/> has not completed.</exception>
        private DomainClientAsyncResult EndAsyncResult(IAsyncResult asyncResult, AsyncOperationType operationType, bool cancel)
        {
            DomainClientAsyncResult domainClientResult = asyncResult as DomainClientAsyncResult;

            if ((domainClientResult != null) && (!object.ReferenceEquals(this, domainClientResult.DomainClient) || domainClientResult.AsyncOperationType != operationType))
            {
                throw new ArgumentException(Resources.WrongAsyncResult, "asyncResult");
            }

            return AsyncResultBase.EndAsyncOperation<DomainClientAsyncResult>(asyncResult, cancel);
        }
예제 #26
0
 /// <summary>
 /// Sets the next operation to schedule.
 /// </summary>
 internal void SetNextOperation(AsyncOperationType operationType, AsyncOperationTarget target, ulong targetId)
 {
     this.Type     = operationType;
     this.Target   = target;
     this.TargetId = targetId;
 }
예제 #27
0
 public void SetWaitMessage(AsyncOperationType type)
 {
     throw new NotImplementedException();
 }
예제 #28
0
        /// <summary>
        /// Initializes a new <see cref="DomainClientAsyncResult"/> instance used for Invoke operations.
        /// </summary>
        /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
        /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
        /// <param name="callback">The <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        protected DomainClientAsyncResult(DomainClient domainClient, InvokeArgs invokeArgs, AsyncCallback callback, object asyncState)
            : base(callback, asyncState)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }
            if (invokeArgs == null)
            {
                throw new ArgumentNullException("invokeArgs");
            }

            this._asyncOperationType = AsyncOperationType.Invoke;
            this._domainClient = domainClient;
            this._invokeArgs = invokeArgs;
        }
예제 #29
0
        /// <summary>
        /// Transitions an <see cref="IAsyncResult"/> instance to a completed state.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies an invocation.</param>
        /// <param name="operationType">The expected operation type.</param>
        /// <param name="cancel">Boolean indicating whether or not the operation has been canceled.</param>
        /// <returns>A <see cref="WebDomainClientAsyncResult&lt;TContract&gt;"/> reference.</returns>
        /// <exception cref="ArgumentNullException"> if <paramref name="asyncResult"/> is null.</exception>
        /// <exception cref="ArgumentException"> if <paramref name="asyncResult"/> is not of type <cref name="TAsyncResult"/>.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/> has been canceled.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/>'s End* method has already been invoked.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/> has not completed.</exception>
        private WebDomainClientAsyncResult <TContract> EndAsyncResult(IAsyncResult asyncResult, AsyncOperationType operationType, bool cancel)
        {
            WebDomainClientAsyncResult <TContract> wcfClientResult = asyncResult as WebDomainClientAsyncResult <TContract>;

            if ((wcfClientResult != null) && (!object.ReferenceEquals(this, wcfClientResult.DomainClient) || wcfClientResult.AsyncOperationType != operationType))
            {
                throw new ArgumentException(Resources.WrongAsyncResult, "asyncResult");
            }

            return(AsyncResultBase.EndAsyncOperation <WebDomainClientAsyncResult <TContract> >(asyncResult, cancel));
        }
예제 #30
0
 /// <summary>
 /// Sets the operation type.
 /// </summary>
 internal virtual void SetType(AsyncOperationType operationType)
 {
     this.Type = operationType;
 }
예제 #31
0
        /// <summary>
        /// Schedules the next asynchronous operation.
        /// </summary>
        internal void ScheduleNextOperation(AsyncOperationType type, AsyncOperationTarget target, ulong targetId)
        {
            int?taskId = Task.CurrentId;

            // If the caller is the root task, then return.
            if (taskId != null && taskId == this.Runtime.RootTaskId)
            {
                return;
            }

            if (!this.IsSchedulerRunning)
            {
                this.Stop();
                throw new ExecutionCanceledException();
            }

            // Checks if concurrency not controlled by the runtime was used.
            this.Runtime.AssertNoExternalConcurrencyUsed();

            // Checks if the scheduling steps bound has been reached.
            this.CheckIfSchedulingStepsBoundIsReached();

            AsyncOperation current = this.ScheduledOperation;

            current.SetNextOperation(type, target, targetId);

            // Get and order the operations by their id.
            var ops = this.OperationMap.Values.OrderBy(op => op.SourceId).Select(op => op as IAsyncOperation).ToList();

            if (!this.Strategy.GetNext(out IAsyncOperation next, ops, current))
            {
                // Checks if the program has livelocked.
                this.CheckIfProgramHasLivelocked(ops.Select(op => op as AsyncOperation));

                Debug.WriteLine("<ScheduleDebug> Schedule explored.");
                this.HasFullyExploredSchedule = true;
                this.Stop();
                throw new ExecutionCanceledException();
            }

            this.ScheduledOperation = next as AsyncOperation;
            this.Runtime.ScheduleTrace.AddSchedulingChoice(next.SourceId);

            Debug.WriteLine($"<ScheduleDebug> Schedule '{next.SourceName}' with task id '{this.ScheduledOperation.Task.Id}'.");

            if (current != next)
            {
                current.IsActive = false;
                lock (next)
                {
                    this.ScheduledOperation.IsActive = true;
                    System.Threading.Monitor.PulseAll(next);
                }

                lock (current)
                {
                    if (!current.IsInboxHandlerRunning)
                    {
                        return;
                    }

                    while (!current.IsActive)
                    {
                        Debug.WriteLine($"<ScheduleDebug> Sleep '{current.SourceName}' with task id '{current.Task.Id}'.");
                        System.Threading.Monitor.Wait(current);
                        Debug.WriteLine($"<ScheduleDebug> Wake up '{current.SourceName}' with task id '{current.Task.Id}'.");
                    }

                    if (!current.IsEnabled)
                    {
                        throw new ExecutionCanceledException();
                    }
                }
            }
        }
예제 #32
0
 private void ShowWaitScreenWithType(AsyncOperationType type)
 {
     ShowWaitScreen?.Invoke(GetDescription(type));
 }