Ejemplo n.º 1
0
        // Request (GET,POST,PUT,DELETE) comes in. Values (querystring, form) have been read and can be manipulated before the 
        // internal environment initializes. Request can be aborted if it does not match criteria.
        public void handler_IncomingRequestStarted(object sender, Eventing.Args.IncomingRequestEventArgs e)
        {
            // Demo 1: We forbid PUT requests
            // if (e.Context.HttpMethod == "PUT") e.Context.PipelineControl.ExecutePipeline = false;

            e.Context.PipelineControl.Message.MessageText = string.Format(_logpattern, "log-in", "IncomingRequestStarted", DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 2
0
 // Raised when the authorization process finishes with a result in e.Param.IsAuthorized [true|false]
 void handler_AuthorizeRequestFinished(object sender, Eventing.Args.AuthorizeRequestEventArgs e)
 {
     // Demo 3: Deny authorization with e.Param.IsAuthorized
     // if (e.Param.CurrentUserRoles.Count == 0) e.Param.IsAuthorized = false;
   
     e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-auth", "AuthorizeRequestFinished", DateTime.Now.ToLongTimeString());
 }
Ejemplo n.º 3
0
        // Begin of core GET execution method, values of the GET request can be edited, or GET request can be aborted
        void handler_GetFilesRequestStarted(object sender, Eventing.Args.GetFilesRequestEventArgs e)
        {
            // Demo 4: Allow only jpg files
            // e.Param.BackloadValues.FilesFilter = "*.jpg";

            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-get", "GetFilesRequestStarted", DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 4
0
        /// <summary>Perform removal of the specified thing from our Children.</summary>
        /// <param name="thingToRemove">The thing to remove from our Children.</param>
        /// <param name="removalEvent">The removal event to work with; must have previously been sent as the request.</param>
        /// <param name="multipleParentsBehavior">The multipleParentsBehavior, if applicable.</param>
        /// <returns>True if the thing has been successfully removed, else false.</returns>
        private bool PerformRemoval(Thing thingToRemove, RemoveChildEvent removalEvent, MultipleParentsBehavior multipleParentsBehavior)
        {
            if (removalEvent.IsCancelled)
            {
                return(false);
            }

            // Send the removal event.
            Eventing.OnMovementEvent(removalEvent, EventScope.SelfDown);

            // If the thing to remove was in our Children collection, remove it.
            if (Children.Contains(thingToRemove))
            {
                Children.Remove(thingToRemove);
            }

            // If we don't have a MultipleParentsBehavior, directly remove the one-allowed
            // parent ourselves, else use the behavior's logic for adjusting the parents.
            if (multipleParentsBehavior == null)
            {
                thingToRemove.Parent = null;
            }
            else
            {
                multipleParentsBehavior.RemoveParent(this);
            }

            return(true);
        }
Ejemplo n.º 5
0
        private RemoveChildEvent RequestRemoval(Thing thingToRemove)
        {
            // Create and raise a removal event request.
            var removeChildEvent = new RemoveChildEvent(thingToRemove);

            Eventing.OnMovementRequest(removeChildEvent, EventScope.SelfDown);
            return(removeChildEvent);
        }
Ejemplo n.º 6
0
        private AddChildEvent RequestAdd(Thing thingToAdd)
        {
            // Prepare an add event request, and ensure both the new parent (this) and the
            // thing itself both get a chance to cancel this request before committing.
            var addChildEvent = new AddChildEvent(thingToAdd, this);

            Eventing.OnMovementRequest(addChildEvent, EventScope.SelfDown);
            thingToAdd.Eventing.OnMovementRequest(addChildEvent, EventScope.SelfDown);
            return(addChildEvent);
        }
Ejemplo n.º 7
0
        // Raised when the authorization process starts
        void handler_AuthorizeRequestStarted(object sender, Eventing.Args.AuthorizeRequestEventArgs e)
        {
            // Demo 2a: Force authorization of anonymous users:
            // e.Param.AllowAnonymous = true;

            // Demo 2b: Force authorization with roles:
            // e.Param.AllowAnonymous = false;
            // e.Param.IsAuthenticated = true;
            // e.Param.AllowedRoles.Add("SomeRole");
            // e.Param.CurrentUserRoles.Add("SomeRole");

            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-auth", "AuthorizeRequestStarted", DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 8
0
        private bool PerformAdd(Thing thingToAdd, AddChildEvent addEvent, MultipleParentsBehavior multipleParentsBehavior)
        {
            if (addEvent.IsCancelled)
            {
                return(false);
            }

            // If an existing thing is stackable with the added thing, combine the new
            // thing into the existing thing instead of simply adding it.
            foreach (Thing currentThing in Children)
            {
                if (thingToAdd.CanStack(currentThing))
                {
                    currentThing.Combine(thingToAdd);
                    return(true);
                }
            }

            // The item cannot be stacked so add the item to the specified parent.
            if (!Children.Contains(thingToAdd))
            {
                Children.Add(thingToAdd);
            }

            // If we don't have a MultipleParentsBehavior, directly set the one-allowed
            // parent ourselves, else use the behavior's logic for setting parents.
            if (multipleParentsBehavior == null)
            {
                thingToAdd.Parent = this;
            }
            else
            {
                multipleParentsBehavior.AddParent(this);
            }

            Eventing.OnMovementEvent(addEvent, EventScope.SelfDown);
            return(true);
        }
Ejemplo n.º 9
0
        // Outgoing response is created. you can completely override the results in e.Param.Result
        void handler_OutgoingResponseCreated(object sender, Eventing.Args.OutgoingResponseEventArgs e)
        {
            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-out", "OutgoingResponseCreated", DateTime.Now.ToLongTimeString()) + "&nbsp;<br />";

            // Demo 10: Because we want to return extra data (event log) to the client we need to add this to the JSON output as an additional JSON object.
            // The easiest way to do this is to create an anonymous object and assign it to the Data property of the JsonResult object:
           // var result = (JsonResult)e.Param.Result;
           // var plupload = (PlUpload)result.Data; // JsonResult.Data is always of type object. We convert it to the underlying PlUpload object.
           // result.Data = new { files = plupload.files, eventlog = e.Context.PipelineControl.Message.MessageText }; // Assing anonymous object
        }
Ejemplo n.º 10
0
 // Raised when an error within the core delete method occurs (e.g. file cannot be deleted
 void handler_DeleteFilesRequestException(object sender, Eventing.Args.DeleteFilesRequestEventArgs e)
 {
     e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-error", "DeleteFilesRequestException", DateTime.Now.ToLongTimeString());
 }
Ejemplo n.º 11
0
 // End of core DELETE execution method with results of the deletion
 async Task handler_DeleteFilesRequestFinishedAsync(object sender, Eventing.Args.DeleteFilesRequestEventArgs e)
 {
     // Demo 9: In the DeleteFilesRequestStarted event handler we added the additional files to the DeleteFiles list.
     // In this demo we delete the files manually in the event handler. We do not want to block the ui thread, so we do it asynchronous.
     // await Task.Factory.StartNew(
     //    () =>
     //    {
     //        foreach (var file in e.Param.DeleteFiles.Files)
     //        {
     //            if (System.IO.File.Exists(file.StorageInfo.CopyPath)) System.IO.File.Delete(file.StorageInfo.CopyPath);
     //        }
     //    });
   
     e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-delete", "DeleteFilesRequestFinished", DateTime.Now.ToLongTimeString());
 }
Ejemplo n.º 12
0
        // Begin of core DELETE execution method, values can be edited, files removed/added from deletion list, logging,etc
        void handler_DeleteFilesRequestStarted(object sender, Eventing.Args.DeleteFilesRequestEventArgs e)
        {
         //   e.Context.PipelineControl.ExecutePipeline = false;
            // Demo 8: We've setup the copiesRoot attribute in the config to "Backup" which makes copies of uploaded files 
            // in the ~/Files/Backup folder. On a delete request we now want to delete the backup files too. In this demo we add 
            // the additional files to delete to the DeleteFiles list and let Backload delete the files.
            // (Note: The DeleteFilesRequestFinished handler below shows another way to do this).
            // IFileUploadStatus copy = e.Param.DeleteFiles.Clone(); // Clones the files to delete list
            // foreach (var file in copy.Files) file.UploadContext = "Backup"; // Sets the delete folder for the clone to the Backup folder
            // e.Param.DeleteFiles.Files.AddRange(copy.Files); // Adds the clone to the delete list



            DataLayer.Context.EFDbContext EFDbContext = new DataLayer.Context.EFDbContext();

         

            string FileName = e.Param.FileStatus.Files[0].FileName;
            int NewsId = Convert.ToInt32(TempData["FolderId"]);
            TempData["FolderId"] = NewsId;
            ServiceTabFile ServiceTabFile = EFDbContext.ServiceTabFiles.FirstOrDefault(x => x.ServiceTabId == NewsId && x.File == FileName);
            EFDbContext.ServiceTabFiles.Remove(ServiceTabFile);
            EFDbContext.SaveChanges();
            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-delete", "DeleteFilesRequestStarted", DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 13
0
 // Core PUT/POST execution method has saved the file
 void handler_StoreFileRequestFinished(object sender, Eventing.Args.StoreFileRequestEventArgs e)
 {
     // Demo 7: Include a message text
     // e.Param.FileStatusItem.Message = "Changed the storag ";
     e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-post", "StoreFileRequestFinished", DateTime.Now.ToLongTimeString());
 }
Ejemplo n.º 14
0
        // Begin of core PUT/POST execution method, values can be edited, or request can be aborted
        async Task handler_StoreFileRequestStartedAsync(object sender, Eventing.Args.StoreFileRequestEventArgs e)
        {
            string ExtFile = "";
            int FolderId = 0;
            if (TempData["FolderId"] != null)
            {
                FolderId = Convert.ToInt32(TempData["FolderId"]);
                TempData["FolderId"] = FolderId;
            }

            if (e.Param.FileStatusItem.StorageInfo.FilePath != 
                Server.MapPath("~/Files/ServiceGallery/" + FolderId + "/") + e.Param.FileStatusItem.FileName)
            {
                ExtFile = "ErrorPath";
            }
            // GetFileExtension Ext = new GetFileExtension();
            var extt = Path.GetExtension(e.Param.FileStatusItem.FileName);
            if (extt != ".jpg" && extt != ".png" && extt != ".jpeg" && extt != ".gif")
            {
                ExtFile = "ErrorExt";
            }

            if (ExtFile != "" && ExtFile == "ErrorPath")
            {
                e.Param.FileStatusItem.ErrorMessage = "مسیر فایل اشتباه است .";
                e.Param.FileStatusItem.Success = false;
            }
            if (ExtFile != "" && ExtFile == "ErrorExt")
            {
                e.Param.FileStatusItem.ErrorMessage = "نوع فایل معتبر نیست .";
                e.Param.FileStatusItem.Success = false;

            }
            if (ExtFile == "")
            {
                EFDbContext EFDbContext = new EFDbContext();
                string Filen = e.Param.FileStatusItem.FileName;

                int find = Filen.LastIndexOf(".");
                // var ext = Filen.Substring(find, Filen.Length - find);
                var MainName = Filen.Substring(0, find);
                MainName = ChangeUnKnownCharacters(MainName);
                e.Param.FileStatusItem.FileName = DateTime.Now.Ticks + MainName + extt;
                e.Param.FileStatusItem.UpdateStatus(true);

                ServiceTabFile Item = new ServiceTabFile();
                Item.File = e.Param.FileStatusItem.FileName;
                Item.ServiceTabId = FolderId;
                EFDbContext.ServiceTabFiles.Add(Item);
                EFDbContext.SaveChanges();

            }
            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-post", "StoreFileRequestStartedAsync", DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 15
0
        public void OnKeyPress(char keyCode, EventFlags flags)
        {
            bool didTurn = false;

            switch (keyCode)
            {
            case 'a':     // Todo: Map actions
            {
                // TODO: Reserved for interactin with the map. Open doors, pray at altars, etc.
            }
            break;

            case 'c':
            {
                // TODO: Reserved for casting spells

                // Temporary: Heal spell
                var spell = new Spell(6, new IEffect[] { new ApplyStatusEffect {
                                                             UseOn  = EntityTarget.Self,
                                                             Effect = new StatusEffect
                                                             {
                                                                 TickEffect    = new IEffect[] { new HealEffect(5, 0, EntityTarget.Self) },
                                                                 FinalEffect   = new IEffect[] { new MapRevealEffect(MapRevealEffect.RevealMethod.Terrain, 10) },
                                                                 RunsToExecute = 10,
                                                                 RepeatTurns   = 2,
                                                                 Components    = new System.Collections.Generic.List <ECM.IComponent> {
                                                                     new Armor(20, ESlotType.Gloves)
                                                                 }
                                                             }
                                                         } });;

                if (spell.Cast(_controller.Player, _controller.Player))
                {
                    _controller.EndTurn();
                }
            }
            break;

            case 'd':     // Drop Item
            {
                var inv = _controller.Player.GetOne <Inventory>();
                var o   = new OptionWidget($"Drop Item", inv.Items, i => {
                        if (inv.Remove(i))
                        {
                            i.SetLevel(_controller.Player.Level, _controller.Player.Pos);
                            _controller.EndTurn();
                        }
                    });
                _window.PopupStack.Push(o);
            }
            break;

            case 'e':     // Use item
            {
                var l = _controller.Player.GetOne <Inventory>().Items.Where(i => i.EntityFlags.HasFlag(EEntityFlag.Consumable)).ToList();
                var o = new OptionWidget($"Consume", l, i => {
                        if (Eventing.On(new ConsumeEvent(_controller.Player, i)))
                        {
                            _controller.EndTurn();
                        }
                    });
                _window.PopupStack.Push(o);
            }
            break;

            case 'f':     // Fire ranged weapon
            {
                var item  = _controller.Player.GetOne <Inventory>()?.Slots[Inventory.SLOT_RANGED].Item;
                var enemy = _controller.SelectedTarget;

                if (item != null && enemy != null)
                {
                    // TODO: Fix
                    //if (Eventing.On(new AttackEvent(_controller.Player, item, enemy, Combat.EAttackMove.Projectile)))
                    //    _controller.EndTurn();
                }
            }
            break;

            case 'g':
            {
                var pos = _controller.Player.Pos;
                foreach (var i in _controller.Level.GetEntities(pos).ToArray())
                {
                    if (i.EntityFlags.HasFlag(EEntityFlag.Pickable))
                    {
                        i.SetLevel(null, Vec.Zero);
                        _controller.Player.GetOne <Inventory>().Add(i);
                        didTurn = true;
                    }
                }
            }
            break;

            case 's':
            {
                // TODO: Reserved for searching
            }
            break;

            case 't':
            {
                var l = _controller.Player.GetOne <Inventory>().Items.Where(i => i.EntityFlags.HasFlag(EEntityFlag.Throwable)).ToList();

                /* TODO: Reserved for throwing
                 * var o = new OptionWidget($"Throw", l, i => {
                 *
                 * });
                 * _window.PopupStack.Push(o);
                 */
            }
            break;

            case 'w':
            {
                var o = new InventoryWidget(_controller, _window);
                _window.PopupStack.Push(o);
            }
            break;

            case 'z':
            {
                // TODO: Reserved for zapping wands
            }
            break;

            case '>':
            {
                foreach (var entity in _controller.Level.GetEntities(_controller.Player.Pos))
                {
                    if (_controller.Player == entity)
                    {
                        continue;
                    }

                    if (Eventing.On(new DownEvent(_controller.Player, entity)))
                    {
                        didTurn = true;
                        break;
                    }
                }
            }
            break;

            case (char)9:
            {
                var id = _controller.VisibleEnemies.IndexOf(_controller.SelectedTarget);
                id++;
                var newTarget = (id < _controller.VisibleEnemies.Count) ? _controller.VisibleEnemies[id] : null;
                _controller.SelectedTarget = newTarget;
                break;
            }

#if WIZTOOLS
            case '\\':     // Well 'w' will be used for wield/wear
            {
                var o = new OptionWidget($"Wizard tools", WizTools.Tools.Items, i => {
                        Eventing.On(new CastEvent(_controller.Player, i));
                    });
                _window.PopupStack.Push(o);
            }
            break;
#endif
            default:
                break;
            }


            if (didTurn)
            {
                _controller.EndTurn();
            }
        }
Ejemplo n.º 16
0
 // Demo event handler
 void handler_IncomingRequestStarted(object sender, Eventing.Args.IncomingRequestEventArgs e)
 {
     var values = e.Param.BackloadValues;
 }
Ejemplo n.º 17
0
 void handler_FileUploadException(object sender, Eventing.UploadExceptionEventArgs e)
 {
     // do something
 }
Ejemplo n.º 18
0
 void handler_FileUploadedFinished(object sender, Eventing.UploadFinishedEventArgs e)
 {
     // error handling
 }
Ejemplo n.º 19
0
        // Begin of core PUT/POST execution method, values can be edited, or request can be aborted
        async Task handler_StoreFileRequestStartedAsync(object sender, Eventing.Args.StoreFileRequestEventArgs e)
        {
            // Demo 6: Change the file to be stored
            string filepath = Server.MapPath("~/Resources/SomeImage.jpg");
            // var file = e.Param.FileStatusItem;
            // if (System.IO.File.Exists(filepath))
            // {
            //     byte[] bytes = null;
            //     using (FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
            //     {
            //         bytes = new byte[stream.Length];
            //         await stream.ReadAsync(bytes, 0, (int)stream.Length);
            //     }
            //     file.FileData = bytes;
            //     file.FileSize = bytes.LongLength;
            //     file.ContentType = "image/jpeg";
            // }

            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-post", "StoreFileRequestStartedAsync", DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 20
0
        // Begin of core DELETE execution method, values can be edited, files removed/added from deletion list, logging,etc
        void handler_DeleteFilesRequestStarted(object sender, Eventing.Args.DeleteFilesRequestEventArgs e)
        {
            // Demo 8: We've setup the copiesRoot attribute in the config to "Backup" which makes copies of uploaded files 
            // in the ~/Files/Backup folder. On a delete request we now want to delete the backup files too. In this demo we add 
            // the additional files to delete to the DeleteFiles list and let Backload delete the files.
            // (Note: The DeleteFilesRequestFinished handler below shows another way to do this).
            // IFileUploadStatus copy = e.Param.DeleteFiles.Clone(); // Clones the files to delete list
            // foreach (var file in copy.Files) file.UploadContext = "Backup"; // Sets the delete folder for the clone to the Backup folder
            // e.Param.DeleteFiles.Files.AddRange(copy.Files); // Adds the clone to the delete list

            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-delete", "DeleteFilesRequestStarted", DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 21
0
 public void handler_IncomingRequestStarted(object sender, Eventing.Args.IncomingRequestEventArgs e)
 {
 }
Ejemplo n.º 22
0
 // Single point exception handler
 void handler_ProcessPipelineExceptionOccured(object sender, Eventing.Args.ProcessPipelineExceptionEventArgs e)
 {
     e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-error", "ProcessPipelineExceptionOccured", DateTime.Now.ToLongTimeString());
 }
Ejemplo n.º 23
0
        // List of files retrieved and FileUploadStatus.Files filled with FileUploadStatusItems
        void handler_GetFilesRequestFinished(object sender, Eventing.Args.GetFilesRequestEventArgs e)
        {
            // Demo 5: Limit the result of returned files to 5 items.
            //Backload.Contracts.Context.
            //if (e.Context.RequestType == RequestType.Default) // GET requests for a file list, not a single file
            //{
            //    int limit = 5;
            //    int count = e.Param.FileStatus.Files.Count;

            //   if (count > limit) e.Param.FileStatus.Files.RemoveRange(limit, count - limit);
            //}

            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-get", "GetFilesRequestFinished", DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 24
0
 public void handler_IncomingRequestStarted(object sender, Eventing.Args.IncomingRequestEventArgs e)
 {
     // throw new Exception("Demo exception to be shown in the trace output");
 }
Ejemplo n.º 25
0
        // Begin of core GET execution method, values of the GET request can be edited, or GET request can be aborted
        void handler_GetFilesRequestStarted(    object sender, Eventing.Args.GetFilesRequestEventArgs e)
        {
            // Demo 4: Allow only jpg files
          // e.Param.BackloadValues.FilesFilter = "*.jpg";

        // int a=  e.Context.Request.Files.Count;
            int count = e.Param.FileStatus.Files.Count;
            string Folder = Convert.ToString(TempData["FolderId"]);
            TempData["FolderId"] = Folder;
            if (Folder!=null && Folder.Length>0)
                e.Param.SearchPath = Server.MapPath("~/Files/ServiceGallery/" + Folder);
            else
                e.Param.SearchPath = Server.MapPath("~/Files/ServiceGallery");
            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, 
                "log-get", "GetFilesRequestStarted",
                DateTime.Now.ToLongTimeString());
        }
Ejemplo n.º 26
0
 void handler_IncomingRequestStarted(object sender, Eventing.Args.IncomingRequestEventArgs e)
 {
     // Demo: Disallow PUT request within the event handler.
     if (e.Context.HttpMethod == "PUT") e.Context.PipelineControl.ExecutePipeline = false;
 }