Exemplo n.º 1
0
 /// <summary>
 /// Executes the POP3 NOOP command.
 /// </summary>
 /// <exception cref="Pop3Exception">If the NOOP command was unable to be executed successfully.</exception>
 public void SendNoOperation()
 {
     using (NoOperationCommand command = new NoOperationCommand(_clientStream))
     {
         ExecuteCommand <Pop3Response, NoOperationCommand>(command);
     }
 }
Exemplo n.º 2
0
        private void PreventSleep()
        {
            var command = new NoOperationCommand(packetsProcessor);

            command.SetResponseDelegate(OnPreventSleepResponse);
            command.SendNoOperationCommand();
        }
Exemplo n.º 3
0
        public async Task <ViewCommand> ProcessRelationActionAsync(UsageType usageType, string collectionAlias, IEntity relatedEntity, string id, EditContext editContext, string actionId, object?customData)
        {
            var collection = _collectionProvider.GetCollection(collectionAlias);

            var button = collection.FindButton(actionId);

            if (button == null)
            {
                throw new Exception($"Cannot determine which button triggered action for collection {collectionAlias}");
            }

            await EnsureAuthorizedUserAsync(editContext, button);

            EnsureValidEditContext(editContext, button);

            var relationContainer = editContext.GenerateRelationContainer();

            // since the id is known, get the entity variant from the entity
            var entityVariant = collection.GetEntityVariant(editContext.Entity);

            ViewCommand viewCommand;

            var context = new ButtonContext(null, customData);

            switch (await button.ButtonClickBeforeRepositoryActionAsync(editContext, context))
            {
            case CrudType.View:
                viewCommand = new NavigateCommand {
                    Uri = UriHelper.Node(Constants.View, collectionAlias, entityVariant, null, id)
                };
                break;

            case CrudType.Edit:
                viewCommand = new NavigateCommand {
                    Uri = UriHelper.Node(Constants.Edit, collectionAlias, entityVariant, null, id)
                };
                break;

            case CrudType.Update:
                await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalUpdateAsync(id, null, editContext.Entity, relationContainer));

                viewCommand = new ReloadCommand(id);
                break;

            case CrudType.Insert:
                var insertedEntity = await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalInsertAsync(null, editContext.Entity, relationContainer));

                if (insertedEntity == null)
                {
                    throw new Exception("Inserting the new entity failed.");
                }
                editContext.SwapEntity(insertedEntity);
                await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalAddAsync(relatedEntity, editContext.Entity.Id));

                viewCommand = new UpdateParameterCommand
                {
                    Action          = Constants.New,
                    CollectionAlias = collectionAlias,
                    VariantAlias    = entityVariant.Alias,
                    ParentId        = null,
                    Id = editContext.Entity.Id
                };
                break;

            case CrudType.Delete:

                await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalDeleteAsync(id, null));

                viewCommand = new ReloadCommand();
                break;

            case CrudType.Pick:

                await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalAddAsync(relatedEntity, id));

                viewCommand = new ReloadCommand();
                break;

            case CrudType.Remove:

                await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalRemoveAsync(relatedEntity, id));

                viewCommand = new ReloadCommand();
                break;

            case CrudType.None:
                viewCommand = new NoOperationCommand();
                break;

            case CrudType.Refresh:
                viewCommand = new ReloadCommand();
                break;

            default:
                throw new InvalidOperationException();
            }

            await button.ButtonClickAfterRepositoryActionAsync(editContext, context);

            return(viewCommand);
        }
Exemplo n.º 4
0
        public async Task <ViewCommand> ProcessRelationActionAsync(UsageType usageType, string collectionAlias, IEntity relatedEntity, IEnumerable <EditContext> editContexts, string actionId, object?customData)
        {
            var collection = _collectionProvider.GetCollection(collectionAlias);

            var button = collection.FindButton(actionId);

            if (button == null)
            {
                throw new Exception($"Cannot determine which button triggered action for collection {collectionAlias}");
            }

            var rootEditContext = await GetRootEditContextAsync(usageType, collectionAlias, null);

            var newEntity = await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalNewAsync(null, collection.EntityVariant.Type));

            await EnsureAuthorizedUserAsync(rootEditContext, button);

            ViewCommand viewCommand;

            var context = new ButtonContext(null, customData);

            switch (await button.ButtonClickBeforeRepositoryActionAsync(rootEditContext, context))
            {
            case CrudType.Create:
                if (button.EntityVariant == null)
                {
                    throw new InvalidOperationException();
                }

                if (usageType.HasFlag(UsageType.List))
                {
                    viewCommand = new NavigateCommand {
                        Uri = UriHelper.Node(Constants.New, collectionAlias, button.EntityVariant, null, null)
                    };
                }
                else
                {
                    viewCommand = new UpdateParameterCommand
                    {
                        Action          = Constants.New,
                        CollectionAlias = collectionAlias,
                        VariantAlias    = button.EntityVariant.Alias,
                        ParentId        = null,
                        Id = null
                    };
                }
                break;

            case CrudType.Update:
                var contextsToProcess = editContexts.Where(x => x.IsModified()).Where(x => button.RequiresValidForm(x) ? x.IsValid() : true);
                var affectedEntities  = new List <IEntity>();
                foreach (var editContext in contextsToProcess)
                {
                    try
                    {
                        var updatedEntity = editContext.Entity;
                        await EnsureAuthorizedUserAsync(editContext, button);

                        EnsureValidEditContext(editContext, button);
                        var relationContainer = editContext.GenerateRelationContainer();
                        await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalUpdateAsync(updatedEntity.Id, null, updatedEntity, relationContainer));

                        affectedEntities.Add(updatedEntity);
                    }
                    catch (Exception)
                    {
                        // do not care about exceptions here
                    }
                }
                viewCommand = new ReloadCommand(affectedEntities.Select(x => x.Id));
                break;

            case CrudType.Add:
                viewCommand = new UpdateParameterCommand
                {
                    Action          = Constants.Add,
                    CollectionAlias = collectionAlias,
                    VariantAlias    = null,
                    ParentId        = null,
                    Id = null
                };
                break;

            case CrudType.None:
                viewCommand = new NoOperationCommand();
                break;

            case CrudType.Refresh:
                viewCommand = new ReloadCommand();
                break;

            case CrudType.Return:
                viewCommand = new ReturnCommand();
                break;

            default:
                throw new InvalidOperationException();
            }

            await button.ButtonClickAfterRepositoryActionAsync(rootEditContext, context);

            return(viewCommand);
        }
Exemplo n.º 5
0
        public async Task <ViewCommand> ProcessEntityActionAsync(UsageType usageType, string collectionAlias, string?parentId, string?id, EditContext editContext, string actionId, object?customData)
        {
            var collection = _collectionProvider.GetCollection(collectionAlias);

            var entityVariant = collection.GetEntityVariant(editContext.Entity);

            var button = collection.FindButton(actionId);

            if (button == null)
            {
                throw new Exception($"Cannot determine which button triggered action for collection {collectionAlias}");
            }

            await EnsureAuthorizedUserAsync(editContext, button);

            EnsureValidEditContext(editContext, button);

            var relationContainer = editContext.GenerateRelationContainer();

            ViewCommand viewCommand;

            var context = new ButtonContext(parentId, customData);

            switch (await button.ButtonClickBeforeRepositoryActionAsync(editContext, context))
            {
            case CrudType.View:
                viewCommand = new NavigateCommand {
                    Uri = UriHelper.Node(Constants.View, collectionAlias, entityVariant, parentId, id)
                };
                break;

            case CrudType.Edit:
                viewCommand = new NavigateCommand {
                    Uri = UriHelper.Node(Constants.Edit, collectionAlias, entityVariant, parentId, id)
                };
                break;

            case CrudType.Update:
                await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalUpdateAsync(id ?? throw new InvalidOperationException(), parentId, editContext.Entity, relationContainer));

                viewCommand = new ReloadCommand(id);
                break;

            case CrudType.Insert:
                var entity = await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalInsertAsync(parentId, editContext.Entity, relationContainer));

                if (entity == null)
                {
                    throw new Exception("Inserting the new entity failed.");
                }
                editContext.SwapEntity(entity);
                viewCommand = new NavigateCommand {
                    Uri = UriHelper.Node(Constants.Edit, collectionAlias, entityVariant, parentId, editContext.Entity.Id)
                };
                break;

            case CrudType.Delete:
                await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalDeleteAsync(id ?? throw new InvalidOperationException(), parentId));

                viewCommand = new NavigateCommand {
                    Uri = UriHelper.Collection(Constants.List, collectionAlias, parentId)
                };
                break;

            case CrudType.None:
                viewCommand = new NoOperationCommand();
                break;

            case CrudType.Refresh:
                viewCommand = new ReloadCommand();
                break;

            case CrudType.Return:
                viewCommand = new ReturnCommand();
                break;

            default:
                throw new InvalidOperationException();
            }

            await button.ButtonClickAfterRepositoryActionAsync(editContext, context);

            return(viewCommand);
        }
Exemplo n.º 6
0
 public static byte[] BuildNoOpResponse(NoOperationCommand command)
 {
     return(BuildResposne(command.Opcode, BinaryResponseStatus.no_error, command.Opaque, 0, null, null, null));
 }
Exemplo n.º 7
0
        public async Task <ViewCommand> ProcessListActionAsync(UsageType usageType, string collectionAlias, ParentPath?parentPath, IEnumerable <EditContext> editContexts, string actionId, object?customData)
        {
            var collection = _collectionProvider.GetCollection(collectionAlias);

            var button = collection.FindButton(actionId);

            if (button == null)
            {
                throw new Exception($"Cannot determine which button triggered action for collection {collectionAlias}");
            }

            var parent = await _parentService.GetParentAsync(parentPath);

            var rootEditContext = await GetRootEditContextAsync(usageType, collectionAlias, parent);

            var entity = await EnsureCorrectConcurrencyAsync(() => collection.Repository.NewAsync(parent, collection.EntityVariant.Type));

            await EnsureAuthorizedUserAsync(rootEditContext, button);

            ViewCommand viewCommand;

            var context = new ButtonContext(parent, customData);

            switch (await button.ButtonClickBeforeRepositoryActionAsync(rootEditContext, context))
            {
            case CrudType.Create:
                if (button.EntityVariant == null)
                {
                    throw new InvalidOperationException($"Button of type {CrudType.Create} must an {nameof(button.EntityVariant)}.");
                }
                if (usageType.HasFlag(UsageType.List))
                {
                    viewCommand = new NavigateCommand {
                        Uri = UriHelper.Node(Constants.New, collectionAlias, button.EntityVariant, parentPath, null)
                    };
                }
                else
                {
                    viewCommand = new UpdateParameterCommand
                    {
                        Action          = Constants.New,
                        CollectionAlias = collectionAlias,
                        VariantAlias    = button.EntityVariant.Alias,
                        ParentPath      = parentPath?.ToPathString(),
                        Id = null
                    };
                }
                break;

            case CrudType.Update:
                var contextsToProcess = editContexts.Where(x => x.IsModified()).Where(x => button.RequiresValidForm(x) ? x.IsValid() : true);
                var affectedEntities  = new List <IEntity>();
                foreach (var editContext in contextsToProcess)
                {
                    try
                    {
                        await EnsureAuthorizedUserAsync(editContext, button);

                        EnsureValidEditContext(editContext, button);
                        await EnsureCorrectConcurrencyAsync(() => collection.Repository.UpdateAsync(editContext));

                        affectedEntities.Add(editContext.Entity);
                    }
                    catch (Exception)
                    {
                        // do not care about any exception in this case
                    }
                }
                viewCommand = new ReloadCommand(affectedEntities.SelectNotNull(x => x.Id));
                break;

            case CrudType.None:
                viewCommand = new NoOperationCommand();
                break;

            case CrudType.Refresh:
                viewCommand = new ReloadCommand();
                break;

            case CrudType.Return:
                viewCommand = new NavigateCommand {
                    Uri = UriHelper.Collection(Constants.Edit, collectionAlias, parentPath)
                };
                break;

            case CrudType.Up:
                var(newParentPath, parentCollectionAlias, parentId) = ParentPath.RemoveLevel(parentPath);

                if (parentCollectionAlias == null)
                {
                    return(new NoOperationCommand());
                }

                var parentCollection = _collectionProvider.GetCollection(parentCollectionAlias);

                viewCommand = new NavigateCommand {
                    Uri = UriHelper.Node(
                        usageType.HasFlag(UsageType.Edit) ? Constants.Edit : Constants.List,
                        parentCollectionAlias,
                        parentCollection.EntityVariant,
                        newParentPath,
                        parentId)
                };
                break;

            default:
                throw new InvalidOperationException();
            }

            await button.ButtonClickAfterRepositoryActionAsync(rootEditContext, context);

            return(viewCommand);
        }
Exemplo n.º 8
0
        void Build()
        {
            switch (_requestHeader.Opcode)
            {
            //Get command
            case Opcode.Get:
            //GetK command
            case Opcode.GetK:
                CreateGetCommand(_requestHeader.Opcode, false);
                break;

            //Set command
            case Opcode.Set:
            //Add command
            case Opcode.Add:
            //Replace command
            case Opcode.Replace:
            //Append command
            case Opcode.Append:
            //Prepend command
            case Opcode.Prepend:
                CreateStorageCommand(_requestHeader.Opcode, false);
                break;

            //Delete command
            case Opcode.Delete:
                CreateDeleteCommand(_requestHeader.Opcode, false);
                break;

            //Increment command
            case Opcode.Increment:
            //Decrement command
            case Opcode.Decrement:
                CreateCounterCommand(_requestHeader.Opcode, false);
                break;

            //Quit command
            case Opcode.Quit:
                _command = new QuitCommand(_requestHeader.Opcode);
                break;

            //Flush command
            case Opcode.Flush:
                CreateFlushCommand(_requestHeader.Opcode, false);
                break;

            //GetQ command
            case Opcode.GetQ:
            //GetKQ command
            case Opcode.GetKQ:
                CreateGetCommand(_requestHeader.Opcode, true);
                break;

            //No-op command
            case Opcode.No_op:
                _command = new NoOperationCommand();
                break;

            //Version command
            case Opcode.Version:
                CreateVersionCommand();
                break;

            //Stat command
            case Opcode.Stat:
                CreateStatsCommand();
                break;

            //SetQ command
            case Opcode.SetQ:
            //AddQ command
            case Opcode.AddQ:
            //ReplaceQ command
            case Opcode.ReplaceQ:
            //AppendQ command
            case Opcode.AppendQ:
            //PrependQ command
            case Opcode.PrependQ:
                CreateStorageCommand(_requestHeader.Opcode, true);
                break;

            //DeleteQ command
            case Opcode.DeleteQ:
                CreateDeleteCommand(_requestHeader.Opcode, true);
                break;

            //IncrementQ command
            case Opcode.IncrementQ:
            //DecrementQ command
            case Opcode.DecrementQ:
                CreateCounterCommand(_requestHeader.Opcode, true);
                break;

            //QuitQ command
            case Opcode.QuitQ:
                _command         = new QuitCommand(_requestHeader.Opcode);
                _command.NoReply = true;
                break;

            //FlushQ command
            case Opcode.FlushQ:
                CreateFlushCommand(_requestHeader.Opcode, true);
                break;

            default:
                CreateInvalidCommand();
                _command.Opcode = Opcode.unknown_command;
                break;
            }

            _command.Opaque = _requestHeader.Opaque;

            this.State = ParserState.ReadyToDispatch;
        }