Exemplo n.º 1
0
        public IActionResult AddEvent([FromBody] LocalEventsViewModel eventViewModel)
        {
            try
            {
                LocalEvent newEvent = Mapper.Map <LocalEventsViewModel, LocalEvent>(eventViewModel);

                newEvent.EventId      = null;
                newEvent.UserId       = IdentityHelper.GetUserId(HttpContext);
                newEvent.IsApproved   = 0;
                newEvent.Expired      = 0;
                newEvent.CreationDate = DateTime.Now;
                newEvent.LastUpdate   = DateTime.Now;

                _localEventsRepository.addEvent(newEvent);

                string content = "A new event listing has been added\n" +
                                 "\nID: " + newEvent.EventId +
                                 "\nEvent name: " + newEvent.EventName +
                                 "\n\nPlease go to https://capstone1.azurewebsites.net/admin to approve this event listing";
                string subject = "New event listing";

                _emailService.SendToAdmins(subject, content);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 2
0
        public IActionResult GetEventsFromFeed()
        {
            string          url    = "https://itp.nz/events/palmie_north/rss";
            XmlReader       reader = XmlReader.Create(url);
            SyndicationFeed feed   = SyndicationFeed.Load(reader);

            reader.Close();
            List <LocalEvent> lEvents = new List <LocalEvent>();

            foreach (SyndicationItem item in feed.Items)
            {
                LocalEvent Nevent = new LocalEvent();
                Nevent.EventName        = item.Title.Text;
                Nevent.EventDescription = item.Summary.Text;
                Nevent.EventUrl         = item.Links[0].Uri.AbsoluteUri;
                Nevent.CreationDate     = DateTime.Now;
                Nevent.LastUpdate       = DateTime.Now;
                Nevent.StartDate        = DateTime.Now;
                Nevent.Duration         = 1;
                Nevent.EventId          = null;
                Nevent.UserId           = IdentityHelper.GetUserId(HttpContext);
                Nevent.IsApproved       = 0;
                Nevent.Expired          = 0;
                Regex           regex   = new Regex(@"(?<=\()(.*?)(?=\))");
                Match           matches = regex.Match(Nevent.EventName);
                GroupCollection groups  = matches.Groups;

                _localEventsRepository.addEvent(Nevent);
                lEvents.Add(Nevent);
            }
            return(Ok(lEvents));
        }
Exemplo n.º 3
0
 public IActionResult EditEvent([FromBody] LocalEventsViewModel localEventViewModel)
 {
     try
     {
         if (localEventViewModel.EventId.HasValue)
         {
             LocalEvent localEvent = _localEventsRepository.GetEventById(localEventViewModel.EventId.Value);
             if (localEvent.UserId == IdentityHelper.GetUserId(HttpContext))
             {
                 _localEventsRepository.editEvent(localEventViewModel);
                 return(Ok());
             }
             else
             {
                 return(Unauthorized());
             }
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 4
0
            public void RouteEventWithoutRegisteredRouteHasExpectedResult()
            {
                var @event = new LocalEvent();

                _sut.Route(@event);

                Assert.Null(_registeredRoute.Captured);
            }
Exemplo n.º 5
0
    public override void Show(LocalEvent evt)
    {
        base.Show(evt);

        var hackEvt = (OneTimeEvent)evt;
        var lost    = hackEvt.LostBalance;

        LostBalanceView.text = Services.Currency.CreatePriceString(lost, false, " ");
    }
Exemplo n.º 6
0
            public InstanceWithRecords()
            {
                _sut = new EventRecorder();

                _record1 = new LocalEvent();
                _record2 = new LocalEvent();

                _sut.Record(_record1);
                _sut.Record(_record2);
            }
Exemplo n.º 7
0
            public void RecordHasExpectedResult()
            {
                var @event = new LocalEvent();

                _sut.Record(@event);

                Assert.Equal(
                    new object[] { _record1, _record2, @event },
                    _sut.RecordedEvents);
            }
Exemplo n.º 8
0
            public void InvokingRaiseHasExpectedResult()
            {
                var sut = (IEventSource)_sut;

                var @event = new LocalEvent();

                _sut.InvokeRaise(@event);

                Assert.Equal(new object[] { @event }, sut.TakeEvents());
            }
Exemplo n.º 9
0
            public void RestoreFromEventsHasExpectedResult()
            {
                var sut    = (IEventSource)_sut;
                var @event = new LocalEvent();

                sut.RestoreFromEvents(new object[] { @event });

                Assert.Equal(new object[0], sut.TakeEvents());
                Assert.Equal(@event, _sut.Route.Captured);
            }
Exemplo n.º 10
0
 public Task<int> SaveEventAsync(LocalEvent localEvent)
 {
     if (localEvent.ID != 0)
     {
         return _database.UpdateAsync(localEvent);
     }
     else
     {
         return _database.InsertAsync(localEvent);
     }
 }
Exemplo n.º 11
0
            public ResetInstance()
            {
                _sut = new EventRecorder();

                var record1 = new LocalEvent();
                var record2 = new LocalEvent();

                _sut.Record(record1);
                _sut.Record(record2);
                _sut.Reset();
            }
Exemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("ID,Address,Category,Description,StartDate,Title,Url")] LocalEvent localEvent)
        {
            if (ModelState.IsValid)
            {
                _context.Add(localEvent);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(localEvent));
        }
Exemplo n.º 13
0
 public WaitForServerList()
 {
     conn = DistanceServerMain.Instance.Server.OnMasterServerEvent.Connect(evt =>
     {
         if (evt == MasterServerEvent.HostListReceived)
         {
             conn.Disconnect();
             conn = null;
             done = true;
         }
     });
 }
Exemplo n.º 14
0
            public void RegisterUntypedRouteHasExpectedResult()
            {
                var route = new CapturingRoute();

                _sut.RegisterRoute(typeof(LocalEvent), route.Capture);

                var @event = new LocalEvent();

                _sut.Route(@event);

                Assert.Equal(@event, route.Captured);
            }
Exemplo n.º 15
0
            public void RegisterTypedRouteForEventWithoutRegisteredRouteHasExpectedResult()
            {
                var route = new CapturingRoute();

                _sut.RegisterRoute <LocalEvent>(route.Capture);

                var @event = new LocalEvent();

                _sut.Route(@event);

                Assert.Equal(@event, route.Captured);
            }
Exemplo n.º 16
0
 public IActionResult adminRemoveEvent([FromBody] int eventId)
 {
     try
     {
         LocalEvent localEvent = _localEventsRepository.GetEventById(eventId);
         _localEventsRepository.removeEvent(localEvent);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 17
0
        public async Task <IActionResult> GetLocalEvent([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            LocalEvent localEvent = await _context.LocalEvent.SingleOrDefaultAsync(m => m.ID == id);

            if (localEvent == null)
            {
                return(NotFound());
            }

            return(Ok(localEvent));
        }
Exemplo n.º 18
0
        public (bool, object) Apply(LocalEvent e)
        {
            object obj;

            try
            {
                using (var sync = _sequenceNr.Lock())
                {
                    if (!_sequenceNr.IsValidSequence(e.SequenceNr))
                    {
                        return(false, null);
                    }
                    obj = _apply[e.GetType()](e);
                    _sequenceNr.Set(e.SequenceNr);
                    return(true, obj);
                }
            }
            catch { return(false, null); }
        }
Exemplo n.º 19
0
        public IActionResult removeEvent([FromBody] int eventId)
        {
            try
            {
                LocalEvent localEvent = _localEventsRepository.GetEventById(eventId);

                if (localEvent.UserId == IdentityHelper.GetUserId(HttpContext))
                {
                    _localEventsRepository.removeEvent(localEvent);
                    return(Ok());
                }
                else
                {
                    return(Unauthorized());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 20
0
        async Task <NetworkEvent> GetNetworkEvent(LocalEvent e)
        {
            switch (e)
            {
            // upload content
            case LocalFileContentSet ev:
                var(isMap_0, data_0) = await GetMapOrContent(ev.Content);

                return(new NetworkFileContentSet(ev.SequenceNr, ev.FileId, data_0, isMap_0));

            case LocalFileItemCreated ev:
                var(isMap_1, data_1) = await GetMapOrContent(ev.Content);

                return(new NetworkFileItemCreated(ev.SequenceNr, ev.ParentDirId, ev.Name, data_1, isMap_1));

            case null:
                throw new System.ArgumentNullException(nameof(e));

            default:
                return(e.ToNetworkEvent());
            }
        }
Exemplo n.º 21
0
        public void Run(RegressionEnvironment env)
        {
            // Bean
            BiConsumer <EventType, Nullable2Lvl> bean = (
                type,
                val) => {
                LocalEvent @event;
                if (val.IsNullAtRoot)
                {
                    @event = new LocalEvent();
                }
                else if (val.IsNullAtInner)
                {
                    @event = new LocalEventSubA(new LocalInnerEvent(null));
                }
                else
                {
                    @event = new LocalEventSubA(new LocalInnerEvent(new LocalLeafEvent(val.Id)));
                }

                env.SendEventBean(@event, "LocalEvent");
            };
            var beanepl = "@public @buseventtype create schema LocalEvent as " +
                          typeof(EventInfraGetterDynamicNested.LocalEvent).MaskTypeName() +
                          ";\n" +
                          "@public @buseventtype create schema LocalEventSubA as " +
                          typeof(EventInfraGetterDynamicNested.LocalEventSubA).MaskTypeName() +
                          ";\n";

            RunAssertion(env, beanepl, bean);

            // Map
            BiConsumer <EventType, Nullable2Lvl> map = (
                type,
                val) => {
                IDictionary <string, object> @event = new LinkedHashMap <string, object>();
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    var inner = Collections.SingletonDataMap("Leaf", null);
                    @event.Put("Property", inner);
                }
                else
                {
                    var leaf  = Collections.SingletonDataMap("Id", val.Id);
                    var inner = Collections.SingletonDataMap("Leaf", leaf);
                    @event.Put("Property", inner);
                }

                env.SendEventMap(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("map"), map);

            // Object-array
            RunAssertion(env, GetEpl("objectarray"), null);

            // Json
            BiConsumer <EventType, Nullable2Lvl> json = (
                type,
                val) => {
                var @event = new JObject();
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    @event.Add("Property", new JObject(new JProperty("Leaf", null)));
                }
                else
                {
                    var leaf  = new JObject(new JProperty("Id", val.Id));
                    var inner = new JObject(new JProperty("Leaf", leaf));
                    @event.Add("Property", inner);
                }

                env.SendEventJson(@event.ToString(), "LocalEvent");
            };

            RunAssertion(env, GetEpl("json"), json);

            // Json-Class-Provided
            var eplJsonProvided = "@JsonSchema(ClassName='" +
                                  typeof(MyLocalJsonProvided).MaskTypeName() +
                                  "') @public @buseventtype create json schema LocalEvent();\n";

            RunAssertion(env, eplJsonProvided, json);

            // Avro
            BiConsumer <EventType, Nullable2Lvl> avro = (
                type,
                val) => {
                var           emptySchema = SchemaBuilder.Record("empty");
                GenericRecord @event;
                if (val.IsNullAtRoot)
                {
                    @event = new GenericRecord(emptySchema);
                }
                else if (val.IsNullAtInner)
                {
                    var inner     = new GenericRecord(emptySchema);
                    var topSchema = SchemaBuilder.Record("name", TypeBuilder.Field("Property", emptySchema));
                    @event = new GenericRecord(topSchema);
                    @event.Put("Property", inner);
                }
                else
                {
                    var leafSchema = SchemaBuilder.Record(
                        "leaf",
                        TypeBuilder.Field(
                            "Id",
                            TypeBuilder.StringType(
                                TypeBuilder.Property(
                                    AvroConstant.PROP_STRING_KEY,
                                    AvroConstant.PROP_STRING_VALUE))));

                    var innerSchema = SchemaBuilder.Record("inner", TypeBuilder.Field("Leaf", leafSchema));
                    var topSchema   = SchemaBuilder.Record("top", TypeBuilder.Field("Property", innerSchema));
                    var leaf        = new GenericRecord(leafSchema);
                    leaf.Put("Id", val.Id);
                    var inner = new GenericRecord(innerSchema);
                    inner.Put("Leaf", leaf);
                    @event = new GenericRecord(topSchema);
                    @event.Put("Property", inner);
                }

                env.SendEventAvro(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("avro"), avro);
        }
        public void Run(RegressionEnvironment env)
        {
            // Bean
            BiConsumer <EventType, Nullable2Lvl> bean = (
                type,
                val) => {
                LocalEvent @event;
                if (val.IsNullAtRoot)
                {
                    @event = new LocalEvent(null);
                }
                else if (val.IsNullAtInner)
                {
                    @event = new LocalEvent(new LocalInnerEvent(null));
                }
                else
                {
                    @event = new LocalEvent(new LocalInnerEvent(new LocalLeafEvent(val.Id)));
                }

                env.SendEventBean(@event);
            };
            var beanepl = $"@public @buseventtype create schema LocalEvent as {typeof(LocalEvent).MaskTypeName()};\n";

            RunAssertion(env, beanepl, bean);

            // Map
            BiConsumer <EventType, Nullable2Lvl> map = (
                type,
                val) => {
                IDictionary <string, object> @event = new LinkedHashMap <string, object>();
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    var inner = Collections.SingletonDataMap("Leaf", null);
                    @event.Put("Property", inner);
                }
                else
                {
                    var leaf  = Collections.SingletonDataMap("Id", val.Id);
                    var inner = Collections.SingletonDataMap("Leaf", leaf);
                    @event.Put("Property", inner);
                }

                env.SendEventMap(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("map"), map);

            // Object-array
            BiConsumer <EventType, Nullable2Lvl> oa = (
                type,
                val) => {
                var @event = new object[1];
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    var inner = new object[] { null };
                    @event[0] = inner;
                }
                else
                {
                    var leaf  = new object[] { val.Id };
                    var inner = new object[] { leaf };
                    @event[0] = inner;
                }

                env.SendEventObjectArray(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("objectarray"), oa);

            // Json
            BiConsumer <EventType, Nullable2Lvl> json = (
                type,
                val) => {
                var @event = new JObject();
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    @event.Add("Property", new JObject(new JProperty("Leaf", null)));
                }
                else
                {
                    var leaf  = new JObject(new JProperty("Id", val.Id));
                    var inner = new JObject(new JProperty("Leaf", leaf));
                    @event.Add("Property", inner);
                }

                env.SendEventJson(@event.ToString(), "LocalEvent");
            };

            RunAssertion(env, GetEpl("json"), json);

            // Json-Class-Provided
            var eplJsonProvided =
                $"@JsonSchema(ClassName='{typeof(MyLocalJsonProvided).MaskTypeName()}') " +
                "@public @buseventtype create json schema LocalEvent();\n";

            RunAssertion(env, eplJsonProvided, json);

            // Avro
            BiConsumer <EventType, Nullable2Lvl> avro = (
                type,
                val) => {
                var schema = SupportAvroUtil.GetAvroSchema(type);
                var @event = new GenericRecord(schema.AsRecordSchema());
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    var inner = new GenericRecord(schema
                                                  .GetField("Property")
                                                  .Schema.AsRecordSchema());
                    @event.Put("Property", inner);
                }
                else
                {
                    var leaf = new GenericRecord(schema
                                                 .GetField("Property")
                                                 .Schema.AsRecordSchema()
                                                 .GetField("Leaf")
                                                 .Schema.AsRecordSchema());
                    leaf.Put("Id", val.Id);
                    var inner = new GenericRecord(schema.GetField("Property").Schema.AsRecordSchema());
                    inner.Put("Leaf", leaf);
                    @event.Put("Property", inner);
                }

                env.SendEventAvro(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("avro"), avro);
        }
Exemplo n.º 23
0
 public EventConnection(LocalEvent <T> evt, LocalEventHandler handler, int priority)
 {
     Event    = evt;
     Handler  = handler;
     Priority = priority;
 }
Exemplo n.º 24
0
 public static void RaiseAll(LocalEvent e, params object[] args)
 {
     OnRaised?.Invoke(e, args);
 }
Exemplo n.º 25
0
 public void Local()
 {
     LocalPage  = true;
     OnlinePage = false;
     LocalEvent?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 26
0
            public void RouteEventWithoutRegisteredRouteDoesNotThrow()
            {
                var @event = new LocalEvent();

                _sut.Route(@event);
            }
Exemplo n.º 27
0
 public Task<int> DeleteEventAsync(LocalEvent localEvent)
 {
     return _database.DeleteAsync(localEvent);
 }
Exemplo n.º 28
0
 public virtual void Show(LocalEvent evt)
 {
     gameObject.SetActive(true);
 }
Exemplo n.º 29
0
 public bool Transact(LocalEvent e)
 => Transact <object>(e).Succeeded;
Exemplo n.º 30
0
 public void Subscribe(LocalEvent e, Action <object[]> del)
 {
     _events[(int)e].Add(del);
 }