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