Exemple #1
0
        /// <summary>
        /// Fills a Stack with the contents of a particular collection.  The items are
        /// pushed onto the stack in the same order they are read by the enumerator.
        /// </summary>
        public PooledStack(IEnumerable <T> enumerable, ClearMode clearMode, ArrayPool <T> customPool)
        {
            _pool        = customPool ?? ArrayPool <T> .Shared;
            _clearOnFree = ShouldClear(clearMode);

            switch (enumerable)
            {
            case null:
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.enumerable);
                break;

            case ICollection <T> collection:
                if (collection.Count == 0)
                {
                    _array = Array.Empty <T>();
                }
                else
                {
                    _array = _pool.Rent(collection.Count);
                    collection.CopyTo(_array, 0);
                    _size = collection.Count;
                }
                break;

            default:
                using (var list = new PooledList <T>(enumerable))
                {
                    _array = _pool.Rent(list.Count);
                    list.Span.CopyTo(_array);
                    _size = list.Count;
                }
                break;
            }
        }
Exemple #2
0
 /// <summary>
 /// Fills a Stack with the contents of a particular collection.  The items are
 /// pushed onto the stack in the same order they are read by the enumerator.
 /// </summary>
 public PooledStack(ReadOnlySpan <T> span, ClearMode clearMode, ArrayPool <T> customPool)
 {
     _pool        = customPool ?? ArrayPool <T> .Shared;
     _clearOnFree = ShouldClear(clearMode);
     _array       = _pool.Rent(span.Length);
     span.CopyTo(_array);
     _size = span.Length;
 }
Exemple #3
0
        public void ClearLine(ClearMode clearMode)
        {
            int clearCode = 48 + (int)clearMode;

            byte[] buffer = new byte[4] {
                27, 91, (byte)clearCode, 75
            };
            stream.Write(buffer, 0, buffer.Length);
        }
Exemple #4
0
        private static bool ShouldClear(ClearMode mode)
        {
#if NETCOREAPP2_1
            return(mode == ClearMode.Always ||
                   (mode == ClearMode.Auto && RuntimeHelpers.IsReferenceOrContainsReferences <T>()));
#else
            return(mode != ClearMode.Never);
#endif
        }
Exemple #5
0
 /// <summary>
 /// Creates a Command which clears the given Graph or Graphs depending on the Clear Mode specified
 /// </summary>
 /// <param name="graphUri">Graph URI</param>
 /// <param name="mode">Clear Mode</param>
 /// <param name="silent">Whether errors should be suppressed</param>
 public ClearCommand(Uri graphUri, ClearMode mode, bool silent)
     : base(SparqlUpdateCommandType.Clear)
 {
     this._graphUri = graphUri;
     this._mode = mode;
     if (this._graphUri == null && this._mode == ClearMode.Graph) this._mode = ClearMode.Default;
     if (this._mode == ClearMode.Default) this._graphUri = null;
     this._silent = silent;
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that is empty and has the specified initial capacity.
 /// </summary>
 public PooledQueue(int capacity, ClearMode clearMode, ArrayPool <T> customPool)
 {
     if (capacity < 0)
     {
         ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity,
                                                      ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
     }
     _pool        = customPool ?? ArrayPool <T> .Shared;
     _array       = _pool.Rent(capacity);
     _clearOnFree = ShouldClear(clearMode);
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that contains elements copied from the specified
 /// span and has sufficient capacity to accommodate the number of elements copied.
 /// </summary>
 public PooledQueue(ReadOnlySpan <T> span, ClearMode clearMode, ArrayPool <T> customPool)
 {
     _pool        = customPool ?? ArrayPool <T> .Shared;
     _clearOnFree = ShouldClear(clearMode);
     _array       = _pool.Rent(span.Length);
     span.CopyTo(_array);
     _size = span.Length;
     if (_size != _array.Length)
     {
         _tail = _size;
     }
 }
Exemple #8
0
        /// <summary>
        /// Determines if the given value represents a valid state of this property.
        /// </summary>
        /// <param name="value">The state that should be used.</param>
        /// <returns>True if the state is valid, otherwise false.</returns>
        protected override Boolean IsValid(CSSValue value)
        {
            ClearMode mode;

            if (modes.TryGetValue(value, out mode))
            {
                _mode = mode;
                return(true);
            }

            return(false);
        }
Exemple #9
0
    public void Clear(ClearMode clearMode)
    {
        if (this._itemSlotViews == null)
        {
            return;
        }

        for (int i = 0; i < this._itemSlotViews.Count; i++)
        {
            this._itemSlotViews[i].Clear(clearMode);
        }
    }
Exemple #10
0
        public override void Run(bool forced, ClearMode mode)
        {
            byte frcd = (forced) ? frcd = 0x03 : frcd = 0x01;

            byte[] sendbuffer = { NetNo,      PcNo, destinationCpu, 0x03, 0x00, 0x0A, 0x00, 0x10, 0x00,
                                  0x01,       0x10,
                                  0x00,       0x00,
                                  frcd,       0x00,
                                  (byte)mode, 0x00 };
            sendbuffer = Concat(PacketHead, sendbuffer);
            SendBuffer(sendbuffer);
        }
Exemple #11
0
 /// <summary>
 /// Creates a new DROP command
 /// </summary>
 /// <param name="graphUri">URI ofthe Graph to DROP</param>
 /// <param name="mode">DROP Mode to use</param>
 /// <param name="silent">Whether the DROP should be done silently</param>
 public DropCommand(Uri graphUri, ClearMode mode, bool silent)
     : base(SparqlUpdateCommandType.Drop)
 {
     this._graphUri = graphUri;
     this._mode     = mode;
     if (this._graphUri == null && this._mode == ClearMode.Graph)
     {
         this._mode = ClearMode.Default;
     }
     if (this._mode == ClearMode.Default)
     {
         this._graphUri = null;
     }
     this._silent = silent;
 }
Exemple #12
0
        protected override Boolean IsValid(CSSValue value)
        {
            ClearMode mode;

            if (value is CSSIdentifierValue && modes.TryGetValue(((CSSIdentifierValue)value).Value, out mode))
            {
                _mode = mode;
            }
            else if (value != CSSValue.Inherit)
            {
                return(false);
            }

            return(true);
        }
 /// <summary>
 /// Creates a Command which clears the given Graph or Graphs depending on the Clear Mode specified.
 /// </summary>
 /// <param name="graphUri">Graph URI.</param>
 /// <param name="mode">Clear Mode.</param>
 /// <param name="silent">Whether errors should be suppressed.</param>
 public ClearCommand(Uri graphUri, ClearMode mode, bool silent)
     : base(SparqlUpdateCommandType.Clear)
 {
     _graphUri = graphUri;
     _mode     = mode;
     if (_graphUri == null && _mode == ClearMode.Graph)
     {
         _mode = ClearMode.Default;
     }
     if (_mode == ClearMode.Default)
     {
         _graphUri = null;
     }
     _silent = silent;
 }
Exemple #14
0
 /// <summary>
 /// Creates a Command which performs the specified type of clear
 /// </summary>
 /// <param name="mode">Clear Mode</param>
 public ClearCommand(ClearMode mode)
     : this(mode, false) { }
Exemple #15
0
 public void SetState(ClearMode mode)
 {
     _mode = mode;
 }
Exemple #16
0
 /// <summary>
 /// Creates a Command which performs the specified type of clear
 /// </summary>
 /// <param name="mode">Clear Mode</param>
 /// <param name="silent">Whether errors should be suppressed</param>
 public ClearCommand(ClearMode mode, bool silent)
     : this(null, mode, silent) { }
Exemple #17
0
 /// <summary>
 /// Create a stack with the default initial capacity.
 /// </summary>
 public PooledStack(ClearMode clearMode) : this(clearMode, ArrayPool <T> .Shared)
 {
 }
Exemple #18
0
 internal override void Reset()
 {
     _mode = ClearMode.None;
 }
Exemple #19
0
 public static MCACommand Clear(ClearMode mode)
 {
     return new MCACommand(CommandName.CMD_CLEAR, (byte)mode);
 }
 /// <summary>
 /// Creates a Command which performs the specified type of clear.
 /// </summary>
 /// <param name="mode">Clear Mode.</param>
 public ClearCommand(ClearMode mode)
     : this(mode, false)
 {
 }
Exemple #21
0
 /// <summary>
 /// Creates a new DROP command
 /// </summary>
 /// <param name="graphUri">URI of the Graph to DROP</param>
 /// <param name="mode">DROP Mode to use</param>
 public DropCommand(Uri graphUri, ClearMode mode)
     : this(graphUri, mode, false) { }
Exemple #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that is empty and has the default initial capacity.
 /// </summary>
 public PooledQueue(ClearMode clearMode) : this(clearMode, ArrayPool <T> .Shared)
 {
 }
Exemple #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that contains elements copied from the specified
 /// array and has sufficient capacity to accommodate the number of elements copied.
 /// </summary>
 public PooledQueue(T[] array, ClearMode clearMode, ArrayPool <T> customPool) : this(array.AsSpan(), clearMode, customPool)
 {
 }
Exemple #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that contains elements copied from the specified
 /// span and has sufficient capacity to accommodate the number of elements copied.
 /// </summary>
 public PooledQueue(ReadOnlySpan <T> span, ClearMode clearMode) : this(span, clearMode, ArrayPool <T> .Shared)
 {
 }
Exemple #25
0
 public abstract void Run(bool forced, ClearMode mode);
Exemple #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that contains elements copied from the specified
 /// collection and has sufficient capacity to accommodate the number of elements copied.
 /// </summary>
 public PooledQueue(IEnumerable <T> enumerable, ClearMode clearMode) : this(enumerable, clearMode, ArrayPool <T> .Shared)
 {
 }
Exemple #27
0
 private static void TestImport([JetBrains.Annotations.NotNull] string path, bool clearDstFolder, ClearMode cleartablemode,
                                bool verifyRowCount = false)
 {
     TestImport(path, out _, out _, cleartablemode, verifyRowCount, out _, clearDstFolder);
 }
Exemple #28
0
 internal CSSClearProperty()
     : base(PropertyNames.Clear)
 {
     _mode      = modes["none"];
     _inherited = false;
 }
Exemple #29
0
 internal override void Reset()
 {
     _mode = Default;
 }
Exemple #30
0
 /// <summary>
 /// Creates a new DROP command
 /// </summary>
 /// <param name="graphUri">URI of the Graph to DROP</param>
 /// <param name="mode">DROP Mode to use</param>
 public DropCommand(Uri graphUri, ClearMode mode)
     : this(graphUri, mode, false)
 {
 }
Exemple #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that is empty and has the default initial capacity.
 /// </summary>
 public PooledQueue(ClearMode clearMode, ArrayPool <T> customPool)
 {
     _pool        = customPool ?? ArrayPool <T> .Shared;
     _array       = Array.Empty <T>();
     _clearOnFree = ShouldClear(clearMode);
 }
 /// <summary>
 /// Creates a Command which performs the specified type of clear.
 /// </summary>
 /// <param name="mode">Clear Mode.</param>
 /// <param name="silent">Whether errors should be suppressed.</param>
 public ClearCommand(ClearMode mode, bool silent)
     : this(null, mode, silent)
 {
 }
Exemple #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that is empty and has the specified initial capacity.
 /// </summary>
 public PooledQueue(int capacity, ClearMode clearMode) : this(capacity, clearMode, ArrayPool <T> .Shared)
 {
 }
Exemple #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PooledQueue{T}"/> class that contains elements copied from the specified
 /// array and has sufficient capacity to accommodate the number of elements copied.
 /// </summary>
 public PooledQueue(T[] array, ClearMode clearMode) : this(array.AsSpan(), clearMode, ArrayPool <T> .Shared)
 {
 }
Exemple #35
0
        private static void TestImport([JetBrains.Annotations.NotNull] string srcfilename, [JetBrains.Annotations.NotNull] out Simulator mainsim,
                                       [JetBrains.Annotations.NotNull] out DatabaseMerger dbm, ClearMode clearTablesMode,
                                       bool checkrowcounts, [JetBrains.Annotations.NotNull] out DatabaseSetup db, bool clearDstFolder)
        {
            var acceptedUneven = new List <string>
            {
                "tblSettings",
                "tblOptions",
                "tblHHTTraits",           // this is messed up since it would need a sorting of the householdtraits by subtraits
                "tblLPGVersion",          // settings are not imported
                "tblHouseholdPlanEntries" //nobody cares about the household plans anymore
            };

            if (clearDstFolder)
            {
                CleanTestBase.RunAutomatically(false);
            }
            DirectoryInfo di = new DirectoryInfo(".");

            Logger.Info("Current directory:" + di.FullName);
            var fis = di.GetFiles();

            Logger.Info("Files in this directory:");
            foreach (var fileInfo in fis)
            {
                Logger.Info(fileInfo.Name);
            }

            var fi = FindImportFile(srcfilename);

            db = new DatabaseSetup(Utili.GetCurrentMethodAndClass());

            var oldSim = new Simulator(db.ConnectionString);
            Dictionary <string, int> srctablerowcounts = null;

            switch (clearTablesMode)
            {
            case ClearMode.ClearTable: {
                var connectionstrOld = "Data Source=" + fi.FullName;
                srctablerowcounts = GetTableRowCounts(connectionstrOld);
                ClearAllTables(db);
            }
            break;

            case ClearMode.DeleteOnlyOneRow: {
                var connectionstrOld = "Data Source=" + fi.FullName;
                srctablerowcounts = GetTableRowCounts(connectionstrOld);
                DeleteOneElementFromAllTables(db);
            }
            break;

            case ClearMode.NoClearing:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(clearTablesMode), clearTablesMode, null);
            }
            var mainSim = new Simulator(db.ConnectionString);

            dbm = new DatabaseMerger(mainSim);

            dbm.RunFindItems(fi.FullName, null);
            dbm.RunImport(null);
            foreach (var oldAff in oldSim.Affordances.MyItems)
            {
                foreach (var newAff in mainSim.Affordances.MyItems)
                {
                    if (newAff.Name == oldAff.Name)
                    {
                        foreach (var oldDes in oldAff.AffordanceDesires)
                        {
                            var foundDesire = false;
                            foreach (var newDes in newAff.AffordanceDesires)
                            {
                                if (oldDes.Desire.Name == newDes.Desire.Name)
                                {
                                    foundDesire = true;
                                }
                            }
                            if (!foundDesire)
                            {
                                Logger.Info("Missing affordance Desire in " + oldAff.Name + " " + oldDes.Desire.Name);
                            }
                        }
                    }
                }
            }
            foreach (var hhg in oldSim.HouseholdTemplates.It)
            {
                Logger.Info("HHG 1:" + hhg.Name + " " + hhg.Entries.Count);
            }
            foreach (var hhg in mainSim.HouseholdTemplates.It)
            {
                Logger.Info("HHG 2:" + hhg.Name + " " + hhg.Entries.Count);
            }
            if (checkrowcounts && srctablerowcounts != null)
            {
                var dsttablerowcounts = GetTableRowCounts(db.ConnectionString);
                var errors            = new List <string>();

                foreach (var srctablerowcount in srctablerowcounts)
                {
                    if (!acceptedUneven.Contains(srctablerowcount.Key))
                    {
                        if (!dsttablerowcounts.ContainsKey(srctablerowcount.Key))
                        {
                            errors.Add(srctablerowcount.Key + " is missing in the dst");
                        }
                        if (dsttablerowcounts[srctablerowcount.Key] != srctablerowcount.Value)
                        {
                            errors.Add(srctablerowcount.Key + " is missing rows: dst = " +
                                       dsttablerowcounts[srctablerowcount.Key] + " src = " + srctablerowcount.Value);
                        }
                    }
                }
                var s = string.Empty;

                foreach (var error in errors)
                {
                    Logger.Error(error);
                    s += error + Environment.NewLine;
                }
                if (s.Length > 0)
                {
                    throw new LPGException("Errors happened in " + s);
                }
            }

            mainsim = mainSim;
            // load again to see if anything gets deleted on loading
            Logger.Threshold = Severity.Debug;
            var oldSim2 = new Simulator(db.ConnectionString);

            foreach (var hhg in oldSim2.HouseholdTemplates.It)
            {
                Logger.Info("HHG 3:" + hhg.Name + " " + hhg.Entries.Count);
            }
            foreach (var hhg in mainSim.HouseholdTemplates.It)
            {
                Logger.Info("HHG 4:" + hhg.Name + " " + hhg.Entries.Count);
            }
            if (checkrowcounts)
            {
                var dsttablerowcounts = GetTableRowCounts(db.ConnectionString);
                var errors            = new List <string>();

                if (srctablerowcounts == null)
                {
                    throw new LPGException("srctablerowcounts was null");
                }
                foreach (var srctablerowcount in srctablerowcounts)
                {
                    if (!acceptedUneven.Contains(srctablerowcount.Key))
                    {
                        if (!dsttablerowcounts.ContainsKey(srctablerowcount.Key))
                        {
                            errors.Add(srctablerowcount.Key + " is missing in the dst");
                        }
                        if (dsttablerowcounts[srctablerowcount.Key] != srctablerowcount.Value)
                        {
                            errors.Add(srctablerowcount.Key + " is missing rows: dst = " +
                                       dsttablerowcounts[srctablerowcount.Key] + " src = " + srctablerowcount.Value);
                        }
                    }
                }
                var s = string.Empty;

                foreach (var error in errors)
                {
                    Logger.Error(error);
#pragma warning disable CC0039 // Don't concatenate strings in loops
                    s += error + Environment.NewLine;
#pragma warning restore CC0039 // Don't concatenate strings in loops
                }
                if (s.Length > 0)
                {
                    throw new LPGException("Errors happened in " + s);
                }
            }
            db.Cleanup();
            if (clearDstFolder)
            {
                CleanTestBase.RunAutomatically(true);
            }
        }