Inheritance: SectionWeapon
        public TaskResult <bool> DoTask(Nothing nothing)
        {
            try
            {
                var countries = _dbContext.Countries.ToList();
                if (countries.Any())
                {
                    return(new TaskResult <bool>(false));
                }

                _dbContext.Countries.Add(new Country {
                    Name = SeedData("COUNTRY_UNITED_STATES"), IsoCode = "US"
                });
                _dbContext.Countries.Add(new Country {
                    Name = SeedData("COUNTRY_CANADA"), IsoCode = "CA"
                });

                _dbContext.SaveChanges();

                return(new TaskResult <bool>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <bool>(new TaskException(e)));
            }
        }
        public TaskResult <bool> DoTask(Nothing nothing)
        {
            try
            {
                var pros = _dbContext.PerformingRightsOrganizations.ToList();
                if (pros.Any())
                {
                    return(new TaskResult <bool>(false));
                }

                _seedCountriesTask.DoTask(nothing);

                var us = _dbContext.Countries.SingleOrDefault(c => c.IsoCode.ToUpper() == "US");
                if (us == null)
                {
                    throw new NullReferenceException(SystemMessage("USA_NOT_FOUND"));
                }

                _dbContext.PerformingRightsOrganizations.Add(new PerformingRightsOrganization {
                    Name = "ASCAP", CountryId = us.Id
                });
                _dbContext.PerformingRightsOrganizations.Add(new PerformingRightsOrganization {
                    Name = "BMI", CountryId = us.Id
                });

                _dbContext.SaveChanges();

                return(new TaskResult <bool>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <bool>(new TaskException(e)));
            }
        }
        public TaskResult <bool> DoTask(Nothing input)
        {
            try
            {
                var installation = _dbContext.Installation.SingleOrDefault();
                if (installation != null)
                {
                    return(new TaskResult <bool>(false));
                }

                installation = new Installation
                {
                    Uuid    = Guid.NewGuid(),
                    Version = ApplicationSettings.Version,
                    Name    = SeedData("APP_NAME"),
                    Tagline = SeedData("APP_TAGLINE")
                };

                _dbContext.Installation.Add(installation);
                _dbContext.SaveChanges();

                return(new TaskResult <bool>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <bool>(new TaskException(e)));
            }
        }
示例#4
0
        public IMonad <B> App <B>(IMonad <Func <A, IMonad <B> > > functionMonad)
        {
            IMonad <B> result = new Nothing <B>();

            if (this is Just <A> && functionMonad != null)
            {
                result = null;
                //result = functionMonad.Return()(aValue).Return();
                foreach (var function in functionMonad)
                {
                    if (function != null)
                    {
                        if (result == null)  // if first time or first time (and second...) was Nothing
                        {
                            result = function(aValue);
                        }
                        else
                        {
                            var fResult = function(aValue);
                            if (!(fResult is Nothing <B>))        // skip if result is nothing
                            {
                                result = result.Concat(fResult);
                            }
                        }
                    }
                }
                if (result == null) // If some function returned null
                {
                    result = new Nothing <B>();
                }
            }

            return(result);
        }
示例#5
0
        public TaskResult <Installation> DoTask(Nothing nothing)
        {
            try
            {
                var installation = _dbContext.Installation.SingleOrDefault();
                if (installation == null)
                {
                    return(new TaskResult <Installation>(null as Installation));
                }

                var connectionStringBuilder = new SqlConnectionStringBuilder(ApplicationSettings.Database.ConnectionString);
                installation.DatabaseServer    = connectionStringBuilder.DataSource;
                installation.DatabaseName      = connectionStringBuilder.InitialCatalog;
                installation.DatabaseConsole   = ApplicationSettings.Database.HostingConsole;
                installation.Domain            = ApplicationSettings.Web.Domain;
                installation.HostingConsole    = ApplicationSettings.Web.HostingConsole;
                installation.OAuthId           = ApplicationSettings.Web.OAuthId;
                installation.OAuthConsole      = ApplicationSettings.Web.OAuthConsole;
                installation.ApiDomain         = ApplicationSettings.Api.Domain;
                installation.ApiHostingConsole = ApplicationSettings.Api.HostingConsole;
                installation.EmailServer       = ApplicationSettings.Mail.Smtp;
                installation.EmailAccount      = ApplicationSettings.Mail.From;
                installation.EmailConsole      = ApplicationSettings.Mail.WebConsole;
                installation.Culture           = ApplicationSettings.Culture;
                installation.Currency          = ApplicationSettings.Currency;

                return(new TaskResult <Installation>(installation));
            }
            catch (Exception e)
            {
                return(new TaskResult <Installation>(new TaskException(e)));
            }
        }
 public void Nothingから値を取り出そうとするとNullReferenceExceptionが送出されること()
 {
     var nothing = new Nothing<int>();
     var value = 0;
     Assert.Throws<NullReferenceException>(() => value = nothing.Value);
     Assert.Throws<NullReferenceException>(() => Maybe<int>.FromJust(nothing));
 }
示例#7
0
文件: Me.cs 项目: slavig/pepperspray
        internal override IPromise <Nothing> Dispatch(PlayerHandle sender, CommandDomain domain, string tag, IEnumerable <string> arguments)
        {
            if (domain.IsWorld && (!this.manager.CheckWorldMessagePermission(sender) || !this.lobbyService.CheckSlowmodeTimerInWorld(sender)))
            {
                return(Nothing.Resolved());
            }

            if (domain.IsLocal && sender.CurrentLobby != null && !this.lobbyService.CheckSlowmodeTimer(sender.CurrentLobby, sender))
            {
                return(Nothing.Resolved());
            }

            var contents      = tag + " " + String.Join(" ", arguments);
            var messageToSend = "";

            var components     = contents.Split(new char[] { '\\', '/', ';' }).Select(s => s.Trim()).Where(s => s.Any());
            var selfSufficient = contents.StartsWith("/me") && components.Count() == 1;

            foreach (var substring in components)
            {
                if (substring.StartsWith("me"))
                {
                    messageToSend += substring.Substring(2);
                }
                else if (substring.StartsWith("я"))
                {
                    messageToSend += substring.Substring(1);
                }
                else
                {
                    messageToSend += String.Format(" \"{0}\"", substring);
                }
            }

            messageToSend = messageToSend.Trim();

            var text = String.Format("{0}/me {1}", domain.Identifier, messageToSend);

            var commands = domain.Recipients.Select(r => r.Stream.Write(Responses.Message(sender, text))).ToList();

            if (!selfSufficient)
            {
                if (domain.IsPrivate)
                {
                    if (domain.Recipients.Count() > 0)
                    {
                        var recipient = domain.Recipients.First();
                        var selfText  = String.Format("{0}/me {1} {2} {3}", domain.Identifier, this.manager.Monogram, sender.Name, messageToSend);
                        commands.Add(sender.Stream.Write(Responses.Message(recipient, selfText)));
                    }
                }
                else
                {
                    var selfText = String.Format("{0}/me {1} {2}", domain.Identifier, sender.Name, messageToSend);
                    commands.Add(sender.Stream.Write(Responses.ServerMessage(this.manager, selfText)));
                }
            }

            return(new CombinedPromise <Nothing>(commands));
        }
示例#8
0
        public IMonad <C> Com <B, C>(Func <A, B, IMonad <C> > function, IMonad <B> mOther)
        {
            IMonad <C> result = new Nothing <C>();  // New Nothing<B> maybe

            if (!isNothing && !(mOther is Nothing <B>))
            {
                result = null;
                foreach (var otherValue in mOther)
                {
                    if (result == null)
                    {
                        result = function(aValue, otherValue);
                    }
                    else
                    {
                        var fResult = function(aValue, otherValue);
                        if (!(fResult is Nothing <B>))
                        {
                            result = result.Concat(fResult);
                        }
                    }
                }
                if (result == null)
                {
                    result = new Nothing <C>();
                }
            }
            return(result);
        }
示例#9
0
        public void Nothing_FMap_ReturnsNothing()
        {
            var nothing = new Nothing <int>();
            var result  = nothing.FMap <string>(a => a.ToString());

            Assert.IsInstanceOf <Nothing <string> >(result);
        }
示例#10
0
        protected override void _Start()
        {
            grid.ResetTiles();

            Process p = new Nothing();

            int i = 0;

            foreach( Unit unit in allUnits ) {
                if( !subjectUnit.team.IsAlly( unit ) && targetType == TargetType.Ally )
                    continue;

                if( !subjectUnit.team.IsEnemy( unit ) && targetType == TargetType.Enemy )
                    continue;

                if( onlyVisible && !subjectUnit.CanSee( unit.currentTile ) )
                    continue;

                unit.currentTile.MakeSelectable();
                unit.collider.enabled = true;

                SelectionManager.MarkTargetable( unit );

                i++;

            }

            print( i + " targetable units found." );

            End();
        }
示例#11
0
        public void Nothing_Bind_ReturnsNothing()
        {
            var nothing = new Nothing <string>();
            var result  = nothing.Bind <string>(a => new Just <string>(a));

            Assert.IsInstanceOf <Nothing <string> >(result);
        }
示例#12
0
        public IMonad <C> Com <B, C>(IMonad <Func <A, B, IMonad <C> > > functionMonad, IMonad <B> mOther)
        {
            IMonad <C> result = new Nothing <C>();

            if (!isNothing && !(mOther is Nothing <B>))         // other is no maybe and this is not nothing.
            {
                result = null;
                //resultMaybe = functionMonad.Return()(aValue, mOther.Return());
                foreach (var function in functionMonad)
                {
                    foreach (var otherValue in mOther)
                    {
                        if (result == null)       // Make result monad the monad type of the function result
                        {
                            result = function(aValue, otherValue);
                        }
                        else
                        {
                            var fResult = function(aValue, otherValue);
                            if (!(fResult is Nothing <B>))
                            {
                                result = result.Concat(fResult);
                            }
                        }
                    }
                }
                if (result == null)
                {
                    result = new Nothing <C>();
                }
            }

            return(result);
        }
示例#13
0
        internal IPromise <Nothing> Listen()
        {
            return(new CIO.CIOListener("CoreServer")
                   .Bind(this.config.ChatServerAddress, this.config.ChatServerPort)
                   .Incoming()
                   .Map(connection => this.coreServer.ConnectPlayer(connection))
                   .Map(player => player.Stream.Stream()
                        .Map(ev => this.coreServer.ProcessMessage(player, ev))
                        .Then(_ =>
            {
                Log.Information("Input stream of {player} finished", player.Digest);
            })
                        .Catch(ex =>
            {
                if (player.Stream.IsConnectionAlive)
                {
                    Log.Warning("Input stream of {player} rejected and is being terminated due to unhandled exception: {exception}", player.Digest, ex);
                }
                else
                {
                    Log.Debug("Input stream of {player} ended on rejected state ({ex}), already terminated.", player.Digest, ex.Message);
                }
            })
                        .Then(() =>
            {
                if (player.Stream.IsConnectionAlive)
                {
                    Log.Debug("Terminating connection of {player}", player.Digest);

                    this.coreServer.PlayerLoggedOff(player);
                    player.Stream.Terminate();
                }
            })
                        ).Then(a => Nothing.Resolved()));
        }
示例#14
0
        internal IPromise <Nothing> QueueMessage(PlayerHandle sender, string recipientName, string messageText)
        {
            try
            {
                Log.Debug("Offline message queue: from {sender} to {recipientName}", sender.Digest, recipientName);
                var recipient  = this.characterService.Find(recipientName);
                var dateString = DateTime.Now.ToShortDateString();
                var timeString = DateTime.Now.ToShortTimeString();

                var message = new OfflineMessage
                {
                    SenderId    = sender.Id,
                    RecepientId = recipient.Id,
                    Message     = String.Format("{0} {1}: {2}", dateString, timeString, messageText),
                };

                this.db.Write((c) => c.OfflineMessageInsert(message));
                return(sender.Stream.Write(Responses.ServerPrivateChatMessage(
                                               recipient.Name,
                                               recipient.Id,
                                               Strings.PLAYER_IS_OFFLINE_MESSAGES_WILL_BE_DELIVERED
                                               )));
            }
            catch (Database.NotFoundException)
            {
                Log.Warning("Failed to queue offline message from {sender} - {recipientName} not found!", sender.Digest, recipientName);
                return(Nothing.Resolved());
            }
        }
示例#15
0
        internal IPromise <Nothing> Dispatch(PlayerHandle client, Message eventMsg)
        {
            ARequest request = ARequest.Parse(client, this.server, eventMsg);

            if (request == null)
            {
                Log.Warning("Failed to parse request from {name}/{hash}/{address}: {msg_name} \"{msg_data}\"",
                            client.Name,
                            client.Stream.ConnectionHash,
                            client.Stream.ConnectionEndpoint,
                            eventMsg.name,
                            eventMsg.DebugDescription());

                return(Nothing.Resolved());
            }

            if (!request.Validate(client, this.server))
            {
                Log.Warning("Failed to validate request from {name}/{hash}/{address}: {msg_name} \"{msg_data}\"",
                            client.Name,
                            client.Stream.ConnectionHash,
                            client.Stream.ConnectionEndpoint,
                            eventMsg.name,
                            eventMsg.DebugDescription());

                return(Nothing.Resolved());
            }

            Log.Verbose("<= {player}@{lobby} {event_description}",
                        client.Digest,
                        client.CurrentLobbyIdentifier,
                        request.DebugDescription());

            return(request.Process(client, this.server));
        }
示例#16
0
 // Use this for initialization
 public void Start()
 {
     if (onClick == null)
     {
         onClick = new Nothing();
     }
 }
示例#17
0
        internal IPromise <Nothing> ExpelPlayer(PlayerHandle player, UserRoom userRoom, TimeSpan duration)
        {
            lock (this.server)
            {
                this.expelRecordsFor(player.User.Id).Add(new ExpelRecord
                {
                    UserId    = player.User.Id,
                    UserRoom  = userRoom,
                    UntilDate = DateTime.Now + duration,
                });
            }

            lock (this.server)
            {
                if (player.CurrentLobby != null && player.CurrentLobby.Identifier == userRoom.Identifier)
                {
                    var lobby = player.CurrentLobby;
                    player.CurrentLobby = null;

                    lobby.RemovePlayer(player);

                    return(this.lobbyService.NotifyLobbyAboutLeavingPlayer(player, lobby)
                           .Then((a) => player.Stream.Write(Responses.UserRoomClosed(userRoom))));
                }
                else
                {
                    Log.Debug("Player {name} is not currently in the target lobby ({identifier}), only timer added", player.Digest, userRoom.Identifier);
                }
            }

            return(Nothing.Resolved());
        }
示例#18
0
        internal IPromise <Nothing> ErrorAlert(ErrorException exception)
        {
            var loginServer = DI.Get <LoginServerListener>();

            if (this.Token != null && loginServer.HasClient(this.Token))
            {
                try
                {
                    var message = String.Format(Strings.DISCONNECTING_ON_TIMEOUT_LONG, exception.PlayerMessage, exception.Message);
                    return(loginServer.Emit(this.Token, "alert", message));
                }
                catch (LoginServerListener.NotFoundException) { }
            }

            if (this.Stream != null)
            {
                var message = String.Format(Strings.DISCONNECTING_ON_TIMEOUT_SHORT, exception.PlayerMessage);
                return(this.Stream.Write(Responses.MakeshiftAlert(message)));
            }

            Log.Error("Failed to alert player {player} ({hash}/{endpoint}) about exception error {exception}",
                      this.Name,
                      this.Stream != null ? this.Stream.ConnectionHash : 0,
                      this.Stream != null ? this.Stream.ConnectionEndpoint : null,
                      exception);

            return(Nothing.Resolved());
        }
示例#19
0
 public static bool IsEqual(this NotNothingView v, Nothing n)
 {
     return(v._float == n._float &&
            v._enum1 == n._enum1 &&
            Comparer.Equal(v.l, n.l) &&
            Comparer.Equal(v.s, n.s) &&
            Comparer.Equal(v.vl, n.vl));
 }
示例#20
0
        public void HasValue_WhenFieldHasNoValue_RetrunsFalse()
        {
            Assert.False(str_Nothing.HasValue());
            Assert.False(int_Nothing.HasValue());

            Assert.False(maybeStr_Default.HasValue());
            Assert.False(Nothing.HasValue());
        }
 private static IPooledBuffer Serialize(IInvocationSendCompleted message, Nothing _)
 {
     using (var envelope = InvocationMessageEnvelope.Rent())
     {
         var proto = InvocationSendCompletion.Rent();
         envelope.SendCompletion = proto;
         return(envelope.Serialize());
     }
 }
示例#22
0
 public IPooledBuffer Handle(ITransportConnectionOpenHeader header, Nothing _)
 {
     using (var headerProto = Header.Rent())
         using (var openProto = ConnectionOpenHeader.Rent())
         {
             headerProto.Open = MergeToProto(openProto, header);
             return(headerProto.Serialize());
         }
 }
示例#23
0
        internal IPromise <Nothing> OpenRoom(UserRoom room)
        {
            lock (this.server)
            {
                this.server.World.AddUserRoom(room);
            }

            return(Nothing.Resolved());
        }
示例#24
0
        public static Nothing Otherwise(this bool self, Action action)
        {
            if (self is false)
            {
                action();
            }

            return(Nothing.Of());
        }
示例#25
0
 public IPooledBuffer Handle(ITransportConnectionCloseHeader header, Nothing _)
 {
     using (var headerProto = Header.Rent())
         using (var closeProto = ConnectionCloseHeader.Rent())
         {
             headerProto.Close = MergeToProto(closeProto, header);
             return(headerProto.Serialize());
         }
 }
 private static IPooledBuffer Serialize(IInvocationMessageReceived message, Nothing _)
 {
     using (var envelope = InvocationMessageEnvelope.Rent())
     {
         var proto = InvocationMessageReceived.Rent();
         envelope.Confirmation = proto;
         return(envelope.Serialize());
     }
 }
示例#27
0
 public IPooledBuffer Handle(ITransportChannelOpenHeader header, Nothing _)
 {
     using (var headerProto = Header.Rent())
         using (var channelOpenProto = ChannelOpenHeader.Rent())
         {
             headerProto.ChannelOpen = MergeToProto(channelOpenProto, header);
             return(headerProto.Serialize());
         }
 }
示例#28
0
 public IPooledBuffer Handle(ITransportFrameHeader header, Nothing _)
 {
     using (var headerProto = Header.Rent())
         using (var frameProto = MessageFrameHeader.Rent())
         {
             headerProto.MessageFrame = MergeToProto(frameProto, header);
             return(headerProto.Serialize());
         }
 }
 private static IPooledBuffer Serialize(IInvocationMessageHeader message, Nothing _)
 {
     using (var envelope = InvocationMessageEnvelope.Rent())
     {
         var proto = InvocationMessageHeader.Rent();
         envelope.Message = proto;
         return(envelope.Serialize());
     }
 }
示例#30
0
        internal IPromise <Nothing> Dispatch(PlayerHandle sender, IEnumerable <PlayerHandle> recipients, ChatManager manager, string text)
        {
            if (recipients.Count() < 1)
            {
                Log.Debug("Failed to dispatch message from {sender} - no recipients", sender.Digest);
                return(Nothing.Resolved());
            }

            return(sender.Stream.Write(Responses.CharacterAppearance(recipients.First())));
        }
示例#31
0
        public IMonad <B> Select <B>(Func <A, int, B> function)
        {
            Maybe <B> resMaybe = new Nothing <B>();

            if (!this.isNothing)
            {
                resMaybe = function(aValue, 0);
            }
            return(resMaybe);
        }
示例#32
0
        public IMonad <B> SelectMany <B>(Func <A, int, IMonad <B> > f)
        {
            IMonad <B> result = new Nothing <B>();

            if (!this.isNothing)
            {
                result = f(aValue, 0);
            }
            return(result);
        }
示例#33
0
        protected override void _Start()
        {
            Process p = new Nothing();

            processManager.AddImmediately( p );

            p = path.Aggregate( p , ( current , tile ) => current.Enqueue( new UnitMoveToTile( subjectUnit , tile ) ) );

            p.eventEnded += End;

            subjectUnit.model.animator.moving = true;
        }
示例#34
0
 public void Nothing_Bind_ReturnsNothing()
 {
     var nothing = new Nothing<string>();
     var result = nothing.Bind<string>(a => new Just<string>(a));
     Assert.IsInstanceOf<Nothing<string>>(result);
 }
示例#35
0
 public void Nothing_FMap_ReturnsNothing()
 {
     var nothing = new Nothing<int>();
     var result = nothing.FMap<string>(a => a.ToString());
     Assert.IsInstanceOf<Nothing<string>>(result);
 }
示例#36
0
 static Maybe<Distance> Distance(Nothing<Location> a, Nothing<Location> b)
 {
     return new Nothing<Distance>();
 }
示例#37
0
文件: MaybeSpec.cs 项目: rarous/Maybe
 public void NothingShouldBindToNothing()
 {
     var nothing = new Nothing<int>();
     Assert.IsType<Nothing<int>>(nothing.Bind(x => (x + 1).ToMaybe()));
 }
示例#38
0
文件: MaybeSpec.cs 项目: rarous/Maybe
 public void NothingShouldReturnDefaultValue()
 {
     var nothing = new Nothing<string>();
     Assert.Null(nothing.Return());
 }
示例#39
0
        protected override void _Start()
        {
            grid.ResetTiles();

            Process p = new Nothing();

            foreach( GridTile tile in grid.GetAllTiles() )
                if( subjectUnit.CanSee( tile ) && tile.transform.position.IsInRange( subjectUnit.transform.position, range ) )
                //if( subjectUnit.CanSee( tile ) && subjectUnit.GetDistance( tile ) < range )
                    tile.MakeSelectable();

            End();
        }
示例#40
0
        public void TestMethod2()
        {
            ISomething something = new Something();
            var tasks = new List<Task>();
            var rwlock = new ReaderWriterLockSlim();

            for (var i = 0; i < 100; i++)
            {
                // These threads should never see "nothing"....
                tasks.Add(Task.Run(() =>
                {
                    for (var x = 0; x < 1000000; x++)
                    {
                        rwlock.EnterReadLock();
                        try
                        {
                            Thread.Sleep(100);
                            Assert.That(something.IsNothing, Is.False);
                        }
                        finally
                        {
                            rwlock.ExitReadLock();
                        }
                    }
                }));
            }

            // ... even though this one keeps setting it to nothing
            tasks.Add(Task.Run(() =>
            {
                for (var x = 0; x < 1000000; x++)
                {
                    rwlock.EnterWriteLock();
                    try
                    {
                        something = new Nothing();
                        Thread.Sleep(100);
                        something = new Something();
                    }
                    finally
                    {
                        rwlock.ExitWriteLock();
                    }
                }
            }));

            Task.WhenAll(tasks).Wait();
        }