コード例 #1
0
        /// <summary>
        /// Gets old values from given index, skip saving paths and things we cannot write
        /// </summary>
        /// <param name="index">The Index</param>
        /// <returns>The argument getIndexProperties</returns>
        IndexAttributes GetIndexAttributes(Index index)
        {
            IndexAttributes indexAttributes = new IndexAttributes();

            indexAttributes.BlockSignSize          = index.BlockSignSize;
            indexAttributes.FrozenTimePeriodInSecs = index.FrozenTimePeriodInSecs;
            indexAttributes.MaxConcurrentOptimizes = index.MaxConcurrentOptimizes;
            indexAttributes.MaxDataSize            = index.MaxDataSize;
            indexAttributes.MaxHotBuckets          = index.MaxHotBuckets;
            indexAttributes.MaxHotIdleSecs         = index.MaxHotIdleSecs;
            indexAttributes.MaxHotSpanSecs         = index.MaxHotSpanSecs;
            indexAttributes.MaxMemMB                 = index.MaxMemMB;
            indexAttributes.MaxMetaEntries           = index.MaxMetaEntries;
            indexAttributes.MaxTotalDataSizeMB       = index.MaxTotalDataSizeMB;
            indexAttributes.MaxWarmDBCount           = index.MaxWarmDBCount;
            indexAttributes.MinRawFileSyncSecs       = index.MinRawFileSyncSecs;
            indexAttributes.PartialServiceMetaPeriod = index.PartialServiceMetaPeriod;
            indexAttributes.QuarantineFutureSecs     = index.QuarantineFutureSecs;
            indexAttributes.QuarantinePastSecs       = index.QuarantinePastSecs;
            indexAttributes.RawChunkSizeBytes        = index.RawChunkSizeBytes;
            indexAttributes.RotatePeriodInSecs       = index.RotatePeriodInSecs;
            indexAttributes.ServiceMetaPeriod        = index.ServiceMetaPeriod;
            indexAttributes.SyncMeta                 = index.SyncMeta;
            indexAttributes.ThrottleCheckPeriod      = index.ThrottleCheckPeriod;

            return(indexAttributes);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="declaringType">The <see cref="TypeInfo"/> that declares this instance.</param>
 /// <param name="indexAttributes"><see cref="IndexAttributes"/> attributes for this instance.</param>
 public IndexInfo(TypeInfo declaringType, IndexAttributes indexAttributes)
     : this()
 {
     this.declaringType = declaringType;
     attributes         = indexAttributes;
     reflectedType      = declaringType;
     declaringIndex     = this;
 }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="reflectedType">Reflected type.</param>
        /// <param name="ancestorIndex">The ancestors index.</param>
        /// <param name="indexAttributes"><see cref="IndexAttributes"/> attributes for this instance.</param>
        public IndexInfo(TypeInfo reflectedType, IndexAttributes indexAttributes, IndexInfo ancestorIndex)
            : this()
        {
            declaringType      = ancestorIndex.DeclaringType;
            this.reflectedType = reflectedType;
            attributes         = indexAttributes;

            fillFactor       = ancestorIndex.FillFactor;
            filterExpression = ancestorIndex.FilterExpression;
            declaringIndex   = ancestorIndex.DeclaringIndex;
            shortName        = ancestorIndex.ShortName;
        }
コード例 #4
0
        public IndexInfo FindFirst(IndexAttributes indexAttributes)
        {
            var result = Find(indexAttributes);

            if (result.Count != 0)
            {
                var enumerator = result.GetEnumerator();
                enumerator.MoveNext();
                return(enumerator.Current);
            }
            return(null);
        }
コード例 #5
0
        public async Task Transmitter2()
        {
            string indexName = "main";

            using (var service = await SdkHelper.CreateService())
            {
                Index index = await service.Indexes.GetAsync(indexName);

                long currentEventCount = index.TotalEventCount;
                Assert.NotNull(index);

                Transmitter     transmitter     = service.Transmitter;
                IndexAttributes indexAttributes = GetIndexAttributes(index);
                Assert.NotNull(indexAttributes);

                // Submit event to default index using variable arguments

                await transmitter.SendAsync(
                    MockContext.GetOrElse(string.Format("{0}, DefaultIndexArgs string event Hello World 1", DateTime.Now)),
                    indexName);

                await transmitter.SendAsync(
                    MockContext.GetOrElse(string.Format("{0}, DefaultIndexArgs string event Hello World 2", DateTime.Now)),
                    indexName);

                await index.PollForUpdatedEventCount(currentEventCount + 2);

                currentEventCount += 2;

                using (MemoryStream stream = new MemoryStream())
                {
                    using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8, 4096, leaveOpen: true))
                    {
                        writer.WriteLine(
                            MockContext.GetOrElse(string.Format("{0}, DefaultIndexArgs stream events 1", DateTime.Now)));
                        writer.WriteLine(
                            MockContext.GetOrElse(string.Format("{0}, DefaultIndexArgs stream events 2", DateTime.Now)));
                    }

                    stream.Seek(0, SeekOrigin.Begin);
                    await transmitter.SendAsync(stream, indexName);
                }

                await index.PollForUpdatedEventCount(currentEventCount + 2);

                currentEventCount += 2;
            }
        }
コード例 #6
0
        public async Task DefaultIndexArgs()
        {
            string         indexName = "main";
            DateTimeOffset offset    = new DateTimeOffset(DateTime.Now);
            string         now       = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss") +
                                       string.Format("{0}{1} ", offset.Offset.Hours.ToString("D2"),
                                                     offset.Offset.Minutes.ToString("D2"));

            Service service = this.Connect();
            //Receiver receiver = service.GetReceiver();
            Receiver receiver = new Receiver();
            Index    index    = await service.GetIndexAsync(indexName);

            //index.Enable();
            Assert.False(index.Disabled);

            IndexAttributes indexAttributes = GetIndexAttributes(index);
            ReceiverArgs    receiverArgs    = new ReceiverArgs()
            {
                Index = index.Name,
            };
            // submit event to default index using variable arguments
            //receiver.Log(indexAttributes, "Hello World. \u0150");
            //receiver.Log(indexAttributes, "Goodbye World. \u0150");
            await receiver.SendAsync("Hello World", receiverArgs);

            await receiver.SendAsync("Hello World 2", receiverArgs);

            // stream event to default index with variable arguments
            //Stream streamArgs = receiver.Attach(indexAttributes);
            //streamArgs.Write(Encoding.UTF8.GetBytes(" Hello World again. \u0150\r\n"));
            //streamArgs.Write(Encoding.UTF8.GetBytes(" Goodbye World again.\u0150\r\n"));
            //streamArgs.Close();

            UnicodeEncoding uniEncoding = new UnicodeEncoding();

            byte[]       inputString = uniEncoding.GetBytes("stream hello world ");
            MemoryStream stream      = new MemoryStream();

            stream.Write(inputString, 0, inputString.Length);
            await receiver.SendAsync(stream, receiverArgs);

            stream.Close();
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="reflectedType">Reflected type.</param>
        /// <param name="indexAttributes">The index attributes.</param>
        /// <param name="baseIndex">Base index.</param>
        /// <param name="baseIndexes">The base indexes.</param>
        public IndexInfo(TypeInfo reflectedType, IndexAttributes indexAttributes, IndexInfo baseIndex, params IndexInfo[] baseIndexes)
            : this()
        {
            declaringType      = baseIndex.DeclaringType;
            this.reflectedType = reflectedType;
            attributes         = indexAttributes;

            fillFactor       = baseIndex.FillFactor;
            filterExpression = baseIndex.FilterExpression;
            declaringIndex   = baseIndex.DeclaringIndex;
            shortName        = baseIndex.ShortName;

            UnderlyingIndexes.Add(baseIndex);

            foreach (IndexInfo info in baseIndexes)
            {
                UnderlyingIndexes.Add(info);
            }
        }
コード例 #8
0
        void CanConstruct()
        {
            var attributes = new IndexAttributes();

            Assert.Equal(
                "blockSignSize=null; " +
                "bucketRebuildMemoryHint=null; " +
                "coldToFrozenDir=null; " +
                "coldToFrozenScript=null; " +
                "compressRawdata=null; " +
                "enableOnlineBucketRepair=null; " +
                "frozenTimePeriodInSecs=null; " +
                "maxBloomBackfillBucketAge=null; " +
                "maxConcurrentOptimizes=null; " +
                "maxDataSize=null; " +
                "maxHotBuckets=null; " +
                "maxHotIdleSecs=null; " +
                "maxHotSpanSecs=null; " +
                "maxMemMB=null; " +
                "maxMetaEntries=null; " +
                "maxTimeUnreplicatedNoAcks=null; " +
                "maxTimeUnreplicatedWithAcks=null; " +
                "maxTotalDataSizeMB=null; " +
                "maxWarmDBCount=null; " +
                "minRawFileSyncSecs=null; " +
                "minStreamGroupQueueSize=null; " +
                "partialServiceMetaPeriod=null; " +
                "processTrackerServiceInterval=null; " +
                "quarantineFutureSecs=null; " +
                "quarantinePastSecs=null; " +
                "rawChunkSizeBytes=null; " +
                "repFactor=null; " +
                "rotatePeriodInSecs=null; " +
                "serviceMetaPeriod=null; " +
                "syncMeta=null; " +
                "throttleCheckPeriod=null; " +
                "tstatsHomePath=null; " +
                "warmToColdScript=null",
                attributes.ToString());

            Assert.Equal(0, ((IEnumerable <Argument>)attributes).Count());
        }
コード例 #9
0
        void CanConstruct()
        {
            var attributes = new IndexAttributes();

            Assert.Equal(
                "blockSignSize=null; " +
                "bucketRebuildMemoryHint=null; " +
                "coldToFrozenDir=null; " +
                "coldToFrozenScript=null; " +
                "compressRawdata=null; " +
                "enableOnlineBucketRepair=null; " +
                "frozenTimePeriodInSecs=null; " +
                "maxBloomBackfillBucketAge=null; " +
                "maxConcurrentOptimizes=null; " +
                "maxDataSize=null; " +
                "maxHotBuckets=null; " +
                "maxHotIdleSecs=null; " +
                "maxHotSpanSecs=null; " +
                "maxMemMB=null; " +
                "maxMetaEntries=null; " +
                "maxTimeUnreplicatedNoAcks=null; " +
                "maxTimeUnreplicatedWithAcks=null; " +
                "maxTotalDataSizeMB=null; " +
                "maxWarmDBCount=null; " +
                "minRawFileSyncSecs=null; " +
                "minStreamGroupQueueSize=null; " +
                "partialServiceMetaPeriod=null; " +
                "processTrackerServiceInterval=null; " +
                "quarantineFutureSecs=null; " +
                "quarantinePastSecs=null; " +
                "rawChunkSizeBytes=null; " +
                "repFactor=null; " +
                "rotatePeriodInSecs=null; " +
                "serviceMetaPeriod=null; " +
                "syncMeta=null; " +
                "throttleCheckPeriod=null; " +
                "tstatsHomePath=null; " +
                "warmToColdScript=null",
                attributes.ToString());

            Assert.Equal(0, ((IEnumerable<Argument>)attributes).Count());
        }
コード例 #10
0
ファイル: Mesh.cs プロジェクト: X-Hax/SA3D
        public static Mesh Read(byte[] source, uint address, uint imageBase, ref IndexAttributes indexAttribs)
        {
            // getting the addresses and sizes
            uint parameters_addr  = source.ToUInt32(address) - imageBase;
            int  parameters_count = source.ToInt32(address + 4);

            uint primitives_addr = source.ToUInt32(address + 8) - imageBase;
            int  primitives_size = source.ToInt32(address + 12);

            // reading the parameters
            List <IParameter> parameters = new();

            for (int i = 0; i < parameters_count; i++)
            {
                parameters.Add(ParameterExtensions.Read(source, parameters_addr));
                parameters_addr += 8;
            }

            // getting the index attribute parameter
            var p = parameters.FirstOrDefault(x => x.Type == ParameterType.IndexAttributes);

            if (p != null)
            {
                indexAttribs = ((IndexAttributeParameter)p).IndexAttributes;
            }

            // reading the primitives
            List <Poly> primitives = new();
            uint        end_pos    = (uint)(primitives_addr + primitives_size);

            while (primitives_addr < end_pos)
            {
                // if the primitive isnt valid
                if (source[primitives_addr] == 0)
                {
                    break;
                }
                primitives.Add(Poly.Read(source, ref primitives_addr, indexAttribs));
            }

            return(new Mesh(parameters.ToArray(), primitives.ToArray()));
        }
コード例 #11
0
        /// <summary>
        /// Finds <see cref="IndexInfo"/> objects by the specified criteria and match type.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <param name="matchType">Type of the match.</param>
        /// <returns>A sequence of found objects.</returns>
        public ICollection <IndexInfo> Find(IndexAttributes criteria, MatchType matchType)
        {
            if (criteria == IndexAttributes.None)
            {
                return(ArrayUtils <IndexInfo> .EmptyArray);
            }

            switch (matchType)
            {
            case MatchType.Partial:
                return(this.Where(f => (f.Attributes & criteria) > 0).ToList());

            case MatchType.Full:
                return(this.Where(f => (f.Attributes & criteria) == criteria).ToList());

            case MatchType.None:
            default:
                return(this.Where(f => (f.Attributes & criteria) == 0).ToList());
            }
        }
コード例 #12
0
 /// <summary>
 /// Asynchronously updates an index.
 /// </summary>
 /// <param name="name">
 /// Name of the index to update.
 /// </param>
 /// <param name="attributes">
 /// Attributes to set on the index.
 /// </param>
 /// <remarks>
 /// This method uses the <a href="http://goo.gl/n3S22S">POST
 /// data/indexes/{name}</a> endpoint to update the <see cref=
 /// "Index"/> identified by <see cref="name"/> with a new set of <see 
 /// cref="attributes"/>.
 /// </remarks>
 public async Task UpdateIndexAsync(string name, IndexAttributes attributes)
 {
     var entity = new Index(this.Context, this.Namespace, name);
     await entity.UpdateAsync(attributes);
 }
コード例 #13
0
 /// <summary>
 /// Asynchronously creates a new index.
 /// </summary>
 /// <param name="name">
 /// Name of the index to create.
 /// </param>
 /// <param name="coldPath">
 /// Location for storing the cold databases for the index identified by
 /// <see cref="name"/>. A value of <c>null</c> or <c>""</c> specifies 
 /// that the cold databases should be stored at the default location.
 /// </param>
 /// <param name="homePath">
 /// Location for storing the hot and warm buckets for the index 
 /// identified by <see cref="name"/>. A value of <c>null</c> or <c>""
 /// </c> specifies that the hot and warm buckets should be stored at 
 /// the default location.
 /// </param>
 /// <param name="thawedPath">
 /// <summary>
 /// Specifies the absolute path for storing the resurrected databases 
 /// for the index identified by <see cref="name"/>. A value of <c>null
 /// </c> or <c>""</c> specifies that the resurrected databases should 
 /// be stored at the default location.
 /// </param>
 /// <param name="attributes">
 /// Attributes to set on the newly created index.
 /// </param>
 /// <returns>
 /// An object representing the newly created index.
 /// </returns>
 /// <remarks>
 /// This method uses the <a href="http://goo.gl/yDfQ4T">POST
 /// data/indexes</a> endpoint to create the <see cref="Index"/> object
 /// it returns.
 /// </remarks>
 public async Task<Index> CreateIndexAsync(string name, string coldPath = null, string homePath = null, 
     string thawedPath = null, IndexAttributes attributes = null)
 {
     var entity = new Index(this.Context, this.Namespace, name);
     await entity.CreateAsync(coldPath, homePath, thawedPath, attributes);
     return entity;
 }
コード例 #14
0
        public async Task CanCrudIndex()
        {
            var ns = new Namespace("nobody", "search");

            using (var service = await SdkHelper.CreateService(ns))
            {
                var indexName = MockContext.GetOrElse(string.Format("delete-me-{0}", Guid.NewGuid()));
                Index index;

                //// Create

                index = await service.Indexes.CreateAsync(indexName);
                Assert.Equal(true, index.EnableOnlineBucketRepair);

                //// Read

                index = await service.Indexes.GetAsync(indexName);

                //// Update

                Exception updateException = null;

                var attributes = new IndexAttributes()
                {
                    EnableOnlineBucketRepair = false
                };

                await index.UpdateAsync(attributes);
                Assert.Equal(attributes.EnableOnlineBucketRepair, index.EnableOnlineBucketRepair);
                Assert.False(index.Disabled);

                await index.DisableAsync();
                Assert.True(index.Disabled);

                await service.Server.RestartAsync(2 * 60 * 1000);
                await service.LogOnAsync();

                await index.EnableAsync();
                Assert.False(index.Disabled);

                //// Delete
                await index.RemoveAsync();
                await SdkHelper.ThrowsAsync<ResourceNotFoundException>(async () =>
                {
                    await index.GetAsync();
                });

            }
        }
コード例 #15
0
        void CanSetEveryValue()
        {
            var defaultAttributes = new IndexAttributes()
            {
                BlockSignSize = 0,
                BucketRebuildMemoryHint = "auto",
                ColdToFrozenDir = "",
                ColdToFrozenScript = "",
                CompressRawData = true,
                EnableOnlineBucketRepair = true,
                FrozenTimePeriodInSecs = 188697600,
                MaxBloomBackfillBucketAge = "30d",
                MaxConcurrentOptimizes = 6,
                MaxDataSize = "auto",
                MaxHotBuckets = 3,
                MaxHotIdleSecs = 0,
                MaxHotSpanSecs = 7776000,
                MaxMemMB = 5,
                MaxMetaEntries = 1000000,
                MaxTimeUnreplicatedNoAcks = 300,
                MaxTimeUnreplicatedWithAcks = 60,
                MaxTotalDataSizeMB = 500000,
                MaxWarmDBCount = 300,
                MinRawFileSyncSecs = "disable",
                MinStreamGroupQueueSize = 2000,
                PartialServiceMetaPeriod = 0,
                ProcessTrackerServiceInterval = 1,
                QuarantineFutureSecs = 2592000,
                QuarantinePastSecs = 77760000,
                RawChunkSizeBytes = 131072,
                RepFactor = "0",
                RotatePeriodInSecs = 60,
                ServiceMetaPeriod = 25,
                SyncMeta = true,
                ThrottleCheckPeriod = 15,
                TStatsHomePath = "",
                WarmToColdScript = "",
            };

            Assert.Equal(new List<Argument>()
                {
                    new Argument("blockSignSize", "0"),
                    new Argument("bucketRebuildMemoryHint", "auto"),
                    new Argument("coldToFrozenDir", ""),
                    new Argument("coldToFrozenScript", ""),
                    new Argument("compressRawdata", 1),
                    new Argument("enableOnlineBucketRepair", 1),
                    new Argument("frozenTimePeriodInSecs", "188697600"),
                    new Argument("maxBloomBackfillBucketAge", "30d"),
                    new Argument("maxConcurrentOptimizes", "6"),
                    new Argument("maxDataSize", "auto"),
                    new Argument("maxHotBuckets", "3"),
                    new Argument("maxHotIdleSecs", "0"),
                    new Argument("maxHotSpanSecs", "7776000"),
                    new Argument("maxMemMB", "5"),
                    new Argument("maxMetaEntries", "1000000"),
                    new Argument("maxTimeUnreplicatedNoAcks", "300"),
                    new Argument("maxTimeUnreplicatedWithAcks", "60"),
                    new Argument("maxTotalDataSizeMB", "500000"),
                    new Argument("maxWarmDBCount", "300"),
                    new Argument("minRawFileSyncSecs", "disable"),
                    new Argument("minStreamGroupQueueSize", "2000"),
                    new Argument("partialServiceMetaPeriod", "0"),
                    new Argument("processTrackerServiceInterval", "1"),
                    new Argument("quarantineFutureSecs", "2592000"),
                    new Argument("quarantinePastSecs", "77760000"),
                    new Argument("rawChunkSizeBytes", "131072"),
                    new Argument("repFactor", "0"),
                    new Argument("rotatePeriodInSecs", "60"),
                    new Argument("serviceMetaPeriod", "25"),
                    new Argument("syncMeta", 1),
                    new Argument("throttleCheckPeriod", "15"),
                    new Argument("tstatsHomePath", ""),
                    new Argument("warmToColdScript", ""),
                },
                defaultAttributes);

            var attributes = new IndexAttributes()
            {
                BlockSignSize = 1 + 0,
                BucketRebuildMemoryHint = "some_unchecked_string_value",
                ColdToFrozenDir = "some_unchecked_string_value",
                ColdToFrozenScript = "some_unchecked_string_value",
                CompressRawData = false,
                EnableOnlineBucketRepair = false,
                FrozenTimePeriodInSecs = int.MaxValue,
                MaxBloomBackfillBucketAge = "some_unchecked_string_value",
                MaxConcurrentOptimizes = 2,
                MaxDataSize = "some_unchecked_string_value",
                MaxHotBuckets = 3 * 3,
                MaxHotIdleSecs = 4,
                MaxHotSpanSecs = 7776000 * 5,
                MaxMemMB = 6,
                MaxMetaEntries = 7 * 1000000,
                MaxTimeUnreplicatedNoAcks = 8 * 300,
                MaxTimeUnreplicatedWithAcks = 9 * 60,
                MaxTotalDataSizeMB = 10 * 500000,
                MaxWarmDBCount = 11 * 300,
                MinRawFileSyncSecs = "some_unchecked_string_value",
                MinStreamGroupQueueSize = 12 * 2000,
                PartialServiceMetaPeriod = 13 + 0,
                ProcessTrackerServiceInterval = 14 + 1,
                QuarantineFutureSecs = 15 + 2592000,
                QuarantinePastSecs = 16 + 77760000,
                RawChunkSizeBytes = 17 + 131072,
                RepFactor = "some_unchecked_string_value",
                RotatePeriodInSecs = 19 + 60,
                ServiceMetaPeriod = 20 + 25,
                SyncMeta = false,
                ThrottleCheckPeriod = 21 + 15,
                TStatsHomePath = "some_unchecked_string_value",
                WarmToColdScript = "some_unchecked_string_value",
            };

            Assert.Equal(
                "blockSignSize=1; " +
                "bucketRebuildMemoryHint=some_unchecked_string_value; " +
                "coldToFrozenDir=some_unchecked_string_value; " +
                "coldToFrozenScript=some_unchecked_string_value; " +
                "compressRawdata=0; " +
                "enableOnlineBucketRepair=0; " +
                "frozenTimePeriodInSecs=2147483647; " +
                "maxBloomBackfillBucketAge=some_unchecked_string_value; " +
                "maxConcurrentOptimizes=2; " +
                "maxDataSize=some_unchecked_string_value; " +
                "maxHotBuckets=9; " +
                "maxHotIdleSecs=4; " +
                "maxHotSpanSecs=38880000; " +
                "maxMemMB=6; " +
                "maxMetaEntries=7000000; " +
                "maxTimeUnreplicatedNoAcks=2400; " +
                "maxTimeUnreplicatedWithAcks=540; " +
                "maxTotalDataSizeMB=5000000; " +
                "maxWarmDBCount=3300; " +
                "minRawFileSyncSecs=some_unchecked_string_value; " +
                "minStreamGroupQueueSize=24000; " +
                "partialServiceMetaPeriod=13; " +
                "processTrackerServiceInterval=15; " +
                "quarantineFutureSecs=2592015; " +
                "quarantinePastSecs=77760016; " +
                "rawChunkSizeBytes=131089; " +
                "repFactor=some_unchecked_string_value; " +
                "rotatePeriodInSecs=79; " +
                "serviceMetaPeriod=45; " +
                "syncMeta=0; " +
                "throttleCheckPeriod=36; " +
                "tstatsHomePath=some_unchecked_string_value; " +
                "warmToColdScript=some_unchecked_string_value",
                attributes.ToString());

            Assert.Equal(new List<Argument>()
                {
                    new Argument("blockSignSize", "1"),
                    new Argument("bucketRebuildMemoryHint", "some_unchecked_string_value"),
                    new Argument("coldToFrozenDir", "some_unchecked_string_value"),
                    new Argument("coldToFrozenScript", "some_unchecked_string_value"),
                    new Argument("compressRawdata", 0),
                    new Argument("enableOnlineBucketRepair", 0),
                    new Argument("frozenTimePeriodInSecs", "2147483647"),
                    new Argument("maxBloomBackfillBucketAge", "some_unchecked_string_value"),
                    new Argument("maxConcurrentOptimizes", "2"),
                    new Argument("maxDataSize", "some_unchecked_string_value"),
                    new Argument("maxHotBuckets", "9"),
                    new Argument("maxHotIdleSecs", "4"),
                    new Argument("maxHotSpanSecs", "38880000"),
                    new Argument("maxMemMB", "6"),
                    new Argument("maxMetaEntries", "7000000"),
                    new Argument("maxTimeUnreplicatedNoAcks", "2400"),
                    new Argument("maxTimeUnreplicatedWithAcks", "540"),
                    new Argument("maxTotalDataSizeMB", "5000000"),
                    new Argument("maxWarmDBCount", "3300"),
                    new Argument("minRawFileSyncSecs", "some_unchecked_string_value"),
                    new Argument("minStreamGroupQueueSize", "24000"),
                    new Argument("partialServiceMetaPeriod", "13"),
                    new Argument("processTrackerServiceInterval", "15"),
                    new Argument("quarantineFutureSecs", "2592015"),
                    new Argument("quarantinePastSecs", "77760016"),
                    new Argument("rawChunkSizeBytes", "131089"),
                    new Argument("repFactor", "some_unchecked_string_value"),
                    new Argument("rotatePeriodInSecs", "79"),
                    new Argument("serviceMetaPeriod", "45"),
                    new Argument("syncMeta", 0),
                    new Argument("throttleCheckPeriod", "36"),
                    new Argument("tstatsHomePath", "some_unchecked_string_value"),
                    new Argument("warmToColdScript", "some_unchecked_string_value")
                },
                attributes);
        }
コード例 #16
0
ファイル: TestIndex.cs プロジェクト: Netsuye/Splunk-SDK
        /// <summary>
        /// Gets old values from given index, skip saving paths and things we cannot write
        /// </summary>
        /// <param name="index">The Index</param>
        /// <returns>The argument getIndexProperties</returns>
        IndexAttributes GetIndexAttributes(Index index)
        {
            IndexAttributes indexAttributes = new IndexAttributes();

            indexAttributes.BlockSignSize = index.BlockSignSize;
            indexAttributes.FrozenTimePeriodInSecs = index.FrozenTimePeriodInSecs;
            indexAttributes.MaxConcurrentOptimizes = index.MaxConcurrentOptimizes;
            indexAttributes.MaxDataSize = index.MaxDataSize;
            indexAttributes.MaxHotBuckets = index.MaxHotBuckets;
            indexAttributes.MaxHotIdleSecs = index.MaxHotIdleSecs;
            indexAttributes.MaxHotSpanSecs = index.MaxHotSpanSecs;
            indexAttributes.MaxMemMB = index.MaxMemMB;
            indexAttributes.MaxMetaEntries = index.MaxMetaEntries;
            indexAttributes.MaxTotalDataSizeMB = index.MaxTotalDataSizeMB;
            indexAttributes.MaxWarmDBCount = index.MaxWarmDBCount;
            indexAttributes.MinRawFileSyncSecs = index.MinRawFileSyncSecs;
            indexAttributes.PartialServiceMetaPeriod = index.PartialServiceMetaPeriod;
            indexAttributes.QuarantineFutureSecs = index.QuarantineFutureSecs;
            indexAttributes.QuarantinePastSecs = index.QuarantinePastSecs;
            indexAttributes.RawChunkSizeBytes = index.RawChunkSizeBytes;
            indexAttributes.RotatePeriodInSecs = index.RotatePeriodInSecs;
            indexAttributes.ServiceMetaPeriod = index.ServiceMetaPeriod;
            indexAttributes.SyncMeta = index.SyncMeta;
            indexAttributes.ThrottleCheckPeriod = index.ThrottleCheckPeriod;

            return indexAttributes;
        }
コード例 #17
0
        void CanSetEveryValue()
        {
            var defaultAttributes = new IndexAttributes()
            {
                BlockSignSize             = 0,
                BucketRebuildMemoryHint   = "auto",
                ColdToFrozenDir           = "",
                ColdToFrozenScript        = "",
                CompressRawData           = true,
                EnableOnlineBucketRepair  = true,
                FrozenTimePeriodInSecs    = 188697600,
                MaxBloomBackfillBucketAge = "30d",
                MaxConcurrentOptimizes    = 6,
                MaxDataSize                   = "auto",
                MaxHotBuckets                 = 3,
                MaxHotIdleSecs                = 0,
                MaxHotSpanSecs                = 7776000,
                MaxMemMB                      = 5,
                MaxMetaEntries                = 1000000,
                MaxTimeUnreplicatedNoAcks     = 300,
                MaxTimeUnreplicatedWithAcks   = 60,
                MaxTotalDataSizeMB            = 500000,
                MaxWarmDBCount                = 300,
                MinRawFileSyncSecs            = "disable",
                MinStreamGroupQueueSize       = 2000,
                PartialServiceMetaPeriod      = 0,
                ProcessTrackerServiceInterval = 1,
                QuarantineFutureSecs          = 2592000,
                QuarantinePastSecs            = 77760000,
                RawChunkSizeBytes             = 131072,
                RepFactor                     = "0",
                RotatePeriodInSecs            = 60,
                ServiceMetaPeriod             = 25,
                SyncMeta                      = true,
                ThrottleCheckPeriod           = 15,
                TStatsHomePath                = "",
                WarmToColdScript              = "",
            };

            Assert.Equal(new List <Argument>()
            {
                new Argument("blockSignSize", "0"),
                new Argument("bucketRebuildMemoryHint", "auto"),
                new Argument("coldToFrozenDir", ""),
                new Argument("coldToFrozenScript", ""),
                new Argument("compressRawdata", 1),
                new Argument("enableOnlineBucketRepair", 1),
                new Argument("frozenTimePeriodInSecs", "188697600"),
                new Argument("maxBloomBackfillBucketAge", "30d"),
                new Argument("maxConcurrentOptimizes", "6"),
                new Argument("maxDataSize", "auto"),
                new Argument("maxHotBuckets", "3"),
                new Argument("maxHotIdleSecs", "0"),
                new Argument("maxHotSpanSecs", "7776000"),
                new Argument("maxMemMB", "5"),
                new Argument("maxMetaEntries", "1000000"),
                new Argument("maxTimeUnreplicatedNoAcks", "300"),
                new Argument("maxTimeUnreplicatedWithAcks", "60"),
                new Argument("maxTotalDataSizeMB", "500000"),
                new Argument("maxWarmDBCount", "300"),
                new Argument("minRawFileSyncSecs", "disable"),
                new Argument("minStreamGroupQueueSize", "2000"),
                new Argument("partialServiceMetaPeriod", "0"),
                new Argument("processTrackerServiceInterval", "1"),
                new Argument("quarantineFutureSecs", "2592000"),
                new Argument("quarantinePastSecs", "77760000"),
                new Argument("rawChunkSizeBytes", "131072"),
                new Argument("repFactor", "0"),
                new Argument("rotatePeriodInSecs", "60"),
                new Argument("serviceMetaPeriod", "25"),
                new Argument("syncMeta", 1),
                new Argument("throttleCheckPeriod", "15"),
                new Argument("tstatsHomePath", ""),
                new Argument("warmToColdScript", ""),
            },
                         defaultAttributes);

            var attributes = new IndexAttributes()
            {
                BlockSignSize             = 1 + 0,
                BucketRebuildMemoryHint   = "some_unchecked_string_value",
                ColdToFrozenDir           = "some_unchecked_string_value",
                ColdToFrozenScript        = "some_unchecked_string_value",
                CompressRawData           = false,
                EnableOnlineBucketRepair  = false,
                FrozenTimePeriodInSecs    = int.MaxValue,
                MaxBloomBackfillBucketAge = "some_unchecked_string_value",
                MaxConcurrentOptimizes    = 2,
                MaxDataSize                   = "some_unchecked_string_value",
                MaxHotBuckets                 = 3 * 3,
                MaxHotIdleSecs                = 4,
                MaxHotSpanSecs                = 7776000 * 5,
                MaxMemMB                      = 6,
                MaxMetaEntries                = 7 * 1000000,
                MaxTimeUnreplicatedNoAcks     = 8 * 300,
                MaxTimeUnreplicatedWithAcks   = 9 * 60,
                MaxTotalDataSizeMB            = 10 * 500000,
                MaxWarmDBCount                = 11 * 300,
                MinRawFileSyncSecs            = "some_unchecked_string_value",
                MinStreamGroupQueueSize       = 12 * 2000,
                PartialServiceMetaPeriod      = 13 + 0,
                ProcessTrackerServiceInterval = 14 + 1,
                QuarantineFutureSecs          = 15 + 2592000,
                QuarantinePastSecs            = 16 + 77760000,
                RawChunkSizeBytes             = 17 + 131072,
                RepFactor                     = "some_unchecked_string_value",
                RotatePeriodInSecs            = 19 + 60,
                ServiceMetaPeriod             = 20 + 25,
                SyncMeta                      = false,
                ThrottleCheckPeriod           = 21 + 15,
                TStatsHomePath                = "some_unchecked_string_value",
                WarmToColdScript              = "some_unchecked_string_value",
            };

            Assert.Equal(
                "blockSignSize=1; " +
                "bucketRebuildMemoryHint=some_unchecked_string_value; " +
                "coldToFrozenDir=some_unchecked_string_value; " +
                "coldToFrozenScript=some_unchecked_string_value; " +
                "compressRawdata=0; " +
                "enableOnlineBucketRepair=0; " +
                "frozenTimePeriodInSecs=2147483647; " +
                "maxBloomBackfillBucketAge=some_unchecked_string_value; " +
                "maxConcurrentOptimizes=2; " +
                "maxDataSize=some_unchecked_string_value; " +
                "maxHotBuckets=9; " +
                "maxHotIdleSecs=4; " +
                "maxHotSpanSecs=38880000; " +
                "maxMemMB=6; " +
                "maxMetaEntries=7000000; " +
                "maxTimeUnreplicatedNoAcks=2400; " +
                "maxTimeUnreplicatedWithAcks=540; " +
                "maxTotalDataSizeMB=5000000; " +
                "maxWarmDBCount=3300; " +
                "minRawFileSyncSecs=some_unchecked_string_value; " +
                "minStreamGroupQueueSize=24000; " +
                "partialServiceMetaPeriod=13; " +
                "processTrackerServiceInterval=15; " +
                "quarantineFutureSecs=2592015; " +
                "quarantinePastSecs=77760016; " +
                "rawChunkSizeBytes=131089; " +
                "repFactor=some_unchecked_string_value; " +
                "rotatePeriodInSecs=79; " +
                "serviceMetaPeriod=45; " +
                "syncMeta=0; " +
                "throttleCheckPeriod=36; " +
                "tstatsHomePath=some_unchecked_string_value; " +
                "warmToColdScript=some_unchecked_string_value",
                attributes.ToString());

            Assert.Equal(new List <Argument>()
            {
                new Argument("blockSignSize", "1"),
                new Argument("bucketRebuildMemoryHint", "some_unchecked_string_value"),
                new Argument("coldToFrozenDir", "some_unchecked_string_value"),
                new Argument("coldToFrozenScript", "some_unchecked_string_value"),
                new Argument("compressRawdata", 0),
                new Argument("enableOnlineBucketRepair", 0),
                new Argument("frozenTimePeriodInSecs", "2147483647"),
                new Argument("maxBloomBackfillBucketAge", "some_unchecked_string_value"),
                new Argument("maxConcurrentOptimizes", "2"),
                new Argument("maxDataSize", "some_unchecked_string_value"),
                new Argument("maxHotBuckets", "9"),
                new Argument("maxHotIdleSecs", "4"),
                new Argument("maxHotSpanSecs", "38880000"),
                new Argument("maxMemMB", "6"),
                new Argument("maxMetaEntries", "7000000"),
                new Argument("maxTimeUnreplicatedNoAcks", "2400"),
                new Argument("maxTimeUnreplicatedWithAcks", "540"),
                new Argument("maxTotalDataSizeMB", "5000000"),
                new Argument("maxWarmDBCount", "3300"),
                new Argument("minRawFileSyncSecs", "some_unchecked_string_value"),
                new Argument("minStreamGroupQueueSize", "24000"),
                new Argument("partialServiceMetaPeriod", "13"),
                new Argument("processTrackerServiceInterval", "15"),
                new Argument("quarantineFutureSecs", "2592015"),
                new Argument("quarantinePastSecs", "77760016"),
                new Argument("rawChunkSizeBytes", "131089"),
                new Argument("repFactor", "some_unchecked_string_value"),
                new Argument("rotatePeriodInSecs", "79"),
                new Argument("serviceMetaPeriod", "45"),
                new Argument("syncMeta", 0),
                new Argument("throttleCheckPeriod", "36"),
                new Argument("tstatsHomePath", "some_unchecked_string_value"),
                new Argument("warmToColdScript", "some_unchecked_string_value")
            },
                         attributes);
        }
コード例 #18
0
 /// <summary>
 /// Constructs an attribute that specifies to include this property in an index
 /// as a column.
 /// </summary>
 /// <param name="indexName">The name of the index to add this column to</param>
 /// <param name="indexAttributes">Additional charateristics for this index</param>
 public SchemaIndexAttribute(string indexName, IndexAttributes indexAttributes)
 {
     IndexName       = indexName;
     IndexAttributes = indexAttributes;
 }
コード例 #19
0
        public async Task CanCrudIndex()
        {
            var ns = new Namespace("nobody", "search");

            using (var service = await SdkHelper.CreateService(ns))
            {
                var indexName = MockContext.GetOrElse(string.Format("delete-me-{0}", Guid.NewGuid()));
                Index index;

                //// Create

                index = await service.Indexes.CreateAsync(indexName);
                Assert.Equal(true, index.EnableOnlineBucketRepair);

                //// Read

                index = await service.Indexes.GetAsync(indexName);

                //// Update

                Exception updateException = null;

                try
                {
                    var attributes = new IndexAttributes()
                    {
                        EnableOnlineBucketRepair = false
                    };

                    await index.UpdateAsync(attributes);
                    Assert.Equal(attributes.EnableOnlineBucketRepair, index.EnableOnlineBucketRepair);
                    Assert.False(index.Disabled);

                    await index.DisableAsync();
                    Assert.True(index.Disabled);

                    await service.Server.RestartAsync(2 * 60 * 1000);
                    await service.LogOnAsync();

                    await index.EnableAsync();
                    Assert.False(index.Disabled);

                }
                catch (Exception e)
                {
                    updateException = e;
                }

                //// Delete

                try
                {
                    await index.RemoveAsync();
                }
                catch (Exception removeException)
                {
                    if (updateException != null)
                    {
                        var text = string.Format("Update/remove failed:\nUpdate failure: {0}\n\n{1}\nRemove failure: {2}\n{3}",
                            updateException.Message, updateException.StackTrace,
                            removeException.Message, removeException.StackTrace);
                        Assert.True(false, text);
                    }
                    throw;
                }

                try
                {
                    await index.GetAsync();
                    Assert.True(false);
                }
                catch (ResourceNotFoundException)
                { }

                index = await service.Indexes.GetOrNullAsync(indexName);
                Assert.Null(index);
            }
        }
コード例 #20
0
ファイル: GCAttach.cs プロジェクト: X-Hax/SA3D
        public override uint Write(EndianWriter writer, uint imageBase, bool DX, Dictionary <string, uint> labels)
        {
            VertexSet[] sets         = VertexData.Values.ToArray();
            uint[]      vtxAddresses = new uint[VertexData.Count];
            for (int i = 0; i < sets.Length; i++)
            {
                VertexSet vtxSet = sets[i];
                vtxAddresses[i] = writer.Position + imageBase;
                IOType outputType = vtxSet.DataType.ToStructType();

                switch (vtxSet.Attribute)
                {
                case VertexAttribute.Position:
                case VertexAttribute.Normal:
                    foreach (Vector3 vec in vtxSet.Vector3Data)
                    {
                        vec.Write(writer, outputType);
                    }
                    break;

                case VertexAttribute.Color0:
                case VertexAttribute.Color1:
                    foreach (Color col in vtxSet.ColorData)
                    {
                        col.Write(writer, outputType);
                    }
                    break;

                case VertexAttribute.Tex0:
                case VertexAttribute.Tex1:
                case VertexAttribute.Tex2:
                case VertexAttribute.Tex3:
                case VertexAttribute.Tex4:
                case VertexAttribute.Tex5:
                case VertexAttribute.Tex6:
                case VertexAttribute.Tex7:
                    foreach (Vector2 uv in vtxSet.UVData)
                    {
                        (uv * 256).Write(writer, outputType);
                    }
                    break;

                case VertexAttribute.PositionMatrixId:
                case VertexAttribute.Null:
                default:
                    throw new FormatException($"Vertex set had an invalid or unavailable type: {vtxSet.Attribute}");
                }
            }

            uint vtxAddr = writer.Position + imageBase;

            // writing vertex attributes
            for (int i = 0; i < sets.Length; i++)
            {
                VertexSet vtxSet = sets[i];

                writer.Write(new byte[] { (byte)vtxSet.Attribute, (byte)vtxSet.StructSize });
                writer.WriteUInt16((ushort)vtxSet.DataLength);

                uint structure = (uint)vtxSet.StructType;
                structure |= (uint)((byte)vtxSet.DataType << 4);
                writer.WriteUInt32(structure);

                writer.WriteUInt32(vtxAddresses[i]);
                writer.WriteUInt32((uint)(vtxSet.DataLength * vtxSet.StructSize));
            }

            // empty vtx attribute
            byte[] nullVtx = new byte[16];
            nullVtx[0] = 0xFF;
            writer.Write(nullVtx);

            // writing geometry data
            uint[] WriteMeshData(Mesh[] meshes)
            {
                uint[]          result       = new uint[meshes.Length * 4];
                IndexAttributes indexAttribs = IndexAttributes.HasPosition;

                for (int i = 0, ri = 0; i < meshes.Length; i++, ri += 4)
                {
                    Mesh m = meshes[i];

                    IndexAttributes?t = m.IndexAttributes;
                    if (t.HasValue)
                    {
                        indexAttribs = t.Value;
                    }

                    // writing parameters
                    result[ri]     = writer.Position + imageBase;
                    result[ri + 1] = (uint)m.Parameters.Length;
                    foreach (IParameter p in m.Parameters)
                    {
                        p.Write(writer);
                    }

                    // writing polygons
                    uint addr = writer.Position;
                    foreach (Poly p in m.Polys)
                    {
                        p.Write(writer, indexAttribs);
                    }
                    result[ri + 2] = addr + imageBase;
                    result[ri + 3] = writer.Position - addr;
                }
                return(result);
            }

            uint[] opaqueMeshStructs      = WriteMeshData(OpaqueMeshes);
            uint[] transparentMeshStructs = WriteMeshData(TransparentMeshes);

            // writing geometry properties
            uint opaqueAddress = writer.Position + imageBase;

            foreach (uint i in opaqueMeshStructs)
            {
                writer.Write(i);
            }

            uint transparentAddress = writer.Position + imageBase;

            foreach (uint i in transparentMeshStructs)
            {
                writer.Write(i);
            }

            uint address = writer.Position + imageBase;

            labels.AddLabel(Name, address);

            writer.WriteUInt32(vtxAddr);
            writer.WriteUInt32(0);
            writer.WriteUInt32(opaqueAddress);
            writer.WriteUInt32(transparentAddress);
            writer.WriteUInt16((ushort)OpaqueMeshes.Length);
            writer.WriteUInt16((ushort)TransparentMeshes.Length);
            MeshBounds.Write(writer);
            return(address);
        }
コード例 #21
0
ファイル: GCAttach.cs プロジェクト: X-Hax/SA3D
        /// <summary>
        /// Load a gc attach from a file
        /// </summary>
        /// <param name="source">Byte source from a file</param>
        /// <param name="address">Address at which the attach is located</param>
        /// <param name="imageBase">Address image base</param>
        /// <param name="labels">Labels for the data to use</param>
        /// <returns></returns>
        public static GCAttach Read(byte[] source, uint address, uint imageBase, Dictionary <uint, string> labels)
        {
            string name;

            if (labels.ContainsKey(address))
            {
                name = labels[address];
            }
            else
            {
                name = "attach_" + address.ToString("X8");
            }

            // The struct is 36/0x24 bytes long

            uint vertexAddress = source.ToUInt32(address) - imageBase;
            //uint gap = source.ToUInt32(address + 4);
            uint opaqueAddress      = source.ToUInt32(address + 8) - imageBase;
            uint transparentAddress = source.ToUInt32(address + 12) - imageBase;

            int opaqueCount      = source.ToInt16(address + 16);
            int transparentCount = source.ToInt16(address + 18);

            address += 20;
            Bounds bounds = Bounds.Read(source, ref address);

            // reading vertex data
            List <VertexSet> vertexData = new();
            VertexSet        vertexSet  = VertexSet.Read(source, vertexAddress, imageBase);

            while (vertexSet.Attribute != VertexAttribute.Null)
            {
                vertexData.Add(vertexSet);
                vertexAddress += 16;
                vertexSet      = VertexSet.Read(source, vertexAddress, imageBase);
            }

            IndexAttributes indexAttribs = IndexAttributes.HasPosition;

            List <Mesh> opaqueMeshes = new();

            for (int i = 0; i < opaqueCount; i++)
            {
                Mesh mesh = Mesh.Read(source, opaqueAddress, imageBase, ref indexAttribs);
                opaqueMeshes.Add(mesh);
                opaqueAddress += 16;
            }

            indexAttribs = IndexAttributes.HasPosition;

            List <Mesh> transparentMeshes = new();

            for (int i = 0; i < transparentCount; i++)
            {
                Mesh mesh = Mesh.Read(source, transparentAddress, imageBase, ref indexAttribs);
                transparentMeshes.Add(mesh);
                transparentAddress += 16;
            }

            return(new GCAttach(vertexData.ToArray(), opaqueMeshes.ToArray(), transparentMeshes.ToArray())
            {
                Name = name,
                MeshBounds = bounds
            });
        }
コード例 #22
0
        public async Task IndexArgs()
        {
            string         indexName = "sdk-tests2";
            DateTimeOffset offset    = new DateTimeOffset(DateTime.Now);
            string         now       = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss") +
                                       string.Format("{0}{1} ", offset.Offset.Hours.ToString("D2"),
                                                     offset.Offset.Minutes.ToString("D2"));

            Service service = this.Connect();
            Index   index   = await service.GetIndexAsync(indexName);

            //index.Enable();
            Assert.False(index.Disabled);

            IndexAttributes indexAttributes = GetIndexAttributes(index);

            //ClearIndex(service, indexName, index);

            // submit event to index using variable arguments
            //index.Submit(indexAttributes, now + " Hello World. \u0150");
            //index.Submit(indexAttributes, now + " Goodbye World. \u0150");
            //WaitUntilEventCount(index, 2, 45);

            await ClearIndex(service, indexName, index);

            // stream event to index with variable arguments
            //Stream streamArgs = index.Attach(indexAttributes);
            //streamArgs.Write(Encoding.UTF8.GetBytes(now + " Hello World again. \u0150\r\n"));
            //streamArgs.Write(Encoding.UTF8.GetBytes(now + " Goodbye World again.\u0150\r\n"));
            //streamArgs.Close();
            //WaitUntilEventCount(index, 2, 45);

            // submit event using ReceiverSubmitArgs
            const string Source     = "splunk-sdk-tests";
            const string SourceType = "splunk-sdk-test-event";
            const string Host       = "test-host";
            var          args       = new ReceiverArgs
            {
                Index      = indexName,
                Host       = Host,
                Source     = Source,
                SourceType = SourceType,
            };

            //var receiver = service.GetReceiver();
            Receiver receiver = new Receiver();
            //receiver.Submit(args, "Hello World.");
            //receiver.Submit(args, "Goodbye world.");
            await receiver.SendAsync("Hello World.", args);

            await receiver.SendAsync("Goodbye world.", args);

            //WaitUntilEventCount(index, 4, 45);
            // verify the fields of events in the index matching the args.
            //using (var stream =
            //    service.Oneshot(
            //        string.Format(
            //            "search index={0} host={1} source={2} sourcetype={3}",
            //            indexName,
            //            Host,
            //            Source,
            //            SourceType)))

            SearchResults result = await service.SearchOneshotAsync(
                string.Format(
                    "search index={0} host={1} source={2} sourcetype={3}",
                    indexName,
                    Host,
                    Source,
                    SourceType));

            //using (var reader = new ResultsReaderXml(stream))
            //{
            //    Assert.Equal(2, reader.Count());
            //}
            Assert.Equal(2, result.FieldNames.Count);
            await index.GetAsync();

            Assert.Equal(2, index.TotalEventCount);

            await ClearIndex(service, indexName, index);

            //index.Clean(180);
            //Assert.Equal(0, index.TotalEventCount, "Expected the total event count to be 0");
        }
コード例 #23
0
ファイル: Poly.cs プロジェクト: X-Hax/SA3D
        /// <summary>
        /// Read a primitive object from a file
        /// </summary>
        /// <param name="source">The files contents as a byte array</param>
        /// <param name="address">The starting address of the primitive</param>
        /// <param name="indexAttribs">How the indices of the loops are structured</param>
        public static Poly Read(byte[] source, ref uint address, IndexAttributes indexAttribs)
        {
            PushBigEndian(true);

            PolyType type     = (PolyType)source[address];
            ushort   vtxCount = source.ToUInt16(address + 1);

            // checking the attributes
            bool hasFlag(IndexAttributes attrib) => indexAttribs.HasFlag(attrib);

            // position always exists
            bool hasCol = hasFlag(IndexAttributes.HasColor);
            bool hasNrm = hasFlag(IndexAttributes.HasNormal);
            bool hasUV  = hasFlag(IndexAttributes.HasUV);

            //whether any of the indices use 16 bits instead of 8
            bool shortPos = hasFlag(IndexAttributes.Position16BitIndex);
            bool shortCol = hasFlag(IndexAttributes.Color16BitIndex);
            bool shortNrm = hasFlag(IndexAttributes.Normal16BitIndex);
            bool shortUV  = hasFlag(IndexAttributes.UV16BitIndex);

            address += 3;

            List <Corner> corners = new();

            for (ushort i = 0; i < vtxCount; i++)
            {
                Corner l = new();

                // reading position, which should always exist
                if (shortPos)
                {
                    l.PositionIndex = source.ToUInt16(address);
                    address        += 2;
                }
                else
                {
                    l.PositionIndex = source[address];
                    address++;
                }

                // reading normals
                if (hasNrm)
                {
                    if (shortNrm)
                    {
                        l.NormalIndex = source.ToUInt16(address);
                        address      += 2;
                    }
                    else
                    {
                        l.NormalIndex = source[address];
                        address++;
                    }
                }

                // reading colors
                if (hasCol)
                {
                    if (shortCol)
                    {
                        l.Color0Index = source.ToUInt16(address);
                        address      += 2;
                    }
                    else
                    {
                        l.Color0Index = source[address];
                        address++;
                    }
                }

                // reading uvs
                if (hasUV)
                {
                    if (shortUV)
                    {
                        l.UV0Index = source.ToUInt16(address);
                        address   += 2;
                    }
                    else
                    {
                        l.UV0Index = source[address];
                        address++;
                    }
                }

                corners.Add(l);
            }

            PopEndian();
            return(new Poly(type, corners.ToArray()));
        }
コード例 #24
0
 /// <summary>
 /// Finds <see cref="IndexInfo"/> objects by the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria.</param>
 /// <returns>A sequence of found objects.</returns>
 public ICollection <IndexInfo> Find(IndexAttributes criteria)
 {
     return(Find(criteria, MatchType.Full));
 }
コード例 #25
0
ファイル: Poly.cs プロジェクト: X-Hax/SA3D
        /// <summary>
        /// Write the contents
        /// </summary>
        /// <param name="writer">The output stream</param>
        /// <param name="indexAttribs">How the indices of the loops are structured</param>
        public void Write(EndianWriter writer, IndexAttributes indexAttribs)
        {
            writer.PushBigEndian(true);

            writer.Write((byte)Type);
            writer.Write((ushort)Corners.Length);

            // checking the attributes
            bool hasFlag(IndexAttributes attrib) => indexAttribs.HasFlag(attrib);

            // position always exists
            bool hasCol = hasFlag(IndexAttributes.HasColor);
            bool hasNrm = hasFlag(IndexAttributes.HasNormal);
            bool hasUV  = hasFlag(IndexAttributes.HasUV);

            bool shortPos = hasFlag(IndexAttributes.Position16BitIndex);
            bool shortCol = hasFlag(IndexAttributes.Color16BitIndex);
            bool shortNrm = hasFlag(IndexAttributes.Normal16BitIndex);
            bool shortUV  = hasFlag(IndexAttributes.UV16BitIndex);

            foreach (Corner v in Corners)
            {
                // Position should always exist
                if (shortPos)
                {
                    writer.Write(v.PositionIndex);
                }
                else
                {
                    writer.Write((byte)v.PositionIndex);
                }

                if (hasNrm)
                {
                    if (shortNrm)
                    {
                        writer.Write(v.NormalIndex);
                    }
                    else
                    {
                        writer.Write((byte)v.NormalIndex);
                    }
                }

                if (hasCol)
                {
                    if (shortCol)
                    {
                        writer.Write(v.Color0Index);
                    }
                    else
                    {
                        writer.Write((byte)v.Color0Index);
                    }
                }

                if (hasUV)
                {
                    if (shortUV)
                    {
                        writer.Write(v.UV0Index);
                    }
                    else
                    {
                        writer.Write((byte)v.UV0Index);
                    }
                }
            }

            writer.PopEndian();
        }
コード例 #26
0
 /// <summary>
 /// Constructs an attribute that specifies to include this property in an index
 /// as a column.
 /// </summary>
 /// <param name="indexName">The name of the index to add this column to</param>
 public SchemaIndexAttribute(string indexName)
 {
     IndexName       = indexName;
     IndexAttributes = IndexAttributes.None;
 }