Please find character in bold with login below.
public void PrintByMetricsAMFGroupThread(object stateInfo)
{
bool IsGroupThreadError = false;
try
{
slideIndex = 0;
string ReportName = string.Format(@“Metrics Research Group.pptx”);
string ReportTemplatePath = string.Empty;
string ReportTemplateName = string.Empty;
string FolderPath = “Areas/BenchmarkAdmin/Common/”;
string subPath = currentLoginUser;
string PresentationSavePath = SharedPathForPPT + subPath + “/” + ReportName;
string MasterTemplatePath = Path.Combine(HttpRuntime.AppDomainAppPath, FolderPath + “DS_MetricsResearchMaster.pptx”);
TableOfContents = new DataTable();
TableOfContents.Columns.Add("MetricName", typeof(string));
TableOfContents.Columns.Add("AMFType", typeof(string));
TableOfContents.Columns.Add("SlideNumber", typeof(int));
ReportTemplateName = "DS_MetricsResearch.pptx";
ReportTemplatePath = Path.Combine(HttpRuntime.AppDomainAppPath, FolderPath + ReportTemplateName);
Presentation MasterTemplate = new Presentation(MasterTemplatePath);
Presentation Pres = new Presentation(ReportTemplatePath);
LicenseFile licenseFile = new LicenseFile();
licenseFile.AssignLicense();
Contacts contact = _metricResearchDataStore.GetContactDetailsFromProfileId(currentLoginUser);
string company_name = _metricResearchDataStore.GetCompanyNameFromAccountId(contact.AccountId);
#region Title Slide (0)
string PrimarySetName, SecondaryPeerSetName;
if (printIsPeerSet == 0)
{
PrimarySetName = _peerSetDataStore.GetPeerSetByPeerSetId(Convert.ToInt64(printPrimaryPeerset)).PeerSet;
}
else
{
PrimarySetName = _responseSetDataStore.GetResponseSetByResponseSetId(Convert.ToInt64(printPrimaryPeerset)).ServiceResponseID;
}
if (Convert.ToInt64(printSecondaryPeerset) != 0)
{
if (printIsSecondaryPeerSet == 0)
{
SecondaryPeerSetName = _peerSetDataStore.GetPeerSetByPeerSetId(Convert.ToInt64(printSecondaryPeerset)).PeerSet;
}
else
{
SecondaryPeerSetName = _responseSetDataStore.GetResponseSetByResponseSetId(Convert.ToInt64(printSecondaryPeerset)).ServiceResponseID;
}
}
else
{
SecondaryPeerSetName = "";
}
//SecondaryPeerSetName = Convert.ToInt64(printSecondaryPeerset) == 0 ? "" : _peerSetDataStore.GetPeerSetByPeerSetId(Convert.ToInt64(printSecondaryPeerset)).PeerSet;
Pres = GetFirstSlide(MasterTemplate, Pres, PrimarySetName, SecondaryPeerSetName, contact);
#endregion
#region Get all metrics to print
List<MetricsResearchMetricsViewModel> lstMetric = new List<MetricsResearchMetricsViewModel>();
if (PrintIsfavourite)
{
lstMetric = _metricResearchDataStore.GetFavouriteMetrics();
}
else
{
if (PrintSelectedColor == "ALL")
lstMetric = _metricResearchDataStore.GetMetricsByMetricAMF(PrintFunctionId, PrintRoleId, PrintPrioritiesId, PrintModuleId, printMetric, null);
else
lstMetric = _metricResearchDataStore.GetMetricsBasedonFilter(PrintFunctionId, PrintRoleId, PrintPrioritiesId, PrintModuleId, printMetric, null, null, (int?)(Convert.ToInt16(printPrimaryPeerset)), (int?)printIsPeerSet, (int?)printIsSecondaryPeerSet, (int?)(Convert.ToInt16(printSecondaryPeerset)), PrintSelectedColor);
}
DataSet ds = new DataSet();
lstMetric = lstMetric.OrderBy(i => i.MetricAMF == "Readiness").
ThenBy(i => i.MetricAMF == "Activity").
ThenBy(i => i.MetricAMF == "Output").
ThenBy(i => i.MetricAMF == "Impact")
.ToList();
// foreach (MetricsResearchMetricsViewModel metric in lstMetric)
for (int metric = 0; metric < lstMetric.Count(); metric++)
{
try
{
if ((lstMetric[metric].MetricType.ToLower() == "numeric ranges - single column" || lstMetric[metric].MetricType.ToLower() == "numeric ranges - grid" || lstMetric[metric].MetricType.ToLower() == "maturity scale - single column") && ((printIsPeerSet == 1 && printIsSecondaryPeerSet == 1) || (printIsPeerSet == 1 && printIsSecondaryPeerSet == 0 && printSecondaryPeerset == "0")))
{
lstMetric[metric].ChartType = "line";
}
// Author : Ghanshyam Gandhi
// Date : 13/02/2018
// Desc : If Chart Type is Box and Whisker than change chart type as Grid and use Second Priority Chart type
//Start
if (lstMetric[metric].ChartType.ToLower() == "boxandwhiskers")
{
lstMetric[metric].ChartType = lstMetric[metric].SChartType;
lstMetric[metric].MetricType = "grid";
}
//END
PrintIncludeMetrics = true;
if (PrintSelectedColor != "ALL" ? (PrintfilteredMetricIds != null ? PrintfilteredMetricIds.Contains(" " + lstMetric[metric].MetricId + " ") : false) : true)
{
#region Chart Slide (1) and Table Slide (2)
TableOfContents.Rows.Add(lstMetric[metric].Metric, lstMetric[metric].MetricAMF, slideIndex);
TableId++;
if (lstMetric[metric].MetricType.ToLower() == "grid" || lstMetric[metric].MetricType.ToLower() == "numeric ranges - single column" || lstMetric[metric].MetricType.ToLower() == "numeric ranges - grid")
{
vmColumnsAndRows columnsAndRows = BindColumnsAndRowsForReport(lstMetric[metric].MetricId);
Pres = generateChartForReport(printPrimaryPeerset, printSecondaryPeerset, printIsPeerSet, printIsSecondaryPeerSet, lstMetric[metric], MasterTemplate, Pres, "Group", contact, company_name, PrimarySetName, SecondaryPeerSetName, columnsAndRows, PrintSelectedColor);
}
else
{
vmColumnsAndRows columnsAndRows = BindColumnsAndRowsForReport(lstMetric[metric].MetricId);
if ((columnsAndRows.Columns != null || columnsAndRows.Rows != null) && (lstMetric[metric].MetricType.ToLower() == "list - single select" || lstMetric[metric].MetricType.ToLower() == "h-list - open response"))
{
Pres = generateChartForReport(printPrimaryPeerset, printSecondaryPeerset, printIsPeerSet, printIsSecondaryPeerSet, lstMetric[metric], MasterTemplate, Pres, "Group", contact, company_name, PrimarySetName, SecondaryPeerSetName, columnsAndRows, PrintSelectedColor);
}
else
{
Pres = generateChartForReport(printPrimaryPeerset, printSecondaryPeerset, printIsPeerSet, printIsSecondaryPeerSet, lstMetric[metric], MasterTemplate, Pres, "Group", contact, company_name, PrimarySetName, SecondaryPeerSetName, null, PrintSelectedColor);
}
}
if (!PrintIncludeMetrics)
{
TableOfContents.Rows.RemoveAt(TableOfContents.Rows.Count - 1);
continue;
}
#endregion
#region Research Related Slide (last)
Pres = generateResearchTable(printPrimaryPeerset, printSecondaryPeerset, printIsPeerSet, lstMetric[metric], MasterTemplate, Pres, contact, company_name, PrimarySetName, SecondaryPeerSetName);
#endregion
}
}
catch (Exception e)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(e);
}
}
#endregion
#region Table Of Contents
int max = 0;
max = TableOfContents.Select("AMFType = 'Impact'").Count() > max ? TableOfContents.Select("AMFType = 'Impact'").Count() : max;
max = TableOfContents.Select("AMFType = 'Output'").Count() > max ? TableOfContents.Select("AMFType = 'Output'").Count() : max;
max = TableOfContents.Select("AMFType = 'Activity'").Count() > max ? TableOfContents.Select("AMFType = 'Activity'").Count() : max;
max = TableOfContents.Select("AMFType = 'Readiness'").Count() > max ? TableOfContents.Select("AMFType = 'Readiness'").Count() : max;
int rowCountInSlide = 0;
ISlide TempSlide, IndexSlide;
ISlideCollection slds = Pres.Slides;
IShape shape;
ITable table;
IHyperlinkManager hyperLinkMgr;
rowCountInSlide = 14;
IndexSlide = MasterTemplate.Slides[1];
double TableOfContentSlides = Math.Ceiling(Convert.ToDouble(max) / rowCountInSlide);
int RemoveRows = max % rowCountInSlide == 0 && max > 0 ? 13 : (max % rowCountInSlide) + 1;
int count = 0;
string str;
int index;
int outcolIndex = 0, actcolIndex = 0, readcolIndex = 0;
//Impact
for (int i = 1; i <= TableOfContentSlides; i++)
{
slds.InsertClone(i, IndexSlide);
TempSlide = Pres.Slides[i];
shape = FindShape(TempSlide, "Tableofcontents");
if (shape != null)
{
table = (ITable)shape;
//Add Elements in Table of Contents
for (int j = 1; j <= rowCountInSlide && count < max; j++)
{
if (count >= TableOfContents.Select("AMFType = 'Impact'").Count() || TableOfContents.Select("AMFType = 'Impact'").Count() == 0)
{
table[0, j].TextFrame.Text = " ";
}
else
{
table[0, j].TextFrame.Text = TableOfContents.Select("AMFType = 'Impact'").ElementAt(count)["MetricName"].ToString();
hyperLinkMgr = table[0, j].TextFrame.Paragraphs[0].Portions[0].PortionFormat.HyperlinkManager;
index = Convert.ToInt16(TableOfContents.Select("AMFType = 'Impact'").ElementAt(count)["SlideNumber"]) + i;
hyperLinkMgr.SetInternalHyperlinkClick(Pres.Slides[index]);
}
//output
if (j == 1)
{
if (table[0, 1].TextFrame.Text == " " || table[0, 1].TextFrame.Text.ElementAt(0) == '<')
outcolIndex = 0;
else
outcolIndex = 1;
//Add Elements in Table of Contents
table[outcolIndex, 0].TextFrame.Text = "Output";
}
if (count >= TableOfContents.Select("AMFType = 'Output'").Count() || TableOfContents.Select("AMFType = 'Output'").Count() == 0)
{
table[outcolIndex, j].TextFrame.Text = " ";
}
else
{
table[outcolIndex, j].TextFrame.Text = TableOfContents.Select("AMFType = 'Output'").ElementAt(count)["MetricName"].ToString();
hyperLinkMgr = table[outcolIndex, j].TextFrame.Paragraphs[0].Portions[0].PortionFormat.HyperlinkManager;
index = Convert.ToInt16(TableOfContents.Select("AMFType = 'Output'").ElementAt(count)["SlideNumber"]) + Convert.ToInt16(TableOfContentSlides);
hyperLinkMgr.SetInternalHyperlinkClick(Pres.Slides[index]);
}
//Activities
if (j == 1)
{
for (int c = 0; c < 2; c++)
{
if (table[c, 1].TextFrame.Text == " " || table[c, 1].TextFrame.Text.ElementAt(0) == '<')
{
actcolIndex = c;
break;
}
else
actcolIndex = 2;
}
//Add Elements in Table of Contents
table[actcolIndex, 0].TextFrame.Text = "Activity";
}
if (count >= TableOfContents.Select("AMFType = 'Activity'").Count() || TableOfContents.Select("AMFType = 'Activity'").Count() == 0)
{
table[actcolIndex, j].TextFrame.Text = " ";
}
else
{
table[actcolIndex, j].TextFrame.Text = TableOfContents.Select("AMFType = 'Activity'").ElementAt(count)["MetricName"].ToString();
hyperLinkMgr = table[actcolIndex, j].TextFrame.Paragraphs[0].Portions[0].PortionFormat.HyperlinkManager;
index = Convert.ToInt16(TableOfContents.Select("AMFType = 'Activity'").ElementAt(count)["SlideNumber"]) + Convert.ToInt16(TableOfContentSlides);
hyperLinkMgr.SetInternalHyperlinkClick(Pres.Slides[index]);
}
//Readiness
if (j == 1)
{
for (int c = 0; c < 3; c++)
{
if (table[c, 1].TextFrame.Text == " " || table[c, 1].TextFrame.Text.ElementAt(0) == '<')
{
readcolIndex = c;
break;
}
else
readcolIndex = 3;
}
}
if (count >= TableOfContents.Select("AMFType = 'Readiness'").Count() || TableOfContents.Select("AMFType = 'Readiness'").Count() == 0)
{
table[readcolIndex, j].TextFrame.Text = " ";
}
else
{
table[readcolIndex, j].TextFrame.Text = TableOfContents.Select("AMFType = 'Readiness'").ElementAt(count)["MetricName"].ToString();
hyperLinkMgr = table[readcolIndex, j].TextFrame.Paragraphs[0].Portions[0].PortionFormat.HyperlinkManager;
index = Convert.ToInt16(TableOfContents.Select("AMFType = 'Readiness'").ElementAt(count)["SlideNumber"]) + Convert.ToInt16(TableOfContentSlides);
hyperLinkMgr.SetInternalHyperlinkClick(Pres.Slides[index]);
}
count++;
}
//remove extra rows in last table of content slide
if (i == TableOfContentSlides)
{
for (int j = rowCountInSlide; j >= RemoveRows; j--)
{
table.Rows.RemoveAt(j, true);
}
}
}
//Remove Continued in first Table of Contents Slide Header
if (i == 1)
{
shape = FindShape(TempSlide, "Header");
if (shape != null)
{
str = ((IAutoShape)shape).TextFrame.Text;
str = str.Replace("<continued>", "");
((IAutoShape)shape).TextFrame.Text = str;
}
}
//last part
shape = FindShape(TempSlide, "Tableofcontents");
if (shape != null)
{
table = (ITable)shape;
for (int j = 3; j >= 0; j--)
{
if (table[j, 1].TextFrame.Text == " " || table[j, 1].TextFrame.Text.ElementAt(0) == '<')
table.Columns.RemoveAt(j, true);
}
if (table.Columns.Count == 1)
{
if (table.Columns[0] != null)
{
table.Columns[0].Width = 34 * 2 * 10;
}
}
else if (table.Columns.Count == 2)
{
table.Columns[0].Width = 34 * 10;
table.Columns[1].Width = 34 * 10;
}
else if (table.Columns.Count == 3)
{
table.Columns[0].Width = 22 * 10;
table.Columns[1].Width = 22 * 10;
table.Columns[2].Width = 22 * 10;
}
}
}
#endregion
#region Master Slide Update
Pres = UpdateMasterSlide(Pres);
#endregion
#region Save Report
TempData["ReportName"] = ReportName;
//Get a reference to the directory
CloudFileDirectory profileDir = GetCloudAccess(subPath);
//Get a reference to the PPT file
CloudFile file = profileDir.GetFileReference(ReportName);
//MemoryTributary ms = new MemoryTributary();
//Save ppt in memory stream
**MemoryStream ms = new MemoryStream();**
** Pres.Save(ms, Aspose.Slides.Export.SaveFormat.Pptx);**
//Set poistion to 0 in memory stream
ms.Position = 0;
//Uplode stream to Azure file storage
file.UploadFromStream(ms);
//Close memory stream and releases resources
ms.Close();
//Set value to true
isFileUploadOnAzure = true;
#endregion
}
catch (Exception ex)
{
Sitecore.Diagnostics.Log.Error("ChiragDekavadiya:" + ex, this);
// Check Exception type and accordingly update flag in database
if (ex.InnerException != null)
{
if (ex.InnerException.Message == "Thread was being aborted.")
IsGroupThreadError = true;
else
IsGroupThreadError = false;
}
else
{
if (ex.Message == "Thread was being aborted.")
IsGroupThreadError = true;
else
IsGroupThreadError = false;
}
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
finally
{
//update end status of print
if (IsGroupThreadError)
_metricResearchDataStore.UpdatePrintStatus(currentLoginUser, "GroupPrint", "false", null, 1);
else
_metricResearchDataStore.UpdatePrintStatus(currentLoginUser, "GroupPrint", "false", null, 0);
}
}