public bool AddStaticData(string key, IRunTimeStaticData vaule)
        {
            switch (vaule.RunTimeStaticDataType)
            {
            case CaseStaticDataType.caseStaticData_vaule:
                return(AddStaticDataKey(key, vaule));

            case CaseStaticDataType.caseStaticData_index:
            case CaseStaticDataType.caseStaticData_long:
            case CaseStaticDataType.caseStaticData_random:
            case CaseStaticDataType.caseStaticData_time:
            case CaseStaticDataType.caseStaticData_list:
            case CaseStaticDataType.caseStaticData_strIndex:
                return(AddStaticDataParameter(key, vaule));

            case CaseStaticDataType.caseStaticData_csv:
            case CaseStaticDataType.caseStaticData_mysql:
            case CaseStaticDataType.caseStaticData_redis:
                IRunTimeDataSource tempDataSource = vaule as IRunTimeDataSource;
                if (tempDataSource == null)
                {
                    return(false);
                }
                return(AddStaticDataSouce(key, tempDataSource));

            default:
                throw new NotSupportedException("nukonw CaseStaticDataType");
            }
        }
 public bool AddStaticDataSouce(string key, IRunTimeDataSource vaule)
 {
     if (IsHasSameKey(key, IsAllCollectionKeyUnique ? 0 : 3) != null)
     {
         if (!RemoveStaticData(key, false))
         {
             return(false);
         }
     }
     runActuatorStaticDataSouceList.MyAdd <IRunTimeDataSource>(key, vaule);
     OnListChanged(true);
     return(true);
 }
Example #3
0
        public static bool GetCsvStaticDataSource(out IRunTimeDataSource yourStaticData, out string errorMes, string yourFormatData)
        {
            errorMes       = null;
            yourStaticData = null;
            string   csvPath     = null;
            int      CodePage    = 65001;
            Encoding csvEncoding = null;

            if (yourFormatData.Contains('-'))
            {
                if (!yourFormatData.MySplitIntEnd('-', out csvPath, out CodePage))
                {
                    errorMes = string.Format("[GetCsvStaticDataSource]error in [MySplitIntEnd] with :[{0}]", yourFormatData);
                    return(false);
                }
            }
            else
            {
                csvPath = yourFormatData;
            }
            try
            {
                csvEncoding = System.Text.Encoding.GetEncoding(CodePage);
            }
            catch
            {
                errorMes = string.Format("[GetCsvStaticDataSource]error in 【CodePage】 [{0}]", yourFormatData);
                return(false);
            }
            csvPath = csvPath.StartsWith("@") ? csvPath.Remove(0, 1) : string.Format("{0}\\casefile\\{1}", CaseTool.rootPath, csvPath);
            if (!System.IO.File.Exists(csvPath))
            {
                errorMes = string.Format("[GetCsvStaticDataSource]error in csv path [path not exixts] [{0}]", yourFormatData);
                return(false);
            }
            MyCommonHelper.FileHelper.CsvFileHelper myCsv = new MyCommonHelper.FileHelper.CsvFileHelper(csvPath, csvEncoding);
            try
            {
                yourStaticData = new MyStaticDataSourceCsv(myCsv.GetListCsvData());
            }
            catch (Exception ex)
            {
                errorMes = ex.Message;
                return(false);
            }
            finally
            {
                myCsv.Dispose();
            }
            return(true);
        }
        public static bool GetCsvStaticDataSource(out IRunTimeDataSource yourStaticData, out string errorMes, string yourFormatData)
        {
            errorMes       = null;
            yourStaticData = null;
            string   csvPath     = null;
            int      CodePage    = 65001;
            Encoding csvEncoding = null;

#if ALLOW_CSV_EMPTY
            if (yourFormatData.StartsWith("*"))
            {
                int[] tempConuts;
                if (!yourFormatData.Remove(0, 1).MySplitToIntArray('-', out tempConuts) || tempConuts.Length != 2)
                {
                    errorMes = string.Format("[GetCsvStaticDataSource]error in [MySplitToIntArray] with :[{0}]", yourFormatData);
                    return(false);
                }
                if (tempConuts[0] < 1 || tempConuts[1] < 1)
                {
                    errorMes = string.Format("[GetCsvStaticDataSource]error in [MySplitToIntArray] with :[{0}] \nYour row conut and columu conut should greater than 0 ", yourFormatData);
                    return(false);
                }
                List <string> tempRow = new List <string>(tempConuts[0]);
                for (int i = 0; i < tempConuts[0]; i++)
                {
                    tempRow.Add(null);
                }
                List <List <string> > tempCsvDataSource = new List <List <string> >(tempConuts[1]);
                for (int i = 0; i < tempConuts[1]; i++)
                {
                    tempCsvDataSource.Add(tempRow.ToList());
                }
                yourStaticData = new MyStaticDataSourceCsv(tempCsvDataSource, yourFormatData);
                return(true);
            }
#endif
            if (yourFormatData.Contains('-'))
            {
                if (!yourFormatData.MySplitIntEnd('-', out csvPath, out CodePage))
                {
                    errorMes = string.Format("[GetCsvStaticDataSource]error in [MySplitIntEnd] with :[{0}]", yourFormatData);
                    return(false);
                }
            }
            else
            {
                csvPath = yourFormatData;
            }
            try
            {
                csvEncoding = System.Text.Encoding.GetEncoding(CodePage);
            }
            catch
            {
                errorMes = string.Format("[GetCsvStaticDataSource]error in 【CodePage】 [{0}]", yourFormatData);
                return(false);
            }
            csvPath = csvPath.StartsWith("@") ? csvPath.Remove(0, 1) : string.Format("{0}\\FreeHttp\\{1}", MyCommonTool.rootPath, csvPath);
            if (!System.IO.File.Exists(csvPath))
            {
                errorMes = string.Format("[GetCsvStaticDataSource]error in csv path [path not exixts] [{0}]", yourFormatData);
                return(false);
            }
            MyCommonHelper.FileHelper.CsvFileHelper myCsv = new MyCommonHelper.FileHelper.CsvFileHelper(csvPath, csvEncoding);
            try
            {
                yourStaticData = new MyStaticDataSourceCsv(myCsv.GetListCsvData(), yourFormatData);
            }
            catch (Exception ex)
            {
                errorMes = ex.Message;
                return(false);
            }
            finally
            {
                myCsv.Dispose();
            }
            return(true);
        }