public bool InsertMarks(MarksDTO marksdto)
{
XmlSerializer serializer = new XmlSerializer(typeof(MarksDTO));
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
try
{
serializer.Serialize(stream, marksdto);
stream.Position = 0;
doc.Load(stream);
ExaminationBranchDAO examDAO = new ExaminationBranchDAO();
return examDAO.InsertStudentMarks(doc.InnerXml);
}
catch
{
throw;
}
finally
{
stream.Close();
stream.Dispose();
}
}
public bool InsertStudentMarks(string MarksXML)
{
object[] parameters = { MarksXML };
try
{
Int32 n = Convert.ToInt32(db.ExecuteScalar("usp_add_student_marks", parameters));
if (n > 0)
{
return true;
}
}
catch (System.Data.DataException exception)
{
ErrorHandler.WriteError(exception.Message, exception);
}
return false;
}
I, Me, Myself
Search
Tuesday, July 12, 2011
Tuesday, June 7, 2011
Error File
public static void WriteError(string errorMessage, Exception objException)
{
try
{
string path = "~/ErrorLogs/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))
{
File.Create(System.Web.HttpContext.Current.Server.MapPath(path)).Close();
}
using (StreamWriter w = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(path)))
{
w.WriteLine("\r\n Error Logs : ");
string err = "An Unhandled Exception Occured in: " + System.Web.HttpContext.Current.Request.Url.ToString() + "\r\n" +
"\r\n Machine Name : " + Dns.GetHostName().ToString() + "\r\n" +
"\r\n Date : " + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "\r\n" +
"\r\n Method Name : " + objException.TargetSite.Name.ToString() + "\r\n" +
"\r\n Error Message : " + objException.Message.ToString().Trim() + "\r\n" +
"\r\n Stack Trace : " + objException.StackTrace.ToString().Trim();
w.WriteLine(err);
w.WriteLine("^^-------------------------------------------------------------------^^");
w.Flush();
w.Close();
}
}
catch (Exception ex)
{
WriteError(ex.Message, ex);
}
}
{
try
{
string path = "~/ErrorLogs/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))
{
File.Create(System.Web.HttpContext.Current.Server.MapPath(path)).Close();
}
using (StreamWriter w = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(path)))
{
w.WriteLine("\r\n Error Logs : ");
string err = "An Unhandled Exception Occured in: " + System.Web.HttpContext.Current.Request.Url.ToString() + "\r\n" +
"\r\n Machine Name : " + Dns.GetHostName().ToString() + "\r\n" +
"\r\n Date : " + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "\r\n" +
"\r\n Method Name : " + objException.TargetSite.Name.ToString() + "\r\n" +
"\r\n Error Message : " + objException.Message.ToString().Trim() + "\r\n" +
"\r\n Stack Trace : " + objException.StackTrace.ToString().Trim();
w.WriteLine(err);
w.WriteLine("^^-------------------------------------------------------------------^^");
w.Flush();
w.Close();
}
}
catch (Exception ex)
{
WriteError(ex.Message, ex);
}
}
Making serilization
Category cat1 = new Category();
cat1.Available = true;
cat1.CategoryCode = "CatCode1";
cat1.CategoryID = Guid.NewGuid();
cat1.IsProgramLevel = true;
cat1.ParentCategoryID = Guid.NewGuid();
cat1.StringID = Guid.NewGuid();
cat1.CategoryName = new LocalizationEntity();
cat1.CategoryName.LocalizedString = "Cat Name1";
cat1.CategoryName.LocalizedStringID = cat1.StringID;
cat1.CategoryName.PlatformLanguageID = Guid.NewGuid();
cat1.CategoryName.LocalizedStringID = Guid.NewGuid();
string xmldataCat = SerializationHelper.Serialize(typeof(Category), cat1);
SerializationHelper.SerializeBOData(typeof(Category), @"d:\testcat.xml",cat1);
Category catNew = (Category)SerializationHelper.DeSerialize(typeof(Category), xmldataCat);
Category catnewFile = (Category)SerializationHelper.DeserializeXml(typeof(Category), @"d:\testcat.xml");
//CIPAttribute attr1 = new CIPAttribute();
//CIPAttribute attr2 = new CIPAttribute();
//ca.Attributes.Add(attr1);
//ca.Attributes.Add(attr2);
//ca.CIPCategory = cat1;
// string xmlData = SerializationHelper.Serialize(typeof(CategoryAttribute), ca);
cat1.Available = true;
cat1.CategoryCode = "CatCode1";
cat1.CategoryID = Guid.NewGuid();
cat1.IsProgramLevel = true;
cat1.ParentCategoryID = Guid.NewGuid();
cat1.StringID = Guid.NewGuid();
cat1.CategoryName = new LocalizationEntity();
cat1.CategoryName.LocalizedString = "Cat Name1";
cat1.CategoryName.LocalizedStringID = cat1.StringID;
cat1.CategoryName.PlatformLanguageID = Guid.NewGuid();
cat1.CategoryName.LocalizedStringID = Guid.NewGuid();
string xmldataCat = SerializationHelper.Serialize(typeof(Category), cat1);
SerializationHelper.SerializeBOData(typeof(Category), @"d:\testcat.xml",cat1);
Category catNew = (Category)SerializationHelper.DeSerialize(typeof(Category), xmldataCat);
Category catnewFile = (Category)SerializationHelper.DeserializeXml(typeof(Category), @"d:\testcat.xml");
//CIPAttribute attr1 = new CIPAttribute();
//CIPAttribute attr2 = new CIPAttribute();
//ca.Attributes.Add(attr1);
//ca.Attributes.Add(attr2);
//ca.CIPCategory = cat1;
// string xmlData = SerializationHelper.Serialize(typeof(CategoryAttribute), ca);
Serilization
public class SerializationHelper
{
///
/// Method to Serialize Object
///
///
Object Entity Type
/// seralization object
///Inner XML Data
public static string Serialize(Type entityType, object seralizationObject)
{
string resultXML = string.Empty;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
try
{
XmlSerializer xmlSerializer = new XmlSerializer(entityType);
xmlSerializer.Serialize(stream, seralizationObject);
if (stream != null)
{
stream.Position = 0;
doc.Load(stream);
resultXML = doc.InnerXml;
}
}
catch
{
return string.Empty;
}
return resultXML;
}
///
/// Method to DeSerialize XMl to Object
///
/// Object Entity Type
/// Inner XML Data
///DeSerialized Object
public static object DeSerialize(Type entityType, string xmlData)
{
object result = null;
try
{
XmlSerializer xmlSerializer = new XmlSerializer(entityType);
using (TextReader tr = new StringReader(xmlData))
{
result = xmlSerializer.Deserialize(tr);
}
}
catch
{
return null;
}
return result;
}
public static void SerializeBOData(Type type, string xmlFile, object obj)
{
TextWriter textWriter = null;
try
{
XmlSerializer xmlSerializer = new XmlSerializer(type);
// Writing the file requires a StreamWriter.
textWriter = new StreamWriter(xmlFile);
// Serialize the BOData to xml.
if (textWriter != null)
{
xmlSerializer.Serialize(textWriter, obj);
}
}
catch (Exception ex)
{
// Log the exception.
}
finally
{
if (textWriter != null)
{
textWriter.Close();
}
}
}
public static object DeserializeXml(Type boDataType, string xmlFile)
{
TextReader textReader = null;
try
{
if (!System.IO.File.Exists(xmlFile))
{
return null;
}
XmlSerializer xmlSer = new XmlSerializer(boDataType);
// Read the XML.
textReader = new StreamReader(xmlFile);
// Cast the deserialized xml to the type of BOData.
return xmlSer.Deserialize(textReader);
}
catch (Exception ex)
{
// Propogate the exception.
}
finally
{
if (textReader != null)
{
textReader.Close();
textReader = null;
}
}
// Return the data transfer object.
return null;
}
}
{
///
/// Method to Serialize Object
///
///
Object Entity Type
/// seralization object
///
public static string Serialize(Type entityType, object seralizationObject)
{
string resultXML = string.Empty;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
try
{
XmlSerializer xmlSerializer = new XmlSerializer(entityType);
xmlSerializer.Serialize(stream, seralizationObject);
if (stream != null)
{
stream.Position = 0;
doc.Load(stream);
resultXML = doc.InnerXml;
}
}
catch
{
return string.Empty;
}
return resultXML;
}
///
/// Method to DeSerialize XMl to Object
///
/// Object Entity Type
/// Inner XML Data
///
public static object DeSerialize(Type entityType, string xmlData)
{
object result = null;
try
{
XmlSerializer xmlSerializer = new XmlSerializer(entityType);
using (TextReader tr = new StringReader(xmlData))
{
result = xmlSerializer.Deserialize(tr);
}
}
catch
{
return null;
}
return result;
}
public static void SerializeBOData(Type type, string xmlFile, object obj)
{
TextWriter textWriter = null;
try
{
XmlSerializer xmlSerializer = new XmlSerializer(type);
// Writing the file requires a StreamWriter.
textWriter = new StreamWriter(xmlFile);
// Serialize the BOData to xml.
if (textWriter != null)
{
xmlSerializer.Serialize(textWriter, obj);
}
}
catch (Exception ex)
{
// Log the exception.
}
finally
{
if (textWriter != null)
{
textWriter.Close();
}
}
}
public static object DeserializeXml(Type boDataType, string xmlFile)
{
TextReader textReader = null;
try
{
if (!System.IO.File.Exists(xmlFile))
{
return null;
}
XmlSerializer xmlSer = new XmlSerializer(boDataType);
// Read the XML.
textReader = new StreamReader(xmlFile);
// Cast the deserialized xml to the type of BOData.
return xmlSer.Deserialize(textReader);
}
catch (Exception ex)
{
// Propogate the exception.
}
finally
{
if (textReader != null)
{
textReader.Close();
textReader = null;
}
}
// Return the data transfer object.
return null;
}
}
XML Sqlquery
USE [CIPDB]
GO
/****** Object: StoredProcedure [dbo].[uspAddProgramCategory] Script Date: 02/08/2011 18:44:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[upsAddProgramCategory]
(
/* Serialized DataXML*/
@xmlData XML
)
AS
/* Try Statement Begins */
/*BEGIN TRY
BEGIN TRANSACTION */
/* This Insert Statement populates a CIPProgram Table*/
DECLARE @xmlPointer INT -- Pointer variable
EXEC sp_xml_preparedocument @xmlPointer OUTPUT,
@xmlData -- Get XML document into memory
DECLARE @ProgramID uniqueidentifier
DECLARE @CategoryID uniqueidentifier
DECLARE @err AS INT
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO dbo.LocalizationMaster
(
StringID
)
SELECT
StringID
FROM OPENXML (@xmlPointer,'/ProgramCategory',1)
WITH(StringID uniqueidentifier 'StringID')
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured',16,1)
RETURN @err
END
SELECT @ProgramID = ProgramID ,@CategoryID = CategoryID
FROM OPENXML (@xmlPointer,'/ProgramCategory',1)
WITH(
ProgramID uniqueidentifier 'ProgramID',
CategoryID uniqueidentifier 'CategoryAttribute/CategoryID'
)
Print '1'
INSERT INTO ProgramCategory
(
[ProgramID],
[CategoryID],
[StringID],
[DefaultLanguageID]
)
SELECT
ProgramID,
CategoryID,
StringID,
'cca5bd8d-172f-4687-9d58-607f0b235192'
FROM OPENXML (@xmlPointer,'/ProgramCategory',1)
WITH(
ProgramID uniqueidentifier 'ProgramID',
CategoryID uniqueidentifier 'CategoryAttribute/CategoryID',
StringID uniqueidentifier 'StringID'
)
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured while adding the Program',16,1)
RETURN @err
END
Print '2'
INSERT INTO LocalizedString
(
[LocalizedStringID],
[PlatformLanguageID],
[LocalizedString],
[StringID]
)
SELECT
LocalizedStringID,
PlatformLanguageID,
LocalizedString,
StringID
FROM OPENXML (@xmlPointer,'/ProgramCategory/ProgramCategoryName',1)
WITH(
LocalizedStringID uniqueidentifier 'LocalizedStringID',
PlatformLanguageID uniqueidentifier 'PlatformLanguageID',
StringID uniqueidentifier 'StringID',
LocalizedString varchar(max) 'LocalizedString'
)
Print '3'
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured while adding LocalizedString',16,1)
RETURN @err
END
SELECT
AttributeID,
StringID,
DefaultLanguageID,
Required,
LocalizedStringID,
PlatformLanguageID,
LocalizedString
INTO #AttributeDetails
FROM OPENXML (@xmlPointer,'/ProgramCategory/Attributes/Attribute',1)
WITH(
AttributeID uniqueidentifier 'AttributeID',
StringID uniqueidentifier 'StringID',
DefaultLanguageID uniqueidentifier 'DefaultLanguageID',
Required bit 'Available',
LocalizedStringID uniqueidentifier 'ProgramAttributeName/LocalizedStringID',
PlatformLanguageID uniqueidentifier 'ProgramAttributeName/PlatformLanguageID',
LocalizedString varchar(max) 'ProgramAttributeName/LocalizedString'
)
Print '4'
INSERT INTO dbo.LocalizationMaster
(
StringID
)
SELECT #AttributeDetails.StringID
FROM #AttributeDetails
Print '5'
select * from #AttributeDetails
SELECT
@ProgramID,
categoryAttribute.CategoryAttributeID,
--#AttributeDetails.ProgramCategoryAttributeID,
#AttributeDetails.Required,
#AttributeDetails.StringID
FROM #AttributeDetails , CategoryAttribute categoryAttribute
WHERE categoryAttribute.AttributeID = #AttributeDetails.AttributeID
AND categoryAttribute.CategoryID = @CategoryID
INSERT INTO ProgramCategoryAttribute(
ProgramID,
CategoryAttributeID,
Required,
StringID)
SELECT
@ProgramID,
categoryAttribute.CategoryAttributeID,
#AttributeDetails.Required,
#AttributeDetails.StringID
FROM #AttributeDetails , CategoryAttribute categoryAttribute
WHERE categoryAttribute.AttributeID = #AttributeDetails.AttributeID
AND categoryAttribute.CategoryID = @CategoryID
Print '6'
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured while adding to ProgramCategoryAttribute',16,1)
RETURN @err
END
Print '7'
INSERT INTO LocalizedString
(
[LocalizedStringID],
[PlatformLanguageID],
[LocalizedString],
[StringID]
)
SELECT
#AttributeDetails.LocalizedStringID,
#AttributeDetails.PlatformLanguageID,
#AttributeDetails.LocalizedString,
#AttributeDetails.StringID
FROM #AttributeDetails
Print '8'
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured while adding to ProgramCategoryAttribute',16,1)
RETURN @err
END
COMMIT TRANSACTION
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('Caught exception An error occured',16,1)
RETURN @err
END
END TRY
/* Catch Begins */
BEGIN CATCH
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('Caught exception An error occured',16,1)
RETURN @err
END
/* Catch Ends */
END CATCH
GO
/****** Object: StoredProcedure [dbo].[uspAddProgramCategory] Script Date: 02/08/2011 18:44:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[upsAddProgramCategory]
(
/* Serialized DataXML*/
@xmlData XML
)
AS
/* Try Statement Begins */
/*BEGIN TRY
BEGIN TRANSACTION */
/* This Insert Statement populates a CIPProgram Table*/
DECLARE @xmlPointer INT -- Pointer variable
EXEC sp_xml_preparedocument @xmlPointer OUTPUT,
@xmlData -- Get XML document into memory
DECLARE @ProgramID uniqueidentifier
DECLARE @CategoryID uniqueidentifier
DECLARE @err AS INT
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO dbo.LocalizationMaster
(
StringID
)
SELECT
StringID
FROM OPENXML (@xmlPointer,'/ProgramCategory',1)
WITH(StringID uniqueidentifier 'StringID')
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured',16,1)
RETURN @err
END
SELECT @ProgramID = ProgramID ,@CategoryID = CategoryID
FROM OPENXML (@xmlPointer,'/ProgramCategory',1)
WITH(
ProgramID uniqueidentifier 'ProgramID',
CategoryID uniqueidentifier 'CategoryAttribute/CategoryID'
)
Print '1'
INSERT INTO ProgramCategory
(
[ProgramID],
[CategoryID],
[StringID],
[DefaultLanguageID]
)
SELECT
ProgramID,
CategoryID,
StringID,
'cca5bd8d-172f-4687-9d58-607f0b235192'
FROM OPENXML (@xmlPointer,'/ProgramCategory',1)
WITH(
ProgramID uniqueidentifier 'ProgramID',
CategoryID uniqueidentifier 'CategoryAttribute/CategoryID',
StringID uniqueidentifier 'StringID'
)
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured while adding the Program',16,1)
RETURN @err
END
Print '2'
INSERT INTO LocalizedString
(
[LocalizedStringID],
[PlatformLanguageID],
[LocalizedString],
[StringID]
)
SELECT
LocalizedStringID,
PlatformLanguageID,
LocalizedString,
StringID
FROM OPENXML (@xmlPointer,'/ProgramCategory/ProgramCategoryName',1)
WITH(
LocalizedStringID uniqueidentifier 'LocalizedStringID',
PlatformLanguageID uniqueidentifier 'PlatformLanguageID',
StringID uniqueidentifier 'StringID',
LocalizedString varchar(max) 'LocalizedString'
)
Print '3'
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured while adding LocalizedString',16,1)
RETURN @err
END
SELECT
AttributeID,
StringID,
DefaultLanguageID,
Required,
LocalizedStringID,
PlatformLanguageID,
LocalizedString
INTO #AttributeDetails
FROM OPENXML (@xmlPointer,'/ProgramCategory/Attributes/Attribute',1)
WITH(
AttributeID uniqueidentifier 'AttributeID',
StringID uniqueidentifier 'StringID',
DefaultLanguageID uniqueidentifier 'DefaultLanguageID',
Required bit 'Available',
LocalizedStringID uniqueidentifier 'ProgramAttributeName/LocalizedStringID',
PlatformLanguageID uniqueidentifier 'ProgramAttributeName/PlatformLanguageID',
LocalizedString varchar(max) 'ProgramAttributeName/LocalizedString'
)
Print '4'
INSERT INTO dbo.LocalizationMaster
(
StringID
)
SELECT #AttributeDetails.StringID
FROM #AttributeDetails
Print '5'
select * from #AttributeDetails
SELECT
@ProgramID,
categoryAttribute.CategoryAttributeID,
--#AttributeDetails.ProgramCategoryAttributeID,
#AttributeDetails.Required,
#AttributeDetails.StringID
FROM #AttributeDetails , CategoryAttribute categoryAttribute
WHERE categoryAttribute.AttributeID = #AttributeDetails.AttributeID
AND categoryAttribute.CategoryID = @CategoryID
INSERT INTO ProgramCategoryAttribute(
ProgramID,
CategoryAttributeID,
Required,
StringID)
SELECT
@ProgramID,
categoryAttribute.CategoryAttributeID,
#AttributeDetails.Required,
#AttributeDetails.StringID
FROM #AttributeDetails , CategoryAttribute categoryAttribute
WHERE categoryAttribute.AttributeID = #AttributeDetails.AttributeID
AND categoryAttribute.CategoryID = @CategoryID
Print '6'
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured while adding to ProgramCategoryAttribute',16,1)
RETURN @err
END
Print '7'
INSERT INTO LocalizedString
(
[LocalizedStringID],
[PlatformLanguageID],
[LocalizedString],
[StringID]
)
SELECT
#AttributeDetails.LocalizedStringID,
#AttributeDetails.PlatformLanguageID,
#AttributeDetails.LocalizedString,
#AttributeDetails.StringID
FROM #AttributeDetails
Print '8'
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('An error occured while adding to ProgramCategoryAttribute',16,1)
RETURN @err
END
COMMIT TRANSACTION
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('Caught exception An error occured',16,1)
RETURN @err
END
END TRY
/* Catch Begins */
BEGIN CATCH
SELECT @err = @@error
IF @err <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ('Caught exception An error occured',16,1)
RETURN @err
END
/* Catch Ends */
END CATCH
Deployer Service
public class Deployer : IDeployer
{
public Deployer()
{
}
public bool Deploy(DeploymentManifest dto, BODataDeployInformation boDeployInfo, DeploymentComponentType deployComponentType)
{
bool status = false;
string logFilePath = System.IO.Path.Combine(boDeployInfo.ExecutableDirectory, Constants.CDF_ERROR_LOG_FILE);
if (logFilePath != string.Empty)
{
logFilePath = logFilePath.Replace(Constants.CDF_CLIENT_FOLDER_NAME, Constants.CDF_AGENT_FOLDER_NAME);
}
Logger.InitializeLogger(logFilePath);
switch (deployComponentType)
{
case DeploymentComponentType.Solution:
SolutionDeployer solutionDeployer = new SolutionDeployer(dto as Solution, boDeployInfo);
status = solutionDeployer.Deploy();
break;
case DeploymentComponentType.Site:
SiteDeployer siteDeployer = new SiteDeployer(dto as Site, boDeployInfo);
status = siteDeployer.Deploy();
break;
case DeploymentComponentType.SiteTemplate:
SiteTemplateDeployer siteTemplateDeployer = new SiteTemplateDeployer(dto as SiteTemplate, boDeployInfo);
status = siteTemplateDeployer.Deploy();
break;
case DeploymentComponentType.DeploymentManisfestList:
DeploymentManifestListDeployer listDeployer = new DeploymentManifestListDeployer(dto as DeploymentManifestList, boDeployInfo);
status = listDeployer.Deploy();
break;
case DeploymentComponentType.ListTemplate:
ListTemplateDeployer listTemplateDeployer = new ListTemplateDeployer(dto as ListTemplate, boDeployInfo);
status = listTemplateDeployer.Deploy();
break;
case DeploymentComponentType.ProfileProperty:
ProfilePropertyDeployer profilePropertyDeployer = new ProfilePropertyDeployer(dto as ProfileProperty);
status = profilePropertyDeployer.Deploy();
break;
case DeploymentComponentType.ManagedProperty:
ManagedMetadataPropertyDeployer managedPropertyDeployer = new ManagedMetadataPropertyDeployer(dto as ManagedProperty);
status = managedPropertyDeployer.Deploy();
break;
case DeploymentComponentType.StsAdmCommand:
ICommand commandStsAdm = CommandHandler.GetCommand(CommandType.StsAdmCommand, boDeployInfo);
status = commandStsAdm.Execute(dto as Microsoft.Spo.Cdf.BusinessObjects.StsAdmCommand);
break;
case DeploymentComponentType.PowerShellCommand:
ICommand commandPS = CommandHandler.GetCommand(CommandType.PowerShellCommand, boDeployInfo);
status = commandPS.Execute(dto as Microsoft.Spo.Cdf.BusinessObjects.PowerShellCommand);
break;
}
return status;
}
public bool UploadDeploymentBit(BODataDeployInformation boDeployInfo, DeployComponent component)
{
bool uploadBitStatus = true;
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
Logger.InitializeLogger(logFilePath);
BackupSPSite backupHandler = new BackupSPSite(boDeployInfo);
uploadBitStatus = backupHandler.UploadDeploymentBit(new DeployComponent(Constants.CDF_AGGREGATE_MANIFEST_XML,
string.Empty,
DeploymentComponentType.AggregateOperation));
return uploadBitStatus;
}
public bool UploadDeploymentBits(BODataDeployInformation boDeployInfo, DeploymentComponents components)
{
bool uploadBitStatus = true;
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
Logger.InitializeLogger(logFilePath);
BackupSPSite backupHandler = new BackupSPSite(boDeployInfo);
uploadBitStatus = backupHandler.UploadDeploymentBits(components);
return uploadBitStatus;
}
public bool DownloadDataBits(BODataDeployInformation deployInformation, DeployComponent component)
{
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
Logger.InitializeLogger(logFilePath);
IDataManager dataDownload = DeployDataManager.Create(DataOperationType.FarmDataOperation);
bool downloadBitsStatus = (bool)dataDownload.GetData(deployInformation, component);
return downloadBitsStatus;
}
public bool CreateSPTimerJob(BODataDeployInformation deployInfo)
{
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
Logger.InitializeLogger(logFilePath);
if (deployInfo.ExecutableDirectory != string.Empty)
{
deployInfo.ExecutableDirectory = agentPath; //setting Agent installed path
}
Assembly assembly = Assembly.Load(Constants.TIMERJOB_ASSEMBLY_NAME);
if (assembly == null)
{
throw new Exception(string.Format("Failed to load assembly '{0}'", Constants.TIMERJOB_ASSEMBLY_NAME));
}
System.Type type = assembly.GetType(Constants.TIMERJOB_TIMER_FULLYQUALIFIED_CLASS);
if (null == type)
{
throw new Exception(string.Format("Failed to load type '{0}'", Constants.TIMERJOB_TIMER_FULLYQUALIFIED_CLASS));
}
try
{
IDeploymentTimer deploymentTimer = Activator.CreateInstance(type) as IDeploymentTimer;
deploymentTimer.Create(deployInfo);
}
catch (Exception ex)
{
CDFException ex1 = new CDFException(ex.Message);
throw new FaultException(ex1);
Logger.WriteLog(ex, CDFEventType.Error, DeploymentComponentType.TimerJob);
}
finally
{
}
//SPTimerJob spTimerJob = new SPTimerJob();
//return spTimerJob.Create(deployInfo);
return true;
}
public void TranferCafPackageFile(CAFPackageFile packageFile)
{
try
{
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
if (packageFile.CDFExecutableDirectory != string.Empty)
{
packageFile.CDFExecutableDirectory = agentPath;
}
Logger.InitializeLogger(logFilePath);
string cabFilePath = packageFile.CDFRunDirectory;
string destinationFilePath = string.Empty;
if (!System.IO.Directory.Exists(packageFile.CDFRunDirectory))
System.IO.Directory.CreateDirectory(packageFile.CDFRunDirectory);
//constrct the CabFilePath in CDF RunDirectory and CR Number
if (packageFile.ChangeRequestNumber != string.Empty)
cabFilePath = System.IO.Path.Combine(cabFilePath, packageFile.ChangeRequestNumber);
// create output folder, if does not exist -- Change request number
if (!System.IO.Directory.Exists(cabFilePath))
System.IO.Directory.CreateDirectory(cabFilePath);
if (packageFile.CAFPackageName.Contains(Constants.CDF_AGGREGATE_MANIFEST_XML))
{
// create output folder, if does not exist -- Solution Artifacts
cabFilePath = System.IO.Path.Combine(cabFilePath, Constants.CDF_PACKAGE_FOLDER_NAME);
if (!System.IO.Directory.Exists(cabFilePath))
{
System.IO.Directory.CreateDirectory(cabFilePath);
}
}
destinationFilePath = cabFilePath;
// delete the CAB file if it is already exists
cabFilePath = System.IO.Path.Combine(cabFilePath, packageFile.CAFPackageName);
if (System.IO.File.Exists(cabFilePath))
{
System.IO.File.Delete(cabFilePath);
}
int chunkSize = 2048;
byte[] buffer = new byte[chunkSize];
using (System.IO.FileStream writeStream = new System.IO.FileStream(cabFilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
{
try
{
do
{
// read bytes from input stream
int bytesRead = packageFile.FileByteStream.Read(buffer, 0, chunkSize);
if (bytesRead == 0) break;
// write bytes to output stream
writeStream.Write(buffer, 0, bytesRead);
} while (true);
}
catch (Exception ex)
{
Logger.WriteLog(ex, CDFEventType.Error, DeploymentComponentType.CABFileTransfer);
}
finally
{
if (writeStream != null)
{
writeStream.Close();
}
}
}
if (packageFile.CAFPackageName == Constants.CAF_PACKAGE_NAME)
{
FileIO.ExtractUploadedPackagedFile(cabFilePath, destinationFilePath, packageFile.CDFExecutableDirectory);
}
//return true;
}
catch (Exception ex)
{
Logger.WriteLog(ex, CDFEventType.Error, DeploymentComponentType.CABFileTransfer);
//return false;
}
}
}
{
public Deployer()
{
}
public bool Deploy(DeploymentManifest dto, BODataDeployInformation boDeployInfo, DeploymentComponentType deployComponentType)
{
bool status = false;
string logFilePath = System.IO.Path.Combine(boDeployInfo.ExecutableDirectory, Constants.CDF_ERROR_LOG_FILE);
if (logFilePath != string.Empty)
{
logFilePath = logFilePath.Replace(Constants.CDF_CLIENT_FOLDER_NAME, Constants.CDF_AGENT_FOLDER_NAME);
}
Logger.InitializeLogger(logFilePath);
switch (deployComponentType)
{
case DeploymentComponentType.Solution:
SolutionDeployer solutionDeployer = new SolutionDeployer(dto as Solution, boDeployInfo);
status = solutionDeployer.Deploy();
break;
case DeploymentComponentType.Site:
SiteDeployer siteDeployer = new SiteDeployer(dto as Site, boDeployInfo);
status = siteDeployer.Deploy();
break;
case DeploymentComponentType.SiteTemplate:
SiteTemplateDeployer siteTemplateDeployer = new SiteTemplateDeployer(dto as SiteTemplate, boDeployInfo);
status = siteTemplateDeployer.Deploy();
break;
case DeploymentComponentType.DeploymentManisfestList:
DeploymentManifestListDeployer listDeployer = new DeploymentManifestListDeployer(dto as DeploymentManifestList, boDeployInfo);
status = listDeployer.Deploy();
break;
case DeploymentComponentType.ListTemplate:
ListTemplateDeployer listTemplateDeployer = new ListTemplateDeployer(dto as ListTemplate, boDeployInfo);
status = listTemplateDeployer.Deploy();
break;
case DeploymentComponentType.ProfileProperty:
ProfilePropertyDeployer profilePropertyDeployer = new ProfilePropertyDeployer(dto as ProfileProperty);
status = profilePropertyDeployer.Deploy();
break;
case DeploymentComponentType.ManagedProperty:
ManagedMetadataPropertyDeployer managedPropertyDeployer = new ManagedMetadataPropertyDeployer(dto as ManagedProperty);
status = managedPropertyDeployer.Deploy();
break;
case DeploymentComponentType.StsAdmCommand:
ICommand commandStsAdm = CommandHandler.GetCommand(CommandType.StsAdmCommand, boDeployInfo);
status = commandStsAdm.Execute(dto as Microsoft.Spo.Cdf.BusinessObjects.StsAdmCommand);
break;
case DeploymentComponentType.PowerShellCommand:
ICommand commandPS = CommandHandler.GetCommand(CommandType.PowerShellCommand, boDeployInfo);
status = commandPS.Execute(dto as Microsoft.Spo.Cdf.BusinessObjects.PowerShellCommand);
break;
}
return status;
}
public bool UploadDeploymentBit(BODataDeployInformation boDeployInfo, DeployComponent component)
{
bool uploadBitStatus = true;
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
Logger.InitializeLogger(logFilePath);
BackupSPSite backupHandler = new BackupSPSite(boDeployInfo);
uploadBitStatus = backupHandler.UploadDeploymentBit(new DeployComponent(Constants.CDF_AGGREGATE_MANIFEST_XML,
string.Empty,
DeploymentComponentType.AggregateOperation));
return uploadBitStatus;
}
public bool UploadDeploymentBits(BODataDeployInformation boDeployInfo, DeploymentComponents components)
{
bool uploadBitStatus = true;
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
Logger.InitializeLogger(logFilePath);
BackupSPSite backupHandler = new BackupSPSite(boDeployInfo);
uploadBitStatus = backupHandler.UploadDeploymentBits(components);
return uploadBitStatus;
}
public bool DownloadDataBits(BODataDeployInformation deployInformation, DeployComponent component)
{
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
Logger.InitializeLogger(logFilePath);
IDataManager dataDownload = DeployDataManager.Create(DataOperationType.FarmDataOperation);
bool downloadBitsStatus = (bool)dataDownload.GetData(deployInformation, component);
return downloadBitsStatus;
}
public bool CreateSPTimerJob(BODataDeployInformation deployInfo)
{
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
Logger.InitializeLogger(logFilePath);
if (deployInfo.ExecutableDirectory != string.Empty)
{
deployInfo.ExecutableDirectory = agentPath; //setting Agent installed path
}
Assembly assembly = Assembly.Load(Constants.TIMERJOB_ASSEMBLY_NAME);
if (assembly == null)
{
throw new Exception(string.Format("Failed to load assembly '{0}'", Constants.TIMERJOB_ASSEMBLY_NAME));
}
System.Type type = assembly.GetType(Constants.TIMERJOB_TIMER_FULLYQUALIFIED_CLASS);
if (null == type)
{
throw new Exception(string.Format("Failed to load type '{0}'", Constants.TIMERJOB_TIMER_FULLYQUALIFIED_CLASS));
}
try
{
IDeploymentTimer deploymentTimer = Activator.CreateInstance(type) as IDeploymentTimer;
deploymentTimer.Create(deployInfo);
}
catch (Exception ex)
{
CDFException ex1 = new CDFException(ex.Message);
throw new FaultException
Logger.WriteLog(ex, CDFEventType.Error, DeploymentComponentType.TimerJob);
}
finally
{
}
//SPTimerJob spTimerJob = new SPTimerJob();
//return spTimerJob.Create(deployInfo);
return true;
}
public void TranferCafPackageFile(CAFPackageFile packageFile)
{
try
{
String agentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
agentPath = System.IO.Path.GetDirectoryName(agentPath);
string logFilePath = System.IO.Path.Combine(agentPath, Constants.CDF_ERROR_LOG_FILE);
if (packageFile.CDFExecutableDirectory != string.Empty)
{
packageFile.CDFExecutableDirectory = agentPath;
}
Logger.InitializeLogger(logFilePath);
string cabFilePath = packageFile.CDFRunDirectory;
string destinationFilePath = string.Empty;
if (!System.IO.Directory.Exists(packageFile.CDFRunDirectory))
System.IO.Directory.CreateDirectory(packageFile.CDFRunDirectory);
//constrct the CabFilePath in CDF RunDirectory and CR Number
if (packageFile.ChangeRequestNumber != string.Empty)
cabFilePath = System.IO.Path.Combine(cabFilePath, packageFile.ChangeRequestNumber);
// create output folder, if does not exist -- Change request number
if (!System.IO.Directory.Exists(cabFilePath))
System.IO.Directory.CreateDirectory(cabFilePath);
if (packageFile.CAFPackageName.Contains(Constants.CDF_AGGREGATE_MANIFEST_XML))
{
// create output folder, if does not exist -- Solution Artifacts
cabFilePath = System.IO.Path.Combine(cabFilePath, Constants.CDF_PACKAGE_FOLDER_NAME);
if (!System.IO.Directory.Exists(cabFilePath))
{
System.IO.Directory.CreateDirectory(cabFilePath);
}
}
destinationFilePath = cabFilePath;
// delete the CAB file if it is already exists
cabFilePath = System.IO.Path.Combine(cabFilePath, packageFile.CAFPackageName);
if (System.IO.File.Exists(cabFilePath))
{
System.IO.File.Delete(cabFilePath);
}
int chunkSize = 2048;
byte[] buffer = new byte[chunkSize];
using (System.IO.FileStream writeStream = new System.IO.FileStream(cabFilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
{
try
{
do
{
// read bytes from input stream
int bytesRead = packageFile.FileByteStream.Read(buffer, 0, chunkSize);
if (bytesRead == 0) break;
// write bytes to output stream
writeStream.Write(buffer, 0, bytesRead);
} while (true);
}
catch (Exception ex)
{
Logger.WriteLog(ex, CDFEventType.Error, DeploymentComponentType.CABFileTransfer);
}
finally
{
if (writeStream != null)
{
writeStream.Close();
}
}
}
if (packageFile.CAFPackageName == Constants.CAF_PACKAGE_NAME)
{
FileIO.ExtractUploadedPackagedFile(cabFilePath, destinationFilePath, packageFile.CDFExecutableDirectory);
}
//return true;
}
catch (Exception ex)
{
Logger.WriteLog(ex, CDFEventType.Error, DeploymentComponentType.CABFileTransfer);
//return false;
}
}
}
Tuesday, April 19, 2011
Subscribe to:
Posts (Atom)