예제 #1
0
        public IActionResult FileUploadedByTeacher([FromForm] List <EventAtachmentUpload> upload)
        {
            foreach (var item in upload)
            {
                var fileName   = "";
                var deletefile = Path.Combine(hostingEnvironment.WebRootPath);
                var uploads    = Path.Combine(hostingEnvironment.WebRootPath, "uploads");

                if (item.upload != null)
                {
                    fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(item.upload.FileName);
                    using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                    {
                        item.upload.CopyToAsync(fileStream);
                    }


                    EventAttachment eventAttachment = new EventAttachment()
                    {
                        event_id  = item.event_id,
                        file_name = item.upload.FileName,
                        file_path = fileName,
                        mtype     = "Teacher",
                        file_type = Path.GetExtension(item.upload.FileName),
                    };
                    _context.eventAttachments.Add(eventAttachment);
                    _context.SaveChanges();
                }
            }
            return(new JsonResult("Uploaded"));
        }
예제 #2
0
 /// <summary>
 /// Attach an event handler to the element.
 /// </summary>
 /// <param name="name">The HTML script event name.</param>
 /// <param name="handler">The event handler.</param>
 public override void AttachEvent(string name, EventHandler<HtmlEventArgs> handler)
 {
     EventAttachment<EventHandler<HtmlEventArgs>> attachment = new EventAttachment<EventHandler<HtmlEventArgs>>
     {
         EventName = name,
         Handler = handler
     };
     _htmlEvents.Add(attachment);
 }
예제 #3
0
 /// <summary>
 /// Attach an event handler.
 /// </summary>
 /// <param name="name">The event name.</param>
 /// <param name="handler">The event handler.</param>
 public override void AttachEvent(string name, EventHandler handler)
 {
     EventAttachment<EventHandler> attachment = new EventAttachment<EventHandler>
     {
         EventName = name,
         Handler = handler
     };
     _events.Add(attachment);
 }
        private bool AttachmentIsMissing(EventParticipation eventParticipation, EventAttachment attachment)
        {
            if (eventParticipation.Event == default)
            {
                return(true);
            }

            var eventObj = _events.FirstOrDefault(i => i.Id == eventParticipation.Event.Id);

            return(!(eventObj.RequireAttachment && attachment == default));
        }
예제 #5
0
		Dictionary<int, Action<XamlContext, XElement>> ExtractConnectionId(XamlContext ctx, MethodDef method) {
			var context = new DecompilerContext(method.Module) {
				CurrentType = method.DeclaringType,
				CurrentMethod = method,
				CancellationToken = ctx.CancellationToken
			};
			var body = new ILBlock(new ILAstBuilder().Build(method, true, context));
			new ILAstOptimizer().Optimize(context, body);

			var sw = body.GetSelfAndChildrenRecursive<ILSwitch>().FirstOrDefault();
			if (sw == null)
				return null;

			var connIds = new Dictionary<int, Action<XamlContext, XElement>>();
			foreach (var cas in sw.CaseBlocks) {
				if (cas.Values == null)
					continue;

				Action<XamlContext, XElement> cb = null;
				foreach (var node in cas.Body) {
					var expr = node as ILExpression;
					if (expr == null)
						continue;

					switch (expr.Code) {
						case ILCode.Stfld:
							cb += new FieldAssignment { FieldName = ((IField)expr.Operand).Name }.Callback;
							break;

						case ILCode.Call:
						case ILCode.Callvirt:
							var operand = (IMethod)expr.Operand;
							if (operand.Name == "AddHandler" && operand.DeclaringType.FullName == "System.Windows.UIElement") {
								// Attached event
								var re = expr.Arguments[1];
								var ctor = expr.Arguments[2];
								var reField = re.Operand as IField;

								if (re.Code != ILCode.Ldsfld || ctor.Code != ILCode.Newobj ||
								    ctor.Arguments.Count != 2 || ctor.Arguments[1].Code != ILCode.Ldftn) {
									cb += new Error { Msg = "Attached event '" + reField.Name + "'." }.Callback;
									break;
								}
								var handler = (IMethod)ctor.Arguments[1].Operand;
								string evName = reField.Name;
								if (evName.EndsWith("Event"))
									evName = evName.Substring(0, evName.Length - 5);

								cb += new EventAttachment {
									AttachedType = reField.DeclaringType.ResolveTypeDefThrow(),
									EventName = evName,
									MethodName = handler.Name
								}.Callback;
							}
							else {
								// CLR event
								var add = operand.ResolveMethodDefThrow();
								var ev = add.DeclaringType.Events.FirstOrDefault(e => e.AddMethod == add);

								var ctor = expr.Arguments[1];
								if (ev == null || ctor.Code != ILCode.Newobj ||
								    ctor.Arguments.Count != 2 || ctor.Arguments[1].Code != ILCode.Ldftn) {
									cb += new Error { Msg = "Attached event '" + add.Name + "'." }.Callback;
									break;
								}
								var handler = (IMethod)ctor.Arguments[1].Operand;

								cb += new EventAttachment {
									EventName = ev.Name,
									MethodName = handler.Name
								}.Callback;
							}
							break;
					}
				}

				if (cb != null) {
					foreach (var id in cas.Values)
						connIds[id] = cb;
				}
			}

			return connIds.Count == 0 ? null : connIds;
		}
예제 #6
0
        Dictionary <int, Action <XamlContext, XElement> > ExtractConnectionId(XamlContext ctx, MethodDef method)
        {
            var context = new DecompilerContext(method.Module)
            {
                CurrentType       = method.DeclaringType,
                CurrentMethod     = method,
                CancellationToken = ctx.CancellationToken
            };
            var body = new ILBlock(new ILAstBuilder().Build(method, true, context));

            new ILAstOptimizer().Optimize(context, body);

            var sw = body.GetSelfAndChildrenRecursive <ILSwitch>().FirstOrDefault();

            if (sw == null)
            {
                return(null);
            }

            var connIds = new Dictionary <int, Action <XamlContext, XElement> >();

            foreach (var cas in sw.CaseBlocks)
            {
                if (cas.Values == null)
                {
                    continue;
                }

                Action <XamlContext, XElement> cb = null;
                foreach (var node in cas.Body)
                {
                    var expr = node as ILExpression;
                    if (expr == null)
                    {
                        continue;
                    }

                    switch (expr.Code)
                    {
                    case ILCode.Stfld:
                        cb += new FieldAssignment {
                            FieldName = ((IField)expr.Operand).Name
                        }.Callback;
                        break;

                    case ILCode.Call:
                    case ILCode.Callvirt:
                        var operand = (IMethod)expr.Operand;
                        if (operand.Name == "AddHandler" && operand.DeclaringType.FullName == "System.Windows.UIElement")
                        {
                            // Attached event
                            var re      = expr.Arguments[1];
                            var ctor    = expr.Arguments[2];
                            var reField = re.Operand as IField;

                            if (re.Code != ILCode.Ldsfld || ctor.Code != ILCode.Newobj ||
                                ctor.Arguments.Count != 2 || ctor.Arguments[1].Code != ILCode.Ldftn)
                            {
                                cb += new Error {
                                    Msg = string.Format(dnSpy_BamlDecompiler_Resources.Error_AttachedEvent, reField.Name)
                                }.Callback;
                                break;
                            }
                            var    handler = (IMethod)ctor.Arguments[1].Operand;
                            string evName  = reField.Name;
                            if (evName.EndsWith("Event"))
                            {
                                evName = evName.Substring(0, evName.Length - 5);
                            }

                            cb += new EventAttachment {
                                AttachedType = reField.DeclaringType.ResolveTypeDefThrow(),
                                EventName    = evName,
                                MethodName   = handler.Name
                            }.Callback;
                        }
                        else
                        {
                            // CLR event
                            var add = operand.ResolveMethodDefThrow();
                            var ev  = add.DeclaringType.Events.FirstOrDefault(e => e.AddMethod == add);

                            var ctor = expr.Arguments[1];
                            if (ev == null || ctor.Code != ILCode.Newobj ||
                                ctor.Arguments.Count != 2 || ctor.Arguments[1].Code != ILCode.Ldftn)
                            {
                                cb += new Error {
                                    Msg = string.Format(dnSpy_BamlDecompiler_Resources.Error_AttachedEvent, add.Name)
                                }.Callback;
                                break;
                            }
                            var handler = (IMethod)ctor.Arguments[1].Operand;

                            cb += new EventAttachment {
                                EventName  = ev.Name,
                                MethodName = handler.Name
                            }.Callback;
                        }
                        break;
                    }
                }

                if (cb != null)
                {
                    foreach (var id in cas.Values)
                    {
                        connIds[id] = cb;
                    }
                }
            }

            return(connIds.Count == 0 ? null : connIds);
        }
예제 #7
0
        public ActionResult SaveEvent([FromForm] EventDto eventDto)
        {
            if (eventDto.id == 0)
            {
                DateTime dateTime = DateTime.Parse(eventDto.startDateTime);

                DateTime enddate = DateTime.Parse(eventDto.endDateTime);
                Event    @event  = new Event();
                @event.title         = eventDto.title;
                @event.description   = eventDto.description;
                @event.teacher_id    = eventDto.teacher_id;
                @event.endDateTime   = enddate;
                @event.startDateTime = dateTime;
                @event.location      = eventDto.location;
                _context.events.Add(@event);
                _context.SaveChanges();
                foreach (var v in eventDto.clasid)
                {
                    ClassEvent classEvent = new ClassEvent()
                    {
                        clasid  = v,
                        eventID = @event.id
                    }

                    ;
                    _context.classEvents.Add(classEvent);
                    _context.SaveChanges();
                }
                var fileName   = "";
                var deletefile = Path.Combine(hostingEnvironment.WebRootPath);
                var uploads    = Path.Combine(hostingEnvironment.WebRootPath, "uploads");

                if (eventDto.uploadFile != null)
                {
                    fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(eventDto.uploadFile.FileName);
                    using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                    {
                        eventDto.uploadFile.CopyToAsync(fileStream);
                    }


                    EventAttachment eventAttachment = new EventAttachment()
                    {
                        event_id  = @event.id,
                        file_name = eventDto.uploadFile.FileName,
                        file_path = fileName,
                        file_type = Path.GetExtension(eventDto.uploadFile.FileName),
                    };
                    _context.eventAttachments.Add(eventAttachment);
                    _context.SaveChanges();
                }
            }
            else
            {
                var      data     = _context.events.FirstOrDefault(o => o.id == eventDto.id);
                DateTime dateTime = DateTime.Parse(eventDto.startDateTime);

                DateTime enddate = DateTime.Parse(eventDto.endDateTime);
                data.title         = eventDto.title;
                data.description   = eventDto.description;
                data.teacher_id    = eventDto.teacher_id;
                data.endDateTime   = enddate;
                data.startDateTime = dateTime;
                data.location      = eventDto.location;

                var claesfromevent = _context.classEvents.Where(o => o.eventID == data.id).ToList();

                foreach (var item in claesfromevent)
                {
                    _context.classEvents.Remove(item);
                    _context.SaveChanges();
                }
                foreach (var v in eventDto.clasid)
                {
                    ClassEvent classEvent = new ClassEvent()
                    {
                        clasid  = v,
                        eventID = data.id
                    }

                    ;
                    _context.classEvents.Add(classEvent);
                    _context.SaveChanges();
                }


                if (eventDto.uploadFile != null)
                {
                    var enevtAtachment = _context.eventAttachments.FirstOrDefault(o => o.event_id == data.id);

                    var fileName   = "";
                    var deletefile = Path.Combine(hostingEnvironment.WebRootPath, "uploads");
                    var uploads    = Path.Combine(hostingEnvironment.WebRootPath);
                    if (enevtAtachment != null)
                    {
                        if (eventDto.uploadFile.Length > 0)
                        {
                            if (System.IO.File.Exists((Path.Combine(deletefile, enevtAtachment.file_path))))
                            {
                                System.IO.File.Delete((Path.Combine(deletefile, enevtAtachment.file_path)));
                            }
                        }

                        fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(eventDto.uploadFile.FileName);
                        using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                        {
                            eventDto.uploadFile.CopyToAsync(fileStream);
                        }


                        enevtAtachment.file_path             = fileName;
                        enevtAtachment.file_name             = eventDto.uploadFile.FileName;
                        enevtAtachment.file_type             = Path.GetExtension(eventDto.uploadFile.FileName);
                        _context.Entry(enevtAtachment).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        _context.SaveChanges();
                    }
                }
            }



            return(new JsonResult("Data Saved"));
        }