Esempio n. 1
0
 void esig_OnQuoteChanged(string sSymbol)
 {
     try
     {
         // get tick info
         BasicQuote q = esig.get_GetBasicQuote(sSymbol);
         // get our struct
         Tick k = new TickImpl(sSymbol);
         // convert it
         k.ask   = (decimal)q.dAsk;
         k.bid   = (decimal)q.dBid;
         k.trade = (decimal)q.dLast;
         k.bs    = q.lBidSize;
         k.os    = q.lAskSize;
         k.size  = q.lLastSize;
         DateTime now = esig.GetAppTime;
         k.time = Util.ToTLTime(now);
         k.date = Util.ToTLDate(now);
         if (isPaperTradeEnabled)
         {
             ptt.newTick(k);
         }
         // send it
         tl.newTick(k);
     }
     catch (Exception ex)
     {
         if (GotDebug != null)
         {
             GotDebug(DebugImpl.Create(ex.Message + ex.StackTrace, DebugLevel.Debug));
         }
     }
 }
Esempio n. 2
0
 void debug(string msg)
 {
     if (GotDebug != null)
     {
         GotDebug(DebugImpl.Create(msg));
     }
 }
Esempio n. 3
0
 void debug(string msg)
 {
     if (SendDebug != null)
     {
         SendDebug(DebugImpl.Create(msg));
     }
 }
 void status(string msg)
 {
     if (SendDebug != null)
     {
         SendDebug(DebugImpl.Create(msg, DebugLevel.Status));
     }
 }
Esempio n. 5
0
        /// <summary>
        /// stop the server
        /// </summary>
        public void Stop()
        {
            // request thread be stopped
            _go = false;
            if (tl != null)
            {
                tl.Stop();
            }
            if (!_valid)
            {
                return;
            }

            try
            {
                // stop thread
                bw.CancelAsync();
                // release symbols
                foreach (Security sec in _mb)
                {
                    esig.ReleaseSymbol(sec.Symbol);
                }
            }
            catch (Exception ex)
            {
                if (GotDebug != null)
                {
                    GotDebug(DebugImpl.Create(ex.Message + ex.StackTrace, DebugLevel.Debug));
                }
            }
            // garbage collect esignal object
            esig = null;
        }
Esempio n. 6
0
        public static bool Delete(string space, string user, string password, string documentid)
        {
            string         url = GetDocumentsUrl(space) + documentid;
            HttpWebRequest hr  = WebRequest.Create(url) as HttpWebRequest;

            hr.Credentials = new System.Net.NetworkCredential(user, password);
            hr.Method      = "DELETE";
            hr.ContentType = "application/xml";
            try
            {
                // write it
                //System.IO.Stream post = hr.GetRequestStream();
                //post.Write(bytes, 0, 0);
                // get response
                System.IO.StreamReader response = new System.IO.StreamReader(hr.GetResponse().GetResponseStream());
                // display it
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create(response.ReadToEnd()));
                }
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }
                return(false);
            }
            return(true);
        }
Esempio n. 7
0
        public static bool Create(string space, string user, string password, string filename, int ticketid, bool prependdatetime)
        {
            string url = GetDocumentsUrl(space);

            try
            {
                FileStream fs   = new FileStream(filename, FileMode.Open, FileAccess.Read);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();

                // Generate post objects
                Dictionary <string, object> postParameters = new Dictionary <string, object>();
                string unique = prependdatetime ? Util.ToTLDate(DateTime.Now).ToString() + Util.DT2FT(DateTime.Now) + Path.GetFileName(filename) : Path.GetFileName(filename);
                postParameters.Add("document[name]", unique);
                postParameters.Add("document[file]", data);
                if (ticketid != 0)
                {
                    postParameters.Add("document[ticket_id]", ticketid);
                }

                // Create request and receive response
                string postURL = url;
                try
                {
                    HttpWebResponse webResponse = WebHelpers.MultipartFormDataPost(postURL, user, password, postParameters, contenttype(filename), filename);


                    // Process response
                    StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                    string       fullResponse   = responseReader.ReadToEnd();
                    webResponse.Close();
                }
                catch (WebException ex)
                {
                    // workaround for http://www.assembla.com/spaces/AssemblaSupport/support/tickets/122--500-internal-server-error--received-when-trying-to-create-documents
                    if (ex.Message.Contains("500"))
                    {
                        return(true);
                    }
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }

                return(false);
            }
        }
Esempio n. 8
0
        public static void Debug(string tag, string format, PObject context, params object[] ps)
        {
            string msg = Format(format, ps);

            if (Thread.CurrentThread.ManagedThreadId == MainThreadID)
            {
                DebugImpl?.Invoke(tag, msg, context);
            }
            else
            {
                lock (DebugThreadQueue)
                {
                    DebugThreadQueue.Enqueue(LogP.Make(tag, msg, context));
                }
            }
        }
Esempio n. 9
0
        public void SetState <T>(T state)
        {
#if LOG_DEBUG
            Debug.Log(string.Format("PRESENT<{0}={1:X8}>:STATE:{2}",
                                    this.GetType().Name,
                                    (uint)this.GetHashCode(),
                                    state));
#endif// LOG_DEBUG
#if LOG_MEMORY
            var presentType    = Present.IsOpened ? Present.CurrentPresentType : null;
            var stateOfPresent = state.GetHashCode();
            Debug.Log(string.Format("APP:{0}, {1}, {2}",
                                    DebugImpl.CreateUptimeChunk(),
                                    DebugImpl.CreatePresentChunk("AT", presentType, stateOfPresent),
                                    DebugImpl.CreatePresentChunk("EVENT:SET_STATE_PREV", presentType, this.GetState())));
#endif// LOG_MEMORY
            this.fsm.SetState(state);
        }
Esempio n. 10
0
        public static bool Create(string space, string user, string password, string filename, int ticketid)
        {
            string url = GetDocumentsUrl(space);

            try
            {
                FileStream fs   = new FileStream(filename, FileMode.Open, FileAccess.Read);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();

                // Generate post objects
                Dictionary <string, object> postParameters = new Dictionary <string, object>();
                string unique = Util.ToTLDate(DateTime.Now).ToString() + Util.ToTLTime(DateTime.Now) + Path.GetFileName(filename);
                postParameters.Add("document[name]", unique);
                postParameters.Add("document[file]", data);
                if (ticketid != 0)
                {
                    postParameters.Add("document[ticket_id]", ticketid);
                }

                // Create request and receive response
                string          postURL     = url;
                HttpWebResponse webResponse = WebHelpers.MultipartFormDataPost(postURL, user, password, postParameters, contenttype(filename));


                // Process response
                StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                string       fullResponse   = responseReader.ReadToEnd();
                webResponse.Close();


                return(true);
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }

                return(false);
            }
        }
Esempio n. 11
0
        public bool Start(string username, string password, string type, int data2)
        {
            List <string> accts = new List <string>();

            try
            {
                _tradeDesk.Login(username, password, LOGINURL, type);
                TableAut tab = (TableAut)_tradeDesk.FindMainTable("accounts");
                _acct = new string[] { tab.CellValue(1, 1).ToString() };
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create(ex.Message + ex.StackTrace));
                }
                return(false);
            }


            return(true);
        }
Esempio n. 12
0
        public static bool Update(string space, string user, string password, int ticket, string xml)
        {
            string         url = "http://www.assembla.com/spaces/" + space + "/tickets/" + ticket.ToString();
            HttpWebRequest hr  = WebRequest.Create(url) as HttpWebRequest;

            hr.Credentials = new System.Net.NetworkCredential(user, password);
            hr.Method      = "PUT";
            hr.ContentType = "application/xml";
            StringBuilder data = new StringBuilder();

            data.AppendLine(System.Web.HttpUtility.HtmlEncode(xml));
            // encode
            byte[] bytes = UTF8Encoding.UTF8.GetBytes(data.ToString());
            hr.ContentLength = bytes.Length;
            try
            {
                // write it
                System.IO.Stream post = hr.GetRequestStream();
                post.Write(bytes, 0, bytes.Length);
                // get response
                System.IO.StreamReader response = new System.IO.StreamReader(hr.GetResponse().GetResponseStream());
                // display it
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create(response.ReadToEnd()));
                }
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }
                return(false);
            }
            return(true);
        }
Esempio n. 13
0
            internal void OpenNextPresent(Type presentType, LoadRuleData rule, object openArg, Action callback)
            {
                if (null == rule)
                {
                    rule = Present.DefaultLoadRule;
                }

#if LOG_DEBUG
                Debug.Log(string.Format("PRESENT<{0}={1:X8}>:NEXT:{2}, RULE:{3}, ARG:{4}, CB:{5}, STACK_TRACE:\n{6}",
                                        this.CurrentPresentName,
                                        (uint)this.CurrentPresentHashCode,
                                        null != presentType ? presentType.Name : "null",
                                        rule,
                                        openArg,
                                        callback,
                                        new System.Diagnostics.StackTrace(true).ToString()));
#endif// LOG_DEBUG
#if LOG_MEMORY
                var stateOfPresent = null != this.loadedPresent ? this.loadedPresent.GetState() : -1;
                Debug.Log(string.Format("APP:{0}, {1}, {2}",
                                        DebugImpl.CreateUptimeChunk(),
                                        DebugImpl.CreatePresentChunk("AT", presentType, -1),
                                        DebugImpl.CreatePresentChunk("EVENT:SET_PRESENT_PREV", this.presentType, stateOfPresent)));
#endif// LOG_MEMORY

                this.ClosePresent(presentType);

                if (null != this.asyncOperFakeOpenForGarbageCollect || null != this.asyncOper || this.fastOpenWait)
                {
#if LOG_DEBUG
                    Debug.Log(string.Format("PRESENT<{0}={1:X8}>:NEXT_DUPLICATED:{2}",
                                            this.CurrentPresentName,
                                            (uint)this.CurrentPresentHashCode,
                                            null != presentType ? presentType.Name : "null"));
#endif// LOG_DEBUG
                    this.OpenPresentWait(presentType, rule, openArg, callback);
                    return;
                }
                else if (null != this.wait)
                {
                    Debug.LogError(string.Format("PRESENT<{0}={1:X8}>:NEXT_DUPLICATED_EXCEPTION#2:{2}, RULE:{3}, ARG:{4}, CB{5}, WAIT:{6}, CURRENT:{7}",
                                                 this.CurrentPresentName,
                                                 (uint)this.CurrentPresentHashCode,
                                                 null != presentType ? presentType.Name : "null",
                                                 rule,
                                                 openArg,
                                                 callback,
                                                 this.wait,
                                                 this.presentType));
                    return;
                }

                this.presentTypePrev = this.presentType;
                this.presentType     = presentType;

                this.openArg = openArg;

                this.openCallback = callback;
                this.isChanging   = true;

                Preference.Save();
                this.preloadPresent = (Present)Activator.CreateInstance(this.presentType);
#if LOG_DEBUG
                Debug.Log(string.Format("PRESENT<{0}={1:X8}>:CREATE_INSTANCE:<{2}={3:X8}>",
                                        this.CurrentPresentName,
                                        (uint)this.CurrentPresentHashCode,
                                        null != this.preloadPresent ? this.preloadPresent.GetType().Name : "null",
                                        null != this.preloadPresent ? (uint)this.preloadPresent.GetHashCode() : 0u));
#endif// LOG_DEBUG
                try
                {
                    this.preloadPresent.OnPreloading();
                }
                catch (Exception e)
                {
                    Debug.LogError(string.Format("PRESENT<{0}={1:X8}>:LOAD_EXCEPT:{2}",
                                                 this.CurrentPresentName,
                                                 (uint)this.CurrentPresentHashCode,
                                                 e));
                }

                switch (rule.Rule)
                {
                case LoadRule.FlushGarbage:
                    this.asyncOperFakeOpenForGarbageCollect = SceneManager.LoadSceneAsync("Next");
                    break;

                case LoadRule.Direct:
                    if (this.preloadPresent.DoOpen)
                    {
                        this.asyncOper = SceneManager.LoadSceneAsync(this.presentType.Name);
                    }
                    else
                    {
                        this.fastOpenWait = true;
                    }
                    break;

                case LoadRule.PreloadedScene:
                    this.asyncOper = rule.Preloaded;
                    break;
                }
            }
Esempio n. 14
0
        public static void Update()
        {
            while (DebugThreadQueue.Count > 0)
            {
                lock (DebugThreadQueue)
                {
                    var log = DebugThreadQueue.Dequeue();
                    DebugImpl?.Invoke(log.tag, log.msg, log.context);
                }
                return;
            }

            while (WarnThreadQueue.Count > 0)
            {
                lock (WarnThreadQueue)
                {
                    var log = WarnThreadQueue.Dequeue();
                    WarnImpl?.Invoke(log.tag, log.msg, log.context);
                }
                return;
            }

            while (ErrorThreadQueue.Count > 0)
            {
                lock (ErrorThreadQueue)
                {
                    var log = ErrorThreadQueue.Dequeue();
                    ErrorImpl?.Invoke(log.tag, log.msg, log.context);
                }
                return;
            }

            while (AssertThreadQueue.Count > 0)
            {
                lock (AssertThreadQueue)
                {
                    var log = AssertThreadQueue.Dequeue();
                    AssertImpl?.Invoke(log.tag, log.msg, log.context);
                }
                return;
            }

            while (ExpThreadQueue.Count > 0)
            {
                lock (ExpThreadQueue)
                {
                    var log = ExpThreadQueue.Dequeue();
                    ExpImpl?.Invoke(log.tag, log.msg, log.exception, log.context);
                }
                return;
            }

            while (InfoThreadQueue.Count > 0)
            {
                lock (InfoThreadQueue)
                {
                    var log = InfoThreadQueue.Dequeue();
                    InfoImpl?.Invoke(log.tag, log.msg);
                }
                return;
            }

            while (VerboseThreadQueue.Count > 0)
            {
                lock (VerboseThreadQueue)
                {
                    var log = VerboseThreadQueue.Dequeue();
                    VerboseImpl?.Invoke(log.tag, log.msg);
                }
                return;
            }

            while (WtfThreadQueue.Count > 0)
            {
                lock (WtfThreadQueue)
                {
                    var log = WtfThreadQueue.Dequeue();
                    WtfImpl?.Invoke(log.tag, log.msg);
                }
                return;
            }

            while (FatalThreadQueue.Count > 0)
            {
                lock (FatalThreadQueue)
                {
                    var log = FatalThreadQueue.Dequeue();
                    FatalImpl?.Invoke(log.tag, log.msg);
                }
                return;
            }

            while (WriteLineThreadQueue.Count > 0)
            {
                lock (WriteLineThreadQueue)
                {
                    var log = WriteLineThreadQueue.Dequeue();
                    WriteLineImpl?.Invoke(log.lv, log.tag, log.msg);
                }
                return;
            }

            while (ToastShortThreadQueue.Count > 0)
            {
                lock (DebugThreadQueue)
                {
                    var log = ToastShortThreadQueue.Dequeue();
                    ToastShortImpl?.Invoke(log.ptr, log.msg);
                }
                return;
            }

            while (ToastLongThreadQueue.Count > 0)
            {
                lock (ToastLongThreadQueue)
                {
                    var log = ToastLongThreadQueue.Dequeue();
                    ToastLongImpl?.Invoke(log.ptr, log.msg);
                }
            }
        }
Esempio n. 15
0
 public void GotDebug(string msg)
 {
     GotDebug(DebugImpl.Create(msg));
 }
Esempio n. 16
0
        public static int Create(string space, string user, string password, string summary, string description, AssemblaStatus status, AssemblaPriority priority)
        {
            int            stat = (int)status;
            int            pri  = (int)priority;
            string         url  = GetTicketsUrl(space);
            HttpWebRequest hr   = WebRequest.Create(url) as HttpWebRequest;

            hr.Credentials     = new System.Net.NetworkCredential(user, password);
            hr.PreAuthenticate = true;
            hr.Method          = "POST";
            hr.ContentType     = "application/xml";
            StringBuilder data = new StringBuilder();

            data.AppendLine("<ticket>");
            data.AppendLine("<status>" + stat.ToString() + "</status>");
            data.AppendLine("<priority>" + pri.ToString() + "</priority>");
            data.AppendLine("<summary>");
            data.AppendLine(System.Web.HttpUtility.HtmlEncode(summary));
            data.AppendLine("</summary>");
            data.AppendLine("<description>");
            data.AppendLine(System.Web.HttpUtility.HtmlEncode(description));
            data.AppendLine("</description>");
            data.AppendLine("</ticket>");
            // encode
            byte[] bytes = UTF8Encoding.UTF8.GetBytes(data.ToString());
            hr.ContentLength = bytes.Length;
            // prepare id
            int id = 0;

            try
            {
                // write it
                System.IO.Stream post = hr.GetRequestStream();
                post.Write(bytes, 0, bytes.Length);
                // get response
                System.IO.StreamReader response = new System.IO.StreamReader(hr.GetResponse().GetResponseStream());
                // get string version
                string rs = response.ReadToEnd();

                XmlDocument xd = new XmlDocument();
                xd.LoadXml(rs);
                XmlNodeList xnl = xd.GetElementsByTagName("id");
                string      val = xnl[0].InnerText;
                if ((val != null) && (val != string.Empty))
                {
                    id = Convert.ToInt32(val);
                }
                // display it
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create(rs));
                }
            }
            catch (Exception ex)
            {
                if (SendDebug != null)
                {
                    SendDebug(DebugImpl.Create("exception: " + ex.Message + ex.StackTrace));
                }
                return(0);
            }
            return(id);
        }
Esempio n. 17
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!_valid)
            {
                return;
            }
            while (_go)
            {
                try
                {
                    if (qc > qr)
                    {
                        // get requested symbols
                        string[] syms = _tmpregister.Split(',');
                        // go through each one
                        foreach (string sym in syms)
                        {
                            // if we don't have subscription already
                            if (!contains(sym))
                            {
                                // add it to list
                                _mb.Add(sym);
                                // request subscription
                                esig.RequestSymbol(sym, 1);
                            }
                        }
                        if (ReleaseDeadSymbols)
                        {
                            // clone requested basket
                            Basket newbasket = new BasketImpl(syms);
                            // clone existing basket as deadbasket
                            Basket deadbasket = new BasketImpl(_mb);
                            // existing - new = deadsymbols
                            deadbasket.Remove(newbasket);
                            // release dead symbols
                            string symsreleased = string.Empty;
                            foreach (Security dead in deadbasket)
                            {
                                try
                                {
                                    esig.ReleaseSymbol(dead.Symbol);
                                    symsreleased += dead.Symbol + " ";
                                }
                                catch { }
                            }
                            if (symsreleased != string.Empty)
                            {
                                verb("released unused symbols: " + symsreleased);
                            }
                        }
                        qr = qc;
                    }
                    while (_barrequests.hasItems)
                    {
                        BarRequest br = new BarRequest();
                        try
                        {
                            br = _barrequests.Read();
                            BarInterval bi       = (BarInterval)br.Interval;
                            string      interval = string.Empty;
                            int         barsback = DefaultBarsBack;
                            if (bi == BarInterval.CustomTicks)
                            {
                                interval = br.CustomInterval + "T";
                            }
                            else if (bi == BarInterval.CustomTime)
                            {
                                interval = br.CustomInterval + "S";
                            }
                            else if (bi == BarInterval.CustomVol)
                            {
                                interval = br.CustomInterval + "V";
                            }
                            else
                            {
                                if (br.Interval == (int)BarInterval.Day)
                                {
                                    interval = "D";
                                }
                                else
                                {
                                    interval = (br.Interval / 60).ToString();
                                }

                                barsback = BarImpl.BarsBackFromDate(bi, br.StartDateTime, br.EndDateTime);
                            }
                            int alldata = BarRequestsGetAllData ? -1 : 0;
                            int hnd     = esig.get_RequestHistory(br.Symbol, interval, (bi == BarInterval.Day) ? barType.btDAYS : barType.btBARS, barsback, alldata, alldata);
                            verb("requested bar data for " + br.Symbol + " on: " + br.Interval.ToString() + " " + br.CustomInterval.ToString() + " reqhandle: " + hnd);
                            // cache request
                            if (!_barhandle2barrequest.ContainsKey(hnd))
                            {
                                _barhandle2barrequest.Add(hnd, br);
                            }
                            else
                            {
                                verb("already had bar request: " + hnd + " " + _barhandle2barrequest[hnd].ToString());
                            }
                            if (esig.get_IsHistoryReady(hnd) != 0)
                            {
                                processhistory(hnd, br);
                            }
                        }
                        catch (Exception ex)
                        {
                            debug("error on historical bar request: " + br.ToString());
                            debug(ex.Message + ex.StackTrace);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (GotDebug != null)
                    {
                        GotDebug(DebugImpl.Create(ex.Message + ex.StackTrace, DebugLevel.Debug));
                    }
                }
                if (e.Cancel || !_go)
                {
                    break;
                }
                System.Threading.Thread.Sleep(WaitBetweenEvents);
            }
        }