public virtual string Build(WriteOptions options)
        {
            Ensure.That(options, nameof(options)).IsNotNull();

            var sb = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(options.RetentionPolicy))
            {
                sb.Append("&rp=");
                sb.Append(UrlEncoder.Encode(options.RetentionPolicy));
            }

            if (options.Consistency.HasValue)
            {
                sb.Append("&consistency=");
                sb.Append(options.Consistency.Value.ToUrlValue());
            }

            if (options.TimeStampPrecision.HasValue)
            {
                sb.Append("&precision=");
                sb.Append(options.TimeStampPrecision.Value.ToUrlValue());
            }

            return sb.ToString();
        }
Ejemplo n.º 2
0
 public void Write(WriteOptions options, string value)
 {
     var lines = value.Split(SplitCharacters,
         StringSplitOptions.RemoveEmptyEntries);
     bool is_multiline = lines.Length > 1;
     if (is_multiline)
     {
         // Write all internal lines
         for (int i = 0; i < lines.Length - 1; i++)
         {
             var line = lines[i];
             WriteIndentations(options);
             sw.Write(line);
             sw.Write(System.Environment.NewLine);
         }
         // Write the last line without appending a newline
         WriteIndentations(options);
         sw.Write(lines[lines.Length - 1]);
     }
     else
     {
         WriteIndentations(options);
         sw.Write(value);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Fire is used to fire a new user event. Only the Name, Payload and Filters are respected. This returns the ID or an associated error. Cross DC requests are supported.
 /// </summary>
 /// <param name="ue">A User Event definition</param>
 /// <param name="q">Customized write options</param>
 /// <returns></returns>
 public WriteResult<string> Fire(UserEvent ue, WriteOptions q)
 {
     var req =
         _client.CreateWrite<byte[], EventCreationResult>(string.Format("/v1/event/fire/{0}", ue.Name),
             ue.Payload, q);
     if (!string.IsNullOrEmpty(ue.NodeFilter))
     {
         req.Params["node"] = ue.NodeFilter;
     }
     if (!string.IsNullOrEmpty(ue.ServiceFilter))
     {
         req.Params["service"] = ue.ServiceFilter;
     }
     if (!string.IsNullOrEmpty(ue.TagFilter))
     {
         req.Params["tag"] = ue.TagFilter;
     }
     var res = req.Execute();
     var ret = new WriteResult<string>()
     {
         RequestTime = res.RequestTime,
         Response = res.Response.ID
     };
     return ret;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Fire is used to fire a new user event. Only the Name, Payload and Filters are respected. This returns the ID or an associated error. Cross DC requests are supported.
 /// </summary>
 /// <param name="ue">A User Event definition</param>
 /// <param name="q">Customized write options</param>
 /// <returns></returns>
 public async Task<WriteResult<string>> Fire(UserEvent ue, WriteOptions q)
 {
     var req = _client.Put<byte[], EventCreationResult>(string.Format("/v1/event/fire/{0}", ue.Name), ue.Payload, q);
     if (!string.IsNullOrEmpty(ue.NodeFilter))
     {
         req.Params["node"] = ue.NodeFilter;
     }
     if (!string.IsNullOrEmpty(ue.ServiceFilter))
     {
         req.Params["service"] = ue.ServiceFilter;
     }
     if (!string.IsNullOrEmpty(ue.TagFilter))
     {
         req.Params["tag"] = ue.TagFilter;
     }
     var res = await req.Execute().ConfigureAwait(false);
     return new WriteResult<string>(res, res.Response.ID);
 }
Ejemplo n.º 5
0
        public void Write(WriteOptions options, string value)
        {
            var lines = value.Split(SplitStrings, StringSplitOptions.None);
            for (int i = 0; i < lines.Length; ++i)
            {
                if (lines[i].Length != 0)
                {
                    if (newline)
                    {
                        WriteIndentations(options);
                    }
                    newline = false;
                    sw.Write(lines[i]);
                }

                // if we're going to write another line add a line break string
                if (i + 1 < lines.Length)
                {
                    sw.Write(System.Environment.NewLine);
                    newline = true;
                }
            }
        }
Ejemplo n.º 6
0
 public Task <WriteResult> Update(PreparedQueryDefinition query, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put(string.Format("/v1/query/{0}", query.ID), query, q).Execute(ct));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Clone is used to return a new token cloned from an existing one
        /// </summary>
        /// <param name="id">The ACL ID to clone</param>
        /// <param name="q">Customized write options</param>
        /// <returns>A write result containing the newly created ACL token</returns>
        public async Task <WriteResult <string> > Clone(string id, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.PutReturning <ACLCreationResult>(string.Format("/v1/acl/clone/{0}", id), q).Execute(ct).ConfigureAwait(false);

            return(new WriteResult <string>(res, res.Response.ID));
        }
Ejemplo n.º 8
0
 public async Task<WriteResult<string>> Create(PreparedQueryDefinition query, WriteOptions q)
 {
     var res = await _client.Post<PreparedQueryDefinition, PreparedQueryCreationResult>("/v1/query", query, q).Execute().ConfigureAwait(false);
     return new WriteResult<string>(res, res.Response.ID);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Write is used to do a PUT request against an endpoint and serialize/deserialized using the standard Consul conventions.
 /// </summary>
 /// <param name="endpoint">The URL endpoint to access</param>
 /// <param name="obj">The object to serialize and send to the endpoint. Must be able to be JSON serialized, or be an object of type byte[], which is sent without serialzation.</param>
 /// <param name="q">Custom write options</param>
 /// <returns>The data returned by the custom endpoint in response to the write request</returns>
 public Task<WriteResult<dynamic>> Write(string endpoint, object obj, WriteOptions q)
 {
     return _client.Put<object, dynamic>(endpoint, obj, q).Execute();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures.
 /// </summary>
 /// <param name="p">The key/value pair to delete</param>
 /// <param name="q">Customized write options</param>
 /// <returns>A write result indicating if the delete attempt succeeded</returns>
 public async Task<WriteResult<bool>> DeleteCAS(KVPair p, WriteOptions q)
 {
     p.Validate();
     var req = _client.Delete<bool>(string.Format("/v1/kv/{0}", p.Key), q);
     req.Params.Add("cas", p.ModifyIndex.ToString());
     return await req.Execute().ConfigureAwait(false);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Save a vcard object to a vcf file
 /// </summary>
 /// <param name="filePath">Path to file to save to</param>
 /// <param name="version">Set the save version</param>
 /// <param name="writeOption">Option to determine if the method would overwrite the file or throw an error</param>
 /// <returns>A boolean value stating whether the save option was successful or not</returns>
 public bool Save(string filePath, Version version, WriteOptions writeOption = WriteOptions.ThrowError)
 {
     return(Serializer.Serialize(this, filePath, version, writeOption));
 }
Ejemplo n.º 12
0
        static int Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                ShowUnknown(args);
                return 1;
            }

            var cssClassesAndImagePaths = new List<CssClassAndImagePath>();
            string listPath = null;
            string jsonPath = null;

            var options = new WriteOptions();

            var optionSet = new OptionSet();

            optionSet.Add("?|h|help", ": show help",
                help => ShowHelp(optionSet));

            optionSet.Add("i=|image=", ": a {0:CSS-CLASS} and image {1:FILE} to include in the sprite\n" +
                "example: --image=print-icon:\"printer_icon_32.png\"\n" +
                "this option can be specified multiple times",
                (c, i) => cssClassesAndImagePaths.Add(new CssClassAndImagePath() { CssClass = c, ImagePath = i }));

            optionSet.Add("t=|list=", ": a {FILE} containing a line-delimited list of CSS-CLASS:FILE pairs",
                l => listPath = l);
            #if JSON
            optionSet.Add("j=|json=", ": a JSON {FILE} containing CSS-CLASS and FILE pairs\n" +
                          "example JSON: {{ \"my-icon\": \"my_icon_32.png\" }}",
                j => jsonPath = j);
            #endif
            optionSet.Add("c=|css=", ": output {FILE} for the CSS image map",
                c => options.CssPath = c);

            optionSet.Add("s=|sprite=", ": output {FILE} for the sprite PNG image",
                s => options.SpritePath = s);

            optionSet.Add("l=|class=", ": an optional {CSS-CLASS} that differentiates between background-image " +
                "urls in the output CSS image map",
                l => options.SpriteCssClass = l);

            optionSet.Add("p=|padding=", ": {PADDING} space between images, in pixels",
                p => options.Padding = int.Parse(p));

            optionSet.Add("desaturate", ": desaturate (convert to grayscale) the output image\n" +
                "may be used with hue to colorize the output image",
                d => options.Desaturate = (d != null ? true : false));

            optionSet.Add("hue=", ": EXPERIMENTAL color {HUE} adjustment for the output image\n" +
                "hue is measured in degrees, as an integer between 0 and 360",
                h => options.Hue = int.Parse(h));

            optionSet.Add("saturation=", ": EXPERIMENTAL color {SATURATION} adjustment for the output image\n" +
                "saturation is measured as decimal number between 0 and 1",
                s => options.Saturation = float.Parse(s));

            optionSet.Add("value=", ": EXPERIMENTAL color {VALUE} adjustment for the output image\n" +
                "value is measured as a decimal number between -1 and 1",
                v => options.Value = float.Parse(v));

            optionSet.Add("v|verbose", ": verbose output",
                v => options.Verbose = (v != null ? true : false));

            try
            {
                var extraOptions = optionSet.Parse(args);

                if (extraOptions != null && extraOptions.Count > 0)
                {
                    ShowUnknown(extraOptions.ToArray());
                    return 1;
                }
            }
            catch (OptionException)
            {
                ShowUnknown(args);
                return 1;
            }

            if (!string.IsNullOrEmpty(listPath))
            {
                var cssClassesAndImagePathsFromList = GetCssClassesAndImagePathsFromList(listPath);
                cssClassesAndImagePaths.AddRange(cssClassesAndImagePathsFromList);
            }

            #if JSON
            if (!string.IsNullOrEmpty(jsonPath))
            {
                var cssClassesAndImagePathsFromJson = GetCssClassesAndImagePathsFromJson(jsonPath);
                cssClassesAndImagePaths.AddRange(cssClassesAndImagePathsFromJson);
            }
            #endif

            if (cssClassesAndImagePaths != null && cssClassesAndImagePaths.Count > 0)
            {
                return Sprightly.Write(cssClassesAndImagePaths, options);
            }

            return 0;
        }
 public Task <WriteResult <bool> > DeleteTree(string prefix, WriteOptions q, CancellationToken ct = default)
 {
     throw new NotImplementedException();
 }
 public Task <WriteResult <bool> > DeleteCAS(KVPair p, WriteOptions q, CancellationToken ct = default)
 {
     throw new NotImplementedException();
 }
 public Task <WriteResult <KVTxnResponse> > Txn(List <KVTxnOp> txn, WriteOptions q, CancellationToken ct = default)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
        public async Task Client_SetWriteOptions()
        {
            var client = new ConsulClient();

            var opts = new WriteOptions()
            {
                Datacenter = "foo",
                Token = "12345"
            };

            var request = client.Put<KVPair>("/v1/kv/foo", new KVPair("kv/foo"), opts);
            try
            {
                await request.Execute();
            }
            catch (Exception)
            {
                // ignored
            }

            Assert.Equal("foo", request.Params["dc"]);
            Assert.Equal("12345", request.Params["token"]);
        }
Ejemplo n.º 17
0
        //
        // [TODO]
        //
        static void Main(string[] args)
        {
            CommandArgumentSet arguments = new CommandArgumentSet();

            arguments.Register("-output", "");
            if (arguments.Parse(args) == false)
            {
                return;
            }
            if (arguments.Filenames.Count != 1)
            {
                print_usage();
                return;
            }

            string sInputFile    = arguments.Filenames[0];
            string sFilenameRoot = Path.GetFileNameWithoutExtension(sInputFile);

            if (!File.Exists(sInputFile))
            {
                System.Console.WriteLine("cannot find file " + sInputFile);
                return;
            }


            DMesh3Builder      builder = new DMesh3Builder();
            StandardMeshReader reader  = new StandardMeshReader()
            {
                MeshBuilder = builder
            };
            ReadOptions read_options = ReadOptions.Defaults;

            read_options.ReadMaterials = true;
            IOReadResult readOK = reader.Read(sInputFile, read_options);

            if (readOK.code != IOCode.Ok)
            {
                System.Console.WriteLine("Error reading " + sInputFile);
                System.Console.WriteLine(readOK.message);
                return;
            }

            if (builder.Meshes.Count == 0)
            {
                System.Console.WriteLine("did not find any valid meshes in " + sInputFile);
                return;
            }

            // [TODO] out if count == 0

            string sOutRoot = arguments.Strings["-output"];

            if (sOutRoot.Length > 0)
            {
                bool bOutIsFolder = Directory.Exists(sOutRoot);
                if (!bOutIsFolder)
                {
                    System.Console.WriteLine("-output folder {0} does not exist", sOutRoot);
                    return;
                }
            }

            Dictionary <int, List <int> > MeshesByMaterial = new Dictionary <int, List <int> >();

            MeshesByMaterial[-1] = new List <int>();
            for (int i = 0; i < builder.Materials.Count; ++i)
            {
                MeshesByMaterial[i] = new List <int>();
            }

            int N = builder.Meshes.Count;

            for (int i = 0; i < N; ++i)
            {
                int mati = builder.MaterialAssignment[i];
                if (mati >= builder.Materials.Count)
                {
                    mati = -1;
                }
                MeshesByMaterial[mati].Add(i);
            }

            int file_i = 0;

            foreach (int mat_i in MeshesByMaterial.Keys)
            {
                List <int> mesh_idxs = MeshesByMaterial[mat_i];
                if (mesh_idxs.Count == 0)
                {
                    continue;
                }

                WriteMesh[] write_meshes = new WriteMesh[mesh_idxs.Count];
                for (int i = 0; i < mesh_idxs.Count; ++i)
                {
                    write_meshes[i] = new WriteMesh(builder.Meshes[mesh_idxs[i]]);
                }

                string suffix   = string.Format("_material{0}", file_i++);
                string sOutPath = Path.Combine(sOutRoot, sFilenameRoot + suffix + ".obj");

                StandardMeshWriter writer        = new StandardMeshWriter();
                WriteOptions       write_options = WriteOptions.Defaults;
                if (mat_i != -1)
                {
                    write_options.bWriteMaterials  = true;
                    write_options.bPerVertexUVs    = true;
                    write_options.MaterialFilePath = Path.Combine(sOutRoot, sFilenameRoot + suffix + ".mtl");

                    GenericMaterial        mat     = builder.Materials[mat_i];
                    List <GenericMaterial> matList = new List <GenericMaterial>()
                    {
                        mat
                    };
                    ConstantIndexMap idxmap = new ConstantIndexMap(0);

                    for (int i = 0; i < write_meshes.Length; ++i)
                    {
                        write_meshes[i].Materials        = matList;
                        write_meshes[i].TriToMaterialMap = idxmap;
                    }
                }
                IOWriteResult writeOK = writer.Write(sOutPath, new List <WriteMesh>(write_meshes), write_options);
                if (writeOK.code != IOCode.Ok)
                {
                    System.Console.WriteLine("Error writing " + sOutPath);
                    System.Console.WriteLine(writeOK.message);
                }
            }


            // ok done!
            //System.Console.ReadKey();
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Create is used to generate a new token with the given parameters
        /// </summary>
        /// <param name="acl">The ACL entry to create</param>
        /// <param name="q">Customized write options</param>
        /// <returns>A write result containing the newly created ACL token</returns>
        public async Task <WriteResult <string> > Create(ACLEntry acl, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.Put <ACLEntry, ACLCreationResult>("/v1/acl/create", acl, q).Execute(ct).ConfigureAwait(false);

            return(new WriteResult <string>(res, res.Response.ID));
        }
Ejemplo n.º 19
0
 public Task <WriteResult> Restore(Stream s, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put("/v1/snapshot", s, q).Execute(ct));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Writes a message to the stream, if there is enough space in the buffer and <see cref="WriteCompleteAsync"/>
 /// hasn't already been called.
 /// </summary>
 /// <param name="message">The message to write.</param>
 /// <param name="options">The write options to use for this message.</param>
 /// <exception cref="InvalidOperationException">There isn't enough space left in the buffer,
 /// or <see cref="WriteCompleteAsync"/> has already been called.</exception>
 /// <returns>A <see cref="Task"/> which will complete when the message has been written to the stream.</returns>
 public Task WriteAsync(T message, WriteOptions options) => WriteAsyncImpl(message, options, true, true);
Ejemplo n.º 21
0
 public static WriteFlags GetWriteFlags(WriteOptions writeOptions)
 {
     return(writeOptions != null ? writeOptions.Flags : default(WriteFlags));
 }
Ejemplo n.º 22
0
 public void WriteLine(WriteOptions options, string value)
 {
     Write(options, value);
     WriteLine();
 }
Ejemplo n.º 23
0
 public void WriteLine(WriteOptions options, string value)
 {
     Write(options, value);
     WriteLine();
 }
Ejemplo n.º 24
0
 public void Write(WriteOptions options, string format, params object[] args)
 {
     Write(options, String.Format(format, args));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// CAS is used for a Check-And-Set operation. The Key, ModifyIndex, Flags and Value are respected. Returns true on success or false on failures.
 /// </summary>
 /// <param name="p">The key/value pair to store in Consul</param>
 /// <param name="q">Customized write options</param>
 /// <returns>A write result indicating if the write attempt succeeded</returns>
 public async Task<WriteResult<bool>> CAS(KVPair p, WriteOptions q)
 {
     p.Validate();
     var req = _client.Put<byte[], bool>(string.Format("/v1/kv/{0}", p.Key), p.Value, q);
     if (p.Flags > 0)
     {
         req.Params["flags"] = p.Flags.ToString();
     }
     req.Params["cas"] = p.ModifyIndex.ToString();
     return await req.Execute().ConfigureAwait(false);
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Create makes a new session. Providing a session entry can customize the session. It can also be null to use defaults.
        /// </summary>
        /// <param name="se">The SessionEntry options to use</param>
        /// <param name="q">Customized write options</param>
        /// <returns>A write result containing the new session ID</returns>
        public async Task <WriteResult <string> > Create(SessionEntry se, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.Put <SessionEntry, SessionCreationResult>("/v1/session/create", se, q).Execute(ct).ConfigureAwait(false);

            return(new WriteResult <string>(res, res.Response.ID));
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Release is used for a lock release operation. The Key, Flags, Value and Session are respected.
 /// </summary>
 /// <param name="p">The key/value pair to store in Consul</param>
 /// <param name="q">Customized write options</param>
 /// <returns>A write result indicating if the release attempt succeeded</returns>
 public async Task<WriteResult<bool>> Release(KVPair p, WriteOptions q)
 {
     p.Validate();
     var req = _client.Put<object, bool>(string.Format("/v1/kv/{0}", p.Key), q);
     if (p.Flags > 0)
     {
         req.Params["flags"] = p.Flags.ToString();
     }
     req.Params["release"] = p.Session;
     return await req.Execute().ConfigureAwait(false);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Destroy invalidates a given session
 /// </summary>
 /// <param name="id">The session ID to destroy</param>
 /// <param name="q">Customized write options</param>
 /// <returns>A write result containing the result of the session destruction</returns>
 public Task <WriteResult <bool> > Destroy(string id, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put <object, bool>(string.Format("/v1/session/destroy/{0}", id), q).Execute(ct));
 }
Ejemplo n.º 29
0
 public async Task<WriteResult> Update(PreparedQueryDefinition query, WriteOptions q)
 {
     return await _client.Put(string.Format("/v1/query/{0}", query.ID), query, q).Execute().ConfigureAwait(false);
 }
Ejemplo n.º 30
0
        public IGattCharacteristicBuilder SetWrite(Func <WriteRequest, GattState> request, WriteOptions options = WriteOptions.Write)
        {
            var enc  = options.HasFlag(WriteOptions.EncryptionRequired);
            var auth = options.HasFlag(WriteOptions.AuthenticatedSignedWrites);

            if (enc && auth)
            {
                this.writeProtection = GattProtectionLevel.EncryptionAndAuthenticationRequired;
            }
            else if (enc)
            {
                this.writeProtection = GattProtectionLevel.EncryptionRequired;
            }
            else if (auth)
            {
                this.writeProtection = GattProtectionLevel.AuthenticationRequired;
            }

            if (options.HasFlag(WriteOptions.Write))
            {
                this.properties |= GattCharacteristicProperties.Write;
            }

            if (options.HasFlag(WriteOptions.WriteWithoutResponse))
            {
                this.properties |= GattCharacteristicProperties.WriteWithoutResponse;
            }

            return(this);
        }
Ejemplo n.º 31
0
 public Task<WriteResult> Update(PreparedQueryDefinition query, WriteOptions q)
 {
     return _client.Put(string.Format("/v1/query/{0}", query.ID), query, q).Execute();
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Write is used to do a PUT request against an endpoint and serialize/deserialized using the standard Consul conventions.
 /// </summary>
 /// <param name="endpoint">The URL endpoint to access</param>
 /// <param name="obj">The object to serialize and send to the endpoint. Must be able to be JSON serialized, or be an object of type byte[], which is sent without serialzation.</param>
 /// <param name="q">Custom write options</param>
 /// <returns>The data returned by the custom endpoint in response to the write request</returns>
 public async Task<WriteResult<dynamic>> Write(string endpoint, object obj, WriteOptions q)
 {
     return await _client.Put<object, dynamic>(endpoint, obj, q).Execute().ConfigureAwait(false);
 }
Ejemplo n.º 33
0
        public async Task <WriteResult> Delete(string queryID, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.DeleteReturning <string>(string.Format("/v1/query/{0}", queryID), q).Execute(ct);

            return(new WriteResult(res));
        }
Ejemplo n.º 34
0
        protected virtual DbOptions BuildOptions(IDbConfig dbConfig)
        {
            _maxThisDbSize = 0;
            BlockBasedTableOptions tableOptions = new BlockBasedTableOptions();

            tableOptions.SetBlockSize(16 * 1024);
            tableOptions.SetPinL0FilterAndIndexBlocksInCache(true);
            tableOptions.SetCacheIndexAndFilterBlocks(ReadConfig <bool>(dbConfig, nameof(dbConfig.CacheIndexAndFilterBlocks)));

            tableOptions.SetFilterPolicy(BloomFilterPolicy.Create(10, true));
            tableOptions.SetFormatVersion(2);

            ulong blockCacheSize = ReadConfig <ulong>(dbConfig, nameof(dbConfig.BlockCacheSize));

            _maxThisDbSize += (long)blockCacheSize;

            IntPtr cache = Native.Instance.rocksdb_cache_create_lru(new UIntPtr(blockCacheSize));

            tableOptions.SetBlockCache(cache);

            DbOptions options = new DbOptions();

            options.SetCreateIfMissing(true);
            options.SetAdviseRandomOnOpen(true);
            options.OptimizeForPointLookup(blockCacheSize); // I guess this should be the one option controlled by the DB size property - bind it to LRU cache size
            //options.SetCompression(CompressionTypeEnum.rocksdb_snappy_compression);
            //options.SetLevelCompactionDynamicLevelBytes(true);

            /*
             * Multi-Threaded Compactions
             * Compactions are needed to remove multiple copies of the same key that may occur if an application overwrites an existing key. Compactions also process deletions of keys. Compactions may occur in multiple threads if configured appropriately.
             * The entire database is stored in a set of sstfiles. When a memtable is full, its content is written out to a file in Level-0 (L0). RocksDB removes duplicate and overwritten keys in the memtable when it is flushed to a file in L0. Some files are periodically read in and merged to form larger files - this is called compaction.
             * The overall write throughput of an LSM database directly depends on the speed at which compactions can occur, especially when the data is stored in fast storage like SSD or RAM. RocksDB may be configured to issue concurrent compaction requests from multiple threads. It is observed that sustained write rates may increase by as much as a factor of 10 with multi-threaded compaction when the database is on SSDs, as compared to single-threaded compactions.
             * TKS: Observed 500MB/s compared to ~100MB/s between multithreaded and single thread compactions on my machine (processor count is returning 12 for 6 cores with hyperthreading)
             * TKS: CPU goes to insane 30% usage on idle - compacting only app
             */
            options.SetMaxBackgroundCompactions(Environment.ProcessorCount);

            //options.SetMaxOpenFiles(32);
            ulong writeBufferSize = ReadConfig <ulong>(dbConfig, nameof(dbConfig.WriteBufferSize));

            options.SetWriteBufferSize(writeBufferSize);
            int writeBufferNumber = (int)ReadConfig <uint>(dbConfig, nameof(dbConfig.WriteBufferNumber));

            options.SetMaxWriteBufferNumber(writeBufferNumber);
            options.SetMinWriteBufferNumberToMerge(2);

            lock (DbsByPath)
            {
                _maxThisDbSize += (long)writeBufferSize * writeBufferNumber;
                Interlocked.Add(ref _maxRocksSize, _maxThisDbSize);
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Expected max memory footprint of {Name} DB is {_maxThisDbSize / 1024 / 1024}MB ({writeBufferNumber} * {writeBufferSize / 1024 / 1024}MB + {blockCacheSize / 1024 / 1024}MB)");
                }
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Total max DB footprint so far is {_maxRocksSize / 1024 / 1024}MB");
                }
                ThisNodeInfo.AddInfo("DB mem est   :", $"{_maxRocksSize / 1024 / 1024}MB");
            }

            options.SetBlockBasedTableFactory(tableOptions);

            options.SetMaxBackgroundFlushes(Environment.ProcessorCount);
            options.IncreaseParallelism(Environment.ProcessorCount);
            options.SetRecycleLogFileNum(dbConfig.RecycleLogFileNum); // potential optimization for reusing allocated log files

//            options.SetLevelCompactionDynamicLevelBytes(true); // only switch on on empty DBs
            WriteOptions = new WriteOptions();
            WriteOptions.SetSync(dbConfig.WriteAheadLogSync); // potential fix for corruption on hard process termination, may cause performance degradation

            return(options);
        }
Ejemplo n.º 35
0
        public static async Task Example(InfluxDBClient influxDB)
        {
            var organizationClient = influxDB.GetOrganizationsApi();

            var medicalGMBH = await organizationClient
                              .CreateOrganizationAsync("Medical Corp " +
                                                       DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff",
                                                                                CultureInfo.InvariantCulture));


            //
            // Create New Bucket with retention 1h
            //
            var temperatureBucket = await influxDB.GetBucketsApi().CreateBucketAsync("temperature-sensors", medicalGMBH.Id);

            //
            // Add Permissions to read and write to the Bucket
            //
            var resource = new PermissionResource
            {
                Type = PermissionResource.TypeEnum.Buckets, OrgID = medicalGMBH.Id, Id = temperatureBucket.Id
            };
            var readBucket = new Permission
            {
                Resource = resource,
                Action   = Permission.ActionEnum.Read
            };

            var writeBucket = new Permission
            {
                Resource = resource,
                Action   = Permission.ActionEnum.Write
            };

            var authorization = await influxDB.GetAuthorizationsApi()
                                .CreateAuthorizationAsync(medicalGMBH, new List <Permission> {
                readBucket, writeBucket
            });

            Console.WriteLine($"The token to write to temperature-sensors bucket is: {authorization.Token}");

            influxDB.Dispose();

            //
            // Create new client with specified authorization token
            //

            influxDB = InfluxDBClientFactory.Create("http://localhost:8086", authorization.Token);

            var writeOptions = WriteOptions
                               .CreateNew()
                               .BatchSize(5000)
                               .FlushInterval(1000)
                               .JitterInterval(1000)
                               .RetryInterval(5000)
                               .Build();

            //
            // Write data
            //
            using (var writeClient = influxDB.GetWriteApi(writeOptions))
            {
                //
                // Write by POCO
                //
                var temperature = new Temperature {
                    Location = "south", Value = 62D, Time = DateTime.UtcNow
                };
                writeClient.WriteMeasurement("temperature-sensors", medicalGMBH.Id, WritePrecision.Ns, temperature);

                //
                // Write by Point
                //
                var point = PointData.Measurement("temperature")
                            .Tag("location", "west")
                            .Field("value", 55D)
                            .Timestamp(DateTime.UtcNow.AddSeconds(-10), WritePrecision.Ns);
                writeClient.WritePoint("temperature-sensors", medicalGMBH.Id, point);

                //
                // Write by LineProtocol
                //
                var record = "temperature,location=north value=60.0";
                writeClient.WriteRecord("temperature-sensors", medicalGMBH.Id, WritePrecision.Ns, record);

                writeClient.Flush();
                Thread.Sleep(2000);
            }

            //
            // Read data
            //
            var fluxTables = await influxDB.GetQueryApi().QueryAsync("from(bucket:\"temperature-sensors\") |> range(start: 0)", medicalGMBH.Id);

            fluxTables.ForEach(fluxTable =>
            {
                var fluxRecords = fluxTable.Records;
                fluxRecords.ForEach(fluxRecord =>
                {
                    Console.WriteLine($"{fluxRecord.GetTime()}: {fluxRecord.GetValue()}");
                });
            });

            //
            // Delete data
            //
            await influxDB.GetDeleteApi().Delete(DateTime.UtcNow.AddMinutes(-1), DateTime.Now, "", temperatureBucket, medicalGMBH);

            influxDB.Dispose();
        }
Ejemplo n.º 36
0
        public ExportStatus Export(FScene s, string filename)
        {
            List <WriteMesh> vMeshes = new List <WriteMesh>();

            if (WriteFaceGroups)
            {
                throw new Exception("SceneMeshExporter.Export: writing face groups has not yet been implemented!");
            }

            foreach (SceneObject so in s.SceneObjects)
            {
                if (so.IsTemporary)
                {
                    continue;
                }

                SimpleMesh m = new SimpleMesh();
                m.Initialize(WriteNormals, WriteVertexColors, WriteUVs, WriteFaceGroups);
                int groupCounter = 1;

                GameObject rootgo = so.RootGameObject;

                int[] vertexMap = new int[2048];
                foreach (GameObject childgo in rootgo.Children())
                {
                    MeshFilter filter = childgo.GetComponent <MeshFilter>();
                    if (filter == null || filter.mesh == null)
                    {
                        continue;
                    }
                    if (GOFilterF != null && GOFilterF(so, childgo) == false)
                    {
                        continue;
                    }

                    Mesh      curMesh  = filter.sharedMesh;
                    Vector3[] vertices = curMesh.vertices;
                    Vector3[] normals  = (WriteNormals) ? curMesh.normals : null;
                    Color[]   colors   = (WriteVertexColors) ? curMesh.colors : null;
                    Vector2[] uvs      = (WriteUVs) ? curMesh.uv : null;

                    if (vertexMap.Length < curMesh.vertexCount)
                    {
                        vertexMap = new int[curMesh.vertexCount * 2];
                    }

                    for (int i = 0; i < curMesh.vertexCount; ++i)
                    {
                        NewVertexInfo vi = new NewVertexInfo();
                        vi.bHaveN = WriteNormals; vi.bHaveC = WriteVertexColors; vi.bHaveUV = WriteUVs;

                        Vector3 v = vertices[i];
                        // local to world
                        v = filter.gameObject.transform.TransformPoint(v);
                        // world back to scene
                        vi.v = UnityUtil.SwapLeftRight(s.RootGameObject.transform.InverseTransformPoint(v));

                        if (WriteNormals)
                        {
                            Vector3 n = normals[i];
                            n    = filter.gameObject.transform.TransformDirection(n);
                            vi.n = UnityUtil.SwapLeftRight(s.RootGameObject.transform.InverseTransformDirection(n));
                        }
                        if (WriteVertexColors)
                        {
                            vi.c = colors[i];
                        }
                        if (WriteUVs)
                        {
                            vi.uv = uvs[i];
                        }

                        vertexMap[i] = m.AppendVertex(vi);
                    }

                    int[] triangles  = curMesh.triangles;
                    int   nTriangles = triangles.Length / 3;
                    for (int i = 0; i < nTriangles; ++i)
                    {
                        int a = vertexMap[triangles[3 * i]];
                        int b = vertexMap[triangles[3 * i + 1]];
                        int c = vertexMap[triangles[3 * i + 2]];
                        m.AppendTriangle(a, c, b, groupCounter);  // TRI ORIENTATION IS REVERSED HERE!!
                    }
                    groupCounter++;
                }

                vMeshes.Add(new WriteMesh(m, so.Name));
            }


            if (WriteInBackgroundThreads)
            {
                ExportStatus status = new ExportStatus()
                {
                    Exporter = this, IsComputing = true
                };
                WriteOptions useOptions = Options;
                useOptions.ProgressFunc = (cur, max) => {
                    status.Progress    = cur;
                    status.MaxProgress = max;
                };
                BackgroundWriteThread t = new BackgroundWriteThread()
                {
                    Meshes      = vMeshes, options = useOptions, Filename = filename,
                    CompletionF = (result) => {
                        LastWriteStatus         = result.code;
                        LastErrorMessage        = result.message;
                        status.LastErrorMessage = result.message;
                        status.Ok          = (result.code == IOCode.Ok);
                        status.IsComputing = false;
                    }
                };
                t.Start();
                return(status);
            }
            else
            {
                IOWriteResult result = StandardMeshWriter.WriteFile(filename, vMeshes, Options);
                LastWriteStatus  = result.code;
                LastErrorMessage = result.message;
                return(new ExportStatus()
                {
                    Exporter = this, IsComputing = false,
                    Ok = (result.code == IOCode.Ok),
                    LastErrorMessage = result.message
                });
            }
        }
Ejemplo n.º 37
0
 /// <summary>
 /// Writes a message to the stream, if there is enough space in the buffer and <see cref="WriteCompleteAsync"/>
 /// hasn't already been called.
 /// </summary>
 /// <param name="message">The message to write.</param>
 /// <param name="options">The write options to use for this message.</param>
 /// <returns><c>null</c> if the message queue is full or the stream has already been completed.</returns>
 public Task TryWriteAsync(T message, WriteOptions options) => WriteAsyncImpl(message, options, true, false);
Ejemplo n.º 38
0
 /// <summary>
 /// Deregister an existing catalog item
 /// </summary>
 /// <param name="reg">A catalog deregistration</param>
 /// <param name="q">Customized write options</param>
 /// <returns>An empty write result</returns>
 public async Task<WriteResult> Deregister(CatalogDeregistration reg, WriteOptions q)
 {
     return await _client.Put("/v1/catalog/deregister", reg, q).Execute().ConfigureAwait(false);
 }
Ejemplo n.º 39
0
        public void Client_SetWriteOptions()
        {
            var client = new Client();

            var opts = new WriteOptions()
            {
                Datacenter = "foo",
                Token = "12345"
            };

            var request = client.CreateWrite("/v1/kv/foo", opts);
            try
            {
                request.Execute();
            }
            catch (Exception)
            {
                // ignored
            }

            Assert.AreEqual("foo", request.Params["dc"]);
            Assert.AreEqual("12345", request.Params["token"]);
        }
Ejemplo n.º 40
0
 /// <summary>
 /// Register a new catalog item
 /// </summary>
 /// <param name="reg">A catalog registration</param>
 /// <param name="q">Customized write options</param>
 /// <returns>An empty write result</returns>
 public WriteResult Register(CatalogRegistration reg, WriteOptions q)
 {
     return
         _client.CreateInWrite<CatalogRegistration>("/v1/catalog/register", reg, q).Execute();
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Deregister an existing catalog item
 /// </summary>
 /// <param name="reg">A catalog deregistration</param>
 /// <param name="q">Customized write options</param>
 /// <returns>An empty write result</returns>
 public WriteResult<object> Deregister(CatalogDeregistration reg, WriteOptions q)
 {
     return _client.CreateWriteRequest<CatalogDeregistration, object>("/v1/catalog/deregister", reg, q)
                 .Execute();
 }
Ejemplo n.º 42
0
        public IGattCharacteristicBuilder SetWrite(Func <WriteRequest, GattState> onWrite, WriteOptions options = WriteOptions.Write)
        {
            this.onWrite = onWrite;
            if (options.HasFlag(WriteOptions.EncryptionRequired))
            {
                this.permissions = GattPermission.WriteEncrypted;
            }
            else if (options.HasFlag(WriteOptions.AuthenticatedSignedWrites))
            {
                this.properties  |= GattProperty.SignedWrite;
                this.permissions |= GattPermission.WriteSigned;
            }
            else
            {
                this.properties  |= GattProperty.Write;
                this.permissions |= GattPermission.Write;
            }
            if (options.HasFlag(WriteOptions.WriteWithoutResponse))
            {
                this.properties |= GattProperty.WriteNoResponse;
            }

            return(this);
        }
Ejemplo n.º 43
0
 void WriteIndentations(WriteOptions options)
 {
     if (options != WriteOptions.NoIndent)
     {
         for (int i = indent_level; i > 0; i--)
             sw.Write("    ");
     }
 }
 public new void SetUp()
 {
     _influxDbClient = InfluxDBClientFactory.Create(MockServerUrl, "token");
     _writeApi       = _influxDbClient.GetWriteApi(WriteOptions.CreateNew().RetryInterval(1_000).Build());
 }
Ejemplo n.º 45
0
 public void Write(WriteOptions options, string format, params object[] args)
 {
     Write(options, String.Format(format, args));
 }
Ejemplo n.º 46
0
        public IGattCharacteristicBuilder SetWrite(Func <WriteRequest, GattState> request, WriteOptions options = WriteOptions.Write)
        {
            if (options.HasFlag(GattCharacteristicProperties.Write))
            {
                this.properties |= GattCharacteristicProperties.Write;
            }

            if (options.HasFlag(GattCharacteristicProperties.WriteWithoutResponse))
            {
                this.properties |= GattCharacteristicProperties.WriteWithoutResponse;
            }

            return(this);
        }
Ejemplo n.º 47
0
 /// <summary>
 /// Delete is used to delete a single key.
 /// </summary>
 /// <param name="key">The key name to delete</param>
 /// <param name="q">Customized write options</param>
 /// <returns>A write result indicating if the delete attempt succeeded</returns>
 public async Task<WriteResult<bool>> Delete(string key, WriteOptions q)
 {
     KVPair.ValidatePath(key);
     return await _client.Delete<bool>(string.Format("/v1/kv/{0}", key), q).Execute().ConfigureAwait(false);
 }
Ejemplo n.º 48
0
 /// <inheritdoc/>
 public override Task WriteAsync(StreamingRecognizeRequest message, WriteOptions options) =>
 _writeBuffer.WriteAsync(ModifyRequest(message), options);
Ejemplo n.º 49
0
 /// <summary>
 /// DeleteTree is used to delete all keys under a prefix
 /// </summary>
 /// <param name="prefix">The key prefix to delete from</param>
 /// <param name="q">Customized write options</param>
 /// <returns>A write result indicating if the recursiv edelete attempt succeeded</returns>
 public async Task<WriteResult<bool>> DeleteTree(string prefix, WriteOptions q)
 {
     KVPair.ValidatePath(prefix);
     var req = _client.Delete<bool>(string.Format("/v1/kv/{0}", prefix), q);
     req.Params.Add("recurse", string.Empty);
     return await req.Execute().ConfigureAwait(false);
 }
Ejemplo n.º 50
0
        public void Client_SetWriteOptions()
        {
            var c = MakeClient();

            var q = new WriteOptions()
            {
                Datacenter = "foo",
                Token = "12345"
            };

            var r = c.CreateWriteRequest<object, object>("/v1/kv/foo", q);
            try
            {
                r.Execute();
            }
            catch (Exception)
            {
                // ignored
            }

            Assert.AreEqual(r.Params["dc"], "foo");
            Assert.AreEqual(r.Params["token"], "12345");
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Write is used to do a PUT request against an endpoint and serialize/deserialized using the standard Consul conventions.
 /// </summary>
 /// <param name="endpoint">The URL endpoint to access</param>
 /// <param name="obj">The object to serialize and send to the endpoint. Must be able to be JSON serialized, or be an object of type byte[], which is sent without serialzation.</param>
 /// <param name="q">Custom write options</param>
 /// <returns>The data returned by the custom endpoint in response to the write request</returns>
 public WriteResult<dynamic> Write(string endpoint, object obj, WriteOptions q)
 {
     return Client.CreateWriteRequest<object, dynamic>(endpoint, obj, q).Execute();
 }
Ejemplo n.º 52
0
        private const int HeaderSize           = MessageDelimiterSize + 1; // message length + compression flag

        public static Task WriteMessageAsync <TResponse>(this PipeWriter pipeWriter, TResponse response, Func <TResponse, byte[]> serializer, WriteOptions writeOptions)
        {
            var responsePayload = serializer(response);

            // Flush messages unless WriteOptions.Flags has BufferHint set
            var flush = ((writeOptions?.Flags ?? default) & WriteFlags.BufferHint) != WriteFlags.BufferHint;

            return(pipeWriter.WriteMessageAsync(responsePayload, flush));
        }
Ejemplo n.º 53
0
 public async Task<WriteResult> Delete(string queryID, WriteOptions q)
 {
     return await _client.Delete<string>(string.Format("/v1/query/{0}", queryID), q).Execute().ConfigureAwait(false);
 }
Ejemplo n.º 54
0
 /// <summary>
 /// Deregister an existing catalog item
 /// </summary>
 /// <param name="reg">A catalog deregistration</param>
 /// <param name="q">Customized write options</param>
 /// <returns>An empty write result</returns>
 public Task<WriteResult> Deregister(CatalogDeregistration reg, WriteOptions q)
 {
     return _client.Put("/v1/catalog/deregister", reg, q).Execute();
 }
Ejemplo n.º 55
0
 private static Task WriteRangeInTask(string dbName, int offset, int limit)
 {
     return Task.Run(() =>
     {
         var writeOpts = new WriteOptions();
         using (var db = new DB(new Options { CreateIfMissing = true }, dbName))
         {
             for (int i = offset; i < limit; i++)
             {
                 db.Put(writeOpts, Slice.FromString($"key::{i,20:D20}"), Slice.FromString($"{i,32}"));
             }
         }
     });
 }
Ejemplo n.º 56
0
Archivo: KV.cs Proyecto: stulzq/NConsul
 /// <summary>
 /// Delete is used to delete a single key.
 /// </summary>
 /// <param name="key">The key name to delete</param>
 /// <param name="q">Customized write options</param>
 /// <returns>A write result indicating if the delete attempt succeeded</returns>
 public Task <WriteResult <bool> > Delete(string key, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     KVPair.ValidatePath(key);
     return(_client.DeleteReturning <bool>(string.Format("/v1/kv/{0}", key.TrimStart('/')), q).Execute(ct));
 }
Ejemplo n.º 57
0
 public async Task<WriteResult> Delete(string queryID, WriteOptions q)
 {
     var res = await _client.Delete<string>(string.Format("/v1/query/{0}", queryID), q).Execute();
     return new WriteResult(res);
 }
Ejemplo n.º 58
0
        public async Task <WriteResult <string> > Create(PreparedQueryDefinition query, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.Post <PreparedQueryDefinition, PreparedQueryCreationResult>("/v1/query", query, q).Execute(ct).ConfigureAwait(false);

            return(new WriteResult <string>(res, res.Response.ID));
        }
 internal Container(Guid id, DateTimeOffset initiatedTime, int totalNodesCount, WriteOptions options)
 {
     this.Id              = id;
     this.InitiatedTime   = initiatedTime;
     this.Options         = options;
     this.TotalNodesCount = totalNodesCount;
     this.CompletionEvent = new ManualResetEvent(false);
     this.CompletionTimes = new Dictionary <string, int>();
     this.WaitingForAck   = new HashSet <string>();
     if (options != null)
     {
         this.MinimumNodesRequired = (int)Math.Ceiling((double)this.TotalNodesCount * options.PercentageOfNodesToSucceed / 100.0);
         if (options.WaitForNodes != null)
         {
             EnumerableEx.ForEach <string>(options.WaitForNodes, delegate(string node)
             {
                 this.WaitingForAck.Add(node);
             });
         }
     }
 }
Ejemplo n.º 60
0
 /// <summary>
 /// Update is used to update the rules of an existing token
 /// </summary>
 /// <param name="acl">The ACL entry to update</param>
 /// <param name="q">Customized write options</param>
 /// <returns>An empty write result</returns>
 public Task <WriteResult> Update(ACLEntry acl, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put("/v1/acl/update", acl, q).Execute(ct));
 }