Example #1
0
 /// <summary>
 /// Access a contained field by name. Forwards to the field accessor.
 /// </summary>
 /// <param name="fieldName">The field to access</param>
 /// <returns>Field value</returns>
 public object this[string fieldName]
 {
     get
     {
         object res = null;
         if (CachedValues.TryGetValue(fieldName, out res))
         {
             return(res);
         }
         res = Accessor.GetValue(InnerItem, fieldName);
         CachedValues[fieldName] = res;
         return(res);
     }
     set
     {
         if (Accessor.GetValue(InnerItem, fieldName) != value)
         {
             CachedValues[fieldName] = value;
             Accessor.SetValue(InnerItem, fieldName, value);
             if (PropertyChanged != null)
             {
                 PropertyChanged(this, new PropertyChangedEventArgs(fieldName));
             }
         }
     }
 }
        public ModelPropertyEntry(ModelProperty property, ModelPropertyValue parentValue)
            : base(parentValue) 
        {

            _valueCache = new CachedValues(this);
            SetUnderlyingModelPropertyHelper(property, false);
        }
Example #3
0
        internal bool Get(GameObject from, GameObject target, float range)
        {
            if (IsDisposing)
            {
                return(false);
            }

            Tuple <float, bool> output;

            if (CachedValues.TryGetValue(new Tuple <int, int, float>(from.NetworkId, target.NetworkId, range), out output))
            {
                if (Game.Time * 1000 - output.Item1 < RefreshRate)
                {
                    return(output.Item2);
                }

                CachedValues[new Tuple <int, int, float>(from.NetworkId, target.NetworkId, range)] = new Tuple <float, bool>(
                    Game.Time * 1000, from.IsInRange(target, range));
            }
            else
            {
                CachedValues[new Tuple <int, int, float>(from.NetworkId, target.NetworkId, range)] = new Tuple <float, bool>(
                    Game.Time * 1000, from.IsInRange(target, range));
            }
            return(CachedValues[new Tuple <int, int, float>(from.NetworkId, target.NetworkId, range)].Item2);
        }
Example #4
0
        internal float Get(GameObject from, GameObject target)
        {
            if (IsDisposing)
            {
                return(0);
            }

            Tuple <float, float> output;

            if (CachedValues.TryGetValue(new KeyValuePair <int, int>(from.NetworkId, target.NetworkId), out output))
            {
                if (Game.Time * 1000 - output.Item1 < RefreshRate)
                {
                    return(output.Item2);
                }

                CachedValues[new KeyValuePair <int, int>(from.NetworkId, target.NetworkId)] = new Tuple <float, float>(
                    Game.Time * 1000, from.Distance(target));
            }
            else
            {
                CachedValues[new KeyValuePair <int, int>(from.NetworkId, target.NetworkId)] = new Tuple <float, float>(
                    Game.Time * 1000, from.Distance(target));
            }
            return(CachedValues[new KeyValuePair <int, int>(from.NetworkId, target.NetworkId)].Item2);
        }
Example #5
0
 /// <summary>
 /// Resets any values that were cached after reading from <see cref="Sop.DataSource"/>.
 /// </summary>
 /// <remarks>
 /// Many of the property values are cached for performance reasons, as they generally never change,
 /// and parsing values from the image header can be expensive, especially when done repeatedly.
 /// </remarks>
 public override void ResetCache()
 {
     base.ResetCache();
     _cache = new CachedValues();
     foreach (var frame in Frames)
     {
         frame.ResetCache();
     }
 }
Example #6
0
        /// <summary>
        /// Correspones To: S[i]
        /// </summary>
        /// <param name="index"></param>
        /// <returns><see cref="QsSequenceElement"/></returns>
        public new QsSequenceElement this[int index]
        {
            get
            {
                QsSequenceElement el;
                if (!this.TryGetValue(index, out el))
                {
                    //failed to get the value
                    // here the magic begins

                    if (index > 0)
                    {
                        int IX = index;
                        while (!this.ContainsKey(IX))
                        {
                            IX--;  //decrease the index.
                        }
                        //Bingo we found it
                        this.TryGetValue(IX, out el);
                    }
                    else if (index < 0)
                    {
                        int IX = index;
                        while (!this.ContainsKey(IX))
                        {
                            IX++;  //decrease the index.
                        }
                        //Bingo we found it
                        this.TryGetValue(IX, out el);
                    }
                    else
                    {
                        //zero and not found the in logical error or some one altered the zero element.
                        throw new QsException("Damn it. Where is the zero element");
                    }
                }
                return(el);
            }
            set
            {
                if (index < MinimumIndex)
                {
                    MinimumIndex = index;
                }
                if (index > MaximumIndex)
                {
                    MaximumIndex = index;
                }

                value.ParentSequence        = this;
                value.IndexInParentSequence = index;
                base[index] = value;

                //clear the cache
                CachedValues.Clear();
            }
        }
Example #7
0
        public void ApplyFilter()
        {
            for (var i = 0; i < InputPixels.Count; i++)
            {
                //Get X/Y coordinate of pixel
                var x = i % ImageWidth;
                var y = i / ImageWidth;

                //If grid fits on image
                if (x + Filter.Width > ImageWidth ||
                    y + Filter.Height > ImageHeight)
                {
                    continue;
                }

                //For the entire filter, cache weight and color of pixel as int
                for (var j = 0; j < Filter.Weights[0].Length; j += Filter.Width)
                {
                    for (var k = 0; k < Filter.Width; k++)
                    {
                        CachedValues.Add(new int[]
                        {
                            Filter.Weights[0][j + k],
                            Filter.Weights[1][j + k],
                            Filter.Weights[2][j + k],
                            InputPixels[i + k + ((j / Filter.Width) * ImageWidth)].Color.R,
                            InputPixels[i + k + ((j / Filter.Width) * ImageWidth)].Color.G,
                            InputPixels[i + k + ((j / Filter.Width) * ImageWidth)].Color.B
                        });
                    }
                }

                //ReLU
                var output = new List <double>();
                foreach (var cachedValue in CachedValues)
                {
                    output.Add(Activation.ReLU(cachedValue[0] * cachedValue[1]));
                }

                //Pooling
                for (var j = 0; j < Filter.Weights.Length; j += Filter.Width)
                {
                    for (var k = 0; k < Filter.Width; k++)
                    {
                        Console.WriteLine();
                    }
                }
            }
        }
Example #8
0
 private void ReadJsonAndSaveToCache(ref Utf8JsonReader reader, string culture)
 {
     reader.Read();
     while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
     {
         if (reader.TokenType != JsonTokenType.PropertyName)
         {
             throw new JsonException("Expected PropertyName");
         }
         string key   = reader.GetString() ?? throw new JsonException("PropertyName cannot be null");
         string?value = ParseValue(ref reader);
         if (!CachedValues.TryAdd(new LocalizationCacheKey(key, culture), value))
         {
             throw new InvalidOperationException();
         }
     }
 }
Example #9
0
        private void Initialize()
        {
            Surface   surface = this.EnvironmentParameters.SourceSurface;
            Rectangle bounds  = this.EnvironmentParameters.GetSelection(surface.Bounds).GetBoundsInt();

            if (this._cachedCharacteristics == null)
            {
                this._cachedCharacteristics = new CachedValues <TensorCharacteristics>(bounds.Height, this.GetCharacteristics);
            }

            lock (this)
            {
                if (this._taskSTField == null)
                {
                    this._cancelToken = new EdgeDetectionEffect();
                    this._taskSTField = StructurTensorField.FromSurfaceAsync(surface, bounds, this._diffX.GetNormalized(), null, this._cancelToken);
                    this._cachedCharacteristics.Invalidate();
                }
            }
        }
Example #10
0
        // <summary>
        // Basic ctor.  Note, however, that this class should only be created by ModelPropertyValueCollection
        // as that class ensures that the new instance is correctly added and removed from the
        // ModelItemMap.
        // </summary>
        // <param name="modelItem">ModelItem to wrap around</param>
        // <param name="index">Index of the ModelItem in the collection</param>
        // <param name="parentCollection">Parent collection</param>
        public ModelPropertyIndexer(
            ModelItem modelItem,
            int index,
            ModelPropertyValueCollection parentCollection)
            : base(parentCollection.ParentValue)
        {
            if (modelItem == null)
            {
                throw FxTrace.Exception.ArgumentNull("modelItem");
            }
            if (parentCollection == null)
            {
                throw FxTrace.Exception.ArgumentNull("parentCollection");
            }

            _modelItem        = modelItem;
            _index            = index;
            _parentCollection = parentCollection;
            _valueCache       = new CachedValues(this);
        }
Example #11
0
        public static void SetUpTimer(bool retry)
        {
            if (!_alreadyStarted || retry)
            {
                // Load values FROM THE LATEST PREVIOUS VERSION inside the current settings.
                // Upgrading after saving will STILL get the PREVIOUS VERSION's settings
                // TODO: Detect if version changed before calling upgrade.

                var settingsIpv6 = Properties.Settings.Default.LastIPv6;
                Log.WriteLine("IPv6 from settings:" + settingsIpv6);
                var settingsIpv4 = Properties.Settings.Default.LastIPv4;
                Log.WriteLine("IPv4 from settings:" + settingsIpv4);
                if (!_alreadyStarted && string.IsNullOrEmpty(settingsIpv4) && string.IsNullOrEmpty(settingsIpv6))
                {
                    // No settings, try to upgrade.
                    Properties.Settings.Default.Upgrade();

                    // Try again
                    _alreadyStarted = true;
                    SetUpTimer(true);
                }
                else
                {
                    if (settingsIpv6 != null && System.Net.IPAddress.TryParse(settingsIpv6, out System.Net.IPAddress v6))
                    {
                        CachedValues.SetCachedExternalIpAddressv6(v6);
                        CachedValues.SetPreviousExternalIpAddressv6(v6);
                    }
                    if (settingsIpv4 != null && System.Net.IPAddress.TryParse(settingsIpv4, out System.Net.IPAddress v4))
                    {
                        CachedValues.SetCachedExternalIpAddressv4(v4);
                        CachedValues.SetPreviousExternalIpAddressv4(v4);
                    }

                    CheckAndSendEmail();
                    System.Timers.Timer aTimer = new System.Timers.Timer(60 * 60 * 1000); //one hour in milliseconds
                    aTimer.Elapsed += OnTimedIpUpdaterEvent;
                    _alreadyStarted = true;
                }
            }
        }
        // <summary>
        // Basic ctor.  Note, however, that this class should only be created by ModelPropertyValueCollection
        // as that class ensures that the new instance is correctly added and removed from the
        // ModelItemMap.
        // </summary>
        // <param name="modelItem">ModelItem to wrap around</param>
        // <param name="index">Index of the ModelItem in the collection</param>
        // <param name="parentCollection">Parent collection</param>
        public ModelPropertyIndexer(
            ModelItem modelItem,
            int index,
            ModelPropertyValueCollection parentCollection)
            : base(parentCollection.ParentValue) 
        {

            if (modelItem == null)
            {
                throw FxTrace.Exception.ArgumentNull("modelItem");
            }
            if (parentCollection == null)
            {
                throw FxTrace.Exception.ArgumentNull("parentCollection");
            }

            _modelItem = modelItem;
            _index = index;
            _parentCollection = parentCollection;
            _valueCache = new CachedValues(this);
        }
        public ModelPropertyEntry(IEnumerable<ModelProperty> propertySet, ModelPropertyValue parentValue)
            : base(parentValue) 
        {

            _valueCache = new CachedValues(this);
            SetUnderlyingModelPropertyHelper(propertySet, false);
        }
Example #14
0
 /// <summary>
 /// Resets any values that were cached after reading from the parent <see cref="Sop"/>'s <see cref="Sop.DataSource"/>.
 /// </summary>
 /// <remarks>
 /// Many of the property values are cached for performance reasons, as they generally never change, 
 /// and parsing values from the image header can be expensive, especially when done repeatedly.
 /// </remarks>
 public void ResetCache()
 {
     _cache = new CachedValues();
     InvalidateImagePlaneHelper();
 }
Example #15
0
 /// <summary>
 /// Resets any values that were cached after reading from <see cref="Sop.DataSource"/>.
 /// </summary>
 /// <remarks>
 /// Many of the property values are cached for performance reasons, as they generally never change, 
 /// and parsing values from the image header can be expensive, especially when done repeatedly.
 /// </remarks>
 public override void ResetCache()
 {
     base.ResetCache();
     _cache = new CachedValues();
     foreach (var frame in Frames)
         frame.ResetCache();
 }
Example #16
0
 /// <summary>
 /// Resets any values that were cached after reading from <see cref="DataSource"/>.
 /// </summary>
 /// <remarks>
 /// Many of the property values are cached for performance reasons, as they generally never change,
 /// and parsing values from the image header can be expensive, especially when done repeatedly.
 /// </remarks>
 public virtual void ResetCache()
 {
     _cache = new CachedValues();
 }
Example #17
0
        private static bool CheckIpChange(/*bool forced = false*/)
        {
            Debug.WriteLine("Called CheckIPChange()");
            IEnumerable <IPAddress> cachedIps = CachedValues.GetCachedIPs();

            System.Collections.Generic.HashSet <System.Net.IPAddress> newIps = GetNewPublicIPs();
            if (newIps == null)
            {
                Log.WriteLine("IP Fetcher returned null! Woah! We don't have offline mode right now so something is very wrong!");
                return(false);
            }
            var changed = !newIps.SetEquals(cachedIps);

            // Clear out cached IPs, otherwise we would return invalid IPs if we lose either (stack disabled, etc)
            if (changed)
            {
                changed = false;
                if (CachedValues.GetPreviousExternalIpAddressv6() != null)
                {
                    Log.WriteLine("Previous IPv6: " + CachedValues.GetPreviousExternalIpAddressv6());
                }

                if (CachedValues.GetPreviousExternalIpAddressv4() != null)
                {
                    Log.WriteLine("Previous IPv4: " + CachedValues.GetPreviousExternalIpAddressv4());
                }

                CachedValues.SetPreviousExternalIpAddressv6(CachedValues.GetCachedExternalIpAddressv6());
                CachedValues.SetPreviousExternalIpAddressv4(CachedValues.GetCachedExternalIpAddressv4());
                CachedValues.SetCachedExternalIpAddressv6(null);
                CachedValues.SetCachedExternalIpAddressv4(null);
                Log.WriteLine("Fetched IPs:" + string.Join(",", newIps));
                foreach (System.Net.IPAddress address in newIps)
                {
                    switch (address.AddressFamily)
                    {
                    case System.Net.Sockets.AddressFamily.InterNetworkV6:
                        // we have IPv6
                        if (CachedValues.GetPreviousExternalIpAddressv6() != null)
                        {
                            if (!address.Equals(CachedValues.GetPreviousExternalIpAddressv6()))
                            {
                                changed = true;
                                Log.WriteLine("IPv6 Changed (" + CachedValues.GetPreviousExternalIpAddressv6() + " => " + address + ")");
                            }
                        }
                        else
                        {
                            changed = true;
                        }

                        CachedValues.SetCachedExternalIpAddressv6(address);
                        break;

                    case System.Net.Sockets.AddressFamily.InterNetwork:
                        // we have IPv4
                        if (CachedValues.GetPreviousExternalIpAddressv4() != null)
                        {
                            if (!address.Equals(CachedValues.GetPreviousExternalIpAddressv4()))
                            {
                                changed = true;
                                Log.WriteLine("IPv4 Changed (" + CachedValues.GetPreviousExternalIpAddressv4() + " => " + address + ")");
                            }
                        }
                        else
                        {
                            changed = true;
                        }

                        CachedValues.SetCachedExternalIpAddressv4(address);
                        break;

                    default:
                        // Do nothing. Security wants this.
                        throw new NotSupportedException();
                    }
                }
            }
            if (changed)
            {
                Properties.Settings.Default.LastIPv4 = CachedValues.GetCachedExternalIpAddressv4()?.ToString();
                Properties.Settings.Default.LastIPv6 = CachedValues.GetCachedExternalIpAddressv6()?.ToString();
                Properties.Settings.Default.Save();
            }
            return(changed);
        }
Example #18
0
		/// <summary>
        /// Resets any values that were cached after reading from <see cref="DataSource"/>.
        /// </summary>
        /// <remarks>
        /// Many of the property values are cached for performance reasons, as they generally never change, 
        /// and parsing values from the image header can be expensive, especially when done repeatedly.
        /// </remarks>
        public virtual void ResetCache()
        {
            _cache = new CachedValues();
        }
Example #19
0
 internal bool Exist(GameObject from, GameObject target, float range)
 {
     return(!IsDisposing && CachedValues.ContainsKey(new Tuple <int, int, float>(@from.NetworkId, target.NetworkId, range)));
 }
Example #20
0
 private void Finallize()
 {
     CachedValues?.Clear();
     CachedValues2?.Clear();
 }
Example #21
0
 internal bool Exist(GameObject from, GameObject target)
 {
     return(!IsDisposing && CachedValues.ContainsKey(new KeyValuePair <int, int>(@from.NetworkId, target.NetworkId)));
 }
Example #22
0
 public void DeleteUnnecessaryData()
 {
     CachedValues?.Clear();
     CachedValues2?.Clear();
 }