コード例 #1
0
        public bool newTick(Tick t)
        {
            if (_stopped)
            {
                return(false);
            }
            if ((t.FullSymbol == null) || (t.FullSymbol == ""))
            {
                return(false);
            }
            TickWriter tw;
            // prepare last date of tick
            int lastdate = t.Date;

            lastdate = _datedict.GetOrAdd(t.FullSymbol, t.Date);

            // see if we need a new day
            bool samedate = lastdate == t.Date;
            // see if we have stream already
            bool havestream = _filedict.TryGetValue(t.FullSymbol, out tw);

            // if no changes, just save tick
            if (samedate && havestream)
            {
                try
                {
                    tw.newTick((Tick)t);
                    return(true);
                }
                catch (IOException) { return(false); }
            }
            else
            {
                try
                {
                    // if new date, close stream
                    if (!samedate)
                    {
                        try
                        {
                            tw.Close();
                        }
                        catch (IOException) { }
                    }
                    // ensure file is writable
                    string file = Util.SafeFilename(t.FullSymbol, _folderpath, t.Date);
                    if (TickUtil.IsFileWritetable(file))
                    {
                        // open new stream
                        tw = new TickWriter(_folderpath, t.FullSymbol, t.Date);
                        // save tick
                        tw.newTick((Tick)t);
                        // save stream
                        if (!havestream)
                        {
                            _filedict.Add(t.FullSymbol, tw);
                        }
                        else
                        {
                            _filedict[t.FullSymbol] = tw;
                        }
                        // save date if changed
                        if (!samedate)
                        {
                            _datedict[t.FullSymbol] = t.Date;
                        }
                    }
                }
                catch (IOException) { return(false); }
                catch (Exception) { return(false); }
            }

            return(false);
        }
コード例 #2
0
        public bool newTick(Tick t)
        {
            if (_stopped) return false;
            if ((t.FullSymbol == null) || (t.FullSymbol == "")) return false;
            TickWriter tw;
            // prepare last date of tick
            int lastdate = t.Date;
            lastdate = _datedict.GetOrAdd(t.FullSymbol, t.Date);

            // see if we need a new day
            bool samedate = lastdate == t.Date;
            // see if we have stream already
            bool havestream = _filedict.TryGetValue(t.FullSymbol, out tw);
            // if no changes, just save tick
            if (samedate && havestream)
            {
                try
                {
                    tw.newTick((Tick)t);
                    return true;
                }
                catch (IOException) { return false; }
            }
            else
            {
                try
                {
                    // if new date, close stream
                    if (!samedate)
                    {
                        try
                        {
                            tw.Close();
                        }
                        catch (IOException) { }
                    }
                    // ensure file is writable
                    string file = Util.SafeFilename(t.FullSymbol, _folderpath, t.Date);
                    if (TickUtil.IsFileWritetable(file))
                    {
                        // open new stream
                        tw = new TickWriter(_folderpath, t.FullSymbol, t.Date);
                        // save tick
                        tw.newTick((Tick)t);
                        // save stream
                        if (!havestream)
                            _filedict.Add(t.FullSymbol, tw);
                        else
                            _filedict[t.FullSymbol] = tw;
                        // save date if changed
                        if (!samedate)
                        {
                            _datedict[t.FullSymbol] = t.Date;
                        }
                    }
                }
                catch (IOException) { return false; }
                catch (Exception) { return false; }
            }

            return false;
        }