// Private Methods (1) private void RunRefreshAll() { LogMessage("Running Refresh All"); try { var workEngineApi = new WorkEngineAPI(); workEngineApi.Execute("Reporting_RefreshAll", string.Empty); } catch (Exception e) { LogMessage("\t", e.Message, 3); } }
private void GetReports() { XmlDocument doc = new XmlDocument(); using (var workEngineAPI = new WorkEngineAPI()) { doc.LoadXml(workEngineAPI.Execute("Reporting_GetAllReports", string.Empty)); } if (doc.FirstChild.Attributes["Status"].Value == "0") { try { XmlNode ndReports = doc.FirstChild.SelectSingleNode("//Data").FirstChild.SelectSingleNode("Folder[@Name='epmlivetl']").SelectSingleNode("Folder[@Name='Resources']"); StringBuilder sb = new StringBuilder(); foreach (XmlNode nd in ndReports.SelectNodes("Folder/Report")) { sb.Append("<Button"); sb.Append(" Id=\'Ribbon.BuildTeam.ToolsGroup.Reports.ShowReport"); //sb.Append(nd.Attributes["Name"].Value.Replace(" ","")); sb.Append("\' Command='Ribbon.BuildTeam.ShowReport\'"); sb.Append(" CommandValueId='"); sb.Append(System.Web.HttpUtility.UrlEncode(nd.Attributes["Url"].Value)); sb.Append("'"); sb.Append(" LabelText=\'"); sb.Append(nd.Attributes["Name"].Value); sb.Append("\'/>"); } output = sb.ToString(); } catch { } } else { output = "Error"; } }
/// <summary> /// Gets the layout. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public string GetLayout(string data) { try { XDocument layoutXml = XDocument.Parse(Resources.AssignmentPlannerGridLayout); if (layoutXml.Root == null) { throw new APIException((int)Errors.NoGridElementFound, "Cannot find the Grid element."); } XElement headerElement = layoutXml.Root.Element("Header"); if (headerElement == null) { throw new APIException((int)Errors.NoHeaderElementFound, "Cannot find the Header element."); } XElement colsElement = layoutXml.Root.Element("Cols"); if (colsElement == null) { throw new APIException((int)Errors.NoColsElementFound, "Cannot find the Cols element."); } string fieldsResponse; using (var workEngineAPI = new WorkEngineAPI()) { fieldsResponse = workEngineAPI.Execute("Reporting_GetMyWorkFields", string.Empty); } XElement errorElement = XDocument.Parse(fieldsResponse).Root.Descendants("Error").FirstOrDefault(); if (errorElement != null) { if (errorElement.Value.Contains("ExecuteReader requires an open and available Connection.")) { throw new APIException((int)Errors.ReportingConnection, ReportingConnectionError); } } XDocument dataXml = XDocument.Parse(Utilities.DecodeGridData(data)); RegisterGridIdAndCss(layoutXml.Root, dataXml); XDocument fieldsXml = XDocument.Parse(fieldsResponse); List <string> fields = fieldsXml.Root.Element("GetMyWorkFields").Element("Data").Elements("Field").Select( e => e.Attribute("Name").Value).ToList(); using (var spSite = new SPSite(_spWeb.Site.ID)) { using (SPWeb spWeb = spSite.OpenWeb()) { SPList spList = spWeb.Lists["My Work"]; SPRegionalSettings regionalSettings = spWeb.RegionalSettings; SPRegionalSettings spRegionalSettings = _spWeb.CurrentUser.RegionalSettings ?? regionalSettings; var cultureInfo = new CultureInfo((int)spRegionalSettings.LocaleId); string currencyFormat = string.Format("{0}#.00", cultureInfo.NumberFormat.CurrencySymbol); string datePattern = cultureInfo.DateTimeFormat.ShortDatePattern; var defaultColumns = new List <string>(); var workDayStartHour = (short)(regionalSettings.WorkDayStartHour / 60); var workDayEndHour = (short)(regionalSettings.WorkDayEndHour / 60); ConfigureDefaultColumns(spList, datePattern, currencyFormat, spWeb, workDayStartHour, workDayEndHour, GetGanttExclude(regionalSettings, spWeb, workDayStartHour, workDayEndHour), ref layoutXml, ref defaultColumns); ConfigureColumns(spWeb, currencyFormat, ref headerElement, ref colsElement, datePattern, defaultColumns, fields, spList); } } return(layoutXml.ToString()); } catch (APIException) { throw; } catch (Exception e) { throw new APIException((int)Errors.GetLayout, e.Message); } }
/// <summary> /// Gets the data. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public string GetData(string data) { try { string response; NumberFormatInfo providerEn = new System.Globalization.NumberFormatInfo(); providerEn.NumberDecimalSeparator = "."; providerEn.NumberGroupSeparator = ","; providerEn.NumberGroupSizes = new int[] { 3 }; XElement dataRootElement = XDocument.Parse(data).Root; if (dataRootElement == null) { throw new APIException((int)Errors.GetDataRootElementNotFound, "Cannot find the Root AssignmentPlanner element."); } using (var workEngineAPI = new WorkEngineAPI()) { response = workEngineAPI.Execute("Reporting_GetMyWorkData", new XElement("GetMyWorkReportingData", dataRootElement.Element("Params")).ToString()); } XDocument myWorkDataXml = XDocument.Parse(response); ValidateMyWorkDataResponse(myWorkDataXml); var gridSafeFields = new Dictionary <string, string>(); var bElement = new XElement("B"); var resourcesElement = new XElement("Resources"); var footElement = new XElement("Foot"); var resources = new Dictionary <int, string>(); SPRegionalSettings spRegionalSettings = _spWeb.CurrentUser.RegionalSettings ?? _spWeb.Site.RootWeb.RegionalSettings; var workDayStartHour = (short)(spRegionalSettings.WorkDayStartHour / 60); var workDayEndHour = (short)(spRegionalSettings.WorkDayEndHour / 60); string siteUrl = _spWeb.Site.Url; string safeServerRelativeUrl = _spWeb.SafeServerRelativeUrl(); foreach ( XElement resourceElement in myWorkDataXml.Element("Result").Element("GetMyWorkData").Element("Data").Elements("Resource")) { XElement resultElement = resourceElement.Element("Result"); if (!resultElement.Attribute("Status").Value.Equals("0")) { continue; } int resourceId = 0; string resourceName = string.Empty; foreach (XElement itemElement in resourceElement.Element("Data").Elements("Item")) { var iElement = new XElement("I"); int itemId = 0; Guid listId = Guid.Empty; Guid webId = Guid.Empty; Guid siteId = Guid.Empty; string value = string.Empty; float floatFieldValue; foreach (XElement fieldElement in itemElement.Elements("Field")) { string field = fieldElement.Attribute("Name").Value; if (!gridSafeFields.ContainsKey(field)) { gridSafeFields.Add(field, Utils.ToGridSafeFieldName(field)); } if (float.TryParse(fieldElement.Value.ToString(), out floatFieldValue)) { value = floatFieldValue.ToString(providerEn); } else { value = fieldElement.Value; } string fieldName = field.ToLower(); if (fieldName.Equals("id")) { itemId = Convert.ToInt32(value); } else if (fieldName.Equals("listid")) { listId = new Guid(value); } else if (fieldName.Equals("webid")) { webId = new Guid(value); } else if (fieldName.Equals("siteid")) { siteId = new Guid(value); } else if (fieldName.Equals("assignedtoid")) { resourceId = Convert.ToInt32(value); } else if (fieldName.Equals("assignedtotext")) { resourceName = value; } else if (fieldElement.Attribute("Type").Value.Equals("System.DateTime") && !string.IsNullOrEmpty(value)) { DateTime localTime = SPUtility.CreateDateTimeFromISO8601DateTimeString(value); if (fieldName.Equals("startdate") && (localTime.Hour < workDayStartHour || localTime.Hour > workDayEndHour)) { localTime = new DateTime(localTime.Year, localTime.Month, localTime.Day, workDayStartHour, 0, 0); } else if (fieldName.Equals("duedate") && (localTime.Hour < workDayStartHour || localTime.Hour > workDayEndHour)) { localTime = new DateTime(localTime.Year, localTime.Month, localTime.Day, workDayEndHour, 0, 0); } value = SPUtility.CreateISO8601DateTimeFromSystemDateTime(localTime); } iElement.Add(new XAttribute(gridSafeFields[field], value)); } string flagQuery = string.Format( @"<MyPersonalization> <Keys>AssignmentPlannerFlag</Keys> <Item ID=""{0}""/> <List ID=""{1}""/> <Web ID=""{2}""/> <Site ID=""{3}"" URL=""{4}""/> </MyPersonalization>", itemId, listId, webId, siteId, siteUrl); XDocument flagResponse = XDocument.Parse(MyPersonalization.GetMyPersonalization(flagQuery)); string flag = null; XElement personalizationRootElement = flagResponse.Element("MyPersonalization"); if (personalizationRootElement != null) { flag = (from e in personalizationRootElement.Descendants("Personalization") let keyAttribute = e.Attribute("Key") where keyAttribute != null && keyAttribute.Value.Equals("AssignmentPlannerFlag") let valueAttribute = e.Attribute("Value") where valueAttribute != null select valueAttribute.Value).FirstOrDefault(); } var flagValue = flag ?? "0"; var flagUrl = safeServerRelativeUrl + "/_layouts/epmlive/images/mywork/flagged.png"; if (flagValue.Equals("0")) { flagUrl = safeServerRelativeUrl + "/_layouts/epmlive/images/mywork/unflagged.png"; } iElement.Add(new XAttribute("Duration", string.Empty), new XAttribute("Flag", string.Format(@"<img src=""{0}"" class=""AP_Flag""/>", flagUrl)), new XAttribute("FlagValue", flagValue), new XAttribute("Height", 23)); if (resourceId == 0 || string.IsNullOrEmpty(resourceName)) { continue; } bElement.Add(iElement); if (!resources.ContainsKey(resourceId)) { resources.Add(resourceId, resourceName); } } } foreach (var keyValuePair in resources) { resourcesElement.Add(new XElement("R", new XAttribute("Name", keyValuePair.Value), new XAttribute("Availability", 8), new XAttribute("Type", 1))); footElement.Add(new XElement("I", new XAttribute("id", string.Format("-{0}", keyValuePair.Key)), new XAttribute("Def", "Resource"), new XAttribute("Title", keyValuePair.Value))); } return(new XElement("Grid", new XElement("Body", bElement), resourcesElement, footElement).ToString()); } catch (APIException) { throw; } catch (Exception e) { throw new APIException((int)Errors.GetData, e.Message); } }