Example #1
0
        public List <IMatchable> Get(IMatchable Matchable)
        {
            using (var db = new EGULFEntities())
            {
                var queryResult = db.sp_SelProjectSuitability(
                    Matchable.CompanyId,
                    Matchable.MatchableId,
                    Matchable.SuitabilityId,
                    Matchable.PemexCheck,
                    Matchable.StartDate,
                    Matchable.EndDate,
                    Matchable.RegionId,
                    Matchable.DynamicPositionSystem,
                    Matchable.DailyMaxRate,
                    Matchable.SubtypeId,
                    Matchable.BollardPull,
                    Matchable.BollardPullAhead,
                    Matchable.BollardPullAstern,
                    Matchable.NumberPassengers,
                    Matchable.CargoCapacity
                    ).ToList();

                List <IMatchable> result = new List <IMatchable>();
                foreach (var c in queryResult.ToList())
                {
                    IMatchable nItem = new MatchModel();
                    nItem.Offerted                  = c.Offerted;
                    nItem.MatchableId               = c.VesselId;
                    nItem.SuitabilityId             = c.ProjectTypeId;
                    nItem.PemexCheck                = c.PemexCheck;
                    nItem.StartDate                 = c.StartDate;
                    nItem.EndDate                   = c.EndDate;
                    nItem.RegionId                  = c.RegionId;
                    nItem.DynamicPositionSystem     = c.DynamicPositionSystem;
                    nItem.DynamicPositionSystemName = c.DynamicPositionSystemName;
                    nItem.DailyMaxRate              = c.DailyMaxRate;
                    nItem.SubtypeId                 = c.SubtypeId;
                    nItem.Subtype                   = c.Subtype;
                    nItem.BollardPull               = c.BollardPull;
                    nItem.BollardPullAhead          = c.BollardPullAhead;
                    nItem.BollardPullAstern         = c.BollardPullAstern;
                    nItem.NumberPassengers          = c.NumberPassengers;
                    nItem.CargoCapacity             = c.CargoCapacity;
                    nItem.BHP       = c.BHP;
                    nItem.PumpRates = c.PumpRates;

                    nItem.VesselMatch = new VesselModel()
                    {
                        Location = new LatLng()
                        {
                            Lat = c.Lat, Lng = c.Lng
                        },
                        VesselType = new VesselTypeModel()
                        {
                            Name = c.VesselType
                        },
                        YearBuild = c.YearBuild,
                        Country   = new CountryModel()
                        {
                            Name = c.Country
                        },
                        HomePort = new PortModel()
                        {
                            Name = c.HomePort
                        },
                        Imo     = c.IMO,
                        Name    = c.VesselName,
                        Company = new CompanyModel()
                        {
                            CompanyId = c.VesselCompanyId
                        }
                    };
                    nItem.VesselSuitabilityProject = c.VesselProjectTypes;
                    nItem.IsMyVessel = (c.IsMyVessel == 1);
                    result.Add(nItem);
                }
                return(result);
            }
        }
Example #2
0
 /// <summary>
 /// Create a pattern that lazily matches a given pattern or the empty string.
 /// </summary>
 /// <param name="pat">given pattern</param>
 /// <returns>the new pattern</returns>
 public static Pattern MaybeLazy(IMatchable pat)
 {
     return(new OptionalPattern(pat, true));
 }
Example #3
0
 public RepeatingPattern(IMatchable pattern, bool needAtLeastOne, bool lazy = false)
 {
     this.pattern        = pattern;
     this.needAtLeastOne = needAtLeastOne;
     this.lazy           = lazy;
 }
Example #4
0
        /// <summary>
        /// This gives sub-classes the chance to directly override, control or otherwise tamper
        /// with the matching process.  This is also where normal matching is performed,
        /// so to replace it, simply don't call the base.OnMatch method.  To tweak the results,
        /// the base method should be performed first, and the results can then be modified.
        /// </summary>
        /// <param name="other"></param>
        /// <param name="mismatchedProperties"></param>
        /// <returns></returns>
        protected virtual bool OnMatch(IMatchable other, List<string> mismatchedProperties)
        {
            Type original = GetType();
            Type copy = other.GetType();

            // Public Properties ------------------------------------------------------
            PropertyInfo[] originalProperties = original.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            PropertyInfo[] copyProperties = copy.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo originalProperty in originalProperties)
            {
                if (copyProperties.Contains(originalProperty.Name) == false)
                {
                    mismatchedProperties.Add(originalProperty.Name);
                    continue;
                }
                PropertyInfo copyProperty = copyProperties.GetFirst(originalProperty.Name);
                if (copyProperty == null)
                {
                    // The name of the property was not found on the other object
                    mismatchedProperties.Add(originalProperty.Name);
                    continue;
                }

                object originalValue = originalProperty.GetValue(this, null);
                object copyValue = copyProperty.GetValue(other, null);
                if (Match(originalValue, copyValue) == false)
                {
                    mismatchedProperties.Add(originalProperty.Name);
                }
            }

            // Public Fields ---------------------------------------------------------
            FieldInfo[] originalFields = original.GetFields(BindingFlags.Public | BindingFlags.Instance);
            FieldInfo[] copyFields = copy.GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (FieldInfo originalField in originalFields)
            {
                if (copyFields.Contains(originalField.Name) == false)
                {
                    mismatchedProperties.Add(originalField.Name);
                    continue;
                }

                FieldInfo copyField = copyFields.GetFirst(originalField.Name);
                if (copyField == null)
                {
                    mismatchedProperties.Add(originalField.Name);
                    continue;
                }

                object originalValue = originalField.GetValue(this);
                object copyValue = copyField.GetValue(other);
                if (Match(originalValue, copyValue) == false)
                {
                    mismatchedProperties.Add(originalField.Name);
                }
            }
            if (mismatchedProperties.Count > 0)
            {
                return false;
            }
            return true;
        }
Example #5
0
 /// <summary>
 /// Create a pattern that lazily matches strings from this pattern, followed by zero or more occurrences of the given pattern.
 /// </summary>
 /// <param name="pattern">the given pattern</param>
 /// <returns>the new pattern</returns>
 public Pattern ThenMaybeRepeatLazy(IMatchable pattern)
 {
     return(Then(MaybeRepeatLazy(pattern)));
 }
Example #6
0
 internal WrapPattern(IMatchable tomatch)
 {
     this.tomatch = tomatch;
 }
Example #7
0
 public void Setup(int id)
 {
     match2CardData = new Match2CardDataProxy(id);
     //match2CardData = new Match2CardData(id);
 }
Example #8
0
 /// <summary>
 /// Create a pattern that matches strings from this pattern, followed by one or more occurrences of a given pattern.
 /// </summary>
 /// <param name="pattern">the given pattern</param>
 /// <returns>the new pattern</returns>
 public Pattern ThenRepeat(IMatchable pattern)
 {
     return(Then(Repeat(pattern)));
 }
Example #9
0
 public CTokenRepeat(IMatchable content, bool greedyMatch,
                     int repeatLowerBound = 0, MatchCompleteChecker matchCompleteChecker = null)
     : this(content, greedyMatch, repeatLowerBound, 0, matchCompleteChecker)
 {
     this.infiniteRepeat = true;
 }
Example #10
0
 public ConjunctionMatchable(IMatchable left, Conjunction conjunction, IMatchable right)
 {
     Left        = left;
     Conjunction = conjunction;
     Right       = right;
 }
Example #11
0
        private static bool Match(object originalValue, object copyValue)
        {
            // If a custom IMatchable description exists use it to determine if there is a match
            IMatchable originalMatch = originalValue as IMatchable;
            IMatchable copyMatch     = copyValue as IMatchable;

            if (originalMatch != null && copyMatch != null)
            {
                bool res = originalMatch.Matches(copyMatch);
                return(res);
            }

            // Strings are enumerable, so test them first, since string.Equals should be faster than
            // cycling through each character.
            string origString = originalValue as string;

            if (origString != null)
            {
                string mString = copyValue as string;
                if (mString == null)
                {
                    return(false);
                }

                return(origString.Equals(mString));
            }

            // If the object is an enumeration, test the members of the enumeration.
            // If any members fail the match test, then the whole collection fails the match.
            IEnumerable originalList = originalValue as IEnumerable;

            if (originalList != null)
            {
                IEnumerable copyList = copyValue as IEnumerable;
                if (copyList != null)
                {
                    IEnumerator e = copyList.GetEnumerator();
                    e.MoveNext();
                    foreach (object originalItem in originalList)
                    {
                        if (Match(originalItem, e.Current) == false)
                        {
                            return(false);
                        }

                        e.MoveNext();
                    }
                }

                return(true);
            }

            if (originalValue == null && copyValue == null)
            {
                return(true);
            }

            // If the objects are not collections and are not IMatchable, the only remaining thing we can
            // realistically test is simple equality.
            // Don't use == here!  It will always be false for boxed value types.
            return(originalValue != null && originalValue.Equals(copyValue));
        }
Example #12
0
    public int DeleteMatched()
    {
        int count = 0;

        List <Character[, ]> allDirectionsForMatching = new List <Character[, ]>()
        {
            HorizontalLines(),
            VerticalLines(),
            UpDiagonalLines(),
            DownDiagonalLines()
        };

        List <IMatchable> lineMatched = new List <IMatchable>();

        foreach (var item in allDirectionsForMatching)
        {
            for (int n = 0; n < item.GetLength(0); n++)
            {
                lineMatched.Clear();

                for (int i = 0; i < item.GetLength(1); i++)
                {
                    IMatchable matchable = item[n, i];
                    if (lineMatched.Count < minMatchesCount)
                    {
                        if (matchable == null)
                        {
                            lineMatched.Clear();
                            continue;
                        }

                        if (lineMatched.Count == 0 || IsMatched(lineMatched[0], matchable) == false)
                        {
                            lineMatched.Clear();
                        }

                        lineMatched.Add(matchable);
                    }
                    else
                    {
                        if (item == null || IsMatched(lineMatched[0], matchable) == false)
                        {
                            break;
                        }

                        lineMatched.Add(matchable);
                    }
                }

                if (lineMatched.Count >= minMatchesCount)
                {
                    foreach (var matchable in lineMatched)
                    {
                        var destroyed = matchable as Character;

                        if (destroyed != null)
                        {
                            characterProvider.Destroy(destroyed);
                        }
                    }

                    count += lineMatched.Count;
                }
            }
        }

        return(count);
    }
Example #13
0
 static object[] Make(string section, string regex, IMatchable matchable, bool reversed = false) =>
Example #14
0
 /// <summary>
 /// Create a pattern that lazily matches zero or more occurrences of a given pattern.
 /// </summary>
 /// <param name="pattern">given pattern</param>
 /// <returns>the new pattern</returns>
 public static Pattern MaybeRepeatLazy(IMatchable pattern)
 {
     return(new RepeatingPattern(pattern, false, true));
 }
Example #15
0
        /// <summary>
        /// This gives sub-classes the chance to directly override, control or otherwise tamper
        /// with the matching process.  This is also where normal matching is performed,
        /// so to replace it, simply don't call the base.OnMatch method.  To tweak the results,
        /// the base method should be performed first, and the results can then be modified.
        /// </summary>
        /// <param name="other"></param>
        /// <param name="mismatchedProperties"></param>
        /// <returns></returns>
        protected virtual bool OnMatch(IMatchable other, List <string> mismatchedProperties)
        {
            Type original = GetType();
            Type copy     = other.GetType();

            // Public Properties ------------------------------------------------------
            PropertyInfo[] originalProperties = original.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            PropertyInfo[] copyProperties     = copy.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo originalProperty in originalProperties)
            {
                if (copyProperties.Contains(originalProperty.Name) == false)
                {
                    mismatchedProperties.Add(originalProperty.Name);
                    continue;
                }
                PropertyInfo copyProperty = copyProperties.GetFirst(originalProperty.Name);
                if (copyProperty == null)
                {
                    // The name of the property was not found on the other object
                    mismatchedProperties.Add(originalProperty.Name);
                    continue;
                }

                object originalValue = originalProperty.GetValue(this, null);
                object copyValue     = copyProperty.GetValue(other, null);
                if (Match(originalValue, copyValue) == false)
                {
                    mismatchedProperties.Add(originalProperty.Name);
                }
            }

            // Public Fields ---------------------------------------------------------
            FieldInfo[] originalFields = original.GetFields(BindingFlags.Public | BindingFlags.Instance);
            FieldInfo[] copyFields     = copy.GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (FieldInfo originalField in originalFields)
            {
                if (copyFields.Contains(originalField.Name) == false)
                {
                    mismatchedProperties.Add(originalField.Name);
                    continue;
                }

                FieldInfo copyField = copyFields.GetFirst(originalField.Name);
                if (copyField == null)
                {
                    mismatchedProperties.Add(originalField.Name);
                    continue;
                }

                object originalValue = originalField.GetValue(this);
                object copyValue     = copyField.GetValue(other);
                if (Match(originalValue, copyValue) == false)
                {
                    mismatchedProperties.Add(originalField.Name);
                }
            }
            if (mismatchedProperties.Count > 0)
            {
                return(false);
            }
            return(true);
        }
Example #16
0
 /// <summary>
 /// Create a pattern that matches strings from this pattern, followed by strings from the given pattern.
 /// </summary>
 /// <param name="tocat">pattern to append to this one</param>
 /// <returns>the new pattern</returns>
 public virtual Pattern Then(IMatchable tocat)
 {
     return(new CatPattern(this, tocat));
 }
Example #17
0
 /// <summary>
 /// Compares the properties of this object with the specified IMatchable other.
 /// This does not test every property of other, but does test every property
 /// of this item.  As long as the other item has corresponding properties
 /// for every property on this item, the items are said to match.
 /// The IMatchable interface allows custom definitions of matching.
 /// For collections to match, all of their sub-members must match.
 /// </summary>
 /// <param name="other"></param>
 /// <param name="mismatchedProperties"></param>
 /// <returns></returns>
 public bool Matches(IMatchable other, out List <string> mismatchedProperties)
 {
     mismatchedProperties = new List <string>();
     return(OnMatch(other, mismatchedProperties));
 }
Example #18
0
 /// <summary>
 /// Create a pattern that matches strings from this pattern, maybe followed by a match of the given pattern.
 /// </summary>
 /// <param name="pattern">the given pattern</param>
 /// <returns>the new pattern</returns>
 public Pattern ThenMaybe(IMatchable pattern)
 {
     return(Then(Maybe(pattern)));
 }
Example #19
0
 /// <summary>
 /// This tests the public properties from the two objects.  If any properties implement
 /// the IMatchable interface, and do not match, this returns false.  If any public
 /// properties are value types, and they are not equal, then this returns false.
 /// </summary>
 /// <param name="self">This matchable item </param>
 /// <param name="other">The other item to compare to this item</param>
 /// <returns>Boolean, true if there is a match</returns>
 public static bool Matches(this IMatchable self, IMatchable other)
 {
     List<string> ignoreMe;
     return self.Matches(other, out ignoreMe);
 }
Example #20
0
 internal CatPattern(IMatchable first, IMatchable then)
 {
     this.first   = first;
     this.then    = then;
     MatchesEmpty = first.MatchesEmpty && then.MatchesEmpty;
 }
Example #21
0
 public MatchResult(Matchable <T> match, IMatchable original, IMetricGenerator metricGenerator)
 {
     Match  = match;
     Metric = metricGenerator.GenerateMetric(match, original);
 }
Example #22
0
 public override Pattern Then(IMatchable tocat)
 {
     return(Match(tocat));
 }
Example #23
0
 /// <summary>
 /// Create a pattern that matches one or more occurrences of a given pattern.
 /// </summary>
 /// <param name="pattern">given pattern</param>
 /// <returns>the new pattern</returns>
 public static Pattern Repeat(IMatchable pattern)
 {
     return(new RepeatingPattern(pattern, true));
 }
Example #24
0
        /// <summary>
        /// Tests this object against the comparison object.  If any of the 
        /// value type members are different, or if any of the properties
        /// are IMatchable and do not match, then this returns false.
        /// </summary>
        /// <param name="other">The other IMatcheable object of the same type</param>
        /// <param name="mismatchedProperties">The list of property names that do not match</param>
        /// <returns>Boolean, true if the properties are comparably equal.</returns>
        public bool Matches(IMatchable other, out List<string> mismatchedProperties)
        {
            var matches = true;

            mismatchedProperties = new List<string>();
            var otherBruTileLayer = other as BruTileLayer;
            if (otherBruTileLayer == null)
            {
                AddAllProperties(mismatchedProperties);
                return false;
            }

            if (!ReferenceEquals(TileSource, otherBruTileLayer.TileSource))
            {
                mismatchedProperties.Add("TileSource");
                matches = false;
            }

            if (!ReferenceEquals(TileCache, otherBruTileLayer.TileCache))
            {
                mismatchedProperties.Add("TileCache");
                matches = false;
            }

            if (ShowErrorInTile != otherBruTileLayer.ShowErrorInTile)
            {
                mismatchedProperties.Add("ShowErrorInTile");
                matches = false;
            }

            return matches;
        }
Example #25
0
 /// <summary>
 /// Create a pattern that matches a given pattern or the empty string.
 /// </summary>
 /// <param name="pat">given pattern</param>
 /// <returns>the new pattern</returns>
 public static Pattern Maybe(IMatchable pat)
 {
     return(new OptionalPattern(pat));
 }
Example #26
0
 /// <summary>
 /// Compares the properties of this object with the specified IMatchable other.
 /// This does not test every property of other, but does test every property
 /// of this item.  As long as the other item has corresponding properties
 /// for every property on this item, the items are said to match.
 /// The IMatchable interface allows custom definitions of matching.
 /// For collections to match, all of their sub-members must match.
 /// </summary>
 /// <param name="other"></param>
 /// <param name="mismatchedProperties"></param>
 /// <returns></returns>
 public bool Matches(IMatchable other, out List<string> mismatchedProperties)
 {
     mismatchedProperties = new List<string>();
     return OnMatch(other, mismatchedProperties);
 }
Example #27
0
        /// <summary>
        /// This tests the public properties from the two objects. If any properties implement
        /// the IMatchable interface, and do not match, this returns false. If any public
        /// properties are value types, and they are not equal, then this returns false.
        /// </summary>
        /// <param name="self">This matchable item </param>
        /// <param name="other">The other item to compare to this item</param>
        /// <returns>Boolean, true if there is a match</returns>
        public static bool Matches(this IMatchable self, IMatchable other)
        {
            List <string> ignoreMe;

            return(self.Matches(other, out ignoreMe));
        }