/// <summary> /// Gets called in regular intervals from a Timer in Class TTimedProcessing. /// </summary> /// <param name="ADBAccessObj">Instantiated DB Access object with opened DB connection.</param> /// <param name="ARunManually">this is true if the process was called manually from the server admin console</param> public static void Process(TDataBase ADBAccessObj, bool ARunManually) { // only check once a day (or as specified in config file), if not manually called if (!ARunManually) { DateTime LastRun = TVariant.DecodeFromString( TSystemDefaults.GetSystemDefault( PROCESSDATACHECK_LAST_RUN, new TVariant(DateTime.MinValue).EncodeToString())).ToDate(); if (LastRun.AddDays(TAppSettingsManager.GetInt16("DataChecks.RunEveryXDays", 1)) > DateTime.Now) { // do not run the data check more than once a day or a week (depending on configuration setting), too many emails TLogging.LogAtLevel(1, "TProcessDataChecks.Process: not running, since last run was at " + LastRun.ToString()); return; } } Errors_SinceDate = DateTime.Today.AddDays(-1 * SENDREPORTFORDAYS_TOUSERS); TLogging.LogAtLevel(1, "TProcessDataChecks.Process: Checking Modules"); CheckModule(ADBAccessObj, "DataCheck.MPartner."); TSystemDefaults.SetSystemDefault(PROCESSDATACHECK_LAST_RUN, new TVariant(DateTime.Now).EncodeToString()); }
/// <summary> /// get a session variable, not decoded yet /// </summary> /// <param name="name"></param> /// <returns></returns> public static TVariant GetVariant(string name) { if ((FSessionValues != null) && FSessionValues.Keys.Contains(name)) { return(TVariant.DecodeFromString(FSessionValues[name])); } return(new TVariant((object)null)); }
/// <summary> /// get a session variable /// </summary> /// <param name="name"></param> /// <returns></returns> public static object GetVariable(string name) { if ((FSessionValues != null) && FSessionValues.Keys.Contains(name)) { return(TVariant.DecodeFromString(FSessionValues[name]).ToObject()); } return(null); }
/// <summary> /// Read the parameters from a text file (xml format); /// used for loading settings /// </summary> /// <param name="filename">relative or absolute filename /// </param> /// <returns>void</returns> public void Load(String filename) { XmlNode startNode; XmlNode node; TXMLParser myDoc; String level; String column; int levelNr; int columnNr; int subreport; myDoc = new TXMLParser(filename, false); try { startNode = myDoc.GetDocument().DocumentElement; if (startNode.Name.ToLower() == "parameters") { node = startNode.FirstChild; while (node != null) { if (node.Name == "Parameter") { column = TXMLParser.GetAttribute(node, "column"); level = TXMLParser.GetAttribute(node, "level"); subreport = TXMLParser.GetIntAttribute(node, "subreport"); columnNr = -1; levelNr = -1; if (column.Length != 0) { columnNr = (int)StringHelper.StrToInt(column); } if (level.Length != 0) { levelNr = (int)StringHelper.StrToInt(level); } Add(TXMLParser.GetAttribute(node, "id"), TVariant.DecodeFromString(TXMLParser.GetAttribute(node, "value")), columnNr, levelNr, subreport); } node = node.NextSibling; } } } catch (Exception E) { throw new Exception(E.Message); } }
/// <summary> /// For development and testing purposes this Method can either execute actions that /// are set up by the program 'PetraMultiStart' (indicated by 'RunAutoTests=true' on /// the command line) OR open a screen with parameters that /// come either from the .config file or Command Line (indicated by 'TestAction="xxx"'). /// The 'Test Action' will not be run if the Control Key is pressed. /// </summary> /// <remarks> /// sample action: TestAction="Namespace=Ict.Petra.Client.MPartner.Gui,ActionOpenScreen=TFrmPartnerEdit2,PartnerKey=0043005002,InitiallySelectedTabPage=petpDetails" ///</remarks> private void RunTestAction() { string DisconnectTimeFromCommandLine = TAppSettingsManager.GetValue("DisconnectTime"); #if TODORemoting if (TAppSettingsManager.GetBoolean("RunAutoTests", false) == true) { // We need to manually 'fix up' the value of DisconnectTime that we get from .NET when we request // the commandline parameters as an array because .NET removes quotation marks in two places where // they were present on the command line. Those two quotation marks need to be there as the call to // TVariant.DecodeFromString() will not succeed if they aren't there in their proper places! DisconnectTimeFromCommandLine = DisconnectTimeFromCommandLine.Substring( 0, DisconnectTimeFromCommandLine.IndexOf(':') + 1) + "\"" + DisconnectTimeFromCommandLine.Substring( DisconnectTimeFromCommandLine.IndexOf(':') + 1) + "\""; TestRunner = new PetraClient_AutomatedAppTest.TAutomatedAppTest( TAppSettingsManager.GetValue("AutoTestConfigFile"), TAppSettingsManager.GetValue("AutoTestParameters"), TVariant.DecodeFromString(DisconnectTimeFromCommandLine).ToDate(), TConnectionManagementBase.GConnectionManagement.ClientName); TestRunner.TestForm = this; TestRunner.ClientID = TConnectionManagementBase.GConnectionManagement.ClientID; TestRunner.Start(this); } else #endif if (System.Windows.Forms.Form.ModifierKeys != Keys.Control) { string testAction = TAppSettingsManager.GetValue("TestAction", false); if (testAction != TAppSettingsManager.UNDEFINEDVALUE) { XmlDocument temp = new XmlDocument(); XmlNode testActionNode = temp.CreateElement("testAction"); temp.AppendChild(testActionNode); testAction = testAction.Trim(new char[] { '"' }); while (testAction.Length > 0) { string[] pair = StringHelper.GetNextCSV(ref testAction, ",").Split(new char[] { '=' }); XmlAttribute attr = temp.CreateAttribute(pair[0]); attr.Value = pair[1]; testActionNode.Attributes.Append(attr); } TLstTasks.ExecuteAction(testActionNode, null); } } }
/// <summary> /// Read the parameters from a text file (json format); /// used for loading settings /// </summary> /// <param name="filename">relative or absolute filename /// </param> /// <returns>void</returns> public void Load(String filename) { String jsonString; if (!System.IO.File.Exists(filename)) { throw new Exception("file " + filename + " could not be found."); } using (StreamReader sr = new StreamReader(filename)) { jsonString = sr.ReadToEnd(); } try { JavaScriptSerializer serializer = new JavaScriptSerializer(); Object[] list = (Object[])serializer.DeserializeObject(jsonString); foreach (Dictionary <string, object> param in list) { string name = String.Empty; int columnNr = -1, levelNr = -1; TVariant value = new TVariant(); foreach (KeyValuePair <string, object> entry in param) { if (entry.Key == "name") { name = entry.Value.ToString(); } else if (entry.Key == "column") { columnNr = Convert.ToInt32(entry.Value); } else if (entry.Key == "level") { levelNr = Convert.ToInt32(entry.Value); } else if (entry.Key == "value") { value = TVariant.DecodeFromString(entry.Value.ToString()); } } Add(name, value, columnNr, levelNr); } } catch (Exception E) { throw new Exception(E.Message); } }
/// <summary> /// This loads the parameters from a datatable /// Mainly used for sending the parameters over a remote connection /// </summary> /// <param name="param">the datatable that contains a collection of parameters /// </param> /// <returns>void</returns> public void LoadFromDataTable(System.Data.DataTable param) { Fparameters.Clear(); foreach (System.Data.DataRow row in param.Rows) { Fparameters.Add(new TParameter(row["name"].ToString(), TVariant.DecodeFromString(row["value"].ToString()), Convert.ToInt32(row["column"]), Convert.ToInt32(row["level"]), Convert.ToInt16(row["subreport"]))); } if ((TLogging.DebugLevel >= TLogging.DEBUGLEVEL_REPORTING) && (TSrvSetting.ServerLogFile.Length > 0)) { Save(Path.GetDirectoryName(TSrvSetting.ServerLogFile) + Path.DirectorySeparatorChar + "param.xml"); } }
/// load from json public void LoadFromJson(String jsonString) { try { JavaScriptSerializer serializer = new JavaScriptSerializer(); Object[] list = (Object[])serializer.DeserializeObject(jsonString); foreach (Dictionary <string, object> param in list) { string name = String.Empty; int columnNr = -1, levelNr = -1; TVariant value = new TVariant(); foreach (KeyValuePair <string, object> entry in param) { if (entry.Key == "name") { name = entry.Value.ToString(); } else if (entry.Key == "column") { columnNr = Convert.ToInt32(entry.Value); } else if (entry.Key == "level") { levelNr = Convert.ToInt32(entry.Value); } else if (entry.Key == "value") { value = TVariant.DecodeFromString(entry.Value.ToString()); } } Add(name, value, columnNr, levelNr); } } catch (Exception E) { throw new Exception(E.Message); } }
/// <summary> /// This loads the resultlist from a datatable. /// Mainly used for sending the resultlist over a remote connection /// </summary> /// <param name="table">the datatable that contains a collection of results /// </param> /// <returns>void</returns> public void LoadFromDataTable(System.Data.DataTable table) { Int32 maxColumn; Int32 i; TVariant[] header = { new TVariant(), new TVariant() }; TVariant[] descr = { new TVariant(), new TVariant() }; TVariant[] column; results.Clear(); foreach (DataRow row in table.Rows) { header[0] = TVariant.DecodeFromString(row["header1"].ToString()); header[1] = TVariant.DecodeFromString(row["header2"].ToString()); descr[0] = TVariant.DecodeFromString(row["descr1"].ToString()); descr[1] = TVariant.DecodeFromString(row["descr2"].ToString()); maxColumn = Convert.ToInt32(row["maxcolumn"]); column = new TVariant[maxColumn]; for (i = 0; i <= maxColumn - 1; i += 1) { column[i] = TVariant.DecodeFromString(row["column" + i.ToString()].ToString()); } AddRow(Convert.ToInt32(row["masterRow"]), Convert.ToInt32(row["childRow"]), Convert.ToBoolean(row["display"]), Convert.ToInt32(row["depth"]), row["code"].ToString(), row["condition"].ToString(), Convert.ToBoolean( row["debit_credit_indicator"]), header, descr, column); } }
/// <summary> /// store the data into Excel format, Open Office XML, .xlsx /// /// this makes use of the EPPlus library /// http://epplus.codeplex.com/ /// </summary> private static void Xml2ExcelWorksheet(XmlDocument ADoc, ExcelWorksheet AWorksheet, bool AWithHashInCaption = true) { Int32 rowCounter = 1; Int16 colCounter = 1; // first write the header of the csv file List <string> AllAttributes = new List <string>(); List <XmlNode> AllNodes = new List <XmlNode>(); GetAllAttributesAndNodes(ADoc.DocumentElement, ref AllAttributes, ref AllNodes); foreach (string attrName in AllAttributes) { if (AWithHashInCaption) { AWorksheet.Cells[rowCounter, colCounter].Value = "#" + attrName; } else { AWorksheet.Cells[rowCounter, colCounter].Value = attrName; } colCounter++; } rowCounter++; colCounter = 1; foreach (XmlNode node in AllNodes) { foreach (string attrName in AllAttributes) { if (attrName == "childOf") { AWorksheet.Cells[rowCounter, colCounter].Value = TXMLParser.GetAttribute(node.ParentNode, "name"); } else { string value = TXMLParser.GetAttribute(node, attrName); if (value.StartsWith(eVariantTypes.eDateTime.ToString() + ":")) { AWorksheet.Cells[rowCounter, colCounter].Value = TVariant.DecodeFromString(value).ToDate(); AWorksheet.Cells[rowCounter, colCounter].Style.Numberformat.Format = "dd/mm/yyyy"; } else if (value.StartsWith(eVariantTypes.eInteger.ToString() + ":")) { AWorksheet.Cells[rowCounter, colCounter].Value = TVariant.DecodeFromString(value).ToInt64(); } else if (value.StartsWith(eVariantTypes.eDecimal.ToString() + ":")) { AWorksheet.Cells[rowCounter, colCounter].Value = TVariant.DecodeFromString(value).ToDecimal(); } else { AWorksheet.Cells[rowCounter, colCounter].Value = value; } } colCounter++; } rowCounter++; colCounter = 1; } }
/// <summary> /// store the data into Excel format, Open Office XML, .xlsx /// </summary> private static void Xml2ExcelWorksheet(XmlDocument ADoc, IWorkbook AWorkbook, ISheet AWorksheet, bool AWithHashInCaption = true) { Int32 rowCounter = 1; Int16 colCounter = 1; IRow wsrow = null; ICell wscell = null; ICellStyle wsstyle_dateformat = AWorkbook.CreateCellStyle(); ICreationHelper createHelper = AWorkbook.GetCreationHelper(); wsstyle_dateformat.DataFormat = createHelper.CreateDataFormat().GetFormat("dd/mm/yyyy"); // first write the header of the csv file List <string> AllAttributes = new List <string>(); List <XmlNode> AllNodes = new List <XmlNode>(); GetAllAttributesAndNodes(ADoc.DocumentElement, ref AllAttributes, ref AllNodes); wsrow = AWorksheet.CreateRow(rowCounter); foreach (string attrName in AllAttributes) { wscell = wsrow.CreateCell(colCounter); wscell.SetCellValue((AWithHashInCaption?"#":"") + attrName); colCounter++; } rowCounter++; colCounter = 1; foreach (XmlNode node in AllNodes) { wsrow = AWorksheet.CreateRow(rowCounter); foreach (string attrName in AllAttributes) { wscell = wsrow.CreateCell(colCounter); if (attrName == "childOf") { wscell.SetCellValue(TXMLParser.GetAttribute(node.ParentNode, "name")); } else { string value = TXMLParser.GetAttribute(node, attrName); if (value.StartsWith(eVariantTypes.eDateTime.ToString() + ":")) { wscell.SetCellValue(TVariant.DecodeFromString(value).ToDate()); wscell.CellStyle = wsstyle_dateformat; } else if (value.StartsWith(eVariantTypes.eInteger.ToString() + ":")) { wscell.SetCellValue(TVariant.DecodeFromString(value).ToInt64()); } else if (value.StartsWith(eVariantTypes.eDecimal.ToString() + ":")) { wscell.SetCellValue((double)TVariant.DecodeFromString(value).ToDecimal()); } else { wscell.SetCellValue(value); } } colCounter++; } rowCounter++; colCounter = 1; } }