//[ExpectedException(typeof(DirectoryNotFoundException))]
        public void NotExistingAttachmentTest()
        {
            string notExistingPath = "C:/asfpfs/safsaklfa/";

            ListStructure attachments = new ListStructure(new List <Structure>()
            {
                new TextStructure(notExistingPath)
            });

            if (File.Exists(notExistingPath))
            {
                Assert.Inconclusive($"File on path [{notExistingPath}] exists, very unlikely");
            }

            Scripter scripter = new Scripter();

            scripter.InitVariables.Clear();
            scripter.InitVariables.Add("att", attachments);
            scripter.Text = $"mail.smtp login {SpecialChars.Variable}credential{SpecialChars.IndexBegin}Net:email{SpecialChars.IndexEnd} password {SpecialChars.Variable}credential{SpecialChars.IndexBegin}Net:pass{SpecialChars.IndexEnd} " +
                            $"from {SpecialChars.Variable}credential{SpecialChars.IndexBegin}Net:email{SpecialChars.IndexEnd} to {SpecialChars.Variable}credential{SpecialChars.IndexBegin}Net:email{SpecialChars.IndexEnd} attachments {SpecialChars.Variable}att";


            Exception exception = Assert.Throws <ApplicationException>(delegate
            {
                scripter.Run();
            });

            Assert.IsInstanceOf <DirectoryNotFoundException>(exception.GetBaseException());
        }
        private void AddRequestFiles(RestRequest request, ListStructure files, TextStructure bodyFile)
        {
            var allFiles = new List <PostFileModel>();

            if (bodyFile?.Value != null)
            {
                allFiles.Add(new PostFileModel(ParameterType.RequestBody.ToString(), bodyFile.Value.ToString(), null));
            }
            if (files != null)
            {
                allFiles.AddRange(files.Value.Select(v => new PostFileModel(v.ToString())));
            }

            foreach (var file in allFiles)
            {
                if (file.FormFieldName == ParameterType.RequestBody.ToString())
                {
                    AddBodyFileName(request, file);
                }
                else
                {
                    request.AddFile(file.FormFieldName, file.FilePath, file.ContentType);
                }
            }
        }
        public void Execute(Arguments arguments)
        {
            var           sheetsManager = SheetsManager.CurrentSheet;
            var           sheetName     = arguments.SheetName.Value == "" ? sheetsManager.sheets[0].Properties.Title : arguments.SheetName.Value;
            var           val           = sheetsManager.GetValue(arguments.Range.Value, sheetName);
            ListStructure result        = new ListStructure(new System.Collections.Generic.List <object>());

            //string result=null;
            //var result = val. == null ? "" : val.Values[0][0].ToString();
            if (val.ValueRanges[0].Values == null)
            {
                for (int i = 0; i < val.ValueRanges.Count; i++)
                {
                    TextStructure tmp = new TextStructure("");
                    result.Value.Add(tmp);
                }
                Scripter.Variables.SetVariableValue(arguments.Result.Value, result);
            }
            else
            {
                for (int i = 0; i < val.ValueRanges.Count; i++)
                {
                    // TextStructure tmp = new TextStructure(val.ValueRanges[i].Values[0][0].ToString());
                    result.Value.Add(val.ValueRanges[i].Values[0][0].ToString());
                }
                Scripter.Variables.SetVariableValue(arguments.Result.Value, result);
            }
        }
        private ListStructure CreateMessageStructuresFromMessages(IMailFolder folder, List <IMessageSummary> messages)
        {
            var messageList = new ListStructure();

            foreach (var message in messages)
            {
                var messageWithFolder = new SimplifiedMessageSummary(message as MessageSummary, folder);
                var structure         = new MailStructure(messageWithFolder, null, null);
                messageList.AddItem(structure);
            }
            return(messageList);
        }
        public void SendEmailTest()
        {
            Scripter scripter         = new Scripter();
            int      startingQuantity = GetUnreadEmails((string)scripter.Variables.GetVariable("credential").GetValue("Net:email").Object, (string)scripter.Variables.GetVariable("credential").GetValue("Net:pass").Object).Count;
            string   subject          = GetEmailName();

            StringBuilder pathBuilder   = new StringBuilder("testfile");
            string        fileExtension = "txt";

            while (File.Exists($"{pathBuilder}.{fileExtension}"))
            {
                pathBuilder.Append('a');
            }
            pathBuilder.Append($".{fileExtension}");
            string path = pathBuilder.ToString();

            File.Create(path).Close();

            ListStructure attachments = new ListStructure(new List <Structure>()
            {
                new TextStructure(pathBuilder.ToString())
            });


            scripter.InitVariables.Clear();
            scripter.InitVariables.Add("att", attachments);
            scripter.Text = $"mail.smtp login {SpecialChars.Variable}credential{SpecialChars.IndexBegin}Net:email{SpecialChars.IndexEnd} password {SpecialChars.Variable}credential{SpecialChars.IndexBegin}Net:pass{SpecialChars.IndexEnd} " +
                            $"from {SpecialChars.Variable}credential{SpecialChars.IndexBegin}Net:email{SpecialChars.IndexEnd} to {SpecialChars.Variable}credential{SpecialChars.IndexBegin}Net:email{SpecialChars.IndexEnd} subject {textChar}{subject}{textChar} " +
                            $"attachments {SpecialChars.Variable}att";
            scripter.Run();

            Thread.Sleep(OneSecond * 3);

            var emails = GetUnreadEmails((string)scripter.Variables.GetVariable("credential").GetValue("Net:email").Object, (string)scripter.Variables.GetVariable("credential").GetValue("Net:pass").Object);

            bool found = false;

            for (int i = 0; i < emails.Count && !found; i++)
            {
                if (emails[i] == subject)
                {
                    found = true;
                }
            }

            Assert.IsTrue(found);
            // Assert.AreEqual(startingQuantity + 1, emails.Count); // gets always first 20 unreaded, so quantity will be 21 but emails.count always max 20

            //if (File.Exists(path))
            //{
            //    File.Delete(path);
            //}
        }
Beispiel #6
0
        private ListStructure CreateAttachmentStructuresFromAttachments(IMessageSummary message, IMailFolder folder,
                                                                        IEnumerable <BodyPartBasic> attachments)
        {
            ListStructure attachmentsList = new ListStructure();

            foreach (var attachment in attachments)
            {
                AttachmentModel     attachmentModel = new AttachmentModel(attachment, folder, message);
                AttachmentStructure temp            = new AttachmentStructure(attachmentModel);
                attachmentsList.AddItem(temp);
            }
            return(attachmentsList);
        }
        public void Execute(Arguments arguments)
        {
            ListStructure result       = new ListStructure(null, "", Scripter);
            var           searchResult = XlsxManager.CurrentXlsx.Find(arguments.Value.Value, arguments.InSelection.Value);

            if (searchResult != null)
            {
                var list = searchResult.
                           Select(x => new PointStructure(new Point(x.ColumnNumber, x.RowNumber))).ToList <object>();
                result = new ListStructure(list, "", Scripter);
            }
            Scripter.Variables.SetVariableValue(arguments.Result.Value, result);
        }
Beispiel #8
0
        public void Execute(Arguments arguments)
        {
            manager = AbbyyManager.Instance;
            int           docID = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            var           doc   = manager.GetDocument(docID);
            List <string> table = doc.Tables[arguments.TableIndex.Value].ReturnWordPosition(arguments.Search.Value);
            ListStructure cells = new ListStructure(new List <Structure>());

            foreach (String t in table)
            {
                cells.Value.Add(new TextStructure(t));
            }
            Scripter.Variables.SetVariableValue(arguments.Result.Value, cells);
        }
        public void Execute(Arguments arguments)
        {
            manager = AbbyyManager.Instance;
            int docID = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            var doc   = manager.GetDocument(docID);

            List <Rectangle> rectangles = doc.FindPosition(arguments.Search.Value);

            ListStructure matchesRectangles = new ListStructure(new List <Structure>());

            foreach (Rectangle r in rectangles)
            {
                matchesRectangles.Value.Add(new RectangleStructure(r));
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, matchesRectangles);
        }
 public void Execute(Arguments arguments)
 {
     try
     {
         ListStructure result  = new ListStructure(new System.Collections.Generic.List <object>());
         List <String> regions = AmazonS3Helper.GetRegionsList();
         foreach (string region in regions)
         {
             result.Value.Add(region);
         }
         Scripter.Variables.SetVariableValue(arguments.Result.Value, result);
     }
     catch (Exception exc)
     {
         throw new ApplicationException(exc.Message);
     }
 }
        public void SendDataWithHeadersTest()
        {
            string        url        = "https://httpbin.org/put";
            string        url2       = "https://httpbin.org/get";
            ListStructure parameters = new ListStructure(new List <object>()
            {
                "something:val"
            });

            ListStructure headers1 = new ListStructure(new List <object>()
            {
                "encoding-language:foo",
                "version:3.0"
            });
            ListStructure headers2 = new ListStructure(new List <object>()
            {
                "type1:xml"
            });

            Scripter scripter = new Scripter();

            scripter.InitVariables.Clear();
            scripter.InitVariables.Add("params", parameters);
            scripter.InitVariables.Add("url", new TextStructure(url));
            scripter.InitVariables.Add("method", new TextStructure("put"));
            scripter.InitVariables.Add("headers", headers1);
            scripter.InitVariables.Add("url2", new Language.TextStructure(url2));
            scripter.InitVariables.Add("method2", new Language.TextStructure("get"));
            scripter.InitVariables.Add("headers2", headers2);

            scripter.Text = ($@"rest method {SpecialChars.Variable}method url {SpecialChars.Variable}url headers {SpecialChars.Variable}headers parameters {SpecialChars.Variable}params timeout {TestTimeout} result {SpecialChars.Variable}result1
                                json {SpecialChars.Variable}result jpath ['headers']['Encoding-Language'] result {SpecialChars.Variable}json1
                                json {SpecialChars.Variable}result jpath ['headers']['Version'] result {SpecialChars.Variable}json2
                                rest method {SpecialChars.Variable}method2 url {SpecialChars.Variable}url2 headers {SpecialChars.Variable}headers2 parameters {SpecialChars.Variable}params result {SpecialChars.Variable}result12
                                json {SpecialChars.Variable}result jpath ['headers']['Type1'] result {SpecialChars.Variable}ress");
            scripter.Run();

            Assert.AreEqual("xml", scripter.Variables.GetVariableValue <string>("ress"));

            string resultJson = scripter.Variables.GetVariableValue <string>("result1");

            resultJson = scripter.Variables.GetVariableValue <string>("result12");
            Assert.AreEqual("3.0", scripter.Variables.GetVariableValue <string>("json2"));
            Assert.AreEqual("foo", scripter.Variables.GetVariableValue <string>("json1"));
        }
Beispiel #12
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager       manager  = AbbyyManager.Instance;
            int                docID    = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            FineReaderDocument document = manager.GetDocument(docID);

            document.ExtractData();
            List <FineReaderParagraph> paragraphs = document.Paragraphs;

            ListStructure paragraphsList = new ListStructure(new List <Structure>());

            foreach (FineReaderParagraph p in paragraphs)
            {
                paragraphsList.Value.Add(new TextStructure(p.Text));
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, paragraphsList);
        }
        public void Execute(Arguments arguments)
        {
            ListStructure cmdresult = new ListStructure();

            try
            {
                if (arguments.directory.Value == null)
                {
                    arguments.directory.Value = String.Empty;
                }
                ftpRequest             = (FtpWebRequest)FtpWebRequest.Create("ftp://" + FtpSettings.GetInstance().Host + "/" + arguments.directory.Value);
                ftpRequest.Credentials = new NetworkCredential(FtpSettings.GetInstance().User, FtpSettings.GetInstance().Password);
                ftpRequest.UseBinary   = FtpSettings.GetInstance().UseBinary;
                ftpRequest.UsePassive  = FtpSettings.GetInstance().UsePassive;
                ftpRequest.KeepAlive   = FtpSettings.GetInstance().KeepAlive;

                ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                ftpResponse       = (FtpWebResponse)ftpRequest.GetResponse();
                ftpStream         = ftpResponse.GetResponseStream();
                StreamReader ftpReader    = new StreamReader(ftpStream);
                string       directoryRaw = ftpReader.ReadToEnd();

                ftpReader.Close();
                ftpStream.Close();
                ftpResponse.Close();
                ftpRequest = null;

                string[] list = directoryRaw.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (String line in list)
                {
                    string[] items = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    string   fn    = items.Last();
                    bool     isDir = items[0].StartsWith("d", StringComparison.InvariantCultureIgnoreCase);
                    String   s     = new FtpListingItem(fn, isDir).ToString();
                    cmdresult.Value.Add(new TextStructure(s));
                }
                Scripter.Variables.SetVariableValue(arguments.Result.Value, new ListStructure(cmdresult));
            }
            catch (Exception exc)
            {
                throw new ApplicationException($"Error occured while list directory", exc);
            }
            return;
        }
        private void AddRequestData(RestRequest request, ListStructure list, bool toHeader)
        {
            if (list != null)
            {
                foreach (var listData in list.Value)
                {
                    string data          = listData.ToString();
                    var    separatedData = data.Split(KeyValueSeparator);
                    if (separatedData.Length != 2)
                    {
                        throw new FormatException($"Missing separator in [{data}], use [{KeyValueSeparator}] instead");
                    }
                    var name  = separatedData[0];
                    var value = separatedData[1];

                    request.AddParameter(name, value, GetParameterType(toHeader, name));
                }
            }
        }
Beispiel #15
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager manager = AbbyyManager.Instance;

            int docID = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;

            FineReaderDocument document = manager.GetDocument(docID);

            document.ExtractData();

            ListStructure cellsText = new ListStructure(new List <Structure>());

            foreach (FineReaderCell c in document.Cells)
            {
                cellsText.Value.Add(new TextStructure(c.Text));
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, cellsText);
        }
 public void Execute(Arguments arguments)
 {
     try
     {
         List <String> keys   = S3Settings.GetInstance().awsS3.ListingObjects(arguments.bucketName.Value);
         ListStructure result = new ListStructure(new List <object>());
         if (keys != null)
         {
             foreach (string key in keys)
             {
                 result.AddItem(new TextStructure(key));
             }
         }
         //String flatStr = string.Join(";", keys.ToArray());
         Scripter.Variables.SetVariableValue(arguments.Result.Value, result);
     }
     catch (Exception exc)
     {
         throw new ApplicationException(exc.Message);
     }
 }
        public void CorrectHeaderSeparatorTest()
        {
            string url = "http://jsonplaceholder.typicode.com/posts/1";

            ListStructure headers = new ListStructure(new List <Structure>()
            {
                new TextStructure("content-type:json")
            });

            Scripter scripter = new Scripter();

            scripter.InitVariables.Clear();
            scripter.InitVariables.Add("method", new TextStructure("put"));
            scripter.InitVariables.Add("url", new TextStructure(url));
            scripter.InitVariables.Add("headers", headers);

            scripter.Text = ($"rest method {SpecialChars.Variable}method url {SpecialChars.Variable}url headers {SpecialChars.Variable}headers");
            scripter.Run();

            Assert.IsTrue(scripter.Variables.GetVariableValue <string>("result").Length > 0);
            Assert.AreEqual("Completed", scripter.Variables.GetVariableValue <string>("status"));
        }
        public void SendDataTest()
        {
            Scripter scripter = new Scripter();
            string   url      = "https://httpbin.org/post";

            ListStructure list = new ListStructure(new List <object>()
            {
                "something:val"
            }, null, scripter);


            scripter.InitVariables.Clear();
            scripter.InitVariables.Add("url", new TextStructure(url));
            scripter.InitVariables.Add("method", new TextStructure("post"));
            scripter.InitVariables.Add("list", list);

            scripter.Text = ($@"rest method {SpecialChars.Variable}method url {SpecialChars.Variable}url parameters {SpecialChars.Variable}list timeout {TestTimeout}
                               {SpecialChars.Variable}result2 = {SpecialChars.Variable}result{SpecialChars.IndexBegin}['form']['something']{SpecialChars.IndexEnd}");
            scripter.Run();

            Assert.AreEqual("val", scripter.Variables.GetVariableValue <string>("result2"));
            Assert.AreEqual("Completed", scripter.Variables.GetVariableValue <string>("status"));
        }
Beispiel #19
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager manager = AbbyyManager.Instance;

            FineReaderDocument.FilterFlags paramsFilter = FineReaderDocument.FilterFlags.none;

            string[] flagsString = arguments.Filter.Value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string flag in flagsString)
            {
                FineReaderDocument.FilterFlags currentFlag = FineReaderDocument.FilterFlags.none;
                try
                {
                    currentFlag   = (FineReaderDocument.FilterFlags)Enum.Parse(typeof(FineReaderDocument.FilterFlags), flag.Trim(), true);
                    paramsFilter |= (FineReaderDocument.FilterFlags)Enum.Parse(typeof(FineReaderDocument.FilterFlags), flag.Trim(), true);
                }
                catch
                {
                    throw new ArgumentOutOfRangeException(nameof(arguments.Filter), currentFlag, $"{currentFlag} is not defined filter");
                }
            }

            int docID = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;

            FineReaderDocument document = manager.GetDocument(docID);

            document.ExtractData();

            ListStructure filteredTexts = new ListStructure(new List <Structure>());

            foreach (string s in document.Filter(paramsFilter))
            {
                filteredTexts.Value.Add(new TextStructure(s));
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, filteredTexts);
        }
        // [ExpectedException(typeof(FormatException))]
        public void BadHeaderSeparatorTest()
        {
            string url = "http://jsonplaceholder.typicode.com/posts/1";

            ListStructure headers = new ListStructure(new List <Structure>()
            {
                new TextStructure("content-type(json")
            });

            Scripter scripter = new Scripter();

            scripter.InitVariables.Clear();
            scripter.InitVariables.Add("method", new TextStructure("put"));
            scripter.InitVariables.Add("url", new TextStructure(url));
            scripter.InitVariables.Add("headers", headers);
            scripter.Text = ($"rest method {SpecialChars.Variable}method url {SpecialChars.Variable}url headers {SpecialChars.Variable}headers");

            Exception exception = Assert.Throws <ApplicationException>(delegate
            {
                scripter.Run();
            });

            Assert.IsInstanceOf <FormatException>(exception.GetBaseException());
        }
        private void AddRequestData(RestRequest request, ListStructure list, char separator, bool toHeader)
        {
            if (list != null)
            {
                foreach (var listData in list.Value)
                {
                    string data          = listData.ToString();
                    var    separatedData = data.Split(separator);
                    if (separatedData.Length != 2)
                    {
                        throw new FormatException($" Bad separator in [{data}], use [{separator}] instead ");
                    }

                    if (toHeader)
                    {
                        request.AddHeader(separatedData[0], separatedData[1]);
                    }
                    else
                    {
                        request.AddParameter(separatedData[0], separatedData[1]);
                    }
                }
            }
        }