protected override IEnumerable <CommandParameters> Execute(IEnumerable <CommandParameters> inParametersList) { foreach (var inParameters in inParametersList) { //inParameters = GetCurrentInParameters(); string file = inParameters.GetValue <string>("File"); string startParameter = inParameters.GetValue <string>("StartParameter"); string logFile = inParameters.GetValue <string>("OutputLogFile"); startParameter = TokenProcessor.ReplaceTokens(startParameter, inParameters.ToDictionary()); var shellOutput = this.commandShellAction.RunExternalExe(file, startParameter); // log output to logfile if (!string.IsNullOrEmpty(logFile) && !string.IsNullOrWhiteSpace(shellOutput)) { System.IO.File.AppendAllText(logFile, shellOutput + Environment.NewLine); } var outParameters = this.GetCurrentOutParameters(); outParameters.AddOrUpdate(new CommandParameter() { Name = "Output", Value = shellOutput }); yield return(outParameters); } }
protected override IEnumerable <CommandParameters> Execute(IEnumerable <CommandParameters> inParametersList) { foreach (var inParameters in inParametersList) { //inParameters = GetCurrentInParameters(); string sourceFile = inParameters.GetValue <string>("SourceFile"); string targetDirectory = inParameters.GetValueOrDefault <string>("TargetDirectory", Path.Combine(Path.GetDirectoryName(sourceFile), @"\{yyyy}\{MM}\")); string zipName = inParameters.GetValueOrDefault <string>("ZipName", Path.GetFileNameWithoutExtension(sourceFile) + ".zip"); string password = inParameters.GetValue <string>("Password"); bool removeSourceFile = inParameters.GetValueOrDefault <bool>("RemoveSourceFile", true); zipName = TokenProcessor.ReplaceToken(zipName, "SourceFileName", Path.GetFileName(sourceFile)); DirectoryUtil.CreateDirectoryIfNotExists(targetDirectory); var targetFile = Path.Combine(targetDirectory, zipName); this.ZipFile(sourceFile, targetFile, password); if (removeSourceFile) { File.Delete(sourceFile); } this.LogDebug(string.Format("Zipping archive='{0}'", targetFile)); var outParameters = this.GetCurrentOutParameters(); outParameters.SetOrAddValue("File", targetFile); yield return(outParameters); } }
private List <DbParameter> BuildDbParameters(IDictionary <string, object> parameters) { var dbParameters = new List <DbParameter>(); foreach (var dataMapping in this.DataMappings) { var dbParameter = this.dbAdapter.DbProviderFactory.CreateParameter(); dbParameter.ParameterName = dataMapping.Name; // replace token in the datamapping value e.g. ["Filename"]="{Filename}" -> ["Filename"]="C:\Temp\Test.txt" dbParameter.Value = TokenProcessor.ReplaceTokens(dataMapping.Value.ToStringOrEmpty(), parameters); dbParameter.DbType = dataMapping.DbType; switch (dataMapping.Direction) { case Directions.In: dbParameter.Direction = ParameterDirection.Input; break; case Directions.Out: dbParameter.Direction = ParameterDirection.Output; break; case Directions.InOut: dbParameter.Direction = ParameterDirection.InputOutput; break; } } return(dbParameters); }
static void Main(string[] args) { var tokenProcessor = new TokenProcessor(); tokenProcessor.ProcessSourceCode(); Console.Write("Done!"); }
public void TestUserCRUD() { IUser user = CreateUser(); UserProcessor up = new UserProcessor(user); var save = up.Create().Result; Assert.IsTrue(save != null && save.Data != null && save.Data.Id != Guid.Empty, "User save failed."); var one = up.FetchById().Result; one.Data.Password = "******"; Assert.IsTrue(one != null && JsonConvert.SerializeObject(one, Formatting.None).Equals(JsonConvert.SerializeObject(save, Formatting.None)), "User fetch failed."); var loggedIn = up.Login().Result; Assert.IsTrue(loggedIn != null && loggedIn.Data != Guid.Empty, "User login failed."); var delete = up.Delete().Result; one = up.FetchById().Result; Assert.IsTrue(one.Data == null, "User delete failed."); var tp = new TokenProcessor(loggedIn.Data); int result = tp.Delete().Result; var t = tp.FetchById().Result; Assert.IsTrue(t.Data == null, "Token delete failed."); }
private object InvokeWebRequestWithParameters(SimpleWebRequest webRequest, IDictionary <string, object> values = null) { // Take the values, which are defined in the mapping foreach (var dataMapping in this.DataMappings) { object value = null; if (dataMapping.Value != null) { // replace token e.g {Filename} -> C:\Temp\Test.txt value = TokenProcessor.ReplaceTokens(dataMapping.Value.ToStringOrEmpty(), values); } else { value = values.GetValue(dataMapping.Name); } webRequest.Parameters.Add(dataMapping.Name, value.ToStringOrEmpty()); } // call the service var result = webRequest.Invoke(); // format the result object data = null; if (this.formatter != null && result != null) { data = this.formatter.Format(result, null); } return(data); }
public static void RemoveTokenProcessor(TokenProcessor procesor) { TokenProcessors.Remove(procesor); if (TokenProcessors.Count == 0) { LastProcessor = null; } else { LastProcessor = TokenProcessors[TokenProcessors.Count - 1]; } }
protected override IEnumerable <CommandParameters> Execute(IEnumerable <CommandParameters> inParametersList) { foreach (var inParameters in inParametersList) { //inParameters = GetCurrentInParameters(); string script = inParameters.GetValue <string>("Script"); string logFile = inParameters.GetValue <string>("OutputLogFile"); var parameters = new Dictionary <string, object>(); if (this.DataMappings.Any()) { // Take the values, which are defined in the mapping foreach (var dataMapping in this.DataMappings) { string parameterValue = ""; if (dataMapping.Value != null) { parameterValue = TokenProcessor.ReplaceTokens(dataMapping.Value.ToStringOrEmpty()); } else { parameterValue = inParameters.GetValue <string>(dataMapping.Name); } parameters.Add(dataMapping.Name, parameterValue); } } else { parameters = inParameters.ToDictionary(); } var shellOutput = this.powerShellAction.Run(script, parameters); // log output to logfile if (!string.IsNullOrEmpty(logFile) && !string.IsNullOrWhiteSpace(shellOutput)) { System.IO.File.AppendAllText(logFile, shellOutput + Environment.NewLine); } var outParameters = this.GetCurrentOutParameters(); outParameters.AddOrUpdate(new CommandParameter() { Name = "Output", Value = shellOutput }); yield return(outParameters); } }
public void UntokenFilePreserveEncoding() { using (TestDirectory dir = new TestDirectory(@"MPFProjectTests\UntokenFilePreserveEncoding")) { TokenProcessor processor = new TokenProcessor(); // Test 1: Unicode file. string sourcePath = Path.Combine(dir.Path, "UnicodeSource"); string destinationPath = Path.Combine(dir.Path, "UnicodeDestination"); Encoding expectedEncoding = Encoding.Unicode; File.WriteAllText(sourcePath, "Test", expectedEncoding); processor.UntokenFile(sourcePath, destinationPath); Encoding actualEncoding; using (StreamReader reader = new StreamReader(destinationPath, Encoding.ASCII, true)) { // Read the content to force the encoding detection. reader.ReadToEnd(); actualEncoding = reader.CurrentEncoding; } Assert.AreEqual <Encoding>(expectedEncoding, actualEncoding); // Test 2: UTF8 file. sourcePath = Path.Combine(dir.Path, "UTF8Source"); destinationPath = Path.Combine(dir.Path, "UTF8Destination"); expectedEncoding = Encoding.UTF8; File.WriteAllText(sourcePath, "Test", expectedEncoding); processor.UntokenFile(sourcePath, destinationPath); using (StreamReader reader = new StreamReader(destinationPath, Encoding.ASCII, true)) { // Read the content to force the encoding detection. reader.ReadToEnd(); actualEncoding = reader.CurrentEncoding; } Assert.AreEqual <Encoding>(expectedEncoding, actualEncoding); // Test 3: ASCII file. sourcePath = Path.Combine(dir.Path, "AsciiSource"); destinationPath = Path.Combine(dir.Path, "AsciiDestination"); expectedEncoding = Encoding.ASCII; File.WriteAllText(sourcePath, "Test", expectedEncoding); processor.UntokenFile(sourcePath, destinationPath); using (StreamReader reader = new StreamReader(destinationPath, Encoding.ASCII, true)) { // Read the content to force the encoding detection. reader.ReadToEnd(); actualEncoding = reader.CurrentEncoding; } Assert.AreEqual <Encoding>(expectedEncoding, actualEncoding); } }
public void UntokenFilePreserveEncoding() { using(TestDirectory dir = new TestDirectory(@"MPFProjectTests\UntokenFilePreserveEncoding")) { TokenProcessor processor = new TokenProcessor(); // Test 1: Unicode file. string sourcePath = Path.Combine(dir.Path, "UnicodeSource"); string destinationPath = Path.Combine(dir.Path, "UnicodeDestination"); Encoding expectedEncoding = Encoding.Unicode; File.WriteAllText(sourcePath, "Test", expectedEncoding); processor.UntokenFile(sourcePath, destinationPath); Encoding actualEncoding; using(StreamReader reader = new StreamReader(destinationPath, Encoding.ASCII, true)) { // Read the content to force the encoding detection. reader.ReadToEnd(); actualEncoding = reader.CurrentEncoding; } Assert.AreEqual<Encoding>(expectedEncoding, actualEncoding); // Test 2: UTF8 file. sourcePath = Path.Combine(dir.Path, "UTF8Source"); destinationPath = Path.Combine(dir.Path, "UTF8Destination"); expectedEncoding = Encoding.UTF8; File.WriteAllText(sourcePath, "Test", expectedEncoding); processor.UntokenFile(sourcePath, destinationPath); using(StreamReader reader = new StreamReader(destinationPath, Encoding.ASCII, true)) { // Read the content to force the encoding detection. reader.ReadToEnd(); actualEncoding = reader.CurrentEncoding; } Assert.AreEqual<Encoding>(expectedEncoding, actualEncoding); // Test 3: ASCII file. sourcePath = Path.Combine(dir.Path, "AsciiSource"); destinationPath = Path.Combine(dir.Path, "AsciiDestination"); expectedEncoding = Encoding.ASCII; File.WriteAllText(sourcePath, "Test", expectedEncoding); processor.UntokenFile(sourcePath, destinationPath); using(StreamReader reader = new StreamReader(destinationPath, Encoding.ASCII, true)) { // Read the content to force the encoding detection. reader.ReadToEnd(); actualEncoding = reader.CurrentEncoding; } Assert.AreEqual<Encoding>(expectedEncoding, actualEncoding); } }
public void UntokenFileBadParameters() { TokenProcessor processor = new TokenProcessor(); Assert.IsTrue(Utilities.HasFunctionThrown<ArgumentNullException>(delegate { processor.UntokenFile(null, null); })); Assert.IsTrue(Utilities.HasFunctionThrown<ArgumentNullException>(delegate { processor.UntokenFile(@"C:\SomeFile", null); })); Assert.IsTrue(Utilities.HasFunctionThrown<ArgumentNullException>(delegate { processor.UntokenFile(null, @"C:\SomeFile"); })); Assert.IsTrue(Utilities.HasFunctionThrown<ArgumentNullException>(delegate { processor.UntokenFile(@"C:\SomeFile", string.Empty); })); Assert.IsTrue(Utilities.HasFunctionThrown<ArgumentNullException>(delegate { processor.UntokenFile(string.Empty, @"C:\SomeFile"); })); Assert.IsTrue(Utilities.HasFunctionThrown<ArgumentNullException>(delegate { processor.UntokenFile(string.Empty, string.Empty); })); using(TestDirectory dir = new TestDirectory(@"MPFProjectTests\UntokenFileBadParameters")) { string sourcePath = Path.Combine(dir.Path, "NotExistingSource"); string destinationPath = Path.Combine(dir.Path, "NotExistingDestination"); Assert.IsTrue(Utilities.HasFunctionThrown<FileNotFoundException>(delegate { processor.UntokenFile(sourcePath, destinationPath); })); } }
protected void btnEmailCustomer_Click(object sender, EventArgs e) { if (LoadOrder()) { TokenHelper tokenHelper = new TokenHelper(StoreContext); var tokens = tokenHelper.GetOrderTokens(order, true); var tokenizer = new TokenProcessor(Constants.TemplateTokenStart, Constants.TemplateTokenEnd); vStoreEmailTemplate emailTemplate = StoreContext.CurrentStore.GetStoreEmailTemplate(EmailTemplateNames.OrderReceived); string body = tokenizer.ReplaceTokensInString(HttpUtility.HtmlDecode(emailTemplate.BodyTemplate), tokens); Session["from"] = StoreContext.CurrentStore.GetSetting(StoreSettingNames.CustomerServiceEmailAddress); Session["to"] = order.CustomerEmail; Session["body"] = body; Response.Redirect(StoreUrls.Admin(ModuleDefs.Admin.Views.SendCustomerEmail)); } }
public override void OnAuthorization(HttpActionContext actionContext) { if (actionContext.Request.Headers.Contains("TokenId")) { var h = actionContext.Request.Headers.GetValues("TokenId").FirstOrDefault(); Guid val = Guid.Parse(h); var tp = new TokenProcessor(val); var t = tp.FetchById().Result; if (!t.Success || t.Data == null || !t.Data.Id.Equals(val)) { actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); } } else { actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); } }
public void UntokenFileBadParameters() { TokenProcessor processor = new TokenProcessor(); Assert.IsTrue(Utilities.HasFunctionThrown <ArgumentNullException>(delegate { processor.UntokenFile(null, null); })); Assert.IsTrue(Utilities.HasFunctionThrown <ArgumentNullException>(delegate { processor.UntokenFile(@"C:\SomeFile", null); })); Assert.IsTrue(Utilities.HasFunctionThrown <ArgumentNullException>(delegate { processor.UntokenFile(null, @"C:\SomeFile"); })); Assert.IsTrue(Utilities.HasFunctionThrown <ArgumentNullException>(delegate { processor.UntokenFile(@"C:\SomeFile", string.Empty); })); Assert.IsTrue(Utilities.HasFunctionThrown <ArgumentNullException>(delegate { processor.UntokenFile(string.Empty, @"C:\SomeFile"); })); Assert.IsTrue(Utilities.HasFunctionThrown <ArgumentNullException>(delegate { processor.UntokenFile(string.Empty, string.Empty); })); using (TestDirectory dir = new TestDirectory(@"MPFProjectTests\UntokenFileBadParameters")) { string sourcePath = Path.Combine(dir.Path, "NotExistingSource"); string destinationPath = Path.Combine(dir.Path, "NotExistingDestination"); Assert.IsTrue(Utilities.HasFunctionThrown <FileNotFoundException>(delegate { processor.UntokenFile(sourcePath, destinationPath); })); } }
public Node Parse(string code) { Code = code; Stopwatch stopwatch = Stopwatch.StartNew(); // Tokenize code Tokens = tokenizer.Tokenize(code); if (Tokens == null) { return(null); } // Pre-process tokens so their values are correct TokenProcessor.ProcessTokens(Tokens); stopwatch.Stop(); double T_Token = stopwatch.ElapsedMilliseconds; // Generate the program node stopwatch = Stopwatch.StartNew(); Node ProgramNode = generalParser.Parse(Tokens); stopwatch.Stop(); double T_Parse = stopwatch.ElapsedMilliseconds; // Debug program node //Console.WriteLine("Program:\n" + ProgramNode); //ScopeContext AnalizeScope = new ScopeContext(); //analizer.Analize(ProgramNode, AnalizeScope); stopwatch = Stopwatch.StartNew(); GlobalScope = executor.ExecuteBlock(ProgramNode, GlobalScope); stopwatch.Stop(); double T_Execute = stopwatch.ElapsedMilliseconds; Console.WriteLine("Execution: {0}ms, Parsing: {1}ms, Tokenization: {2}ms", T_Execute, T_Parse, T_Token); return(ProgramNode); }
protected override IEnumerable <CommandParameters> Execute(IEnumerable <CommandParameters> inParametersList) { foreach (var inParameters in inParametersList) { //inParameters = GetCurrentInParameters(); string file = inParameters.GetValue <string>("File"); string encodingName = inParameters.GetValue <string>("EncodingName"); string fileTemplate = inParameters.GetValue <string>("FileTemplate"); if (!string.IsNullOrEmpty(fileTemplate)) { var tokenValues = TokenProcessor.ParseTokenValues(file, fileTemplate); this.SetTokens(tokenValues); } this.fileAdapter.FileName = file; if (string.IsNullOrEmpty(encodingName)) { this.AutoDetectSettings(); encodingName = this.EncodingName; } this.fileAdapter.Encoding = EncodingUtil.GetEncodingOrDefault(encodingName); this.LogDebugFormat("Start reading File='{0}'", file); int rowCount = 0; foreach (var table in this.fileAdapter.ReadData(this.MaxRowsToRead)) { rowCount += table.Rows.Count; var outParameters = this.GetCurrentOutParameters(); outParameters.SetOrAddValue("Data", table); outParameters.SetOrAddValue("DataName", table.TableName); yield return(outParameters); } this.LogDebugFormat("End reading File='{0}': Rows={1}", file, rowCount); } }
private object InvokeWebserviceWithParameters(SimpleWebserviceRequest webService, IDictionary <string, object> values = null) { webService.Parameters.Clear(); // Take the values, which are defined in the mapping foreach (var dataMapping in this.DataMappings) { var webserviceParameter = new SimpleWebserviceRequest.WebserviceParameter() { Name = dataMapping.Name, Type = dataMapping.DataType.ToString() }; if (dataMapping.Value != null) { // replace token e.g {Filename} -> C:\Temp\Test.txt webserviceParameter.Value = TokenProcessor.ReplaceTokens(dataMapping.Value.ToStringOrEmpty(), values); } //else //{ // // set the value // webserviceParameter.Value = values.GetValue(dataMapping.Name); //} webService.Parameters.Add(webserviceParameter); } // call the service var result = webService.Invoke(); // format the result object data = null; if (this.formatter != null && result != null) { data = this.formatter.Format(result.OuterXml, null); } return(data); }
private List <QuizAction> ProcessTokensInActions(IEnumerable <QuizAction> actions, Dictionary <string, string> tokens) { var tokenizer = new TokenProcessor("[", "]"); var processedActions = new List <QuizAction>(); foreach (var a in actions) { foreach (var actionEmail in a.Emails) { actionEmail.From = tokenizer.ReplaceTokensInString(actionEmail.From, tokens); actionEmail.To = tokenizer.ReplaceTokensInString(actionEmail.To, tokens); actionEmail.Cc = tokenizer.ReplaceTokensInString(actionEmail.Cc, tokens); actionEmail.Bcc = tokenizer.ReplaceTokensInString(actionEmail.Bcc, tokens); actionEmail.SubjectTemplate = tokenizer.ReplaceTokensInString(actionEmail.SubjectTemplate, tokens); actionEmail.BodyTemplate = tokenizer.ReplaceTokensInString(actionEmail.BodyTemplate, tokens); //EmailService.SendEmail(from, to, cc, bcc, subject, body); } a.Message = tokenizer.ReplaceTokensInString(a.Message, tokens); processedActions.Add(a); } return(processedActions); }
private string ApplyDataMappings(string sql, IDictionary <string, object> parameters) { // prepare the sql and set the values if (this.DataMappings.Any()) { foreach (var dataMapping in this.DataMappings) { if (dataMapping.Value != null) { // replace token in the datamapping value e.g. ["Filename"]="{Filename}" -> ["Filename"]="C:\Temp\Test.txt" string value = TokenProcessor.ReplaceTokens(dataMapping.Value.ToStringOrEmpty(), parameters); // Replace the tokens in the sql template e.g. "SELECT * FROM tb_test WHERE ID = {Id}" sql = TokenProcessor.ReplaceToken(sql, dataMapping.Name, value); } } } else { sql = TokenProcessor.ReplaceTokens(sql, parameters); } return(sql); }
public void TestVendorCRUD() { IVendor vendor = CreateVendor(VendorType.Photographer); var vp = new VendorProcessor(vendor); var save = vp.Create().Result; Assert.IsTrue(save.Data != null && save.Data.Id != Guid.Empty, "Vendor save failed."); var one = vp.FetchById().Result; one.Data.Password = "******"; Assert.IsTrue(one.Data != null && JsonConvert.SerializeObject(one.Data, Formatting.None).Equals(JsonConvert.SerializeObject(save.Data, Formatting.None)), "Vendor fetch failed."); var uHelper = new UserProcessor(save.Data.Id); var uOne = uHelper.FetchById().Result; Assert.IsTrue(uOne.Data != null, "User not populated from vendor save."); var loggedIn = vp.Login().Result; Assert.IsTrue(loggedIn != null && loggedIn.Data != Guid.Empty, "Vendor login failed."); var delete = vp.Delete().Result; one = vp.FetchById().Result; Assert.IsTrue(one.Data == null, "Vendor delete failed."); uOne = uHelper.FetchById().Result; Assert.IsTrue(uOne.Data == null, "User not deleted from vendor delete."); var tp = new TokenProcessor(loggedIn.Data); int result = tp.Delete().Result; var t = tp.FetchById().Result; Assert.IsTrue(t.Data == null, "Token delete failed."); }
public SkryptEngine(string code = "") { _code = code; Tokenizer = new Tokenizer(this); TokenProcessor = new TokenProcessor(this); StatementParser = new StatementParser(this); ExpressionParser = new ExpressionParser(this); GeneralParser = new GeneralParser(this); MethodParser = new FunctionParser(this); ModifierChecker = new ModifierChecker(this); ClassParser = new ClassParser(this); Analizer = new Analizer(this); Executor = new Executor(this); var systemObject = ObjectGenerator.MakeObjectFromClass(typeof(Library.Native.System), this); GlobalScope.SetVariable(systemObject.Name, systemObject, Modifier.Const); CurrentScope = GlobalScope; // Tokens that are found using a token rule with type defined as 'null' won't get added to the token list. // This means you can ignore certain characters, like whitespace in this case, that way. Tokenizer.AddRule( new Regex(@"\s"), TokenTypes.None ); Tokenizer.AddRule( new Regex(@"\d+(\.\d+)?([eE][-+]?\d+)?"), TokenTypes.NumericLiteral ); Tokenizer.AddRule( new Regex(@"0x([A-Fa-f\d])*"), TokenTypes.HexadecimalLiteral ); Tokenizer.AddRule( new Regex(@"0b([01])*"), TokenTypes.BinaryLiteral ); Tokenizer.AddRule( new Regex(@"[_a-zA-Z]+[_a-zA-Z0-9]*"), TokenTypes.Identifier ); Tokenizer.AddRule( new Regex(@"include|const|using|public|private|strong|in|class|fn|if|elseif|else|while"), TokenTypes.Keyword ); Tokenizer.AddRule( new Regex("true|false"), TokenTypes.BooleanLiteral ); Tokenizer.AddRule( new Regex("null"), TokenTypes.NullLiteral ); Tokenizer.AddRule( new Regex(@"[;]"), TokenTypes.EndOfExpression ); Tokenizer.AddRule( new Regex( @"(import)|(return)|(continue)|(break)|(&&)|(\+=)|(\-=)|(\/=)|(\*=)|(\%=)|(\^=)|(\&=)|(\|=)|(\|\|\|=)|(\|\|\|)|(\|\|)|(=>)|(==)|(!=)|(>=)|(<=)|(<<)|(>>>)|(>>)|(\+\+)|(--)|[~=<>+\-*/%^&|!\[\]\(\)\.\,{}\?\:]"), TokenTypes.Punctuator ); // Single line comment Tokenizer.AddRule( new Regex(@"\/\/.*\n?"), TokenTypes.None ); // Multi line comment Tokenizer.AddRule( new Regex(@"\/\*.*?\*\/", RegexOptions.Singleline), TokenTypes.None ); Tokenizer.AddRule( new Regex(@""".*?(?<!\\)""", RegexOptions.Singleline), TokenTypes.StringLiteral ); }
public static void RegisterTokenProcessor(TokenProcessor procesor) { TokenProcessors.Add(procesor); LastProcessor = procesor; }
protected override IEnumerable <CommandParameters> Execute(IEnumerable <CommandParameters> inParametersList) { foreach (var inParameters in inParametersList) { //inParameters = GetCurrentInParameters(); string mailFrom = inParameters.GetValue <string>("From"); string mailTo = inParameters.GetValue <string>("To"); string mailCc = inParameters.GetValue <string>("CC"); string mailBcc = inParameters.GetValue <string>("BCC"); //object data = inParameters.GetValue<object>("Data"); var smtpConnectionInfo = this.ConnectionInfo as SmtpConnectionInfo; if (smtpConnectionInfo == null) { throw new ArgumentNullException("ConnectionInfo"); } using (var message = new MailMessage()) { // From message.From = new MailAddress(mailFrom, mailFrom, Encoding.UTF8); // To var to = mailTo.Replace(";", ","); foreach (string emailaddress in to.Split(',')) { message.To.Add(new MailAddress(emailaddress, string.Empty, Encoding.UTF8)); } message.Subject = TokenProcessor.ReplaceTokens(this.Subject, inParameters.ToDictionary()); message.Body = TokenProcessor.ReplaceTokens(this.Body, inParameters.ToDictionary()); // Attachments foreach (var attachment in this.Attachments) { string fileName = TokenProcessor.ReplaceTokens(attachment, inParameters.ToDictionary()); message.Attachments.Add(new Attachment(fileName)); } using (var smtpClient = new SmtpClient()) { smtpClient.Host = smtpConnectionInfo.SmtpServer; smtpClient.Port = smtpConnectionInfo.SmtpPort; if (smtpConnectionInfo.EnableSecure) { smtpClient.EnableSsl = smtpConnectionInfo.EnableSecure; } if (!string.IsNullOrEmpty(smtpConnectionInfo.UserName)) { smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential(smtpConnectionInfo.UserName, smtpConnectionInfo.DecryptedPassword); } smtpClient.Send(message); } } var outParameters = this.GetCurrentOutParameters(); yield return(outParameters); } }
/// <summary> /// Add Bar Descriptor to each project. /// </summary> private void AddBarDescriptor() { try { DTE dte = _applicationObject as DTE; Projects projs = dte.Solution.Projects; List <Project> projList = new List <Project>(); foreach (Project proj in projs) { projList.Add(proj); } while (projList.Count > 0) { Project proj = projList.ElementAt(0); projList.RemoveAt(0); Configuration config; Property prop; try { config = proj.ConfigurationManager.ActiveConfiguration; prop = config.Properties.Item("ConfigurationType"); } catch { config = null; prop = null; } if (prop == null) { if (proj.ProjectItems != null) { foreach (ProjectItem projItem in proj.ProjectItems) { if (projItem.SubProject != null) { projList.Add(projItem.SubProject); } } } continue; } if (Convert.ToInt16(prop.Value) != Convert.ToInt16(ConfigurationTypes.typeApplication)) { continue; } if (config.PlatformName != BLACKBERRY && config.PlatformName != BLACKBERRYSIMULATOR) { continue; } ProjectItem baritem = proj.ProjectItems.Item(BAR_DESCRIPTOR); string n = proj.Name; if (baritem == null) { tokenProcessor = new TokenProcessor(); Debug.WriteLine("Add bar descriptor file to the project"); string templatePath = dte.Solution.ProjectItemsTemplatePath(proj.Kind); templatePath += BAR_DESCRIPTOR_PATH + BAR_DESCRIPTOR; tokenProcessor.AddReplace(@"[!output PROJECT_NAME]", proj.Name); string destination = System.IO.Path.GetFileName(templatePath); // Remove directory used in previous versions of this plug-in. string folder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(proj.FullName), proj.Name + "_barDescriptor"); if (Directory.Exists(folder)) { try { Directory.Delete(folder); } catch (Exception e) { } } folder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(proj.FullName), "BlackBerry-" + proj.Name); System.IO.Directory.CreateDirectory(folder); destination = System.IO.Path.Combine(folder, destination); tokenProcessor.UntokenFile(templatePath, destination); ProjectItem projectitem = proj.ProjectItems.AddFromFile(destination); } } } catch (Exception e) { Debug.WriteLine(e.Message); } }