Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BuildScripts/MF.ClientAbsenteeReport/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ module.exports = function(grunt) {
});

grunt.option( 'PROD',{
connection_String:'Server=cannibalcoder.cloudapp.net;Database=MethodFitness_PROD;User ID=methodFitness;Password=m3th0d;Connection Timeout=30;',
connection_String:'Server=localhost;Database=MethodFitness_PROD;User ID=methodFitness;Password=m3th0df1t;Connection Timeout=30;',
environment:grunt.option('target'),
customErrors:"RemoteOnly",
debug:"false",
EmailReportAddress:"methodfit@gmail.com",
EmailReportAddress:"harik.raif@gmail.com",
AdminEmail:"info.prov@methodfit.com"
});

Expand Down
12 changes: 2 additions & 10 deletions src/Projects/CC.Core/CC.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Solutions\packages\ImageResizer.3.4.3\lib\ImageResizer.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\..\Solutions\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net-loggly, Version=8.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\Solutions\packages\log4net-loggly.8.0.1\lib\net40\log4net-loggly.dll</HintPath>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\..\Solutions\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation">
Expand All @@ -67,10 +63,6 @@
<HintPath>..\..\Solutions\packages\Microsoft.ReportViewer.Runtime.WebForms.12.0.2402.15\lib\Microsoft.ReportViewer.WebForms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\Solutions\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Solutions\packages\NHibernate.3.3.3.4001\lib\Net35\NHibernate.dll</HintPath>
Expand Down
4 changes: 1 addition & 3 deletions src/Projects/CC.Core/packages.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ImageResizer" version="3.4.3" targetFramework="net45" />
<package id="log4net" version="2.0.8" targetFramework="net45" />
<package id="log4net-loggly" version="8.0.1" targetFramework="net45" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.ReportViewer.Runtime.Common" version="12.0.2402.15" targetFramework="net45" />
<package id="Microsoft.ReportViewer.Runtime.WebForms" version="12.0.2402.15" targetFramework="net45" />
<package id="Microsoft.ReportViewer.Web.2012" version="1.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
<package id="structuremap" version="2.6.4.1" targetFramework="net40" />
</packages>
22 changes: 19 additions & 3 deletions src/Projects/MF.ClientAbsenteeReport/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<appSettings>
<add key="MethodFitness.sql_server_connection_string" value="Server=cannibalcoder.cloudapp.net;Database=MethodFitness_QA;User ID=methodFitness;Password=m3th0d;Connection Timeout=30;" />
Expand All @@ -10,7 +13,15 @@
<add key="SMTPPW" value="964159bf2fb0e2353e559aff4a32d255" />
<add key="EmailReportAddress" value="vze122tb2@verizon.net" />
<add key="AdminEmail" value="reharik@gmail.com" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net1213">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="..\\..\\Logs\\Dev\\Services\\ClientAbsentee.log" />
Expand All @@ -36,9 +47,9 @@
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
Expand All @@ -65,6 +76,11 @@
<assemblyIdentity name="System.Xml.Linq" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.4.1.0" newVersion="3.4.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

</configuration>
26 changes: 26 additions & 0 deletions src/Projects/MF.ClientAbsenteeReport/App.config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<appSettings>
<add key="MethodFitness.sql_server_connection_string" value="{{{connection_String}}}"/>
Expand All @@ -11,6 +14,13 @@
<add key="EmailReportAddress" value="{{{EmailReportAddress}}}"/>
<add key="AdminEmail" value="{{{AdminEmail}}}"/>
</appSettings>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net1213">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="..\\..\\Logs\\{{{environment}}}\Services\\ClientAbsentee.log" />
Expand All @@ -22,6 +32,18 @@
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%timestamp %date (%property{log4net:HostName})[%thread] %-5level %logger [%method(%line)] - %message %exception%newline" />
</layout>
</appender>
<appender name="NHibernateFileLog" type="log4net.Appender.RollingFileAppender">
<file value="..\\..\\Logs\\{{{environment}}}\\Services\\ClientAbsenteeNH.log" />
<appendToFile value="true" />
<preserveLogFileNameExtension value="true"/>
<rollingStyle value="Size"/>
<datePattern value="yyyy.MM.dd" />
<maxSizeRollBackups value="-1" />
<maximumFileSize value="20MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%timestamp %date (%property{log4net:HostName})[%thread] %-5level %logger [%method(%line)] - %message %exception%newline" />
</layout>
</appender>
<logger name="NHibernate" additivity="false">
<level value="ERROR" />
Expand Down Expand Up @@ -65,6 +87,10 @@
<assemblyIdentity name="System.Xml.Linq" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.4.1.0" newVersion="3.4.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
27 changes: 13 additions & 14 deletions src/Projects/MF.ClientAbsenteeReport/ClientAbsenteeJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ public class ClientAbsenteeJob : IJob
{
public void Execute(IJobExecutionContext context)
{
var service = ObjectFactory.Container.GetInstance<IGetDroppedClients>();
var logger = ObjectFactory.Container.GetInstance<ILogger>();
logger.LogError("about to check for clients");
var droppedClients = service.GetClients();
if (!droppedClients.Any())
{
logger.LogInfo("No new dropped clients on: " + DateTime.Now.ToString());
return;
}
var email = service.CreateEmail(droppedClients);
service.SendEmail(email, "absentee report");
service.UpdateClients(droppedClients);
logger.LogInfo("Job Processed at: "+ DateTime.Now.ToString());
logger.LogDebug("{0}", email);
var logger = ObjectFactory.Container.GetInstance<ILogger>();
var service = ObjectFactory.Container.GetInstance<IGetDroppedClients>();
var droppedClients = service.GetClients();
if (!droppedClients.Any())
{
logger.LogInfo("No new dropped clients on: " + DateTime.Now.ToString());
return;
}
var email = service.CreateEmail(droppedClients);
service.SendEmail(email, "absentee report");
service.UpdateClients(droppedClients);
logger.LogInfo("Job Processed at: " + DateTime.Now.ToString());
logger.LogDebug("{0}", email);
}
}
}
131 changes: 91 additions & 40 deletions src/Projects/MF.ClientAbsenteeReport/GetAbsentClients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
using MF.Core.Domain;
using MF.Core.Services;
using MF.Core;
using System.Linq;
using System.Linq;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace MF.ClientAbsenteeReport
{
Expand Down Expand Up @@ -37,41 +40,83 @@ public GetDroppedClients(IRepository repository,

public IEnumerable<DroppedClientDto> GetClients()
{
_logger.LogDebug("about to get clients");
var sql = @"SELECT c.EntityId,
c.FirstName,
c.LastName,
c.Email,
c.MobilePhone,
MAX(a.date) LastDate,
u.FirstName as TrainerFirstName,
u.LastName as TrainerLastName
FROM client c
INNER JOIN appointment_client ac
ON c.entityid = ac.clientid
INNER JOIN appointment a
ON ac.appointmentid = a.entityid
left join [user] u on a.trainerid = u.entityId
left JOIN ClientStatus cs
ON c.ClientStatusId = cs.EntityId
GROUP BY c.entityid ,c.entityId,
c.firstName,
c.lastName,
c.email,
c.mobilephone,
a.Completed,
cs.AdminAlerted,
u.FirstName,
u.LastName
having max(a.date) < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -10)
and max(a.date) > DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -90)
and a.Completed = 1
and (cs.AdminAlerted is null OR cs.AdminAlerted = 0)
order by u.lastname, u.FirstName ";
var droppedClientDtos = _repository.CreateSQLQuery<DroppedClientDto>(sql, new List<object>());
_logger.LogDebug(droppedClientDtos);
return droppedClientDtos;
_logger.LogInfo("Beginning GetClients Process.");
var droppedClientDtoList = new List<DroppedClientDto>();
try
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["MethodFitness.sql_server_connection_string"]))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "DailyClientAbsenteeReport";
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 180;

connection.Open();
int count = 0;
using (IDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
_logger.LogDebug(reader.GetString(5));
var droppedClientDto = new DroppedClientDto();
droppedClientDto.EntityId = reader.GetInt32(0);
droppedClientDto.TrainerFirstName = reader.GetString(1);
droppedClientDto.TrainerLastName = reader.GetString(2);
droppedClientDto.FirstName = reader.GetString(3);
droppedClientDto.LastName = reader.GetString(4);
droppedClientDto.Email = reader.GetString(5);
droppedClientDto.MobilePhone = reader.GetString(6);
droppedClientDto.LastDate = reader.GetDateTime(7);
droppedClientDtoList.Add(droppedClientDto);
}
}
connection.Close();
}
}
catch (Exception ex)
{
_logger.LogError(ex.Message, ex);
}
return droppedClientDtoList;
}




// _logger.LogDebug("about to get clients");
// var sql = @"SELECT c.EntityId,
// c.FirstName,
// c.LastName,
// c.Email,
// c.MobilePhone,
// MAX(a.date) LastDate,
// u.FirstName as TrainerFirstName,
// u.LastName as TrainerLastName
//FROM client c
// INNER JOIN appointment_client ac
// ON c.entityid = ac.clientid
// INNER JOIN appointment a
// ON ac.appointmentid = a.entityid
// left join [user] u on a.trainerid = u.entityId
// left JOIN ClientStatus cs
// ON c.ClientStatusId = cs.EntityId
//GROUP BY c.entityid ,c.entityId,
// c.firstName,
// c.lastName,
// c.email,
// c.mobilephone,
// a.Completed,
// cs.AdminAlerted,
// u.FirstName,
// u.LastName
//having max(a.date) < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -10)
//and max(a.date) > DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -90)
//and a.Completed = 1
//and (cs.AdminAlerted is null OR cs.AdminAlerted = 0)
//order by u.lastname, u.FirstName ";
// var droppedClientDtos = _repository.CreateSQLQuery<DroppedClientDto>(sql, new List<object>(), 120000);
// _logger.LogDebug("droppedClients", droppedClientDtos);

public IEnumerable<DroppedClientDto> GetWeeklyClients()
{
Expand Down Expand Up @@ -110,6 +155,7 @@ and max(a.date) > DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -17)

public string CreateEmail(IEnumerable<DroppedClientDto> clients)
{
_logger.LogDebug("About to Create Email");
var grouped = clients.GroupBy(c => c.TrainerLastName + ", " + c.TrainerFirstName, c => c,
(key, g) => new { Trainer = key, Clients = g.ToList() });
var email = new StringBuilder("<b>Daily absentee report for {0} </b>".ToFormat(DateTime.Now.AddDays(-10)));
Expand Down Expand Up @@ -140,7 +186,9 @@ public string CreateEmail(IEnumerable<DroppedClientDto> clients)
email.Append("</a>");
email.Append("<br />");
});
});
});
_logger.LogDebug(email.ToString());

return email.ToString();
}

Expand Down Expand Up @@ -176,8 +224,8 @@ public string CreateWeeklyEmail(IEnumerable<DroppedClientDto> clients)
email.Append("</a>");
email.Append("<br />");
});
});

});
_logger.LogDebug(email.ToString());
return email.ToString();
}

Expand All @@ -189,12 +237,15 @@ public void SendEmail(string email, string subject)
Subject = subject,
From = new MailAddress(Site.Config.EmailReportAddress),
To = new MailAddress(Site.Config.AdminEmail)
};
};
_logger.LogDebug("about to send Email");
_emailService.SendEmail(emailDto);
}

public void UpdateClients(IEnumerable<DroppedClientDto> clients)
{
{
_logger.LogDebug("about to updateClients");

clients.ForEachItem(x =>
{
var client = _repository.Find<Client>(x.EntityId);
Expand Down
Loading