private string GetIAPropertyValue(SourceTemplate sourceTemplate, string propertyName, string propertyValueInTemplate, FileCategory category)
        {
            try
            {
                if ((propertyName + "").Trim().Length == 0)
                {
                    return(GetIAEmptyPropertyName(sourceTemplate, category));
                }

                if (propertyName.Contains("HONG KONG CODE"))
                {
                    return(GetIAOfficialCode(sourceTemplate, category));
                }

                if (propertyName.Contains("ASSET COMMON NAME"))
                {
                    return(GetIADisplayname(sourceTemplate, category));
                }

                if (propertyName.Contains("RCS ASSET CLASS"))
                {
                    return(FileCategory.RIGHTS.Equals(category) ? "RTS" : propertyValueInTemplate);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("\r\n	     ClassName:  {0}\r\n	     MethodName: {1}\r\n	     Message:    {2}",
                                           System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),
                                           System.Reflection.MethodBase.GetCurrentMethod().Name,
                                           ex.Message);
                Logger.Log(msg, Logger.LogType.Error);
            }

            return(string.Empty);
        }
        private void FillIATemplate(List <List <string> > iaTemplate, SourceTemplate sourceTemplate, FileCategory category)
        {
            try
            {
                if (sourceTemplate == null)
                {
                    LogMessage("there is no data in the ParellelTrading source file.");
                    return;
                }

                List <List <string> > propertyName = GetPropertyName(iaTemplate);
                if (propertyName == null || propertyName.Count == 0)
                {
                    LogMessage("ParellelTrading QATemplate is emptyt.");
                    return;
                }

                for (int i = 0; i < propertyName[0].Count; i++)
                {
                    iaTemplate[i + 1][4] = GetIAEffectiveTo(category);
                    iaTemplate[i + 1][3] = GetIAEffectiveDate(sourceTemplate, category);
                    iaTemplate[i + 1][2] = GetIAPropertyValue(sourceTemplate, propertyName[0][i], iaTemplate[i + 1][2], category);
                    iaTemplate[i + 1][5] = GetIAChangeOffset(sourceTemplate, propertyName[0][i], category);
                    iaTemplate[i + 1][6] = GetIAChangeTrigger(sourceTemplate, propertyName[0][i], category);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("\r\n	     ClassName:  {0}\r\n	     MethodName: {1}\r\n	     Message:    {2}",
                                           System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),
                                           System.Reflection.MethodBase.GetCurrentMethod().Name,
                                           ex.Message);
                Logger.Log(msg, Logger.LogType.Error);
            }
        }
        private void FillQATemplate(List <List <string> > qaTemplate, SourceTemplate sourceTemplate, FileCategory category)
        {
            try
            {
                if (sourceTemplate == null)
                {
                    LogMessage("there is no data in the ParellelTrading source file.");
                    return;
                }

                List <List <string> > propertyName = GetPropertyName(qaTemplate);
                if (propertyName == null || propertyName.Count == 0)
                {
                    LogMessage("ParellelTrading is emptyt.");
                    return;
                }

                Dictionary <int, string> endString = new Dictionary <int, string>();
                endString.Add(0, ".HK");

                if (category.Equals(FileCategory.RIGHTS))
                {
                    endString.Add(1, "ta.HK");
                    //endString.Add(2, ".HS");
                }
                else
                {
                    endString.Add(1, "stat.HK");
                    endString.Add(2, "ta.HK");
                    endString.Add(3, ".HS");
                }

                int index;
                for (int i = 0; i < propertyName.Count; i++)
                {
                    for (int j = 0; j < propertyName[i].Count; j++)
                    {
                        index = GetIndex(i, j, propertyName);
                        qaTemplate[index][0] = string.Format("{0}{1}", GetQAUnderlying(sourceTemplate, category), endString[i]);
                        qaTemplate[index][2] = GetQAPropertyValue(sourceTemplate, propertyName[i][j], endString[i], category);
                        qaTemplate[index][3] = GetQAEffectiveDate(sourceTemplate, category);
                        qaTemplate[index][4] = GetQAEffectiveTo(propertyName[i][j], category);
                        qaTemplate[index][5] = GetQAChangeOffset(sourceTemplate, propertyName[i][j], category);
                        qaTemplate[index][6] = GetQAChangeTrigger(sourceTemplate, propertyName[i][j], category);
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("\r\n	     ClassName:  {0}\r\n	     MethodName: {1}\r\n	     Message:    {2}",
                                           System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),
                                           System.Reflection.MethodBase.GetCurrentMethod().Name,
                                           ex.Message);
                Logger.Log(msg, Logger.LogType.Error);
            }
        }
        private string GetIAChangeOffset(SourceTemplate sourceTemplate, string propertyName, FileCategory category)
        {
            //if (category.Equals(FileCategory.RIGHTS))
            //{
            //    if ((propertyName + "").Trim().Length == 0)
            //        return string.Empty;
            //    else
            //        return "23";
            //}

            return(string.Empty);
        }
        private string GetIAChangeTrigger(SourceTemplate sourceTemplate, string propertyName, FileCategory category)
        {
            if (category.Equals(FileCategory.HShareIPO) || category.Equals(FileCategory.IPO) || category.Equals(FileCategory.RIGHTS))
            {
                if ((propertyName + "").Trim().Length == 0)
                {
                    return(string.Empty);
                }
                else
                {
                    return("PEO");
                }
            }

            return(string.Empty);
        }
        private string GetQAChangeOffset(SourceTemplate sourceTemplate, string propertyName, FileCategory category)
        {
            if (category.Equals(FileCategory.RIGHTS))
            {
                if ((propertyName + "").Contains("RIC"))
                {
                    return("23");
                }
                else
                {
                    return(string.Empty);
                }
            }

            return(string.Empty);
        }
        private string GetIALotSize(SourceTemplate sourceTemplate, FileCategory category)
        {
            //if (category.Equals(FileCategory.ParellelTrading))
            //    return sourceTemplate.LotSizeNew;
            //else
            //    return sourceTemplate.LotSize;

            if ((sourceTemplate.LotSizeNew + "").Trim().Length != 0)
            {
                return(sourceTemplate.LotSizeNew);
            }
            else if ((sourceTemplate.LotSize + "").Trim().Length != 0)
            {
                return(sourceTemplate.LotSize);
            }
            else
            {
                LogMessage("cannot found the LotSizeNew/LotSize in the source file.");
                return(string.Empty);
            }
        }
        private string GetIAUnderlying(SourceTemplate sourceTemplate, FileCategory category)
        {
            //if (category.Equals(FileCategory.ParellelTrading))
            //    return sourceTemplate.UnderlyingRICNew;
            //else
            //    return sourceTemplate.UnderlyingRIC;

            if ((sourceTemplate.UnderlyingRICNew + "").Trim().Length != 0)
            {
                return(sourceTemplate.UnderlyingRICNew);
            }
            else if ((sourceTemplate.UnderlyingRIC + "").Trim().Length != 0)
            {
                return(sourceTemplate.UnderlyingRIC);
            }
            else
            {
                LogMessage("cannot found the UnderlyingRICNew/UnderlyingRIC in the source file.");
                return(string.Empty);
            }
        }
        private string GetQAPropertyValue(SourceTemplate sourceTemplate, string propertyName, string endString, FileCategory category)
        {
            try
            {
                if ((propertyName + "").Trim().Length == 0)
                {
                    return(string.Empty);
                }

                if (propertyName.Contains("RIC"))
                {
                    return(string.Format("{0}{1}", GetQAUnderlying(sourceTemplate, category), endString));
                }

                if (propertyName.Contains("ASSET COMMON NAME"))
                {
                    return(GetQADisplayname(sourceTemplate, category));
                }

                if (propertyName.Contains("ROUND LOT SIZE"))
                {
                    return(GetQALotSize(sourceTemplate, category));
                }

                if (propertyName.Contains("TICKER SYMBOL"))
                {
                    return(GetQAOfficialCode(sourceTemplate, category));
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("\r\n	     ClassName:  {0}\r\n	     MethodName: {1}\r\n	     Message:    {2}",
                                           System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),
                                           System.Reflection.MethodBase.GetCurrentMethod().Name,
                                           ex.Message);
                Logger.Log(msg, Logger.LogType.Error);
            }

            return(string.Empty);
        }
        private string GetIADisplayname(SourceTemplate sourceTemplate, FileCategory category)
        {
            if (category.Equals(FileCategory.HShareIPO))
            {
                return(string.Format("{0} Ord Shs H", sourceTemplate.LegalRegisteredName.Replace("Company", "").Replace("Limited", "").Trim()));
            }

            if (category.Equals(FileCategory.IPO))
            {
                return(string.Format("{0} Ord Shs", sourceTemplate.LegalRegisteredName.Replace("Company", "").Replace("Limited", "").Trim()));
            }

            if (category.Equals(FileCategory.ParellelTrading))
            {
                return(string.Format("{0} Ord Shs (Temp)", sourceTemplate.LegalRegisteredName.Replace("Company", "").Replace("Limited", "").Trim()));
            }

            if (category.Equals(FileCategory.RIGHTS))
            {
                return(string.Format("{0} Rights", sourceTemplate.LegalRegisteredName.Replace("Company", "").Replace("Limited", "").Trim()));
            }

            return(string.Empty);
        }
        private string GetQADisplayname(SourceTemplate sourceTemplate, FileCategory category)
        {
            if (category.Equals(FileCategory.HShareIPO))
            {
                return(string.Format("{0} ORD H", sourceTemplate.Displayname.Replace("<--NOT YET CFM", "").Trim()));
            }

            if (category.Equals(FileCategory.IPO))
            {
                return(string.Format("{0} ORD", sourceTemplate.Displayname.Replace("<--NOT YET CFM", "").Trim()));
            }

            if (category.Equals(FileCategory.ParellelTrading))
            {
                return(string.Format("{0} ORD (TEMP)", sourceTemplate.Displayname.Replace("<--NOT YET CFM", "").Trim()));
            }

            if (category.Equals(FileCategory.RIGHTS))
            {
                return(sourceTemplate.Displayname.Replace("<--NOT YET CFM", "").Trim());
            }

            return(string.Empty);
        }
        private SourceTemplate FormatSource(List <List <string> > listSource)
        {
            SourceTemplate sourceTemplate = new SourceTemplate();

            try
            {
                foreach (var line in listSource)
                {
                    if (line == null || line.Count < 2)
                    {
                        continue;
                    }

                    if ((line[0] + "").Trim().Length == 0)
                    {
                        continue;
                    }

                    string name  = line[0].Trim();
                    string value = (line[1] + "").Replace("<-- NOT YET CFM", "").Trim();
                    if (name.Contains("Effective Date:") && value.Length != 0)
                    {
                        sourceTemplate.EffectiveDate = ConvertDateNumber(value);
                    }

                    if (name.Contains("Effective Date (NEW):") && value.Length != 0)
                    {
                        sourceTemplate.EffectiveDateNew = ConvertDateNumber(value);
                    }

                    if (name.Contains("Underlying RIC:") && value.Length != 0)
                    {
                        sourceTemplate.UnderlyingRIC = value.Substring(0, value.Length - 3);
                    }

                    if (name.Contains("Underlying RIC (NEW):") && value.Length != 0)
                    {
                        sourceTemplate.UnderlyingRICNew = value.Substring(0, value.Length - 3);
                    }

                    if (name.Contains("Displayname:") && value.Length != 0)
                    {
                        sourceTemplate.Displayname = value;
                    }

                    if (name.Contains("Displayname (NEW):") && value.Length != 0)
                    {
                        sourceTemplate.DisplaynameNew = value;
                    }

                    if (name.Contains("Official Code:") && value.Length != 0)
                    {
                        sourceTemplate.OfficialCode = value;
                    }

                    if (name.Contains("Official Code (NEW):") && value.Length != 0)
                    {
                        sourceTemplate.OfficialCodeNew = value;
                    }

                    if (name.Contains("Lot Size:") && value.Length != 0)
                    {
                        sourceTemplate.LotSize = value;
                    }

                    if (name.Contains("Lot Size (NEW):") && value.Length != 0)
                    {
                        sourceTemplate.LotSizeNew = value;
                    }

                    if (name.Contains("Legal Registered Name:") && value.Length != 0)
                    {
                        sourceTemplate.LegalRegisteredName = value;
                    }

                    if (name.Contains("Legal Registered Name (NEW):") && value.Length != 0)
                    {
                        sourceTemplate.LegalRegisteredNameNew = value;
                    }
                }

                return(sourceTemplate);
            }
            catch (Exception ex)
            {
                string msg = string.Format("\r\n	     ClassName:  {0}\r\n	     MethodName: {1}\r\n	     Message:    {2}",
                                           System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),
                                           System.Reflection.MethodBase.GetCurrentMethod().Name,
                                           ex.Message);
                Logger.Log(msg, Logger.LogType.Error);

                return(null);
            }
        }
 private string GetIAEffectiveDate(SourceTemplate sourceTemplate, FileCategory category)
 {
     return(sourceTemplate.EffectiveDate);
 }
 private string GetIAEmptyPropertyName(SourceTemplate sourceTemplate, FileCategory category)
 {
     return(string.Empty);
 }
        protected override void Start()
        {
            if (!CheckConfig())
            {
                return;
            }

            #region [HShareIPO]
            if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.HShareIPO))
            {
                LogMessage(string.Format("start to generate {0} bulk file.", FileCategory.HShareIPO.ToString()));
                string folder = Path.Combine(configObj.OutputFolder, Path.Combine("HShareIPO", DateTime.Now.ToString("MM-dd-yyyy")));
                List <List <string> > source         = ReadExcel(configObj.SourcePathHShareIPO, 1);
                List <List <string> > qaTemplate     = ReadExcel(configObj.TemplatePathHShareIPO, 1);
                SourceTemplate        sourceTemplate = FormatSource(source);
                FillQATemplate(qaTemplate, sourceTemplate, FileCategory.HShareIPO);
                FillIATemplate(iaTemplate, sourceTemplate, FileCategory.HShareIPO);

                string pathQA = Path.Combine(folder, string.Format("Quote_Future_Add_{0}(HShareIPO).csv", sourceTemplate.OfficialCode));
                GenerateFile(pathQA, qaTemplate);
                AddResult("Quote_Future_Add_HShareIPO.csv", pathQA, "qa bulk file");

                string pathIA = Path.Combine(folder, string.Format("Issue_Future_Add_{0}(HShareIPO).csv", sourceTemplate.OfficialCode));
                GenerateFile(pathIA, iaTemplate);
                AddResult("Issue_Future_Add_HShareIPO.csv", pathIA, "ia bulk file");
            }
            #endregion

            #region [IPO]
            if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.IPO))
            {
                LogMessage(string.Format("start to generate {0} bulk file.", FileCategory.IPO.ToString()));
                string folder = Path.Combine(configObj.OutputFolder, Path.Combine("IPO", DateTime.Now.ToString("MM-dd-yyyy")));
                List <List <string> > source         = ReadExcel(configObj.SourcePathIPO, 1);
                List <List <string> > qaTemplate     = ReadExcel(configObj.TemplatePathIPO, 1);
                SourceTemplate        sourceTemplate = FormatSource(source);
                FillQATemplate(qaTemplate, sourceTemplate, FileCategory.IPO);
                FillIATemplate(iaTemplate, sourceTemplate, FileCategory.IPO);

                string pathQA = Path.Combine(folder, string.Format("Quote_Future_Add_{0}(IPO).csv", sourceTemplate.OfficialCode));
                GenerateFile(pathQA, qaTemplate);
                AddResult("Quote_Future_Add_IPO.csv", pathQA, "qa bulk file");

                string pathIA = Path.Combine(folder, string.Format("Issue_Future_Add_{0}(IPO).csv", sourceTemplate.OfficialCode));
                GenerateFile(pathIA, iaTemplate);
                AddResult("Issue_Future_Add_IPO.csv", pathIA, "ia bulk file");
            }
            #endregion

            #region [ParaellelTrading]
            if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.ParellelTrading))
            {
                LogMessage(string.Format("start to generate {0} bulk file.", FileCategory.ParellelTrading.ToString()));
                string folder = Path.Combine(configObj.OutputFolder, Path.Combine("ParellelTrading", DateTime.Now.ToString("MM-dd-yyyy")));
                List <List <string> > source         = ReadExcel(configObj.SourcePathParellel, 1);
                List <List <string> > qaTemplate     = ReadExcel(configObj.TemplatePathParellel, 1);
                SourceTemplate        sourceTemplate = FormatSource(source);
                FillQATemplate(qaTemplate, sourceTemplate, FileCategory.ParellelTrading);
                FillIATemplate(iaTemplate, sourceTemplate, FileCategory.ParellelTrading);

                string pathQA = Path.Combine(folder, string.Format("Quote_Future_Add_{0}(Parellel trading).csv", sourceTemplate.OfficialCodeNew));
                GenerateFile(pathQA, qaTemplate);
                AddResult("Quote_Future_Add_Parellel trading.csv", pathQA, "qa bulk file");

                string pathIA = Path.Combine(folder, string.Format("Issue_Future_Add_{0}(Parellel trading)(Parellel trading).csv", sourceTemplate.OfficialCodeNew));
                GenerateFile(pathIA, iaTemplate);
                AddResult("Issue_Future_Add_Parellel trading.csv", pathIA, "ia bulk file");
            }
            #endregion

            #region [RIGHTS]
            if (configObj.FileType.Equals(FileCategory.AllType) || configObj.FileType.Equals(FileCategory.RIGHTS))
            {
                LogMessage(string.Format("start to generate {0} bulk file.", FileCategory.RIGHTS.ToString()));
                string folder = Path.Combine(configObj.OutputFolder, Path.Combine("RIGHTS", DateTime.Now.ToString("MM-dd-yyyy")));
                List <List <string> > source         = ReadExcel(configObj.SourcePathRIGHTS, 1);
                List <List <string> > qaTemplate     = ReadExcel(configObj.TemplatePathRIGHTS, 1);
                SourceTemplate        sourceTemplate = FormatSource(source);
                FillQATemplate(qaTemplate, sourceTemplate, FileCategory.RIGHTS);
                FillIATemplate(iaTemplate, sourceTemplate, FileCategory.RIGHTS);

                string pathQA = Path.Combine(folder, string.Format("Quote_Future_Add_{0}(RIGHTS).csv", sourceTemplate.OfficialCode));
                GenerateFile(pathQA, qaTemplate);
                AddResult("Quote_Future_Add_RIGHTS.csv", pathQA, "qa bulk file");

                string pathIA = Path.Combine(folder, string.Format("Issue_Future_Add_{0}(RIGHTS).csv", sourceTemplate.OfficialCode));
                GenerateFile(pathIA, iaTemplate);
                AddResult("Issue_Future_Add_RIGHTS.csv", pathIA, "ia bulk file");
            }
            #endregion
        }