Shedules fix
This commit is contained in:
parent
645229bef1
commit
476f7a2b19
7 changed files with 461 additions and 542 deletions
|
@ -971,7 +971,6 @@ GO
|
||||||
|
|
||||||
CREATE PROCEDURE [dbo].[GetBackgroundTask]
|
CREATE PROCEDURE [dbo].[GetBackgroundTask]
|
||||||
(
|
(
|
||||||
@ActorID INT,
|
|
||||||
@TaskID NVARCHAR(255)
|
@TaskID NVARCHAR(255)
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
@ -1013,6 +1012,16 @@ CREATE PROCEDURE [dbo].[GetBackgroundTasks]
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
|
||||||
|
with GetChildUsersId(id) as (
|
||||||
|
select UserID
|
||||||
|
from Users
|
||||||
|
where UserID = @ActorID
|
||||||
|
union all
|
||||||
|
select C.UserId
|
||||||
|
from GetChildUsersId P
|
||||||
|
inner join Users C on P.id = C.OwnerID
|
||||||
|
)
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
T.ID,
|
T.ID,
|
||||||
T.Guid,
|
T.Guid,
|
||||||
|
@ -1035,9 +1044,12 @@ SELECT
|
||||||
T.NotifyOnComplete,
|
T.NotifyOnComplete,
|
||||||
T.Status
|
T.Status
|
||||||
FROM BackgroundTasks AS T
|
FROM BackgroundTasks AS T
|
||||||
INNER JOIN BackgroundTaskStack AS TS
|
INNER JOIN (SELECT T.Guid, MIN(T.StartDate) AS Date
|
||||||
ON TS.TaskId = T.ID
|
FROM BackgroundTasks AS T
|
||||||
WHERE T.UserID = @ActorID
|
INNER JOIN BackgroundTaskStack AS TS
|
||||||
|
ON TS.TaskId = T.ID
|
||||||
|
WHERE T.UserID in (select id from GetChildUsersId)
|
||||||
|
GROUP BY T.Guid) AS TT ON TT.Guid = T.Guid AND TT.Date = T.StartDate
|
||||||
GO
|
GO
|
||||||
|
|
||||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetThreadBackgroundTasks')
|
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetThreadBackgroundTasks')
|
||||||
|
@ -1046,7 +1058,6 @@ GO
|
||||||
|
|
||||||
CREATE PROCEDURE [dbo].GetThreadBackgroundTasks
|
CREATE PROCEDURE [dbo].GetThreadBackgroundTasks
|
||||||
(
|
(
|
||||||
@ActorID INT,
|
|
||||||
@Guid UNIQUEIDENTIFIER
|
@Guid UNIQUEIDENTIFIER
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
@ -1084,7 +1095,6 @@ GO
|
||||||
|
|
||||||
CREATE PROCEDURE [dbo].[GetBackgroundTopTask]
|
CREATE PROCEDURE [dbo].[GetBackgroundTopTask]
|
||||||
(
|
(
|
||||||
@ActorID INT,
|
|
||||||
@Guid UNIQUEIDENTIFIER
|
@Guid UNIQUEIDENTIFIER
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
@ -1114,7 +1124,7 @@ FROM BackgroundTasks AS T
|
||||||
INNER JOIN BackgroundTaskStack AS TS
|
INNER JOIN BackgroundTaskStack AS TS
|
||||||
ON TS.TaskId = T.ID
|
ON TS.TaskId = T.ID
|
||||||
WHERE T.Guid = @Guid
|
WHERE T.Guid = @Guid
|
||||||
ORDER BY T.StartDate DESC
|
ORDER BY T.StartDate ASC
|
||||||
GO
|
GO
|
||||||
|
|
||||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'AddBackgroundTaskLog')
|
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'AddBackgroundTaskLog')
|
||||||
|
@ -1311,10 +1321,6 @@ VALUES
|
||||||
)
|
)
|
||||||
GO
|
GO
|
||||||
|
|
||||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'DeleteBackgroundTaskStack')
|
|
||||||
DROP PROCEDURE DeleteBackgroundTaskStack
|
|
||||||
GO
|
|
||||||
|
|
||||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'DeleteBackgroundTasks')
|
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'DeleteBackgroundTasks')
|
||||||
DROP PROCEDURE DeleteBackgroundTasks
|
DROP PROCEDURE DeleteBackgroundTasks
|
||||||
GO
|
GO
|
||||||
|
@ -1401,7 +1407,6 @@ GO
|
||||||
|
|
||||||
CREATE PROCEDURE [dbo].[GetScheduleBackgroundTasks]
|
CREATE PROCEDURE [dbo].[GetScheduleBackgroundTasks]
|
||||||
(
|
(
|
||||||
@ActorID INT,
|
|
||||||
@ScheduleID INT
|
@ScheduleID INT
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
@ -1431,91 +1436,5 @@ FROM BackgroundTasks AS T
|
||||||
WHERE T.Guid = (
|
WHERE T.Guid = (
|
||||||
SELECT Guid FROM BackgroundTasks
|
SELECT Guid FROM BackgroundTasks
|
||||||
WHERE ScheduleID = @ScheduleID
|
WHERE ScheduleID = @ScheduleID
|
||||||
AND UserID = @ActorID
|
|
||||||
AND Completed = 0 AND Status IN (1, 3))
|
AND Completed = 0 AND Status IN (1, 3))
|
||||||
AND T.UserID = @ActorID AND T.Completed = 0 AND T.Status IN (1, 3)
|
|
||||||
GO
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ALTER PROCEDURE [dbo].[GetBackgroundTopTask]
|
|
||||||
(
|
|
||||||
@ActorID INT,
|
|
||||||
@Guid UNIQUEIDENTIFIER
|
|
||||||
)
|
|
||||||
AS
|
|
||||||
|
|
||||||
SELECT TOP 1
|
|
||||||
T.ID,
|
|
||||||
T.Guid,
|
|
||||||
T.TaskID,
|
|
||||||
T.ScheduleId,
|
|
||||||
T.PackageId,
|
|
||||||
T.UserId,
|
|
||||||
T.EffectiveUserId,
|
|
||||||
T.TaskName,
|
|
||||||
T.ItemId,
|
|
||||||
T.ItemName,
|
|
||||||
T.StartDate,
|
|
||||||
T.FinishDate,
|
|
||||||
T.IndicatorCurrent,
|
|
||||||
T.IndicatorMaximum,
|
|
||||||
T.MaximumExecutionTime,
|
|
||||||
T.Source,
|
|
||||||
T.Severity,
|
|
||||||
T.Completed,
|
|
||||||
T.NotifyOnComplete,
|
|
||||||
T.Status
|
|
||||||
FROM BackgroundTasks AS T
|
|
||||||
INNER JOIN BackgroundTaskStack AS TS
|
|
||||||
ON TS.TaskId = T.ID
|
|
||||||
WHERE T.Guid = @Guid
|
|
||||||
ORDER BY T.StartDate ASC
|
|
||||||
GO
|
|
||||||
|
|
||||||
|
|
||||||
ALTER PROCEDURE [dbo].[GetBackgroundTasks]
|
|
||||||
(
|
|
||||||
@ActorID INT
|
|
||||||
)
|
|
||||||
AS
|
|
||||||
|
|
||||||
with GetChildUsersId(id) as (
|
|
||||||
select UserID
|
|
||||||
from Users
|
|
||||||
where UserID = @ActorID
|
|
||||||
union all
|
|
||||||
select C.UserId
|
|
||||||
from GetChildUsersId P
|
|
||||||
inner join Users C on P.id = C.OwnerID
|
|
||||||
)
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
T.ID,
|
|
||||||
T.Guid,
|
|
||||||
T.TaskID,
|
|
||||||
T.ScheduleId,
|
|
||||||
T.PackageId,
|
|
||||||
T.UserId,
|
|
||||||
T.EffectiveUserId,
|
|
||||||
T.TaskName,
|
|
||||||
T.ItemId,
|
|
||||||
T.ItemName,
|
|
||||||
T.StartDate,
|
|
||||||
T.FinishDate,
|
|
||||||
T.IndicatorCurrent,
|
|
||||||
T.IndicatorMaximum,
|
|
||||||
T.MaximumExecutionTime,
|
|
||||||
T.Source,
|
|
||||||
T.Severity,
|
|
||||||
T.Completed,
|
|
||||||
T.NotifyOnComplete,
|
|
||||||
T.Status
|
|
||||||
FROM BackgroundTasks AS T
|
|
||||||
INNER JOIN (SELECT T.Guid, MIN(T.StartDate) AS Date
|
|
||||||
FROM BackgroundTasks AS T
|
|
||||||
INNER JOIN BackgroundTaskStack AS TS
|
|
||||||
ON TS.TaskId = T.ID
|
|
||||||
WHERE T.UserID in (select id from GetChildUsersId)
|
|
||||||
GROUP BY T.Guid) AS TT ON TT.Guid = T.Guid AND TT.Date = T.StartDate
|
|
||||||
GO
|
GO
|
|
@ -36,11 +36,11 @@ using WebsitePanel.Providers;
|
||||||
|
|
||||||
namespace WebsitePanel.EnterpriseServer
|
namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Summary description for ObjectUtils.
|
/// Summary description for ObjectUtils.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ObjectUtils
|
public class ObjectUtils
|
||||||
{
|
{
|
||||||
public static DT ConvertObject<ST, DT>(ST so)
|
public static DT ConvertObject<ST, DT>(ST so)
|
||||||
{
|
{
|
||||||
Dictionary<string, PropertyInfo> sProps = GetTypePropertiesHash(typeof(ST));
|
Dictionary<string, PropertyInfo> sProps = GetTypePropertiesHash(typeof(ST));
|
||||||
|
@ -53,23 +53,23 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
if (dProps.ContainsKey(propName) && sProps[propName].Name != "Item")
|
if (dProps.ContainsKey(propName) && sProps[propName].Name != "Item")
|
||||||
{
|
{
|
||||||
if (sProps[propName].CanRead)
|
if (sProps[propName].CanRead)
|
||||||
{
|
{
|
||||||
object val = sProps[propName].GetValue(so, null);
|
object val = sProps[propName].GetValue(so, null);
|
||||||
if (dProps[propName] != null)
|
if (dProps[propName] != null)
|
||||||
{
|
{
|
||||||
if (val != null && dProps[propName].CanWrite)
|
if (val != null && dProps[propName].CanWrite)
|
||||||
{
|
{
|
||||||
dProps[propName].SetValue(dobj, val, null);
|
dProps[propName].SetValue(dobj, val, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dobj;
|
return dobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Hashtable typeProperties = new Hashtable();
|
private static Hashtable typeProperties = new Hashtable();
|
||||||
|
|
||||||
public static Hashtable GetObjectProperties(object obj, bool persistentOnly)
|
public static Hashtable GetObjectProperties(object obj, bool persistentOnly)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
// check for persistent attribute
|
// check for persistent attribute
|
||||||
object[] attrs = prop.GetCustomAttributes(typeof(PersistentAttribute), false);
|
object[] attrs = prop.GetCustomAttributes(typeof(PersistentAttribute), false);
|
||||||
if (!persistentOnly || (persistentOnly && attrs.Length > 0))
|
if (!persistentOnly || (persistentOnly && attrs.Length > 0) && !hash.ContainsKey(prop.Name))
|
||||||
{
|
{
|
||||||
object val = prop.GetValue(obj, null);
|
object val = prop.GetValue(obj, null);
|
||||||
string s = "";
|
string s = "";
|
||||||
|
@ -110,60 +110,60 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FillCollectionFromDataSet<T>(List<T> list, DataSet ds)
|
public static void FillCollectionFromDataSet<T>(List<T> list, DataSet ds)
|
||||||
{
|
{
|
||||||
if(ds.Tables.Count == 0)
|
if (ds.Tables.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FillCollectionFromDataView<T>(list, ds.Tables[0].DefaultView);
|
FillCollectionFromDataView<T>(list, ds.Tables[0].DefaultView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FillCollectionFromDataView<T>(List<T> list, DataView dv)
|
public static void FillCollectionFromDataView<T>(List<T> list, DataView dv)
|
||||||
{
|
{
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
|
|
||||||
PropertyInfo[] props = GetTypeProperties(type);
|
PropertyInfo[] props = GetTypeProperties(type);
|
||||||
|
|
||||||
foreach(DataRowView dr in dv)
|
foreach (DataRowView dr in dv)
|
||||||
{
|
{
|
||||||
// create an instance
|
// create an instance
|
||||||
T obj = (T)Activator.CreateInstance(type);
|
T obj = (T)Activator.CreateInstance(type);
|
||||||
list.Add(obj);
|
list.Add(obj);
|
||||||
|
|
||||||
// fill properties
|
// fill properties
|
||||||
for(int i = 0; i < props.Length; i++)
|
for (int i = 0; i < props.Length; i++)
|
||||||
{
|
{
|
||||||
string propName = props[i].Name;
|
string propName = props[i].Name;
|
||||||
if(dv.Table.Columns[propName] == null)
|
if (dv.Table.Columns[propName] == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
object propVal = dr[propName];
|
object propVal = dr[propName];
|
||||||
if(propVal == DBNull.Value)
|
if (propVal == DBNull.Value)
|
||||||
props[i].SetValue(obj, GetNull(props[i].PropertyType), null);
|
props[i].SetValue(obj, GetNull(props[i].PropertyType), null);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// try implicit type conversion
|
// try implicit type conversion
|
||||||
props[i].SetValue(obj, propVal, null);
|
props[i].SetValue(obj, propVal, null);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// convert to string and then set property value
|
// convert to string and then set property value
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string strVal = propVal.ToString();
|
string strVal = propVal.ToString();
|
||||||
props[i].SetValue(obj, Cast(strVal, props[i].PropertyType), null);
|
props[i].SetValue(obj, Cast(strVal, props[i].PropertyType), null);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// skip property init
|
// skip property init
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // for properties
|
} // for properties
|
||||||
} // for rows
|
} // for rows
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<T> CreateListFromDataReader<T>(IDataReader reader)
|
public static List<T> CreateListFromDataReader<T>(IDataReader reader)
|
||||||
{
|
{
|
||||||
|
@ -179,201 +179,201 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FillCollectionFromDataReader<T>(List<T> list, IDataReader reader)
|
public static void FillCollectionFromDataReader<T>(List<T> list, IDataReader reader)
|
||||||
{
|
{
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// get type properties
|
// get type properties
|
||||||
PropertyInfo[] props = GetTypeProperties(type);
|
PropertyInfo[] props = GetTypeProperties(type);
|
||||||
|
|
||||||
// iterate through reader
|
// iterate through reader
|
||||||
while(reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
T obj = (T)Activator.CreateInstance(type);
|
T obj = (T)Activator.CreateInstance(type);
|
||||||
list.Add(obj);
|
list.Add(obj);
|
||||||
|
|
||||||
// set properties
|
// set properties
|
||||||
for(int i = 0; i < props.Length; i++)
|
for (int i = 0; i < props.Length; i++)
|
||||||
{
|
{
|
||||||
string propName = props[i].Name;
|
string propName = props[i].Name;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
object propVal = reader[propName];
|
object propVal = reader[propName];
|
||||||
if(propVal == DBNull.Value)
|
if (propVal == DBNull.Value)
|
||||||
props[i].SetValue(obj, GetNull(props[i].PropertyType), null);
|
props[i].SetValue(obj, GetNull(props[i].PropertyType), null);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// try implicit type conversion
|
// try implicit type conversion
|
||||||
props[i].SetValue(obj, propVal, null);
|
props[i].SetValue(obj, propVal, null);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// convert to string and then set property value
|
// convert to string and then set property value
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string strVal = propVal.ToString();
|
string strVal = propVal.ToString();
|
||||||
props[i].SetValue(obj, Cast(strVal, props[i].PropertyType), null);
|
props[i].SetValue(obj, Cast(strVal, props[i].PropertyType), null);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// skip property init
|
// skip property init
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) { } // just skip
|
catch (Exception e) { } // just skip
|
||||||
} // for properties
|
} // for properties
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
reader.Close();
|
reader.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T FillObjectFromDataView<T>(DataView dv)
|
public static T FillObjectFromDataView<T>(DataView dv)
|
||||||
{
|
{
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
T obj = default(T);
|
T obj = default(T);
|
||||||
|
|
||||||
// get type properties
|
// get type properties
|
||||||
PropertyInfo[] props = GetTypeProperties(type);
|
PropertyInfo[] props = GetTypeProperties(type);
|
||||||
|
|
||||||
// iterate through reader
|
// iterate through reader
|
||||||
foreach(DataRowView dr in dv)
|
foreach (DataRowView dr in dv)
|
||||||
{
|
{
|
||||||
obj = (T)Activator.CreateInstance(type);
|
obj = (T)Activator.CreateInstance(type);
|
||||||
|
|
||||||
// set properties
|
// set properties
|
||||||
for(int i = 0; i < props.Length; i++)
|
for (int i = 0; i < props.Length; i++)
|
||||||
{
|
{
|
||||||
string propName = props[i].Name;
|
string propName = props[i].Name;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// verify if there is such a column
|
// verify if there is such a column
|
||||||
if (!dr.Row.Table.Columns.Contains(propName.ToLower()))
|
if (!dr.Row.Table.Columns.Contains(propName.ToLower()))
|
||||||
{
|
{
|
||||||
// if not, we move to another property
|
// if not, we move to another property
|
||||||
// because this one we cannot set
|
// because this one we cannot set
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
object propVal = dr[propName];
|
object propVal = dr[propName];
|
||||||
if(propVal == DBNull.Value)
|
if (propVal == DBNull.Value)
|
||||||
props[i].SetValue(obj, GetNull(props[i].PropertyType), null);
|
props[i].SetValue(obj, GetNull(props[i].PropertyType), null);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string strVal = propVal.ToString();
|
string strVal = propVal.ToString();
|
||||||
|
|
||||||
//convert to DateTime
|
//convert to DateTime
|
||||||
if (props[i].PropertyType.UnderlyingSystemType.FullName == typeof(DateTime).FullName)
|
if (props[i].PropertyType.UnderlyingSystemType.FullName == typeof(DateTime).FullName)
|
||||||
{
|
{
|
||||||
DateTime date = DateTime.MinValue;
|
DateTime date = DateTime.MinValue;
|
||||||
if (DateTime.TryParse(strVal, out date))
|
if (DateTime.TryParse(strVal, out date))
|
||||||
{
|
{
|
||||||
props[i].SetValue(obj, date, null);
|
props[i].SetValue(obj, date, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Convert generic
|
//Convert generic
|
||||||
props[i].SetValue(obj, Cast(strVal, props[i].PropertyType), null);
|
props[i].SetValue(obj, Cast(strVal, props[i].PropertyType), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// skip property init
|
// skip property init
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch{} // just skip
|
catch { } // just skip
|
||||||
} // for properties
|
} // for properties
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T FillObjectFromDataReader<T>(IDataReader reader)
|
public static T FillObjectFromDataReader<T>(IDataReader reader)
|
||||||
{
|
{
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
|
|
||||||
T obj = default(T);
|
T obj = default(T);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// get type properties
|
// get type properties
|
||||||
PropertyInfo[] props = GetTypeProperties(type);
|
PropertyInfo[] props = GetTypeProperties(type);
|
||||||
|
|
||||||
// iterate through reader
|
// iterate through reader
|
||||||
while(reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
obj = (T)Activator.CreateInstance(type);
|
obj = (T)Activator.CreateInstance(type);
|
||||||
|
|
||||||
// set properties
|
// set properties
|
||||||
for(int i = 0; i < props.Length; i++)
|
for (int i = 0; i < props.Length; i++)
|
||||||
{
|
{
|
||||||
string propName = props[i].Name;
|
string propName = props[i].Name;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!IsColumnExists(propName, reader.GetSchemaTable()))
|
if (!IsColumnExists(propName, reader.GetSchemaTable()))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
object propVal = reader[propName];
|
object propVal = reader[propName];
|
||||||
|
|
||||||
if(propVal == DBNull.Value)
|
if (propVal == DBNull.Value)
|
||||||
props[i].SetValue(obj, GetNull(props[i].PropertyType), null);
|
props[i].SetValue(obj, GetNull(props[i].PropertyType), null);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//try string first
|
//try string first
|
||||||
if (props[i].PropertyType.UnderlyingSystemType.FullName == typeof(String).FullName)
|
if (props[i].PropertyType.UnderlyingSystemType.FullName == typeof(String).FullName)
|
||||||
{
|
{
|
||||||
props[i].SetValue(obj, propVal.ToString(), null);
|
props[i].SetValue(obj, propVal.ToString(), null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// then, try implicit type conversion
|
// then, try implicit type conversion
|
||||||
props[i].SetValue(obj, propVal, null);
|
props[i].SetValue(obj, propVal, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// convert to string and then set property value
|
// convert to string and then set property value
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string strVal = propVal.ToString();
|
string strVal = propVal.ToString();
|
||||||
props[i].SetValue(obj, Cast(strVal, props[i].PropertyType), null);
|
props[i].SetValue(obj, Cast(strVal, props[i].PropertyType), null);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// skip property init
|
// skip property init
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch{} // just skip
|
catch { } // just skip
|
||||||
} // for properties
|
} // for properties
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
reader.Close();
|
reader.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Hashtable propertiesCache = new Hashtable();
|
private static Hashtable propertiesCache = new Hashtable();
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
Hashtable propValues = new Hashtable();
|
Hashtable propValues = new Hashtable();
|
||||||
foreach (DataRowView dr in dv)
|
foreach (DataRowView dr in dv)
|
||||||
{
|
{
|
||||||
if (propValues[dr[nameColumn]] == null)
|
if (propValues[dr[nameColumn]] == null && !propValues.ContainsKey(dr[nameColumn]))
|
||||||
propValues.Add(dr[nameColumn], dr[valueColumn]);
|
propValues.Add(dr[nameColumn], dr[valueColumn]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
Hashtable propValues = new Hashtable();
|
Hashtable propValues = new Hashtable();
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
if (propValues[reader[nameColumn]] == null)
|
if (propValues[reader[nameColumn]] == null && !propValues.ContainsKey(reader[nameColumn]))
|
||||||
propValues.Add(reader[nameColumn], reader[valueColumn]);
|
propValues.Add(reader[nameColumn], reader[valueColumn]);
|
||||||
}
|
}
|
||||||
reader.Close();
|
reader.Close();
|
||||||
|
@ -416,50 +416,54 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CopyPersistentPropertiesFromSource<T>(T source, T target)
|
public static void CopyPersistentPropertiesFromSource<T>(T source, T target)
|
||||||
where T : ServiceProviderItem
|
where T : ServiceProviderItem
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var typeSource = source.GetType();
|
var typeSource = source.GetType();
|
||||||
var typeTarget = target.GetType();
|
var typeTarget = target.GetType();
|
||||||
// get all property infos
|
// get all property infos
|
||||||
Hashtable props = null;
|
Hashtable props = null;
|
||||||
if (propertiesCache[typeSource.Name] != null)
|
if (propertiesCache[typeSource.Name] != null)
|
||||||
{
|
{
|
||||||
// load properties from cache
|
// load properties from cache
|
||||||
props = (Hashtable)propertiesCache[typeSource.Name];
|
props = (Hashtable)propertiesCache[typeSource.Name];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// create properties cache
|
// create properties cache
|
||||||
props = new Hashtable();
|
props = new Hashtable();
|
||||||
//
|
//
|
||||||
PropertyInfo[] objProps = typeSource.GetProperties(BindingFlags.Instance
|
PropertyInfo[] objProps = typeSource.GetProperties(BindingFlags.Instance
|
||||||
//| BindingFlags.DeclaredOnly
|
//| BindingFlags.DeclaredOnly
|
||||||
| BindingFlags.Public);
|
| BindingFlags.Public);
|
||||||
foreach (PropertyInfo prop in objProps)
|
foreach (PropertyInfo prop in objProps)
|
||||||
{
|
{
|
||||||
// check for persistent attribute
|
// check for persistent attribute
|
||||||
object[] attrs = prop.GetCustomAttributes(typeof(PersistentAttribute), false);
|
object[] attrs = prop.GetCustomAttributes(typeof(PersistentAttribute), false);
|
||||||
// Persistent only
|
// Persistent only
|
||||||
if (attrs.Length > 0)
|
if (attrs.Length > 0 && !props.ContainsKey(prop.Name))
|
||||||
{
|
{
|
||||||
// add property to hash
|
// add property to hash
|
||||||
props.Add(prop.Name, prop);
|
props.Add(prop.Name, prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add to cache
|
|
||||||
propertiesCache.Add(typeSource.Name, props);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the data
|
if (!propertiesCache.ContainsKey(typeSource.Name))
|
||||||
foreach (PropertyInfo propertyInfo in props.Values)
|
{
|
||||||
{
|
// add to cache
|
||||||
propertyInfo.SetValue(target, propertyInfo.GetValue(source, null), null);
|
propertiesCache.Add(typeSource.Name, props);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateObjectFromHash(object obj, Hashtable propValues, bool persistentOnly)
|
// Copy the data
|
||||||
|
foreach (PropertyInfo propertyInfo in props.Values)
|
||||||
|
{
|
||||||
|
propertyInfo.SetValue(target, propertyInfo.GetValue(source, null), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CreateObjectFromHash(object obj, Hashtable propValues, bool persistentOnly)
|
||||||
{
|
{
|
||||||
Type type = obj.GetType();
|
Type type = obj.GetType();
|
||||||
|
|
||||||
|
@ -481,15 +485,18 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
// check for persistent attribute
|
// check for persistent attribute
|
||||||
object[] attrs = prop.GetCustomAttributes(typeof(PersistentAttribute), false);
|
object[] attrs = prop.GetCustomAttributes(typeof(PersistentAttribute), false);
|
||||||
if (!persistentOnly || (persistentOnly && attrs.Length > 0))
|
if (!persistentOnly || (persistentOnly && attrs.Length > 0) && !props.ContainsKey(prop.Name))
|
||||||
{
|
{
|
||||||
// add property to hash
|
// add property to hash
|
||||||
props.Add(prop.Name, prop);
|
props.Add(prop.Name, prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to cache
|
if (!propertiesCache.ContainsKey(type.Name))
|
||||||
propertiesCache.Add(type.Name, props);
|
{
|
||||||
|
// add to cache
|
||||||
|
propertiesCache.Add(type.Name, props);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill properties
|
// fill properties
|
||||||
|
@ -513,37 +520,37 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
else
|
else
|
||||||
if (prop.PropertyType == typeof(long))
|
if (prop.PropertyType == typeof(long))
|
||||||
prop.SetValue(obj, long.Parse(val), null);
|
prop.SetValue(obj, long.Parse(val), null);
|
||||||
else
|
|
||||||
if (prop.PropertyType == typeof(Boolean))
|
|
||||||
prop.SetValue(obj, Boolean.Parse(val), null);
|
|
||||||
else if (prop.PropertyType == typeof(Single))
|
|
||||||
prop.SetValue(obj, Single.Parse(val), null);
|
|
||||||
else if (prop.PropertyType.IsEnum)
|
|
||||||
prop.SetValue(obj, Enum.Parse(prop.PropertyType, val, true), null);
|
|
||||||
else
|
|
||||||
if (prop.PropertyType == typeof(Guid))
|
|
||||||
prop.SetValue(obj, new Guid(val), null);
|
|
||||||
else
|
|
||||||
if (prop.PropertyType == typeof(string[]))
|
|
||||||
{
|
|
||||||
if (val == "")
|
|
||||||
prop.SetValue(obj, new string[0], null);
|
|
||||||
else
|
else
|
||||||
prop.SetValue(obj, val.Split(';'), null);
|
if (prop.PropertyType == typeof(Boolean))
|
||||||
}
|
prop.SetValue(obj, Boolean.Parse(val), null);
|
||||||
else if (prop.PropertyType == typeof(int[]))
|
else if (prop.PropertyType == typeof(Single))
|
||||||
{
|
prop.SetValue(obj, Single.Parse(val), null);
|
||||||
string[] svals = val.Split(';');
|
else if (prop.PropertyType.IsEnum)
|
||||||
int[] ivals = new int[svals.Length];
|
prop.SetValue(obj, Enum.Parse(prop.PropertyType, val, true), null);
|
||||||
|
else
|
||||||
|
if (prop.PropertyType == typeof(Guid))
|
||||||
|
prop.SetValue(obj, new Guid(val), null);
|
||||||
|
else
|
||||||
|
if (prop.PropertyType == typeof(string[]))
|
||||||
|
{
|
||||||
|
if (val == "")
|
||||||
|
prop.SetValue(obj, new string[0], null);
|
||||||
|
else
|
||||||
|
prop.SetValue(obj, val.Split(';'), null);
|
||||||
|
}
|
||||||
|
else if (prop.PropertyType == typeof(int[]))
|
||||||
|
{
|
||||||
|
string[] svals = val.Split(';');
|
||||||
|
int[] ivals = new int[svals.Length];
|
||||||
|
|
||||||
for (int i = 0; i < svals.Length; i++)
|
for (int i = 0; i < svals.Length; i++)
|
||||||
ivals[i] = Int32.Parse(svals[i]);
|
ivals[i] = Int32.Parse(svals[i]);
|
||||||
|
|
||||||
if (val == "")
|
if (val == "")
|
||||||
ivals = new int[0];
|
ivals = new int[0];
|
||||||
|
|
||||||
prop.SetValue(obj, ivals, null);
|
prop.SetValue(obj, ivals, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -553,50 +560,55 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
Dictionary<string, PropertyInfo> hash = new Dictionary<string, PropertyInfo>();
|
Dictionary<string, PropertyInfo> hash = new Dictionary<string, PropertyInfo>();
|
||||||
PropertyInfo[] props = GetTypeProperties(type);
|
PropertyInfo[] props = GetTypeProperties(type);
|
||||||
foreach (PropertyInfo prop in props)
|
foreach (PropertyInfo prop in props)
|
||||||
hash.Add(prop.Name, prop);
|
{
|
||||||
|
if (!hash.ContainsKey(prop.Name))
|
||||||
|
{
|
||||||
|
hash.Add(prop.Name, prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PropertyInfo[] GetTypeProperties(Type type)
|
private static PropertyInfo[] GetTypeProperties(Type type)
|
||||||
{
|
{
|
||||||
string typeName = type.AssemblyQualifiedName;
|
string typeName = type.AssemblyQualifiedName;
|
||||||
if(typeProperties[typeName] != null)
|
if (typeProperties[typeName] != null)
|
||||||
return (PropertyInfo[])typeProperties[typeName];
|
return (PropertyInfo[])typeProperties[typeName];
|
||||||
|
|
||||||
PropertyInfo[] props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
|
PropertyInfo[] props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
|
||||||
typeProperties[typeName] = props;
|
typeProperties[typeName] = props;
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static object GetNull(Type type)
|
public static object GetNull(Type type)
|
||||||
{
|
{
|
||||||
if(type == typeof(string))
|
if (type == typeof(string))
|
||||||
return null;
|
return null;
|
||||||
if(type == typeof(Int32))
|
if (type == typeof(Int32))
|
||||||
return 0;
|
return 0;
|
||||||
if(type == typeof(Int64))
|
if (type == typeof(Int64))
|
||||||
return 0;
|
return 0;
|
||||||
if(type == typeof(Boolean))
|
if (type == typeof(Boolean))
|
||||||
return false;
|
return false;
|
||||||
if(type == typeof(Decimal))
|
if (type == typeof(Decimal))
|
||||||
return 0M;
|
return 0M;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static object Cast(string val, Type type)
|
public static object Cast(string val, Type type)
|
||||||
{
|
{
|
||||||
if(type == typeof(string))
|
if (type == typeof(string))
|
||||||
return val;
|
return val;
|
||||||
if(type == typeof(Int32))
|
if (type == typeof(Int32))
|
||||||
return Int32.Parse(val);
|
return Int32.Parse(val);
|
||||||
if(type == typeof(Int64))
|
if (type == typeof(Int64))
|
||||||
return Int64.Parse(val);
|
return Int64.Parse(val);
|
||||||
if(type == typeof(Boolean))
|
if (type == typeof(Boolean))
|
||||||
return Boolean.Parse(val);
|
return Boolean.Parse(val);
|
||||||
if(type == typeof(Decimal))
|
if (type == typeof(Decimal))
|
||||||
return Decimal.Parse(val);
|
return Decimal.Parse(val);
|
||||||
if(type == typeof(string[]) && val != null)
|
if (type == typeof(string[]) && val != null)
|
||||||
{
|
{
|
||||||
return val.Split(';');
|
return val.Split(';');
|
||||||
}
|
}
|
||||||
|
@ -611,49 +623,49 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
iarr[i] = Int32.Parse(sarr[i]);
|
iarr[i] = Int32.Parse(sarr[i]);
|
||||||
return iarr;
|
return iarr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetTypeFullName(Type type)
|
public static string GetTypeFullName(Type type)
|
||||||
{
|
{
|
||||||
return type.FullName + ", " + type.Assembly.GetName().Name;
|
return type.FullName + ", " + type.Assembly.GetName().Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Helper Functions
|
#region Helper Functions
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This function is used to determine whether IDataReader contains a Column.
|
/// This function is used to determine whether IDataReader contains a Column.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="columnName">Name of the column.</param>
|
/// <param name="columnName">Name of the column.</param>
|
||||||
/// <param name="schemaTable">The schema <see cref="DataTable"/> that decribes result-set <see cref="IDataReader"/> contains.</param>
|
/// <param name="schemaTable">The schema <see cref="DataTable"/> that decribes result-set <see cref="IDataReader"/> contains.</param>
|
||||||
/// <returns>True, when required column exists in the <paramref name="schemaTable"/>. Otherwise, false.</returns>
|
/// <returns>True, when required column exists in the <paramref name="schemaTable"/>. Otherwise, false.</returns>
|
||||||
/// <remark>
|
/// <remark>
|
||||||
/// The followin example shows how to look for the "Role" column in the <see cref="IDataReader"/>.
|
/// The followin example shows how to look for the "Role" column in the <see cref="IDataReader"/>.
|
||||||
/// <example>
|
/// <example>
|
||||||
/// IDataReader reader = ....
|
/// IDataReader reader = ....
|
||||||
/// if (!IsColumnExists("Role", reader.GetSchemaTable())
|
/// if (!IsColumnExists("Role", reader.GetSchemaTable())
|
||||||
/// {
|
/// {
|
||||||
/// continue;
|
/// continue;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// object roleValue = reader["Role"];
|
/// object roleValue = reader["Role"];
|
||||||
/// </example>
|
/// </example>
|
||||||
/// </remark>
|
/// </remark>
|
||||||
static bool IsColumnExists(string columnName, DataTable schemaTable)
|
static bool IsColumnExists(string columnName, DataTable schemaTable)
|
||||||
{
|
{
|
||||||
foreach (DataRow row in schemaTable.Rows)
|
foreach (DataRow row in schemaTable.Rows)
|
||||||
{
|
{
|
||||||
if (String.Compare(row[0].ToString(), columnName, StringComparison.OrdinalIgnoreCase) == 0)
|
if (String.Compare(row[0].ToString(), columnName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1837,19 +1837,17 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
#region Scheduler
|
#region Scheduler
|
||||||
|
|
||||||
public static IDataReader GetBackgroundTask(int actorId, string taskId)
|
public static IDataReader GetBackgroundTask(string taskId)
|
||||||
{
|
{
|
||||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||||
ObjectQualifier + "GetBackgroundTask",
|
ObjectQualifier + "GetBackgroundTask",
|
||||||
new SqlParameter("@actorId", actorId),
|
|
||||||
new SqlParameter("@taskId", taskId));
|
new SqlParameter("@taskId", taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IDataReader GetScheduleBackgroundTasks(int actorId, int scheduleId)
|
public static IDataReader GetScheduleBackgroundTasks(int scheduleId)
|
||||||
{
|
{
|
||||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||||
ObjectQualifier + "GetScheduleBackgroundTasks",
|
ObjectQualifier + "GetScheduleBackgroundTasks",
|
||||||
new SqlParameter("@actorId", actorId),
|
|
||||||
new SqlParameter("@scheduleId", scheduleId));
|
new SqlParameter("@scheduleId", scheduleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1860,11 +1858,10 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
new SqlParameter("@actorId", actorId));
|
new SqlParameter("@actorId", actorId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IDataReader GetBackgroundTasks(int actorId, Guid guid)
|
public static IDataReader GetBackgroundTasks(Guid guid)
|
||||||
{
|
{
|
||||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||||
ObjectQualifier + "GetThreadBackgroundTasks",
|
ObjectQualifier + "GetThreadBackgroundTasks",
|
||||||
new SqlParameter("@actorId", actorId),
|
|
||||||
new SqlParameter("@guid", guid));
|
new SqlParameter("@guid", guid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1875,11 +1872,10 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
new SqlParameter("@status", (int)status));
|
new SqlParameter("@status", (int)status));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IDataReader GetBackgroundTopTask(int actorId, Guid guid)
|
public static IDataReader GetBackgroundTopTask(Guid guid)
|
||||||
{
|
{
|
||||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||||
ObjectQualifier + "GetBackGroundTopTask",
|
ObjectQualifier + "GetBackgroundTopTask",
|
||||||
new SqlParameter("@actorId", actorId),
|
|
||||||
new SqlParameter("@guid", guid));
|
new SqlParameter("@guid", guid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
public sealed class Scheduler
|
public sealed class Scheduler
|
||||||
{
|
{
|
||||||
public static SchedulerJob nextSchedule = null;
|
public static SchedulerJob nextSchedule = null;
|
||||||
//private static Timer timer = new Timer(ScheduleTasks, null, 30000, 30000);
|
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
|
@ -57,33 +56,10 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
return scheduledTasks.ContainsKey(scheduleId);
|
return scheduledTasks.ContainsKey(scheduleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartSchedule(SchedulerJob schedule)
|
|
||||||
{
|
|
||||||
if (IsScheduleActive(schedule.ScheduleInfo.ScheduleId))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// run schedule
|
|
||||||
RunSchedule(schedule, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void StopSchedule(SchedulerJob schedule)
|
|
||||||
{
|
|
||||||
Dictionary<int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();
|
|
||||||
if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
|
|
||||||
return;
|
|
||||||
|
|
||||||
BackgroundTask activeTask = scheduledTasks[schedule.ScheduleInfo.ScheduleId];
|
|
||||||
TaskManager.StopTask(activeTask.TaskId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ScheduleTasks()
|
public static void ScheduleTasks()
|
||||||
{
|
|
||||||
ScheduleTasks(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ScheduleTasks(object obj)
|
|
||||||
{
|
{
|
||||||
RunManualTasks();
|
RunManualTasks();
|
||||||
|
|
||||||
nextSchedule = SchedulerController.GetNextSchedule();
|
nextSchedule = SchedulerController.GetNextSchedule();
|
||||||
|
|
||||||
if (nextSchedule != null)
|
if (nextSchedule != null)
|
||||||
|
@ -125,6 +101,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
backgroundTask.Guid = TaskManager.Guid;
|
backgroundTask.Guid = TaskManager.Guid;
|
||||||
backgroundTask.Status = BackgroundTaskStatus.Run;
|
backgroundTask.Status = BackgroundTaskStatus.Run;
|
||||||
|
|
||||||
|
|
||||||
TaskController.UpdateTask(backgroundTask);
|
TaskController.UpdateTask(backgroundTask);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -132,7 +109,6 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
var objTask = (SchedulerTask)Activator.CreateInstance(Type.GetType(schedule.Task.TaskType));
|
var objTask = (SchedulerTask)Activator.CreateInstance(Type.GetType(schedule.Task.TaskType));
|
||||||
|
|
||||||
objTask.DoWork();
|
objTask.DoWork();
|
||||||
// Thread.Sleep(40000);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -199,6 +175,8 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
if (counter == MAX_RETRY_COUNT)
|
||||||
|
return;
|
||||||
|
|
||||||
// skip execution if the current task is still running
|
// skip execution if the current task is still running
|
||||||
scheduledTasks = TaskManager.GetScheduledTasks();
|
scheduledTasks = TaskManager.GetScheduledTasks();
|
||||||
|
|
|
@ -5,7 +5,6 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace WebsitePanel.EnterpriseServer
|
namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
public class TaskController
|
public class TaskController
|
||||||
|
@ -13,7 +12,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
public static BackgroundTask GetTask(string taskId)
|
public static BackgroundTask GetTask(string taskId)
|
||||||
{
|
{
|
||||||
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
||||||
DataProvider.GetBackgroundTask(SecurityContext.User.UserId, taskId));
|
DataProvider.GetBackgroundTask(taskId));
|
||||||
|
|
||||||
if (task == null)
|
if (task == null)
|
||||||
{
|
{
|
||||||
|
@ -28,12 +27,14 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
public static List<BackgroundTask> GetScheduleTasks(int scheduleId)
|
public static List<BackgroundTask> GetScheduleTasks(int scheduleId)
|
||||||
{
|
{
|
||||||
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
||||||
DataProvider.GetScheduleBackgroundTasks(SecurityContext.User.UserId, scheduleId));
|
DataProvider.GetScheduleBackgroundTasks(scheduleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BackgroundTask> GetTasks()
|
public static List<BackgroundTask> GetTasks()
|
||||||
{
|
{
|
||||||
return GetTasks(SecurityContext.User.UserId);
|
var user = SecurityContext.User;
|
||||||
|
|
||||||
|
return GetTasks(user.IsPeer ? user.OwnerId : user.UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BackgroundTask> GetTasks(int actorId)
|
public static List<BackgroundTask> GetTasks(int actorId)
|
||||||
|
@ -45,7 +46,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
public static List<BackgroundTask> GetTasks(Guid guid)
|
public static List<BackgroundTask> GetTasks(Guid guid)
|
||||||
{
|
{
|
||||||
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
||||||
DataProvider.GetBackgroundTasks(SecurityContext.User.UserId, guid));
|
DataProvider.GetBackgroundTasks(guid));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BackgroundTask> GetProcessTasks(BackgroundTaskStatus status)
|
public static List<BackgroundTask> GetProcessTasks(BackgroundTaskStatus status)
|
||||||
|
@ -57,7 +58,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
public static BackgroundTask GetTopTask(Guid guid)
|
public static BackgroundTask GetTopTask(Guid guid)
|
||||||
{
|
{
|
||||||
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
||||||
DataProvider.GetBackgroundTopTask(SecurityContext.User.UserId, guid));
|
DataProvider.GetBackgroundTopTask(guid));
|
||||||
|
|
||||||
if (task == null)
|
if (task == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -190,32 +190,36 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
// call event handler
|
// call event handler
|
||||||
CallTaskEventHandler(task, false);
|
CallTaskEventHandler(task, false);
|
||||||
|
|
||||||
int newTaskId = TaskController.AddTask(task);
|
AddTaskThread(TaskController.AddTask(task), Thread.CurrentThread);
|
||||||
AddTaskThread(newTaskId, Thread.CurrentThread);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteParameter(string parameterName, object parameterValue)
|
public static void WriteParameter(string parameterName, object parameterValue)
|
||||||
{
|
{
|
||||||
string val = parameterValue != null ? parameterValue.ToString() : "";
|
string val = parameterValue != null ? parameterValue.ToString() : "";
|
||||||
WriteLogRecord(0, parameterName + ": " + val, null, null);
|
WriteLogRecord(Guid, 0, parameterName + ": " + val, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Write(string text, params string[] textParameters)
|
public static void Write(string text, params string[] textParameters)
|
||||||
{
|
{
|
||||||
// INFO
|
// INFO
|
||||||
WriteLogRecord(0, text, null, textParameters);
|
WriteLogRecord(Guid, 0, text, null, textParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteWarning(string text, params string[] textParameters)
|
public static void WriteWarning(string text, params string[] textParameters)
|
||||||
|
{
|
||||||
|
WriteWarning(Guid, text, textParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteWarning(Guid guid, string text, params string[] textParameters)
|
||||||
{
|
{
|
||||||
// WARNING
|
// WARNING
|
||||||
WriteLogRecord(1, text, null, textParameters);
|
WriteLogRecord(guid, 1, text, null, textParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Exception WriteError(Exception ex)
|
public static Exception WriteError(Exception ex)
|
||||||
{
|
{
|
||||||
// ERROR
|
// ERROR
|
||||||
WriteLogRecord(2, ex.Message, ex.StackTrace);
|
WriteLogRecord(Guid, 2, ex.Message, ex.StackTrace);
|
||||||
|
|
||||||
return new Exception((TopTask != null)
|
return new Exception((TopTask != null)
|
||||||
? String.Format("Error executing '{0}' task on '{1}' {2}",
|
? String.Format("Error executing '{0}' task on '{1}' {2}",
|
||||||
|
@ -234,18 +238,18 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
prms[0] = ex.Message;
|
prms[0] = ex.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteLogRecord(2, text, ex.Message + "\n" + ex.StackTrace, prms);
|
WriteLogRecord(Guid, 2, text, ex.Message + "\n" + ex.StackTrace, prms);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteError(string text, params string[] textParameters)
|
public static void WriteError(string text, params string[] textParameters)
|
||||||
{
|
{
|
||||||
// ERROR
|
// ERROR
|
||||||
WriteLogRecord(2, text, null, textParameters);
|
WriteLogRecord(Guid, 2, text, null, textParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteLogRecord(int severity, string text, string stackTrace, params string[] textParameters)
|
private static void WriteLogRecord(Guid guid, int severity, string text, string stackTrace, params string[] textParameters)
|
||||||
{
|
{
|
||||||
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
|
List<BackgroundTask> tasks = TaskController.GetTasks(guid);
|
||||||
|
|
||||||
if (tasks.Count > 0)
|
if (tasks.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -571,6 +575,8 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
task.FinishDate = DateTime.Now;
|
task.FinishDate = DateTime.Now;
|
||||||
|
|
||||||
|
WriteWarning(task.Guid, "Task aborted by user");
|
||||||
|
|
||||||
AddAuditLog(task);
|
AddAuditLog(task);
|
||||||
|
|
||||||
TaskController.UpdateTask(task);
|
TaskController.UpdateTask(task);
|
||||||
|
|
|
@ -6,14 +6,16 @@ namespace WebsitePanel.SchedulerService
|
||||||
{
|
{
|
||||||
public partial class SchedulerService : ServiceBase
|
public partial class SchedulerService : ServiceBase
|
||||||
{
|
{
|
||||||
private Timer _timer = new Timer(Process, null, 5000, 5000);
|
private Timer _Timer;
|
||||||
|
private static bool _isRuninng;
|
||||||
#region Construcor
|
#region Construcor
|
||||||
|
|
||||||
public SchedulerService()
|
public SchedulerService()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
_Timer = new Timer(Process, null, 5000, 5000);
|
||||||
|
_isRuninng = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -22,12 +24,17 @@ namespace WebsitePanel.SchedulerService
|
||||||
|
|
||||||
protected override void OnStart(string[] args)
|
protected override void OnStart(string[] args)
|
||||||
{
|
{
|
||||||
Scheduler.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void Process(object callback)
|
protected static void Process(object callback)
|
||||||
{
|
{
|
||||||
Scheduler.Start();
|
//check running service
|
||||||
|
if (_isRuninng)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isRuninng = true;
|
||||||
|
Scheduler.Start();
|
||||||
|
_isRuninng = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue