public void Persist(PluginDescription pluginDescription, byte[] pluginPackage) { using (var ctx = new DeploymentDataContext()) { try { using (var transaction = new TransactionScope()) { Plugin pluginEntity = InsertOrUpdatePlugin(ctx, pluginDescription); if (pluginEntity.PluginPackage == null) { // insert pluginEntity.PluginPackage = MakePluginPackage(pluginEntity, pluginPackage); } else { // update pluginEntity.PluginPackage.Data = pluginPackage; } ctx.SubmitChanges(); transaction.Complete(); } } catch (SqlException ex) { throw new ArgumentException("Something went wrong while trying to persist plugin", ex); } catch (InvalidOperationException ex) { throw new ArgumentException("Something went wrong while trying to persist plugin", ex); } } }
private ProductDescription MakeProductDescription(DeploymentDataContext ctx, Product p, IEnumerable <Plugin> plugins) { var desc = new ProductDescription(p.Name, new Version(p.Version), from plugin in plugins select MakePluginDescription(ctx, plugin)); return(desc); }
private Product GetExistingProduct(DeploymentDataContext ctx, string name, Version version) { return((from p in ctx.Products where p.Name == name where p.Version == version.ToString() select p).Single()); }
private IEnumerable <Plugin> GetDependencies(DeploymentDataContext ctx, Plugin plugin) { return(from pair in ctx.Dependencies from dependency in ctx.Plugins where pair.PluginId == plugin.Id where pair.DependencyId == dependency.Id select dependency); }
private void DoServiceActions() { DataAccessLayer dal = new DataAccessLayer(); SystemShutMailer ssm = new SystemShutMailer(); DeploymentDataContext db = new DeploymentDataContext(); bool IsMailSendingNeeded = false; var locs = (from l in db.locations select new { l.Location_id, l.Location_name }); string MailTitle = "<table border='1' style='width:100%;border-width:1px;font-family: Verdana;font-size: 12px;letter-spacing: 1.5px;'><tr><th align='left' colspan='4' scope='col'>System Generated Report After Auto Shut Time</th></tr>"; string MailContent = "<tr><th width='20%' align='left'> Location Name </th><th width='28%' align='left'> Projected Deployment </th><th width='28%' align='left'> Actual Scenario </th><th width='24%' align='left'> Remarks </th></tr>"; string ShftName = ""; foreach (var loc in locs) { string shiftid = ""; SqlParameter[] para = new SqlParameter[2]; para[0] = new SqlParameter("@LocationID", loc.Location_id); para[1] = new SqlParameter("@CurrDate", DateTime.Now); DataTable dt = dal.executeprocedure("GetCurrentShift", para, false); if (dt.Rows.Count > 0) { string Shiftname = dt.Columns[0].ColumnName; ShftName = Shiftname; string FromTime, ToTime = ""; FromTime = Shiftname.Split('-')[0].Trim(); ToTime = Shiftname.Split('-')[1].Trim(); DateTime[] dtarr = CDashBoard.GetFromToFromColumnName(FromTime, ToTime); long DGAID = 0; DGAID += long.Parse(dt.Rows[0][0].ToString().Split(new String[] { "||" }, StringSplitOptions.None)[1]); bool IsMailSent = (from vw in db.vwDailyDeployments join wdr in db.WeekDayRosters on vw.WDRID equals wdr.WDRID where vw.DGAID == DGAID select wdr.IsMailSent.Value).SingleOrDefault(); if (dtarr[0].AddHours(3) < DateTime.Now && (!IsMailSent)) { IsMailSendingNeeded = true; MailContent += "<tr><td>" + loc.Location_name + "</td>"; MailContent += ssm.SendAutoShutEmail(dt, Shiftname, loc.Location_id.ToString()); MailContent += "</tr>"; WeekDayRoster wd = (from vw in db.vwDailyDeployments join wdr in db.WeekDayRosters on vw.WDRID equals wdr.WDRID where vw.DGAID == DGAID select wdr).SingleOrDefault(); wd.IsMailSent = true; db.SubmitChanges(); } } } MailContent += "</table>"; if (IsMailSendingNeeded) { //List<string> toemails = new List<string>(); //DataTable dt = new DataTable(); //foreach MailHelper.SendEmail("*****@*****.**", "*****@*****.**", "", "Shift Report for Shift " + ShftName, MailTitle + MailContent, true); } }
private void DeleteOldDependencies(DeploymentDataContext ctx, Plugin pluginEntity) { var oldDependencies = (from dep in ctx.Dependencies where dep.PluginId == pluginEntity.Id select dep).ToList(); ctx.Dependencies.DeleteAllOnSubmit(oldDependencies); ctx.SubmitChanges(); }
private void DeleteProductPlugins(DeploymentDataContext ctx, Product productEntity) { var oldPlugins = (from p in ctx.ProductPlugins where p.ProductId == productEntity.Id select p).ToList(); ctx.ProductPlugins.DeleteAllOnSubmit(oldPlugins); ctx.SubmitChanges(); }
private PluginDescription MakePluginDescription(DeploymentDataContext ctx, Plugin plugin) { if (!pluginDescriptions.ContainsKey(plugin.Id)) { // no cached description -> create new var desc = new PluginDescription(plugin.Name, new Version(plugin.Version)); pluginDescriptions[plugin.Id] = desc; // and add to cache // fill remaining properties of plugin description desc.Dependencies = new List <PluginDescription>(from dep in GetDependencies(ctx, plugin) select MakePluginDescription(ctx, dep)); desc.ContactEmail = plugin.ContactEmail ?? string.Empty; desc.ContactName = plugin.ContactName ?? string.Empty; desc.LicenseText = plugin.License ?? string.Empty; } return(pluginDescriptions[plugin.Id]); }
private Plugin InsertOrUpdatePlugin(DeploymentDataContext ctx, PluginDescription pluginDescription) { var pluginEntity = (from p in ctx.Plugins where p.Name == pluginDescription.Name where p.Version == pluginDescription.Version.ToString() select p).FirstOrDefault() ?? MakePluginFromDescription(pluginDescription); if (pluginEntity.Id <= 0) { ctx.Plugins.InsertOnSubmit(pluginEntity); ctx.SubmitChanges(); } UpdatePlugin(ctx, pluginEntity, pluginDescription); return(pluginEntity); }
public void Delete(ProductDescription productDescription) { using (var ctx = new DeploymentDataContext()) { try { using (var transaction = new TransactionScope()) { var productEntity = GetExistingProduct(ctx, productDescription.Name, productDescription.Version); DeleteProductPlugins(ctx, productEntity); ctx.Products.DeleteOnSubmit(productEntity); ctx.SubmitChanges(); transaction.Complete(); } } catch (SqlException ex) { throw new ArgumentException("Something went wrong while trying to delete product", ex); } catch (InvalidOperationException ex) { throw new ArgumentException("Something went wrong while trying to delete product", ex); } } }
public void Persist(ProductDescription productDescription) { using (var ctx = new DeploymentDataContext()) { try { using (var transaction = new TransactionScope()) { foreach (var plugin in productDescription.Plugins) { var pluginEntity = GetExistingPlugin(ctx, plugin.Name, plugin.Version); UpdatePlugin(ctx, pluginEntity, plugin); } InsertOrUpdateProduct(ctx, productDescription); ctx.SubmitChanges(); transaction.Complete(); } } catch (SqlException ex) { throw new ArgumentException("Something went wrong while trying to persist product", ex); } catch (InvalidOperationException ex) { throw new ArgumentException("Something went wrong while trying to persist product", ex); } } }
private void UpdatePlugin(DeploymentDataContext ctx, Plugin pluginEntity, PluginDescription pluginDescription) { // update plugin data pluginEntity.License = pluginDescription.LicenseText; pluginEntity.ContactName = pluginDescription.ContactName; pluginEntity.ContactEmail = pluginDescription.ContactEmail; // delete cached entry if (pluginDescriptions.ContainsKey(pluginEntity.Id)) { pluginDescriptions.Remove(pluginEntity.Id); } DeleteOldDependencies(ctx, pluginEntity); foreach (var dependency in pluginDescription.Dependencies) { var dependencyEntity = GetExistingPlugin(ctx, dependency.Name, dependency.Version); Dependency d = new Dependency(); d.PluginId = pluginEntity.Id; d.DependencyId = dependencyEntity.Id; ctx.Dependencies.InsertOnSubmit(d); } }
private void InsertOrUpdateProduct(DeploymentDataContext ctx, ProductDescription product) { var productEntity = (from p in ctx.Products where p.Name == product.Name where p.Version == product.Version.ToString() select p).FirstOrDefault() ?? MakeProductFromDescription(product); if (productEntity.Id <= 0) { ctx.Products.InsertOnSubmit(productEntity); ctx.SubmitChanges(); } DeleteProductPlugins(ctx, productEntity); foreach (var plugin in product.Plugins) { var existingPlugin = GetExistingPlugin(ctx, plugin.Name, plugin.Version); ProductPlugin prodPlugin = new ProductPlugin(); prodPlugin.PluginId = existingPlugin.Id; prodPlugin.ProductId = productEntity.Id; ctx.ProductPlugins.InsertOnSubmit(prodPlugin); } }
public string SendAutoShutEmail(DataTable dt, string ShiftName, string LocationID) { string MailContent = "<td>"; for (int i = 0; i < dt.Rows.Count; i++) { MailContent += dt.Rows[i][0].ToString().Split(new String[] { "||" }, StringSplitOptions.None)[0] + "<br />"; } MailContent += "</td>"; MailContent += "<td>"; string FromTime, ToTime = ""; FromTime = ShiftName.Split('-')[0].Trim(); ToTime = ShiftName.Split('-')[1].Trim(); DateTime[] dtarr = CDashBoard.GetFromToFromColumnName(FromTime, ToTime); for (int i = 0; i < dt.Rows.Count; i++) { MailContent += dt.Rows[i][0].ToString().Split(new String[] { "||" }, StringSplitOptions.None)[0] + " "; DataTable dtr = CDashBoard.CheckUserCheckedInStatus(dt.Rows[i][0].ToString().Split(new String[] { "||" }, StringSplitOptions.None)[2], dtarr[0], dtarr[1], LocationID); if (dtr.Rows[0][0].ToString() == "Green") { MailContent += "<font style='font-color:green'>On Time : </font>Checked In At " + DateTime.Parse(dtr.Rows[0][1].ToString()).ToString("MM/dd/yyyy HH:mm:ss tt"); } else if (dtr.Rows[0][0].ToString() == "Orange") { MailContent += "<font style='font-color:orange'>Late By : </font>" + decimal.Ceiling(decimal.Parse(DateTime.Parse(dtr.Rows[0][1].ToString()).Subtract(dtarr[0]).TotalMinutes.ToString())).ToString() + " minutes. Checked In At : " + DateTime.Parse(dtr.Rows[0][1].ToString()).ToString("MM/dd/yyyy HH:mm:ss tt"); } else { TimeSpan ts = DateTime.Now.Subtract(dtarr[0]); if (ts.TotalMinutes > 30) { MailContent += "<font style='font-color:maroon'>Not Checked In Yet</font>"; } else { MailContent += "<font style='font-color:black'>Expected To Come</font>"; } } MailContent += "<br />"; } MailContent += "</td>"; MailContent += "<td>"; DeploymentDataContext db = new DeploymentDataContext(); long DGAID = 0; DGAID += long.Parse(dt.Rows[0][0].ToString().Split(new String[] { "||" }, StringSplitOptions.None)[1]); string Remark = (from vw in db.vwDailyDeployments join wdr in db.WeekDayRosters on vw.WDRID equals wdr.WDRID where vw.DGAID == DGAID select wdr.Remarks).SingleOrDefault(); MailContent += Remark + "</td>"; //List<string> emailids = new List<string>(); //DataTable dte = dal.getdata("select EmailID from UserInformation where Role like '%director%' or Role like '%superuser%'"); //foreach (DataRow dr in dte.Rows) //{ // emailids.Add(dr[0].ToString()); //} //MailHelper.SendEmail(emailids, "*****@*****.**", "", "Shift Report for Shift " + ShiftName + " on " + LocationName, MailContent, true); return(MailContent); }
public byte[] PluginFile(PluginDescription pluginDescription) { using (var ctx = new DeploymentDataContext()) { return(GetExistingPlugin(ctx, pluginDescription.Name, pluginDescription.Version).PluginPackage.Data.ToArray()); } }