Exemplo n.º 1
0
 public void Setup()
 {
     provicerMock = new Mock <IAppConfigProvider>();
     provicerMock.Setup(p => p.AppConfig).Returns(new AppConfig());
     provider = provicerMock.Object;
     cmd      = new GetAppSettings(provider);
 }
        public IHttpActionResult GetESKey(string username)
        {
            string   serializeResponse = "";
            Response response          = new Response();

            try
            {
                // Validate inputs
                if (!string.IsNullOrEmpty(username))
                {
                    string errorMessage = "";
                    // Get appsettings
                    AppSettingsValues appKeys   = GetAppSettings.GetAppSettingsValues();
                    ElasticSearch     es        = new ElasticSearch();
                    string            secretKey = "";
                    // Gets the key from ElasticSearch
                    string[] esResults = es.GetESKey(username, appKeys.LookupKey, out errorMessage);
                    if (esResults != null)
                    {
                        secretKey = esResults[0];
                    }
                    response.success = true;
                    response.message = secretKey;
                    Log.Info(username + " username, Process : Get ES key, Message : The Get method for Secret Key from Elastic Search has been successfully executed.");
                }
            }
            catch (Exception ex)
            {
                response.success = false;
                response.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                Log.Error(ex, username);
            }
            serializeResponse = JsonConvert.SerializeObject(response);
            return(Json(serializeResponse));
        }
Exemplo n.º 3
0
 public void Setup()
 {
     provicerMock = new Mock<IAppConfigProvider>();
     provicerMock.Setup(p => p.AppConfig).Returns(new AppConfig());
     provider = provicerMock.Object;
     cmd = new GetAppSettings(provider);
 }
Exemplo n.º 4
0
 public object Get(GetAppSettings getAppSettings)
 {
     return(new GetAppSettingsResponse()
     {
         AppSettings = AppSettingBusiness.GetAppSettings(getAppSettings.AppId)
     });
 }
Exemplo n.º 5
0
        public ApiResult <AppConfig> GetAppSettings()
        {
            var cmd = new GetAppSettings(appConfigProvider);

            cmd.Execute();
            return(cmd.Result);
        }
Exemplo n.º 6
0
 public async Task <object> Get(GetAppSettings getAppSettings)
 {
     return(new GetAppSettingsResponse()
     {
         AppSettings = await AppSettingBusiness.GetAppSettingsAsync(getAppSettings.AppId)
     });
 }
Exemplo n.º 7
0
        // Return a Model Object with index View and fill the data from Assets / Database
        public ActionResult Index([FromBody] OIDCRequest request)
        {
            // Model Object Declerations
            ParentModel     obj      = new ParentModel();
            Form9035        form     = new Form9035();
            Lists           allLists = new Lists();
            OrchestratorAPI api      = new OrchestratorAPI();
            // Add starting point on ES
            ElasticSearch es     = new ElasticSearch();
            string        bal_no = "";

            ViewBag.id_no = "";
            string errorMessage = "";

            try
            {
                AppSettingsValues appKeys = GetAppSettings.GetAppSettingsValues();
                string            url     = Request.Url.ToString();
                // LOCAL USE : Comment this 2 lines whenever you need to publish and push the code these are only for local use
                // add the case no. and the id no. whenever you're debugging and using this as local
                if (url.Contains("localhost"))
                {
                    //for staging localhost
                    request.State = "'+bal_no=1615.54312.7;id_no=BOT0001711;-5791a545d45a92763d8216ffb7004e3ebc32226af366113cf24975ea00014d51+";
                    //localhost
                    request.State = "'+bal_no=91.147449.2;id_no=43383;-5791a545d45a92763d8216ffb7004e3ebc32226af366113cf24975ea00014d51+";
                    request.Code  = "182635";
                }
                TempData["Error"] = "";
                string filter            = "";
                string encryptedData     = "";
                string decodeData        = "";
                string data              = "";
                string ListencryptedData = "";
                if ((request.Code != null && request.Code != "") && (request.State != null && request.State != ""))
                {
                    // GET The username which try to access this page
                    string sUserName = null;

                    if (url.Contains("localhost"))
                    {
                        sUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                    }
                    else
                    {
                        sUserName = User.Identity.Name;
                    }
                    // Extract the username from the identity
                    Log.Info("The User identity Name is : " + sUserName);
                    string[] spliUser = sUserName.Split('\\');
                    sUserName = spliUser[1];
                    Log.Info("The User Name is : " + sUserName);
                    // Split the request string and extract BAL Number and ID Number
                    string              stateStr    = request.State.ToString().Substring(2);
                    string[]            stateArray  = stateStr.Split('-');
                    string              splitArray  = stateArray[0].Replace(";", "&");
                    NameValueCollection queryString = HttpUtility.ParseQueryString(splitArray);
                    bal_no = queryString["bal_no"].ToString();
                    // Save into ViewBags for JS Use
                    ViewBag.id_no    = queryString["id_no"];
                    ViewBag.bal_no   = bal_no;
                    ViewBag.email_id = sUserName;
                    // Entry point on ES
                    if (es.AddESLog(ViewBag.bal_no, ViewBag.id_no, out errorMessage) == HttpStatusCode.BadRequest)
                    {
                        Log.Info(bal_no + ": Process : Draft9089 -  Error Occurred while Calling ES. See ES Log File for further details");
                    }
                    // Getting UIPATH Token
                    string token = api.Authentication(appKeys.isDevelopmentEnvironment);
                    Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message :  All variables has been initialized successfully.");
                    // get n check if asset exist
                    filter = "?$filter=Name eq '" + bal_no + "'";
                    AssetModel assetModel = api.GetAsset(token, filter);
                    // Extracting the Encrypted Data String
                    foreach (var item in assetModel.value)
                    {
                        // 9035 Model Value
                        if (!item.Name.Contains("Lists"))
                        {
                            if (encryptedData == "")
                            {
                                encryptedData = item.Value;
                            }
                            else
                            {
                                encryptedData += item.Value;
                            }
                        }
                        // List Model Value
                        else if (item.Name.Contains("Lists"))
                        {
                            if (ListencryptedData == "")
                            {
                                ListencryptedData = item.Value;
                            }
                            else
                            {
                                ListencryptedData += item.Value;
                            }
                        }
                    }
                    // decode and deserialize data if exists form9035 object
                    if (encryptedData != "")
                    {
                        // 9035 Object Decryption
                        decodeData = SecureData.AesDecryptString(appKeys.SecretKey, encryptedData);
                        if (decodeData != "")
                        {
                            data = CompressString.Unzip(decodeData);
                            form = JsonConvert.DeserializeObject <Form9035>(data);
                            Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message :  Form9035 Data has been decrypted successfully.");
                        }
                    }
                    // List Object Data Decryption
                    if (!string.IsNullOrEmpty(ListencryptedData))
                    {
                        decodeData = SecureData.AesDecryptString(appKeys.SecretKey, ListencryptedData);
                        if (decodeData != "")
                        {
                            data     = CompressString.Unzip(decodeData);
                            allLists = JsonConvert.DeserializeObject <Lists>(data);
                            Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message :  Lists Data has been decrypted successfully.");
                        }
                    }
                    // if data not exist check from SQL
                    if (assetModel.value.Count <= 0)
                    {
                        //string query = @"select * from BAL9035";
                        // string query = @"select * from BAL9035 where BALNumber='20000.50054.51'";
                        string query = @"select c.CompanyName, c.CompanyNumber, c.IsH1BDependent as 'Company H-1B Dependent', ce.EntityName as 'Sponsoring Entity', ce.IsH1BDependent as 'Entity H-1B Dependent',
                                        b.MatterNumber, b.FullName as 'Beneficiary', b.JobPosition as 'Beneficiary Job Title',
                                        cc.BALNumber, cst.CaseSubType, --max of 6
                                        lca.SocCode, lca.SocOccupation, lca.BeginOfValidity, lca.EndOfValidity, lca.WageRangeLow, lca.WageRangeHigh, lca.WageLevel, lca.NumberOfPositions,
                                        bt1.StaffFirstName as 'Attorney First Name', bt1.StaffMiddleName as 'Attorney Middle Name', bt1.StaffLastName as 'Attorney Last Name', bt1.StaffEmail as 'Attorney Email',
                                        bt2.StaffFirstName as 'Assistant First Name', bt2.StaffMiddleName as 'Assistant Middle Name', bt2.StaffLastName as 'Assistant Last Name', bt2.StaffEmail as 'Assistant Email',
                                        bt3.ContactFirstName as 'Signer First Name', bt3.ContactMiddleName as 'Signer Middle Name', bt3.ContactLastName as 'Signer Last Name', bt3.JobTitle as 'Signer Job',
                                        ca.AddressLine1, ca.AddressLine2, ca.Suite, ca.City, ca.State, ca.ZipCode, l.PrevailingWage, l.PrevailingWageSource, l.PrevailingWagePublishedYear, l.PrevailingWageOther,
                                        p.BALNumber as 'Parent Case Number', ps.CaseSubType as 'ParentCaseSubType'
                                        from ClientCase cc
                                        inner join Beneficiary b on b.beneid = cc.BeneId
                                        inner join Company c on c.CompanyId = b.CompanyId
                                        inner join LCADetail lca on lca.CaseId = cc.CaseId
                                        left join CompanyEntity ce on ce.CompanyEntityId = cc.SponsorEntityId
                                        inner join casecontacts cc1 (nolock) on cc.caseid = cc1.caseid and cc1.casecontacttype = 'BAL_MANAGER' and cc1.isprimary = 1
                                        inner join balteam bt1 (nolock) on cc1.userid = bt1.userid
                                        inner join casecontacts cc2 (nolock) on cc.caseid = cc2.caseid and cc2.casecontacttype = 'BAL_ASSISTANT' and cc2.isprimary = 1
                                        inner join balteam bt2 (nolock) on cc2.userid = bt2.userid
                                        left join casecontacts cc3 (nolock) on cc.caseid = cc3.caseid and cc3.casecontacttype = 'SIGNER'
                                        left join CompanyContacts bt3 (nolock) on cc3.userid = bt3.userid
                                        --inner join CaseAddress a on a.CaseId = cc.CaseId
                                        left join CaseCompanyAddressLink l on l.CaseId = cc.CaseId
                                        left join CompanyAddress ca on ca.CompanyAddressId = l.CompanyAddressId
                                        inner join CaseSubTypeRel r on r.CaseId = cc.CaseId
                                        inner join CaseSubTypes cst on cst.MetaDataId = r.MetaDataId
                                        left join ClientCase p on cc.ParentCaseId = p.CaseId
                                        left join CaseSubTypeRel pr on pr.CaseId = p.CaseId
                                        left join CaseSubTypes ps on ps.MetaDataId = pr.MetaDataId
                                        where CC.BALNumber = '" + bal_no + "' order by cc.BALNumber";
                        //20000.55.52,20000.50054.51
                        // Calling db object and sending the query and returning the DataTable
                        Database  db = new Database();
                        DataTable dt = db.SqlSelect(query);
                        // If Results found map data else send Error message
                        if (dt.Rows.Count > 0)
                        {
                            // Mapping DataTable to the 9035 and Lists object
                            MapDbData dbData = new MapDbData();
                            form     = dbData.MapdbResult(dt);
                            allLists = dbData.CreateLists(dt, bal_no);
                            dbData.AssignValue(form, allLists.parentCaseSubTypes);
                            Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message :  Data from SQL Query has been generated successfully.");
                        }
                        else
                        {
                            Log.Info("Bal Number : " + bal_no + ": Process : Draft9035 -  No Data Found from the SQL Query.");
                            TempData["Error"] = "You have entered an invalid case matter number. Please submit a new request with the correct matter number";
                            es.AddErrorESLog(ViewBag.id_no, "Business", "No Data Found from the SQL Query.", out errorMessage);
                            api.AddErrorQueueItem(ViewBag.id_no, TempData["Error"].ToString(), "Business", TempData["Error"].ToString(), "Failed", bal_no);
                            return(RedirectToAction("Error"));
                        }
                    }
                    // Second Asset check n if it is submit case (NOT IN USE)
                    //ViewBag.isSubmit = false;
                    //filter = "?$filter=Name eq '" + ViewBag.id_no + "'";
                    //AssetModel idModel = api.GetAsset(token, filter);
                    //if (idModel.value.Count > 0 && assetModel.value.Count > 0)
                    //{
                    //    foreach (var item in idModel.value)
                    //    {
                    //        if (item.Name == ViewBag.id_no)
                    //        {
                    //            ViewBag.isSubmit = true;
                    //        }
                    //    }
                    //}
                    //form.isSubmit = false;
                    obj.Form9035 = form;
                    obj.Lists    = allLists;
                    Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message : Process has been executued successfully returning an object to View.");
                    return(View(obj));
                }
                else
                {
                    throw new Exception("HTTP Web Request Failed. The data in the URL is not found.");
                }
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly";
                Log.Error(ex, bal_no);
                es.AddErrorESLog(ViewBag.id_no, "Technical", ex.Message, out errorMessage);
                api.AddErrorQueueItem(ViewBag.id_no, ex.Message, "Technical", ex.Message, "In Progress", bal_no);
                return(RedirectToAction("Error"));
            }
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            GetAppSettings settings = new GetAppSettings();

            Console.WriteLine(settings.GetSetting("Test"));

            Spelling spelling = new Spelling();
            string   word     = "";

            word = "PORK";
            Console.WriteLine("{0} => {1}", word, spelling.Correct(word));

            word = "FUU"; // 'correcter' is not in the dictionary file so this doesn't work
            Console.WriteLine("{0} => {1}", word, spelling.Correct(word));

            word = "LAMM";
            Console.WriteLine("{0} => {1}", word, spelling.Correct(word));

            word = "PAINT";
            Console.WriteLine("{0} => {1}", word, spelling.Correct(word));

            word = "ETAE";
            Console.WriteLine("{0} => {1}", word, spelling.Correct(word));

            // A sentence
            string sentence   = "I havve speled thes woord wwrong"; // sees speed instead of spelled (see notes on norvig.com)
            string correction = "";

            foreach (string item in sentence.Split(' '))
            {
                correction += " " + spelling.Correct(item);
            }
            Console.WriteLine("Did you mean:" + correction);

            Enumerable.Range(Convert.ToInt32('A'), 26).Union(Enumerable.Range(Convert.ToInt32('0'), 10)).ToList().
            ForEach(e => Console.WriteLine(Convert.ToChar(e)));

            Console.WriteLine($"{DuoVia.FuzzyStrings.StringExtensions.FuzzyMatch("HONG", "HONG")}");
            Console.WriteLine($"{DuoVia.FuzzyStrings.StringExtensions.FuzzyMatch("HOONG", "HONG")}");
            Console.WriteLine($"{DuoVia.FuzzyStrings.StringExtensions.FuzzyMatch("HOONG", "HSOUNG")}");
            Console.WriteLine($"{DuoVia.FuzzyStrings.StringExtensions.FuzzyMatch("HOONG", "HSIN")}");
            Console.WriteLine($"{DuoVia.FuzzyStrings.StringExtensions.FuzzyMatch("Hello Wor1ld3", "Hello Warl12d3")}");



            Console.WriteLine($"{FuzzyString.ComparisonMetrics.JaccardDistance("Hello World", "Hello World")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.JaccardDistance("Hello World", "Hello Warld")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.JaccardDistance("Hello World", "Hello Warl12d3")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.JaccardDistance("Hello Wor1ld3", "Hello Warl12d3")}");

            Console.WriteLine($"{FuzzyString.ComparisonMetrics.HammingDistance("Hello World", "Hello World")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.HammingDistance("Hello World", "Hello Warld")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.HammingDistance("Hello World", "Hello Warl12d3")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.HammingDistance("Hello Wor1ld3", "Hello Warl12d3")}");

            Console.WriteLine($"{FuzzyString.ComparisonMetrics.SorensenDiceDistance("Hello World", "Hello World")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.SorensenDiceDistance("Hello World", "Hello Warld")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.SorensenDiceDistance("Hello World", "Hello Warl12d3")}");
            Console.WriteLine($"{FuzzyString.ComparisonMetrics.SorensenDiceDistance("Hello Wor1ld3", "Hello Warl12d3")}");

            Console.WriteLine("Hello World".DiceCoefficient("Hello World"));
            Console.WriteLine("Hello World".DiceCoefficient("Hello Warld"));
            Console.WriteLine("Hello World".DiceCoefficient("Heo Warl12d3"));
            Console.WriteLine("Hello World".DiceCoefficient("Hello Warl12d3"));

            StringTrie <string> Trie = new StringTrie <string>();

            Trie.Add("ABC", "ABC");
            Trie.Add("ABCDEF", "ABCDEF");
            Trie.Add("FGHIJK", "FGHIJK");
            Trie.Add("KKK", "KKK");
            Trie.Add("LLLLL", "LLLLL");
            Trie.Add("LLLLLT", "LLLLLT");
            Trie.Add("Tai Po", "Tai Po");
            Trie.Add("Tai Po ABC", "Tai Po ABC");
            Trie.Add("Tai Po ABC DEF", "Tai Po ABC DEF");
            Trie.Add("Tai Po XXX", "Tai Po XXX");
            Trie.Add("Tai Po YYY", "Tai Po YYY");

            TraverseTrie(Trie,
                         n =>
            {
                Console.WriteLine($"Node: {n.Value}");
            },
                         lf =>
            {
                Console.WriteLine($"Leaf: *****");
            });


            var node = Trie.Find("Tai Po A");

            Console.WriteLine(node.IsLeaf + " " + node.HasValue);
            Console.WriteLine("*************************");
            node.Descendants.ToList().ForEach(e =>
            {
                if (e.HasValue)
                {
                    Console.WriteLine(e.Value);
                }
            });
            Console.WriteLine("*************************");
            node = Trie.Find("Tai Po AB");
            Console.WriteLine(node.IsLeaf + " " + node.HasValue);
            node = Trie.Find("Tai Po ABC");
            Console.WriteLine(node.IsLeaf + " " + node.HasValue);


            List <string> l = new List <string>();

            l.Add("");
            l.Add(null);
            l.Add("Hello World");
            foreach (var ll in l)
            {
                if (string.IsNullOrEmpty(ll))
                {
                    continue;
                }
                Console.WriteLine(ll);
            }

            var s = "([([}) []  A [] []   Test  ]]]]]   ";

            Console.WriteLine(s.Replace('(', Convert.ToChar(32)).Replace(')', Convert.ToChar(32)).Replace('[', Convert.ToChar(32)));



            /*
             * FileStream fs = new FileStream(@"C:\Temp\TestAddr.csv", FileMode.Open, FileAccess.Read);
             * var reader = new CsvReader(new StreamReader(fs));
             * reader.ReadHeader();
             * int i = 0;
             * while (reader.Read())
             * {
             *  var addr = reader.GetRecord<Addr>();
             *  Console.WriteLine(addr);
             *  if (i++ >= 10)
             *      break;
             * }
             * var p = System.IO.Path.GetTempPath();
             */

            var r = "A".CompareTo("B");

            var cm = new CodeMappings();


            HashSet <int> hs = new HashSet <int>();

            hs.Add(1);
            hs.Add(2);
            hs.Add(1);
            hs.Add(2);
            hs.Add(3);

            foreach (var x in hs)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("First Result Set ******************************************************************************");
            var res1 = LCSFinder.GetLCS("A B C D E F G H", "A B C D U V Y K");
            var res2 = LCSFinder.GetLCS("A B C D E F G H", "A I B T C O D L");

            Console.WriteLine(res1);
            Console.WriteLine(res2);

            Console.WriteLine("Second Result Set ******************************************************************************");
            var res3 = LCSFinder.GetLCS("AA BB CC DDD EE FFFF GG H", "AA XXXX BDB YYYYYY CC DD123DD U EE V Y K");
            var res4 = LCSFinder.GetLCS("AA BB CC DDD EE FFFF GG H", "AA I BB T CC OXXXXX DDD L EE");

            Console.WriteLine(res3);
            Console.WriteLine(res4);

            Console.WriteLine("Third Result Set ******************************************************************************");
            var res5 = LCSFinder.GetLCS("AA BB CC DD E F G", "AA BB CC BB II CC KK DD H I K");
            var res6 = LCSFinder.GetLCS("AA BB CC DD E F G", "AA BB CCCC DD II E A F B G");

            Console.WriteLine(res5);
            Console.WriteLine(res6);
            Console.WriteLine("******************************************************************************");

            Console.WriteLine("First Result Set ******************************************************************************");
            var resX = "A B C D E F G H".LongestCommonSubsequence("A B C D U V Y K");
            var resY = "A B C D E F G H".LongestCommonSubsequence("A I B T C O D L");

            Console.WriteLine(resX);
            Console.WriteLine(resY);

            Console.WriteLine("Second Result Set ******************************************************************************");
            var resA = "AA BB CC DDD EE FFFF GG H".LongestCommonSubsequence("AA XXXX BDB YYYYYY CC DD123DD U EE V Y K");
            var resB = "AA BB CC DDD EE FFFF GG H".LongestCommonSubsequence("AA I BB T CC OXXXXX DDD L EE");

            Console.WriteLine(resA);
            Console.WriteLine(resB);

            Console.WriteLine("Third Result Set ******************************************************************************");
            var resC = "AA BB CC DD E F G".LongestCommonSubsequence("AA BB CC BB II CC KK DD H I K");
            var resD = "AA BB CC DD E F G".LongestCommonSubsequence("AA BB CCCC DD II E A F B G");

            Console.WriteLine(resC);
            Console.WriteLine(resD);
            Console.WriteLine("******************************************************************************");


            Console.WriteLine("1 Result Set ******************************************************************************");
            var r1 = "ABCDEFGH".LongestCommonSubsequence("ABCDUVYK");
            var r2 = "ABCDEFGH".LongestCommonSubsequence("AIBTCODL");

            Console.WriteLine(r1);
            Console.WriteLine(r2);

            Console.WriteLine("2 Result Set ******************************************************************************");
            var r3 = "AABBCCDDDEEFFFFGGH".LongestCommonSubsequence("AAXXXXBDBYYYYYYCCDD123DDUEEVYK");
            var r4 = "AABBCCDDDEEFFFFGGH".LongestCommonSubsequence("AAIBBTCCOXXXXXDDDLEE");

            Console.WriteLine(r3);
            Console.WriteLine(r4);

            Console.WriteLine("3 Result Set ******************************************************************************");
            var r5 = "AABBCCDDEFG".LongestCommonSubsequence("AABBCCBBIICCKKDDHIK");
            var r6 = "AABBCCDDEFG".LongestCommonSubsequence("AABBCCCCDDIIEAFBG");

            Console.WriteLine(r5);
            Console.WriteLine(r6);
            Console.WriteLine("******************************************************************************");

            Console.WriteLine("4 Result Set ******************************************************************************");
            var r7 = "SUN FUNG WAI".LongestCommonSubsequence("SAN FUNG WAI");
            var r8 = "SUN FUNG WAI".LongestCommonSubsequence("SAN WAI COURT");

            Console.WriteLine(r7);
            Console.WriteLine(r8);
            Console.WriteLine("******************************************************************************");


            Enumerable.Range(1, 20).ToList().ForEach(e =>
            {
                var rA = ToRoman(e);
                var sA = ConvertRomanToNumber(rA);
                Console.WriteLine($"{rA}->{sA}");
            });

            MainStore ms = new MainStore();

            ms.Serialize(@"C:\Temp\tt.json");



            List <StreetNoExpansion> stl = new List <StreetNoExpansion>()
            {
                new StreetNoExpansion(13, "A", 13, "A"),    //0
                new StreetNoExpansion(13, "L", 14, "L"),    //1
                new StreetNoExpansion(13, "L", 17, "L"),    //2
                new StreetNoExpansion(13, "L", 20, "L"),    //3
                new StreetNoExpansion(13, "L", 14, "M"),    //4
                new StreetNoExpansion(12, "", 12, ""),      //5
                new StreetNoExpansion(12, "A", 12, "A"),    //6
                new StreetNoExpansion(12, "", 19, ""),      //7
                new StreetNoExpansion(12, "", 20, ""),      //8
                new StreetNoExpansion(12, "", 12, ""),      //9
                new StreetNoExpansion(12, "", 13, ""),      //10
                new StreetNoExpansion(12, "A", 12, "B"),    //11
                new StreetNoExpansion(14, "D", 21, "S"),    //12
                new StreetNoExpansion(15, "A", 17, ""),     //13
                new StreetNoExpansion(15, "A", 29, ""),     //14
                new StreetNoExpansion(15, "B", 16, ""),     //15
                new StreetNoExpansion(15, "C", 15, ""),     //16
                new StreetNoExpansion(16, "", 17, "B"),     //17
                new StreetNoExpansion(16, "", 18, "B"),     //18
                new StreetNoExpansion(16, "", 16, "B"),     //19
                new StreetNoExpansion(16, "", 20, "D"),     //20
                new StreetNoExpansion(16, "A", 17, ""),     //21
                new StreetNoExpansion(16, "B", 18, ""),     //22
                new StreetNoExpansion(16, "C", 16, ""),     //23
                new StreetNoExpansion(16, "D", 20, ""),     //24
                new StreetNoExpansion(3, "EA3", 3, "EA3"),  //25
                new StreetNoExpansion(3, "A", 0, ""),       //26
                new StreetNoExpansion(3, "", 0, ""),        //27
            };

            stl.ForEach(e => Console.WriteLine(e));
            var line = "";

            while (!string.IsNullOrEmpty(line = Console.ReadLine()))
            {
                Console.Write(">");
                if (!ConvertStreetNoFromStringToComponents(line, out int from, out string fromA, out int to, out string toA))
                {
                    Console.WriteLine("Conversion Failed");
                    continue;
                }
                int idx = 0;
                stl.ForEach(e =>
                {
                    Console.WriteLine($"{idx++}->{e.MatchStreetNo(from, fromA, to, toA)}");
                });
            }
        }
        // POST: api/AddCredentials
        // Create the Credential Asset on UIPATH Orchestrator
        public IHttpActionResult Post([FromBody] CredentialAsset bodyModel)
        {
            string          assetResponse = "";
            Response        outResponse   = new Response();
            OrchestratorAPI api           = new OrchestratorAPI();
            ElasticSearch   es            = new ElasticSearch();
            string          logMsg        = "";
            string          errorMessage  = "";

            try
            {
                // Check if the Input Parameters has all the values or not
                if (string.IsNullOrEmpty(bodyModel.Username) && string.IsNullOrEmpty(bodyModel.Password) && string.IsNullOrEmpty(bodyModel.Name) && string.IsNullOrEmpty(bodyModel.Email))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    assetResponse       = JsonConvert.SerializeObject(outResponse);
                    logMsg = "Bal Number : " + bodyModel.Name + ", Proecess : Create Credential Asset, Message : Parameter : Username : "******"Password : "******" Name : " + bodyModel.Name + " Email : " + bodyModel.Email + " : Parameter is required.";
                    Log.Info(logMsg);
                    es.AddErrorESLog(bodyModel.Name, "Technical", "Credential Asset Parameter Missing", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Name, "Credential Asset Parameter Missing", "Technical", "Credential Asset Parameter Missing", "In Progress");
                    return(Json(assetResponse));
                }
                string filter = "";
                //  Get the Config from AppSettings
                AppSettingsValues appKeys = GetAppSettings.GetAppSettingsValues();
                // UIPATH TOKEN
                string token = api.Authentication(appKeys.isDevelopmentEnvironment);
                // Send error message if the token is null
                if (string.IsNullOrEmpty(token))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    logMsg = "Bal Number : " + bodyModel.Name + ", Proecess : Create Credential Asset, Message : You are not been able to authenticated. Token : " + token;
                    Log.Info(logMsg);
                    es.AddErrorESLog(bodyModel.Name, "Technical", "UIPATH Token not generated. Authentication Failed.", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Name, "UIPATH Token not generated. Authentication Failed.", "Technical", "UIPATH Token not generated. Authentication Failed.", "In Progress");
                }
                else
                {
                    // get n check if asset exist
                    filter = "?$filter=Name eq '" + bodyModel.Name + "'";
                    AssetModel assetModel = api.GetAsset(token, filter);
                    // create or update asset
                    Dictionary <string, object> assetBody = new Dictionary <string, object>();
                    assetBody.Add("Name", bodyModel.Name);
                    assetBody.Add("ValueScope", "Global");
                    assetBody.Add("ValueType", "Credential");
                    assetBody.Add("StringValue", "no idea");
                    assetBody.Add("CredentialUsername", bodyModel.Username);
                    assetBody.Add("CredentialPassword", bodyModel.Password);
                    assetResponse = api.CreateAsset(assetModel, token, assetBody);
                    // get n check if asset exist
                    assetModel = api.GetAsset(token, filter);
                    if (assetModel.value.Count > 0)
                    {
                        // Gets user old records and sets the new updated key against it
                        string esKeyID = "";
                        // gets the KeyID
                        string[] esResults   = es.GetESKey(bodyModel.Email, appKeys.LookupKey, out errorMessage);
                        string   initalKeyID = "";
                        if (esResults != null)
                        {
                            initalKeyID = esResults[1];
                        }
                        // Set the SecretKey against the KeyID
                        es.SetESKey(initalKeyID, bodyModel.Email, bodyModel.SecretKey, appKeys.LookupKey, out errorMessage, out esKeyID);

                        outResponse.success = true;
                        outResponse.message = esKeyID;
                        logMsg = "Bal Number : " + bodyModel.Name + " Process : Create Credential Asset, Message :  The method has been successfully exexuted.";
                        Log.Info(logMsg);
                    }
                    else
                    {
                        outResponse.success = false;
                        outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                        logMsg = "Bal Number : " + bodyModel.Name + " Process : Create Credential Asset, Message :  The asset has not been found";
                        Log.Info(logMsg);
                        es.AddErrorESLog(bodyModel.Name, "Technical", "The Credential Asset has not been created", out errorMessage);
                        api.AddErrorQueueItem(bodyModel.Name, "The Credential Asset has not been created", "Technical", "The Credential Asset has not been created", "In Progress");
                    }
                }
            }
            catch (Exception ex)
            {
                outResponse.success = false;
                outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                Log.Error(ex, bodyModel.Name);
                es.AddErrorESLog(bodyModel.Name, "Technical", ex.Message, out errorMessage);
                api.AddErrorQueueItem(bodyModel.Name, ex.Message, "Technical", ex.Message, "In Progress");
            }
            assetResponse = JsonConvert.SerializeObject(outResponse);
            return(Json(assetResponse));
        }
Exemplo n.º 10
0
        public IHttpActionResult CreateAsset([FromBody] PostSaveData bodyModel)
        {
            string          assetResponse = "";
            string          logMsg        = "";
            Response        outResponse   = new Response();
            OrchestratorAPI api           = new OrchestratorAPI();
            string          errorMessage  = "";

            try
            {
                // Validate the input parameters
                if (string.IsNullOrEmpty(bodyModel.JsonString) && string.IsNullOrEmpty(bodyModel.Sysid) && string.IsNullOrEmpty(bodyModel.BalNumber))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : JsonString  parameter required";
                    Log.Info(logMsg);
                    assetResponse = JsonConvert.SerializeObject(outResponse);
                    es.AddErrorESLog(bodyModel.Sysid, "Technical", "Data Asset Parameter Missing", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Sysid, "Data Asset Parameter Missing", "Technical", "Data Asset Parameter Missing", "In Progress");
                    return(Json(assetResponse));
                }
                string filter = "";
                // configuration getting from Appsetting
                AppSettingsValues appKeys = GetAppSettings.GetAppSettingsValues();
                // Saving all keys in a class object
                string token = api.Authentication(appKeys.isDevelopmentEnvironment);
                // check if token is generated or not
                if (string.IsNullOrEmpty(token))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : UIPATH Token has not been generated. Token : " + token;
                    Log.Info(logMsg);
                    es.AddErrorESLog(bodyModel.Sysid, "Technical", "UIPATH Token not generated. Authentication Failed.", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Sysid, "UIPATH Token not generated. Authentication Failed.", "Technical", "UIPATH Token not generated. Authentication Failed.", "In Progress");
                }
                else
                {
                    // GETS all the Assets against the BAL Number
                    string assetName = bodyModel.BalNumber;
                    filter = "?$filter=Name eq '" + bodyModel.BalNumber + "'";
                    AssetModel assetModel = api.GetAsset(token, filter);
                    // Removing List asset from the assetModel Object
                    if (assetModel.value.Count > 1)
                    {
                        foreach (var item in assetModel.value)
                        {
                            if (item.Name.Contains("Lists"))
                            {
                                assetModel.value.Remove(item);
                                break;
                            }
                        }
                    }
                    // create or update asset
                    Dictionary <string, object> assetBody = new Dictionary <string, object>();
                    assetBody.Add("Name", assetName);
                    assetBody.Add("ValueScope", "Global");
                    assetBody.Add("ValueType", "Text");
                    //Object to JSON
                    //string jsonString = JsonConvert.SerializeObject(bodyModel.JsonString);
                    //Compressing JSON
                    string compressValue = CompressString.Zip(bodyModel.JsonString);
                    //Encoding JSON
                    string encodeValue = SecureData.AesEncryptString(appKeys.SecretKey, compressValue);
                    int    chkStrLen   = encodeValue.Length;
                    // If length is greater than 4000 Create 2 Assets elsse 1
                    if (chkStrLen > 4000)
                    {
                        assetBody.Add("StringValue", encodeValue.Substring(0, 4000));
                        assetResponse = api.CreateAsset(assetModel, token, assetBody);
                        string secondAsset = encodeValue.Substring(4000);
                        // get n check if asset exist
                        string filter1 = "?$filter=Name eq '" + bodyModel.BalNumber + " A" + "'";
                        assetModel = api.GetAsset(token, filter1);
                        //second asset
                        Dictionary <string, object> asset2Body = new Dictionary <string, object>();
                        asset2Body.Add("ValueScope", "Global");
                        asset2Body.Add("ValueType", "Text");
                        asset2Body.Add("Name", bodyModel.BalNumber + " A");
                        asset2Body.Add("StringValue", secondAsset);
                        assetResponse = api.CreateAsset(assetModel, token, asset2Body);
                        logMsg        = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : 2 Assets has been created successfully";
                        Log.Info(logMsg);
                    }
                    else
                    {
                        // Delete the current existing assets first
                        if (assetModel.value.Count == 2)
                        {
                            string id          = assetModel.value[1].Id.ToString();
                            string deleteAsset = api.DeleteAsset(id, token);
                            logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Extra Asset has been deleted";
                            Log.Info(logMsg);
                        }
                        assetBody.Add("StringValue", encodeValue);
                        assetResponse = api.CreateAsset(assetModel, token, assetBody);
                        logMsg        = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Data asset has been created";
                        Log.Info(logMsg);
                    }
                    //Compressing JSON
                    compressValue = CompressString.Zip(bodyModel.ListJsonString);
                    //Encoding JSON
                    encodeValue = SecureData.AesEncryptString(appKeys.SecretKey, compressValue);
                    // getting lists assets
                    filter = "?$filter=Name eq '" + bodyModel.BalNumber + ".Lists'";
                    AssetModel ListAssetModel = api.GetAsset(token, filter);
                    // Adding or updating Lits Assets
                    Dictionary <string, object> assetListBody = new Dictionary <string, object>();
                    assetListBody.Add("Name", bodyModel.BalNumber + ".Lists");
                    assetListBody.Add("ValueScope", "Global");
                    assetListBody.Add("ValueType", "Text");
                    assetListBody.Add("StringValue", encodeValue);

                    assetResponse = api.CreateAsset(ListAssetModel, token, assetListBody);
                    // get n check if asset exist
                    logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : List Asset has been created";
                    Log.Info(logMsg);
                    assetModel = api.GetAsset(token, filter);
                    // In Case of submit sends the message
                    if (assetModel.value.Count > 0 && bodyModel.isSubmit == true)
                    {
                        logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Submit 9035 has been executed.";
                        outResponse.success = true;
                        outResponse.message = "Your 9035 will be drafted on the DOL ETA site and a copy will be uploaded to Cobalt.  You will receive a notification from ServiceNow when it is complete.  If you have any questions, contact #automationinfo.";
                    }
                    // in case of save Later
                    else if (assetModel.value.Count > 0 && bodyModel.isSubmit == false)
                    {
                        logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Save Later has been executed";
                        outResponse.success = true;
                        outResponse.message = @"Your progress has been saved.  To access your draft 9035 in the future, click on the ""Access My Draft 9035"" button in your ServiceNow ticket and you will be redirected to the form.";
                    }
                    // In case of any error
                    else
                    {
                        logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Some error occurred while returning an asset";
                        outResponse.success = false;
                        outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    }
                    Log.Info(logMsg);
                }
            }
            catch (Exception ex)
            {
                outResponse.success = false;
                outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                Log.Error(ex, bodyModel.BalNumber);
                es.AddErrorESLog(bodyModel.Sysid, "Technical", ex.Message, out errorMessage);
                api.AddErrorQueueItem(bodyModel.Sysid, ex.Message, "Technical", ex.Message, "In Progress");
            }
            assetResponse = JsonConvert.SerializeObject(outResponse);
            return(Json(assetResponse));
        }
Exemplo n.º 11
0
        public IHttpActionResult AddQueueItem([FromBody] PostSaveData bodyModel)
        {
            string          assetResponse = "";
            Response        outResponse   = new Response();
            OrchestratorAPI api           = new OrchestratorAPI();
            string          logMsg        = "";
            string          errorMessage  = "";

            try
            {
                if (string.IsNullOrEmpty(bodyModel.Sysid) && string.IsNullOrEmpty(bodyModel.BalNumber) && string.IsNullOrEmpty(bodyModel.Email))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    logMsg = "Bal Number : " + bodyModel.BalNumber + ", Process : Add Queue Item, Message : JsonString  parameter required";
                    Log.Info(logMsg);
                    assetResponse = JsonConvert.SerializeObject(outResponse);
                    es.AddErrorESLog(bodyModel.Sysid, "Technical", "QueueItem API Parameter Missing", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Sysid, "QueueItem API Parameter Missing", "Technical", "QueueItem API Parameter Missing", "In Progress");
                    return(Json(assetResponse));
                }
                string filter = "?$filter=Name eq '" + bodyModel.BalNumber + "'";
                // configuration
                AppSettingsValues appKeys = GetAppSettings.GetAppSettingsValues();
                string            token   = api.Authentication(appKeys.isDevelopmentEnvironment);

                AssetModel assetModel = api.GetAsset(token, filter);
                if (assetModel.value.Count > 0)
                {
                    SpecificContent content = new SpecificContent();
                    content.ID          = bodyModel.Sysid;
                    content.Err_Message = null;
                    content.Err_Type    = null;
                    content.Note        = null;
                    content.Status      = null;
                    content.Data        = "[{'CaseNo':'" + bodyModel.BalNumber + "','Email':'" + bodyModel.Email + "','EsIdNo':'" + bodyModel.EsIdNo + "', 'ExtraAsset':''}]";
                    if (assetModel.value.Count > 2)
                    {
                        content.Data = "[{'CaseNo':'" + bodyModel.BalNumber + "','Email':'" + bodyModel.Email + "','EsIdNo':'" + bodyModel.EsIdNo + "', 'ExtraAsset':'" + bodyModel.BalNumber + " A" + "'}]";
                    }

                    ItemData itemData = new ItemData();
                    itemData.Name            = appKeys.QueueName;
                    itemData.Priority        = "Normal";
                    itemData.SpecificContent = content;

                    RootObject queueItemBody = new RootObject();
                    queueItemBody.itemData = itemData;

                    string strQueue = JsonConvert.SerializeObject(queueItemBody);
                    string message  = api.AddQueueItem(token, strQueue);
                    outResponse.success = true;
                    outResponse.message = "Your 9035 will be drafted on FLAG and a copy will be updated to Cobalt. You will receive a notification from ServiceNow when it is complete. if you have any questions, contact #automationinfo";
                    logMsg = "Bal Number : " + bodyModel.BalNumber + ", Process : Add Queue Item, Message : Queueitem has been added.";
                    Log.Info(logMsg);
                }
            }
            catch (Exception ex)
            {
                outResponse.success = false;
                outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                Log.Error(ex, bodyModel.BalNumber);
                es.AddErrorESLog(bodyModel.Sysid, "Technical", ex.Message, out errorMessage);
                api.AddErrorQueueItem(bodyModel.Sysid, ex.Message, "Technical", ex.Message, "In Progress");
            }
            assetResponse = JsonConvert.SerializeObject(outResponse);
            return(Json(assetResponse));
        }
Exemplo n.º 12
0
 public ApiResult<AppConfig> GetAppSettings()
 {
     var cmd = new GetAppSettings(appConfigProvider);
     cmd.Execute();
     return cmd.Result;
 }