string glueDateParts(string csvValue, CsvBar targetCsvBar) {
			if (this.CsvType == CsvFieldType.Date) {
				targetCsvBar.DateAsString = csvValue;
				return null;
			}
			if (this.CsvType == CsvFieldType.Time) targetCsvBar.TimeAsString = csvValue;
			return targetCsvBar.DateAsString + " " + targetCsvBar.TimeAsString;
		}
Esempio n. 2
0
 string glueDateParts(string csvValue, CsvBar targetCsvBar)
 {
     if (this.CsvType == CsvFieldType.Date)
     {
         targetCsvBar.DateAsString = csvValue;
         return(null);
     }
     if (this.CsvType == CsvFieldType.Time)
     {
         targetCsvBar.TimeAsString = csvValue;
     }
     return(targetCsvBar.DateAsString + " " + targetCsvBar.TimeAsString);
 }
Esempio n. 3
0
        public void ParseAndPushThrows(string csvValue, CsvBar targetCsvBar, string formatForDateTimeGlued)
        {
            switch (this.CsvType)
            {
            case CsvFieldType.Date:
                this.glueDateParts(csvValue, targetCsvBar);
                break;

            case CsvFieldType.Time:
                string   dateAndTime = this.glueDateParts(csvValue, targetCsvBar);
                DateTime dateTimeParsed;
                try {
                    dateTimeParsed = DateTime.ParseExact(dateAndTime, formatForDateTimeGlued, null);
                } catch (Exception ex) {
                    string msg = "DateTime.ParseExact(" + dateAndTime + ", " + formatForDateTimeGlued + ", null)\r\n" + ex.Message;
                    throw new Exception(msg, ex);
                }
                try {
                    targetCsvBar.AbsorbOneValueFromStringThrows(dateTimeParsed, CsvFieldType.DateTime);
                } catch (Exception ex) {
                    string msg = "AbsorbOneValueFromStringThrows(" + dateAndTime + ", " + this.CsvType + ")\r\n" + ex.Message;
                    throw new Exception(msg, ex);
                }
                break;

            case CsvFieldType.Unknown:
            case CsvFieldType.Ignore:
            case CsvFieldType.Symbol:
            case CsvFieldType.Interval_Min:
            case CsvFieldType.Interval_Hrs:
            case CsvFieldType.Interval_Days:
                break;

            default:
                object csvValueParsed = this.parse(csvValue);
                targetCsvBar.AbsorbOneValueFromStringThrows(csvValueParsed, this.CsvType);
                break;
            }
        }
Esempio n. 4
0
        BarScaleInterval findMinimalInterval(List <CsvBar> csvParsedByFormat, int takeFirstBarsLimit = 10)
        {
            BarScaleInterval ret = BarScaleInterval.MaxValue;

            if (takeFirstBarsLimit <= 1)
            {
                takeFirstBarsLimit = csvParsedByFormat.Count;
            }
            DateTime prevDateTime = csvParsedByFormat[0].DateTime;

            for (int i = 1; i < takeFirstBarsLimit; i++)
            {
                CsvBar   bar = csvParsedByFormat[i];
                TimeSpan ts  = bar.DateTime - prevDateTime;
                prevDateTime = bar.DateTime;
                BarScaleInterval bsi = BarScaleInterval.FromTimeSpan(ts);
                if (bsi < ret)
                {
                    ret = bsi;
                }
            }
            return(ret);
        }
		public void ParseAndPushThrows(string csvValue, CsvBar targetCsvBar, string formatForDateTimeGlued) {
			switch(this.CsvType) {
				case CsvFieldType.Date:
					this.glueDateParts(csvValue, targetCsvBar);
					break;

				case CsvFieldType.Time:
					string dateAndTime = this.glueDateParts(csvValue, targetCsvBar);
					DateTime dateTimeParsed;
					try {
						dateTimeParsed = DateTime.ParseExact(dateAndTime, formatForDateTimeGlued, null);
					} catch (Exception ex) {
						string msg = "DateTime.ParseExact(" + dateAndTime + ", " + formatForDateTimeGlued + ", null)\r\n" + ex.Message;
						throw new Exception(msg, ex);
					}
					try {
						targetCsvBar.AbsorbOneValueFromStringThrows(dateTimeParsed, CsvFieldType.DateTime);
					} catch (Exception ex) {
						string msg = "AbsorbOneValueFromStringThrows(" + dateAndTime + ", " + this.CsvType + ")\r\n" + ex.Message;
						throw new Exception(msg, ex);
					}
					break;
					
				case CsvFieldType.Unknown:
				case CsvFieldType.Ignore:
				case CsvFieldType.Symbol:
				case CsvFieldType.Interval_Min:
				case CsvFieldType.Interval_Hrs:
				case CsvFieldType.Interval_Days:
					break;

				default:
					object csvValueParsed = this.parse(csvValue);
					targetCsvBar.AbsorbOneValueFromStringThrows(csvValueParsed, this.CsvType);
					break;
			}
		}
		void step3syncCsvRawAndFieldSetupToParsedByFormat() {
			List<CsvBar> csvParsedByFormat = new List<CsvBar>();
			string symbol = null;
			BarScaleInterval scaleInterval = null;
			bool allCsvBarsHaveDOHLCV = true;
			string dateAndTimeFormatsGlued = this.dataSnapshot.FieldSetupCurrent.DateAndTimeFormatsGlued;
			
			foreach (OLVColumn each in this.olvParsedByFormat.Columns) {
				each.HeaderForeColor = Color.Black;
			}

			foreach (List<string> row in this.csvUnnamed) {
				try {
					CsvBar newCsvBar = new CsvBar();
					//foreach (string cell in row) {
					for (int i=0; i<row.Count; i++) {
						string cell = row[i];
						var iColumn = this.dataSnapshot.FieldSetupCurrent[i];
						try {
							iColumn.Parser.ParseAndPushThrows(cell, newCsvBar, dateAndTimeFormatsGlued);
						} catch (Exception ex) {
							//YOULL_RESET_COLUMNS_DESIGNER_this.olvParsedByFormat.Reset();
							//UPSTACK_CATCH_DOES_THIS this.olvParsedByFormat.SetObjects(null);
							//UPSTACK_CATCH_DOES_THIS this.olvParsedByFormat.EmptyListMsg = msg;
							string msg = "value[" + cell + "] column#[" + i + "] type[" + iColumn.Parser.CsvType + "]"
								+ "\r\n" + ex.Message;
							throw new Exception(msg, ex);
						}
						switch (iColumn.Parser.CsvType) {
							case CsvFieldType.Symbol:
								if (String.IsNullOrEmpty(symbol) == false) break;
								symbol = cell;
								break;
							case CsvFieldType.Interval_Min:
								if (scaleInterval != null) break;
								int minutes = 0;
								bool minutesParsedOk = int.TryParse(cell, out minutes);
								if (minutesParsedOk == false) break;
								if (minutes <= 0) break;
								scaleInterval = new BarScaleInterval(BarScale.Minute, minutes);
								break;
							case CsvFieldType.Interval_Hrs:
								if (scaleInterval != null) break;
								int hours = 0;
								bool hoursParsedOk = int.TryParse(cell, out hours);
								if (hoursParsedOk == false) break;
								if (hours <= 0) break;
								scaleInterval = new BarScaleInterval(BarScale.Hour, hours);
								break;
							case CsvFieldType.Interval_Days:
								if (scaleInterval != null) break;
								int days = 0;
								bool daysParsedOk = int.TryParse(cell, out days);
								if (daysParsedOk == false) break;
								if (days <= 0) break;
								scaleInterval = new BarScaleInterval(BarScale.Daily, days);
								break;
						}
					}
					allCsvBarsHaveDOHLCV &= newCsvBar.IsFullyFilledDOHLCV;
					csvParsedByFormat.Add(newCsvBar);
				} catch (Exception ex) {
					this.olvCsvParsedRaw.SelectObject(row);
					throw ex;
				}
			}
			this.olvParsedByFormat.SetObjects(csvParsedByFormat);

			if (allCsvBarsHaveDOHLCV == false || csvParsedByFormat.Count == 0) {
				this.disableRangeBarAndBtnImport();
				return;
			}

			this.csvParsedByFormat = csvParsedByFormat;
			this.symbolDetectedInCsv = symbol;
			this.scaleIntervalDetectedInCsv = scaleInterval;
			this.step4createBarsDisplayChart();
		}
Esempio n. 7
0
        void step3syncCsvRawAndFieldSetupToParsedByFormat()
        {
            List <CsvBar>    csvParsedByFormat       = new List <CsvBar>();
            string           symbol                  = null;
            BarScaleInterval scaleInterval           = null;
            bool             allCsvBarsHaveDOHLCV    = true;
            string           dateAndTimeFormatsGlued = this.dataSnapshot.FieldSetupCurrent.DateAndTimeFormatsGlued;

            foreach (OLVColumn each in this.olvParsedByFormat.Columns)
            {
                each.HeaderForeColor = Color.Black;
            }

            foreach (List <string> row in this.csvUnnamed)
            {
                try {
                    CsvBar newCsvBar = new CsvBar();
                    //foreach (string cell in row) {
                    for (int i = 0; i < row.Count; i++)
                    {
                        string cell    = row[i];
                        var    iColumn = this.dataSnapshot.FieldSetupCurrent[i];
                        try {
                            iColumn.Parser.ParseAndPushThrows(cell, newCsvBar, dateAndTimeFormatsGlued);
                        } catch (Exception ex) {
                            //YOULL_RESET_COLUMNS_DESIGNER_this.olvParsedByFormat.Reset();
                            //UPSTACK_CATCH_DOES_THIS this.olvParsedByFormat.SetObjects(null);
                            //UPSTACK_CATCH_DOES_THIS this.olvParsedByFormat.EmptyListMsg = msg;
                            string msg = "value[" + cell + "] column#[" + i + "] type[" + iColumn.Parser.CsvType + "]"
                                         + "\r\n" + ex.Message;
                            throw new Exception(msg, ex);
                        }
                        switch (iColumn.Parser.CsvType)
                        {
                        case CsvFieldType.Symbol:
                            if (String.IsNullOrEmpty(symbol) == false)
                            {
                                break;
                            }
                            symbol = cell;
                            break;

                        case CsvFieldType.Interval_Min:
                            if (scaleInterval != null)
                            {
                                break;
                            }
                            int  minutes         = 0;
                            bool minutesParsedOk = int.TryParse(cell, out minutes);
                            if (minutesParsedOk == false)
                            {
                                break;
                            }
                            if (minutes <= 0)
                            {
                                break;
                            }
                            scaleInterval = new BarScaleInterval(BarScale.Minute, minutes);
                            break;

                        case CsvFieldType.Interval_Hrs:
                            if (scaleInterval != null)
                            {
                                break;
                            }
                            int  hours         = 0;
                            bool hoursParsedOk = int.TryParse(cell, out hours);
                            if (hoursParsedOk == false)
                            {
                                break;
                            }
                            if (hours <= 0)
                            {
                                break;
                            }
                            scaleInterval = new BarScaleInterval(BarScale.Hour, hours);
                            break;

                        case CsvFieldType.Interval_Days:
                            if (scaleInterval != null)
                            {
                                break;
                            }
                            int  days         = 0;
                            bool daysParsedOk = int.TryParse(cell, out days);
                            if (daysParsedOk == false)
                            {
                                break;
                            }
                            if (days <= 0)
                            {
                                break;
                            }
                            scaleInterval = new BarScaleInterval(BarScale.Daily, days);
                            break;
                        }
                    }
                    allCsvBarsHaveDOHLCV &= newCsvBar.IsFullyFilledDOHLCV;
                    csvParsedByFormat.Add(newCsvBar);
                } catch (Exception ex) {
                    this.olvCsvParsedRaw.SelectObject(row);
                    throw ex;
                }
            }
            this.olvParsedByFormat.SetObjects(csvParsedByFormat);

            if (allCsvBarsHaveDOHLCV == false || csvParsedByFormat.Count == 0)
            {
                this.disableRangeBarAndBtnImport();
                return;
            }

            this.csvParsedByFormat          = csvParsedByFormat;
            this.symbolDetectedInCsv        = symbol;
            this.scaleIntervalDetectedInCsv = scaleInterval;
            this.step4createBarsDisplayChart();
        }