Exemple #1
0
 public bool TryGetValue(TKey key, out TValue value)
 {
     if (!IsKeyFiltered(key))
     {
         value = default;
         return(false);
     }
     return(OriginalValues.TryGetValue(key, out value));
 }
 // Resets the ObjectChangeTracker to the Unchanged state and
 // clears the original values as well as the record of changes
 // to collection properties
 public void AcceptChanges()
 {
     ModifiedProperties.Clear();
     OriginalValues.Clear();
     ObjectsAddedToCollectionProperties.Clear();
     ObjectsRemovedFromCollectionProperties.Clear();
     IsChangeTrackingEnabled = true;
     State = ObjectState.Unchanged;
 }
Exemple #3
0
 // 将 ObjectChangeTracker 重置为 Unchanged 状态,并
 // 清除原始值和
 // 集合属性的更改记录
 public void AcceptChanges()
 {
     OnObjectStateChanging(ObjectState.Unchanged);
     OriginalValues.Clear();
     ObjectsAddedToCollectionProperties.Clear();
     ObjectsRemovedFromCollectionProperties.Clear();
     ChangeTrackingEnabled = true;
     _objectState          = ObjectState.Unchanged;
 }
Exemple #4
0
        public static void Render(FMAT material)
        {
            if (CustomCategory.Count == 0)
            {
                Init();
            }


            ShaderInfo shaderInfo = null;

            if (material.MaterialAsset is BfshaRenderer)
            {
                shaderInfo = ((BfshaRenderer)material.MaterialAsset).GLShaderInfo;
            }

            if (shaderInfo != null)
            {
                ImGui.Checkbox("Display Only Used Uniforms From Shader", ref limitUniformsUsedByShaderCode);
            }

            if (OriginalValues.Count == 0)
            {
                foreach (var param in material.ShaderParams)
                {
                    OriginalValues.Add(param.Key, param.Value.DataValue);
                }
            }


            LoadHeaders();
            if (ImGui.BeginChild("PARAM_LIST"))
            {
                int index = 0;
                foreach (var param in material.ShaderParams.Values)
                {
                    if (limitUniformsUsedByShaderCode && shaderInfo != null &&
                        !shaderInfo.UsedVertexStageUniforms.Contains(param.Name) &&
                        !shaderInfo.UsedPixelStageUniforms.Contains(param.Name))
                    {
                        continue;
                    }

                    if (material.AnimatedParams.ContainsKey(param.Name))
                    {
                        ImGui.PushStyleColor(ImGuiCol.FrameBg, new Vector4(0, 0.5f, 0, 1));
                        LoadParamColumns(material.AnimatedParams[param.Name], index++, true);
                        ImGui.PopStyleColor();
                    }
                    else
                    {
                        LoadParamColumns(param, index++);
                    }
                }
            }
            ImGui.EndChild();
        }
        public void Filter(string query)
        {
            var count = Items.Count;
            var items = !string.IsNullOrWhiteSpace(query) ? OriginalValues.Where(i => i.Name.Contains(query)).ToList() : OriginalValues;

            Items = items;
            EmptyText.Visibility = Items.Count > 0 ? ViewStates.Gone : ViewStates.Visible;
            NotifyItemRangeRemoved(0, count);
            NotifyItemRangeInserted(0, Items.Count);
        }
 // Captures the original value for a property that is changing.
 //moved internal to public scope
 public void RecordOriginalValue(string propertyName, object value)
 {
     if (_changeTrackingEnabled && _objectState != ObjectState.Added)
     {
         if (!OriginalValues.ContainsKey(propertyName))
         {
             OriginalValues[propertyName] = value;
         }
     }
 }
 public void SetOriginalValue(string propertyName, object value)
 {
     if (OriginalValues.ContainsKey(propertyName))
     {
         OriginalValues[propertyName] = value;
     }
     else
     {
         OriginalValues.Add(propertyName, value);
     }
 }
        /// <summary>
        /// Initialize change tracker
        /// </summary>
        /// <param name="entity">Entity to track</param>
        public void Initialize(object entity)
        {
            var infos = entity.GetType().GetRuntimeProperties();

            foreach (var info in infos)
            {
                if (info.Name != "Id" && info.Name != "InternalId")
                {
                    OriginalValues.Add(info.Name, info.GetValue(entity));
                }
            }
        }
Exemple #9
0
        // Resets the ObjectChangeTracker to the Unchanged state and
        // sets the actual values to be the original values as well as the record of changes
        // to collection properties
        public void CancelChanges(IObjectWithChangeTracker entity)
        {
            if (this.State == ObjectState.Added)
            {
                return;
            }

            OnObjectStateChanging(ObjectState.Unchanged);
            ChangeTrackingEnabled = false;

            ModifiedValues.Clear();

            var originalValues = OriginalValues.ToArray();

            foreach (var kvp in originalValues)
            {
                string propertyName  = kvp.Key;
                object propertyValue = kvp.Value;

                entity.SetPropertyValue(propertyName, propertyValue);
            }

            var objectsAddedToCollectionProperties = ObjectsAddedToCollectionProperties.ToArray();

            foreach (var kvp in objectsAddedToCollectionProperties)
            {
                var propertyName = kvp.Key;
                var items        = kvp.Value;

                foreach (var item in items.ToArray())
                {
                    entity.RemoveItemFromCollection(propertyName, item);
                }
            }
            ObjectsAddedToCollectionProperties.Clear();

            var objectsRemovedFromCollectionProperties = ObjectsRemovedFromCollectionProperties.ToArray();

            foreach (var kvp in objectsRemovedFromCollectionProperties)
            {
                var propertyName = kvp.Key;
                var items        = kvp.Value;

                foreach (var item in items.ToArray())
                {
                    entity.AddItemToCollection(propertyName, item);
                }
            }
            ObjectsRemovedFromCollectionProperties.Clear();

            ChangeTrackingEnabled = true;
            _objectState          = ObjectState.Unchanged;
        }
Exemple #10
0
 protected override void EffectOnEnter(GameObject obj, out object savedData)
 {
     if(obj.rigidbody != null)
     {
         savedData = new OriginalValues { Scale = obj.transform.localScale };
         obj.transform.localScale *= ScaleMultiplier;
     }
     else
     {
         savedData = null;
     }
 }
Exemple #11
0
        // Resets the ObjectChangeTracker to the Unchanged state and
        // rollback the original values as well as the record of changes
        // to collection properties
        public void CancelChanges()
        {
            OnObjectStateChanging(ObjectState.Unchanged);
            // rollback original values
            Type type = _parentObject.GetType();

            foreach (var originalValue in OriginalValues.ToList())
            {
                type.GetProperty(originalValue.Key).SetValue(
                    _parentObject, originalValue.Value, null);
            }
            // create copy of ObjectsAddedToCollectionProperties
            // and ObjectsRemovedFromCollectionProperties
            Dictionary <string, ObjectList> removeCollection =
                ObjectsAddedToCollectionProperties.ToDictionary(n => n.Key, n => n.Value);
            Dictionary <string, ObjectList> addCollection =
                ObjectsRemovedFromCollectionProperties.ToDictionary(n => n.Key, n => n.Value);

            // rollback ObjectsAddedToCollectionProperties
            if (removeCollection.Count > 0)
            {
                foreach (KeyValuePair <string, ObjectList> entry in removeCollection)
                {
                    PropertyInfo collectionProperty = type.GetProperty(entry.Key);
                    IList        collectionObject   = (IList)collectionProperty.GetValue(_parentObject, null);
                    foreach (object obj in entry.Value.ToList())
                    {
                        collectionObject.Remove(obj);
                    }
                }
            }
            // rollback ObjectsRemovedFromCollectionProperties
            if (addCollection.Count > 0)
            {
                foreach (KeyValuePair <string, ObjectList> entry in addCollection)
                {
                    PropertyInfo collectionProperty = type.GetProperty(entry.Key);
                    IList        collectionObject   = (IList)collectionProperty.GetValue(_parentObject, null);
                    foreach (object obj in entry.Value.ToList())
                    {
                        collectionObject.Add(obj);
                    }
                }
            }
            OriginalValues.Clear();
            ObjectsAddedToCollectionProperties.Clear();
            ObjectsRemovedFromCollectionProperties.Clear();
            _objectState = ObjectState.Unchanged;
            OnObjectStateChanged(ObjectState.Unchanged);
        }
Exemple #12
0
        /// <summary>
        /// Take the (first) four hexadecimal characters from the
        /// buffer and convert them to an unsigned short
        /// </summary>
        private static void ParseData(char[] buf)
        {
            string hex   = new string(buf, 0, 4);
            ushort value = ushort.Parse(hex, NumberStyles.HexNumber);

            if (value <= 1023)
            {
                OriginalValues.Add(value);
            }
            else
            {
                OriginalValues.Add(1023);
            }
        }
Exemple #13
0
            public void SetNewValue(string propertyName, object value)
            {
                if (OriginalValues.ContainsKey(propertyName) && OriginalValues[propertyName] == value)
                {
                    return;
                }

                if (NewValues.ContainsKey(propertyName))
                {
                    NewValues[propertyName] = value;
                }
                else
                {
                    NewValues.Add(propertyName, value);
                }
            }
        public Statistics(IEnumerable <double> values)
        {
            OriginalValues = values.Where(d => !double.IsNaN(d)).ToArray();
            SortedValues   = OriginalValues.OrderBy(value => value).ToArray();
            N = SortedValues.Count;
            if (N == 0)
            {
                throw new InvalidOperationException("Sequence of values contains no elements, Statistics can't be calculated");
            }

            if (N == 1)
            {
                Q1 = Median = Q3 = SortedValues[0];
            }
            else
            {
                double GetMedian(IReadOnlyList <double> x) => x.Count % 2 == 0
                    ? (x[x.Count / 2 - 1] + x[x.Count / 2]) / 2
                    : x[x.Count / 2];

                Median = GetMedian(SortedValues);
                Q1     = GetMedian(SortedValues.Take(N / 2).ToList());
                Q3     = GetMedian(SortedValues.Skip((N + 1) / 2).ToList());
            }

            Min  = SortedValues.First();
            Mean = SortedValues.Average();
            Max  = SortedValues.Last();

            InterquartileRange = Q3 - Q1;
            LowerFence         = Q1 - 1.5 * InterquartileRange;
            UpperFence         = Q3 + 1.5 * InterquartileRange;

            AllOutliers   = SortedValues.Where(IsOutlier).ToArray();
            LowerOutliers = SortedValues.Where(IsLowerOutlier).ToArray();
            UpperOutliers = SortedValues.Where(IsUpperOutlier).ToArray();

            Variance           = N == 1 ? 0 : SortedValues.Sum(d => Math.Pow(d - Mean, 2)) / (N - 1);
            StandardDeviation  = Math.Sqrt(Variance);
            StandardError      = StandardDeviation / Math.Sqrt(N);
            Skewness           = CalcCentralMoment(3) / StandardDeviation.Pow(3);
            Kurtosis           = CalcCentralMoment(4) / StandardDeviation.Pow(4);
            ConfidenceInterval = new ConfidenceInterval(Mean, StandardError, N);
            Percentiles        = new PercentileValues(SortedValues);
        }
Exemple #15
0
        public void queryKey()
        {
            if (!hKeyQueried)
            {
                IntPtr subKeyNamesUnmanaged;
                int    cSubKeys;
                IntPtr regValuesUnmanaged;
                int    cValues;
                regQuery(hKey, out subKeyNamesUnmanaged, out cSubKeys, out regValuesUnmanaged, out cValues);

                var subKeyNames   = new KeyName[cSubKeys];
                var keyNameStride = Marshal.SizeOf(typeof(KeyName));
                for (int i = 0; i < cSubKeys; i++)
                {
                    var p = new IntPtr(subKeyNamesUnmanaged.ToInt64() + i * keyNameStride);
                    subKeyNames[i] = (KeyName)Marshal.PtrToStructure(p, typeof(KeyName));
                }

                Items.Clear();
                for (int i = 0; i < cSubKeys; i++)
                {
                    Items.Add(new RegTreeViewItem(RegTreeViewItemType.FOLDER)
                    {
                        Title = subKeyNames[i].Name, Parent = this
                    });
                }

                OriginalValues.Clear();
                Values.Clear();
                var regValueStride = Marshal.SizeOf(typeof(RegValue));
                for (int i = 0; i < cValues; i++)
                {
                    var p        = new IntPtr(regValuesUnmanaged.ToInt64() + i * regValueStride);
                    var regValue = (RegValue)Marshal.PtrToStructure(p, typeof(RegValue));
                    OriginalValues.Add(regValue);
                    Values.Add(new RegValueItem(regValue));
                }

                hKeyQueried = true;
            }
        }
        public List <ReturnValue> GetPermutationList(List <string> originalArray)
        {
            foreach (var element in originalArray)
            {
                // if already processed (duplicated elements)
                if (_generated.Any(p => p.ValueString.Contains(element)))
                {
                    continue;
                }
                // check if already exist
                if (_existing.Any(p => p.ValueString.Contains(element)))
                {
                    _generated.Add(_existing.FirstOrDefault(p => p.ValueString == element));
                    continue;
                }
                // generate permutations
                var generationResult = Generate(element);
                // save to result
                _generated.Add(generationResult);
            }

            //save new Values to DB
            _generated.Except(_existing).ToList().ForEach(p =>
            {
                var or = new OriginalValues
                {
                    Value          = p.ValueString,
                    ElapsedSeconds = p.Seconds
                };
                or.Id = _database.SaveOriginalValues(or);
                p.PermutationList.ForEach(per =>
                {
                    _database.SavePermutations(new Combinations
                    {
                        Value           = per,
                        OriginalValueId = or.Id
                    });
                });
            });
            return(_generated);
        }
Exemple #17
0
 // Captures the original value for a property that is changing.
 internal void RecordValue(string propertyName, object oldValue, object newValue)
 {
     if (_changeTrackingEnabled && _objectState != ObjectState.Added)
     {
         if (OriginalValues.ContainsKey(propertyName) &&
             OriginalValues[propertyName] == newValue)
         {
             // On repasse à l'état initial
             OriginalValues.Remove(propertyName);
             ModifiedValues.Remove(propertyName);
         }
         else
         {
             if (!OriginalValues.ContainsKey(propertyName))
             {
                 OriginalValues[propertyName] = oldValue;
             }
             ModifiedValues[propertyName] = newValue;
         }
     }
 }
        public Statistics(IEnumerable <double> values)
        {
            OriginalValues = values.Where(d => !double.IsNaN(d)).ToArray();
            SortedValues   = OriginalValues.OrderBy(value => value).ToArray();
            N = SortedValues.Count;
            if (N == 0)
            {
                throw new InvalidOperationException("Sequence of values contains no elements, Statistics can't be calculated");
            }

            var quartiles = Quartiles.FromSorted(SortedValues);

            Min                = quartiles.Min;
            Q1                 = quartiles.Q1;
            Median             = quartiles.Median;
            Q3                 = quartiles.Q3;
            Max                = quartiles.Max;
            InterquartileRange = quartiles.InterquartileRange;

            var moments = Moments.Create(SortedValues);

            Mean = moments.Mean;
            StandardDeviation = moments.StandardDeviation;
            Variance          = moments.Variance;
            Skewness          = moments.Skewness;
            Kurtosis          = moments.Kurtosis;

            var tukey = TukeyOutlierDetector.FromQuartiles(quartiles);

            LowerFence      = tukey.LowerFence;
            UpperFence      = tukey.UpperFence;
            AllOutliers     = SortedValues.Where(tukey.IsOutlier).ToArray();
            LowerOutliers   = SortedValues.Where(tukey.IsLowerOutlier).ToArray();
            UpperOutliers   = SortedValues.Where(tukey.IsUpperOutlier).ToArray();
            outlierDetector = tukey;

            StandardError      = StandardDeviation / Math.Sqrt(N);
            ConfidenceInterval = new ConfidenceInterval(Mean, StandardError, N);
            Percentiles        = new PercentileValues(SortedValues);
        }
Exemple #19
0
        /// <summary>
        /// Validate the e-tag via applies the current DataModificationItem's OriginalValues to the
        /// specified query and returns result.
        /// </summary>
        /// <param name="query">The IQueryable to apply the property values to.</param>
        /// <returns>
        /// The object is e-tag checked passed.
        /// </returns>
        public object ValidateEtag(IQueryable query)
        {
            Ensure.NotNull(query, nameof(query));
            var type  = query.ElementType;
            var param = Expression.Parameter(type);

            Expression where = null;

            if (OriginalValues != null)
            {
                foreach (var item in OriginalValues)
                {
                    if (!item.Key.StartsWith("@", StringComparison.Ordinal))
                    {
                        where = ApplyPredicate(param, where, item);
                    }
                }

                if (OriginalValues.ContainsKey(IfNoneMatchKey))
                {
                    where = Expression.Not(where);
                }
            }

            var whereLambda = Expression.Lambda(where, param);
            var queryable   = ExpressionHelpers.Where(query, whereLambda, type);

            var matchedResource = queryable.SingleOrDefault();

            if (matchedResource == null)
            {
                // If ETAG does not match, should return 412 Precondition Failed
                var message = string.Format(CultureInfo.InvariantCulture, Resources.PreconditionCheckFailed, new object[] { EntitySetOperation, query.SingleOrDefault() });
                throw new PreconditionFailedException(message);
            }

            return(matchedResource);
        }
Exemple #20
0
        /// <summary>
        /// Read the data file, skipping over data we're not interested in
        /// but parsing and storing the contents of the first data channel
        /// </summary>
        public static void Read()
        {
            OriginalValues.Clear();

            using (StreamReader r = new StreamReader("ECGSAMPLE.txt"))
            {
                int    bytesRead = 0;
                char[] buffer    = new char[24];

                while (!r.EndOfStream)
                {
                    bytesRead = r.ReadBlock(buffer, 0, 8);
                    if (bytesRead != 8)
                    {
                        break;
                    }

                    bytesRead = r.ReadBlock(buffer, 0, 24);
                    if (bytesRead != 24)
                    {
                        break;
                    }
                    else
                    {
                        ParseData(buffer);
                    }

                    bytesRead = r.ReadBlock(buffer, 0, 2);
                    if (bytesRead != 2)
                    {
                        break;
                    }
                }
            }

            return;
        }
        /// <summary>
        /// Before page is imported
        /// </summary>
        public void DataImporter_ContentImporting(DataImporter dataImporting, ContentImportingEventArgs e)
        {
            _originalValues = null;
            if (e.TransferContentData is TransferPageData)
            {
                MigrationHook.Invoke(new BeforePageImportEvent(e), Log);

                var externalUrl =
                    e.TransferContentData.RawContentData.Property.FirstOrDefault(x => x.Name == "PageExternalURL");
                if (externalUrl != null && !string.IsNullOrEmpty(externalUrl.Value))
                {
                    externalUrl.Value = null;
                }
                // Todo: Do we need this? Should be handled by property mappings
                RemoveDC(e, "MainBody");
                _originalValues = new OriginalValues {
                    PageSaved     = DateTime.Parse(GetValue(e, "PageSaved")),
                    PageChanged   = DateTime.Parse(GetValue(e, "PageChanged")),
                    PageChangedBy = GetValue(e, "PageChangedBy"),
                    PageCreatedBy = GetValue(e, "PageCreatedBy"),
                    PageGuid      = Guid.Parse(GetValue(e, "PageGUID"))
                };
            }
        }
Exemple #22
0
        public Statistics(IEnumerable <double> values)
        {
            OriginalValues = values.Where(d => !double.IsNaN(d)).ToArray();
            SortedValues   = OriginalValues.OrderBy(value => value).ToArray();
            N = SortedValues.Count;
            if (N == 0)
            {
                throw new InvalidOperationException("Sequence of values contains no elements, Statistics can't be calculated");
            }

            if (N == 1)
            {
                Q1 = Median = Q3 = SortedValues[0];
            }
            else
            {
                double GetMedian(IReadOnlyList <double> x) => x.Count % 2 == 0
                    ? (x[x.Count / 2 - 1] + x[x.Count / 2]) / 2
                    : x[x.Count / 2];

                Median = GetMedian(SortedValues);
                Q1     = GetMedian(SortedValues.Take(N / 2).ToList());
                Q3     = GetMedian(SortedValues.Skip((N + 1) / 2).ToList());
            }

            Min = SortedValues.First();
            Max = SortedValues.Last();

            InterquartileRange = Q3 - Q1;
            LowerFence         = Q1 - 1.5 * InterquartileRange;
            UpperFence         = Q3 + 1.5 * InterquartileRange;

            AllOutliers   = SortedValues.Where(IsOutlier).ToArray();
            LowerOutliers = SortedValues.Where(IsLowerOutlier).ToArray();
            UpperOutliers = SortedValues.Where(IsUpperOutlier).ToArray();
        }
Exemple #23
0
 public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator()
 => OriginalValues.Where(item => IsKeyFiltered(item.Key)).GetEnumerator();
Exemple #24
0
 public static void Reset()
 {
     OriginalValues.Clear();
 }
 public object GetOriginalValue(string propertyName)
 {
     return(OriginalValues.ContainsKey(propertyName) ? OriginalValues[propertyName] : null);
 }
Exemple #26
0
 public bool ContainsKey(TKey key)
 => IsKeyFiltered(key) && OriginalValues.ContainsKey(key);