Beispiel #1
0
 /// <summary>
 /// 添加镜像
 /// </summary>
 /// <param name="native">库</param>
 /// <param name="target">目标</param>
 public void AddMirror(INativeBase native, ControlA target)
 {
     if (target.Parent == null || (target.Location.x == 0 && target.Location.y == 0))
     {
         ClientSize = new Size(target.Size.cx, target.Size.cy);
     }
     else
     {
         ClientSize = new Size(target.Parent.Size.cx, target.Parent.Size.cy);
     }
     if (m_native == null)
     {
         m_native              = NativeHandler.CreateNative();
         m_native.MirrorMode   = MirrorMode.Shadow;
         m_native.Paint        = new GdiPlusPaintEx();
         m_native.Host         = new WinHostEx();
         m_native.Host.Native  = m_native;
         m_native.ResourcePath = WinHostEx.GetAppPath() + "\\config";
         m_host      = m_native.Host as WinHostEx;
         m_host.HWnd = Handle;
         //设置尺寸
         m_native.AllowScaleSize = true;
         m_native.DisplaySize    = new SIZE(ClientSize.Width, ClientSize.Height);
         ResetScaleSize(GetClientSize());
     }
     m_native.AddMirror(native, target);
     m_native.Invalidate();
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            INativeBase native    = NativeHandler.CreateNative();
            String      script    = "TEST(100);TEST(100);TEST(100);";
            CIndicator  indicator = CFunctionEx.CreateIndicator(script, native);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            for (int i = 0; i < 1000000; i++)
            {
                CMathElement ce = new CMathElement();
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
            Console.ReadLine();
            string appPath  = DataCenter.GetAppPath();
            string fileName = appPath + "\\test.js";

            if (args != null && args.Length > 0)
            {
                fileName = appPath + "\\" + args[0];
            }

            DataCenter.StartService(fileName);
        }
Beispiel #3
0
 /// <summary>
 /// 创建指标
 /// </summary>
 /// <param name="text">脚本</param>
 /// <param name="parameters">参数</param>
 /// <returns>指标ID</returns>
 public static int CreateIndicatorExtern(String text, String parameters)
 {
     try
     {
         if (m_native == null)
         {
             m_native = NativeHandler.CreateNative();
         }
         if (m_chart == null)
         {
             m_chart        = new ChartAEx();
             m_chart.Native = m_native;
         }
         m_serialNumber++;
         CTable dataSource = m_chart.Native.CreateTable();
         dataSource.AddColumn(KeyFields.CLOSE_INDEX);
         dataSource.AddColumn(KeyFields.HIGH_INDEX);
         dataSource.AddColumn(KeyFields.LOW_INDEX);
         dataSource.AddColumn(KeyFields.OPEN_INDEX);
         dataSource.AddColumn(KeyFields.VOL_INDEX);
         dataSource.AddColumn(KeyFields.AMOUNT_INDEX);
         CIndicator indicator = SecurityDataHelper.CreateIndicator(m_chart, dataSource, text, parameters);
         m_indicators[m_serialNumber] = indicator;
         indicator.OnCalculate(0);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
     }
     return(m_serialNumber);
 }
Beispiel #4
0
 /// <summary>
 /// 加载
 /// </summary>
 /// <param name="name">名称</param>
 public void LoadXml()
 {
     m_native             = NativeHandler.CreateNative();
     m_native.Paint       = new GdiPlusPaintEx();
     m_host               = new WinHostEx();
     m_host.Native        = m_native;
     m_native.Host        = m_host;
     m_host.HWnd          = Handle;
     m_native.DisplaySize = new SIZE(ClientSize.Width, ClientSize.Height);
     m_barrageDiv         = new BarrageDiv();
     m_barrageDiv.Dock    = DockStyleA.Fill;
     m_barrageDiv.TopMost = true;
     m_native.AddControl(m_barrageDiv);
     m_native.Update();
     Invalidate();
 }
        private void Open()
        {
            if (_c4db != null)
            {
                return;
            }

            Directory.CreateDirectory(Config.Directory);
            var path   = DatabasePath(Name, Config.Directory);
            var config = DBConfig;

            var encrypted = "";

            #if COUCHBASE_ENTERPRISE
            if (Config.EncryptionKey != null)
            {
                var key = Config.EncryptionKey;
                var i   = 0;
                config.encryptionKey.algorithm = C4EncryptionAlgorithm.AES256;
                foreach (var b in key.KeyData)
                {
                    config.encryptionKey.bytes[i++] = b;
                }

                encrypted = "encrypted ";
            }
            #endif

            Log.To.Database.I(Tag, $"Opening {encrypted}database at {path}");
            var localConfig1 = config;
            ThreadSafety.DoLocked(() =>
            {
                _c4db = (C4Database *)NativeHandler.Create()
                        .AllowError((int)C4ErrorCode.NotADatabaseFile, C4ErrorDomain.LiteCoreDomain).Execute(err =>
                {
                    var localConfig2 = localConfig1;
                    return(Native.c4db_open(path, &localConfig2, err));
                });

                if (_c4db == null)
                {
                    throw new CouchbaseLiteException(StatusCode.Unauthorized);
                }

                _obs = Native.c4dbobs_create(_c4db, _DbObserverCallback, this);
            });
        }
Beispiel #6
0
        /// <summary>
        /// 启动监听
        /// </summary>
        public void Start()
        {
            m_useScript = CFileA.IsFileExist(m_fileName);
            if (m_useScript)
            {
                m_native = NativeHandler.CreateNative();
                CFileA.Read(m_fileName, ref m_script);
                m_indicator = CFunctionEx.CreateIndicator(m_script, m_native);
                Console.WriteLine(m_script);
            }
            try
            {
                //string host = "127.0.0.1";
                //IPAddress ip = IPAddress.Parse(host);
                if (m_indicator != null)
                {
                    m_indicator.CallFunction("ONHTTPSERVERSTARTING('" + m_fileName + "');");
                }
                IPEndPoint ipe = new IPEndPoint(IPAddress.Any, m_port);

                m_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                m_listener.Bind(ipe);
                m_listener.Listen(0);
            }
            catch (Exception ex)
            {
                if (m_indicator != null)
                {
                    m_indicator.CallFunction("ONHTTPSERVERSTARTFAIL('" + ex.Message + "\r\n" + ex.StackTrace + "');");
                }
                return;
            }
            int minThreadNum = 0, portThreadNum = 0, maxThreadNum = 0;

            ThreadPool.GetMaxThreads(out maxThreadNum, out portThreadNum);
            ThreadPool.GetMinThreads(out minThreadNum, out portThreadNum);
            if (m_indicator != null)
            {
                m_indicator.CallFunction("ONHTTPSERVERSTART(" + CStr.ConvertIntToStr(maxThreadNum) + "," + CStr.ConvertIntToStr(minThreadNum) + ");");
            }
            while (DataCenter.IsAppAlive)
            {
                Socket socket = m_listener.Accept();
                ThreadPool.QueueUserWorkItem(new WaitCallback(ReadData), socket);
            }
            m_listener.Close();
        }
Beispiel #7
0
        public MainForm()
        {
            InitializeComponent();
            m_native             = NativeHandler.CreateNative();
            m_native.Paint       = new GdiPlusPaint();
            m_native.DisplaySize = new SIZE(ClientSize.Width, ClientSize.Height);
            m_host        = m_native.Host as WinHost;
            m_host.Native = m_native;
            m_native.Host = m_host;
            m_host.HWnd   = Handle;
            AcceptDiv acceptDiv = new AcceptDiv();

            acceptDiv.Dock = DockStyleA.Fill;
            acceptDiv.Size = m_native.DisplaySize;
            acceptDiv.Text = File.ReadAllText(Application.StartupPath + "\\accept.txt", Encoding.Default);
            m_native.AddControl(acceptDiv);
            m_native.Update();
            m_native.Invalidate();
        }
Beispiel #8
0
        static async void Login(WebAuthenticator authenticator)
        {
            currentHandler?.Cancel();
            try {
                currentHandler = new NativeHandler();

                var gAuth = authenticator as GoogleAuthenticator;
                var user  = await currentHandler.Authenticate(gAuth);

                gAuth.ServerToken  = user.ServerAuthCode;
                gAuth.IdToken      = user.Authentication.IdToken;
                gAuth.RefreshToken = user.Authentication.RefreshToken;
                gAuth.OnRecievedAuthCode(user.Authentication.AccessToken);
            } catch (TaskCanceledException) {
                authenticator?.OnCancelled();
            } catch (Exception ex) {
                Console.WriteLine(ex);
                authenticator.OnError(ex.Message);
            }
        }
Beispiel #9
0
 /// <summary>
 /// 添加镜像
 /// </summary>
 /// <param name="native">库</param>
 /// <param name="target">目标</param>
 public void AddBugHole(INativeBase native, ControlA target)
 {
     if (m_native == null)
     {
         m_native              = NativeHandler.CreateNative();
         m_native.MirrorMode   = MirrorMode.BugHole;
         m_native.Paint        = new GdiPlusPaintEx();
         m_native.Host         = new WinHostEx();
         m_native.Host.Native  = m_native;
         m_native.ResourcePath = WinHostEx.GetAppPath() + "\\config";
         m_host      = m_native.Host as WinHostEx;
         m_host.HWnd = Handle;
         //设置尺寸
         m_native.AllowScaleSize = true;
         m_native.DisplaySize    = new SIZE(ClientSize.Width, ClientSize.Height);
         ResetScaleSize(GetClientSize());
     }
     m_native.AddMirror(native, target);
     m_native.Update();
     m_native.Invalidate();
 }
        private void Save([NotNull] Document doc, C4Document **outDoc, C4Document *baseDoc, bool deletion)
        {
            var revFlags = (C4RevisionFlags)0;

            if (deletion)
            {
                revFlags = C4RevisionFlags.Deleted;
            }

            byte[] body = null;
            if (!deletion && !doc.IsEmpty)
            {
                body = doc.Encode();
                var root = Native.FLValue_FromTrustedData(body);
                if (root == null)
                {
                    Log.To.Database.E(Tag, "Failed to encode document body properly.  Aborting save of document!");
                    return;
                }

                var rootDict = Native.FLValue_AsDict(root);
                if (rootDict == null)
                {
                    Log.To.Database.E(Tag, "Failed to encode document body properly.  Aborting save of document!");
                    return;
                }

                ThreadSafety.DoLocked(() =>
                {
                    if (Native.c4doc_dictContainsBlobs(rootDict, SharedStrings.SharedKeys))
                    {
                        revFlags |= C4RevisionFlags.HasAttachments;
                    }
                });
            }
            else if (doc.IsEmpty)
            {
                FLEncoder *encoder = SharedEncoder;
                Native.FLEncoder_BeginDict(encoder, 0);
                Native.FLEncoder_EndDict(encoder);
                body = Native.FLEncoder_Finish(encoder, null);
                Native.FLEncoder_Reset(encoder);
            }

            var rawDoc = baseDoc != null ? baseDoc :
                         doc.c4Doc?.HasValue == true ? doc.c4Doc.RawDoc : null;

            if (rawDoc != null)
            {
                doc.ThreadSafety.DoLocked(() =>
                {
                    ThreadSafety.DoLocked(() =>
                    {
                        *outDoc = (C4Document *)NativeHandler.Create()
                                  .AllowError((int)C4ErrorCode.Conflict, C4ErrorDomain.LiteCoreDomain).Execute(
                            err => Native.c4doc_update(rawDoc, body, revFlags, err));
                    });
                });
            }
            else
            {
                ThreadSafety.DoLocked(() =>
                {
                    *outDoc = (C4Document *)NativeHandler.Create()
                              .AllowError((int)C4ErrorCode.Conflict, C4ErrorDomain.LiteCoreDomain).Execute(
                        err => Native.c4doc_create(_c4db, doc.Id, body, revFlags, err));
                });
            }
        }
        private Document Save([NotNull] Document document, bool deletion)
        {
            if (document.IsInvalidated)
            {
                throw new CouchbaseLiteException(StatusCode.NotAllowed, "Cannot save or delete a MutableDocument that has already been used to save or delete");
            }

            if (deletion && document.RevID == null)
            {
                throw new CouchbaseLiteException(StatusCode.NotAllowed, "Cannot delete a document that has not yet been saved");
            }

            var         docID = document.Id;
            var         doc = document;
            Document    baseDoc = null, otherDoc = null;
            C4Document *newDoc = null;
            Document    retVal = null;

            while (true)
            {
                var resolve = false;
                retVal = ThreadSafety.DoLocked(() =>
                {
                    VerifyDB(doc);
                    LiteCoreBridge.Check(err => Native.c4db_beginTransaction(_c4db, err));
                    try {
                        if (deletion)
                        {
                            // Check for no-op case if the document does not exist
                            var curDoc = (C4Document *)NativeHandler.Create().AllowError(new C4Error(C4ErrorCode.NotFound))
                                         .Execute(err => Native.c4doc_get(_c4db, docID, true, err));
                            if (curDoc == null)
                            {
                                (document as MutableDocument)?.MarkAsInvalidated();
                                return(null);
                            }

                            Native.c4doc_free(curDoc);
                        }

                        var newDocOther = newDoc;
                        Save(doc, &newDocOther, baseDoc?.c4Doc?.HasValue == true ? baseDoc.c4Doc.RawDoc : null, deletion);
                        if (newDocOther != null)
                        {
                            // Save succeeded, so commit
                            newDoc = newDocOther;
                            LiteCoreBridge.Check(err =>
                            {
                                var success = Native.c4db_endTransaction(_c4db, true, err);
                                if (!success)
                                {
                                    Native.c4doc_free(newDoc);
                                }

                                return(success);
                            });

                            (document as MutableDocument)?.MarkAsInvalidated();
                            baseDoc?.Dispose();
                            return(new Document(this, docID, new C4DocumentWrapper(newDoc)));
                        }

                        // There was a conflict
                        if (deletion && !doc.IsDeleted)
                        {
                            var deletedDoc = doc.ToMutable();
                            deletedDoc.MarkAsDeleted();
                            doc = deletedDoc;
                        }

                        if (doc.c4Doc != null)
                        {
                            baseDoc = new Document(this, docID, doc.c4Doc.Retain <C4DocumentWrapper>());
                        }

                        otherDoc = new Document(this, docID);
                        if (!otherDoc.Exists)
                        {
                            LiteCoreBridge.Check(err => Native.c4db_endTransaction(_c4db, false, err));
                            return(null);
                        }
                    } catch (Exception) {
                        baseDoc?.Dispose();
                        otherDoc?.Dispose();
                        LiteCoreBridge.Check(err => Native.c4db_endTransaction(_c4db, false, err));
                        throw;
                    }

                    resolve = true;
                    LiteCoreBridge.Check(err => Native.c4db_endTransaction(_c4db, false, err));
                    return(null);
                });

                if (!resolve)
                {
                    return(retVal);
                }

                // Resolve Conflict
                Document resolved = null;
                try {
                    var resolver = Config.ConflictResolver;
                    var conflict = new Conflict(doc, otherDoc, baseDoc);
                    resolved = resolver.Resolve(conflict);
                    if (resolved == null)
                    {
                        throw new LiteCoreException(new C4Error(C4ErrorCode.Conflict));
                    }
                } finally {
                    baseDoc?.Dispose();
                    if (!ReferenceEquals(resolved, otherDoc))
                    {
                        otherDoc?.Dispose();
                    }
                }

                retVal = ThreadSafety.DoLocked(() =>
                {
                    var current = new Document(this, docID);
                    if (resolved.RevID == current.RevID)
                    {
                        (document as MutableDocument)?.MarkAsInvalidated();
                        current.Dispose();
                        return(resolved); // Same as current
                    }

                    // For saving
                    doc      = resolved;
                    baseDoc  = current;
                    deletion = resolved.IsDeleted;
                    return(null);
                });

                if (retVal != null)
                {
                    return(retVal);
                }
            }
        }
Beispiel #12
0
 public static void Check(C4TryLogicDelegate3 block)
 {
     NativeHandler.Create().Execute(block);
 }
Beispiel #13
0
 public static void *Check(C4TryLogicDelegate2 block)
 {
     return(NativeHandler.Create().Execute(block));
 }
Beispiel #14
0
 public static byte[] Check(C4TryLogicDelegate4 block)
 {
     return(NativeHandler.Create().Execute(block));
 }