Exemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _timeout = TimeoutMS.Get(context);

            CallWithTimeout(new Action(() => {
                try
                {
                    string credName             = CredentialName.Get(context);
                    string userName             = UserName.Get(context);
                    SecureString credentialName = PassWord.Get(context);
                    IntPtr inP      = Marshal.SecureStringToBSTR(credentialName);
                    string passWord = Marshal.PtrToStringBSTR(inP);
                    WriteCred(credName, userName, passWord, CRED_TYPE.GENERIC, CRED_PERSIST.LOCAL_MACHINE);
                }
                catch (Exception e)
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "设置凭证执行过程出错", e.Message);
                }
            }), _timeout);
        }
Exemplo n.º 2
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                PdfReader pdfReader;
                string    pathUrl = PathUrl.Get(context);
                string    range   = Range.Get(context);

                if (!File.Exists(pathUrl))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "PDF文件不存在,请检查路径有效性", pathUrl);
                    return;
                }
                if (PassWord.Expression != null)
                {
                    byte[] byteArray = System.Text.Encoding.Default.GetBytes(PassWord.Get(context));
                    pdfReader = new iTextSharp.text.pdf.PdfReader(pathUrl, byteArray);
                }
                else
                {
                    pdfReader = new iTextSharp.text.pdf.PdfReader(pathUrl);
                }

                string pdfText = null;
                if (range.Contains(","))
                {
                    string[] rangeArray1 = range.Split(',');
                    foreach (string buff in rangeArray1)
                    {
                        string pdfPara = null;
                        if (buff.Contains("-"))
                        {
                            string[] rangeArray = buff.Split('-');
                            string   range1     = rangeArray[0];
                            string   range2     = rangeArray[1];
                            pdfPara = getContent(pdfReader, range1, range2);
                        }
                        else
                        {
                            pdfPara = getContent(pdfReader, buff);
                        }
                        pdfText += pdfPara;
                    }
                }
                else if (range.Contains("-"))
                {
                    string[] rangeArray = range.Split('-');
                    string   range1     = rangeArray[0];
                    string   range2     = rangeArray[1];
                    pdfText = getContent(pdfReader, range1, range2);
                }
                else
                {
                    pdfText = getContent(pdfReader, range);
                }
                context.SetValue(PDFText, pdfText);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "PDF读取文本失败", e);
                throw e;
            }
        }