public byte[] Serialize()
        {
            byte[]      seperator      = BitConverter.GetBytes(',');
            List <byte> serializedItem = new List <byte>();

            // Add the Brand
            if (Brand != null)
            {
                serializedItem.AddRange(Encoding.UTF8.GetBytes(Brand));
            }
            serializedItem.AddRange(seperator);

            // Add the Description
            if (Description != null)
            {
                serializedItem.AddRange(Encoding.UTF8.GetBytes(Description));
            }
            serializedItem.AddRange(seperator);

            // Add the Part Number
            if (PartNumber != null)
            {
                serializedItem.AddRange(Encoding.UTF8.GetBytes(PartNumber));
            }
            serializedItem.AddRange(seperator);

            // Add the Old Part Number
            if (OldPartNumber != null)
            {
                serializedItem.AddRange(Encoding.UTF8.GetBytes(OldPartNumber));
            }
            serializedItem.AddRange(seperator);

            // Add the Current Count of Items
            serializedItem.AddRange(Encoding.UTF8.GetBytes(CurrentCount.ToString()));
            serializedItem.AddRange(seperator);

            // Add the Number of Needed Items
            serializedItem.AddRange(Encoding.UTF8.GetBytes(NumNeeded.ToString()));
            serializedItem.AddRange(seperator);

            // Add the Number of Ordered Items
            serializedItem.AddRange(Encoding.UTF8.GetBytes(NumOrdered.ToString()));
            serializedItem.AddRange(seperator);

            // Add the Price
            serializedItem.AddRange(Encoding.UTF8.GetBytes(Price.ToString()));
            serializedItem.AddRange(seperator);

            // Add the seperator to signify the end of the serialized item.
            serializedItem.AddRange(BitConverter.GetBytes(';'));

            return(serializedItem.ToArray());
        }
        private void UpdateDisplay()
        {
            if (_lastDisplayUpdate == null || (DateTime.Now - _lastDisplayUpdate.Value).TotalSeconds > DisplayIntervalSeconds)
            {
                _dialogForm.Text = ActionTitle;

                _dialogForm.progressBar1.Value = (int)((CurrentCount * 1.0 / TotalEstimatedCount) * 10000);

                if (!string.IsNullOrEmpty(CurrentAction))
                {
                    _dialogForm.txt_CurrentAction.Text = CurrentAction;
                }

                if (DisplayCounts && TotalEstimatedCount > 1)
                {
                    _dialogForm.lbl_Progress.Text = CurrentCount.ToString() + " / " + TotalEstimatedCount.ToString();
                }
                else
                {
                    _dialogForm.lbl_Progress.Text = "";
                }

                TimeSpan timeElapsed = (DateTime.Now - StartDateTime);
                if (DisplayTimeEstimates && TotalEstimatedCount > 1 &&
                    timeElapsed.TotalSeconds > TimeEstimateInitialDelaySeconds &&
                    CurrentCount > 0)
                {
                    double   rateSoFar    = CurrentCount / timeElapsed.TotalSeconds;
                    TimeSpan expectedTime = TimeSpan.FromSeconds((TotalEstimatedCount - CurrentCount) / rateSoFar);
                    _dialogForm.lbl_TimeEstimate.Text = Utils.GetApproxTimeSpanDescription(expectedTime) + " осталось.";
                }
                else
                {
                    _dialogForm.lbl_TimeEstimate.Text = "";
                }

                _lastDisplayUpdate = DateTime.Now;
            }
        }
Exemplo n.º 3
0
        public void DataAutoFill(bool isAppend = false)
        {
            autoFillStartTime = DateTime.Now;
            AutoFillInfo.Clear();
            var      basedir         = ConfigurationManager.AppSettings["TDX export base folder"];
            var      cs              = ConfigurationManager.ConnectionStrings["MarketDataConnectionString"].ConnectionString;
            var      trans           = new TransMarketDataFromTDX();
            DateTime?InsertBeginTime = null;

            if (isAppend)
            {
                InsertBeginTime = trans.GetLastTime(cs);
            }
            Result = "Auto fill data job start at " + autoFillStartTime.ToString() + ", base dir is " + basedir + ", connection string is " + cs;
            AutoFillInfo.Add(Result);
            var l = GetAllInstrumentTicker();

            if (l.Count > 0)
            {
                AutoFillInfo.Add("Total count is " + l.Count.ToString());
            }
            TotalCount   = l.Count;
            successCount = 0;
            faildFileList.Clear();
            for (int i = 0; i < TotalCount; i++)
            {
                CurrentCount = i + 1;
                AutoFillInfo.Add("Current count is " + CurrentCount.ToString());
                var fs = basedir + GetFileName(l[i]);//only add exist instrument market data
                if (File.Exists(fs))
                {
                    AutoFillInfo.Add("Current file is " + fs);
                    trans.MarketDataList.Clear();
                    trans.LimitBeginTime = InsertBeginTime;
                    try
                    {
                        trans.ReadData(fs);
                        AutoFillInfo.Add(fs + " data read success");
                        trans.WriteToDB(cs);
                        AutoFillInfo.Add(fs + " data fill success");
                        successCount++;
                    }
                    catch (Exception ex)
                    {
                        AutoFillInfo.Add("Error: " + fs + " data fill error, message is " + ex.Message);
                        faildFileList.Add("Error: " + fs + " data fill error, message is " + ex.Message);
                    }
                }
                else
                {
                    AutoFillInfo.Add("Error: file " + fs + " not exist!");
                    faildFileList.Add("Error: file " + fs + " not exist!");
                }
                if (ProcessorCallBack != null)
                {
                    var spendtime = DateTime.Now - autoFillStartTime;
                    var remain    = TimeSpan.FromSeconds((spendtime.TotalSeconds / FinishPercent) - spendtime.TotalSeconds);

                    ProcessorCallBack(TotalCount, CurrentCount, FinishPercent, successCount, faildFileList.Count, spendtime, remain);
                }
            }
            DateTime finishTime = DateTime.Now;

            Result = "job finished at " + finishTime.ToString() + ", spend time:" + (finishTime - autoFillStartTime).ToString() + " , total success " + successCount.ToString();
            AutoFillInfo.Add(Result);
            if (faildFileList.Count > 0)
            {
                AutoFillInfo.Add("Faild count " + faildFileList.Count.ToString());
                faildFileList.ForEach(v => AutoFillInfo.Add(v + ";"));
            }
            if (File.Exists(logFilePath))
            {
                File.Delete(logFilePath);
            }
            File.WriteAllLines(logFilePath, AutoFillInfo.ToArray());
        }