public static bool ExportAllTables(out string ADataYmlGzBase64) { TDataBase DBConnectionObj = null; TDBTransaction ReadTransaction = new TDBTransaction(); XmlDocument OpenPetraData = TYml2Xml.CreateXmlDocument(); XmlNode rootNode = OpenPetraData.FirstChild.NextSibling; Assembly TypedTablesAssembly = Assembly.LoadFrom( TAppSettingsManager.ApplicationDirectory + Path.DirectorySeparatorChar + "Ict.Petra.Shared.lib.data.dll"); try { // Open a separate DB Connection for the exporting of the data... DBConnectionObj = DBAccess.Connect("ExportAllTables"); // ...and start a DB Transaction on that separate DB Connection ReadTransaction = DBConnectionObj.BeginTransaction(IsolationLevel.Serializable, 0, "ExportAllTables"); ExportTables(rootNode, "MSysMan", "", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MCommon", "", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MPartner", "Partner", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MPartner", "Mailroom", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MFinance", "Account", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MFinance", "Gift", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MFinance", "AP", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MFinance", "AR", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MPersonnel", "Personnel", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MPersonnel", "Units", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MConference", "", TypedTablesAssembly, ReadTransaction); ExportTables(rootNode, "MHospitality", "", TypedTablesAssembly, ReadTransaction); ExportSequences(rootNode, ReadTransaction); } finally { if (DBConnectionObj != null) { ReadTransaction.Rollback(); DBConnectionObj.CloseDBConnection(); } } ADataYmlGzBase64 = TYml2Xml.Xml2YmlGz(OpenPetraData); return(true); }
public static string ExportAllTables() { XmlDocument OpenPetraData = TYml2Xml.CreateXmlDocument(); XmlNode rootNode = OpenPetraData.FirstChild.NextSibling; Assembly TypedTablesAssembly = Assembly.LoadFrom( TAppSettingsManager.ApplicationDirectory + Path.DirectorySeparatorChar + "Ict.Petra.Shared.lib.data.dll"); ExportTables(rootNode, "MSysMan", "", TypedTablesAssembly); ExportTables(rootNode, "MCommon", "", TypedTablesAssembly); ExportTables(rootNode, "MPartner", "Partner", TypedTablesAssembly); ExportTables(rootNode, "MPartner", "Mailroom", TypedTablesAssembly); ExportTables(rootNode, "MFinance", "Account", TypedTablesAssembly); ExportTables(rootNode, "MFinance", "Gift", TypedTablesAssembly); ExportTables(rootNode, "MFinance", "AP", TypedTablesAssembly); ExportTables(rootNode, "MFinance", "AR", TypedTablesAssembly); ExportTables(rootNode, "MPersonnel", "Personnel", TypedTablesAssembly); ExportTables(rootNode, "MPersonnel", "Units", TypedTablesAssembly); ExportTables(rootNode, "MConference", "", TypedTablesAssembly); ExportTables(rootNode, "MHospitality", "", TypedTablesAssembly); ExportSequences(rootNode); return(TYml2Xml.Xml2YmlGz(OpenPetraData)); }
/// <summary> /// Default constructor necessary for TTaskList to work with the GUI designer /// Once the control is on a form, the designer should convert this constructor to the parameterized constructor. /// /// Will provide defaults: /// default xmlnode is an empty list /// default style is defined in global settings section. /// </summary> public TTaskList() : this(TYml2Xml.CreateXmlDocument(), DEFAULT_STYLE) { }
/// <summary> /// process the yaml document /// </summary> /// <returns></returns> public Boolean ProcessDocument() { string baseyaml; if (!TYml2Xml.ReadHeader(FYamlFilename, out baseyaml)) { Console.WriteLine("ProcessYAML: cannot recognise type of form"); } else { new TAppSettingsManager(false); //****************** //* parsing ******* //****************** XmlDocument myDoc = TYml2Xml.CreateXmlDocument(); TCodeStorage codeStorage = new TCodeStorage(myDoc, FXmlNodes); TParseYAMLFormsDefinition yamlParser = new TParseYAMLFormsDefinition(ref codeStorage); // should not need to be specific to special forms yamlParser.LoadRecursively(FYamlFilename, FSelectedLocalisation); // for debugging purposes, we can write the xml file that has been parsed from the yaml file // codeStorage.FXmlDocument.Save(FYamlFilename + ".xml"); //**************** //* output ******* //**************** TFormWriter writer = null; // get the appropriate derived class from IFormWriter (e.g. TFrmReportWriter) XmlNode rootNode = (XmlNode)yamlParser.FCodeStorage.FXmlNodes[TParseYAMLFormsDefinition.ROOTNODEYML]; string formType = TYml2Xml.GetAttribute(rootNode, "FormType"); if (formType == "abstract") { Console.WriteLine("Ignore yaml file because it has the formtype abstract: " + FYamlFilename); return(true); } // the Template attribute is also quite important, because it determines which code is written // FormType is mainly important for the difference of the controls of reports and normal screens writer = GetWriter(formType); if (writer == null) { Console.WriteLine("cannot find writer for {0}", formType); return(false); } string templateDir = TAppSettingsManager.GetValue("TemplateDir", true); string template = TYml2Xml.GetAttribute(rootNode, "Template"); if (template.Length > 0) { template = templateDir + Path.DirectorySeparatorChar + template + writer.CodeFileExtension; } string destinationFile = writer.CalculateDestinationFilename(FYamlFilename); string manualCodeFile = writer.CalculateManualCodeFilename(FYamlFilename); // need to know the path to the manual code file in order to call manual functions which would not be called if they do not exist codeStorage.ManualCodeFilename = manualCodeFile; writer.CreateCode(codeStorage, FYamlFilename, template); writer.CreateResourceFile(FYamlFilename, templateDir); writer.CreateDesignerFile(FYamlFilename, rootNode, templateDir); return(writer.WriteFile(destinationFile)); } return(false); }
/// <summary> /// Creates XmlNodes for the Task List. /// </summary> /// <returns>The created XmlNodes for the Task List.</returns> public XmlNode CreateTaskList() { // TLogging.Log("Starting method CreateTaskList!"); // Create the XML document container XmlDocument XMLDocumentOfActivePages = TYml2Xml.CreateXmlDocument(); XmlNode root = XMLDocumentOfActivePages.FirstChild.NextSibling; // Create 'ShepherdPages' element (which serves as 'our' root element) XmlElement ShepherdPages = root.OwnerDocument.CreateElement("ShepherdPages"); // <ShepherdPages> XmlNode ShepherdPagesNode = root.AppendChild(ShepherdPages); int PageCounter = 1; //// TODO: Sub-Shepherds foreach (KeyValuePair <string, TPetraShepherdPage> pair in FShepherdPages.Pages) { XmlElement ID = ShepherdPagesNode.OwnerDocument.CreateElement("Page" + PageCounter.ToString()); // <ID> XmlNode IDNode = ShepherdPagesNode.AppendChild(ID); // Label Attribute XmlAttribute LabelAttribute = ShepherdPagesNode.OwnerDocument.CreateAttribute("Label"); IDNode.Attributes.Append(LabelAttribute); IDNode.Attributes["Label"].Value = pair.Value.Title; // Visible Attribute if (!(pair.Value.Visible)) { XmlAttribute VisibleAttribute = ShepherdPagesNode.OwnerDocument.CreateAttribute("Visible"); IDNode.Attributes.Append(VisibleAttribute); IDNode.Attributes["Visible"].Value = "False"; } // Enabled Attribute if (!(pair.Value.Enabled)) { XmlAttribute EnabledAttribute = ShepherdPagesNode.OwnerDocument.CreateAttribute("Enabled"); IDNode.Attributes.Append(EnabledAttribute); IDNode.Attributes["Enabled"].Value = "False"; } PageCounter++; } XmlNode firstPage = root.FirstChild; //// For debugging only //// TLogging.Log("Count of child nodes: " + firstPage.ChildNodes.Count); //// XmlNodeList PageAttributes = firstPage.ChildNodes; //// int counter = 0; //// foreach(XmlNode node in PageAttributes) //// { //// foreach(XmlNode attributeNode in node.ChildNodes) //// { //// //// TLogging.Log("Foreach Node Value: " + attributeNode.InnerText); //// //// } //// TLogging.Log("Inner foreach: " + counter); //// counter++; //// } //// TLogging.Log("FIRST CHILD NAME: " + root.FirstChild.FirstChild.FirstChild.NextSibling.InnerText); //// ChildDisplay(firstPage,0); return(firstPage); }
private Boolean CreateConnectors(String AOutputPath, String AModulePath, String ATemplateDir) { // Work out the module name from the module path string[] items = AModulePath.Split(new char[] { Path.DirectorySeparatorChar }); if (items.Length == 0) { // the -inputclient command line parameter must be wrong return(false); } // Module name is e.g. MCommon, MPartner etc string moduleName = items[items.Length - 1]; // Work out the actual folder/file for the output file String OutputFolder = AOutputPath + Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar + moduleName + Path.DirectorySeparatorChar + "web"; String OutputFile = OutputFolder + Path.DirectorySeparatorChar + "ReferenceCount-generated.cs"; Console.WriteLine("working on " + OutputFile); // Where is the template? String templateFilename = ATemplateDir + Path.DirectorySeparatorChar + "ORM" + Path.DirectorySeparatorChar + "ReferenceCountWebConnector.cs"; if (!File.Exists(templateFilename)) { // The -templatedir command line parameter must have been wrong return(false); } // Open the template ProcessTemplate Template = new ProcessTemplate(templateFilename); // now we need to remove the leading 'M' from the module name moduleName = moduleName.Substring(1); string className = "T" + moduleName + "ReferenceCountWebConnector"; Console.WriteLine("Starting connector for " + className + Environment.NewLine); int cacheableCount = 0; int nonCacheableCount = 0; // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir)); Template.SetCodelet("TOPLEVELMODULE", moduleName); Template.SetCodelet("CLASSNAME", className); Template.SetCodelet("CACHEABLETABLECASES", string.Empty); Template.SetCodelet("CACHEABLETABLENAME", string.Empty); Template.SetCodelet("CACHEABLETABLECASE", string.Empty); Template.SetCodelet("CACHEABLETABLELISTNAME", string.Empty); Template.SetCodelet("CACHEABLETRANSACTION", string.Empty); Template.SetCodelet("CACHEABLEFINALLY", string.Empty); Template.SetCodelet("TABLESIF", string.Empty); Template.SetCodelet("TABLESELSEIF", string.Empty); Template.SetCodelet("TABLESELSE", string.Empty); Template.SetCodelet("TABLENAME", string.Empty); Template.SetCodelet("NONCACHEABLETRANSACTION", string.Empty); Template.SetCodelet("NONCACHEABLEFINALLY", string.Empty); // Find all the YAML files in the client module folder string[] clientFiles = Directory.GetFiles(AModulePath, "*.yaml", SearchOption.AllDirectories); foreach (String fn in clientFiles) { // only look for main files, not language specific files (*.xy-XY.yaml or *.xy.yaml) if (TProcessYAMLForms.IgnoreLanguageSpecificYamlFile(fn)) { continue; } XmlDocument doc = TYml2Xml.CreateXmlDocument(); SortedList sortedNodes = null; TCodeStorage codeStorage = new TCodeStorage(doc, sortedNodes); TParseYAMLFormsDefinition yamlParser = new TParseYAMLFormsDefinition(ref codeStorage); yamlParser.LoadRecursively(fn, null); string attDetailTableName = codeStorage.GetAttribute("DetailTable"); string attCacheableListName = codeStorage.GetAttribute("CacheableTable"); // Note - this IF clause needs to be the same as the one in FormWriter.cs which is generating the client side code // Do Ctrl+F to find: this IF clause needs to be the same // in that file if ((attDetailTableName != String.Empty) && (codeStorage.FControlList.ContainsKey("btnDelete") || codeStorage.FControlList.ContainsKey("btnDeleteType") || codeStorage.FControlList.ContainsKey("btnDeleteExtract") || codeStorage.FControlList.ContainsKey("btnDeleteDetail") || (codeStorage.FControlList.ContainsKey("btnRemoveDetail") && (codeStorage.GetAttribute("FormType") != "report")))) { if (attCacheableListName != String.Empty) { ProcessTemplate snippet = Template.GetSnippet("CACHEABLETABLECASE"); snippet.SetCodelet("CACHEABLETABLENAME", attDetailTableName); snippet.SetCodelet("CACHEABLETABLELISTNAME", attCacheableListName); Template.InsertSnippet("CACHEABLETABLECASES", snippet); if (cacheableCount == 0) { // Add these on the first time through snippet = Template.GetSnippet("CACHEABLETRANSACTIONSNIP"); Template.InsertSnippet("CACHEABLETRANSACTION", snippet); snippet = Template.GetSnippet("CACHEABLEFINALLYSNIP"); Template.InsertSnippet("CACHEABLEFINALLY", snippet); } Console.WriteLine("Creating cacheable reference count connector for " + attCacheableListName); cacheableCount++; } else { ProcessTemplate snippet = null; if (nonCacheableCount == 0) { snippet = Template.GetSnippet("TABLEIF"); snippet.SetCodelet("TABLENAME", attDetailTableName); Template.InsertSnippet("TABLESIF", snippet); snippet = Template.GetSnippet("NONCACHEABLETRANSACTIONSNIP"); Template.InsertSnippet("NONCACHEABLETRANSACTION", snippet); snippet = Template.GetSnippet("NONCACHEABLEFINALLYSNIP"); Template.InsertSnippet("NONCACHEABLEFINALLY", snippet); } else { snippet = Template.GetSnippet("TABLEELSEIF"); snippet.SetCodelet("TABLENAME", attDetailTableName); Template.InsertSnippet("TABLESELSEIF", snippet); } Console.WriteLine("Creating non-cacheable reference count connector for " + attDetailTableName); nonCacheableCount++; } } } // Now we finish off the template content depending on how many entries we made if ((nonCacheableCount == 0) && (cacheableCount > 0)) { ProcessTemplate snippet = Template.GetSnippet("TABLENONE"); Template.InsertSnippet("TABLESELSE", snippet); } if (nonCacheableCount > 0) { ProcessTemplate snippet = Template.GetSnippet("TABLEELSE"); Template.InsertSnippet("TABLESELSE", snippet); } if ((cacheableCount > 0) || (nonCacheableCount > 0)) { if (!Directory.Exists(OutputFolder)) { // The -outputserver command line parameter must be wrong, or the directory does not exist yet // Directories must be manually created and added to source code control Console.WriteLine("Error: directory does not exist: " + OutputFolder); return(false); } Console.WriteLine("Finishing connector for " + className + Environment.NewLine + Environment.NewLine); Template.FinishWriting(OutputFile, ".cs", true); FTotalCacheable += cacheableCount; FTotalNonCacheable += nonCacheableCount; FTotalConnectors++; } return(true); }
/// <summary> /// return an XmlDocument with all partner info; /// the partners are grouped by class, country, status, and sitekey /// </summary> /// <returns></returns> public static string ExportPartners() { PartnerEditTDS MainDS = new PartnerEditTDS(); LoadDataFromDB(ref MainDS); // Group partners into categories. // // A partner's category is defined by his: class, country, status, and sitekey // It is stored as a string e.g. "FAMILY,DE,ACTIVE,0". // SortedList <string, List <long> > PartnerCategories = GroupPartnersIntoCategories(MainDS); // create XML structure for each category XmlDocument PartnerData = TYml2Xml.CreateXmlDocument(); XmlNode rootNode = PartnerData.FirstChild.NextSibling; Int32 groupCounter = 0; foreach (string category in PartnerCategories.Keys) { // get category data groupCounter++; XmlElement groupNode = PartnerData.CreateElement("PartnerGroup" + groupCounter.ToString()); rootNode.AppendChild(groupNode); Int32 partnerCounter = 0; string[] categoryDetails = category.Split(new char[] { ',' }); // may want to skip the categories with sitekey = -1 // right now, we still export them and ignore the partners 0 and 1000000 later groupNode.SetAttribute("class", categoryDetails[0]); groupNode.SetAttribute("Country", categoryDetails[1]); groupNode.SetAttribute("status", categoryDetails[2]); groupNode.SetAttribute("SiteKey", categoryDetails[3]); List <long> partnerKeys = PartnerCategories[category]; foreach (long partnerKey in partnerKeys) { if ((partnerKey != 0) && (partnerKey != 1000000)) // skip organization root and the 0 when exporting { MainDS.PPartner.DefaultView.RowFilter = PPartnerTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); PPartnerRow partnerRow = (PPartnerRow)MainDS.PPartner.DefaultView[0].Row; PFamilyRow familyRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { MainDS.PFamily.DefaultView.RowFilter = PFamilyTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); familyRow = (PFamilyRow)MainDS.PFamily.DefaultView[0].Row; } PPersonRow personRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { MainDS.PPerson.DefaultView.RowFilter = PPersonTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); personRow = (PPersonRow)MainDS.PPerson.DefaultView[0].Row; } POrganisationRow organisationRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { MainDS.POrganisation.DefaultView.RowFilter = POrganisationTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); organisationRow = (POrganisationRow)MainDS.POrganisation.DefaultView[0].Row; } PUnitRow unitRow = null; UmUnitStructureRow unitStructureRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { MainDS.PUnit.DefaultView.RowFilter = PUnitTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); unitRow = (PUnitRow)MainDS.PUnit.DefaultView[0].Row; MainDS.UmUnitStructure.DefaultView.RowFilter = UmUnitStructureTable.GetChildUnitKeyDBName() + " = " + partnerKey.ToString(); long numParents = MainDS.UmUnitStructure.DefaultView.Count; if (numParents == 1) { unitStructureRow = (UmUnitStructureRow)MainDS.UmUnitStructure.DefaultView[0].Row; } else { throw new Exception( "Units must have exactly one ParentUnit. " + "The unit with partnerKey " + partnerKey.ToString() + " has " + numParents.ToString() + "."); } } PBankRow BankRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { MainDS.PBank.DefaultView.RowFilter = PBankTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); BankRow = (PBankRow)MainDS.PBank.DefaultView[0].Row; } partnerCounter++; XmlElement partnerNode = PartnerData.CreateElement("Partner" + partnerCounter.ToString()); groupNode.AppendChild(partnerNode); partnerNode.SetAttribute("PartnerKey", partnerRow.PartnerKey.ToString()); //groupNode.SetAttribute("ShortName", partnerRow.PartnerShortName.ToString()); if (personRow != null) { partnerNode.SetAttribute("FirstName", personRow.FirstName.ToString()); partnerNode.SetAttribute("LastName", personRow.FamilyName.ToString()); partnerNode.SetAttribute("Title", personRow.Title.ToString()); } else if (familyRow != null) { partnerNode.SetAttribute("FirstName", familyRow.FirstName.ToString()); partnerNode.SetAttribute("LastName", familyRow.FamilyName.ToString()); partnerNode.SetAttribute("Title", familyRow.Title.ToString()); } else if (organisationRow != null) { partnerNode.SetAttribute("Name", organisationRow.OrganisationName.ToString()); } else if (unitRow != null) { partnerNode.SetAttribute("Name", unitRow.UnitName.ToString()); partnerNode.SetAttribute("UnitTypeCode", unitRow.UnitTypeCode.ToString()); if (unitStructureRow != null) { partnerNode.SetAttribute("ParentUnitKey", unitStructureRow.ParentUnitKey.ToString()); } } if (BankRow != null) { partnerNode.SetAttribute("BranchName", BankRow.BranchName); partnerNode.SetAttribute("BranchCode", BankRow.BranchCode); partnerNode.SetAttribute("BranchBic", BankRow.Bic); partnerNode.SetAttribute("EpFormatFile", BankRow.EpFormatFile); } partnerNode.SetAttribute("CreatedAt", partnerRow.DateCreated.Value.ToString("yyyy-MM-dd HH:mm:ss")); // special types string specialTypes = ""; MainDS.PPartnerType.DefaultView.RowFilter = PPartnerTypeTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); foreach (DataRowView rv in MainDS.PPartnerType.DefaultView) { if (specialTypes.Length > 0) { specialTypes += ", "; } specialTypes += ((PPartnerTypeRow)rv.Row).TypeCode; } if (specialTypes.Length > 0) { partnerNode.SetAttribute("SpecialTypes", specialTypes); } // addresses DataView partnerLocationView = MainDS.PPartnerLocation.DefaultView; partnerLocationView.RowFilter = PPartnerLocationTable.GetPartnerKeyDBName() + " = " + partnerRow.PartnerKey.ToString() + "AND " + PPartnerLocationTable.GetLocationKeyDBName() + " <> 0 "; // ignore invalid addresses Int32 addressCounter = 0; foreach (DataRowView rv in partnerLocationView) { XmlElement addressNode = PartnerData.CreateElement("Address" + (addressCounter > 0 ? addressCounter.ToString() : "")); addressCounter++; partnerNode.AppendChild(addressNode); PPartnerLocationRow partnerLocationRow = (PPartnerLocationRow)rv.Row; DataView locationView = MainDS.PLocation.DefaultView; locationView.RowFilter = PLocationTable.GetSiteKeyDBName() + "=" + partnerLocationRow.SiteKey.ToString() + " AND " + PLocationTable.GetLocationKeyDBName() + "=" + partnerLocationRow.LocationKey.ToString(); if (locationView.Count > 0) { PLocationRow locationRow = (PLocationRow)locationView[0].Row; addressNode.SetAttribute("Street", locationRow.StreetName); addressNode.SetAttribute("City", locationRow.City); addressNode.SetAttribute("PostCode", locationRow.PostalCode); } addressNode.SetAttribute("Email", partnerLocationRow.EmailAddress); addressNode.SetAttribute("Phone", partnerLocationRow.TelephoneNumber); addressNode.SetAttribute("MobilePhone", partnerLocationRow.MobileNumber); } // TODO: notes // TODO: This doesn't export as much data as it should? } } } return(TXMLParser.XmlToString(PartnerData)); }