├── test ├── .gitignore ├── data_test │ ├── BasicScalarTest.cs │ ├── BasicVectorTest.cs │ └── BasicIotAnyVectorTest.cs ├── streaming │ ├── cep_test │ │ ├── EventClientTest.cs │ │ └── EventSenderTest.cs │ ├── stream_test │ │ ├── ThreadedClientTest.cs │ │ └── ThreadPoolClientTest.cs │ └── streamReverse_test │ │ ├── ThreadedClientReverseTest.cs │ │ ├── ThreadPoolClientReverseTest.cs │ │ └── AbstractClientTest.cs ├── config.runsettings ├── route_test │ └── MultithreadTableWriter_test.cs ├── compatibility_test │ ├── stream_test │ │ ├── ThreadedClientTest.cs │ │ └── ThreadPoolClientTest.cs │ ├── io_test │ │ └── BigEndianDataOutputStream_test.cs │ └── ha_test │ │ └── ha_test.cs ├── packages.config ├── sysData.ini ├── Properties │ └── AssemblyInfo.cs ├── App.config ├── MyConfigReader.cs ├── dolphindb_csharpapi_net_core_test.csproj ├── io_test │ └── BigEndianDataOutputStream_test.cs └── ha_test │ └── ha_test.cs ├── src ├── io │ ├── ProgressListener.cs │ ├── ExtendedDataInput.cs │ ├── Double2.cs │ ├── ExtendedDataOutput.cs │ ├── BigEndianDataInputStream.cs │ ├── LittleEndianDataInputStream.cs │ └── Long2.cs ├── data │ ├── ISet.cs │ ├── IDictionary.cs │ ├── IScalar.cs │ ├── ITable.cs │ ├── IEntityFactory.cs │ ├── IMatrix.cs │ ├── HashMapHelperClass.cs │ ├── BasicSystemEntity.cs │ ├── IVector.cs │ ├── AbstractEntity.cs │ ├── BasicTimestampMatrix.cs │ ├── BasicTimeMatrix.cs │ ├── BasicMonthMatrix.cs │ ├── BasicDateMatrix.cs │ ├── BasicDateHourMatrix.cs │ ├── BasicDateTimeMatrix.cs │ ├── BasicNanoTimeMatrix.cs │ ├── BasicSecondMatrix.cs │ ├── BasicMinuteMatrix.cs │ ├── BasicNanoTimestampMatrix.cs │ ├── BasicUuidVector.cs │ ├── BasicIPAddrVector.cs │ ├── Void.cs │ ├── BasicDate.cs │ ├── BasicPointVector.cs │ ├── BasicNanoTimestamp.cs │ ├── BasicDateHour.cs │ ├── BasicDateTime.cs │ ├── BasicSecond.cs │ ├── BasicComplexVector.cs │ ├── BasicTimestamp.cs │ ├── BasicMonth.cs │ ├── BasicUuid.cs │ ├── BasicTime.cs │ ├── BasicMinute.cs │ ├── BasicComplexMatrix.cs │ ├── BasicNanoTime.cs │ ├── SymbolBaseCollection.cs │ ├── AbstractScalar.cs │ ├── BasicIntMatrix.cs │ ├── BasicShortMatrix.cs │ ├── BasicFloatMatrix.cs │ ├── BasicBooleanMatrix.cs │ ├── BasicDoubleMatrix.cs │ ├── BasicLongMatrix.cs │ ├── Number.cs │ ├── BasicByteMatrix.cs │ ├── BasicShort.cs │ ├── BasicStringMatrix.cs │ ├── BasicByte.cs │ ├── BasicBoolean.cs │ ├── BasicFloat.cs │ ├── BasicPoint.cs │ ├── BasicComplex.cs │ ├── BasicInt.cs │ ├── BasicDouble.cs │ ├── BasicLong.cs │ └── BasicVoidVector.cs ├── route │ ├── Callback.cs │ ├── Domain.cs │ ├── DBVersion.cs │ ├── DomainFactory.cs │ ├── ErrorCodeInfo.cs │ ├── HashDomain.cs │ ├── ValueDomain.cs │ ├── RangeDomain.cs │ ├── autoFitTableAppender.cs │ └── ListDomain.cs ├── streaming │ ├── MessageHandler.cs │ ├── cep │ │ ├── EventMessageHandler.cs │ │ └── EventSender.cs │ ├── IMessage.cs │ ├── QueueManager.cs │ ├── BasicMessage.cs │ └── TopicPoller.cs ├── compression │ ├── Encoder.cs │ ├── LZ4 │ │ ├── ILZ4Compressor.cs │ │ ├── LZ4CompressorFactory.cs │ │ ├── LZ4DecompressorFactory.cs │ │ ├── ILZ4Decompressor.cs │ │ ├── LZ4Util.cs │ │ └── License.txt │ ├── Decoder.cs │ ├── DecoderFactory.cs │ ├── EncoderFactory.cs │ ├── AbstractDecoder.cs │ ├── VectorDecompressor.cs │ ├── LZ4Decoder.cs │ └── LZ4Encoder.cs ├── IDBTask.cs ├── IDBConnectionPool.cs ├── ServerExceptionUtils.cs ├── Properties │ └── AssemblyInfo.cs └── BasicDBTask.cs ├── dolphindb_csharpapi_net_core.csproj ├── .gitignore ├── dolphindb_csharpapi_net_core.sln └── dolphindb_csharpapi.sln /test/.gitignore: -------------------------------------------------------------------------------- 1 | /*.user 2 | -------------------------------------------------------------------------------- /test/data_test/BasicScalarTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/data_test/BasicScalarTest.cs -------------------------------------------------------------------------------- /test/data_test/BasicVectorTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/data_test/BasicVectorTest.cs -------------------------------------------------------------------------------- /test/data_test/BasicIotAnyVectorTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/data_test/BasicIotAnyVectorTest.cs -------------------------------------------------------------------------------- /test/streaming/cep_test/EventClientTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/streaming/cep_test/EventClientTest.cs -------------------------------------------------------------------------------- /test/streaming/cep_test/EventSenderTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/streaming/cep_test/EventSenderTest.cs -------------------------------------------------------------------------------- /test/config.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | -------------------------------------------------------------------------------- /test/route_test/MultithreadTableWriter_test.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/route_test/MultithreadTableWriter_test.cs -------------------------------------------------------------------------------- /test/streaming/stream_test/ThreadedClientTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/streaming/stream_test/ThreadedClientTest.cs -------------------------------------------------------------------------------- /test/streaming/stream_test/ThreadPoolClientTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/streaming/stream_test/ThreadPoolClientTest.cs -------------------------------------------------------------------------------- /test/compatibility_test/stream_test/ThreadedClientTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/compatibility_test/stream_test/ThreadedClientTest.cs -------------------------------------------------------------------------------- /src/io/ProgressListener.cs: -------------------------------------------------------------------------------- 1 | namespace dolphindb.io 2 | { 3 | 4 | public interface ProgressListener 5 | { 6 | void progress(string message); 7 | } 8 | 9 | } -------------------------------------------------------------------------------- /test/compatibility_test/stream_test/ThreadPoolClientTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/compatibility_test/stream_test/ThreadPoolClientTest.cs -------------------------------------------------------------------------------- /test/streaming/streamReverse_test/ThreadedClientReverseTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/streaming/streamReverse_test/ThreadedClientReverseTest.cs -------------------------------------------------------------------------------- /test/streaming/streamReverse_test/ThreadPoolClientReverseTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/HEAD/test/streaming/streamReverse_test/ThreadPoolClientReverseTest.cs -------------------------------------------------------------------------------- /src/data/ISet.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | 3 | namespace dolphindb.data 4 | { 5 | public interface ISet : IEntity 6 | { 7 | bool contains(IScalar key); 8 | bool add(IScalar key); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /src/data/IDictionary.cs: -------------------------------------------------------------------------------- 1 | namespace dolphindb.data 2 | { 3 | 4 | public interface IDictionary : IEntity 5 | { 6 | DATA_TYPE KeyDataType { get; } 7 | IEntity get(IScalar key); 8 | bool put(IScalar key, IEntity value); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /test/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/route/Callback.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace dolphindb_csharpapi_net_core.src.route 7 | { 8 | public interface Callback 9 | { 10 | void writeCompletion(ITable callbackTable); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/streaming/MessageHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace dolphindb.streaming 7 | { 8 | public interface MessageHandler 9 | { 10 | void doEvent(IMessage msg); 11 | void batchHandler(List msgs); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/streaming/cep/EventMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace dolphindb.streaming.cep 8 | { 9 | public interface EventMessageHandler { 10 | 11 | void doEvent(string eventType, List attribute); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/route/Domain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.data; 6 | 7 | namespace dolphindb.route 8 | { 9 | public interface Domain 10 | { 11 | List getPartitionKeys(IVector partitionCol); 12 | int getPartitionKey(IScalar partitionCol); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/sysData.ini: -------------------------------------------------------------------------------- 1 | #name+null+value 2 | SERVER 192.168.1.167 3 | PORT 18921 4 | USER admin 5 | PASSWORD 123456 6 | NODE1_HOST 192.168.1.167 7 | NODE1_PORT 18921 8 | HASTREAM_GROUP1 192.168.1.167:18921 9 | HASTREAM_GROUP2 192.168.1.167:18922 10 | HASTREAM_GROUP3 192.168.1.167:18923 11 | HASTREAM_GROUPID 3 12 | LOCALHOST 192.168.0.52 13 | LOCALPORT 18221 14 | SUB_FLAG 0 15 | -------------------------------------------------------------------------------- /src/compression/Encoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.data; 6 | 7 | namespace dolphindb.compression 8 | { 9 | interface Encoder 10 | { 11 | 12 | int compress(AbstractVector input, int elementCount, int unitLength, int maxCompressedLength, ByteBuffer output); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/data/IScalar.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | 3 | namespace dolphindb.data 4 | { 5 | 6 | public interface IScalar : IEntity 7 | { 8 | bool isNull(); 9 | void setNull(); 10 | void setObject(object value); 11 | Number getNumber(); 12 | object getTemporal(); 13 | int hashBucket(int buckets); 14 | int getScale(); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /src/compression/LZ4/ILZ4Compressor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace LZ4Sharp 3 | { 4 | public interface ILZ4Compressor 5 | { 6 | int CalculateMaxCompressedLength(int uncompressedLength); 7 | byte[] Compress(byte[] source); 8 | int Compress(byte[] source, byte[] dest); 9 | int Compress(byte[] source, int srcOffset, int count, byte[] dest, int dstOffset); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/data/ITable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using dolphindb.io; 3 | 4 | namespace dolphindb.data 5 | { 6 | public interface ITable : IEntity 7 | { 8 | IVector getColumn(int index); 9 | IVector getColumn(string name); 10 | string getColumnName(int index); 11 | IList getColumnNames(); 12 | ITable getSubTable(int[] indices); 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /src/compression/Decoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.data; 6 | using dolphindb.io; 7 | using System.IO; 8 | namespace dolphindb.compression 9 | { 10 | public interface Decoder 11 | { 12 | ExtendedDataInput Decompress(ExtendedDataInput input, int length, int unitLength, int elementCount, int extra, bool isLittleEndian, int type, short scale); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/compression/LZ4/LZ4CompressorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace LZ4Sharp 7 | { 8 | public static class LZ4CompressorFactory 9 | { 10 | public static ILZ4Compressor CreateNew() 11 | { 12 | if (IntPtr.Size == 4) 13 | return new LZ4Compressor32(); 14 | return new LZ4Compressor64(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/compression/LZ4/LZ4DecompressorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace LZ4Sharp 7 | { 8 | public static class LZ4DecompressorFactory 9 | { 10 | public static ILZ4Decompressor CreateNew() 11 | { 12 | if (IntPtr.Size == 4) 13 | return new LZ4Decompressor32(); 14 | return new LZ4Decompressor64(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/streaming/IMessage.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace dolphindb.streaming 9 | { 10 | public interface IMessage 11 | { 12 | string getTopic(); 13 | long getOffset(); 14 | IEntity getEntity(int colIndex); 15 | T getValue(int colIndex); 16 | 17 | BasicTable getTable(); 18 | 19 | int size(); 20 | string getSym(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/data/IEntityFactory.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | 3 | namespace dolphindb.data 4 | { 5 | public interface IEntityFactory 6 | { 7 | IEntity createEntity(DATA_FORM form, DATA_TYPE type, ExtendedDataInput @in, bool extended); 8 | IMatrix createMatrixWithDefaultValue(DATA_TYPE type, int rows, int columns, int extra = -1); 9 | IVector createVectorWithDefaultValue(DATA_TYPE type, int size, int extra = -1); 10 | IVector createPairWithDefaultValue(DATA_TYPE type); 11 | IScalar createScalarWithDefaultValue(DATA_TYPE type); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /src/data/IMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | public interface IMatrix : IEntity 7 | { 8 | bool isNull(int row, int column); 9 | void setNull(int row, int column); 10 | IScalar getRowLabel(int row); 11 | IScalar getColumnLabel(int column); 12 | IScalar get(int row, int column); 13 | IVector getRowLabels(); 14 | IVector getColumnLabels(); 15 | bool hasRowLabel(); 16 | bool hasColumnLabel(); 17 | Type getElementClass(); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /src/compression/DecoderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace dolphindb.compression 7 | { 8 | class DecoderFactory 9 | { 10 | private DecoderFactory() { } 11 | 12 | public static Decoder get(int method) 13 | { 14 | if (method == 1) 15 | return (Decoder)new LZ4Decoder(); 16 | else if (method == 2) 17 | return new DeltaOfDeltaDecoder(); 18 | else 19 | throw new InvalidOperationException(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /dolphindb_csharpapi_net_core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | True 6 | false 7 | dolphindb_csharpapi 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/IDBTask.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------------- 2 | // Copyright © 2021 DolphinDB Inc. 3 | // Date : 2021.01.21 4 | // Author : zhikun.luo 5 | //------------------------------------------------------------------------------------------- 6 | 7 | using dolphindb.data; 8 | namespace dolphindb 9 | { 10 | public interface IDBTask 11 | { 12 | void setDBConnection(DBConnection conn); 13 | IEntity call(); 14 | IEntity getResults(); 15 | string getErrorMsg(); 16 | bool isSuccessful(); 17 | bool isFinished(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/compression/EncoderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.compression; 6 | 7 | namespace dolphindb.compression 8 | { 9 | class EncoderFactory 10 | { 11 | private EncoderFactory() { } 12 | 13 | public static Encoder Get(int method) 14 | { 15 | if (method == 1) 16 | return (Encoder)new LZ4Encoder(); 17 | else if (method == 2) 18 | return (Encoder)new DeltaOfDeltaEncoder(); 19 | throw new InvalidOperationException(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/data/HashMapHelperClass.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | // internal static class HashMapHelperClass 3 | // { 4 | // internal static HashSet> SetOfKeyValuePairs(this IDictionary dictionary) 5 | // { 6 | // HashSet> entries = new HashSet>(); 7 | // foreach (KeyValuePair keyValuePair in dictionary) 8 | // { 9 | // entries.Add(keyValuePair); 10 | // } 11 | // return entries; 12 | // } 13 | 14 | // internal static TValue GetValueOrNull(this IDictionary dictionary, TKey key) 15 | // { 16 | // TValue ret; 17 | // dictionary.TryGetValue(key, out ret); 18 | // return ret; 19 | // } 20 | // } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.cache 3 | .idea 4 | .idea/* 5 | *.pdb 6 | 7 | *.dll 8 | 9 | *.props 10 | 11 | *.targets 12 | packages 13 | obj/ 14 | bin/ 15 | *.dll 16 | *.pdb 17 | *.sqlite 18 | .vs/dolphindb_csharpapi/v15/.suo 19 | *.pdb 20 | *.dll 21 | .vs/dolphindb_csharpapi/v15/.suo 22 | /WindowsFormsApp1 23 | .vs/dolphindb_csharpapi/v15/Browse.VC.db 24 | .vs/dolphindb_csharpapi/v15/Server/ 25 | .vs/dolphindb_csharpapi/v15/ipch/ 26 | /.idea 27 | /.vs 28 | /dolphindb_dataAppender 29 | /WindowsFormsApp1 30 | /dolphindb_csharpapi_test/SupWin.cs 31 | /dolphindb_csharpapi/*.user 32 | /dolphindb_csharpapi/*.user 33 | test/SupWin.cs 34 | .vscode/launch.json 35 | examples/HAWritingData.cs 36 | longTimeTask/Properties/AssemblyInfo.cs 37 | longTimeTask/Program.cs 38 | longTimeTask/longTimeTask.csproj 39 | -------------------------------------------------------------------------------- /test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | #if NETFRAMEWORK 6 | [assembly: AssemblyTitle("dolphindb_csharp_api_test")] 7 | [assembly: AssemblyDescription("")] 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("dolphindb_csharp_api_test")] 11 | [assembly: AssemblyCopyright("Copyright © 2018")] 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | 15 | [assembly: ComVisible(false)] 16 | 17 | [assembly: Guid("9297ef6f-e380-423b-ba64-fe2907226ff8")] 18 | 19 | // [assembly: AssemblyVersion("1.0.*")] 20 | [assembly: AssemblyVersion("1.0.0.0")] 21 | [assembly: AssemblyFileVersion("1.0.0.0")] 22 | #endif 23 | -------------------------------------------------------------------------------- /test/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/io/ExtendedDataInput.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace dolphindb.io 4 | { 5 | 6 | 7 | public interface ExtendedDataInput 8 | { 9 | bool isLittleEndian(); 10 | 11 | bool readBoolean(); 12 | 13 | byte readByte(); 14 | 15 | long readLong(); 16 | 17 | int readInt(); 18 | 19 | char readChar(); 20 | 21 | double readDouble(); 22 | 23 | float readFloat(); 24 | 25 | void readFully(byte[] arg0); 26 | 27 | void readFully(byte[] arg0, int arg1, int arg2); 28 | 29 | string readLine(); 30 | 31 | string readString(); 32 | 33 | short readShort(); 34 | 35 | int readUnsignedByte(); 36 | 37 | int skipBytes(int n); 38 | 39 | Long2 readLong2(); 40 | 41 | Double2 readDouble2(); 42 | 43 | //2021.01.19 cwj 44 | byte[] readBlob(); 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /src/IDBConnectionPool.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------------- 2 | // Copyright © 2021 DolphinDB Inc. 3 | // Date : 2021.01.21 4 | // Author : zhikun.luo 5 | //------------------------------------------------------------------------------------------- 6 | 7 | using dolphindb.data; 8 | using System.Collections.Generic; 9 | namespace dolphindb 10 | { 11 | public interface IDBConnectionPool 12 | { 13 | void execute(List tasks); 14 | void execute(IDBTask task); 15 | int getConnectionCount(); 16 | void shutdown(); 17 | void waitForThreadCompletion(); 18 | 19 | IEntity run(string function, IList arguments, int priority = 4, int parallelism = 64, bool clearMemory = false); 20 | 21 | IEntity run(string script, int priority = 4, int parallelism = 64, bool clearMemory = false); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/compression/LZ4/ILZ4Decompressor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace LZ4Sharp 3 | { 4 | public interface ILZ4Decompressor 5 | { 6 | unsafe int Decompress(byte* compressedBuffer, byte* decompressedBuffer, int compressedSize, int maxDecompressedSize); 7 | byte[] Decompress(byte[] compressed); 8 | int Decompress(byte[] compressed, byte[] decompressedBuffer); 9 | int Decompress(byte[] compressedBuffer, byte[] decompressedBuffer, int compressedSize); 10 | int Decompress(byte[] compressedBuffer, int compressedPosition, byte[] decompressedBuffer, int decompressedPosition, int compressedSize); 11 | unsafe int DecompressKnownSize(byte* compressed, byte* decompressedBuffer, int decompressedSize); 12 | void DecompressKnownSize(byte[] compressed, byte[] decompressed); 13 | int DecompressKnownSize(byte[] compressed, byte[] decompressedBuffer, int decompressedSize); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/ServerExceptionUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace dolphindb 7 | { 8 | // class ServerExceptionUtils 9 | // { 10 | // public static bool isNotLogin(string exMsg) 11 | // { 12 | // return exMsg.Contains(string.Format("<{0}>",ServerException.NotAuthenticated.ToString())); 13 | // } 14 | 15 | // public static Boolean isNotLeader(String exMsg) 16 | // { 17 | // if (exMsg == null) 18 | // return false; 19 | // return exMsg.IndexOf("") >= 0; 20 | // } 21 | 22 | // public static String newLeader(String exMsg) 23 | // { 24 | // return exMsg.Substring(11); 25 | // } 26 | // } 27 | 28 | // enum ServerException 29 | // { 30 | // NotAuthenticated, 31 | // NotLeader 32 | // } 33 | } 34 | -------------------------------------------------------------------------------- /src/data/BasicSystemEntity.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System.IO; 3 | 4 | namespace dolphindb.data 5 | { 6 | public class BasicSystemEntity : BasicString 7 | { 8 | private DATA_TYPE type; 9 | 10 | public BasicSystemEntity(ExtendedDataInput @in, DATA_TYPE type) : base("") 11 | { 12 | this.type = type; 13 | if (type == DATA_TYPE.DT_FUNCTIONDEF) 14 | { 15 | @in.readByte(); 16 | } 17 | base.setValue(@in.readString()); 18 | } 19 | 20 | public override DATA_CATEGORY getDataCategory() 21 | { 22 | return DATA_CATEGORY.SYSTEM; 23 | } 24 | 25 | public override DATA_TYPE getDataType() 26 | { 27 | return type; 28 | } 29 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 30 | { 31 | throw new IOException("System entity is not supposed to serialize."); 32 | } 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/data/IVector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | namespace dolphindb.data 5 | { 6 | 7 | public interface IVector : IEntity 8 | { 9 | bool isNull(int index); 10 | void setNull(int index); 11 | IScalar get(int index); 12 | IEntity getEntity(int index); 13 | void set(int index, IScalar value); 14 | Type getElementClass(); 15 | object getList(); 16 | void set(int index, string value); 17 | void add(object value); 18 | void addRange(object list); 19 | int hashBucket(int index, int buckets); 20 | IVector getSubVector(int[] indices); 21 | int asof(IScalar value); 22 | void append(IScalar value); 23 | void append(IVector value); 24 | } 25 | 26 | public static class Vector_Fields 27 | { 28 | public const int DISPLAY_ROWS = 10; 29 | public const int COMPRESS_LZ4 = 1; 30 | public const int COMPRESS_DELTA = 2; 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/compression/AbstractDecoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using dolphindb.io; 7 | using dolphindb.compression; 8 | using dolphindb.data; 9 | 10 | namespace dolphindb.compression 11 | { 12 | public abstract class AbstractDecoder : Decoder { 13 | public abstract ExtendedDataInput Decompress(ExtendedDataInput input, int length, int unitLength, int elementCount, int extra, bool isLittleEndian, int type, short scale); 14 | 15 | public ByteBuffer CreateColumnVector(int rows, int extra, int unitLength, bool isLittleEndian, int minSize, int dataType, short scale) 16 | { 17 | ByteBuffer ret = ByteBuffer.Allocate(Math.Max(rows * unitLength + 8, minSize)); 18 | ret.order(isLittleEndian); 19 | ret.WriteInt(rows); 20 | ret.WriteInt(extra); 21 | if (Utils.getCategory((DATA_TYPE)dataType) == DATA_CATEGORY.DENARY) 22 | { 23 | ret.WriteInt(scale); 24 | } 25 | return ret; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("dolphindb_csharpapi")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("dolphindb_csharpapi")] 13 | [assembly: AssemblyCopyright("Copyright © 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("f744da92-d9f2-49bb-9783-f89e825cb307")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("3.00.2.3")] 36 | [assembly: AssemblyFileVersion("3.00.2.3")] 37 | -------------------------------------------------------------------------------- /src/data/AbstractEntity.cs: -------------------------------------------------------------------------------- 1 | namespace dolphindb.data 2 | { 3 | 4 | public abstract class AbstractEntity 5 | { 6 | public abstract DATA_FORM getDataForm(); 7 | 8 | public bool isScalar() 9 | { 10 | return getDataForm() == DATA_FORM.DF_SCALAR; 11 | } 12 | public bool isVector() 13 | { 14 | return getDataForm() == DATA_FORM.DF_VECTOR; 15 | } 16 | public bool isPair() 17 | { 18 | return getDataForm() == DATA_FORM.DF_PAIR; 19 | } 20 | public bool isTable() 21 | { 22 | return getDataForm() == DATA_FORM.DF_TABLE; 23 | } 24 | public bool isMatrix() 25 | { 26 | return getDataForm() == DATA_FORM.DF_MATRIX; 27 | } 28 | public bool isDictionary() 29 | { 30 | return getDataForm() == DATA_FORM.DF_DICTIONARY; 31 | } 32 | public bool isChart() 33 | { 34 | return getDataForm() == DATA_FORM.DF_CHART; 35 | } 36 | public bool isChunk() 37 | { 38 | return getDataForm() == DATA_FORM.DF_CHUNK; 39 | } 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/data/BasicTimestampMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicTimestampMatrix : BasicLongMatrix 8 | { 9 | public BasicTimestampMatrix(int rows, int columns) : base(rows, columns) 10 | { 11 | } 12 | 13 | 14 | public BasicTimestampMatrix(int rows, int columns, IList listOfArrays) : base(rows,columns, listOfArrays) 15 | { 16 | } 17 | 18 | public BasicTimestampMatrix(ExtendedDataInput @in) : base(@in) 19 | { 20 | } 21 | 22 | public virtual void setTimestamp(int row, int column, DateTime value) 23 | { 24 | setLong(row, column, Utils.countMilliseconds(value)); 25 | } 26 | 27 | public virtual DateTime getTimestamp(int row, int column) 28 | { 29 | return Utils.parseTimestamp(getLong(row, column)); 30 | } 31 | 32 | 33 | public override IScalar get(int row, int column) 34 | { 35 | return new BasicTimestamp(getLong(row, column)); 36 | } 37 | 38 | public override DATA_CATEGORY getDataCategory() 39 | { 40 | return DATA_CATEGORY.TEMPORAL; 41 | } 42 | 43 | public override DATA_TYPE getDataType() 44 | { 45 | return DATA_TYPE.DT_TIMESTAMP; 46 | } 47 | 48 | public override Type getElementClass() 49 | { 50 | return typeof(BasicTimestamp); 51 | } 52 | 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /test/MyConfigReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace dolphindb_config 9 | { 10 | public static class MyConfigReader 11 | { 12 | public static String SERVER = "192.168.100.4"; 13 | public static int PORT = 11954; 14 | public static int PORTCON = 11951; 15 | public static int PORTDATE2 = 11954; 16 | public static int PORTDATE3 = 11955; 17 | public static int PORTDATE4 = 11956; 18 | public static string USER = "admin"; 19 | public static string PASSWORD = "123456"; 20 | public static String NODE1_HOST = "192.168.100.4"; 21 | public static int NODE1_PORT = 11954; 22 | public static String LOCALHOST = "192.168.100.4"; 23 | public static int LOCALPORT = 18817; 24 | public static int HASTREAM_GROUPID = 3; 25 | public static string[] HASTREAM_GROUP = new string[] { "192.168.100.4:11954", "192.168.100.4:11955", "192.168.100.4:11956" }; 26 | public static string[] HASTREAM_GROUP1 = new string[] { "192.168.100.4:11954" }; 27 | public static int SUB_FLAG = 0; 28 | public static String DATA_DIR = "E://wsun//cSharp//DATA_DIR//"; 29 | 30 | 31 | } 32 | } 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/route/DBVersion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace dolphindb.route 7 | { 8 | internal class DBVersion 9 | { 10 | int[] v = null; 11 | string version = null; 12 | public DBVersion() { } 13 | 14 | public DBVersion(string version) 15 | { 16 | v = new int[4]; 17 | this.version = version; 18 | string[] parts = version.Split(' ')[0].Split('.'); 19 | v[0] = int.Parse(parts[0]); 20 | v[1] = int.Parse(parts[1]); 21 | v[2] = int.Parse(parts[2]); 22 | if (parts.Length > 3) 23 | { 24 | v[3] = int.Parse(parts[3]); 25 | } 26 | } 27 | 28 | public int getVerNum() 29 | { 30 | try 31 | { 32 | string[] s = version.Split(' '); 33 | if (s.Length >= 2) 34 | { 35 | string vernum = s[0].Replace(".", ""); 36 | return int.Parse(vernum); 37 | } 38 | } 39 | catch (Exception) 40 | { 41 | } 42 | return 0; 43 | } 44 | 45 | public string getVersion() { return version; } 46 | 47 | public int getSubV(int index) 48 | { 49 | return v[index]; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/data/BasicTimeMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicTimeMatrix : BasicIntMatrix 9 | { 10 | public BasicTimeMatrix(int rows, int columns) : base(rows, columns) 11 | { 12 | } 13 | 14 | public BasicTimeMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 15 | { 16 | } 17 | 18 | public BasicTimeMatrix(ExtendedDataInput @in) : base(@in) 19 | { 20 | } 21 | 22 | public virtual void setTime(int row, int column, DateTime value) 23 | { 24 | setInt(row, column, (int)Utils.countMilliseconds(value)); 25 | } 26 | 27 | public virtual TimeSpan getTime(int row, int column) 28 | { 29 | return Utils.parseTime(getInt(row, column)); 30 | } 31 | 32 | public override IScalar get(int row, int column) 33 | { 34 | return new BasicTime(getInt(row, column)); 35 | } 36 | 37 | public override DATA_CATEGORY getDataCategory() 38 | { 39 | return DATA_CATEGORY.TEMPORAL; 40 | } 41 | 42 | public override DATA_TYPE getDataType() 43 | { 44 | return DATA_TYPE.DT_TIME; 45 | } 46 | 47 | public override Type getElementClass() 48 | { 49 | return typeof(BasicTime); 50 | } 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /src/data/BasicMonthMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicMonthMatrix : BasicIntMatrix 8 | { 9 | public BasicMonthMatrix(int rows, int columns) : base(rows, columns) 10 | { 11 | } 12 | 13 | public BasicMonthMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 14 | { 15 | } 16 | 17 | public BasicMonthMatrix(ExtendedDataInput @in) : base(@in) 18 | { 19 | } 20 | 21 | public virtual void setMonth(int row, int column, DateTime value) 22 | { 23 | setInt(row, column, Utils.countMonths(value)); 24 | } 25 | 26 | public virtual DateTime getMonth(int row, int column) 27 | { 28 | return Utils.parseMonth(getInt(row, column)); 29 | } 30 | 31 | 32 | public override IScalar get(int row, int column) 33 | { 34 | return new BasicMonth(getInt(row, column)); 35 | } 36 | 37 | public override DATA_CATEGORY getDataCategory() 38 | { 39 | return DATA_CATEGORY.TEMPORAL; 40 | } 41 | 42 | public override DATA_TYPE getDataType() 43 | { 44 | return DATA_TYPE.DT_MONTH; 45 | } 46 | 47 | public override Type getElementClass() 48 | { 49 | return typeof(BasicMonth); 50 | } 51 | 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/data/BasicDateMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicDateMatrix : BasicIntMatrix 9 | { 10 | public BasicDateMatrix(int rows, int columns) : base(rows, columns) 11 | { 12 | } 13 | 14 | 15 | public BasicDateMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 16 | { 17 | } 18 | 19 | 20 | public BasicDateMatrix(ExtendedDataInput @in) : base(@in) 21 | { 22 | } 23 | 24 | public virtual void setDate(int row, int column, DateTime value) 25 | { 26 | setInt(row, column, Utils.countDays(value)); 27 | } 28 | 29 | public virtual DateTime getDate(int row, int column) 30 | { 31 | return Utils.parseDate(getInt(row, column)); 32 | } 33 | 34 | 35 | public override IScalar get(int row, int column) 36 | { 37 | return new BasicDate(getInt(row, column)); 38 | } 39 | 40 | public override Type getElementClass() 41 | { 42 | 43 | return typeof(BasicDate); 44 | } 45 | 46 | public override DATA_CATEGORY getDataCategory() 47 | { 48 | return DATA_CATEGORY.TEMPORAL; 49 | } 50 | 51 | public override DATA_TYPE getDataType() 52 | { 53 | return DATA_TYPE.DT_DATE; 54 | } 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /test/dolphindb_csharpapi_net_core_test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp7.0 5 | v4 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | all 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/data/BasicDateHourMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicDateHourMatrix : BasicIntMatrix 9 | { 10 | public BasicDateHourMatrix(int rows, int columns) : base(rows, columns) 11 | { 12 | } 13 | 14 | public BasicDateHourMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 15 | { 16 | } 17 | 18 | public BasicDateHourMatrix(ExtendedDataInput @in) : base(@in) 19 | { 20 | } 21 | 22 | public virtual void setDateTime(int row, int column, DateTime value) 23 | { 24 | setInt(row, column, Utils.countHours(value)); 25 | } 26 | 27 | public virtual DateTime getDateTime(int row, int column) 28 | { 29 | return Utils.parseDateHour(getInt(row, column)); 30 | } 31 | 32 | public override IScalar get(int row, int column) 33 | { 34 | return new BasicDateHour(getInt(row, column)); 35 | } 36 | 37 | public override Type getElementClass() 38 | { 39 | return typeof(BasicDateHour); 40 | } 41 | 42 | public override DATA_CATEGORY getDataCategory() 43 | { 44 | return DATA_CATEGORY.TEMPORAL; 45 | } 46 | 47 | public override DATA_TYPE getDataType() 48 | { 49 | return DATA_TYPE.DT_DATEHOUR; 50 | } 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /src/data/BasicDateTimeMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicDateTimeMatrix : BasicIntMatrix 9 | { 10 | public BasicDateTimeMatrix(int rows, int columns) : base(rows, columns) 11 | { 12 | } 13 | 14 | public BasicDateTimeMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 15 | { 16 | } 17 | 18 | public BasicDateTimeMatrix(ExtendedDataInput @in) : base(@in) 19 | { 20 | } 21 | 22 | public virtual void setDateTime(int row, int column, DateTime value) 23 | { 24 | setInt(row, column, Utils.countSeconds(value)); 25 | } 26 | 27 | public virtual DateTime getDateTime(int row, int column) 28 | { 29 | return Utils.parseDateTime(getInt(row, column)); 30 | } 31 | 32 | public override IScalar get(int row, int column) 33 | { 34 | return new BasicDateTime(getInt(row, column)); 35 | } 36 | 37 | public override Type getElementClass() 38 | { 39 | return typeof(BasicDateTime); 40 | } 41 | 42 | public override DATA_CATEGORY getDataCategory() 43 | { 44 | return DATA_CATEGORY.TEMPORAL; 45 | } 46 | 47 | public override DATA_TYPE getDataType() 48 | { 49 | return DATA_TYPE.DT_DATETIME; 50 | } 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /src/data/BasicNanoTimeMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicNanoTimeMatrix : BasicLongMatrix 9 | { 10 | public BasicNanoTimeMatrix(int rows, int columns) : base(rows, columns) 11 | { 12 | } 13 | 14 | public BasicNanoTimeMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 15 | { 16 | } 17 | 18 | public BasicNanoTimeMatrix(ExtendedDataInput @in) : base(@in) 19 | { 20 | } 21 | 22 | public virtual void setNanoTime(int row, int column, DateTime value) 23 | { 24 | setLong(row, column, Utils.countNanoseconds(value)); 25 | } 26 | 27 | public virtual TimeSpan getNanoTime(int row, int column) 28 | { 29 | return Utils.parseNanoTime(getLong(row, column)); 30 | } 31 | 32 | public override IScalar get(int row, int column) 33 | { 34 | return new BasicNanoTime(getLong(row, column)); 35 | } 36 | 37 | public override DATA_CATEGORY getDataCategory() 38 | { 39 | return DATA_CATEGORY.TEMPORAL; 40 | } 41 | 42 | public override DATA_TYPE getDataType() 43 | { 44 | return DATA_TYPE.DT_NANOTIME; 45 | } 46 | 47 | public override Type getElementClass() 48 | { 49 | return typeof(BasicNanoTime); 50 | } 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /src/data/BasicSecondMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicSecondMatrix : BasicIntMatrix 8 | { 9 | public BasicSecondMatrix(int rows, int columns) : base(rows, columns) 10 | { 11 | } 12 | 13 | public BasicSecondMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 14 | { 15 | } 16 | 17 | public BasicSecondMatrix(ExtendedDataInput @in) : base(@in) 18 | { 19 | } 20 | 21 | public virtual void setSecond(int row, int column, TimeSpan value) 22 | { 23 | setInt(row, column, Utils.countSeconds(value.Hours,value.Minutes,value.Seconds)); 24 | } 25 | 26 | public virtual TimeSpan getSecond(int row, int column) 27 | { 28 | return Utils.parseSecond(getInt(row, column)); 29 | } 30 | 31 | public override IScalar get(int row, int column) 32 | { 33 | return new BasicSecond(getInt(row, column)); 34 | } 35 | 36 | public override DATA_CATEGORY getDataCategory() 37 | { 38 | 39 | return DATA_CATEGORY.TEMPORAL; 40 | } 41 | 42 | public override DATA_TYPE getDataType() 43 | { 44 | return DATA_TYPE.DT_SECOND; 45 | } 46 | 47 | public override Type getElementClass() 48 | { 49 | return typeof(BasicSecond); 50 | } 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /test/io_test/BigEndianDataOutputStream_test.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System.Collections.Generic; 3 | using dolphindb; 4 | using dolphindb.data; 5 | using dolphindb.io; 6 | using System.IO; 7 | 8 | namespace dolphindb_csharp_api_test.io_test 9 | { 10 | [TestClass] 11 | public class BigEndianDataOutputStream_test 12 | { 13 | [TestMethod] 14 | public void Test_BigEndianDataOutputStream() 15 | { 16 | Stream outStream = new MemoryStream(); 17 | BigEndianDataOutputStream output = new BigEndianDataOutputStream(outStream); 18 | output.writeLong(1); 19 | output.writeLong2(new Long2(1, 1)); 20 | short[] shortv = { 1, 2, 3, 4, 5 }; 21 | long[] longv = { 1, 2, 3, 4, 5 }; 22 | Long2[] long2v = new Long2[] { new Long2(1, 1), new Long2(1, 1) }; 23 | output.writeShortArray(shortv, 0, 2); 24 | output.writeLongArray(longv, 0, 2); 25 | output.writeLong2Array(long2v, 0, 2); 26 | Assert.AreEqual(false, output.isLittleEndian()); 27 | output.writeBoolean(true); 28 | output.writeBoolean(false); 29 | output.writeChar(1); 30 | output.writeChar((char)1); 31 | output.writeChars("1"); 32 | output.writeString(null); 33 | output.writeStringArray(new string[] { "12A", "HELLO" }); 34 | output.writeStringArray(new string[] { "12A", "HELLO" }, 1, 1); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/data/BasicMinuteMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | 9 | public class BasicMinuteMatrix : BasicIntMatrix 10 | { 11 | public BasicMinuteMatrix(int rows, int columns) : base(rows, columns) 12 | { 13 | } 14 | 15 | public BasicMinuteMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 16 | { 17 | } 18 | 19 | public BasicMinuteMatrix(ExtendedDataInput @in) : base(@in) 20 | { 21 | } 22 | 23 | public virtual void setMinute(int row, int column, TimeSpan value) 24 | { 25 | BasicMinute.checkTimeSpanToMinute(value); 26 | setInt(row, column, Utils.countMinutes(value)); 27 | } 28 | 29 | public virtual TimeSpan getMinute(int row, int column) 30 | { 31 | return Utils.parseMinute(getInt(row, column)); 32 | } 33 | 34 | 35 | public override IScalar get(int row, int column) 36 | { 37 | return new BasicMinute(getInt(row, column)); 38 | } 39 | 40 | public override DATA_CATEGORY getDataCategory() 41 | { 42 | return DATA_CATEGORY.TEMPORAL; 43 | } 44 | 45 | public override DATA_TYPE getDataType() 46 | { 47 | return DATA_TYPE.DT_MINUTE; 48 | } 49 | 50 | public override Type getElementClass() 51 | { 52 | return typeof(BasicMinute); 53 | } 54 | 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /test/compatibility_test/io_test/BigEndianDataOutputStream_test.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System.Collections.Generic; 3 | using dolphindb; 4 | using dolphindb.data; 5 | using dolphindb.io; 6 | using System.IO; 7 | 8 | namespace dolphindb_csharp_api_test.compatibility_test.io_test 9 | { 10 | [TestClass] 11 | public class BigEndianDataOutputStream_test 12 | { 13 | [TestMethod] 14 | public void Test_BigEndianDataOutputStream() 15 | { 16 | Stream outStream = new MemoryStream(); 17 | BigEndianDataOutputStream output = new BigEndianDataOutputStream(outStream); 18 | output.writeLong(1); 19 | output.writeLong2(new Long2(1, 1)); 20 | short[] shortv = { 1, 2, 3, 4, 5 }; 21 | long[] longv = { 1, 2, 3, 4, 5 }; 22 | Long2[] long2v = new Long2[] { new Long2(1, 1), new Long2(1, 1) }; 23 | output.writeShortArray(shortv, 0, 2); 24 | output.writeLongArray(longv, 0, 2); 25 | output.writeLong2Array(long2v, 0, 2); 26 | Assert.AreEqual(false, output.isLittleEndian()); 27 | output.writeBoolean(true); 28 | output.writeBoolean(false); 29 | output.writeChar(1); 30 | output.writeChar((char)1); 31 | output.writeChars("1"); 32 | output.writeString(null); 33 | output.writeStringArray(new string[] { "12A", "HELLO" }); 34 | output.writeStringArray(new string[] { "12A", "HELLO" }, 1, 1); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/data/BasicNanoTimestampMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicNanoTimestampMatrix : BasicLongMatrix 9 | { 10 | public BasicNanoTimestampMatrix(int rows, int columns) : base(rows, columns) 11 | { 12 | } 13 | 14 | public BasicNanoTimestampMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns, listOfArrays) 15 | { 16 | } 17 | 18 | public BasicNanoTimestampMatrix(ExtendedDataInput @in) : base(@in) 19 | { 20 | } 21 | 22 | public virtual void setNanoTimestamp(int row, int column, DateTime value) 23 | { 24 | setLong(row, column, Utils.countNanoseconds(value)); 25 | } 26 | 27 | public virtual DateTime getNanoTimestamp(int row, int column) 28 | { 29 | return Utils.parseNanoTimestamp(getLong(row, column)); 30 | } 31 | 32 | 33 | public override IScalar get(int row, int column) 34 | { 35 | return new BasicNanoTimestamp(getLong(row, column)); 36 | } 37 | 38 | public override DATA_CATEGORY getDataCategory() 39 | { 40 | return DATA_CATEGORY.TEMPORAL; 41 | } 42 | 43 | public override DATA_TYPE getDataType() 44 | { 45 | return DATA_TYPE.DT_NANOTIMESTAMP; 46 | } 47 | 48 | public override Type getElementClass() 49 | { 50 | return typeof(BasicNanoTimestamp); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/streaming/QueueManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections.Concurrent; 6 | 7 | namespace dolphindb.streaming 8 | { 9 | // public class QueueManager 10 | // { 11 | // private Dictionary>> queueMap = new Dictionary>>(); 12 | 13 | // private object Lock = new object(); 14 | 15 | // public BlockingCollection> addQueue(string topic) 16 | // { 17 | // lock (Lock) 18 | // { 19 | // if (!queueMap.ContainsKey(topic)) 20 | // { 21 | // BlockingCollection> q = new BlockingCollection>(4096); 22 | // queueMap.Add(topic, q); 23 | // return q; 24 | // } 25 | // throw new Exception("Topic " + topic + " already subscribed"); 26 | // } 27 | // } 28 | 29 | // public BlockingCollection> getQueue(string topic) 30 | // { 31 | // lock (Lock) 32 | // { 33 | // BlockingCollection> q = queueMap[topic]; 34 | // return q; 35 | // } 36 | // } 37 | 38 | // public void removeQueue(string topic) 39 | // { 40 | // lock (Lock) 41 | // { 42 | // queueMap.Remove(topic); 43 | // } 44 | // } 45 | // } 46 | } 47 | -------------------------------------------------------------------------------- /src/data/BasicUuidVector.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using dolphindb.io; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace dolphindb.data 8 | { 9 | public class BasicUuidVector : BasicInt128Vector 10 | { 11 | 12 | 13 | public BasicUuidVector(int size):base(size) 14 | { 15 | } 16 | 17 | public BasicUuidVector(List list):base(list) 18 | { 19 | } 20 | 21 | public BasicUuidVector(Long2[] array):base(array) 22 | { 23 | } 24 | 25 | internal BasicUuidVector(DATA_FORM df, int size):base(df,size) 26 | { 27 | } 28 | 29 | internal BasicUuidVector(DATA_FORM df, ExtendedDataInput @in):base(df,@in) 30 | { 31 | } 32 | 33 | public override void set(int index, IScalar value) 34 | { 35 | if (value.getDataType() == DATA_TYPE.DT_UUID) 36 | { 37 | Long2 t = ((BasicInt128)value).getLong2(); 38 | setInt128(index, t.high, t.low); 39 | } 40 | else 41 | throw new Exception("The value must be a uuid scalar. "); 42 | } 43 | 44 | public override IScalar get(int index) 45 | { 46 | return new BasicUuid(values[index].high, values[index].low); 47 | } 48 | 49 | public override DATA_TYPE getDataType() 50 | { 51 | return DATA_TYPE.DT_UUID; 52 | } 53 | public override Type getElementClass() 54 | { 55 | return typeof(BasicUuid); 56 | } 57 | 58 | public override IVector getSubVector(int[] indices) 59 | { 60 | return new BasicUuidVector(getSubArray(indices)); 61 | } 62 | 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/io/Double2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.data; 3 | 4 | namespace dolphindb.io 5 | { 6 | 7 | public struct Double2 8 | { 9 | public double x; 10 | public double y; 11 | 12 | public Double2(double x = -double.MaxValue, double y = -double.MaxValue) 13 | { 14 | this.x = x; 15 | this.y = y; 16 | } 17 | 18 | public bool isNull() 19 | { 20 | return x == -double.MaxValue && y == -double.MaxValue; 21 | } 22 | 23 | public void setNull() 24 | { 25 | x = -double.MaxValue; 26 | y = -double.MaxValue; 27 | } 28 | 29 | public bool equals(object o) 30 | { 31 | if (!(o is Double2) || o == null) 32 | return false; 33 | else 34 | return x == ((Double2)o).x && y == ((Double2)o).y; 35 | } 36 | 37 | public int hashBucket(int buckets) 38 | { 39 | return -1; 40 | } 41 | 42 | public override bool Equals(object o) 43 | { 44 | if (!(o is Double2) || o == null) 45 | { 46 | return false; 47 | } 48 | else 49 | { 50 | if (this.x != ((Double2)o).x || this.y != ((Double2)o).y) 51 | { 52 | return false; 53 | } 54 | else 55 | return true; 56 | } 57 | } 58 | 59 | public override int GetHashCode() 60 | { 61 | return new BasicDouble(x).GetHashCode() ^ new BasicDouble(y).GetHashCode(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/compression/VectorDecompressor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using dolphindb.data; 7 | using dolphindb.io; 8 | namespace dolphindb.compression 9 | { 10 | class VectorDecompressor 11 | { 12 | public IVector Decompress(IEntityFactory factory, ExtendedDataInput input, bool extended, bool isLittleEndian) 13 | { 14 | 15 | int compressedBytes = input.readInt(); 16 | //((LittleEndianDataInputStream)input).skipBytes(7); 17 | for(int i =0; i < 7; ++i) 18 | { 19 | input.readByte(); 20 | } 21 | int compression = input.readByte(); 22 | int dataType = input.readByte(); 23 | int unitLength = input.readByte(); 24 | //((LittleEndianDataInputStream)input).skipBytes(6); 25 | short reserved = input.readShort(); 26 | int extra = input.readInt(); 27 | int elementCount = input.readInt(); 28 | int tmp = extra; 29 | if (dataType < (int)DATA_TYPE.DT_BOOL_ARRAY) 30 | extra = 1; 31 | input.readInt(); 32 | 33 | ExtendedDataInput decompressedIn = DecoderFactory.get(compression).Decompress(input, compressedBytes - 20, unitLength, elementCount, extra, isLittleEndian, dataType, reserved); 34 | bool extend = dataType >= 128; 35 | if (dataType >= 128) 36 | dataType -= 128; 37 | DATA_TYPE dt = (DATA_TYPE)dataType; 38 | return (IVector)factory.createEntity(DATA_FORM.DF_VECTOR, dt, decompressedIn, extend); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/compression/LZ4/LZ4Util.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace LZ4Sharp 7 | { 8 | /// 9 | /// Constants and methods shared by LZ4Compressor and LZ4Decompressor 10 | /// 11 | internal class LZ4Util 12 | { 13 | //************************************** 14 | // Constants 15 | //************************************** 16 | public const int COPYLENGTH = 8; 17 | public const int ML_BITS = 4; 18 | public const uint ML_MASK = ((1U << ML_BITS) - 1); 19 | public const int RUN_BITS = (8 - ML_BITS); 20 | public const uint RUN_MASK = ((1U << RUN_BITS) - 1); 21 | 22 | public static unsafe void CopyMemory(byte* dst, byte* src, long length) 23 | { 24 | while (length >= 16) 25 | { 26 | *(ulong*)dst = *(ulong*)src; dst += 8; src += 8; 27 | *(ulong*)dst = *(ulong*)src; dst += 8; src += 8; 28 | length -= 16; 29 | } 30 | 31 | if (length >= 8) 32 | { 33 | *(ulong*)dst = *(ulong*)src; dst += 8; src += 8; 34 | length -= 8; 35 | } 36 | 37 | if (length >= 4) 38 | { 39 | *(uint*)dst = *(uint*)src; dst += 4; src += 4; 40 | length -= 4; 41 | } 42 | 43 | if (length >= 2) 44 | { 45 | *(ushort*)dst = *(ushort*)src; dst += 2; src += 2; 46 | length -= 2; 47 | } 48 | 49 | if (length != 0) 50 | *dst = *src; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/data/BasicIPAddrVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace dolphindb.data 8 | { 9 | public class BasicIPAddrVector : BasicInt128Vector 10 | { 11 | 12 | 13 | public BasicIPAddrVector(int size):base(size) 14 | { 15 | 16 | } 17 | 18 | public BasicIPAddrVector(List list):base(list) 19 | { 20 | } 21 | 22 | public BasicIPAddrVector(Long2[] array):base(array) 23 | { 24 | } 25 | 26 | internal BasicIPAddrVector(DATA_FORM df, int size):base(df,size) 27 | { 28 | } 29 | 30 | internal BasicIPAddrVector(DATA_FORM df, ExtendedDataInput @in):base(df,@in) 31 | { 32 | } 33 | 34 | public override IScalar get(int index) 35 | { 36 | return new BasicIPAddr(values[index].high, values[index].low); 37 | } 38 | 39 | public override void set(int index, IScalar value) 40 | { 41 | if (value.getDataType() == DATA_TYPE.DT_IPADDR) 42 | { 43 | values[index].high = ((BasicInt128)value).getMostSignicantBits(); 44 | values[index].low = ((BasicInt128)value).getLeastSignicantBits(); 45 | } 46 | else 47 | throw new Exception("The value must be a ipaddr scalar. "); 48 | } 49 | 50 | public override DATA_TYPE getDataType() 51 | { 52 | return DATA_TYPE.DT_IPADDR; 53 | } 54 | 55 | public override Type getElementClass() 56 | { 57 | return typeof(BasicIPAddr); 58 | } 59 | 60 | public override IVector getSubVector(int[] indices) 61 | { 62 | return new BasicIPAddrVector(getSubArray(indices)); 63 | } 64 | 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/data/Void.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.io; 3 | 4 | namespace dolphindb.data 5 | { 6 | public class Void : AbstractScalar 7 | { 8 | public Void(){} 9 | 10 | public Void(ExtendedDataInput @in) 11 | { 12 | @in.readByte(); 13 | } 14 | 15 | public override bool isNull() 16 | { 17 | return true; 18 | } 19 | 20 | public override DATA_CATEGORY getDataCategory() 21 | { 22 | return DATA_CATEGORY.NOTHING; 23 | } 24 | 25 | public override DATA_TYPE getDataType() 26 | { 27 | return DATA_TYPE.DT_VOID; 28 | } 29 | 30 | public override string getString() 31 | { 32 | return ""; 33 | } 34 | 35 | public override bool Equals(object o) 36 | { 37 | if (!(o is Void) || o == null) 38 | { 39 | return false; 40 | } 41 | else 42 | { 43 | return true; 44 | } 45 | } 46 | 47 | public override int GetHashCode() 48 | { 49 | return 0; 50 | } 51 | 52 | 53 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 54 | { 55 | @out.writeBoolean(true); //explicit null value 56 | } 57 | 58 | public override object getObject() 59 | { 60 | return null; 61 | } 62 | 63 | public override void setObject(object value) 64 | { 65 | return; 66 | } 67 | 68 | public override int hashBucket(int buckets) 69 | { 70 | throw new NotImplementedException(); 71 | } 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /test/ha_test/ha_test.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace dolphindb_csharp_api_test.ha_test 4 | { 5 | [TestClass] 6 | public class ha_test 7 | { 8 | [TestMethod] 9 | public void testKeepWritingTask() 10 | { 11 | 12 | //DBConnection conn = new DBConnection(); 13 | //conn.connect(SERVER, PORT, USER, PASSWORD, WRITE_FUNCTION_SCRIPT, true, HA_SITES); 14 | //int count = 0; 15 | //Random rnd = new Random(); 16 | //string funcScript = String.Format("saveData{{{0}}}", TBNAME); 17 | //Console.WriteLine(funcScript); 18 | //for (int i = 0; i <86400000; i++) 19 | //{ 20 | // IList args = new List(); 21 | // DateTime dt = new DateTime(2021, 1, 1); 22 | // BasicDateVector bdv = new BasicDateVector(new int[] { Utils.countDays(2021,4,7)}); 23 | // BasicTimeVector btv = new BasicTimeVector(new int[] {i}); 24 | // BasicStringVector bsv = new BasicStringVector(new string[] { SYMBOLS[rnd.Next(3)] }); 25 | // BasicIntVector bqv = new BasicIntVector(new int[] { rnd.Next(80,100) }); 26 | // BasicDoubleVector bpv = new BasicDoubleVector(new double[] {rnd.NextDouble() }); 27 | // List colNames = new List() { "date", "time", "sym", "qty", "price" }; 28 | // List cols = new List() {bdv, btv, bsv, bqv, bpv}; 29 | // BasicTable table1 = new BasicTable(colNames, cols); 30 | // args.Add(table1); 31 | 32 | // BasicInt re = (BasicInt)conn.run(funcScript, args); 33 | // Console.WriteLine(re.getInt()); 34 | //} 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/io/ExtendedDataOutput.cs: -------------------------------------------------------------------------------- 1 | namespace dolphindb.io 2 | { 3 | 4 | 5 | public interface ExtendedDataOutput 6 | { 7 | void write(byte[] b); 8 | void writeShort(int s); 9 | void writeString(string str); 10 | 11 | //2021.01.19 cwj 12 | void writeBlob(byte[] value); 13 | // 14 | 15 | void flush(); 16 | void writeShortArray(short[] A); 17 | void writeShortArray(short[] A, int startIdx, int len); 18 | void writeIntArray(int[] A); 19 | void writeIntArray(int[] A, int startIdx, int len); 20 | void writeLongArray(long[] A); 21 | void writeLongArray(long[] A, int startIdx, int len); 22 | void writeDoubleArray(double[] A); 23 | void writeDoubleArray(double[] A, int startIdx, int len); 24 | void writeFloatArray(float[] A); 25 | void writeFloatArray(float[] A, int startIdx, int len); 26 | void writeStringArray(string[] A); 27 | void writeStringArray(string[] A, int startIdx, int len); 28 | void writeLong2Array(Long2[] A); 29 | void writeLong2Array(Long2[] A, int startIdx, int len); 30 | 31 | void writeDouble2Array(Double2[] A); 32 | void writeDouble2Array(Double2[] A, int startIdx, int len); 33 | 34 | void writeBoolean(bool v); 35 | void writeByte(int v); 36 | void writeChar(char v); 37 | void writeFloat(float v); 38 | void writeDouble(double v); 39 | void writeBytes(string s); 40 | void writeChars(string s); 41 | void writeUTF(string value); 42 | void writeInt(int value); 43 | void writeLong(long value); 44 | void writeLong2(Long2 v); 45 | 46 | void writeDouble2(Double2 v); 47 | 48 | bool isLittleEndian(); 49 | void write(byte[] b, int offset, int length); 50 | } 51 | } -------------------------------------------------------------------------------- /src/route/DomainFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb; 6 | using dolphindb.data; 7 | 8 | namespace dolphindb.route 9 | { 10 | public class DomainFactory 11 | { 12 | public static Domain createDomain(PARTITION_TYPE type, DATA_TYPE partitionColType, IEntity partitionSchema) 13 | { 14 | if (type == PARTITION_TYPE.HASH) 15 | { 16 | DATA_TYPE dataType = partitionColType; 17 | DATA_CATEGORY dataCat = Utils.getCategory(dataType); 18 | int buckets = ((BasicInt)partitionSchema).getValue(); 19 | return new HashDomain(buckets, dataType, dataCat); 20 | } 21 | else if (type == PARTITION_TYPE.VALUE) 22 | { 23 | DATA_TYPE dataType = partitionSchema.getDataType(); 24 | DATA_CATEGORY dataCat = Utils.getCategory(dataType); 25 | return new ValueDomain((IVector)partitionSchema, dataType, dataCat); 26 | } 27 | else if (type == PARTITION_TYPE.RANGE) 28 | { 29 | DATA_TYPE dataType = partitionSchema.getDataType(); 30 | DATA_CATEGORY dataCat = Utils.getCategory(dataType); 31 | return new RangeDomain((IVector)partitionSchema, dataType, dataCat); 32 | } 33 | else if (type == PARTITION_TYPE.LIST) 34 | { 35 | DATA_TYPE dataType = ((BasicAnyVector)partitionSchema).getEntity(0).getDataType(); 36 | DATA_CATEGORY dataCat = Utils.getCategory(dataType); 37 | return new ListDomain((IVector)partitionSchema, dataType, dataCat); 38 | } 39 | throw new Exception("Unsupported partition type " + type.ToString()); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/io/BigEndianDataInputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace dolphindb.io 5 | { 6 | 7 | 8 | public class BigEndianDataInputStream : AbstractExtendedDataInputStream 9 | { 10 | 11 | public BigEndianDataInputStream(Stream @in) : base(@in) 12 | { 13 | 14 | } 15 | 16 | public override bool isLittleEndian() 17 | { 18 | return false; 19 | } 20 | 21 | public override int readInt() 22 | { 23 | byte b1 = readAndCheckByte(); 24 | byte b2 = readAndCheckByte(); 25 | byte b3 = readAndCheckByte(); 26 | byte b4 = readAndCheckByte(); 27 | return fromBytes(b1, b2, b3, b4); 28 | 29 | } 30 | 31 | public override long readLong() 32 | { 33 | byte b1 = readAndCheckByte(); 34 | byte b2 = readAndCheckByte(); 35 | byte b3 = readAndCheckByte(); 36 | byte b4 = readAndCheckByte(); 37 | byte b5 = readAndCheckByte(); 38 | byte b6 = readAndCheckByte(); 39 | byte b7 = readAndCheckByte(); 40 | byte b8 = readAndCheckByte(); 41 | return fromBytes(b1, b2, b3, b4, b5, b6, b7, b8); 42 | } 43 | 44 | public override Long2 readLong2() 45 | { 46 | 47 | long high = readLong(); 48 | long low = readLong(); 49 | return new Long2(high, low); 50 | } 51 | public override Double2 readDouble2() 52 | { 53 | double image = readDouble(); 54 | double real = readDouble(); 55 | return new Double2(real, image); 56 | } 57 | 58 | public override int readUnsignedShort() 59 | { 60 | byte b1 = readAndCheckByte(); 61 | byte b2 = readAndCheckByte(); 62 | return fromBytes(b1, b2, (byte)0, (byte)0); 63 | } 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/io/LittleEndianDataInputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | namespace dolphindb.io 4 | { 5 | 6 | 7 | public class LittleEndianDataInputStream : AbstractExtendedDataInputStream 8 | { 9 | 10 | public LittleEndianDataInputStream(Stream @in) : base(@in) 11 | { 12 | } 13 | 14 | public override int readInt() 15 | { 16 | byte b1 = readAndCheckByte(); 17 | byte b2 = readAndCheckByte(); 18 | byte b3 = readAndCheckByte(); 19 | byte b4 = readAndCheckByte(); 20 | return fromBytes(b4, b3, b2, b1); 21 | } 22 | 23 | public override long readLong() 24 | { 25 | byte b1 = readAndCheckByte(); 26 | byte b2 = readAndCheckByte(); 27 | byte b3 = readAndCheckByte(); 28 | byte b4 = readAndCheckByte(); 29 | byte b5 = readAndCheckByte(); 30 | byte b6 = readAndCheckByte(); 31 | byte b7 = readAndCheckByte(); 32 | byte b8 = readAndCheckByte(); 33 | return fromBytes(b8, b7, b6, b5, b4, b3, b2, b1); 34 | } 35 | 36 | public override Long2 readLong2() 37 | { 38 | long low = readLong(); 39 | long high = readLong(); 40 | return new Long2(high, low); 41 | } 42 | public override Double2 readDouble2() 43 | { 44 | double real = readDouble(); 45 | double image = readDouble(); 46 | return new Double2(real, image); 47 | } 48 | 49 | public override int readUnsignedShort() 50 | { 51 | byte b1 = readAndCheckByte(); 52 | byte b2 = readAndCheckByte(); 53 | return fromBytes((byte)0, (byte)0, b2, b1); 54 | } 55 | 56 | public override bool isLittleEndian() 57 | { 58 | return true; 59 | } 60 | 61 | } 62 | 63 | 64 | } -------------------------------------------------------------------------------- /dolphindb_csharpapi_net_core.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32210.238 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dolphindb_csharpapi_net_core", "dolphindb_csharpapi_net_core.csproj", "{5233ED95-F919-4FA3-8BD9-193E066A8F27}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dolphindb_csharpapi_net_core_test", "test\dolphindb_csharpapi_net_core_test.csproj", "{6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {5233ED95-F919-4FA3-8BD9-193E066A8F27} = {5233ED95-F919-4FA3-8BD9-193E066A8F27} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {5233ED95-F919-4FA3-8BD9-193E066A8F27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {5233ED95-F919-4FA3-8BD9-193E066A8F27}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {5233ED95-F919-4FA3-8BD9-193E066A8F27}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {5233ED95-F919-4FA3-8BD9-193E066A8F27}.Release|Any CPU.Build.0 = Release|Any CPU 23 | {6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}.Release|Any CPU.Build.0 = Release|Any CPU 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(ExtensibilityGlobals) = postSolution 32 | SolutionGuid = {FB1A5801-604F-4CB4-B4AB-ED370B77C83F} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /src/streaming/cep/EventSender.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Data.Common; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace dolphindb.streaming.cep 10 | { 11 | public class EventSender 12 | { 13 | public EventSender(DBConnection conn, string tableName, List eventSchema, List eventTimeFields = null, List commonFields = null) 14 | { 15 | Utils.checkParamIsNull(conn, "conn"); 16 | Utils.checkParamIsNull(tableName, "tableName"); 17 | Utils.checkParamIsNull(eventSchema, "eventSchema"); 18 | conn_ = conn; 19 | if (eventTimeFields == null) eventTimeFields = new List(); 20 | if (commonFields == null) commonFields = new List(); 21 | eventHandler_ = new EventHandler(eventSchema, eventTimeFields, commonFields); 22 | if (tableName == "") 23 | { 24 | throw new Exception("tableName must not be empty."); 25 | } 26 | string sql = "select top 0 * from " + tableName; 27 | BasicTable outputTable = (BasicTable)conn_.run(sql); 28 | eventHandler_.checkOutputTable(outputTable, tableName); 29 | insertScript_ = "tableInsert{" + tableName + "}"; 30 | } 31 | public void sendEvent(string eventType, List attributes) 32 | { 33 | Utils.checkParamIsNull(eventType, "eventType"); 34 | Utils.checkParamIsNull(attributes, "attributes"); 35 | List args = new List(); 36 | eventHandler_.serializeEvent(eventType, attributes, args); 37 | conn_.run(insertScript_, args); 38 | } 39 | 40 | private string insertScript_; 41 | private EventHandler eventHandler_; 42 | private DBConnection conn_; 43 | }; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/streaming/BasicMessage.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace dolphindb.streaming 9 | { 10 | public class BasicMessage : IMessage 11 | { 12 | private long offset = 0; 13 | private string topic = ""; 14 | private BasicAnyVector msg = null; 15 | private string sym_; 16 | private List colsName_; 17 | 18 | public BasicMessage(long offset, string topic, BasicAnyVector msg, string sym = "", List colNames = null) 19 | { 20 | this.offset = offset; 21 | this.topic = topic; 22 | this.msg = msg; 23 | this.sym_ = sym; 24 | this.colsName_ = colNames; 25 | } 26 | 27 | public T getValue(int colIndex) 28 | { 29 | return (T)msg.getEntity(colIndex); 30 | } 31 | 32 | public string getTopic() 33 | { 34 | return topic; 35 | } 36 | 37 | public long getOffset() 38 | { 39 | return offset; 40 | } 41 | 42 | public IEntity getEntity(int colIndex) 43 | { 44 | return msg.getEntity(colIndex); 45 | } 46 | 47 | public int size() 48 | { 49 | return msg.rows(); 50 | } 51 | 52 | public string getSym() 53 | { 54 | return sym_; 55 | } 56 | 57 | public BasicTable getTable() 58 | { 59 | if (colsName_ == null) { 60 | throw new Exception("The getTable method must be used when msgAsTable is true. "); 61 | } 62 | List cols = new List (); 63 | int rows = msg.rows(); 64 | for(int i = 0; i < rows; ++i) 65 | { 66 | cols.Add((IVector)msg.getEntity(i)); 67 | } 68 | return new BasicTable(colsName_, cols); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/compression/LZ4Decoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.compression; 6 | using dolphindb.io; 7 | using System.IO; 8 | using LZ4Sharp; 9 | class LZ4Decoder: AbstractDecoder 10 | { 11 | 12 | public override ExtendedDataInput Decompress(ExtendedDataInput input, int length, int unitLength, int elementCount, int extra, bool isLittleEndian, int type, short scale) { 13 | ByteBuffer buffer = CreateColumnVector(elementCount, extra, unitLength, isLittleEndian, 0, type, scale); 14 | byte[] output = buffer.array(); 15 | int offset = buffer.ReadableBytes; 16 | ILZ4Decompressor t = LZ4DecompressorFactory.CreateNew(); 17 | while (length > 0) { 18 | int blockSize = input.readInt(); 19 | if(blockSize< 0){ 20 | blockSize = blockSize & 2147483647; 21 | } 22 | length -= sizeof(int); 23 | blockSize = Math.Min(blockSize, length); 24 | if (blockSize == 0) break; 25 | 26 | byte[] src = new byte[blockSize]; 27 | int index = 0; 28 | while (index < blockSize) 29 | { 30 | index += ((BinaryReader)input).Read(src, index, blockSize - index); 31 | } 32 | byte[] ret = t.Decompress(src); 33 | if(offset + ret.Length > output.Length) 34 | { 35 | byte[] tmp = new byte[Math.Max(offset + ret.Length, output.Length) * 2]; 36 | Array.Copy(output, tmp, offset); 37 | output = tmp; 38 | } 39 | Buffer.BlockCopy(ret, 0, output, offset, ret.Length); 40 | offset += ret.Length; 41 | length -= blockSize; 42 | } 43 | 44 | if (isLittleEndian) 45 | return new LittleEndianDataInputStream(new MemoryStream(output)); 46 | 47 | return new BigEndianDataInputStream(new MemoryStream(output)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/data/BasicDate.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | public class BasicDate : BasicInt 7 | { 8 | private static string format = "yyyy.MM.dd"; 9 | 10 | public BasicDate(DateTime value) : base(Utils.countDays(value)) 11 | { 12 | } 13 | 14 | public BasicDate(ExtendedDataInput @in) : base(@in) 15 | { 16 | } 17 | 18 | public BasicDate(int value) : base(value) 19 | { 20 | } 21 | 22 | public override DATA_CATEGORY getDataCategory() 23 | { 24 | return DATA_CATEGORY.TEMPORAL; 25 | } 26 | 27 | public override DATA_TYPE getDataType() 28 | { 29 | return DATA_TYPE.DT_DATE; 30 | } 31 | 32 | public override object getObject() 33 | { 34 | return getValue(); 35 | } 36 | public new DateTime getValue() 37 | { 38 | if (isNull()) 39 | { 40 | return DateTime.MinValue; 41 | } 42 | else 43 | { 44 | return Utils.parseDate(base.getValue()); 45 | } 46 | } 47 | 48 | public override object getTemporal() 49 | { 50 | return getValue(); 51 | } 52 | 53 | public int getInternalValue() 54 | { 55 | return base.getValue(); 56 | } 57 | 58 | public override string getString() 59 | { 60 | if (isNull()) 61 | { 62 | return ""; 63 | } 64 | else 65 | { 66 | return getValue().ToString(format); 67 | } 68 | } 69 | 70 | public override void setObject(object value) 71 | { 72 | if (value != null && value.GetType() == Type.GetType("System.DateTime")) 73 | { 74 | base.setObject(Utils.countDays(Convert.ToDateTime(value))); 75 | } 76 | } 77 | 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/data/BasicPointVector.cs: -------------------------------------------------------------------------------- 1 | 2 | using dolphindb.io; 3 | using dolphindb.data; 4 | using System.Collections.Generic; 5 | using System; 6 | 7 | public class BasicPointVector : BasicDouble2Vector 8 | { 9 | public BasicPointVector(int size) : this(DATA_FORM.DF_VECTOR, size) { } 10 | public BasicPointVector(List list) : base(list) { } 11 | 12 | public BasicPointVector(Double2[] array) : base(array) { } 13 | internal BasicPointVector(DATA_FORM df, int size) : base(df, size) { } 14 | 15 | internal BasicPointVector(DATA_FORM df, ExtendedDataInput @in) : base(df, @in) { } 16 | 17 | public override IScalar get(int index) 18 | { 19 | return new BasicPoint(values[index].x, values[index].y); 20 | } 21 | 22 | public override void set(int index, IScalar value) 23 | { 24 | if (value.getDataType() == DATA_TYPE.DT_POINT) 25 | { 26 | values[index] = new Double2(((BasicPoint)value).getX(), ((BasicPoint)value).getY()); 27 | } 28 | else 29 | throw new Exception("The value must be a point scalar. "); 30 | } 31 | 32 | public void setPoint(int index, double x, double y) 33 | { 34 | values[index] = new Double2(x, y); 35 | } 36 | 37 | public override DATA_TYPE getDataType() 38 | { 39 | return DATA_TYPE.DT_POINT; 40 | } 41 | 42 | public override Type getElementClass() 43 | { 44 | return typeof(BasicPoint); 45 | } 46 | 47 | public override IVector getSubVector(int[] indices) 48 | { 49 | int length = indices.Length; 50 | Double2[] sub = new Double2[length]; 51 | for (int i = 0; i < length; ++i) 52 | sub[i] = values[indices[i]]; 53 | return new BasicPointVector(sub); 54 | } 55 | 56 | public override void append(IScalar value) 57 | { 58 | values.Add(((BasicPoint)value).getValue()); 59 | } 60 | 61 | public override void append(IVector value) 62 | { 63 | values.AddRange(((BasicPointVector)value).getDataArray()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/data/BasicNanoTimestamp.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | public class BasicNanoTimestamp : BasicLong 7 | { 8 | private static string format = "yyyy.MM.dd'T'HH:mm:ss.fffffff"; 9 | 10 | public BasicNanoTimestamp(DateTime value) : base(Utils.countNanoseconds(value)) 11 | { 12 | } 13 | 14 | public BasicNanoTimestamp(ExtendedDataInput @in) : base(@in) 15 | { 16 | } 17 | 18 | public BasicNanoTimestamp(long value) : base(value) 19 | { 20 | } 21 | 22 | public override DATA_CATEGORY getDataCategory() 23 | { 24 | return DATA_CATEGORY.TEMPORAL; 25 | } 26 | 27 | public override DATA_TYPE getDataType() 28 | { 29 | return DATA_TYPE.DT_NANOTIMESTAMP; 30 | } 31 | 32 | public override object getObject() 33 | { 34 | return getValue(); 35 | } 36 | public new DateTime getValue() 37 | { 38 | if (isNull()) 39 | { 40 | return DateTime.MinValue; 41 | } 42 | else 43 | { 44 | return Utils.parseNanoTimestamp(base.getValue()); 45 | } 46 | } 47 | public override object getTemporal() 48 | { 49 | return getValue(); 50 | } 51 | 52 | public long getInternalValue() 53 | { 54 | return base.getValue(); 55 | } 56 | 57 | public override string getString() 58 | { 59 | if (isNull()) 60 | { 61 | return ""; 62 | } 63 | else 64 | { 65 | DateTime dateTime = getValue(); 66 | long last = (long)base.getValue() % 100; 67 | return dateTime.ToString(format)+last.ToString("00"); 68 | } 69 | } 70 | 71 | public override void setObject(object value) 72 | { 73 | if (value != null && value.GetType() == Type.GetType("System.DateTime")) 74 | { 75 | base.setObject(Utils.countNanoseconds(Convert.ToDateTime(value))); 76 | } 77 | } 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/data/BasicDateHour.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | 7 | public class BasicDateHour : BasicInt 8 | { 9 | private static string format = "yyyy.MM.dd'T'HH"; 10 | 11 | public BasicDateHour(DateTime value) : base(Utils.countHours(value)) 12 | { 13 | } 14 | 15 | public BasicDateHour(ExtendedDataInput @in) : base(@in) 16 | { 17 | } 18 | 19 | public BasicDateHour(int value) : base(value) 20 | { 21 | } 22 | 23 | public override DATA_CATEGORY getDataCategory() 24 | { 25 | return DATA_CATEGORY.TEMPORAL; 26 | } 27 | 28 | public override DATA_TYPE getDataType() 29 | { 30 | return DATA_TYPE.DT_DATEHOUR; 31 | } 32 | 33 | public override object getObject() 34 | { 35 | return getValue(); 36 | } 37 | public new DateTime getValue() 38 | { 39 | if (isNull()) 40 | { 41 | return DateTime.MinValue; 42 | } 43 | else 44 | { 45 | return Utils.parseDateHour(base.getValue()); 46 | } 47 | } 48 | 49 | public override object getTemporal() 50 | { 51 | return getValue(); 52 | } 53 | 54 | public int getInternalValue() 55 | { 56 | return base.getValue(); 57 | } 58 | 59 | public override string getString() 60 | { 61 | if (isNull()) 62 | { 63 | return ""; 64 | } 65 | else 66 | { 67 | return getValue().ToString(format); 68 | } 69 | } 70 | 71 | public override void setObject(object value) 72 | { 73 | if (value != null && value.GetType() == Type.GetType("System.DateTime")) 74 | { 75 | base.setObject(Utils.countHours(Convert.ToDateTime(value))); 76 | } 77 | } 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/data/BasicDateTime.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | 7 | public class BasicDateTime : BasicInt 8 | { 9 | private static string format = "yyyy.MM.dd'T'HH:mm:ss"; 10 | 11 | public BasicDateTime(DateTime value) : base(Utils.countSeconds(value)) 12 | { 13 | } 14 | 15 | public BasicDateTime(ExtendedDataInput @in) : base(@in) 16 | { 17 | } 18 | 19 | public BasicDateTime(int value) : base(value) 20 | { 21 | } 22 | 23 | public override DATA_CATEGORY getDataCategory() 24 | { 25 | return DATA_CATEGORY.TEMPORAL; 26 | } 27 | 28 | public override DATA_TYPE getDataType() 29 | { 30 | return DATA_TYPE.DT_DATETIME; 31 | } 32 | 33 | public override object getObject() 34 | { 35 | return getValue(); 36 | } 37 | public new DateTime getValue() 38 | { 39 | if (isNull()) 40 | { 41 | return DateTime.MinValue; 42 | } 43 | else 44 | { 45 | return Utils.parseDateTime(base.getValue()); 46 | } 47 | } 48 | 49 | public override object getTemporal() 50 | { 51 | return getValue(); 52 | } 53 | 54 | public int getInternalValue() 55 | { 56 | return base.getValue(); 57 | } 58 | 59 | public override string getString() 60 | { 61 | if (isNull()) 62 | { 63 | return ""; 64 | } 65 | else 66 | { 67 | return getValue().ToString(format); 68 | } 69 | } 70 | 71 | public override void setObject(object value) 72 | { 73 | if(value != null && value.GetType() == Type.GetType("System.DateTime")) 74 | { 75 | base.setObject(Utils.countSeconds(Convert.ToDateTime(value))); 76 | } 77 | } 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/data/BasicSecond.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | 7 | public class BasicSecond : BasicInt 8 | { 9 | private static string format = "c"; 10 | 11 | public BasicSecond(TimeSpan value) : base(Utils.countSeconds(value)) 12 | { 13 | } 14 | 15 | public BasicSecond(ExtendedDataInput @in) : base(@in) 16 | { 17 | } 18 | 19 | public BasicSecond(int value) : base(value) 20 | { 21 | } 22 | 23 | public override DATA_CATEGORY getDataCategory() 24 | { 25 | return DATA_CATEGORY.TEMPORAL; 26 | } 27 | 28 | public override DATA_TYPE getDataType() 29 | { 30 | return DATA_TYPE.DT_SECOND; 31 | } 32 | 33 | public override object getObject() 34 | { 35 | return getValue(); 36 | } 37 | 38 | public new TimeSpan getValue() 39 | { 40 | if (isNull()) 41 | { 42 | return TimeSpan.MinValue; 43 | } 44 | else 45 | { 46 | return Utils.parseSecond(base.getValue()); 47 | } 48 | 49 | } 50 | 51 | public override object getTemporal() 52 | { 53 | return getValue(); 54 | } 55 | 56 | public int getInternalValue() 57 | { 58 | return base.getValue(); 59 | } 60 | 61 | public override string getString() 62 | { 63 | if (isNull()) 64 | { 65 | return ""; 66 | } 67 | else 68 | { 69 | return getValue().ToString(format); 70 | } 71 | } 72 | 73 | public override void setObject(object value) 74 | { 75 | if (value != null && value.GetType() == Type.GetType("System.TimeSpan")) 76 | { 77 | checkTimeSpanToSecond((TimeSpan)value); 78 | base.setObject(Utils.countSeconds((TimeSpan)value)); 79 | } 80 | } 81 | 82 | public static void checkTimeSpanToSecond(TimeSpan value){ 83 | if(value.Days != 0){ 84 | throw new TimeoutException("To convert BasicSecond, TimeSpan's days must equal zero. "); 85 | } 86 | } 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/data/BasicComplexVector.cs: -------------------------------------------------------------------------------- 1 | 2 | using dolphindb.io; 3 | using dolphindb.data; 4 | using System.Collections.Generic; 5 | using System; 6 | 7 | public class BasicComplexVector : BasicDouble2Vector 8 | { 9 | public BasicComplexVector(int size) : this(DATA_FORM.DF_VECTOR, size) { } 10 | public BasicComplexVector(List list) : base(list) { } 11 | 12 | public BasicComplexVector(Double2[] array) : base(array) { } 13 | internal BasicComplexVector(DATA_FORM df, int size) : base(df, size) { } 14 | 15 | internal BasicComplexVector(DATA_FORM df, ExtendedDataInput @in) : base(df, @in) { } 16 | 17 | public override IScalar get(int index) 18 | { 19 | return new BasicComplex(values[index].x, values[index].y); 20 | } 21 | 22 | public override void set(int index, IScalar value) 23 | { 24 | if (value.getDataType() == DATA_TYPE.DT_COMPLEX) 25 | { 26 | values[index] = new Double2(((BasicComplex)value).getReal(), ((BasicComplex)value).getImage()); 27 | } 28 | else 29 | throw new Exception("The value must be a complex scalar. "); 30 | } 31 | 32 | public void setComplex(int index, double real, double image) 33 | { 34 | values[index] = new Double2(real, image); 35 | } 36 | 37 | public override DATA_TYPE getDataType() 38 | { 39 | return DATA_TYPE.DT_COMPLEX; 40 | } 41 | 42 | 43 | public override Type getElementClass() 44 | { 45 | return typeof(BasicComplex); 46 | } 47 | 48 | public override IVector getSubVector(int[] indices) 49 | { 50 | int length = indices.Length; 51 | Double2[] sub = new Double2[length]; 52 | for (int i = 0; i < length; ++i) 53 | sub[i] = values[indices[i]]; 54 | return new BasicComplexVector(sub); 55 | } 56 | 57 | public override void append(IScalar value) 58 | { 59 | values.Add(((BasicComplex)value).getValue()); 60 | } 61 | 62 | public override void append(IVector value) 63 | { 64 | values.AddRange(((BasicComplexVector)value).getDataArray()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/compression/LZ4Encoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using LZ4Sharp; 6 | using dolphindb.data; 7 | 8 | namespace dolphindb.compression 9 | { 10 | class LZ4Encoder :Encoder 11 | { 12 | private static int DEFAULT_BLOCK_SIZE = 65536; 13 | private LZ4Sharp.ILZ4Compressor compresser; 14 | 15 | public int compress(AbstractVector input, int elementCount, int unitLength, int maxCompressedLength, ByteBuffer output) 16 | { 17 | if (compresser == null) 18 | { 19 | compresser = LZ4Sharp.LZ4CompressorFactory.CreateNew(); 20 | } 21 | int byteCount = 0; 22 | int dataCount = input.rows(); 23 | int dataIndex = 0; 24 | ByteBuffer dataBufer = ByteBuffer.Allocate(DEFAULT_BLOCK_SIZE); 25 | dataBufer.order(output.isLittleEndian); 26 | int partial = 0, elementNum; 27 | while (dataCount > dataIndex) 28 | { 29 | int readBytes = input.serialize(dataIndex, partial, dataCount - dataIndex, out elementNum, out partial, dataBufer); 30 | while(readBytes > 0) 31 | { 32 | int blockSize = Math.Min(DEFAULT_BLOCK_SIZE, dataBufer.ReadableBytes); 33 | byte[] srcBuf = new byte[blockSize]; 34 | dataBufer.ReadBytes(srcBuf, 0, blockSize); 35 | byte[] ret = compresser.Compress(srcBuf); 36 | if(ret.Length + sizeof(int) > output.remain()) 37 | { 38 | output.reserve((output.WriterIndex + ret.Length + sizeof(int)) * 2); 39 | } 40 | output.WriteInt(ret.Length); 41 | output.WriteBytes(ret); 42 | byteCount += ret.Length + sizeof(int) * 8; 43 | readBytes -= blockSize; 44 | } 45 | dataIndex += elementNum; 46 | dataBufer.Clear(); 47 | } 48 | return byteCount; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/data/BasicTimestamp.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | public class BasicTimestamp : BasicLong 7 | { 8 | private static string format = "yyyy.MM.dd'T'HH:mm:ss.fff"; 9 | 10 | public BasicTimestamp(DateTime value) : base(Utils.countMilliseconds(value)) 11 | { 12 | } 13 | 14 | public BasicTimestamp(ExtendedDataInput @in) : base(@in) 15 | { 16 | } 17 | 18 | public BasicTimestamp(long value) : base(value) 19 | { 20 | } 21 | 22 | public override DATA_CATEGORY getDataCategory() 23 | { 24 | return DATA_CATEGORY.TEMPORAL; 25 | } 26 | 27 | public override DATA_TYPE getDataType() 28 | { 29 | return DATA_TYPE.DT_TIMESTAMP; 30 | } 31 | 32 | public override object getObject() 33 | { 34 | return getValue(); 35 | } 36 | 37 | public new DateTime getValue() 38 | { 39 | if (isNull()) 40 | { 41 | return DateTime.MinValue; 42 | } 43 | else 44 | { 45 | return Utils.parseTimestamp(base.getValue()); 46 | } 47 | } 48 | 49 | public override object getTemporal() 50 | { 51 | return getValue(); 52 | } 53 | 54 | public long getInternalValue() 55 | { 56 | return base.getValue(); 57 | } 58 | 59 | public override string getString() 60 | { 61 | if (isNull()) 62 | { 63 | return ""; 64 | } 65 | else 66 | { 67 | DateTime dt = getValue(); 68 | 69 | return dt.ToString(format); 70 | } 71 | } 72 | 73 | public override void setObject(object value) 74 | { 75 | if (value!=null && value.GetType() == Type.GetType("System.DateTime")) 76 | { 77 | base.setObject(Utils.countMilliseconds(Convert.ToDateTime(value))); 78 | } 79 | } 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/route/ErrorCodeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace dolphindb.route 7 | { 8 | public class ErrorCodeInfo 9 | { 10 | public enum Code 11 | { 12 | EC_None = 0, 13 | EC_InvalidObject, 14 | EC_InvalidParameter, 15 | EC_InvalidTable, 16 | EC_InvalidColumnType, 17 | EC_Server, 18 | EC_UserBreak, 19 | EC_DestroyedObject, 20 | EC_Other 21 | 22 | } 23 | public ErrorCodeInfo() 24 | { 25 | set(0, ""); 26 | } 27 | public ErrorCodeInfo(Code code, String info) 28 | { 29 | set(code, info); 30 | } 31 | public ErrorCodeInfo(ErrorCodeInfo src) 32 | { 33 | set(src.errorCode, src.errorInfo); 34 | } 35 | public void set(ErrorCodeInfo errorCodeInfo) 36 | { 37 | set(errorCodeInfo.errorCode, errorCodeInfo.errorInfo); 38 | } 39 | public void set(Code code, String info) 40 | { 41 | this.errorCode = formatApiCode((int)code); 42 | this.errorInfo = info; 43 | } 44 | public void set(string code, String info) 45 | { 46 | this.errorCode = code; 47 | this.errorInfo = info; 48 | } 49 | public override string ToString() 50 | { 51 | return "code = " + errorCode + " info = " + errorInfo; 52 | } 53 | public static string formatApiCode(int code) 54 | { 55 | if (code != (int)Code.EC_None) 56 | return "A" + code; 57 | else 58 | return ""; 59 | } 60 | public void clearError() 61 | { 62 | errorCode = ""; 63 | errorInfo = ""; 64 | } 65 | public bool hasError() 66 | { 67 | return errorCode != ""; 68 | } 69 | public bool succeed() 70 | { 71 | return errorCode == ""; 72 | } 73 | public string errorCode = ""; 74 | public string errorInfo; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/data/BasicMonth.cs: -------------------------------------------------------------------------------- 1 | 2 | using dolphindb.io; 3 | using System; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicMonth : BasicInt 9 | { 10 | private static string format = "yyyy.MM"; 11 | 12 | public BasicMonth(int year, int month) : base(year * 12 + month) 13 | { 14 | } 15 | public BasicMonth(DateTime value) : base(value.Year * 12 + value.Month - 1) 16 | { 17 | } 18 | 19 | public BasicMonth(ExtendedDataInput @in) : base(@in) 20 | { 21 | } 22 | 23 | public BasicMonth(int value) : base(value) 24 | { 25 | } 26 | 27 | public override object getObject() 28 | { 29 | return getValue(); 30 | } 31 | 32 | public new DateTime getValue() 33 | { 34 | if (isNull()) 35 | { 36 | return DateTime.MinValue; 37 | } 38 | else 39 | { 40 | return Utils.parseMonth(base.getValue()); 41 | } 42 | } 43 | 44 | public override DATA_CATEGORY getDataCategory() 45 | { 46 | return DATA_CATEGORY.TEMPORAL; 47 | } 48 | 49 | public override DATA_TYPE getDataType() 50 | { 51 | return DATA_TYPE.DT_MONTH; 52 | } 53 | 54 | public override object getTemporal() 55 | { 56 | return getValue(); 57 | } 58 | 59 | public int getInternalValue() 60 | { 61 | return base.getValue(); 62 | } 63 | 64 | public override string getString() 65 | { 66 | if (isNull()) 67 | { 68 | return ""; 69 | } 70 | else 71 | { 72 | return getValue().ToString(format)+"M"; 73 | } 74 | 75 | } 76 | 77 | public override void setObject(object value) 78 | { 79 | if (value != null && value.GetType() == Type.GetType("System.DateTime")) 80 | { 81 | var v = (DateTime)value; 82 | base.setObject(v.Year * 12 + v.Month - 1); 83 | } 84 | } 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /src/data/BasicUuid.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace dolphindb.data 8 | { 9 | public class BasicUuid : BasicInt128 10 | { 11 | 12 | 13 | public BasicUuid(long high, long low) : base(high, low) 14 | { 15 | } 16 | 17 | 18 | internal BasicUuid(ExtendedDataInput @in) : base(@in) 19 | { 20 | } 21 | 22 | public override DATA_TYPE getDataType() 23 | { 24 | return DATA_TYPE.DT_UUID; 25 | } 26 | 27 | public override String getString() 28 | { 29 | if(isNull()) 30 | { 31 | return ""; 32 | }else{ 33 | ulong c = (ulong)0xffffffff << 32; 34 | //ulong a = 0xffffffff; 35 | ulong t = (ulong)value.high & c; 36 | ulong uHigh = (ulong)value.high; 37 | ulong uLow = (ulong)value.low; 38 | byte[] buffer = new byte[8]; 39 | for (int i = 0; i < 8; ++i) 40 | { 41 | buffer[i] = (byte)(uLow >> ((7 - i) * 8)); 42 | } 43 | return new Guid((int)(uHigh >> 32 & 0xffffffff), (short)(uHigh >> 16 & 0xffff), 44 | (short)(uHigh & 0xffff), buffer).ToString(); 45 | } 46 | } 47 | 48 | public static new BasicUuid fromString(String name) 49 | { 50 | String[] components = name.Split('-'); 51 | if (components.Length != 5) 52 | throw new ArgumentException("Invalid UUID string: " + name); 53 | 54 | long mostSigBits = Convert.ToInt64(components[0], 16); 55 | mostSigBits <<= 16; 56 | mostSigBits |= Convert.ToInt64(components[1], 16); 57 | mostSigBits <<= 16; 58 | mostSigBits |= Convert.ToInt64(components[2], 16); 59 | 60 | long leastSigBits = Convert.ToInt64(components[3], 16); 61 | leastSigBits <<= 48; 62 | leastSigBits |= Convert.ToInt64(components[4], 16); 63 | 64 | return new BasicUuid(mostSigBits, leastSigBits); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/route/HashDomain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.data; 6 | 7 | namespace dolphindb.route 8 | { 9 | public class HashDomain: Domain 10 | { 11 | private int buckets; 12 | private DATA_TYPE type; 13 | private DATA_CATEGORY cat; 14 | 15 | public HashDomain(int buckets, DATA_TYPE type, DATA_CATEGORY cat) 16 | { 17 | this.buckets = buckets; 18 | this.type = type; 19 | this.cat = cat; 20 | } 21 | 22 | public int getPartitionKey(IScalar partitionCol) 23 | { 24 | if(partitionCol.getDataCategory() != cat) 25 | throw new Exception("Data category incompatible."); 26 | if(cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType()) 27 | { 28 | //类型转化 29 | DATA_TYPE old = partitionCol.getDataType(); 30 | partitionCol = (IScalar)Utils.castDateTime(partitionCol, type); 31 | if (partitionCol == null) 32 | throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString()); 33 | } 34 | int rows = partitionCol.rows(); 35 | int key = partitionCol.hashBucket(buckets); 36 | return key; 37 | } 38 | 39 | public List getPartitionKeys(IVector partitionCol) 40 | { 41 | if(partitionCol.getDataCategory() != cat) 42 | throw new Exception("Data category incompatible."); 43 | if(cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType()) 44 | { 45 | //类型转化 46 | DATA_TYPE old = partitionCol.getDataType(); 47 | partitionCol = (IVector)Utils.castDateTime(partitionCol, type); 48 | if (partitionCol == null) 49 | throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString()); 50 | } 51 | int rows = partitionCol.rows(); 52 | List keys = new List(rows); 53 | for (int i = 0; i < rows; ++i) 54 | keys.Add(partitionCol.hashBucket(i, buckets)); 55 | return keys; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/route/ValueDomain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.data; 6 | 7 | namespace dolphindb.route 8 | { 9 | public class ValueDomain:Domain 10 | { 11 | private DATA_TYPE type; 12 | private DATA_CATEGORY cat; 13 | 14 | public ValueDomain(IVector partitionScheme, DATA_TYPE type, DATA_CATEGORY cat) 15 | { 16 | this.type = type; 17 | this.cat = cat; 18 | } 19 | 20 | public List getPartitionKeys(IVector partitionCol) 21 | { 22 | if (partitionCol.getDataCategory() != cat) 23 | throw new Exception("Data category incompatible."); 24 | if (cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType()) 25 | { 26 | DATA_TYPE old = partitionCol.getDataType(); 27 | partitionCol = (IVector)Utils.castDateTime(partitionCol, type); 28 | if (partitionCol == null) 29 | throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString()); 30 | } 31 | if (type == DATA_TYPE.DT_LONG) 32 | throw new Exception("Long type value can't be used as a partition column."); 33 | 34 | int rows = partitionCol.rows(); 35 | List keys = new List(rows); 36 | for (int i = 0; i < rows; ++i) 37 | keys.Add(partitionCol.hashBucket(i, 1048576)); 38 | return keys; 39 | } 40 | 41 | public int getPartitionKey(IScalar partitionCol) 42 | { 43 | if (partitionCol.getDataCategory() != cat) 44 | throw new Exception("Data category incompatible."); 45 | if (cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType()) 46 | { 47 | DATA_TYPE old = partitionCol.getDataType(); 48 | partitionCol = (IScalar)Utils.castDateTime(partitionCol, type); 49 | if (partitionCol == null) 50 | throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString()); 51 | } 52 | if (type == DATA_TYPE.DT_LONG) 53 | throw new Exception("Long type value can't be used as a partition column."); 54 | int key = partitionCol.hashBucket(1048576); 55 | return key; 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/data/BasicTime.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | public class BasicTime : BasicInt 7 | { 8 | private static string format = @"hh\:mm\:ss\.fff"; 9 | 10 | public BasicTime(TimeSpan value) : base((int)Utils.countMilliseconds(value.Hours,value.Minutes,value.Seconds,value.Milliseconds)) 11 | { 12 | checkTimeSpanToTime(value); 13 | } 14 | 15 | public BasicTime(ExtendedDataInput @in) : base(@in) 16 | { 17 | } 18 | 19 | public BasicTime(int value) : base(value) 20 | { 21 | } 22 | 23 | public override DATA_CATEGORY getDataCategory() 24 | { 25 | return DATA_CATEGORY.TEMPORAL; 26 | } 27 | 28 | public override DATA_TYPE getDataType() 29 | { 30 | return DATA_TYPE.DT_TIME; 31 | } 32 | 33 | public override object getObject() 34 | { 35 | return getValue(); 36 | } 37 | 38 | public new TimeSpan getValue() 39 | { 40 | if (isNull()) 41 | { 42 | return TimeSpan.MinValue; 43 | } 44 | else 45 | { 46 | return Utils.parseTime(base.getValue()); 47 | } 48 | 49 | } 50 | public override object getTemporal() 51 | { 52 | return getValue(); 53 | } 54 | 55 | public int getInternalValue() 56 | { 57 | return base.getValue(); 58 | } 59 | 60 | public override string getString() 61 | { 62 | if (isNull()) 63 | { 64 | return ""; 65 | } 66 | else 67 | { 68 | return getValue().ToString(format); 69 | } 70 | } 71 | 72 | public override void setObject(object value) 73 | { 74 | if (value != null && value.GetType() == Type.GetType("System.TimeSpan")) 75 | { 76 | var t = (TimeSpan)value; 77 | checkTimeSpanToTime(t); 78 | base.setObject(Utils.countMilliseconds(t.Hours,t.Minutes,t.Seconds,t.Milliseconds)); 79 | } 80 | } 81 | public static void checkTimeSpanToTime(TimeSpan value){ 82 | if(value.Days != 0){ 83 | throw new TimeoutException("To convert BasicTime, TimeSpan's days must equal zero. "); 84 | } 85 | } 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /src/data/BasicMinute.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | public class BasicMinute : BasicInt 7 | { 8 | private static string format = "c"; 9 | 10 | public BasicMinute(TimeSpan value) : base(Utils.countMinutes(value)) 11 | { 12 | checkTimeSpanToMinute(value); 13 | } 14 | 15 | public BasicMinute(ExtendedDataInput @in) : base(@in) 16 | { 17 | } 18 | 19 | public BasicMinute(int value) : base(value) 20 | { 21 | } 22 | 23 | public override DATA_CATEGORY getDataCategory() 24 | { 25 | return DATA_CATEGORY.TEMPORAL; 26 | } 27 | 28 | public override DATA_TYPE getDataType() 29 | { 30 | return DATA_TYPE.DT_MINUTE; 31 | } 32 | public override object getObject() 33 | { 34 | return getValue(); 35 | } 36 | 37 | public new TimeSpan getValue() 38 | { 39 | if (isNull()) 40 | { 41 | return TimeSpan.MinValue; 42 | } 43 | else 44 | { 45 | return Utils.parseMinute(base.getValue()); 46 | } 47 | 48 | } 49 | 50 | public override object getTemporal() 51 | { 52 | return getValue(); 53 | } 54 | 55 | public int getInternalValue() 56 | { 57 | return base.getValue(); 58 | } 59 | 60 | public override string getString() 61 | { 62 | if (isNull()) 63 | { 64 | return ""; 65 | } 66 | else 67 | { 68 | int hours = (base.getValue() / 60) % 24; 69 | TimeSpan ts = new TimeSpan(hours, base.getValue() % 60, 0); 70 | return ts.ToString(format); 71 | } 72 | } 73 | 74 | public override void setObject(object value) 75 | { 76 | if (value != null && value.GetType() == Type.GetType("System.TimeSpan")) 77 | { 78 | checkTimeSpanToMinute((TimeSpan)value); 79 | base.setObject(Utils.countMinutes((TimeSpan)value)); 80 | } 81 | } 82 | 83 | public static void checkTimeSpanToMinute(TimeSpan value){ 84 | if(value.Days != 0){ 85 | throw new TimeoutException("To convert BasicMinute, TimeSpan's days must equal zero. "); 86 | } 87 | } 88 | } 89 | 90 | } -------------------------------------------------------------------------------- /src/route/RangeDomain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.data; 6 | 7 | namespace dolphindb.route 8 | { 9 | public class RangeDomain:Domain 10 | { 11 | private DATA_TYPE type; 12 | private DATA_CATEGORY cat; 13 | private IVector range; 14 | 15 | public RangeDomain(IVector range, DATA_TYPE type, DATA_CATEGORY cat) 16 | { 17 | this.type = type; 18 | this.cat = cat; 19 | this.range = range; 20 | } 21 | 22 | public int getPartitionKey(IScalar partitionCol) 23 | { 24 | if (partitionCol.getDataCategory() != cat) 25 | throw new Exception("Data category incompatible."); 26 | if (cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType()) 27 | { 28 | DATA_TYPE old = partitionCol.getDataType(); 29 | partitionCol = (IScalar)Utils.castDateTime(partitionCol, type); 30 | if (partitionCol == null) 31 | throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString()); 32 | } 33 | int partitions = range.rows() - 1; 34 | int key = range.asof(partitionCol); 35 | if (key >= partitions) 36 | key = -1; 37 | return key; 38 | } 39 | 40 | public List getPartitionKeys(IVector partitionCol) 41 | { 42 | if (partitionCol.getDataCategory() != cat) 43 | throw new Exception("Data category incompatible."); 44 | if (cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType()) 45 | { 46 | DATA_TYPE old = partitionCol.getDataType(); 47 | partitionCol = (IVector)Utils.castDateTime(partitionCol, type); 48 | if (partitionCol == null) 49 | throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString()); 50 | } 51 | int partitions = range.rows() - 1; 52 | int rows = partitionCol.rows(); 53 | List keys = new List(rows); 54 | for (int i = 0; i < rows; ++i) 55 | { 56 | int index = range.asof(partitionCol.get(i)); 57 | if (index >= partitions) 58 | keys.Add(-1); 59 | else 60 | keys.Add(index); 61 | } 62 | return keys; 63 | } 64 | 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test/streaming/streamReverse_test/AbstractClientTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using dolphindb; 7 | using dolphindb.data; 8 | using dolphindb.streaming; 9 | using System.Threading; 10 | using dolphindb_config; 11 | 12 | namespace dolphindb_csharp_api_test.streamReverse_test 13 | { 14 | [TestClass] 15 | public class AbstractClientTest 16 | { 17 | 18 | public static DBConnection streamConn; 19 | private string SERVER = MyConfigReader.SERVER; 20 | static private int PORT = MyConfigReader.PORT; 21 | private readonly string USER = MyConfigReader.USER; 22 | private readonly string PASSWORD = MyConfigReader.PASSWORD; 23 | private string LOCALHOST = MyConfigReader.LOCALHOST; 24 | private readonly int LOCALPORT = MyConfigReader.LOCALPORT; 25 | static private int SUB_FLAG = MyConfigReader.SUB_FLAG; 26 | private string NODE1_HOST = MyConfigReader.NODE1_HOST; 27 | private readonly int NODE1_PORT = MyConfigReader.NODE1_PORT; 28 | public static string[] HASTREAM_GROUP = MyConfigReader.HASTREAM_GROUP; 29 | private readonly int HASTREAM_GROUPID = MyConfigReader.HASTREAM_GROUPID; 30 | //private readonly int TIMEOUT = 10000; 31 | 32 | [TestMethod] 33 | public void Test_activeClosePublishConnection_host_port() 34 | { 35 | DBConnection conn = new DBConnection(); 36 | conn.connect(SERVER, PORT); 37 | //string localIP = "localhost"; 38 | List @params = new List 39 | { 40 | new BasicString("tablename"), 41 | new BasicString("activeName") 42 | }; 43 | conn.run("activeClosePublishConnection", @params); 44 | 45 | } 46 | [TestMethod] 47 | public void Test_activeClosePublishConnection_host_null() 48 | { 49 | DBConnection conn = new DBConnection(); 50 | conn.connect(SERVER, 18921); 51 | try { 52 | List @params = new List 53 | { 54 | //new BasicString(SERVER), 55 | new BasicInt(8878) 56 | }; 57 | conn.run("activeClosePublishConnection", @params); 58 | } 59 | catch(Exception ex){ 60 | Console.WriteLine(ex.ToString()); 61 | } 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/data/BasicComplexMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicComplexMatrix : AbstractMatrix 9 | { 10 | private BasicComplexVector value; 11 | 12 | public BasicComplexMatrix(int rows, int columns) : base(rows, columns) 13 | { 14 | this.value = new BasicComplexVector(rows * columns); 15 | } 16 | 17 | public BasicComplexMatrix(int rows, int columns, IList list) : base(rows, columns) 18 | { 19 | List tmp = new List(); 20 | foreach (Double2[] data in list) 21 | { 22 | tmp.AddRange(data); 23 | } 24 | if (tmp.Count != rows * columns) 25 | { 26 | throw new Exception("the total size of list must be equal to rows * columns"); 27 | } 28 | value = new BasicComplexVector(tmp); 29 | } 30 | 31 | public BasicComplexMatrix(ExtendedDataInput @in) : base(@in) 32 | { 33 | } 34 | 35 | public override bool isNull(int row, int column) 36 | { 37 | return value.isNull(getIndex(row, column)); 38 | } 39 | 40 | public override void setNull(int row, int column) 41 | { 42 | value.setNull(getIndex(row, column)); 43 | } 44 | 45 | public override IScalar get(int row, int column) 46 | { 47 | return this.value.get(getIndex(row, column)); 48 | } 49 | 50 | public void set(int row, int column, IScalar value) 51 | { 52 | this.value.set(getIndex(row, column), value); 53 | } 54 | 55 | public override DATA_CATEGORY getDataCategory() 56 | { 57 | return DATA_CATEGORY.BINARY; 58 | } 59 | 60 | public override DATA_TYPE getDataType() 61 | { 62 | return DATA_TYPE.DT_COMPLEX; 63 | } 64 | 65 | public override Type getElementClass() 66 | { 67 | return typeof(BasicComplex); 68 | } 69 | 70 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 71 | { 72 | this.value = new BasicComplexVector(rows * columns); 73 | value.deserialize(0, rows * columns, @in); 74 | } 75 | 76 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 77 | { 78 | this.value.writeVectorToOutputStream(@out); 79 | } 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/data/BasicNanoTime.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | 7 | public class BasicNanoTime : BasicLong 8 | { 9 | private static string format = "HH:mm:ss.fffffff";// if format='c,it automatically omits the zeros, making it impossible to display all 9 digits. 10 | 11 | public BasicNanoTime(TimeSpan value) : base(Utils.countNanoseconds(value)) 12 | { 13 | checkTimeSpanToNanoTime(value); 14 | } 15 | 16 | 17 | public BasicNanoTime(ExtendedDataInput @in) : base(@in) 18 | { 19 | } 20 | 21 | public BasicNanoTime(long value) : base(value) 22 | { 23 | } 24 | 25 | public override DATA_CATEGORY getDataCategory() 26 | { 27 | return DATA_CATEGORY.TEMPORAL; 28 | } 29 | 30 | public override DATA_TYPE getDataType() 31 | { 32 | return DATA_TYPE.DT_NANOTIME; 33 | } 34 | 35 | public override object getObject() 36 | { 37 | return getValue(); 38 | } 39 | public new TimeSpan getValue() 40 | { 41 | if (isNull()) 42 | { 43 | return TimeSpan.MinValue; 44 | } 45 | else 46 | { 47 | return Utils.parseNanoTime(base.getValue()); 48 | } 49 | } 50 | 51 | public override object getTemporal() 52 | { 53 | return getValue(); 54 | } 55 | 56 | public long getInternalValue() 57 | { 58 | return base.getValue(); 59 | } 60 | 61 | public override string getString() 62 | { 63 | if (isNull()) 64 | { 65 | return ""; 66 | } 67 | else 68 | { 69 | DateTime dateTime = Utils.parseNanoTimestamp(base.getValue()); 70 | long last = (long)base.getValue() % 100; 71 | return dateTime.ToString(format) + last.ToString("00"); 72 | } 73 | } 74 | 75 | public override void setObject(object value) 76 | { 77 | if (value != null && value.GetType() == Type.GetType("System.TimeSpan")) 78 | { 79 | checkTimeSpanToNanoTime((TimeSpan)value); 80 | base.setObject(Utils.countNanoseconds((TimeSpan)value)); 81 | } 82 | } 83 | 84 | public static void checkTimeSpanToNanoTime(TimeSpan value){ 85 | if(value.Days != 0){ 86 | throw new TimeoutException("To convert BasicNanoTime, TimeSpan's days must equal zero. "); 87 | } 88 | } 89 | } 90 | 91 | } -------------------------------------------------------------------------------- /src/data/SymbolBaseCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | 4 | 5 | namespace dolphindb.data 6 | { 7 | using ExtendedDataInput = io.ExtendedDataInput; 8 | using ExtendedDataOutput = io.ExtendedDataOutput; 9 | 10 | public class SymbolBaseCollection 11 | { 12 | private IDictionary symbaseMap = new Dictionary(); 13 | private IDictionary existingBases; 14 | private SymbolBase lastSymbase = null; 15 | 16 | public virtual SymbolBase add(ExtendedDataInput @in) 17 | { 18 | int id = @in.readInt(); 19 | if (symbaseMap.ContainsKey(id)) 20 | { 21 | int size = @in.readInt(); 22 | if (size != 0) 23 | { 24 | throw new IOException("Invalid symbol base."); 25 | } 26 | lastSymbase = symbaseMap[id]; 27 | } 28 | else 29 | { 30 | SymbolBase cur = new SymbolBase(id, @in); 31 | symbaseMap[id] = cur; 32 | lastSymbase = cur; 33 | } 34 | return lastSymbase; 35 | } 36 | 37 | public virtual void write(ExtendedDataOutput @out, SymbolBase @base) 38 | { 39 | bool existing = false; 40 | int id = 0; 41 | if (existingBases == null) 42 | { 43 | existingBases = new Dictionary(); 44 | existingBases[@base] = 0; 45 | } 46 | else 47 | { 48 | int? curId = existingBases[@base]; 49 | if (curId != null) 50 | { 51 | existing = true; 52 | id = curId.Value; 53 | } 54 | else 55 | { 56 | id = existingBases.Count; 57 | existingBases[@base] = id; 58 | } 59 | } 60 | @out.writeInt(id); 61 | if (existing) 62 | { 63 | @out.writeInt(0); 64 | } 65 | else 66 | { 67 | int size = @base.size(); 68 | @out.writeInt(size); 69 | for (int i = 0; i < size; ++i) 70 | { 71 | @out.writeString(@base.getSymbol(i)); 72 | } 73 | } 74 | } 75 | 76 | public virtual SymbolBase LastSymbolBase 77 | { 78 | get 79 | { 80 | return lastSymbase; 81 | } 82 | } 83 | 84 | public virtual void clear() 85 | { 86 | symbaseMap.Clear(); 87 | lastSymbase = null; 88 | } 89 | } 90 | 91 | } -------------------------------------------------------------------------------- /test/compatibility_test/ha_test/ha_test.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using dolphindb; 7 | using dolphindb.data; 8 | 9 | namespace dolphindb_csharp_api_test.compatibility_test.ha_test 10 | { 11 | [TestClass] 12 | public class ha_test 13 | { 14 | private readonly string SERVER = "192.168.1.167"; 15 | private readonly int PORT = 18921; 16 | private readonly string USER = "admin"; 17 | private readonly string PASSWORD = "123456"; 18 | private readonly string CREATE_DFS_SCRIPT = "t = table(1:0, `date`time`sym`qty`price, [DATE,TIME,SYMBOL,INT,DOUBLE])" + 19 | "haStreamTable(2, t, `trades, 100000000)"; 20 | private readonly string DBNAME = "ha_test_db"; 21 | private readonly string TBNAME = "trades"; 22 | private readonly string WRITE_FUNCTION_SCRIPT = "def saveData(hatb, data){return tableInsert(hatb, data)}"; 23 | private readonly string[] HA_SITES = new string[] { "192.168.1.167:18921", "192.168.1.167:18922", "192.168.1.167:18923" }; 24 | private readonly string[] SYMBOLS = new string[] {"appl", "goog", "ms"}; 25 | [TestMethod] 26 | public void testKeepWritingTask() 27 | { 28 | 29 | //DBConnection conn = new DBConnection(); 30 | //conn.connect(SERVER, PORT, USER, PASSWORD, WRITE_FUNCTION_SCRIPT, true, HA_SITES); 31 | //int count = 0; 32 | //Random rnd = new Random(); 33 | //string funcScript = String.Format("saveData{{{0}}}", TBNAME); 34 | //Console.WriteLine(funcScript); 35 | //for (int i = 0; i <86400000; i++) 36 | //{ 37 | // IList args = new List(); 38 | // DateTime dt = new DateTime(2021, 1, 1); 39 | // BasicDateVector bdv = new BasicDateVector(new int[] { Utils.countDays(2021,4,7)}); 40 | // BasicTimeVector btv = new BasicTimeVector(new int[] {i}); 41 | // BasicStringVector bsv = new BasicStringVector(new string[] { SYMBOLS[rnd.Next(3)] }); 42 | // BasicIntVector bqv = new BasicIntVector(new int[] { rnd.Next(80,100) }); 43 | // BasicDoubleVector bpv = new BasicDoubleVector(new double[] {rnd.NextDouble() }); 44 | // List colNames = new List() { "date", "time", "sym", "qty", "price" }; 45 | // List cols = new List() {bdv, btv, bsv, bqv, bpv}; 46 | // BasicTable table1 = new BasicTable(colNames, cols); 47 | // args.Add(table1); 48 | 49 | // BasicInt re = (BasicInt)conn.run(funcScript, args); 50 | // Console.WriteLine(re.getInt()); 51 | //} 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/route/autoFitTableAppender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.data; 6 | using dolphindb.io; 7 | using dolphindb; 8 | using System.Collections; 9 | using System.Data; 10 | namespace dolphindb.route 11 | { 12 | public class autoFitTableAppender 13 | { 14 | private DBConnection conn; 15 | private bool asynTask; 16 | private string dbUrl; 17 | private string tableName; 18 | private string tableStr; 19 | Dictionary dataTypeMap; 20 | Dictionary extrasMap; 21 | bool supportDecimal; 22 | 23 | 24 | 25 | public autoFitTableAppender(string dbUrl, string tableName, bool asynTask,DBConnection conn) 26 | { 27 | this.dbUrl = dbUrl; 28 | this.tableName = tableName; 29 | this.asynTask = asynTask; 30 | this.conn = conn; 31 | conn.setasynTask(false); 32 | tableStr = dbUrl == "" ? tableName : "loadTable(\"" + dbUrl + "\", \"" + tableName + "\")"; 33 | BasicDictionary tableInfo = (BasicDictionary)conn.run("schema(" + tableStr + ")"); 34 | BasicTable colDefs; 35 | colDefs = ((BasicTable)tableInfo.get(new BasicString("colDefs"))); 36 | BasicStringVector names = (BasicStringVector)colDefs.getColumn("name"); 37 | BasicIntVector types = (BasicIntVector)colDefs.getColumn("typeInt"); 38 | supportDecimal = colDefs.getColumnNames().Contains("extra"); 39 | BasicIntVector extras = supportDecimal ? (BasicIntVector)colDefs.getColumn("extra") : null; 40 | int rows = names.rows(); 41 | 42 | this.dataTypeMap = new Dictionary(); 43 | this.extrasMap = new Dictionary(); 44 | for (int i = 0; i < rows; ++i) 45 | { 46 | dataTypeMap.Add(names.getString(i), (DATA_TYPE)types.getInt(i)); 47 | if(supportDecimal) extrasMap.Add(names.getString(i), extras.getInt(i)); 48 | } 49 | conn.setasynTask(asynTask); 50 | 51 | } 52 | 53 | public IEntity append(DataTable table) 54 | { 55 | BasicTable bt = Utils.fillSchema(table, dataTypeMap, extrasMap); 56 | List args = new List(1); 57 | args.Add(bt); 58 | string appendScript = "tableInsert{" + tableStr + "}"; 59 | return conn.run(appendScript, args); 60 | 61 | } 62 | 63 | public IEntity append(BasicTable table) 64 | { 65 | BasicTable bt = Utils.fillSchema(table, dataTypeMap, extrasMap); 66 | List args = new List(1); 67 | args.Add(bt); 68 | string appendScript = "tableInsert{" + tableStr + "}"; 69 | return conn.run(appendScript, args); 70 | } 71 | 72 | 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/data/AbstractScalar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.io; 3 | using System.Data; 4 | namespace dolphindb.data 5 | { 6 | public abstract class AbstractScalar : AbstractEntity, IScalar 7 | { 8 | public abstract void writeScalarToOutputStream(ExtendedDataOutput @out); 9 | 10 | public override DATA_FORM getDataForm() 11 | { 12 | return DATA_FORM.DF_SCALAR; 13 | } 14 | 15 | public int rows() 16 | { 17 | return 1; 18 | } 19 | 20 | public int columns() 21 | { 22 | return 1; 23 | } 24 | 25 | public void write(ExtendedDataOutput @out) 26 | { 27 | int flag = ((int)DATA_FORM.DF_SCALAR << 8) + (int)getDataType(); 28 | @out.writeShort(flag); 29 | if( getDataCategory() == DATA_CATEGORY.DENARY) 30 | { 31 | @out.writeInt(getScale()); 32 | } 33 | writeScalarToOutputStream(@out); 34 | } 35 | 36 | public string toString() 37 | { 38 | return getString(); 39 | } 40 | 41 | public virtual bool isNull() 42 | { 43 | throw new NotImplementedException(); 44 | } 45 | 46 | public virtual void setNull() 47 | { 48 | throw new NotImplementedException(); 49 | } 50 | 51 | public virtual Number getNumber() 52 | { 53 | throw new NotImplementedException(); 54 | } 55 | 56 | public virtual object getTemporal() 57 | { 58 | throw new NotImplementedException(); 59 | } 60 | 61 | public virtual DATA_CATEGORY getDataCategory() 62 | { 63 | throw new NotImplementedException(); 64 | } 65 | 66 | public virtual DATA_TYPE getDataType() 67 | { 68 | throw new NotImplementedException(); 69 | } 70 | 71 | public abstract string getString(); 72 | 73 | public virtual DataTable toDataTable() 74 | { 75 | DataTable dt = new DataTable(); 76 | dt.Columns.Add("dolphinScalar", Utils.getSystemType(getDataType())); 77 | DataRow dr = dt.NewRow(); 78 | dr[0] = Utils.getRowDataTableObject(this); 79 | dt.Rows.Add(dr); 80 | return dt; 81 | } 82 | 83 | public abstract object getObject(); 84 | 85 | public abstract void setObject(object value); 86 | 87 | public void writeCompressed(ExtendedDataOutput output) 88 | { 89 | throw new NotImplementedException(); 90 | } 91 | 92 | public abstract int hashBucket(int buckets); 93 | 94 | public virtual int getScale() 95 | { 96 | throw new NotImplementedException(); 97 | } 98 | 99 | public virtual int getExtraParamForType(){ 100 | return 0; 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /src/compression/LZ4/License.txt: -------------------------------------------------------------------------------- 1 | LZ4Sharp 2 | Copyright (C) 2011, Clayton Stangeland 3 | 4 | BSD License 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following disclaimer 14 | in the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | 30 | with parts in LZ4.cs from LZ4.c at http://code.google.com/p/lz4/ with license 31 | 32 | LZ4 - Fast LZ compression algorithm 33 | Copyright (C) 2011, Yann Collet. 34 | 35 | BSD License 36 | 37 | Redistribution and use in source and binary forms, with or without 38 | modification, are permitted provided that the following conditions are 39 | met: 40 | 41 | * Redistributions of source code must retain the above copyright 42 | notice, this list of conditions and the following disclaimer. 43 | * Redistributions in binary form must reproduce the above 44 | copyright notice, this list of conditions and the following disclaimer 45 | in the documentation and/or other materials provided with the 46 | distribution. 47 | 48 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 49 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 50 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 51 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 52 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 53 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 54 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 55 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 56 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 57 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 58 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/data/BasicIntMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | 9 | public class BasicIntMatrix : AbstractMatrix 10 | { 11 | private int[] values; 12 | 13 | public BasicIntMatrix(int rows, int columns) : base(rows, columns) 14 | { 15 | values = new int[rows * columns]; 16 | } 17 | 18 | public BasicIntMatrix(int rows, int columns, IList list) : base(rows, columns) 19 | { 20 | values = new int[rows * columns]; 21 | if (list == null || list.Count != columns) 22 | { 23 | throw new Exception("input list of arrays does not have " + columns + " columns"); 24 | } 25 | for (int i = 0; i < columns; ++i) 26 | { 27 | int[] array = list[i]; 28 | if (array == null || array.Length != rows) 29 | { 30 | throw new Exception("The length of array " + (i + 1) + " doesn't have " + rows + " elements"); 31 | } 32 | Array.Copy(array, 0, values, i * rows, rows); 33 | } 34 | } 35 | 36 | public BasicIntMatrix(ExtendedDataInput @in) : base(@in) 37 | { 38 | } 39 | 40 | public virtual void setInt(int row, int column, int value) 41 | { 42 | values[getIndex(row, column)] = value; 43 | } 44 | 45 | public virtual int getInt(int row, int column) 46 | { 47 | return values[getIndex(row, column)]; 48 | } 49 | 50 | public override bool isNull(int row, int column) 51 | { 52 | return values[getIndex(row, column)] == int.MinValue; 53 | } 54 | 55 | public override void setNull(int row, int column) 56 | { 57 | values[getIndex(row, column)] = int.MinValue; 58 | } 59 | 60 | public override IScalar get(int row, int column) 61 | { 62 | return new BasicInt(values[getIndex(row, column)]); 63 | } 64 | 65 | public override DATA_CATEGORY getDataCategory() 66 | { 67 | return DATA_CATEGORY.INTEGRAL; 68 | } 69 | 70 | public override DATA_TYPE getDataType() 71 | { 72 | return DATA_TYPE.DT_INT; 73 | } 74 | 75 | public override Type getElementClass() 76 | { 77 | return typeof(BasicInt); 78 | } 79 | 80 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 81 | { 82 | int size = rows * columns; 83 | values = new int[size]; 84 | for (int i = 0; i < size; ++i) 85 | { 86 | values[i] = @in.readInt(); 87 | } 88 | } 89 | 90 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 91 | { 92 | foreach (int value in values) 93 | { 94 | @out.writeInt(value); 95 | } 96 | } 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /dolphindb_csharpapi.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33815.320 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dolphindb_csharpapi", "src\dolphindb_csharpapi.csproj", "{F744DA92-D9F2-49BB-9783-F89E825CB307}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dolphindb_csharpapi_test", "test\dolphindb_csharpapi_test.csproj", "{9297EF6F-E380-423B-BA64-FE2907226FF8}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|x64.ActiveCfg = Debug|Any CPU 23 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|x64.Build.0 = Debug|Any CPU 24 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|x86.ActiveCfg = Debug|Any CPU 25 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|x86.Build.0 = Debug|Any CPU 26 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|x64.ActiveCfg = Release|Any CPU 29 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|x64.Build.0 = Release|Any CPU 30 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|x86.ActiveCfg = Release|Any CPU 31 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|x86.Build.0 = Release|Any CPU 32 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|x64.Build.0 = Debug|Any CPU 36 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|x86.Build.0 = Debug|Any CPU 38 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x64.ActiveCfg = Release|Any CPU 41 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x64.Build.0 = Release|Any CPU 42 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x86.ActiveCfg = Release|Any CPU 43 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {BD8FB1DE-3841-4F68-A643-A686A14E10BC} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /src/data/BasicShortMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicShortMatrix : AbstractMatrix 9 | { 10 | private short[] values; 11 | 12 | public BasicShortMatrix(int rows, int columns) : base(rows, columns) 13 | { 14 | values = new short[rows * columns]; 15 | } 16 | 17 | public BasicShortMatrix(int rows, int columns, IList list) : base(rows, columns) 18 | { 19 | values = new short[rows * columns]; 20 | if (list == null || list.Count != columns) 21 | { 22 | throw new Exception("input list of arrays does not have " + columns + " columns"); 23 | } 24 | for (int i = 0; i < columns; ++i) 25 | { 26 | short[] array = list[i]; 27 | if (array == null || array.Length != rows) 28 | { 29 | throw new Exception("The length of array " + (i + 1) + " doesn't have " + rows + " elements"); 30 | } 31 | Array.Copy(array, 0, values, i * rows, rows); 32 | } 33 | } 34 | 35 | public BasicShortMatrix(ExtendedDataInput @in) : base(@in) 36 | { 37 | } 38 | 39 | public virtual void setShort(int row, int column, short value) 40 | { 41 | values[getIndex(row, column)] = value; 42 | } 43 | 44 | public virtual short getShort(int row, int column) 45 | { 46 | return values[getIndex(row, column)]; 47 | } 48 | 49 | public override bool isNull(int row, int column) 50 | { 51 | return values[getIndex(row, column)] == short.MinValue; 52 | } 53 | 54 | public override void setNull(int row, int column) 55 | { 56 | values[getIndex(row, column)] = short.MinValue; 57 | } 58 | 59 | public override IScalar get(int row, int column) 60 | { 61 | return new BasicShort(values[getIndex(row, column)]); 62 | } 63 | 64 | public override DATA_CATEGORY getDataCategory() 65 | { 66 | return DATA_CATEGORY.INTEGRAL; 67 | } 68 | 69 | public override DATA_TYPE getDataType() 70 | { 71 | return DATA_TYPE.DT_SHORT; 72 | } 73 | 74 | public override Type getElementClass() 75 | { 76 | return typeof(BasicShort); 77 | } 78 | 79 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 80 | { 81 | int size = rows * columns; 82 | values = new short[size]; 83 | for (int i = 0; i < size; ++i) 84 | { 85 | values[i] = @in.readShort(); 86 | } 87 | } 88 | 89 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 90 | { 91 | foreach (short value in values) 92 | { 93 | @out.writeInt(value); 94 | } 95 | } 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /src/data/BasicFloatMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicFloatMatrix : AbstractMatrix 9 | { 10 | private float[] values; 11 | 12 | public BasicFloatMatrix(int rows, int columns) : base(rows, columns) 13 | { 14 | values = new float[rows * columns]; 15 | } 16 | 17 | public BasicFloatMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns) 18 | { 19 | values = new float[rows * columns]; 20 | if (listOfArrays == null || listOfArrays.Count != columns) 21 | { 22 | throw new Exception("input list of arrays does not have " + columns + " columns"); 23 | } 24 | for (int i = 0; i < columns; ++i) 25 | { 26 | float[] array = listOfArrays[i]; 27 | if (array == null || array.Length != rows) 28 | { 29 | throw new Exception("The length of array " + (i + 1) + " doesn't have " + rows + " elements"); 30 | } 31 | Array.Copy(array, 0, values, i * rows, rows); 32 | } 33 | } 34 | 35 | public BasicFloatMatrix(ExtendedDataInput @in) : base(@in) 36 | { 37 | } 38 | 39 | public virtual void setFloat(int row, int column, float value) 40 | { 41 | values[getIndex(row, column)] = value; 42 | } 43 | 44 | public virtual float getFloat(int row, int column) 45 | { 46 | return values[getIndex(row, column)]; 47 | } 48 | 49 | public override bool isNull(int row, int column) 50 | { 51 | return values[getIndex(row, column)] == -float.MaxValue; 52 | } 53 | 54 | public override void setNull(int row, int column) 55 | { 56 | values[getIndex(row, column)] = -float.MaxValue; 57 | } 58 | 59 | public override IScalar get(int row, int column) 60 | { 61 | return new BasicFloat(values[getIndex(row, column)]); 62 | } 63 | 64 | public override DATA_CATEGORY getDataCategory() 65 | { 66 | return DATA_CATEGORY.FLOATING; 67 | } 68 | 69 | public override DATA_TYPE getDataType() 70 | { 71 | return DATA_TYPE.DT_FLOAT; 72 | } 73 | 74 | public override Type getElementClass() 75 | { 76 | return typeof(BasicFloat); 77 | } 78 | 79 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 80 | { 81 | int size = rows * columns; 82 | values = new float[size]; 83 | for (int i = 0; i < size; ++i) 84 | { 85 | values[i] = @in.readFloat(); 86 | } 87 | } 88 | 89 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 90 | { 91 | foreach (float value in values) 92 | { 93 | @out.writeFloat(value); 94 | } 95 | } 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /src/data/BasicBooleanMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicBooleanMatrix : AbstractMatrix 8 | { 9 | private byte[] values; 10 | 11 | public BasicBooleanMatrix(int rows, int columns) : base(rows, columns) 12 | { 13 | values = new byte[rows * columns]; 14 | } 15 | 16 | public BasicBooleanMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns) 17 | { 18 | values = new byte[rows * columns]; 19 | if (listOfArrays == null || listOfArrays.Count != columns) 20 | { 21 | throw new Exception("input list of arrays does not have " + columns + " columns"); 22 | } 23 | for (int i = 0; i < columns; ++i) 24 | { 25 | byte[] array = listOfArrays[i]; 26 | if (array == null || array.Length != rows) 27 | { 28 | throw new Exception("The length of array " + (i + 1) + " doesn't have " + rows + " elements"); 29 | } 30 | Array.Copy(array, 0, values, i * rows, rows); 31 | } 32 | } 33 | 34 | public BasicBooleanMatrix(ExtendedDataInput @in) : base(@in) 35 | { 36 | } 37 | 38 | public virtual void setBoolean(int row, int column, bool value) 39 | { 40 | values[getIndex(row, column)] = value ? (byte)1 : (byte)0; 41 | } 42 | 43 | public virtual bool getBoolean(int row, int column) 44 | { 45 | return values[getIndex(row, column)] == 1; 46 | } 47 | 48 | public override bool isNull(int row, int column) 49 | { 50 | return values[getIndex(row, column)] == byte.MinValue; 51 | } 52 | 53 | public override void setNull(int row, int column) 54 | { 55 | values[getIndex(row, column)] = byte.MinValue; 56 | } 57 | 58 | public override IScalar get(int row, int column) 59 | { 60 | return new BasicBoolean(values[getIndex(row, column)]); 61 | } 62 | 63 | public override DATA_CATEGORY getDataCategory() 64 | { 65 | return DATA_CATEGORY.LOGICAL; 66 | } 67 | 68 | public override DATA_TYPE getDataType() 69 | { 70 | return DATA_TYPE.DT_BOOL; 71 | } 72 | 73 | public override Type getElementClass() 74 | { 75 | return typeof(BasicBoolean); 76 | } 77 | 78 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 79 | { 80 | int size = rows * columns; 81 | values = new byte[size]; 82 | for (int i = 0; i < size; ++i) 83 | { 84 | values[i] = @in.readByte(); 85 | } 86 | } 87 | 88 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 89 | { 90 | foreach (byte value in values) 91 | { 92 | @out.writeByte(value); 93 | } 94 | } 95 | } 96 | 97 | } -------------------------------------------------------------------------------- /src/data/BasicDoubleMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | 9 | public class BasicDoubleMatrix : AbstractMatrix 10 | { 11 | private double[] values; 12 | 13 | public BasicDoubleMatrix(int rows, int columns) : base(rows, columns) 14 | { 15 | values = new double[rows * columns]; 16 | } 17 | 18 | public BasicDoubleMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns) 19 | { 20 | values = new double[rows * columns]; 21 | if (listOfArrays == null || listOfArrays.Count != columns) 22 | { 23 | throw new Exception("input list of arrays does not have " + columns + " columns"); 24 | } 25 | for (int i = 0; i < columns; ++i) 26 | { 27 | double[] array = listOfArrays[i]; 28 | if (array == null || array.Length != rows) 29 | { 30 | throw new Exception("The length of array " + (i + 1) + " doesn't have " + rows + " elements"); 31 | } 32 | Array.Copy(array, 0, values, i * rows, rows); 33 | } 34 | } 35 | 36 | public BasicDoubleMatrix(ExtendedDataInput @in) : base(@in) 37 | { 38 | } 39 | 40 | public virtual void setDouble(int row, int column, double value) 41 | { 42 | values[getIndex(row, column)] = value; 43 | } 44 | 45 | public virtual double getDouble(int row, int column) 46 | { 47 | return values[getIndex(row, column)]; 48 | } 49 | 50 | public override bool isNull(int row, int column) 51 | { 52 | return values[getIndex(row, column)] == -double.MaxValue; 53 | } 54 | 55 | public override void setNull(int row, int column) 56 | { 57 | values[getIndex(row, column)] = -double.MaxValue; 58 | } 59 | 60 | public override IScalar get(int row, int column) 61 | { 62 | return new BasicDouble(values[getIndex(row, column)]); 63 | } 64 | 65 | public override DATA_CATEGORY getDataCategory() 66 | { 67 | return DATA_CATEGORY.FLOATING; 68 | } 69 | 70 | public override DATA_TYPE getDataType() 71 | { 72 | return DATA_TYPE.DT_DOUBLE; 73 | } 74 | 75 | public override Type getElementClass() 76 | { 77 | return typeof(BasicDouble); 78 | } 79 | 80 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 81 | { 82 | int size = rows * columns; 83 | values = new double[size]; 84 | for (int i = 0; i < size; ++i) 85 | { 86 | values[i] = @in.readDouble(); 87 | } 88 | } 89 | 90 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 91 | { 92 | foreach (double value in values) 93 | { 94 | @out.writeDouble(value); 95 | } 96 | } 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /src/data/BasicLongMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | 9 | public class BasicLongMatrix : AbstractMatrix 10 | { 11 | private long[] values; 12 | 13 | public BasicLongMatrix(int rows, int columns) : base(rows, columns) 14 | { 15 | values = new long[rows * columns]; 16 | } 17 | 18 | public BasicLongMatrix(int rows, int columns, IList list) : base(rows, columns) 19 | { 20 | values = new long[rows * columns]; 21 | if (list == null || list.Count != columns) 22 | { 23 | throw new Exception("input list of arrays does not have " + columns + " columns"); 24 | } 25 | for (int i = 0; i < columns; ++i) 26 | { 27 | long[] array = list[i]; 28 | if (array == null || array.Length != rows) 29 | { 30 | throw new Exception("The length of array " + (i + 1) + " doesn't have " + rows + " elements"); 31 | } 32 | Array.Copy(array, 0, values, i * rows, rows); 33 | } 34 | } 35 | 36 | public BasicLongMatrix(ExtendedDataInput @in) : base(@in) 37 | { 38 | } 39 | 40 | public virtual void setLong(int row, int column, long value) 41 | { 42 | values[getIndex(row, column)] = value; 43 | } 44 | 45 | public virtual long getLong(int row, int column) 46 | { 47 | return values[getIndex(row, column)]; 48 | } 49 | 50 | public override bool isNull(int row, int column) 51 | { 52 | return values[getIndex(row, column)] == long.MinValue; 53 | } 54 | 55 | public override void setNull(int row, int column) 56 | { 57 | values[getIndex(row, column)] = long.MinValue; 58 | } 59 | 60 | public override IScalar get(int row, int column) 61 | { 62 | return new BasicLong(values[getIndex(row, column)]); 63 | } 64 | 65 | public override DATA_CATEGORY getDataCategory() 66 | { 67 | return DATA_CATEGORY.INTEGRAL; 68 | } 69 | 70 | public override DATA_TYPE getDataType() 71 | { 72 | return DATA_TYPE.DT_LONG; 73 | } 74 | 75 | public override Type getElementClass() 76 | { 77 | return typeof(BasicLong); 78 | } 79 | 80 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 81 | { 82 | int size = rows * columns; 83 | values = new long[size]; 84 | for (int i = 0; i < size; ++i) 85 | { 86 | values[i] = @in.readLong(); 87 | } 88 | } 89 | 90 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 91 | { 92 | foreach (long value in values) 93 | { 94 | @out.writeLong(value); 95 | } 96 | } 97 | 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /src/data/Number.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace dolphindb.data 4 | { 5 | public class Number 6 | { 7 | private bool _boolVal; 8 | private int _intVal; 9 | private double _doubleVal; 10 | private float _floatVal; 11 | private long _longVal; 12 | private short _shortVal; 13 | private decimal _decimalVal; 14 | private DATA_TYPE _type; 15 | 16 | public Number(int val) 17 | { 18 | _intVal = val; 19 | _type = DATA_TYPE.DT_INT; 20 | } 21 | public Number(bool val) 22 | { 23 | _boolVal = val; 24 | _type = DATA_TYPE.DT_BOOL; 25 | } 26 | 27 | public Number(double val) 28 | { 29 | _doubleVal = val; 30 | _type = DATA_TYPE.DT_DOUBLE; 31 | } 32 | 33 | public Number(float val) 34 | { 35 | _floatVal = val; 36 | _type = DATA_TYPE.DT_FLOAT; 37 | } 38 | 39 | public Number(long val) 40 | { 41 | _longVal = val; 42 | _type = DATA_TYPE.DT_LONG; 43 | } 44 | public Number(short val) 45 | { 46 | _shortVal = val; 47 | _type = DATA_TYPE.DT_SHORT; 48 | } 49 | 50 | public Number(decimal val) 51 | { 52 | _decimalVal = val; 53 | _type = DATA_TYPE.DT_DECIMAL32; 54 | } 55 | 56 | public byte byteValue() 57 | { 58 | switch (_type) 59 | { 60 | case DATA_TYPE.DT_BOOL: 61 | return Convert.ToByte(_boolVal); 62 | case DATA_TYPE.DT_INT: 63 | return Convert.ToByte(_intVal); 64 | case DATA_TYPE.DT_DOUBLE: 65 | return Convert.ToByte(_doubleVal); 66 | case DATA_TYPE.DT_FLOAT: 67 | return Convert.ToByte(_floatVal); 68 | case DATA_TYPE.DT_LONG: 69 | return Convert.ToByte(_longVal); 70 | case DATA_TYPE.DT_SHORT: 71 | return Convert.ToByte(_shortVal); 72 | case DATA_TYPE.DT_DECIMAL32: 73 | return Convert.ToByte(_decimalVal); 74 | default: 75 | throw new InvalidCastException(); 76 | } 77 | } 78 | 79 | public double doubleValue() 80 | { 81 | return _doubleVal; 82 | } 83 | 84 | public float floatValue() 85 | { 86 | return _floatVal; 87 | } 88 | 89 | public int intValue() 90 | { 91 | return _intVal; 92 | } 93 | 94 | public long longValue() 95 | { 96 | return _longVal; 97 | } 98 | 99 | public short shortValue() 100 | { 101 | return _shortVal; 102 | } 103 | 104 | public bool boolValue() 105 | { 106 | return _boolVal; 107 | } 108 | 109 | public decimal decimalValue() 110 | { 111 | return _decimalVal; 112 | } 113 | 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/io/Long2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace dolphindb.io 4 | { 5 | 6 | public class Long2 7 | { 8 | public long high; 9 | public long low; 10 | 11 | public Long2(long high, long low) 12 | { 13 | this.high = high; 14 | this.low = low; 15 | } 16 | 17 | public bool isNull() 18 | { 19 | return high == 0 && low == 0; 20 | } 21 | 22 | public void setNull() 23 | { 24 | high = 0; 25 | low = 0; 26 | } 27 | 28 | public bool equals(object o) 29 | { 30 | if (!(o is Long2) || o == null) 31 | return false; 32 | else 33 | return high == ((Long2)o).high && low == ((Long2)o).low; 34 | } 35 | 36 | public int hashCode() 37 | { 38 | return (int)(high ^ low >> 32); 39 | } 40 | 41 | public int hashBucket(int buckets) 42 | { 43 | int m = 0x5bd1e995; 44 | int r = 24; 45 | int h = 16; 46 | 47 | int k1 = (int)(low & 4294967295L); 48 | int k2 = (int)((ulong)low >> 32); 49 | int k3 = (int)(high & 4294967295L); 50 | int k4 = (int)((ulong)high >> 32); 51 | 52 | k1 *= m; 53 | k1 ^= (int)((uint)k1 >> r); 54 | k1 *= m; 55 | 56 | k2 *= m; 57 | k2 ^= (int)((uint)k2 >> r); 58 | k2 *= m; 59 | 60 | k3 *= m; 61 | k3 ^= (int)((uint)k3 >> r); 62 | k3 *= m; 63 | 64 | k4 *= m; 65 | k4 ^= (int)((uint)k4 >> r); 66 | k4 *= m; 67 | 68 | // Mix 4 bytes at a time into the hash 69 | h *= m; 70 | h ^= k1; 71 | h *= m; 72 | h ^= k2; 73 | h *= m; 74 | h ^= k3; 75 | h *= m; 76 | h ^= k4; 77 | 78 | // Do a few final mixes of the hash to ensure the last few 79 | // bytes are well-incorporated. 80 | h ^= (int)((uint)h >> 13); 81 | h *= m; 82 | h ^= (int)((uint)h >> 15); 83 | 84 | if (h >= 0) 85 | return h % buckets; 86 | else 87 | { 88 | return (int)((4294967296L + h) % buckets); 89 | } 90 | } 91 | 92 | public override bool Equals(object o) 93 | { 94 | if (!(o is Long2) || o == null) 95 | { 96 | return false; 97 | } 98 | else 99 | { 100 | if (this.low != ((Long2)o).low || this.high != ((Long2)o).high) 101 | { 102 | return false; 103 | } 104 | else 105 | return true; 106 | } 107 | } 108 | 109 | public override int GetHashCode() 110 | { 111 | int hashCode = -1466551034; 112 | hashCode = hashCode * -1521134295 + high.GetHashCode(); 113 | hashCode = hashCode * -1521134295 + low.GetHashCode(); 114 | return hashCode; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/data/BasicByteMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicByteMatrix : AbstractMatrix 9 | { 10 | private byte[] values; 11 | 12 | public BasicByteMatrix(int rows, int columns) : base(rows, columns) 13 | { 14 | values = new byte[rows * columns]; 15 | } 16 | 17 | public BasicByteMatrix(int rows, int columns, IList listOfArrays) : base(rows, columns) 18 | { 19 | values = new byte[rows * columns]; 20 | if (listOfArrays == null || listOfArrays.Count != columns) 21 | { 22 | throw new Exception("input list of arrays does not have " + columns + " columns"); 23 | } 24 | for (int i = 0; i < columns; ++i) 25 | { 26 | byte[] array = listOfArrays[i]; 27 | if (array == null || array.Length != rows) 28 | { 29 | throw new Exception("The length of array " + (i + 1) + " doesn't have " + rows + " elements"); 30 | } 31 | Array.Copy(array, 0, values, i * rows, rows); 32 | } 33 | } 34 | 35 | 36 | public BasicByteMatrix(ExtendedDataInput @in) : base(@in) 37 | { 38 | } 39 | 40 | public virtual void setInt(int row, int column, byte value) 41 | { 42 | values[getIndex(row, column)] = value; 43 | } 44 | 45 | public virtual byte getByte(int row, int column) 46 | { 47 | return values[getIndex(row, column)]; 48 | } 49 | 50 | public override bool isNull(int row, int column) 51 | { 52 | return values[getIndex(row, column)] == byte.MinValue; 53 | } 54 | 55 | public override void setNull(int row, int column) 56 | { 57 | values[getIndex(row, column)] = byte.MinValue; 58 | } 59 | 60 | public override IScalar get(int row, int column) 61 | { 62 | return new BasicByte(values[getIndex(row, column)]); 63 | } 64 | 65 | public override DATA_CATEGORY getDataCategory() 66 | { 67 | return DATA_CATEGORY.INTEGRAL; 68 | } 69 | 70 | public override DATA_TYPE getDataType() 71 | { 72 | return DATA_TYPE.DT_BYTE; 73 | } 74 | 75 | public override Type getElementClass() 76 | { 77 | return typeof(BasicByte); 78 | } 79 | 80 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 81 | { 82 | int size = rows * columns; 83 | values = new byte[size]; 84 | for (int i = 0; i < size; ++i) 85 | { 86 | values[i] = @in.readByte(); 87 | } 88 | } 89 | 90 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 91 | { 92 | foreach (byte value in values) 93 | { 94 | @out.writeByte(value); 95 | } 96 | } 97 | 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /src/streaming/TopicPoller.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.Concurrent; 3 | using System; 4 | using System.Linq; 5 | using System.Diagnostics; 6 | 7 | namespace dolphindb.streaming 8 | { 9 | public class TopicPoller 10 | { 11 | private BlockingCollection> queue; 12 | private List cache = new List(); 13 | 14 | public TopicPoller(BlockingCollection> queue) 15 | { 16 | this.queue = queue; 17 | } 18 | 19 | private void fillCache(long timeout) 20 | { 21 | cache = new List(); 22 | List list = new List(); 23 | int count = queue.Count; 24 | for (int i = 0; i < count; i++) 25 | { 26 | if (timeout > 0) 27 | queue.TryTake(out list, (int)timeout); 28 | else 29 | list = queue.Take(); 30 | cache.AddRange(list); 31 | } 32 | } 33 | 34 | public List poll(long timeout) 35 | { 36 | if (cache.Count == 0) 37 | { 38 | fillCache(timeout); 39 | } 40 | //List cachedMessages = cache; 41 | List cachedMessages = cache; 42 | cache = new List(); 43 | return cachedMessages == null ? new List() : cachedMessages; 44 | } 45 | 46 | public List poll(long timeout, int size) 47 | { 48 | if (size <= 0) 49 | throw new Exception("Size must be greater than zero"); 50 | List messages = new List(cache); 51 | cache.Clear(); 52 | DateTime now = System.DateTime.Now; 53 | DateTime end = now.AddTicks(timeout * 10000); 54 | while(messages.Count < size && System.DateTime.Now < end) 55 | { 56 | try 57 | { 58 | long mileSeconds = (end.Ticks - System.DateTime.Now.Ticks) / 10000; 59 | List tmp = new List(); 60 | queue.TryTake(out tmp, (int)mileSeconds); 61 | if(tmp != null) 62 | { 63 | messages.AddRange(tmp); 64 | } 65 | }catch(Exception) 66 | { 67 | return messages; 68 | } 69 | } 70 | return messages; 71 | } 72 | 73 | public IMessage take() 74 | { 75 | while (true) 76 | { 77 | if (cache.Count != 0) 78 | { 79 | IMessage message = cache[0]; 80 | cache.Remove(message); 81 | return message; 82 | } 83 | try 84 | { 85 | List tmp = queue.Take(); 86 | if (tmp != null) 87 | { 88 | cache.AddRange(tmp); 89 | } 90 | } 91 | catch (Exception) 92 | { 93 | return null; 94 | } 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/data/BasicShort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.io; 3 | 4 | namespace dolphindb.data 5 | { 6 | 7 | public class BasicShort : AbstractScalar, IComparable 8 | { 9 | private short value; 10 | static string formatStr = "0"; 11 | 12 | public BasicShort(short value) 13 | { 14 | this.value = value; 15 | } 16 | 17 | public BasicShort(ExtendedDataInput @in) 18 | { 19 | value = @in.readShort(); 20 | } 21 | 22 | public virtual short getValue() 23 | { 24 | return value; 25 | } 26 | 27 | public override bool isNull() 28 | { 29 | return value == short.MinValue; 30 | } 31 | 32 | public override void setNull() 33 | { 34 | value = short.MinValue; 35 | } 36 | 37 | public override DATA_CATEGORY getDataCategory() 38 | { 39 | return DATA_CATEGORY.INTEGRAL; 40 | } 41 | 42 | public override DATA_TYPE getDataType() 43 | { 44 | return DATA_TYPE.DT_SHORT; 45 | } 46 | 47 | public override Number getNumber() 48 | { 49 | if (isNull()) 50 | { 51 | return null; 52 | } 53 | else 54 | { 55 | return new Number(value); 56 | } 57 | } 58 | 59 | public override object getTemporal() 60 | { 61 | throw new Exception("Imcompatible data type"); 62 | } 63 | 64 | public override string getString() 65 | { 66 | if (isNull()) 67 | { 68 | return ""; 69 | } 70 | else 71 | { 72 | return value.ToString(formatStr); 73 | } 74 | } 75 | 76 | public override bool Equals(object o) 77 | { 78 | if (!(o is BasicShort) || o == null) 79 | { 80 | return false; 81 | } 82 | else 83 | { 84 | return value == ((BasicShort)o).value; 85 | } 86 | } 87 | 88 | public override int GetHashCode() 89 | { 90 | return (new short?(value)).GetHashCode(); 91 | } 92 | 93 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 94 | { 95 | @out.writeShort(value); 96 | } 97 | 98 | public virtual int CompareTo(BasicShort o) 99 | { 100 | return value.CompareTo(o.value); 101 | } 102 | 103 | public override object getObject() 104 | { 105 | return getValue(); 106 | } 107 | 108 | public override void setObject(object value) 109 | { 110 | this.value = Convert.ToInt16(value); 111 | } 112 | 113 | public override int hashBucket(int buckets) 114 | { 115 | if (value >= 0) 116 | return value % buckets; 117 | else if (value == short.MinValue) 118 | return -1; 119 | else 120 | { 121 | return (int)((4294967296L + value) % buckets); 122 | } 123 | } 124 | } 125 | 126 | } -------------------------------------------------------------------------------- /src/data/BasicStringMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | 9 | public class BasicStringMatrix : AbstractMatrix 10 | { 11 | private string[] values; 12 | private bool isSymbol = false; 13 | 14 | public BasicStringMatrix(int rows, int columns) : base(rows, columns) 15 | { 16 | values = new string[rows * columns]; 17 | } 18 | 19 | public BasicStringMatrix(int rows, int columns, IList list) : base(rows, columns) 20 | { 21 | values = new string[rows * columns]; 22 | if (list == null || list.Count != columns) 23 | { 24 | throw new Exception("input list of arrays does not have " + columns + " columns"); 25 | } 26 | for (int i = 0; i < columns; ++i) 27 | { 28 | string[] array = list[i]; 29 | if (array == null || array.Length != rows) 30 | { 31 | throw new Exception("The length of array " + (i + 1) + " doesn't have " + rows + " elements"); 32 | } 33 | Array.Copy(array, 0, values, i * rows, rows); 34 | } 35 | } 36 | 37 | public BasicStringMatrix(ExtendedDataInput @in, bool isSymbol) : base(@in) 38 | { 39 | this.isSymbol = isSymbol; 40 | } 41 | 42 | public virtual void setString(int row, int column, string value) 43 | { 44 | values[getIndex(row, column)] = value; 45 | } 46 | 47 | public virtual string getString(int row, int column) 48 | { 49 | return values[getIndex(row, column)]; 50 | } 51 | 52 | public override bool isNull(int row, int column) 53 | { 54 | return values[getIndex(row, column)].Length == 0; 55 | } 56 | 57 | public override void setNull(int row, int column) 58 | { 59 | values[getIndex(row, column)] = ""; 60 | } 61 | 62 | public override IScalar get(int row, int column) 63 | { 64 | return new BasicString(values[getIndex(row, column)]); 65 | } 66 | 67 | public override DATA_CATEGORY getDataCategory() 68 | { 69 | return DATA_CATEGORY.LITERAL; 70 | } 71 | 72 | public override DATA_TYPE getDataType() 73 | { 74 | return isSymbol ? DATA_TYPE.DT_SYMBOL : DATA_TYPE.DT_STRING; 75 | } 76 | 77 | public override Type getElementClass() 78 | { 79 | return typeof(BasicString); 80 | } 81 | 82 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 83 | { 84 | int size = rows * columns; 85 | values = new string[size]; 86 | for (int i = 0; i < size; ++i) 87 | { 88 | values[i] = @in.readString(); 89 | } 90 | } 91 | 92 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 93 | { 94 | foreach (string value in values) 95 | { 96 | @out.writeString(value); 97 | } 98 | } 99 | } 100 | 101 | } -------------------------------------------------------------------------------- /src/data/BasicByte.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.io; 3 | 4 | namespace dolphindb.data 5 | { 6 | 7 | public class BasicByte : AbstractScalar, IComparable 8 | { 9 | private byte value; 10 | static string formatStr = "0"; 11 | 12 | public BasicByte(byte value) 13 | { 14 | this.value = value; 15 | } 16 | 17 | public BasicByte(ExtendedDataInput @in) 18 | { 19 | value = @in.readByte(); 20 | } 21 | 22 | public virtual byte getValue() 23 | { 24 | return value; 25 | } 26 | 27 | public override bool isNull() 28 | { 29 | return value == 128; 30 | } 31 | 32 | public override void setNull() 33 | { 34 | value = 128; 35 | } 36 | 37 | public override DATA_CATEGORY getDataCategory() 38 | { 39 | return DATA_CATEGORY.INTEGRAL; 40 | } 41 | 42 | public override DATA_TYPE getDataType() 43 | { 44 | return DATA_TYPE.DT_BYTE; 45 | } 46 | 47 | public override Number getNumber() 48 | { 49 | if (isNull()) 50 | return null; 51 | else 52 | return new Number(value); 53 | } 54 | 55 | 56 | public override object getTemporal() 57 | { 58 | throw new Exception("Imcompatible data type"); 59 | } 60 | 61 | 62 | public override string ToString() 63 | { 64 | return getString(); 65 | } 66 | public override string getString() 67 | { 68 | if (isNull()) 69 | { 70 | return ""; 71 | } 72 | else if (value > 31 && value < 127) 73 | { 74 | return "'" + ((char)value).ToString() + "'"; 75 | } 76 | else 77 | { 78 | return value.ToString(formatStr); 79 | } 80 | } 81 | 82 | public override bool Equals(object o) 83 | { 84 | if (!(o is BasicByte) || o == null) 85 | { 86 | return false; 87 | } 88 | else 89 | { 90 | return value == ((BasicByte)o).value; 91 | } 92 | } 93 | 94 | public override int GetHashCode() 95 | { 96 | return (new byte?(value)).GetHashCode(); 97 | } 98 | 99 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 100 | { 101 | @out.writeByte(value); 102 | } 103 | 104 | public virtual int CompareTo(BasicByte o) 105 | { 106 | return value.CompareTo(o.value); 107 | } 108 | 109 | public override object getObject() 110 | { 111 | return getValue(); 112 | } 113 | 114 | public override void setObject(object value) 115 | { 116 | this.value = Convert.ToByte(value); 117 | } 118 | 119 | public override int hashBucket(int buckets) 120 | { 121 | if (value > 0) 122 | return value % buckets; 123 | else 124 | return -1; 125 | 126 | } 127 | } 128 | 129 | } -------------------------------------------------------------------------------- /src/data/BasicBoolean.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using dolphindb.io; 3 | using System; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicBoolean : AbstractScalar, IComparable 9 | { 10 | private byte value; 11 | 12 | public BasicBoolean(bool value) 13 | { 14 | this.value = value ? (byte)1 : (byte)0; 15 | } 16 | 17 | public BasicBoolean(ExtendedDataInput @in) 18 | { 19 | value = @in.readByte(); 20 | } 21 | 22 | protected internal BasicBoolean(byte value) 23 | { 24 | this.value = value; 25 | } 26 | 27 | public virtual bool getValue() 28 | { 29 | return value != 0; 30 | } 31 | 32 | public override bool isNull() 33 | { 34 | return value == 128; 35 | } 36 | 37 | public override void setNull() 38 | { 39 | value = 128; 40 | } 41 | 42 | public override DATA_CATEGORY getDataCategory() 43 | { 44 | return DATA_CATEGORY.LOGICAL; 45 | } 46 | 47 | public override DATA_TYPE getDataType() 48 | { 49 | return DATA_TYPE.DT_BOOL; 50 | } 51 | 52 | public override Number getNumber() 53 | { 54 | 55 | if (isNull()) 56 | { 57 | return null; 58 | } 59 | else 60 | { 61 | return new Number(getValue()); 62 | } 63 | } 64 | 65 | public override object getTemporal() 66 | { 67 | throw new Exception("Imcompatible data type"); 68 | } 69 | 70 | public override string getString() 71 | { 72 | if (isNull()) 73 | { 74 | return ""; 75 | } 76 | else 77 | { 78 | if (getValue()) return "true"; 79 | else return "false"; 80 | } 81 | } 82 | 83 | public override bool Equals(object o) 84 | { 85 | if (!(o is BasicBoolean) || o == null) 86 | { 87 | return false; 88 | } 89 | else 90 | { 91 | return value == ((BasicBoolean)o).value; 92 | } 93 | } 94 | 95 | public override int GetHashCode() 96 | { 97 | return (new byte?(value)).GetHashCode(); 98 | } 99 | 100 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 101 | { 102 | @out.writeByte(value); 103 | } 104 | 105 | public virtual int CompareTo(BasicBoolean o) 106 | { 107 | return value.CompareTo(o.value); 108 | } 109 | 110 | public override object getObject() 111 | { 112 | return getValue(); 113 | } 114 | 115 | public override void setObject(object value) 116 | { 117 | this.value = Convert.ToByte(value); 118 | } 119 | 120 | public byte getByte() 121 | { 122 | return value; 123 | } 124 | public override int hashBucket(int buckets) 125 | { 126 | throw new NotImplementedException(); 127 | } 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /src/data/BasicFloat.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | 4 | namespace dolphindb.data 5 | { 6 | /// 7 | /// 8 | /// Corresponds to DolphinDB float scalar 9 | /// 10 | /// 11 | 12 | public class BasicFloat : AbstractScalar, IComparable 13 | { 14 | private readonly string df1 = "0.00000000"; 15 | private float value; 16 | 17 | public BasicFloat(float value) 18 | { 19 | this.value = value; 20 | } 21 | 22 | public BasicFloat(ExtendedDataInput @in) 23 | { 24 | value = @in.readFloat(); 25 | } 26 | 27 | public virtual float getValue() 28 | { 29 | return value; 30 | } 31 | 32 | public override bool isNull() 33 | { 34 | return value == -float.MaxValue; 35 | } 36 | 37 | public override void setNull() 38 | { 39 | value = -float.MaxValue; 40 | } 41 | 42 | public override DATA_CATEGORY getDataCategory() 43 | { 44 | return DATA_CATEGORY.FLOATING; 45 | } 46 | 47 | public override DATA_TYPE getDataType() 48 | { 49 | return DATA_TYPE.DT_FLOAT; 50 | } 51 | 52 | public override Number getNumber() 53 | { 54 | if (isNull()) 55 | { 56 | return null; 57 | } 58 | else 59 | { 60 | return new Number(value); 61 | } 62 | } 63 | 64 | public override object getTemporal() 65 | { 66 | throw new Exception("Imcompatible data type"); 67 | } 68 | 69 | public override string getString() 70 | { 71 | if (isNull()) 72 | { 73 | return ""; 74 | } 75 | else if (float.IsNaN(value) || float.IsInfinity(value)) 76 | { 77 | return value.ToString(); 78 | } 79 | else 80 | { 81 | return value.ToString(df1); 82 | } 83 | } 84 | 85 | public override bool Equals(object o) 86 | { 87 | if (!(o is BasicFloat) || o == null) 88 | { 89 | return false; 90 | } 91 | else 92 | { 93 | return value == ((BasicFloat)o).value; 94 | } 95 | } 96 | 97 | public override int GetHashCode() 98 | { 99 | return (new float?(value)).GetHashCode(); 100 | } 101 | 102 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 103 | { 104 | @out.writeFloat(value); 105 | } 106 | 107 | public virtual int CompareTo(BasicFloat o) 108 | { 109 | return value.CompareTo(o.value); 110 | } 111 | public override object getObject() 112 | { 113 | return getValue(); 114 | } 115 | 116 | public override void setObject(object value) 117 | { 118 | this.value = Convert.ToSingle(value); 119 | } 120 | 121 | public override int hashBucket(int buckets) 122 | { 123 | throw new NotImplementedException(); 124 | } 125 | } 126 | 127 | } -------------------------------------------------------------------------------- /src/data/BasicPoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dolphindb.io; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicPoint : AbstractScalar 8 | { 9 | 10 | protected Double2 value; 11 | 12 | public BasicPoint(double x, double y) 13 | { 14 | value = new Double2(x, y); 15 | } 16 | 17 | public BasicPoint(ExtendedDataInput @in) 18 | { 19 | value = @in.readDouble2(); 20 | } 21 | 22 | public Double2 getDouble2() 23 | { 24 | return value; 25 | } 26 | 27 | 28 | public override bool isNull() 29 | { 30 | return value.isNull(); 31 | } 32 | 33 | 34 | public override void setNull() 35 | { 36 | value = new Double2(-double.MaxValue, -double.MaxValue); 37 | } 38 | 39 | public double getX() 40 | { 41 | return value.x; 42 | } 43 | 44 | public double getY() 45 | { 46 | return value.y; 47 | } 48 | 49 | public override Number getNumber() 50 | { 51 | throw new Exception("Imcompatible data type"); 52 | } 53 | 54 | public override object getObject() 55 | { 56 | throw new NotImplementedException(); 57 | } 58 | 59 | public override void setObject(object value) 60 | { 61 | throw new NotImplementedException(); 62 | } 63 | public override Object getTemporal() 64 | { 65 | throw new Exception("Imcompatible data type"); 66 | } 67 | 68 | public override DATA_CATEGORY getDataCategory() 69 | { 70 | return DATA_CATEGORY.BINARY; 71 | } 72 | public override DATA_TYPE getDataType() 73 | { 74 | return DATA_TYPE.DT_POINT; 75 | } 76 | 77 | public override String getString() 78 | { 79 | if (isNull()) 80 | { 81 | return "(, )"; 82 | } 83 | else 84 | { 85 | return "(" + value.x + ", " + value.y + ")"; 86 | } 87 | } 88 | 89 | public bool equals(Object o) 90 | { 91 | if (!(o is BasicPoint) || o == null) 92 | return false; 93 | else 94 | return value.equals(((BasicPoint)o).value); 95 | } 96 | 97 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 98 | { 99 | @out.writeDouble2(value); 100 | } 101 | 102 | public Double2 getValue() 103 | { 104 | return value; 105 | } 106 | 107 | public override int hashBucket(int buckets) 108 | { 109 | return value.hashBucket(buckets); 110 | } 111 | 112 | public override bool Equals(object o) 113 | { 114 | if (!(o is BasicPoint) || o == null) 115 | { 116 | return false; 117 | } 118 | else 119 | { 120 | return getValue().equals(((BasicPoint)o).getValue()); 121 | } 122 | } 123 | 124 | public override int GetHashCode() 125 | { 126 | return value.GetHashCode(); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/BasicDBTask.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------------- 2 | // Copyright © 2021 DolphinDB Inc. 3 | // Date : 2021.01.21 4 | // Author : zhikun.luo 5 | //------------------------------------------------------------------------------------------- 6 | 7 | using dolphindb.data; 8 | using System.Collections.Generic; 9 | using System; 10 | using System.Threading; 11 | using dolphindb.io; 12 | 13 | namespace dolphindb 14 | { 15 | public class BasicDBTask:IDBTask 16 | { 17 | private IEntity result = null; 18 | private string errMsg = null; 19 | private bool successful = false; 20 | private string script; 21 | private List args; 22 | private bool clearMemory_; 23 | private int priority_; 24 | private int parallelism_; 25 | private DBConnection conn; 26 | private WaitHandle waitHandle = new AutoResetEvent(false); 27 | private Semaphore semaphore = new Semaphore(1,1); 28 | 29 | public void waitFor() 30 | { 31 | semaphore.WaitOne(); 32 | } 33 | public void finish() 34 | { 35 | semaphore.Release(); 36 | } 37 | public BasicDBTask(string script, List args, int priority = 4, int parallelism = 64, bool clearMemory = false) 38 | { 39 | semaphore.WaitOne(); 40 | this.script = script; 41 | this.args = args; 42 | this.clearMemory_ = clearMemory; 43 | this.priority_ = priority; 44 | this.parallelism_ = parallelism; 45 | } 46 | public BasicDBTask(string script, int priority = 4, int parallelism = 64, bool clearMemory = false) 47 | { 48 | semaphore.WaitOne(); 49 | this.script = script; 50 | this.clearMemory_ = clearMemory; 51 | this.priority_ = priority; 52 | this.parallelism_ = parallelism; 53 | } 54 | public IEntity call() 55 | { 56 | try 57 | { 58 | if (args != null) 59 | result = conn.run(script, args, priority_, parallelism_, 0, clearMemory_); 60 | else 61 | result = conn.run(script, priority_, parallelism_, 0, clearMemory_); 62 | errMsg = null; 63 | successful = true; 64 | return result; 65 | } 66 | catch(Exception t) 67 | { 68 | successful = false; 69 | result = null; 70 | errMsg = t.Message; 71 | return null; 72 | } 73 | } 74 | public void setDBConnection(DBConnection conn) 75 | { 76 | this.conn = conn; 77 | } 78 | public IEntity getResults() 79 | { 80 | return result; 81 | } 82 | public string getErrorMsg() 83 | { 84 | return errMsg; 85 | } 86 | public bool isSuccessful() 87 | { 88 | return successful; 89 | } 90 | 91 | public bool isFinished() 92 | { 93 | if(successful || errMsg != null) 94 | { 95 | return true; 96 | } 97 | else 98 | { 99 | return false; 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/data/BasicComplex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dolphindb.io; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicComplex : AbstractScalar 8 | { 9 | 10 | protected Double2 value; 11 | 12 | public BasicComplex(double real, double image) 13 | { 14 | value = new Double2(real, image); 15 | } 16 | 17 | public BasicComplex(ExtendedDataInput @in) 18 | { 19 | value = @in.readDouble2(); 20 | } 21 | 22 | public Double2 getDouble2() 23 | { 24 | return value; 25 | } 26 | 27 | 28 | public override bool isNull() 29 | { 30 | return value.isNull(); 31 | } 32 | 33 | 34 | public override void setNull() 35 | { 36 | value = new Double2(-double.MaxValue, -double.MaxValue); 37 | } 38 | 39 | public double getReal() { 40 | return value.x; 41 | } 42 | 43 | public double getImage(){ 44 | return value.y; 45 | } 46 | 47 | public override Number getNumber() 48 | { 49 | throw new Exception("Imcompatible data type"); 50 | } 51 | 52 | public override object getObject() 53 | { 54 | throw new NotImplementedException(); 55 | } 56 | 57 | public override void setObject(object value) 58 | { 59 | throw new NotImplementedException(); 60 | } 61 | public override Object getTemporal() 62 | { 63 | throw new Exception("Imcompatible data type"); 64 | } 65 | 66 | public override DATA_CATEGORY getDataCategory() 67 | { 68 | return DATA_CATEGORY.BINARY; 69 | } 70 | public override DATA_TYPE getDataType() 71 | { 72 | return DATA_TYPE.DT_COMPLEX; 73 | } 74 | 75 | public override String getString() 76 | { 77 | if (isNull()) 78 | { 79 | return ""; 80 | } 81 | else 82 | { 83 | return value.x.ToString() + (value.y >= 0 ? "+" : "") + value.y.ToString() + "i"; 84 | } 85 | } 86 | 87 | public bool equals(Object o) 88 | { 89 | if (!(o is BasicComplex) || o == null) 90 | return false; 91 | else 92 | return value.equals(((BasicComplex)o).value); 93 | } 94 | 95 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 96 | { 97 | @out.writeDouble2(value); 98 | } 99 | 100 | public Double2 getValue() 101 | { 102 | return value; 103 | } 104 | 105 | public override int hashBucket(int buckets) 106 | { 107 | return value.hashBucket(buckets); 108 | } 109 | 110 | public override bool Equals(object o) 111 | { 112 | if (!(o is BasicComplex) || o == null) 113 | { 114 | return false; 115 | } 116 | else 117 | { 118 | return getValue().equals(((BasicComplex)o).getValue()); 119 | } 120 | } 121 | 122 | public override int GetHashCode() 123 | { 124 | return value.GetHashCode(); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/route/ListDomain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using dolphindb.data; 6 | 7 | 8 | namespace dolphindb.route 9 | { 10 | public class ListDomain:Domain 11 | { 12 | private DATA_TYPE type; 13 | private DATA_CATEGORY cat; 14 | private Dictionary dict; 15 | 16 | public ListDomain(IVector list, DATA_TYPE type, DATA_CATEGORY cat) 17 | { 18 | this.type = type; 19 | this.cat = cat; 20 | if(list.getDataType() != DATA_TYPE.DT_ANY) 21 | { 22 | throw new Exception("The input list must be a tuple."); 23 | } 24 | dict = new Dictionary(); 25 | 26 | BasicAnyVector values = (BasicAnyVector)list; 27 | int partitions = values.rows(); 28 | for (int i = 0; i < partitions; ++i) 29 | { 30 | IEntity cur = values.getEntity(i); 31 | if (cur.isScalar()) 32 | dict.Add((IScalar)cur, i); 33 | else 34 | { 35 | IVector vec = (IVector)cur; 36 | for (int j = 0; j < vec.rows(); ++j) 37 | dict.Add(vec.get(j), i); 38 | } 39 | } 40 | 41 | } 42 | 43 | public int getPartitionKey(IScalar partitionCol) 44 | { 45 | if (partitionCol.getDataCategory() != cat) 46 | throw new Exception("Data category incompatible."); 47 | if (cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType()) 48 | { 49 | DATA_TYPE old = partitionCol.getDataType(); 50 | partitionCol = (IScalar)Utils.castDateTime(partitionCol, type); 51 | if (partitionCol == null) 52 | throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString()); 53 | } 54 | int index = 0; 55 | if (dict.ContainsKey(partitionCol)) 56 | { 57 | index = (int)dict[partitionCol]; 58 | } 59 | else 60 | { 61 | index = -1; 62 | } 63 | return index; 64 | } 65 | 66 | public List getPartitionKeys(IVector partitionCol) 67 | { 68 | if (partitionCol.getDataCategory() != cat) 69 | throw new Exception("Data category incompatible."); 70 | if (cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType()) 71 | { 72 | DATA_TYPE old = partitionCol.getDataType(); 73 | partitionCol = (IVector)Utils.castDateTime(partitionCol, type); 74 | if (partitionCol == null) 75 | throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString()); 76 | } 77 | 78 | int rows = partitionCol.rows(); 79 | List keys = new List(rows); 80 | for (int i = 0; i < rows; ++i) 81 | { 82 | if (dict.ContainsKey(partitionCol.get(i))) 83 | { 84 | keys.Add((int)dict[partitionCol.get(i)]); 85 | } 86 | else 87 | { 88 | keys.Add(-1); 89 | } 90 | } 91 | return keys; 92 | } 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/data/BasicInt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.io; 3 | namespace dolphindb.data 4 | { 5 | /// 6 | /// Corresponds to DolphinDB int scalar 7 | /// 8 | 9 | public class BasicInt : AbstractScalar, IComparable 10 | { 11 | private int value; 12 | static string formatStr = "0"; 13 | 14 | public BasicInt(int value) 15 | { 16 | this.value = value; 17 | } 18 | 19 | public BasicInt(ExtendedDataInput @in) 20 | { 21 | value = @in.readInt(); 22 | } 23 | 24 | public virtual int getValue() 25 | { 26 | return value; 27 | } 28 | 29 | public int getInt() 30 | { 31 | return value; 32 | } 33 | 34 | public override bool isNull() 35 | { 36 | return value == int.MinValue; 37 | } 38 | 39 | public override void setNull() 40 | { 41 | value = int.MinValue; 42 | } 43 | 44 | public override DATA_CATEGORY getDataCategory() 45 | { 46 | return DATA_CATEGORY.INTEGRAL; 47 | } 48 | 49 | public override DATA_TYPE getDataType() 50 | { 51 | return DATA_TYPE.DT_INT; 52 | } 53 | 54 | public override Number getNumber() 55 | { 56 | if (isNull()) 57 | { 58 | return null; 59 | } 60 | else 61 | { 62 | return new Number(value); 63 | } 64 | } 65 | 66 | public override object getTemporal() 67 | { 68 | throw new Exception("Imcompatible data type"); 69 | } 70 | 71 | public override bool Equals(object o) 72 | { 73 | if (!(o is BasicInt) || o == null) 74 | { 75 | return false; 76 | } 77 | else 78 | { 79 | return value == ((BasicInt)o).value; 80 | } 81 | } 82 | 83 | public override int GetHashCode() 84 | { 85 | return (new int?(value)).GetHashCode(); 86 | } 87 | 88 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 89 | { 90 | @out.writeInt(value); 91 | } 92 | 93 | public int CompareTo(BasicInt o) 94 | { 95 | return value.CompareTo(o.value); 96 | } 97 | 98 | public override string getString() 99 | { 100 | if(isNull()) 101 | { 102 | return ""; 103 | }else{ 104 | return value.ToString(formatStr); 105 | } 106 | } 107 | public override object getObject() 108 | { 109 | return getValue(); 110 | } 111 | 112 | public override string ToString() 113 | { 114 | return getString(); 115 | } 116 | 117 | public override void setObject(object value) 118 | { 119 | this.value = Convert.ToInt32(value); 120 | } 121 | 122 | public override int hashBucket(int buckets) 123 | { 124 | if (value >= 0) 125 | return value % buckets; 126 | else if (value == int.MinValue) 127 | return -1; 128 | else 129 | { 130 | return (int)((4294967296L + value) % buckets); 131 | } 132 | } 133 | } 134 | 135 | } -------------------------------------------------------------------------------- /src/data/BasicDouble.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using dolphindb.io; 3 | using System; 4 | 5 | namespace dolphindb.data 6 | { 7 | /// 8 | /// 9 | /// Corresponds to DolphinDB double scalar 10 | /// 11 | /// 12 | 13 | public class BasicDouble : AbstractScalar, IComparable 14 | { 15 | private static readonly string df1 = "0.00000000"; 16 | private double value; 17 | 18 | public BasicDouble(double value) 19 | { 20 | this.value = value; 21 | } 22 | 23 | public BasicDouble(ExtendedDataInput @in) 24 | { 25 | value = @in.readDouble(); 26 | } 27 | 28 | public virtual double getValue() 29 | { 30 | return value; 31 | } 32 | 33 | public override bool isNull() 34 | { 35 | return value == -double.MaxValue; 36 | } 37 | 38 | public override void setNull() 39 | { 40 | value = -double.MaxValue; 41 | } 42 | 43 | public override DATA_CATEGORY getDataCategory() 44 | { 45 | return DATA_CATEGORY.FLOATING; 46 | } 47 | 48 | public override DATA_TYPE getDataType() 49 | { 50 | return DATA_TYPE.DT_DOUBLE; 51 | } 52 | 53 | public override Number getNumber() 54 | { 55 | if (isNull()) 56 | { 57 | return null; 58 | } 59 | else 60 | { 61 | return new Number(value); 62 | } 63 | } 64 | 65 | public override object getTemporal() 66 | { 67 | throw new Exception("Imcompatible data type"); 68 | } 69 | 70 | public override string getString() 71 | { 72 | if (isNull()) 73 | { 74 | return ""; 75 | } 76 | else if (double.IsNaN(value) || double.IsInfinity(value)) 77 | { 78 | return value.ToString(); 79 | } 80 | else 81 | { 82 | return value.ToString(df1); 83 | } 84 | 85 | } 86 | 87 | public override bool Equals(object o) 88 | { 89 | if (!(o is BasicDouble) || o == null) 90 | { 91 | return false; 92 | } 93 | else 94 | { 95 | return value == ((BasicDouble)o).value; 96 | } 97 | } 98 | 99 | public override int GetHashCode() 100 | { 101 | return (new double?(value)).GetHashCode(); 102 | } 103 | 104 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 105 | { 106 | @out.writeDouble(value); 107 | } 108 | 109 | public virtual int CompareTo(BasicDouble o) 110 | { 111 | return value.CompareTo(o.value); 112 | } 113 | 114 | public override object getObject() 115 | { 116 | return getValue(); 117 | } 118 | 119 | public override void setObject(object value) 120 | { 121 | this.value = Convert.ToDouble(value); 122 | } 123 | 124 | 125 | public override string ToString() 126 | { 127 | return getString(); 128 | } 129 | 130 | public override int hashBucket(int buckets) 131 | { 132 | throw new NotImplementedException(); 133 | } 134 | } 135 | 136 | } -------------------------------------------------------------------------------- /src/data/BasicLong.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using dolphindb.io; 3 | using System; 4 | 5 | namespace dolphindb.data 6 | { 7 | /// 8 | /// 9 | /// Corresponds to DolphindB long scalar 10 | /// 11 | /// 12 | 13 | public class BasicLong : AbstractScalar, IComparable 14 | { 15 | private long value; 16 | static string formatStr = "0"; 17 | 18 | public BasicLong(long value) 19 | { 20 | this.value = value; 21 | } 22 | 23 | public BasicLong(ExtendedDataInput @in) 24 | { 25 | value = @in.readLong(); 26 | } 27 | 28 | public virtual long getValue() 29 | { 30 | return value; 31 | } 32 | 33 | public long getLong() 34 | { 35 | return value; 36 | } 37 | 38 | public override bool isNull() 39 | { 40 | return value == long.MinValue; 41 | } 42 | 43 | public override void setNull() 44 | { 45 | value = long.MinValue; 46 | } 47 | 48 | public override DATA_CATEGORY getDataCategory() 49 | { 50 | return DATA_CATEGORY.INTEGRAL; 51 | } 52 | 53 | public override DATA_TYPE getDataType() 54 | { 55 | 56 | return DATA_TYPE.DT_LONG; 57 | } 58 | 59 | public override Number getNumber() 60 | { 61 | if (isNull()) 62 | { 63 | return null; 64 | } 65 | else 66 | { 67 | return new Number(value); 68 | } 69 | } 70 | 71 | public override object getTemporal() 72 | { 73 | throw new Exception("Imcompatible data type"); 74 | } 75 | 76 | public override string getString() 77 | { 78 | if (isNull()) 79 | { 80 | return ""; 81 | } 82 | else 83 | { 84 | return value.ToString(formatStr); 85 | } 86 | } 87 | 88 | public override bool Equals(object o) 89 | { 90 | if (!(o is BasicLong) || o == null) 91 | { 92 | return false; 93 | } 94 | else 95 | { 96 | return value == ((BasicLong)o).value; 97 | } 98 | } 99 | 100 | public override int GetHashCode() 101 | { 102 | return (new long?(value)).GetHashCode(); 103 | } 104 | 105 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 106 | { 107 | @out.writeLong(value); 108 | } 109 | 110 | public virtual int CompareTo(BasicLong o) 111 | { 112 | return value.CompareTo(o.value); 113 | } 114 | 115 | public override object getObject() 116 | { 117 | return getValue(); 118 | } 119 | 120 | public override void setObject(object value) 121 | { 122 | this.value = Convert.ToInt64(value); 123 | } 124 | 125 | public override int hashBucket(int buckets) 126 | { 127 | if (value >= 0) 128 | return (int)(value % buckets); 129 | else if (value == long.MinValue) 130 | return -1; 131 | else 132 | { 133 | return (int)(((long.MaxValue % buckets) + 2 + ((long.MaxValue + value) % buckets)) % buckets); 134 | } 135 | } 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /src/data/BasicVoidVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace dolphindb.data 8 | { 9 | internal class BasicVoidVector : AbstractVector 10 | { 11 | public BasicVoidVector(int size) : base(DATA_FORM.DF_VECTOR) 12 | { 13 | size_= size; 14 | } 15 | 16 | public BasicVoidVector(DATA_FORM df, ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR) 17 | { 18 | int rows = @in.readInt(); 19 | int cols = @in.readInt(); 20 | int size = rows * cols; 21 | size_ = size; 22 | 23 | } 24 | 25 | int size_ = 0; 26 | public override void add(object value) 27 | { 28 | size_++; 29 | } 30 | 31 | public override void addRange(object list) 32 | { 33 | size_++; 34 | } 35 | 36 | public override void append(IScalar value) 37 | { 38 | size_++; 39 | } 40 | 41 | public override void append(IVector value) 42 | { 43 | size_ += value.rows(); 44 | } 45 | 46 | public override int asof(IScalar value) 47 | { 48 | throw new NotImplementedException(); 49 | } 50 | 51 | public override void deserialize(int start, int count, ExtendedDataInput @in) 52 | { 53 | } 54 | 55 | public override IScalar get(int index) 56 | { 57 | return new Void(); 58 | } 59 | 60 | public override DATA_CATEGORY getDataCategory() 61 | { 62 | return DATA_CATEGORY.NOTHING; 63 | } 64 | 65 | public override DATA_TYPE getDataType() 66 | { 67 | return DATA_TYPE.DT_VOID; 68 | } 69 | 70 | public override Type getElementClass() 71 | { 72 | return typeof(Void); 73 | } 74 | 75 | public override IEntity getEntity(int index) 76 | { 77 | return new Void(); 78 | } 79 | 80 | public override IVector getSubVector(int[] indices) 81 | { 82 | return new BasicVoidVector(indices.Length); 83 | } 84 | 85 | public override int getUnitLength() 86 | { 87 | throw new NotImplementedException(); 88 | } 89 | 90 | public override int hashBucket(int index, int buckets) 91 | { 92 | throw new NotImplementedException(); 93 | } 94 | 95 | public override bool isNull(int index) 96 | { 97 | return true; 98 | } 99 | 100 | public override int rows() 101 | { 102 | return size_; 103 | } 104 | 105 | public override void serialize(int start, int count, ExtendedDataOutput @out) 106 | { 107 | } 108 | 109 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 110 | { 111 | numElement = targetNumElement; 112 | partial = 0; 113 | return targetNumElement; 114 | } 115 | 116 | public override void set(int index, IScalar value) 117 | { 118 | } 119 | 120 | public override void set(int index, string value) 121 | { 122 | } 123 | 124 | public override void setNull(int index) 125 | { 126 | } 127 | 128 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 129 | { 130 | } 131 | } 132 | } 133 | --------------------------------------------------------------------------------