예제 #1
0
        /// <summary>
        /// Used to create input text file by taking type of file, templateName and fileextension as input.
        /// </summary>
        /// <param name="typeOfFile","templateName","fileextension">type of file</param>
        /// <returns>success or error message</returns>
        public static string GenerateInputDataTextfile(TypeOfFile typeOfFile, string templateName, string fileextension)
        {
            string projectPath = string.Empty;
            string path        = Directory.GetCurrentDirectory();
            var    patharray   = path.Split('\\');
            int    length      = patharray.Length;

            for (int i = 0; i <= length - 4; i++)
            {
                projectPath = projectPath + patharray[i] + "\\";
            }
            projectPath = projectPath + @"BnPBaseFramework.IO";

            string schemaText = string.Empty;

            string        result         = "Error";
            StringBuilder jsonSchemaPath = new StringBuilder();
            string        inputDataPath  = string.Empty;

            try
            {
                if (ConfigurationManager.AppSettings["JsonSchema"] != null)
                {
                    jsonSchemaPath.Append(ConfigurationManager.AppSettings["JsonSchema"]);

                    jsonSchemaPath.Append(@"\");
                    jsonSchemaPath.Append(typeOfFile.ToString() + @"\");
                    jsonSchemaPath.Append(typeOfFile.ToString() + @"_InputTextFiles");
                    jsonSchemaPath.Append(@"\");
                    jsonSchemaPath.Append(templateName);

                    if (File.Exists(jsonSchemaPath.ToString()))
                    {
                        string[] Input = File.ReadAllLines(jsonSchemaPath.ToString());
                        OutputFilePath = projectPath + @"\DapStuff\" + typeOfFile + ".txt";

                        if (File.Exists(OutputFilePath))
                        {
                            File.WriteAllLines(OutputFilePath, Input);
                            result = "Data Inserted into the file Successfully";
                        }
                        else
                        {
                            File.AppendAllLines(OutputFilePath, Input);
                            result = "Data Inserted into the file Successfully";
                        }
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                result = ex.Message;
            }


            return(result);
        }
예제 #2
0
        /// <summary>
        /// Used to create batch file by taking type of file as input.
        /// </summary>
        /// <param name="typeOfFile">type of file</param>
        /// <returns>success or error message</returns>
        public static string CreateBatchFile(TypeOfFile typeOfFile)
        {
            string  projectPath = string.Empty;
            Process process     = null;

            try
            {
                string path      = Directory.GetCurrentDirectory();
                var    patharray = path.Split('\\');
                int    length    = patharray.Length;
                for (int i = 0; i <= length - 4; i++)
                {
                    projectPath = projectPath + patharray[i] + "\\";
                }
                projectPath = projectPath + @"BnPBaseFramework.IO";

                StringBuilder pushD, config, fileName, script;
                pushD = new StringBuilder();
                pushD.Append(projectPath);
                pushD.Append(ConfigurationManager.AppSettings[typeOfFile.ToString() + "PushD"]);
                pushD.Append("\n");
                config = new StringBuilder();
                config.Append(projectPath);
                config.Append(ConfigurationManager.AppSettings[typeOfFile.ToString() + "Config"]);
                fileName = new StringBuilder();
                fileName.Append(projectPath);
                fileName.Append(ConfigurationManager.AppSettings[typeOfFile.ToString() + "FileName"]);
                fileName.Append("\n");
                script = new StringBuilder();
                script.Append("pushd ");
                script.Append(pushD);
                script.Append("DAPConsoleProcessor.exe  /K -config ");
                script.Append(config);
                script.Append(" -filename ");
                script.Append(fileName);
                // script.Append("pause");
                File.WriteAllText(projectPath + @"\DapStuff\Brierley.DataAcquisition" + "\\" + typeOfFile.ToString() + "File.bat", script.ToString());
                result = "Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (process != null)
                {
                    process.Close();
                }
                result = ex.Message;
            }


            return(result);
        }
예제 #3
0
        /// <summary>
        /// method to generate random input data based on json template
        /// </summary>
        /// <param name="typeOfFile"></param>
        /// <param name="templateName"></param>
        /// <returns></returns>
        public static string GenerateInputData(TypeOfFile typeOfFile, string templateName)

        {
            string schemaText = string.Empty;

            string result = "Error";

            StringBuilder jsonSchemaPath = new StringBuilder();

            string inputDataPath = string.Empty;



            try

            {
                if (ConfigurationManager.AppSettings["JsonSchema"] != null)

                {
                    jsonSchemaPath.Append(ConfigurationManager.AppSettings["JsonSchema"]);

                    jsonSchemaPath.Append(@"\");

                    jsonSchemaPath.Append(typeOfFile.ToString() + @"\");

                    jsonSchemaPath.Append(typeOfFile.ToString() + @"_JSONTemplates");



                    if (jsonSchemaPath != null)

                    {
                        inputDataPath = jsonSchemaPath.ToString().Replace("JSONTemplates", "InputTextFiles");
                        jsonSchemaPath.Append(@"\");
                        jsonSchemaPath.Append(templateName);
                        jsonSchemaPath.Append(".JSON");
                        string outPutFilePath = inputDataPath + "\\" + templateName + ".txt";
                        try

                        {
                            if (File.Exists(outPutFilePath))
                            {
                                File.Delete(outPutFilePath);
                            }
                        }

                        catch (FileNotFoundException ex)

                        {
                            result = ex.Message;
                        }

                        using (var r = new StreamReader(jsonSchemaPath.ToString()))

                        {
                            schemaText = r.ReadToEnd();
                        }

                        dynamic dynObj = JsonConvert.DeserializeObject(schemaText);

                        foreach (var data in dynObj.Files)

                        {
                            foreach (var data1 in data.TypeOfFiles)

                            {
                                JObject       dObject        = data1;
                                var           delimiter      = Convert.ToString(dObject["Delimiter"]);
                                var           noOfRows       = Convert.ToInt32(dObject["No_Of_Rows"]);
                                StringBuilder inputDataStore = null;
                                DataTable     dataTable      = null;
                                int           loyalCount     = 0;
                                while (noOfRows > 0)

                                {
                                    int propertiesCount = 2;
                                    inputDataStore = new StringBuilder();
                                    foreach (var item in dObject.Properties())
                                    {
                                        var attributeName = item.Name;

                                        string[] chkList = { "Delimiter", "No_Of_Rows", "Directive" };

                                        if (attributeName == "Directive")

                                        {
                                            var directiveItem = item.Value.Last;

                                            var directive = Convert.ToString(((Newtonsoft.Json.Linq.JValue)directiveItem.First).Value);

                                            inputDataStore.Append(directive);

                                            inputDataStore.Append(delimiter);
                                        }

                                        else if (Array.IndexOf(chkList, attributeName) < 0)

                                        {
                                            var first = item.Value.First;

                                            var last = item.Value.Last;

                                            var firstValue = Convert.ToString(((Newtonsoft.Json.Linq.JValue)first.First).Value);

                                            var lastValue = Convert.ToString(((Newtonsoft.Json.Linq.JValue)last.First).Value);

                                            int startIndex = firstValue.IndexOf('[');

                                            int endIndex = firstValue.IndexOf(']');

                                            var attributeType = firstValue.Substring(0, startIndex).ToUpper();

                                            var attributeRange = firstValue.Substring(startIndex + 1, endIndex - startIndex - 1);

                                            var attributeRequired = lastValue.Replace("{", "").Replace("}", "").ToUpper();



                                            int length = 0;

                                            uint minLength = 0, maxLength = 0;

                                            string regexExp = string.Empty;
                                            if (attributeType == "STRING" && attributeRange.Contains("-"))
                                            {
                                                minLength = Convert.ToUInt16(attributeRange.Split('-')[0]);
                                                maxLength = Convert.ToUInt16(attributeRange.Split('-')[1]);
                                            }

                                            else if (attributeType == "INT")
                                            {
                                                length = Convert.ToInt32(attributeRange);
                                            }
                                            else if (attributeType == "DATABASEVALUE")
                                            {
                                                //if (loyalCount == 0)
                                                //{
                                                dataTable = GetDBValue(attributeRange.Split('-')[0], attributeName, attributeRange.Split('-')[1], null);
                                                //}
                                            }
                                            else if (attributeType == "REGULAREXP")
                                            {
                                                string parse = @firstValue.Replace("RegularExp[", "");
                                                regexExp = parse.Substring(0, parse.Length - 1).Replace("\"", @"\");
                                            }
                                            else if (attributeType == "STRING" && !attributeRange.Contains('-'))

                                            {
                                                minLength = Convert.ToUInt32(attributeRange);
                                            }



                                            switch (attributeType)
                                            {
                                                #region  Integer
                                            case "INT":
                                                if (attributeRequired == "TRUE")
                                                {
                                                    switch (attributeName)

                                                    {
                                                    case "Status":

                                                    {
                                                        inputDataStore.Append((int)Eric.Morrison.RandomValue.GetRandomEnumValue <Status>());
                                                    }

                                                    break;

                                                    case "StoreType":
                                                    {
                                                        inputDataStore.Append((int)Eric.Morrison.RandomValue.GetRandomEnumValue <StoreType>());
                                                    }


                                                    break;

                                                    default:
                                                    {
                                                        inputDataStore.Append(RandomNumber(length));
                                                    }

                                                    break;
                                                    }
                                                }

                                                break;

                                                #endregion
                                                #region RegularExpressionValidator
                                            case "REGULAREXP":
                                            {
                                                if (attributeRequired == "TRUE")
                                                {
                                                    if (Regex.IsMatch(CreateEmail(), regexExp, RegexOptions.IgnoreCase))
                                                    {
                                                        inputDataStore.Append(CreateEmail());
                                                    }
                                                }
                                                break;
                                            }

                                                #endregion
                                                #region string
                                            case "STRING":

                                                if (attributeRequired == "TRUE")

                                                {
                                                    if (maxLength == 0)

                                                    {
                                                        switch (attributeName)

                                                        {
                                                        case "Password":

                                                        {
                                                            inputDataStore.Append(CreatePassword(minLength));

                                                            break;
                                                        }



                                                        default:

                                                        {
                                                            inputDataStore.Append(Eric.Morrison.RandomString.Get(minLength, true));

                                                            break;
                                                        }
                                                        }
                                                    }

                                                    else

                                                    {
                                                        inputDataStore.Append(Eric.Morrison.RandomString.Get(minLength, maxLength, true));
                                                    }
                                                }

                                                break;

                                                #endregion
                                                #region Date
                                            case "DATE":

                                                if (attributeRequired == "TRUE")

                                                {
                                                    DateTime dateTime = System.DateTime.Now.AddDays(-1);

                                                    inputDataStore.Append(dateTime.ToString("dd-MMM-yy HH.mm.ss tt"));
                                                }

                                                break;
                                                #endregion
                                                #region Double

                                            case "DOUBLE":
                                            {
                                                if (attributeRequired == "TRUE")
                                                {
                                                    System.Random random = new System.Random();

                                                    inputDataStore.Append(Math.Round(random.NextDouble(), 2).ToString("0.00"));
                                                }
                                            }

                                            break;

                                                #endregion
                                                #region DbValue
                                            case "DATABASEVALUE":
                                            {
                                                if (attributeRequired == "TRUE")
                                                {
                                                    if ((attributeRange.Split('-')[1]) == "ALL")
                                                    {
                                                        string    number        = (RandomNumber(10));
                                                        DataTable dtTxnHeaderId = GetDBValue(attributeRange.Split('-')[0], attributeName, attributeRange.Split('-')[1], number);

                                                        while (Convert.ToInt32(dtTxnHeaderId.Rows[0][0]) == 0)
                                                        {
                                                            inputDataStore.Append(number);
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        inputDataStore.Append(dataTable.Rows[loyalCount][0]);
                                                    }
                                                }
                                            }
                                            break;
                                                #endregion
                                            }

                                            if (propertiesCount - 1 < dObject.Properties().Count())

                                            {
                                                inputDataStore.Append(delimiter);
                                            }
                                        }

                                        propertiesCount++;
                                    }

                                    System.IO.File.AppendAllText(outPutFilePath, inputDataStore.ToString() + Environment.NewLine);

                                    result = "Success";

                                    noOfRows--;
                                    loyalCount++;
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)

            {
                result = ex.Message;
            }

            return(result);
        }