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
|
||||||
|
FROM BackgroundTasks AS T
|
||||||
|
INNER JOIN BackgroundTaskStack AS TS
|
||||||
ON TS.TaskId = T.ID
|
ON TS.TaskId = T.ID
|
||||||
WHERE T.UserID = @ActorID
|
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
|
|
@ -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 = "";
|
||||||
|
@ -112,7 +112,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
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);
|
||||||
|
@ -124,21 +124,21 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -189,13 +189,13 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
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;
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -220,7 +220,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@ -246,12 +246,12 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
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;
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -295,7 +295,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch{} // just skip
|
catch { } // just skip
|
||||||
} // for properties
|
} // for properties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,12 +314,12 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
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;
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -363,7 +363,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch{} // just skip
|
catch { } // just skip
|
||||||
} // for properties
|
} // for properties
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -442,15 +442,19 @@ 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);
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!propertiesCache.ContainsKey(typeSource.Name))
|
||||||
|
{
|
||||||
// add to cache
|
// add to cache
|
||||||
propertiesCache.Add(typeSource.Name, props);
|
propertiesCache.Add(typeSource.Name, props);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Copy the data
|
// Copy the data
|
||||||
foreach (PropertyInfo propertyInfo in props.Values)
|
foreach (PropertyInfo propertyInfo in props.Values)
|
||||||
|
@ -481,16 +485,19 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!propertiesCache.ContainsKey(type.Name))
|
||||||
|
{
|
||||||
// add to cache
|
// add to cache
|
||||||
propertiesCache.Add(type.Name, props);
|
propertiesCache.Add(type.Name, props);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fill properties
|
// fill properties
|
||||||
foreach (string propName in propValues.Keys)
|
foreach (string propName in propValues.Keys)
|
||||||
|
@ -553,14 +560,19 @@ 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)
|
||||||
|
{
|
||||||
|
if (!hash.ContainsKey(prop.Name))
|
||||||
|
{
|
||||||
hash.Add(prop.Name, prop);
|
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);
|
||||||
|
@ -570,15 +582,15 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
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;
|
||||||
|
@ -586,17 +598,17 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
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(';');
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
//check running service
|
||||||
|
if (_isRuninng)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isRuninng = true;
|
||||||
Scheduler.Start();
|
Scheduler.Start();
|
||||||
|
_isRuninng = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue