Exemplo n.º 1
0
        public Task ModifyThreatListAsync(ThreatList threatList, IEnumerable <string> threatSha256HashPrefixes, IEnumerable <int> threatIndices, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();
            Guard.ThrowIf(nameof(threatSha256HashPrefixes), threatSha256HashPrefixes).Null();
            Guard.ThrowIf(nameof(threatIndices), threatIndices).Null();

            lock (this._lock) {
                var newSha256HashPrefixes = new List <string>();
                this._threats.TryGetValue(threatList.Descriptor, out var threats);
                if (threats != null)
                {
                    // ...
                    //
                    // Filtering the threat threat requires it to be presorted.
                    var newIndices = Enumerable.Range(0, threats.Count).Except(threatIndices);
                    foreach (var newIndex in newIndices)
                    {
                        var threat = threats[newIndex];
                        newSha256HashPrefixes.Add(threat);
                    }
                }

                // ...
                //
                // We need to sort the threat list so that it can later be searched.
                newSha256HashPrefixes.AddRange(threatSha256HashPrefixes);
                newSha256HashPrefixes.Sort();
                this._threatLists[threatList.Descriptor] = threatList;
                this._threats[threatList.Descriptor]     = newSha256HashPrefixes;

                return(Task.CompletedTask);
            }
        }
    public ThreatList investigate(int[,] board,
                                  Coordinate move,
                                  int attacker,
                                  bool create)
    {
        this.board    = board;
        this.attacker = attacker;
        this.create   = create;

        bool reset = false;

        if (board[move.X, move.Y] == attacker * -1)
        {
            throw new Exception();
        }
        if (board[move.X, move.Y] != attacker)
        {
            board[move.X, move.Y] = attacker;
            reset = true;
        }

        ThreatList res = SearchBoards(move);

        if (reset == true)
        {
            board[move.X, move.Y] = 0;
        }
        return(res);
    }
 /// <summary>
 ///     Store a Threat List Asynchronously.
 /// </summary>
 /// <param name="threatList">
 ///     A <see cref="ThreatList" /> to store.
 /// </param>
 /// <param name="threatSha256HashPrefixes">
 ///     A collection of SHA256 hash prefixes, formatted as hexadecimal encoded strings, identifying the threats
 ///     associated with <paramref name="threatList" /> and should be stored.
 /// </param>
 /// <param name="cancellationToken">
 ///     A cancellation token to cancel the asynchronous operation with.
 /// </param>
 /// <returns>
 ///     A task representing the asynchronous operation.
 /// </returns>
 /// <exception cref="Gee.External.Browsing.Databases.BrowsingDatabaseException">
 ///     Thrown if a database error occurs.
 /// </exception>
 /// <exception cref="System.ArgumentNullException">
 ///     Thrown if <paramref name="threatList" /> is a null reference, or if
 ///     <paramref name="threatSha256HashPrefixes" /> is a null reference.
 /// </exception>
 /// <exception cref="System.ObjectDisposedException">
 ///     Thrown if the object is disposed.
 /// </exception>
 /// <exception cref="System.OperationCanceledException">
 ///     Thrown if the asynchronous operation is cancelled.
 /// </exception>
 public async Task StoreThreatListAsync(ThreatList threatList, IEnumerable <string> threatSha256HashPrefixes, CancellationToken cancellationToken)
 {
     this.ThrowIfDisposed();
     try {
         var storeThreatListTask = this._database.StoreThreatListAsync(threatList, threatSha256HashPrefixes, cancellationToken);
         await storeThreatListTask.ConfigureAwait(false);
     }
     catch (ArgumentNullException) {
         throw;
     }
     catch (BrowsingDatabaseException) {
         throw;
     }
     catch (ObjectDisposedException) {
         this.Dispose();
         throw;
     }
     catch (OperationCanceledException) {
         throw;
     }
     catch (Exception ex) {
         const string detailMessage = "A threat list could not be stored.";
         throw new BrowsingDatabaseException(detailMessage, ex);
     }
 }
    public static void Main()
    {
        int[,] board = new int[, ] {
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
        };

        board = Flip(board);

        ThreatSearcher searcher = new ThreatSearcher();

        ThreatList threats = searcher.investigate(board, new Coordinate(0, 13), 1);

        foreach (Threat t in threats)
        {
            Console.WriteLine(t.ToString());
        }
    }
Exemplo n.º 5
0
    /** Add threats from from into into if they are not contained yet.
     *
     * @returns ArrayList<Threat> List of the added threats.
     */
    private ThreatList Merge(ThreatList into, ThreatList from)
    {
        ThreatList res = new ThreatList();

        foreach (Threat t in from)
        {
            // check for every t if it is already in into-list
            bool alreadyin = false;
            foreach (Threat ct in into)
            {
                alreadyin = true;
                if (ct.category == t.category && ct.fields.Count == t.fields.Count)
                {
                    for (int i = 0; i < ct.fields.Count; ++i)
                    {
                        alreadyin = alreadyin &&
                                    ((((Coordinate)(ct.fields[i])).X == ((Coordinate)(t.fields[i])).X) &&
                                     (((Coordinate)(ct.fields[i])).Y == ((Coordinate)(t.fields[i])).Y));
                    }
                }
                else
                {
                    alreadyin = false;
                }
            }
            if (alreadyin == false)
            {
                into.Add(t);
                res.Add(t);
            }
        }
        return(res);
    }
Exemplo n.º 6
0
        /// <summary>
        ///     Set Retrieved Threat List.
        /// </summary>
        /// <param name="value">
        ///     The <see cref="ThreatList" /> retrieved from the Google Safe Browsing API.
        /// </param>
        /// <returns>
        ///     This threat list update result builder.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="value" /> is a null reference.
        /// </exception>
        public ThreatListUpdateResultBuilder SetRetrievedThreatList(ThreatList value)
        {
            Guard.ThrowIf(nameof(value), value).Null();

            this.RetrievedThreatList = value;
            return(this);
        }
Exemplo n.º 7
0
        /// <summary>
        ///     Create a Threat List Synchronization Completed Event Arguments.
        /// </summary>
        /// <param name="synchronizedThreatList">
        ///     The <see cref="ThreatList" /> that was synchronized successfully.
        /// </param>
        /// <param name="synchronizationStartDate">
        ///     The date, in Coordinated Universal Time (UTC), the synchronization operation for
        ///     <paramref name="synchronizedThreatList" /> started. If the date is not expressed in UTC, it is
        ///     converted to it.
        /// </param>
        /// <param name="synchronizationCompletionDate">
        ///     The date, in Coordinated Universal Time (UTC), the synchronization operation for
        ///     <paramref name="synchronizedThreatList" /> completed. If the date is not expressed in UTC, it is
        ///     converted to it.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="synchronizedThreatList" /> is a null reference.
        /// </exception>
        internal ThreatListSynchronizationCompletedEventArgs(ThreatList synchronizedThreatList, DateTime synchronizationStartDate, DateTime synchronizationCompletionDate)
        {
            Guard.ThrowIf(nameof(synchronizedThreatList), synchronizedThreatList).Null();

            this.SynchronizationCompletionDate = synchronizationCompletionDate;
            this.SynchronizationStartDate      = synchronizationStartDate;
            this.SynchronizedThreatList        = synchronizedThreatList;
        }
    public override object Clone()
    {
        ThreatList tl = new ThreatList ();

        for (int n = 0 ; n < Count ; ++n)
            tl.Add (((Threat) this[n]).Clone ());

        return (tl);
    }
        public Task StoreThreatListAsync(ThreatList threatList, IEnumerable <string> threatSha256HashPrefixes, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();

            Func <Task> resiliencyPolicyAction      = () => this._database.StoreThreatListAsync(threatList, threatSha256HashPrefixes, cancellationToken);
            var         executeResiliencyPolicyTask = this.ExecuteResiliencyPolicyAsync(resiliencyPolicyAction);

            return(executeResiliencyPolicyTask);
        }
        /// <summary>
        ///     Create a Threat List Synchronization Failed Event Arguments.
        /// </summary>
        /// <param name="skippedThreatList">
        ///     The <see cref="ThreatList" /> that failed to synchronize and was skipped.
        /// </param>
        /// <param name="synchronizationStartDate">
        ///     The date, in Coordinated Universal Time (UTC), the synchronization operation for
        ///     <paramref name="skippedThreatList" /> started. If the date is not expressed in UTC, it is converted to
        ///     it.
        /// </param>
        /// <param name="synchronizationFailureDate">
        ///     The date, in Coordinated Universal Time (UTC), the synchronization operation for
        ///     <paramref name="skippedThreatList" /> failed. If the date is not expressed in UTC, it is converted to
        ///     it.
        /// </param>
        /// <param name="synchronizationException">
        ///     The exception that was thrown when the synchronization operation for
        ///     <paramref name="skippedThreatList"/> failed.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="skippedThreatList" /> is a null reference, or if
        ///     <paramref name="synchronizationException" /> is a null reference.
        /// </exception>
        internal ThreatListSynchronizationFailedEventArgs(ThreatList skippedThreatList, DateTime synchronizationStartDate, DateTime synchronizationFailureDate, Exception synchronizationException)
        {
            Guard.ThrowIf(nameof(skippedThreatList), skippedThreatList).Null();
            Guard.ThrowIf(nameof(synchronizationException), synchronizationException).Null();

            this.SkippedThreatList          = skippedThreatList;
            this.SynchronizationException   = synchronizationException;
            this.SynchronizationFailureDate = synchronizationFailureDate.ToUniversalTime();
            this.SynchronizationStartDate   = synchronizationStartDate.ToUniversalTime();
        }
        /// <summary>
        ///     Store a Threat List Asynchronously.
        /// </summary>
        /// <param name="this">
        ///     A <see cref="IManagedBrowsingDatabase" />.
        /// </param>
        /// <param name="threatList">
        ///     A <see cref="ThreatList" /> to store.
        /// </param>
        /// <param name="threatSha256HashPrefixes">
        ///     A collection of SHA256 hash prefixes, formatted as hexadecimal encoded strings, identifying the threats
        ///     associated with <paramref name="threatList" /> and should be stored.
        /// </param>
        /// <exception cref="Gee.External.Browsing.Databases.BrowsingDatabaseException">
        ///     Thrown if a database error occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="this" /> is a null reference, or if <paramref name="threatList" /> is a null
        ///     reference, or if <paramref name="threatSha256HashPrefixes" /> is a null reference.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        ///     Thrown if <paramref name="this" /> is disposed.
        /// </exception>
        public static Task StoreThreatListAsync(this IManagedBrowsingDatabase @this, ThreatList threatList, IEnumerable <string> threatSha256HashPrefixes)
        {
            Guard.ThrowIf(nameof(@this), @this).Null();

            // ...
            //
            // Throws an exception if the operation fails.
            var storeThreatListTask = @this.StoreThreatListAsync(threatList, threatSha256HashPrefixes, CancellationToken.None);

            return(storeThreatListTask);
        }
        /// <summary>
        ///     Store a Threat List Asynchronously.
        /// </summary>
        /// <param name="threatList">
        ///     A <see cref="ThreatList" /> to store.
        /// </param>
        /// <param name="threatSha256HashPrefixes">
        ///     A collection of SHA256 hash prefixes, formatted as hexadecimal encoded strings, identifying the threats
        ///     associated with <paramref name="threatList" /> and should be stored.
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token to cancel the asynchronous operation with.
        /// </param>
        /// <returns>
        ///     A task representing the asynchronous operation.
        /// </returns>
        /// <exception cref="Gee.External.Browsing.Databases.BrowsingDatabaseException">
        ///     Thrown if a database error occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="threatList" /> is a null reference, or if
        ///     <paramref name="threatSha256HashPrefixes" /> is a null reference.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        ///     Thrown if the object is disposed.
        /// </exception>
        /// <exception cref="System.OperationCanceledException">
        ///     Thrown if the asynchronous operation is cancelled.
        /// </exception>
        public virtual Task StoreThreatListAsync(ThreatList threatList, IEnumerable <string> threatSha256HashPrefixes, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();

            // ...
            //
            // Throws an exception if the operation fails.
            var storeThreatListTask = this._database.StoreThreatListAsync(threatList, threatSha256HashPrefixes, cancellationToken);

            return(storeThreatListTask);
        }
Exemplo n.º 13
0
    public override object Clone()
    {
        ThreatList tl = new ThreatList();

        for (int n = 0; n < Count; ++n)
        {
            tl.Add(((Threat)this[n]).Clone());
        }

        return(tl);
    }
 public InterestingFieldAgent(ThreatSearcher searcher, int size)
 {
     interestingfields = new bool[size, size];
     this.size = size;
     ownthreatlist = new ThreatList();
     oppthreatlist = new ThreatList();
     ownremovedthreatlist = new ThreatList();
     oppremovedthreatlist = new ThreatList();
     ownaddedthreatlist = new ThreatList();
     oppaddedthreatlist = new ThreatList();
     this.searcher = searcher;
 }
Exemplo n.º 15
0
 public InterestingFieldAgent(ThreatSearcher searcher, int size)
 {
     interestingfields    = new bool[size, size];
     this.size            = size;
     ownthreatlist        = new ThreatList();
     oppthreatlist        = new ThreatList();
     ownremovedthreatlist = new ThreatList();
     oppremovedthreatlist = new ThreatList();
     ownaddedthreatlist   = new ThreatList();
     oppaddedthreatlist   = new ThreatList();
     this.searcher        = searcher;
 }
        /// <summary>
        ///     Create a Base JSON Database.
        /// </summary>
        /// <param name="databaseFilePath">
        ///     An absolute file path to a database file. If the file does not exist, it will be created.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="databaseFilePath" /> is a null reference.
        /// </exception>
        private protected BaseJsonBrowsingDatabase(string databaseFilePath)
        {
            this._database           = new MemoryBrowsingDatabase();
            this._disposed           = false;
            this.DatabaseFileManager = new JsonFileManager(databaseFilePath);
            this.DatabaseFilePath    = databaseFilePath;
            // ...
            //
            // ...
            LoadDatabase(this);

            // <summary>
            //      Load Database.
            // </summary>
            void LoadDatabase(BaseJsonBrowsingDatabase @this)
            {
                try {
                    // ...
                    //
                    // Throws an exception if the operation fails.
                    var cFileModel = @this.DatabaseFileManager.Read();
                    if (cFileModel.ThreatLists != null)
                    {
                        foreach (var cThreatListModel in cFileModel.ThreatLists)
                        {
                            var cPlatformType    = cThreatListModel.PlatformType;
                            var cThreatEntryType = cThreatListModel.ThreatEntryType;
                            var cThreatType      = cThreatListModel.ThreatType;
                            var cThreatList      = ThreatList.Build()
                                                   .SetDescriptor(cThreatType, cPlatformType, cThreatEntryType)
                                                   .SetRetrieveDate(cThreatListModel.RetrieveDate)
                                                   .SetState(cThreatListModel.State)
                                                   .SetWaitToDate(cThreatListModel.WaitToDate)
                                                   .Build();

                            // ...
                            //
                            // Throws an exception if the operation fails.
                            var cThreatSha256HashPrefixes = cThreatListModel.ThreatSha256HashPrefixes;
                            var cStoreThreatListTask      = @this._database.StoreThreatListAsync(cThreatList, cThreatSha256HashPrefixes);
                            cStoreThreatListTask.Wait();
                        }
                    }
                }
                catch {
                    // ...
                    //
                    // We don't care if we are unable to load the database.
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        ///     Set Retrieved Threat List.
        /// </summary>
        /// <param name="valueAction">
        ///     An action to create the <see cref="ThreatList" /> retrieved from the Google Safe Browsing API.
        /// </param>
        /// <returns>
        ///     This threat list update result builder.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="valueAction" /> is a null reference.
        /// </exception>
        public ThreatListUpdateResultBuilder SetRetrievedThreatList(Func <ThreatListBuilder, ThreatList> valueAction)
        {
            Guard.ThrowIf(nameof(valueAction), valueAction).Null();

            // ...
            //
            // Throws an exception if the operation fails.
            var threatListBuilder = ThreatList.Build();
            var threatList        = valueAction(threatListBuilder);

            this.SetRetrievedThreatList(threatList);

            return(this);
        }
Exemplo n.º 18
0
 public void ReCheckThreatList()
 {
     for (int i = 0; i < Land.allLand.Count; i++)
     {
         if (Land.allLand[i].LandUnit != null && Land.allLand[i].LandUnit.Faction != Faction)
         {
             if (SearchTheartList(Land.allLand[i].LandUnit) == -1)
             {
                 ThreatList temp = new ThreatList();
                 temp.threatUnit  = Land.allLand[i].LandUnit;
                 temp.threatMount = 0.0f;
                 aggroList.Add(temp);
             }
         }
     }
 }
Exemplo n.º 19
0
    public void AddThreat(Unit _target, float _value)
    {
        int temp = SearchTheartList(_target);

        if (temp != -1)
        {
            aggroList[temp].AddThreatValue(_value);
        }
        else
        {
            ThreatList tempList = new ThreatList();
            tempList.threatUnit  = _target;
            tempList.threatMount = _value;
            aggroList.Add(tempList);
        }
    }
Exemplo n.º 20
0
        /// <summary>
        ///     Store a Threat List Asynchronously.
        /// </summary>
        /// <param name="threatList">
        ///     A <see cref="ThreatList" /> to store.
        /// </param>
        /// <param name="threatSha256HashPrefixes">
        ///     A collection of SHA256 hash prefixes, formatted as hexadecimal encoded strings, identifying the threats
        ///     associated with <paramref name="threatList" /> and should be stored.
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token to cancel the asynchronous operation with.
        /// </param>
        /// <returns>
        ///     A task representing the asynchronous operation.
        /// </returns>
        /// <exception cref="Gee.External.Browsing.Databases.BrowsingDatabaseException">
        ///     Thrown if a database error occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="threatList" /> is a null reference, or if
        ///     <paramref name="threatSha256HashPrefixes" /> is a null reference.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        ///     Thrown if the object is disposed.
        /// </exception>
        /// <exception cref="System.OperationCanceledException">
        ///     Thrown if the asynchronous operation is cancelled.
        /// </exception>
        public Task StoreThreatListAsync(ThreatList threatList, IEnumerable <string> threatSha256HashPrefixes, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();
            Guard.ThrowIf(nameof(threatList), threatList).Null();

            lock (this._lock) {
                // ...
                //
                // We need to sort the threat list so that it can later be searched. Throws an exception if the
                // operation fails.
                var newSha256HashPrefixes = new List <string>(threatSha256HashPrefixes);
                newSha256HashPrefixes.Sort();

                this._threatLists[threatList.Descriptor] = threatList;
                this._threats[threatList.Descriptor]     = newSha256HashPrefixes;
                return(Task.CompletedTask);
            }
        }
Exemplo n.º 21
0
        public Actor()
        {
            Abilities = new List<Ability>();
            Auras = new List<Aura>();
            Equipment = new List<Item>();
            Orders = new List<Order>();

            IsAlive = true;
            BaseStatistics = new Statistics();

            CurrentHealth = MaximumHealth;
            CurrentMana = MaximumMana;

            Diameter = 1.0f;
            Targets = new Queue<Actor>();
            ThreatList = new ThreatList();

            Direction = new Vector2(0, -1);
            MovementSpeed = 5f;
        }
Exemplo n.º 22
0
        public static async Task <IReadOnlyCollection <ThreatList> > GetThreatListsAsync(this IUnmanagedBrowsingDatabase @this, IEnumerable <ThreatListDescriptor> threatListDescriptors)
        {
            Guard.ThrowIf(nameof(@this), @this).Null();
            Guard.ThrowIf(nameof(threatListDescriptors), threatListDescriptors).Null();

            var threatLists = new List <ThreatList>();

            foreach (var threatListDescriptor in threatListDescriptors)
            {
                // ...
                //
                // Throws an exception if the operation fails.
                var getThreatListTask = @this.GetThreatListAsync(threatListDescriptor);
                var threatList        = await getThreatListTask.ConfigureAwait(false);

                threatList = threatList ?? ThreatList.CreateInvalid(threatListDescriptor);
                threatLists.Add(threatList);
            }

            return(threatLists);
        }
 /// <summary>
 ///     Get Threat List Updates Asynchronously.
 /// </summary>
 /// <param name="this">
 ///     A <see cref="IBrowsingClient" />.
 /// </param>
 /// <param name="threatList">
 ///     A <see cref="ThreatList" /> to retrieve.
 /// </param>
 /// <param name="updateConstraints">
 ///     The <see cref="ThreatListUpdateConstraints" /> to apply when <paramref name="threatList" /> is
 ///     retrieved. A null reference indicates no <see cref="ThreatListUpdateConstraints" /> should be applied.
 /// </param>
 /// <returns>
 ///     A <see cref="ThreatListUpdateResponse" />.
 /// </returns>
 /// <exception cref="Gee.External.Browsing.Clients.BrowsingClientException">
 ///     Thrown if an error communicating with the Google Safe Browsing API occurs.
 /// </exception>
 /// <exception cref="System.ArgumentNullException">
 ///     Thrown if <paramref name="this" /> is a null reference, or if <paramref name="threatList" /> is a
 ///     null reference.
 /// </exception>
 /// <exception cref="System.ObjectDisposedException">
 ///     Thrown if the <paramref name="this" /> is disposed.
 /// </exception>
 /// <exception cref="System.TimeoutException">
 ///     Thrown if communication with the Google Safe Browsing API times out.
 /// </exception>
 public static Task <ThreatListUpdateResponse> GetThreatListUpdatesAsync(this IBrowsingClient @this, ThreatList threatList, ThreatListUpdateConstraints updateConstraints) => @this.GetThreatListUpdatesAsync(threatList, updateConstraints, CancellationToken.None);
        /// <summary>
        ///     Get Threat List Updates Asynchronously.
        /// </summary>
        /// <param name="this">
        ///     A <see cref="IBrowsingClient" />.
        /// </param>
        /// <param name="threatList">
        ///     A <see cref="ThreatList" /> to retrieve.
        /// </param>
        /// <param name="updateConstraints">
        ///     The <see cref="ThreatListUpdateConstraints" /> to apply when <paramref name="threatList" /> is
        ///     retrieved. A null reference indicates no <see cref="ThreatListUpdateConstraints" /> should be applied.
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token to cancel the asynchronous operation with.
        /// </param>
        /// <returns>
        ///     A <see cref="ThreatListUpdateResponse" />.
        /// </returns>
        /// <exception cref="Gee.External.Browsing.Clients.BrowsingClientException">
        ///     Thrown if an error communicating with the Google Safe Browsing API occurs.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     Thrown if <paramref name="this" /> is a null reference, or if <paramref name="threatList" /> is a
        ///     null reference.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        ///     Thrown if the <paramref name="this" /> is disposed.
        /// </exception>
        /// <exception cref="System.OperationCanceledException">
        ///     Thrown if the asynchronous operation is cancelled.
        /// </exception>
        /// <exception cref="System.TimeoutException">
        ///     Thrown if communication with the Google Safe Browsing API times out.
        /// </exception>
        public static Task <ThreatListUpdateResponse> GetThreatListUpdatesAsync(this IBrowsingClient @this, ThreatList threatList, ThreatListUpdateConstraints updateConstraints, CancellationToken cancellationToken)
        {
            Guard.ThrowIf(nameof(@this), @this).Null();
            Guard.ThrowIf(nameof(threatList), threatList).Null();

            var threatListUpdateRequestBuilder = ThreatListUpdateRequest.Build();

            threatListUpdateRequestBuilder.AddQuery(b => {
                b.SetThreatListDescriptor(threatList.Descriptor);
                b.SetThreatListState(threatList.State);
                b.SetUpdateConstraints(updateConstraints);
                return(b.Build());
            });

            // ...
            //
            // Throws an exception if the operation fails.
            var threatListUpdateRequest  = threatListUpdateRequestBuilder.Build();
            var getThreatListUpdatesTask = @this.GetThreatListUpdatesAsync(threatListUpdateRequest, cancellationToken);

            return(getThreatListUpdatesTask);
        }
        private async Task SynchronizeDatabaseAsync()
        {
            var cancellationToken = this._synchronizationTaskCancellationTokenSource.Token;

            while (!cancellationToken.IsCancellationRequested)
            {
                var getThreatListUpdatesTask = GetThreatListUpdatesAsync(this);
                var(threatListUpdateResponse, delayToDate) = await getThreatListUpdatesTask.ConfigureAwait(false);

                if (threatListUpdateResponse != null)
                {
                    foreach (var threatListUpdateResult in threatListUpdateResponse.Results)
                    {
                        var threatListWaitToDate = threatListUpdateResult.RetrievedThreatList.WaitToDate;
                        if (threatListWaitToDate != null && threatListWaitToDate < delayToDate)
                        {
                            delayToDate = threatListWaitToDate.Value;
                        }

                        var synchronizeThreatListTask = SynchronizeThreatListAsync(this, threatListUpdateResult);
                        await synchronizeThreatListTask.ConfigureAwait(false);
                    }
                }

                var delayToTask = DelayToAsync(this, delayToDate);
                await delayToTask.ConfigureAwait(false);
            }

            // <summary>
            //      Delay to a Date Asynchronously.
            // </summary>
            async Task DelayToAsync(BrowsingDatabaseManager @this, DateTime cDate)
            {
                try {
                    var cCancellationToken = @this._synchronizationTaskCancellationTokenSource.Token;
                    var cDelayToTask       = TaskExtension.DelayTo(cDate, cCancellationToken);
                    await cDelayToTask.ConfigureAwait(false);
                }
                catch (OperationCanceledException) {
                    // ...
                    //
                    // We don't care if the cancellation token is cancelled.
                }
            }

            // <summary>
            //      Get Threat List Updates Asynchronously.
            // </summary>
            async Task <(ThreatListUpdateResponse, DateTime)> GetThreatListUpdatesAsync(BrowsingDatabaseManager @this)
            {
                var cDelayToDate = DateTime.UtcNow.AddMinutes(30);

                try {
                    IEnumerable <ThreatListDescriptor> cThreatListDescriptors = @this._updateConstraints.Keys;
                    if (@this._updateConstraints.Count == 0)
                    {
                        // ...
                        //
                        // If the database synchronizer is not restricted to specific threat lists, we retrieve all
                        // available threat lists from the Google Safe Browsing API. We don't cache the result in case
                        // new threat lists are made available between synchronization iterations.
                        //
                        // Throws an exception if the operation fails.
                        var cGetThreatListDescriptorsTask = @this._client.GetThreatListDescriptorsAsync();
                        cThreatListDescriptors = await cGetThreatListDescriptorsTask.ConfigureAwait(false);
                    }

                    // ...
                    //
                    // Retrieve the threat lists from the database. Throws an exception if the operation fails.
                    var cGetThreatListsTask = @this._database.GetThreatListsAsync(cThreatListDescriptors);
                    var cThreatLists        = await cGetThreatListsTask.ConfigureAwait(false);

                    ThreatListUpdateRequestBuilder cThreatListUpdateRequestBuilder = null;
                    foreach (var cThreatList in cThreatLists)
                    {
                        if (cThreatList.Expired)
                        {
                            cThreatListUpdateRequestBuilder = cThreatListUpdateRequestBuilder ?? ThreatListUpdateRequest.Build();
                            var cThreatListDescriptor = cThreatList.Descriptor;
                            var cThreatListState      = cThreatList.State;
                            @this._updateConstraints.TryGetValue(cThreatListDescriptor, out var cThreatListUpdateConstraints);
                            cThreatListUpdateRequestBuilder.AddQuery(b => {
                                b.SetThreatListDescriptor(cThreatListDescriptor);
                                b.SetThreatListState(cThreatListState);
                                b.SetUpdateConstraints(cThreatListUpdateConstraints);
                                return(b.Build());
                            });
                        }
                        else
                        {
                            if (cThreatList.WaitToDate != null && cThreatList.WaitToDate < cDelayToDate)
                            {
                                // ...
                                //
                                // If the current threat list's wait to date is earlier than the previous threat
                                // list's wait to date, take the current the threat list's wait to date instead.
                                cDelayToDate = cThreatList.WaitToDate.Value;
                            }
                        }
                    }

                    ThreatListUpdateResponse cThreatListUpdateResponse = null;
                    if (cThreatListUpdateRequestBuilder != null)
                    {
                        // ...
                        //
                        // Throws an exception if the operation fails.
                        var cThreatListUpdateRequest  = cThreatListUpdateRequestBuilder.Build();
                        var cGetThreatListUpdatesTask = @this._client.GetThreatListUpdatesAsync(cThreatListUpdateRequest);
                        cThreatListUpdateResponse = await cGetThreatListUpdatesTask.ConfigureAwait(false);
                    }

                    return(cThreatListUpdateResponse, cDelayToDate);
                }
                catch {
                    return(null, cDelayToDate);
                }
            }

            // <summary>
            //      Synchronize Threat List Asynchronously.
            // </summary>
            async Task SynchronizeThreatListAsync(BrowsingDatabaseManager @this, ThreatListUpdateResult cThreatListUpdateResult)
            {
                var cSynchronizationStartDate = DateTime.UtcNow;
                var cThreatList = cThreatListUpdateResult.RetrievedThreatList;

                try {
                    var cSha256HashPrefixes = cThreatListUpdateResult.ThreatsToAdd;
                    if (cThreatListUpdateResult.IsFullUpdate)
                    {
                        // ...
                        //
                        // Throws an exception if the operation fails.
                        var cModifyThreatListTask = @this._database.StoreThreatListAsync(cThreatList, cSha256HashPrefixes);
                        await cModifyThreatListTask.ConfigureAwait(false);
                    }
                    else if (cThreatListUpdateResult.IsPartialUpdate)
                    {
                        // ...
                        //
                        // Throws an exception if the operation fails.
                        var cIndices = cThreatListUpdateResult.ThreatsToRemove;
                        var cModifyThreatListTask = @this._database.ModifyThreatListAsync(cThreatList, cSha256HashPrefixes, cIndices);
                        await cModifyThreatListTask.ConfigureAwait(false);
                    }

                    // ...
                    //
                    // Throws an exception if the operation fails.
                    var cComputeThreatListChecksumTask = @this._database.ComputeThreatListChecksumAsync(cThreatList.Descriptor);
                    var cThreatListChecksum            = await cComputeThreatListChecksumTask.ConfigureAwait(false);

                    if (cThreatListChecksum != cThreatListUpdateResult.RetrievedThreatListChecksum)
                    {
                        // ...
                        //
                        // Throws an exception if the operation fails.
                        cThreatList = ThreatList.CreateInvalid(cThreatList.Descriptor);
                        var cUpdateConstraints        = cThreatListUpdateResult.Query.UpdateConstraints;
                        var cGetThreatListUpdatesTask = @this._client.GetThreatListUpdatesAsync(cThreatList, cUpdateConstraints);
                        var cThreatListUpdateRequest  = await cGetThreatListUpdatesTask.ConfigureAwait(false);

                        cThreatListUpdateResult = cThreatListUpdateRequest.Results.First();
                        cSha256HashPrefixes     = cThreatListUpdateResult.ThreatsToAdd;
                        if (cThreatListUpdateResult.IsFullUpdate)
                        {
                            // ...
                            //
                            // Throws an exception if the operation fails.
                            cThreatList = cThreatListUpdateResult.RetrievedThreatList;
                            var cModifyThreatListTask = @this._database.StoreThreatListAsync(cThreatList, cSha256HashPrefixes);
                            await cModifyThreatListTask.ConfigureAwait(false);
                        }
                    }

                    // ...
                    //
                    // Invoke threat list synchronization completed event.
                    var cSynchronizationCompletionDate = DateTime.UtcNow;
                    @this.OnThreatListSynchronizationCompleted(new ThreatListSynchronizationCompletedEventArgs(
                                                                   cThreatList,
                                                                   cSynchronizationStartDate,
                                                                   cSynchronizationCompletionDate
                                                                   ));
                }
                catch (Exception cEx) {
                    // ...
                    //
                    // Invoke threat list synchronization failed event.
                    var cSynchronizationFailureDate = DateTime.UtcNow;
                    @this.OnThreatListSynchronizationFailed(new ThreatListSynchronizationFailedEventArgs(
                                                                cThreatList,
                                                                cSynchronizationStartDate,
                                                                cSynchronizationFailureDate,
                                                                cEx
                                                                ));
                }
            }
        }
Exemplo n.º 26
0
    public void UpdateThreatLists(int[,] board, Coordinate move, int attacker)
    {
        // 0. Initialized the removelists
        ownremovedthreatlist = new ThreatList();
        oppremovedthreatlist = new ThreatList();
        ownaddedthreatlist   = new ThreatList();
        oppaddedthreatlist   = new ThreatList();

        // 1. Remove blocked threats from both lists.
        ThreatList lookup = new ThreatList();

        foreach (Threat t in oppthreatlist)
        {
            foreach (Coordinate c in t.fields)
            {
                if (c.X == move.X && c.Y == move.Y)
                {
                    oppremovedthreatlist.Add(t);
                    lookup.Add(t.cause);
                }
            }
        }
        foreach (Threat t in oppremovedthreatlist)
        {
            oppthreatlist.Remove(t);
        }
        foreach (Threat t in ownthreatlist)
        {
            foreach (Coordinate c in t.fields)
            {
                if (c.X == move.X && c.Y == move.Y)
                {
                    ownremovedthreatlist.Add(t);
                    lookup.Add(t.cause);
                }
            }
        }
        foreach (Threat t in ownremovedthreatlist)
        {
            ownthreatlist.Remove(t);
        }

        //Lookup if "causes" still cause threats
        foreach (Coordinate c in lookup)
        {
            if (board[c.X, c.Y] == 1)
            {
                ThreatList curthreats = searcher.investigate(board, c, 1);

                ownaddedthreatlist = Merge(ownthreatlist, curthreats);
            }
            if (board[c.X, c.Y] == -1)
            {
                ThreatList curthreats = searcher.investigate(board, c, -1);

                oppaddedthreatlist = Merge(oppthreatlist, curthreats);
            }
        }

        if (attacker == 1)
        {
            // We are attacking
            // 2. Add our threats we build to our list

            ThreatList curthreats = searcher.investigate(board, move, attacker, true);

            Merge(ownaddedthreatlist, Merge(ownthreatlist, curthreats));
        }
        else
        {
            // The opponent is attacking
            // 2. Add his threats to his list
            ThreatList curthreats = searcher.investigate(board, move, attacker, true);

            Merge(oppaddedthreatlist, Merge(oppthreatlist, curthreats));
        }
    }
    private ThreatList SearchBoards(Coordinate node)
    {
        ThreatList res = new ThreatList ();
        int turn = attacker;

        Item tmpval;
        int digit1 = 0;
        int digit2 = 0;
        int digit3 = 0;
        int digit4 = 0;
        for (int j = 8; j >= 0; --j)
        {
            if (j + node.X - 4 >= 0 && j + node.X - 4 < board.GetLength(0))
            {
                digit1 += board[node.X + j - 4, node.Y] * turn + 1;
                //			Console.WriteLine("Grabbing {0}/{1}", node.move.x + j - 4, node.move.y);
            }
            else digit1 += 3;
            if (j + node.Y - 4 >= 0 && j + node.Y - 4 < board.GetLength(1))
            {
                digit2 += board[node.X, node.Y + j - 4] * turn + 1;
                //			Console.WriteLine("Grabbing {0}/{1}", node.move.x , node.move.y + j -4);
            }
            else digit2 += 3;
            if (node.X + j - 4 >= 0 && node.X + j - 4 < board.GetLength(0) &&
                node.Y + j - 4 >= 0 && node.Y + j - 4 < board.GetLength(1) )
            {
                digit3 += board[node.X + j - 4, node.Y + j - 4] * turn + 1;
                //			Console.WriteLine("Grabbing {0}/{1}", node.move.x + j - 4, node.move.y + j - 4);
            }
            else digit3 += 3;
            if (node.X - j + 4 >= 0 && node.X - j + 4 < board.GetLength(0) &&
                node.Y + j - 4 >= 0 && node.Y + j - 4 < board.GetLength(1) )
            {
                digit4 += board[node.X - j + 4, node.Y + j - 4] * turn + 1;
                //			Console.WriteLine("Grabbing {0}/{1}", node.move.x - j + 4, node.move.y + j - 4);
            }
            else digit4 += 3;
            if (j != 0)
            {
                digit1 <<= 2;
                digit2 <<= 2;
                digit3 <<= 2;
                digit4 <<= 2;
            }
        }

        tmpval = table[digit1];

        if (tmpval != null && (tmpval.create == false || create == true))
        {
            //Console.WriteLine("horz category: {0}", tmpval.category);
            ArrayList moves = new ArrayList();
            foreach(int field in tmpval.fields)
            {
                moves.Add(new Coordinate(node.X + tmpval.offset + field, node.Y));
            }
            Threat t = new Threat(node, tmpval.category, moves, tmpval.create);
            res.Add(t);
        }
        tmpval = table[digit2];
        if (tmpval != null && (tmpval.create == false || create == true))
        {
            //Console.WriteLine("vert category: {0}", tmpval.category);
            //Console.WriteLine("Node: {0}", node);
            //Console.WriteLine("offset: {0}", tmpval.offset);
            ArrayList moves = new ArrayList();
            foreach(int field in tmpval.fields)
            {
                //Coordinate tmp = new Coordinate(node.X , node.Y + tmpval.offset + field);
                //Console.WriteLine("adding move: {0}", tmp);
                moves.Add(new Coordinate(node.X, node.Y + tmpval.offset + field));
            }
            Threat t = new Threat(node, tmpval.category, moves, tmpval.create);
            res.Add(t);
        }
        tmpval = table[digit3];
        if (tmpval != null && (tmpval.create == false || create == true))
        {
            //Console.WriteLine("diag 1 category: {0}", tmpval.category);
            ArrayList moves = new ArrayList();
            foreach(int field in tmpval.fields)
            {
                moves.Add(new Coordinate(node.X + tmpval.offset + field, node.Y + tmpval.offset + field));
            }
            Threat t = new Threat(node, tmpval.category, moves, tmpval.create);
            res.Add(t);
        }
        tmpval = table[digit4];
        if (tmpval != null && (tmpval.create == false || create == true))
        {
            //Console.WriteLine("diag 2 category: {0}", tmpval.category);
            //Console.WriteLine("Node: {0}", node);
            //Console.WriteLine("offset: {0}", tmpval.offset);
            ArrayList moves = new ArrayList();
            foreach(int field in tmpval.fields)
            {
                //Coordinate tmp = new Coordinate(node.X -(tmpval.offset + field), node.Y + tmpval.offset + field);
                //Console.WriteLine("adding move: {0}", tmp);
                moves.Add(new Coordinate(node.X -(tmpval.offset + field), node.Y + tmpval.offset + field));
            }
            Threat t = new Threat(node, tmpval.category, moves, tmpval.create);
            res.Add(t);
        }

        return res;
    }
 /** Add threats from from into into if they are not contained yet.
  *
  * @returns ArrayList<Threat> List of the added threats.
  */
 private ThreatList Merge(ThreatList into, ThreatList from)
 {
     ThreatList res = new ThreatList ();
     foreach (Threat t in from)
     {
         // check for every t if it is already in into-list
         bool alreadyin = false;
         foreach (Threat ct in into)
         {
             alreadyin = true;
             if (ct.category == t.category && ct.fields.Count == t.fields.Count)
             {
                 for (int i = 0; i < ct.fields.Count; ++i)
                 {
                     alreadyin = alreadyin &&
                         ( ( ((Coordinate)(ct.fields[i])).X == ((Coordinate)(t.fields[i])).X ) &&
                           ( ((Coordinate)(ct.fields[i])).Y == ((Coordinate)(t.fields[i])).Y ) );
                 }
             }
             else alreadyin = false;
         }
         if (alreadyin == false) {
             into.Add(t);
             res.Add(t);
         }
     }
     return res;
 }
    public void UpdateThreatLists(int[,] board, Coordinate move, int attacker)
    {
        // 0. Initialized the removelists
        ownremovedthreatlist = new ThreatList();
        oppremovedthreatlist = new ThreatList();
        ownaddedthreatlist = new ThreatList();
        oppaddedthreatlist = new ThreatList();

        // 1. Remove blocked threats from both lists.
        ThreatList lookup = new ThreatList();
        foreach (Threat t in oppthreatlist) {
            foreach (Coordinate c in t.fields) {
                if (c.X == move.X && c.Y == move.Y) {
                    oppremovedthreatlist.Add(t);
                    lookup.Add(t.cause);
                }
            }
        }
        foreach (Threat t in oppremovedthreatlist) oppthreatlist.Remove(t);
        foreach (Threat t in ownthreatlist) {
            foreach (Coordinate c in t.fields) {
                if (c.X == move.X && c.Y == move.Y) {
                    ownremovedthreatlist.Add(t);
                    lookup.Add(t.cause);
                }
            }
        }
        foreach (Threat t in ownremovedthreatlist) ownthreatlist.Remove(t);

        //Lookup if "causes" still cause threats
        foreach (Coordinate c in lookup)
        {
            if (board[c.X, c.Y] == 1)
            {
                ThreatList curthreats = searcher.investigate(board, c, 1);

                ownaddedthreatlist = Merge(ownthreatlist, curthreats);

            }
            if (board[c.X, c.Y] == -1)
            {
                ThreatList curthreats = searcher.investigate(board, c, -1);

                oppaddedthreatlist = Merge(oppthreatlist, curthreats);
            }
        }

        if (attacker == 1)
        {
            // We are attacking
            // 2. Add our threats we build to our list

            ThreatList curthreats = searcher.investigate(board, move, attacker, true);

            Merge(ownaddedthreatlist, Merge(ownthreatlist, curthreats));

        }
        else
        {
            // The opponent is attacking
            // 2. Add his threats to his list
            ThreatList curthreats = searcher.investigate(board, move, attacker, true);

            Merge(oppaddedthreatlist, Merge(oppthreatlist, curthreats));
        }
    }
Exemplo n.º 30
0
        /// <summary>
        ///     Synchronize Database File Asynchronously.
        /// </summary>
        /// <returns>
        ///     A task representing the asynchronous operation.
        /// </returns>
        private async Task SyncDatabaseFileAsync()
        {
            var cancellationToken = this._syncTaskCancellationTokenSource.Token;

            while (!cancellationToken.IsCancellationRequested)
            {
                try {
                    // ...
                    //
                    // Throws an exception if the operation fails.
                    var fileModel = this.DatabaseFileManager.Read();
                    if (fileModel.ThreatLists != null)
                    {
                        foreach (var threatListModel in fileModel.ThreatLists)
                        {
                            var platformType    = threatListModel.PlatformType;
                            var threatEntryType = threatListModel.ThreatEntryType;
                            var threatType      = threatListModel.ThreatType;
                            var threatList      = ThreatList.Build()
                                                  .SetDescriptor(threatType, platformType, threatEntryType)
                                                  .SetRetrieveDate(threatListModel.RetrieveDate)
                                                  .SetState(threatListModel.State)
                                                  .SetWaitToDate(threatListModel.WaitToDate)
                                                  .Build();

                            // ...
                            //
                            // Throws an exception if the operation fails.
                            var threatSha256HashPrefixes = threatListModel.ThreatSha256HashPrefixes;
                            var storeThreatListTask      = this.StoreThreatListAsync(threatList, threatSha256HashPrefixes, cancellationToken);
                            await storeThreatListTask.ConfigureAwait(false);
                        }
                    }
                }
                catch {
                    // ...
                    //
                    // We don't care if we failed to synchronize the database file. We'll try again on the next
                    // iteration.
                }
                finally {
                    var delayTask = DelayAsync(this);
                    await delayTask.ConfigureAwait(false);
                }
            }

            // <summary>
            //      Delay Asynchronously.
            // </summary>
            async Task DelayAsync(UnmanagedJsonBrowsingDatabase @this)
            {
                try {
                    var cCancellationToken = @this._syncTaskCancellationTokenSource.Token;
                    var cDelayTask         = Task.Delay(UnmanagedJsonBrowsingDatabase.SyncInterval, cCancellationToken);
                    await cDelayTask.ConfigureAwait(false);
                }
                catch (OperationCanceledException) {
                    // ...
                    //
                    // We don't care if the cancellation token is cancelled.
                }
            }
        }
    private ThreatList SearchBoards(Coordinate node)
    {
        ThreatList res  = new ThreatList();
        int        turn = attacker;

        Item tmpval;
        int  digit1 = 0;
        int  digit2 = 0;
        int  digit3 = 0;
        int  digit4 = 0;

        for (int j = 8; j >= 0; --j)
        {
            if (j + node.X - 4 >= 0 && j + node.X - 4 < board.GetLength(0))
            {
                digit1 += board[node.X + j - 4, node.Y] * turn + 1;
                //			Console.WriteLine("Grabbing {0}/{1}", node.move.x + j - 4, node.move.y);
            }
            else
            {
                digit1 += 3;
            }
            if (j + node.Y - 4 >= 0 && j + node.Y - 4 < board.GetLength(1))
            {
                digit2 += board[node.X, node.Y + j - 4] * turn + 1;
                //			Console.WriteLine("Grabbing {0}/{1}", node.move.x , node.move.y + j -4);
            }
            else
            {
                digit2 += 3;
            }
            if (node.X + j - 4 >= 0 && node.X + j - 4 < board.GetLength(0) &&
                node.Y + j - 4 >= 0 && node.Y + j - 4 < board.GetLength(1))
            {
                digit3 += board[node.X + j - 4, node.Y + j - 4] * turn + 1;
                //			Console.WriteLine("Grabbing {0}/{1}", node.move.x + j - 4, node.move.y + j - 4);
            }
            else
            {
                digit3 += 3;
            }
            if (node.X - j + 4 >= 0 && node.X - j + 4 < board.GetLength(0) &&
                node.Y + j - 4 >= 0 && node.Y + j - 4 < board.GetLength(1))
            {
                digit4 += board[node.X - j + 4, node.Y + j - 4] * turn + 1;
                //			Console.WriteLine("Grabbing {0}/{1}", node.move.x - j + 4, node.move.y + j - 4);
            }
            else
            {
                digit4 += 3;
            }
            if (j != 0)
            {
                digit1 <<= 2;
                digit2 <<= 2;
                digit3 <<= 2;
                digit4 <<= 2;
            }
        }

        tmpval = table[digit1];

        if (tmpval != null && (tmpval.create == false || create == true))
        {
            //Console.WriteLine("horz category: {0}", tmpval.category);
            ArrayList moves = new ArrayList();
            foreach (int field in tmpval.fields)
            {
                moves.Add(new Coordinate(node.X + tmpval.offset + field, node.Y));
            }
            Threat t = new Threat(node, tmpval.category, moves, tmpval.create);
            res.Add(t);
        }
        tmpval = table[digit2];
        if (tmpval != null && (tmpval.create == false || create == true))
        {
            //Console.WriteLine("vert category: {0}", tmpval.category);
            //Console.WriteLine("Node: {0}", node);
            //Console.WriteLine("offset: {0}", tmpval.offset);
            ArrayList moves = new ArrayList();
            foreach (int field in tmpval.fields)
            {
                //Coordinate tmp = new Coordinate(node.X , node.Y + tmpval.offset + field);
                //Console.WriteLine("adding move: {0}", tmp);
                moves.Add(new Coordinate(node.X, node.Y + tmpval.offset + field));
            }
            Threat t = new Threat(node, tmpval.category, moves, tmpval.create);
            res.Add(t);
        }
        tmpval = table[digit3];
        if (tmpval != null && (tmpval.create == false || create == true))
        {
            //Console.WriteLine("diag 1 category: {0}", tmpval.category);
            ArrayList moves = new ArrayList();
            foreach (int field in tmpval.fields)
            {
                moves.Add(new Coordinate(node.X + tmpval.offset + field, node.Y + tmpval.offset + field));
            }
            Threat t = new Threat(node, tmpval.category, moves, tmpval.create);
            res.Add(t);
        }
        tmpval = table[digit4];
        if (tmpval != null && (tmpval.create == false || create == true))
        {
            //Console.WriteLine("diag 2 category: {0}", tmpval.category);
            //Console.WriteLine("Node: {0}", node);
            //Console.WriteLine("offset: {0}", tmpval.offset);
            ArrayList moves = new ArrayList();
            foreach (int field in tmpval.fields)
            {
                //Coordinate tmp = new Coordinate(node.X -(tmpval.offset + field), node.Y + tmpval.offset + field);
                //Console.WriteLine("adding move: {0}", tmp);
                moves.Add(new Coordinate(node.X - (tmpval.offset + field), node.Y + tmpval.offset + field));
            }
            Threat t = new Threat(node, tmpval.category, moves, tmpval.create);
            res.Add(t);
        }

        return(res);
    }