private static void ConfigureASheet( string sLocalName , ref ArrayList allProducts , string sProductName , string sQueryEnd , NameValueCollection nParms , DocDetails dt , ref PcId pc ) { /* * Sub to Call config on the Sheet with the Method * * */ try { foreach (object o in allProducts) { Products pd = (Products)o; if (pd.sProduct == sProductName && pd.sQueryEnd == sQueryEnd) { // Got It // Marshall the Parms try { pc.LogEvent(sUnid , "At dt.CallXlConfigure for " + sLocalName , 0 , pc.IBatchNo); dt.sTarget = sTarget; dt.sOfficesw = sOfficeSw; dt.CallXlConfigure(pd, sLocalName, nParms); } catch (Exception ex) { if (bWebLog) { pc.LogEvent(sUnid , ex.Message + "Results from Configure on " + sLocalName , -1 , pc.IBatchNo); } else { pc.FileLog(sUnid , ex.Message + "Results from Configure on " + sLocalName , -1 , pc.IBatchNo); } } finally { FileInfo fi = new FileInfo(sLocalName); fi.Delete(); if (bWebLog) { pc.LogEvent(sUnid , "Success Results w/Delete from Configure on " + sLocalName , 0 , pc.IBatchNo); } else { pc.FileLog(sUnid , "Success Results w/Delete from Configure on " + sLocalName , 0 , pc.IBatchNo); } } break; } } } catch (Exception ex) { } }
static void Main(string[] args) { // Initialize the program // Set starting conditions bool bError = false; //string url = sHost + "Sheets/Version/070110/"; // HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); // using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) // { // using (StreamReader reader = new StreamReader(response.GetResponseStream())) // { // string html = reader.ReadToEnd(); // } // } /* Arguments * 0 Install Location \\server\share\ - Install * 1 target directory \\server\share\ - tied to unid * 2 unid * */ PcId pc; try { if (File.Exists("Clients.xml")) // We will drive via file. Do the config { XmlDocument xmld = new XmlDocument(); xmld.Load(@"Clients.xml"); XmlNodeList nodesl = xmld.SelectNodes("//Client"); string sFileName = ""; sFileName = sHost + @"\Install\Xml\Products.xml"; Console.WriteLine("Getting file {0}", sFileName); DownLoadASheet(sFileName, sTarget + @"\Products.Xml"); //if (bWebLog) // pc.LogEvent(sUnid, "File Download Complete on " // + sTarget + @"Products.Xml", 0, pc.IBatchNo); //else // pc.FileLog(sUnid, "File Download Complete on " // + sTarget + @"Products.Xml", 0, pc.IBatchNo); foreach (XmlNode n in nodesl) { sHost = n.Attributes["Host"].Value; sUnid = n.Attributes["Unid"].Value; sTarget = n.Attributes["Target"].Value; sEmail = n.Attributes["Email"].Value; sOfficeSw = n.Attributes["Office"].Value; // call the main config class Config_Process.ProcessMain(sHost, sUnid, sTarget, sEmail, sOfficeSw); // reset the logger object } goto Done; } else { sHost = args[0]; if (sHost.Contains("$")) { sHost = sHost.Replace("$", ""); } sTarget = args[1]; if (sTarget.Contains("$")) { sTarget = sTarget.Replace("$", ""); } sUnid = args[2]; sEmail = args[3]; sOfficeSw = args[4]; } } catch { sHost = @"Server Error"; sTarget = @"Drive Error"; sUnid = ""; sEmail = "*****@*****.**"; sOfficeSw = "2007"; } iBatchCl = -999; // Lets Id the box pc = new PcId(sUnid, sTarget, sEmail); // 21 Jan 2011 - Added support for godaddy webservice and Id on box try { pc.LogEvent(); iBatchCl = pc.IBatchNo; bWebLog = true; if (iBatchCl == -1) { // logging is not available bWebLog = false; pc.CreateLogFile(sTarget); } } catch (Exception ex) { bWebLog = false; pc.CreateLogFile(sTarget); } try { Directory.CreateDirectory(sTarget); } catch { } ArrayList nProd = new ArrayList(); //if (args.GetUpperBound(0) > 0) // sUnid = args[0]; // make sure our work directory exists // Clear out old sheets string[] sFiles = Directory.GetFiles(sTarget); foreach (string f in sFiles) { FileInfo fd = new FileInfo(f); if (fd.Extension == ".xls" || fd.Extension == ".xlsm") { fd.IsReadOnly = false; fd.Delete(); } } if (!Directory.Exists(sTarget)) { } else { sFiles = Directory.GetFiles(sTarget); foreach (string f in sFiles) { FileInfo fd = new FileInfo(f); if (fd.Extension == ".xls" || fd.Extension == ".xlsm") { fd.IsReadOnly = false; fd.Delete(); } } } try { string sFileName = ""; sFileName = sHost + @"\Install\Xml\Products.xml"; Console.WriteLine("Getting file {0}", sFileName); DownLoadASheet(sFileName, sTarget + @"\Products.Xml"); if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete on " + sTarget + @"Products.Xml", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete on " + sTarget + @"Products.Xml", 0, pc.IBatchNo); } sFileName = sHost + @"\Install\Xml\" + sUnid + @"\Cust.Xml"; Console.WriteLine("Getting file {0}", sFileName); DownLoadASheet(sFileName, sTarget + @"\Cust.Xml"); if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete on " + sTarget + @"Cust.Xml", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete on " + sTarget + @"Cust.Xml", 0, pc.IBatchNo); } } catch (Exception ex) { if (bWebLog) { pc.LogEvent(sUnid, ex.Message + " - Program Abort", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + " - Program Abort", -1, pc.IBatchNo); } try { pc.Close(); } catch { } Console.WriteLine("Program Stopping - " + ex.Message); return; } if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete", 0, pc.IBatchNo); } // Process the xmlDoc XmlDocument xmldoc = new XmlDocument(); XmlDocument xmldocProducts = new XmlDocument(); xmldocProducts.Load(sTarget + @"\Products.Xml"); System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string sContents; StreamReader sr = new StreamReader(sTarget + @"\Cust.Xml"); sContents = sr.ReadToEnd(); sr.Close(); sr.Dispose(); byte[] b = Convert.FromBase64String(sContents); sContents = System.Text.Encoding.UTF8.GetString(b); //Byte[] sb1 = str.GetBytes(sContents); //sContents = Convert.ToBase64String(sb1); //sContents = Convert.ToString(sb1); StreamWriter sw = new StreamWriter(sTarget + @"\Cust.Xml", false); sw.Write(sContents); sw.Close(); sw.Dispose(); xmldoc.Load(sTarget + @"\Cust.Xml"); NameValueCollection nMethods = new NameValueCollection(); // LoadMethods(ref nMethods, xmldocMethods); // Call the Config Clas DocDetails dt = new DocDetails(xmldocProducts); dt.SetProducts(nProd); NameValueCollection nParms = new NameValueCollection(); XmlNode root; root = xmldoc.DocumentElement; XmlNodeList nodes; // nodes = root.SelectNodes("Customer/Parms[@Sheet='Y']"); nodes = root.SelectNodes("Customer/Parms"); // Build all the nodes, mark which are sheets, which are parms. // Match it by queryand and sheet to determine the parms. string sQry = ""; foreach (XmlNode n in nodes) { if (n.Name == "Parms") { try { if (sQry == "") { sQry = n.Attributes["queryend"].Value; } } catch (Exception ex) { } } foreach (XmlAttribute att in n.Attributes) { Debug.Print("att value={0} Attribute Name{1}", att.Value, att.Name); if (att.Name == "Product" && att.Value == "Y") { Debug.Print("Got a Product{0}", n.Attributes["Value"].Value); // string sRemoteName = "http://localhost/sheets/" + n.Attributes["Value"].Value + ".xls"; // string sLocalName = @"C:\cci\" + n.Attributes["Value"].Value + ".xls"; try { char[] delimiterChars = { ',' }; string[] sqrysplit; try { sQry = nParms.Get("queryend").ToString(); sqrysplit = sQry.Split(delimiterChars); sQry = sqrysplit[0]; } catch (Exception ex) { sQry = @"070110"; } NameValueCollection tParms = FindParmSet(n.Attributes["Value"].Value, sQry, dt.cSheetColl, nParms); string sFile = FindLiveFile(n.Attributes["Value"].Value, sQry, dt.cSheetColl); string sRemoteName = sHost + @"\Install\sheets\version\" + sQry + @"\" + sFile; //HttpUtility.UrlPathEncode(sFile); string sLocalName = sTarget + @"\" + sFile; if (bWebLog) { pc.LogEvent(sUnid, "Downloading Sheet" + sRemoteName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Downloading Sheet" + sRemoteName, 0, pc.IBatchNo); } iDotCount = 0; sCurrentFile = sRemoteName; if (File.Exists(sLocalName)) { FileInfo fi2 = new FileInfo(sLocalName); fi2.IsReadOnly = false; fi2.Delete(); } // Added 26 August 2011 // Purpose // Retry 3 times int iTries = 0; ftpRetry: Console.WriteLine("Getting file {0}", sRemoteName); try { iTries += 1; DownLoadASheet(sRemoteName, sLocalName); } catch (Exception x) { if (iTries > 3) { throw x; } else { Console.WriteLine("Retrying file {0}", sLocalName); goto ftpRetry; } } if (bWebLog) { pc.LogEvent(sUnid, "Download Complete Sheet" + sRemoteName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Download Complete Sheet" + sRemoteName, 0, pc.IBatchNo); } // Call Configure on it! // ConfigureASheet(sLocalName, ref dt.cSheetColl, n.Value, sQry, nParms, dt); FileInfo fi; bool bProcess = false; fi = new FileInfo(sLocalName); if (File.Exists(sLocalName) && fi.Length > 0) { try { // inc the logger iLogCount += 1; if (!pc.bCust) { pc.LogEvent(sUnid, "", 10000, pc.IBatchNo); pc.bCust = true; } if (bWebLog) { pc.LogEvent(sUnid, "Trying to configure" + sLocalName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Trying to configure" + sLocalName, 0, pc.IBatchNo); } ConfigureASheet(sLocalName, ref dt.cSheetColl, n.Attributes["Value"].Value, sQry, tParms, dt, ref pc); if (bWebLog) { pc.LogEvent(sUnid, "Configuring " + sLocalName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Configuring " + sLocalName, 0, pc.IBatchNo); } sQry = ""; } catch (Exception ex) { pc.LogEvent(sUnid, ex.Message + " - Configuring Sheet Fails", -1, pc.IBatchNo); } if (bWebLog) { pc.LogEvent(sUnid, "Processing Completed", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Processing Completed", 0, pc.IBatchNo); } if (bWebLog) { pc.LogEvent(sUnid, " Installer Closing", 11000, pc.IBatchNo); } else { pc.FileLog(sUnid, " Installer Closing", 11000, pc.IBatchNo); } pc.Close(); } else { fi.Delete(); } break; } catch (Exception ex) { if (bWebLog) { pc.LogEvent(sUnid, ex.Message + " - Downloading Sheet", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + " - Downloading Sheet", -1, pc.IBatchNo); } Console.WriteLine("Error - " + ex.Message); } } else { // it is not a sheet try { if (nParms.Get(n.Attributes["LkeyName"].Value) != null) {//skip it string sKeyName = n.Attributes["LkeyName"].Value; string sKeyValue = n.Attributes["Value"].Value; string sCurrentVal = nParms.Get(n.Attributes["LkeyName"].Value); Debug.Print("Atrib {0} ", n.Attributes["Value"].Value); // if (sKeyValue == sCurrentVal) goto Lp1; switch (sKeyName) { //salariedcodes //salariedwithsupp //certifiedcodes //princodes //suppcodes case "suppcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "princodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "certifiedcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "salariedwithsupp": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "salariedcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "otherdepts": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "budgetind": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "specialind": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; default: break; } goto Lp1; } else { nParms.Add(n.Attributes["LkeyName"].Value, n.Attributes["Value"].Value); } } catch (ArgumentOutOfRangeException ex) { // is missing } catch { } } Lp1 :; } ; } // Calling Configuration Class // dt = new DocDetails(xmldocProducts ); // dt.SetProducts(nProd); // dt.CallBudgetMethod(new sTheProducts()); Done: if (bError) { } FileInfo fi1 = new FileInfo(sTarget + @"\Cust.xml"); fi1.Delete(); fi1 = new FileInfo(sTarget + @"\Products.xml"); fi1.Delete(); Console.WriteLine("Installer Processing Completed!"); }
static void Main(string[] args) { /* Arguments * 0 host * 1 target directory * 2 unid * */ bError = false; int iCnt = 0; Console.WriteLine("Installer Begins. {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); string sQuote = "\""; string sCmdLine = ""; try { sHost = args[0]; sUnid = args[1]; sEmail = args[2]; sTarget = args[3]; sTarget = sTarget.Replace(sQuote, ""); Console.WriteLine("Email is {0}", sEmail); string currentAssemblyDirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } catch (Exception ex) { sTarget = sTarget.Replace(sQuote, ""); sHost = @"http://ccisupportsite.com"; // sTarget = @"c:\As400da\"; // sUnid = "4621E8E7157912B185257829006ECFC0"; // sEmail = "*****@*****.**"; Console.WriteLine("Error - Parameter Signature Invalid " + ex.Message); // throw ex; // fix the install directory if (!Directory.Exists(sTarget)) { iCnt = 0; bool bValid = false; while (iCnt <= 2 && !bValid) { Console.WriteLine("Problem with Target Location"); Console.WriteLine("The target {0} cannot be Validated Please Reenter:", sTarget); sTarget = Console.ReadLine(); Console.WriteLine(""); sTarget = sTarget.Trim(); iCnt += 1; if (Directory.Exists(sTarget)) { bValid = true; } } if (iCnt > 2 && !bValid) { bError = true; } } // fix the email address Console.WriteLine("Problem with Email Address"); Console.WriteLine("The email address {0} cannot be Validated Please Reenter:", sEmail); sEmail = Console.ReadLine(); Console.WriteLine(""); sEmail = sEmail.Trim(); } iBatchCl = -999; // Lets Id the box PcId pc = new PcId(sUnid, sTarget, sEmail); pc.sEmail = sEmail; if (bError) { goto Done; } // 21 Jan 2011 - Added support for godaddy webservice and Id on box try { if (sEmail.Contains(@"cookconsulting.net")) { goto Next; } if (pc.ChkInstall(sUnid) == "stop") { Console.WriteLine("This install is terminated - This license code has been previously installed"); bError = true; goto Done; } Next: pc.LogEvent(); iBatchCl = pc.IBatchNo; bWebLog = true; if (iBatchCl == -1) { // logging is not available bWebLog = false; pc.CreateLogFile(sTarget); } } catch (Exception ex) { bWebLog = false; // pc.CreateLogFile(sTarget); } //sUnid = sUnid.Trim(); while (iCnt <= 2 && sUnid.Length != 32) { Console.Write("Problem with the Customer License Code Check your Cut and Past"); Console.Write("The unid {0} cannot be Validated Please Reenter:", sUnid); sUnid = Console.ReadLine(); Console.WriteLine(""); sUnid = sUnid.Trim(); iCnt += 1; } if (sUnid.Length != 32) { Console.WriteLine("The unid {0} cannot be Validated.", sUnid); bError = true; goto Done; } Console.WriteLine("Installer is running Batch ID -> {0} for UNID -> {1}.", iBatchCl, sUnid); // Removed // 31 Jan 2012 if (sTarget.EndsWith("\\")) { } else { sTarget += "\\"; } ArrayList nProd = new ArrayList(); //if (args.GetUpperBound(0) > 0) // sUnid = args[0]; // make sure our work directory exists FileInfo fi; try { if (!Directory.Exists(sTarget)) { Directory.CreateDirectory(sTarget); } } catch (Exception ex) { } ; // 23 Juin 2011 // MJ Moen // added to replace kill switch in script try { DirectoryInfo di = new DirectoryInfo(sTarget); foreach (FileInfo tfi in di.GetFiles()) { if (tfi.Extension == ".xls" || tfi.Extension == ".xlsm") { tfi.IsReadOnly = false; tfi.Delete(); } } di = new DirectoryInfo(@"c:\as400da\"); foreach (FileInfo tfi in di.GetFiles()) { if (tfi.Extension == ".xls" || tfi.Extension == ".xlsm") { tfi.IsReadOnly = false; tfi.Delete(); } } string sDesktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\AS400 SpreadSheets"; di = new DirectoryInfo(sDesktop); foreach (FileInfo tfi in di.GetFiles()) { if (tfi.Extension == ".lnk") { tfi.IsReadOnly = false; tfi.Delete(); } } // Clear CCI Sheets Short Cuts // 31 Jan 2012 sDesktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\CCI SpreadSheets"; di = new DirectoryInfo(sDesktop); foreach (FileInfo tfi in di.GetFiles()) { if (tfi.Extension == ".lnk") { tfi.IsReadOnly = false; tfi.Delete(); } } di = new DirectoryInfo(sTarget); foreach (FileInfo tfi in di.GetFiles()) { if (tfi.Extension == ".lnk") { tfi.IsReadOnly = false; tfi.Delete(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } try { fi = new FileInfo(sTarget + @"Products.xml"); fi.IsReadOnly = false; File.Delete(sTarget + @"Products.xml"); } catch { } try { fi = new FileInfo(sTarget + @"Cust.xml"); fi.IsReadOnly = false; File.Delete(sTarget + @"Cust.xml"); } catch { } try { string sFileName = ""; sFileName = sHost + @"/Xml/Products.xml"; DownLoadASheet(sFileName, sTarget + @"Products.Xml"); if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete on " + sTarget + @"Products.Xml", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete on " + sTarget + @"Products.Xml", 0, pc.IBatchNo); } dws.GetFullCustomersService customersService = new dws.GetFullCustomersService(); NetworkCredential networkCredential = new NetworkCredential("mmoen", "bobbob1", ""); customersService.Credentials = (ICredentials)networkCredential; try { SxmlRet = customersService.GETFULLCUSTOMERS("changeor.nsf", "XMLOUTPUT", sUnid); } catch (Exception ex) { Console.WriteLine(ex.Message); } sFileName = sHost + @"/Xml/" + sUnid + @"/Cust.Xml"; DownLoadASheet(sFileName, sTarget + @"Cust.Xml"); if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete on " + sTarget + @"Cust.Xml", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete on " + sTarget + @"Cust.Xml", 0, pc.IBatchNo); } } catch (Exception ex) { bError = bError || true; if (bWebLog) { pc.LogEvent(sUnid, ex.Message + " - Program Abort", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + " - Program Abort", -1, pc.IBatchNo); } if (bWebLog) { pc.LogEvent(sUnid, ex.Message + "Program Abort", 11000, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + "Program Abort", 11000, pc.IBatchNo); } // test try { pc.Close(); } catch { } Console.WriteLine("Program Stopping - " + ex.Message); goto Done; } fi = new FileInfo(sTarget + @"Products.Xml"); if (File.Exists(sTarget + @"Products.Xml") && fi.Length == 0) { if (bWebLog) { pc.LogEvent(sUnid, "Products File did not Download", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, "Products File did not Download", -1, pc.IBatchNo); } bError = bError || true; goto Done; } fi = new FileInfo(sTarget + @"Cust.Xml"); if (File.Exists(sTarget + @"Cust.Xml") && fi.Length == 0) { if (bWebLog) { pc.LogEvent(sUnid, "Customer File did not Download", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, "Customer File did not Download", -1, pc.IBatchNo); } bError = bError || true; goto Done; } if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete ", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete ", 0, pc.IBatchNo); } // Process the xmlDoc XmlDocument xmldoc = new XmlDocument(); XmlDocument xmldocProducts = new XmlDocument(); xmldocProducts.Load(sTarget + @"Products.Xml"); System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string sContents; StreamReader sr = new StreamReader(sTarget + @"Cust.Xml"); sContents = sr.ReadToEnd(); sr.Close(); sr.Dispose(); byte[] b = Convert.FromBase64String(sContents); sContents = System.Text.Encoding.UTF8.GetString(b); StreamWriter sw = new StreamWriter(sTarget + @"Cust.Xml", false); sw.Write(sContents); sw.Close(); sw.Dispose(); if (bWebLog) { pc.LogEvent(sUnid, sContents, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, sContents, 0, pc.IBatchNo); } xmldoc.Load(sTarget + @"Cust.Xml"); NameValueCollection nMethods = new NameValueCollection(); // LoadMethods(ref nMethods, xmldocMethods); // Call the Config Clas DocDetails dt = new DocDetails(xmldocProducts); dt.SetProducts(nProd); NameValueCollection nParms = new NameValueCollection(); XmlNode root; root = xmldoc.DocumentElement; XmlNodeList nodes; // nodes = root.SelectNodes("Customer/Parms[@Sheet='Y']"); nodes = root.SelectNodes("Customer/Parms"); // Build all the nodes, mark which are sheets, which are parms. // Match it by queryand and sheet to determine the parms. string sQryP = "", sQry = ""; foreach (XmlNode n in nodes) { if (n.Name == "Parms") { try { if (sQry == "") { sQryP = n.Attributes["queryend"].Value; } } catch (Exception ex) { } } foreach (XmlAttribute att in n.Attributes) { Debug.Print("att value={0} Attribute Name{1}", att.Value, att.Name); if (att.Name == "Product" && att.Value == "Y") { Debug.Print("Got a Product{0}", n.Attributes["Value"].Value); // string sRemoteName = "http://localhost/sheets/" + n.Attributes["Value"].Value + ".xls"; // string sLocalName = @"C:\cci\" + n.Attributes["Value"].Value + ".xls"; //try to get the attribute based queryend try { if (sQry == "") { sQry = n.Attributes["queryend"].Value; } } catch (Exception ex) { } try { char[] delimiterChars = { ',' }; string[] sqrysplit; try { if (sQryP == "") { sQryP = nParms.Get("queryend").ToString(); sqrysplit = sQryP.Split(delimiterChars); sQryP = sqrysplit[0]; } } catch (Exception ex) { sQryP = @"070110"; } string sQueryEnd; // logic is there is a node queryend attribute use it // else use the file queryend // 16 July 2012 // Resolve the correct queryend only from cust.xml //if (sQry == "") // sQueryEnd = sQryP; //else sQueryEnd = sQry; NameValueCollection tParms = FindParmSet(n.Attributes["Value"].Value, sQueryEnd, dt.cSheetColl, nParms); string sFile = FindLiveFile(n.Attributes["Value"].Value, sQueryEnd, dt.cSheetColl); string sRemoteName = sHost + @"/sheets/version/" + sQueryEnd + @"/" + HttpUtility.UrlPathEncode(sFile); string sLocalName = sTarget + sFile; if (bWebLog) { pc.LogEvent(sUnid, "Downloading Sheet " + sRemoteName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Downloading Sheet " + sRemoteName, 0, pc.IBatchNo); } sCurrentFile = sRemoteName; iDotCount = 0; if (File.Exists(sLocalName)) { FileInfo fi2 = new FileInfo(sLocalName); fi2.IsReadOnly = false; fi2.Delete(); } DownLoadASheet(sRemoteName, sLocalName); if (bWebLog) { pc.LogEvent(sUnid, "Download Complete Sheet " + sRemoteName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Download Complete Sheet " + sRemoteName, 0, pc.IBatchNo); } bool bProcess = false; fi = new FileInfo(sLocalName); if (File.Exists(sLocalName) && fi.Length > 0) { try { // inc the logger iLogCount += 1; if (!pc.bCust) { pc.LogEvent(sUnid, "", 10000, pc.IBatchNo); pc.bCust = true; } if (bWebLog) { pc.LogEvent(sUnid, "Trying to configure " + sLocalName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Trying to configure " + sLocalName, 0, pc.IBatchNo); } ConfigureASheet(sLocalName, ref dt.cSheetColl, n.Attributes["Value"].Value, sQueryEnd, tParms, dt, ref pc); if (bWebLog) { pc.LogEvent(sUnid, "Configuring " + sLocalName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Configuring " + sLocalName, 0, pc.IBatchNo); } sQry = ""; } catch (Exception ex) { bError = bError || true; pc.LogEvent(sUnid, ex.Message + " - Configuring Sheet Fails", -1, pc.IBatchNo); } } else { fi.Delete(); } break; } catch (Exception ex) { bError = bError || true; if (bWebLog) { pc.LogEvent(sUnid, ex.Message + " - Downloading Sheet", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + " - Downloading Sheet", -1, pc.IBatchNo); } Console.WriteLine("Error - " + ex.Message); } } else { // it is not a sheet try { if (nParms.Get(n.Attributes["LkeyName"].Value) != null) {//skip it string sKeyName = n.Attributes["LkeyName"].Value; Debug.Print("Key name is {0}", sKeyName); if (sKeyName == "queryend" && sQryP == "") { sQryP = n.Attributes["Value"].Value; } string sKeyValue = n.Attributes["Value"].Value; string sCurrentVal = nParms.Get(n.Attributes["LkeyName"].Value); Debug.Print("Atrib {0} ", n.Attributes["Value"].Value); // if (sKeyValue == sCurrentVal) goto Lp1; switch (sKeyName) { //salariedcodes //salariedwithsupp //certifiedcodes //princodes //suppcodes case "suppcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "princodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "certifiedcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "salariedwithsupp": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "salariedcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "otherdepts": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "budgetind": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "specialind": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "username": pc.setUser(n.Attributes["Value"].Value); break; case "customername": pc.setCust(n.Attributes["Value"].Value); break; default: break; } goto Lp1; } else { nParms.Add(n.Attributes["LkeyName"].Value, n.Attributes["Value"].Value); } } catch (ArgumentOutOfRangeException ex) { // is missing } catch { } } Lp1 :; } ; } // Calling Configuration Class // dt = new DocDetails(xmldocProducts ); // dt.SetProducts(nProd); // dt.CallBudgetMethod(new sTheProducts()); if (bWebLog) { pc.LogEvent(sUnid, "Processing Completed", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Processing Completed", 0, pc.IBatchNo); } pc.Close(); FileInfo fi1 = new FileInfo(sTarget + "Cust.xml"); fi1.Delete(); fi1 = new FileInfo(sTarget + "Products.xml"); fi1.Delete(); Done: if (bError) { Console.WriteLine("An Install Error has Occurred! Please Contact Support desk @ 800 425 0720 or email [email protected]"); Console.WriteLine("Please note the following information Batch ID -> {0} and UNID -> {1}.", iBatchCl, sUnid); Console.WriteLine("Press Enter key to continue."); Console.ReadLine(); } Console.WriteLine("Installer Processing Completed!"); if (bWebLog) { pc.LogEvent(sUnid, " Installer Closing", 11000, pc.IBatchNo); } else { pc.FileLog(sUnid, " Installer Closing", 11000, pc.IBatchNo); } return; }
static void Main(string[] args) { // Initialize the program // Set starting conditions //string url = sHost + "Sheets/Version/070110/"; // HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); // using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) // { // using (StreamReader reader = new StreamReader(response.GetResponseStream())) // { // string html = reader.ReadToEnd(); // } // } /* Arguments * 0 host * 1 target directory * 2 unid * */ // Current Build 28 Jan 2012 bError = false; int iCnt = 0; short iSheetCnt = 0; Console.WriteLine("Installer Begins."); string sCmdLine = ""; string currentAssemblyDirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //if (File.Exists(currentAssemblyDirectoryName + @"\Clients.xml")) //// We will drive via file. Do the config //{ // XmlDocument xmld = new XmlDocument(); // xmld.Load(currentAssemblyDirectoryName + @"\Clients.xml"); // XmlNodeList nodesl = xmld.SelectNodes("//Client[@Install='Y']"); // foreach (XmlNode n in nodesl) // { // sHost = PartialInstaller.Properties.Settings.Default.Host; // sUnid = n.Attributes["unid"].Value; // sTarget = n.Attributes["target"].Value; // sEmail = n.Attributes["email"].Value; // Console.WriteLine("Unid = {0}", sUnid); // Console.WriteLine("Target= {0}", sTarget); // Console.WriteLine("Email = {0}", sEmail); // Console.ReadLine(); // } // // 3 October 2011 // // I have read the Class file // // Just start normally // goto setParms; //} try { string sQuote = "\""; sHost = args[0]; sUnid = args[1]; sUnid = sUnid.Trim(); sEmail = args[2]; sTarget = args[3]; sTarget = sTarget.Replace(sQuote, ""); } catch (Exception ex) { sHost = @"http://ccisupportsite.com"; // sTarget = @"c:\As400da\"; // sUnid = "4621E8E7157912B185257829006ECFC0"; // sEmail = "*****@*****.**"; Console.WriteLine("Error - Parameter Signature Invalid " + ex.Message); // throw ex; // fix the install directory if (!Directory.Exists(sTarget)) { iCnt = 0; bool bValid = false; while (iCnt <= 2 && !bValid) { Console.WriteLine("Problem with Target Location"); Console.WriteLine("The target {0} cannot be Validated Please Reenter:", sTarget); sTarget = Console.ReadLine(); Console.WriteLine(""); sTarget = sTarget.Trim(); iCnt += 1; if (Directory.Exists(sTarget)) { bValid = true; } } if (iCnt > 2 && !bValid) { bError = true; } } // fix the email address Console.WriteLine("Problem with Email Address"); Console.WriteLine("The email address {0} cannot be Validated Please Reenter:", sEmail); sEmail = Console.ReadLine(); Console.WriteLine(""); sEmail = sEmail.Trim(); } setParms: iBatchCl = -999; // Lets Id the box PcId pc = new PcId(sUnid, sTarget, sEmail); pc.sEmail = sEmail; if (bError) { goto Done; } // 21 Jan 2011 - Added support for godaddy webservice and Id on box try { if (sEmail.Contains(@"cookconsulting.net")) { goto Next; } //if (pc.ChkInstall(sUnid) == "stop" ) //{ // Console.WriteLine("This install is terminated - This license code has been previously installed"); // bError = true; // goto Done; //} Next: pc.LogEvent(); iBatchCl = pc.IBatchNo; bWebLog = true; if (iBatchCl == -1) { // logging is not available bWebLog = false; pc.CreateLogFile(sTarget); } } catch (Exception ex) { bWebLog = false; pc.CreateLogFile(sTarget); } //sUnid = sUnid.Trim(); while (iCnt <= 2 && sUnid.Length != 32) { Console.Write("Problem with the Customer License Code Check your Cut and Past"); Console.Write("The unid {0} cannot be Validated Please Reenter:", sUnid); sUnid = Console.ReadLine(); Console.WriteLine(""); sUnid = sUnid.Trim(); iCnt += 1; } if (sUnid.Length != 32) { Console.WriteLine("The unid {0} cannot be Validated.", sUnid); bError = true; goto Done; } Console.WriteLine("Installer is running Batch ID -> {0} for UNID -> {1}.", iBatchCl, sUnid); ArrayList nProd = new ArrayList(); //if (args.GetUpperBound(0) > 0) // sUnid = args[0]; // make sure our work directory exists FileInfo fi; try { if (!Directory.Exists(sTarget)) { Directory.CreateDirectory(sTarget); } } catch (Exception ex) { } try { fi = new FileInfo(sTarget + @"\Products.xml"); fi.IsReadOnly = false; File.Delete(sTarget + @"\Products.xml"); } catch { } try { fi = new FileInfo(sTarget + @"\Cust.xml"); fi.IsReadOnly = false; File.Delete(sTarget + @"\Cust.xml"); } catch { } try { string sFileName = ""; sFileName = sHost + @"/Xml/Products.xml"; DownLoadASheet(sFileName, sTarget + @"\Products.Xml"); if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete on " + sTarget + @"Products.Xml", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete on " + sTarget + @"Products.Xml", 0, pc.IBatchNo); } //sFileName = sHost + @"/Xml/" + sUnid + @"/Cust.Xml"; //DownLoadASheet(sFileName, sTarget + @"Cust.Xml"); PartialInstaller.WSCustomer.GetCustomersPartialService gcp = new PartialInstaller.WSCustomer.GetCustomersPartialService(); NetworkCredential cc = new NetworkCredential(@"mmoen", @"bobbob1", ""); gcp.Credentials = cc; string sXmlOut = gcp.GETCUSTOMERSPARTIAL("changeor.nsf", "XMLOUTPUT", sUnid); StreamWriter swcust = new StreamWriter(sTarget + @"\Cust.Xml", false); swcust.Write(pc.PackXml(sXmlOut, sUnid)); swcust.Close(); swcust.Dispose(); if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete on " + sTarget + @"\Cust.Xml", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete on " + sTarget + @"\Cust.Xml", 0, pc.IBatchNo); } } catch (Exception ex) { bError = bError || true; if (bWebLog) { pc.LogEvent(sUnid, ex.Message + " - Program Abort", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + " - Program Abort", -1, pc.IBatchNo); } if (bWebLog) { pc.LogEvent(sUnid, ex.Message + "Program Abort", 11000, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + "Program Abort", 11000, pc.IBatchNo); } // test try { pc.Close(); } catch { } Console.WriteLine("Program Stopping - " + ex.Message); goto Done; } fi = new FileInfo(sTarget + @"\Products.Xml"); if (File.Exists(sTarget + @"\Products.Xml") && fi.Length == 0) { if (bWebLog) { pc.LogEvent(sUnid, "Products File did not Download", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, "Products File did not Download", -1, pc.IBatchNo); } bError = bError || true; goto Done; } fi = new FileInfo(sTarget + @"\Cust.Xml"); if (File.Exists(sTarget + @"\Cust.Xml") && fi.Length == 0) { if (bWebLog) { pc.LogEvent(sUnid, "Customer File did not Download", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, "Customer File did not Download", -1, pc.IBatchNo); } bError = bError || true; goto Done; } if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete ", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete ", 0, pc.IBatchNo); } // Process the xmlDoc XmlDocument xmldoc = new XmlDocument(); XmlDocument xmldocProducts = new XmlDocument(); xmldocProducts.Load(sTarget + @"\Products.Xml"); System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string sContents; StreamReader sr = new StreamReader(sTarget + @"\Cust.Xml"); sContents = sr.ReadToEnd(); sr.Close(); sr.Dispose(); //byte[] b = Convert.FromBase64String(sContents); //sContents = System.Text.Encoding.UTF8.GetString(b); ////Byte[] sb1 = str.GetBytes(sContents); ////sContents = Convert.ToBase64String(sb1); ////sContents = Convert.ToString(sb1); //StreamWriter sw = new StreamWriter(sTarget + @"Cust.Xml", false); //sw.Write(sContents); //sw.Close(); //sw.Dispose(); xmldoc.Load(sTarget + @"\Cust.Xml"); NameValueCollection nMethods = new NameValueCollection(); // LoadMethods(ref nMethods, xmldocMethods); // Call the Config Clas DocDetails dt = new DocDetails(xmldocProducts); dt.SetProducts(nProd); NameValueCollection nParms = new NameValueCollection(); XmlNode root; root = xmldoc.DocumentElement; XmlNodeList nodes; // nodes = root.SelectNodes("Customer/Parms[@Sheet='Y']"); nodes = root.SelectNodes("Customer/Parms"); // Build all the nodes, mark which are sheets, which are parms. // Match it by queryand and sheet to determine the parms. string sQry = ""; foreach (XmlNode n in nodes) { if (n.Name == "Parms") { try { if (sQry == "") { sQry = n.Attributes["queryend"].Value; } } catch (Exception ex) { } } foreach (XmlAttribute att in n.Attributes) { Debug.Print("att value={0} Attribute Name{1}", att.Value, att.Name); if (att.Name == "Product" && att.Value == "Y") { iSheetCnt += 1; Debug.Print("Got a Product{0}", n.Attributes["Value"].Value); // string sRemoteName = "http://localhost/sheets/" + n.Attributes["Value"].Value + ".xls"; // string sLocalName = @"C:\cci\" + n.Attributes["Value"].Value + ".xls"; try { char[] delimiterChars = { ',' }; string[] sqrysplit; try { sQry = nParms.Get("queryend").ToString(); sqrysplit = sQry.Split(delimiterChars); sQry = sqrysplit[0]; } catch (Exception ex) { sQry = @"070110"; } NameValueCollection tParms = FindParmSet(n.Attributes["Value"].Value, sQry, dt.cSheetColl, nParms); string sFile = FindLiveFile(n.Attributes["Value"].Value, sQry, dt.cSheetColl); string sRemoteName = sHost + @"/sheets/version/" + sQry + @"/" + HttpUtility.UrlPathEncode(sFile); string sLocalName = sTarget + @"\" + sFile; if (bWebLog) { pc.LogEvent(sUnid, "Downloading Sheet " + sRemoteName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Downloading Sheet " + sRemoteName, 0, pc.IBatchNo); } sCurrentFile = sRemoteName; iDotCount = 0; if (File.Exists(sLocalName)) { FileInfo fi2 = new FileInfo(sLocalName); fi2.IsReadOnly = false; fi2.Delete(); } DownLoadASheet(sRemoteName, sLocalName); if (bWebLog) { pc.LogEvent(sUnid, "Download Complete Sheet " + sRemoteName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Download Complete Sheet " + sRemoteName, 0, pc.IBatchNo); } // Call Configure on it! // ConfigureASheet(sLocalName, ref dt.cSheetColl, n.Value, sQry, nParms, dt); bool bProcess = false; fi = new FileInfo(sLocalName); if (File.Exists(sLocalName) && fi.Length > 0) { try { // inc the logger iLogCount += 1; if (!pc.bCust) { pc.LogEvent(sUnid, "", 10000, pc.IBatchNo); pc.bCust = true; } if (bWebLog) { pc.LogEvent(sUnid, "Trying to configure " + sLocalName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Trying to configure " + sLocalName, 0, pc.IBatchNo); } ConfigureASheet(sLocalName, ref dt.cSheetColl, n.Attributes["Value"].Value, sQry, tParms, dt, ref pc); if (bWebLog) { pc.LogEvent(sUnid, "Configuring " + sLocalName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Configuring " + sLocalName, 0, pc.IBatchNo); } // System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); //string sContents; //StreamReader sr = new StreamReader(sLocalName); //sContents = sr.ReadToEnd(); //sr.Close(); //sr.Dispose(); //Byte[] sb1 = str.GetBytes(sContents); //sContents = Convert.ToBase64String(sb1); //sContents = Convert.ToString(sb1); //StreamWriter sw = new StreamWriter(sLocalName,false); //sw.Write(sContents); //sw.Close(); //sw.Dispose(); sQry = ""; } catch (Exception ex) { bError = bError || true; pc.LogEvent(sUnid, ex.Message + " - Configuring Sheet Fails", -1, pc.IBatchNo); } } else { fi.Delete(); } break; } catch (Exception ex) { bError = bError || true; if (bWebLog) { pc.LogEvent(sUnid, ex.Message + " - Downloading Sheet", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + " - Downloading Sheet", -1, pc.IBatchNo); } Console.WriteLine("Error - " + ex.Message); } } else { // it is not a sheet try { if (nParms.Get(n.Attributes["LkeyName"].Value) != null) {//skip it string sKeyName = n.Attributes["LkeyName"].Value; string sKeyValue = n.Attributes["Value"].Value; string sCurrentVal = nParms.Get(n.Attributes["LkeyName"].Value); Debug.Print("Atrib {0} ", n.Attributes["Value"].Value); // if (sKeyValue == sCurrentVal) goto Lp1; switch (sKeyName) { //salariedcodes //salariedwithsupp //certifiedcodes //princodes //suppcodes case "suppcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "princodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "certifiedcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "salariedwithsupp": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "salariedcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "otherdepts": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "budgetind": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "specialind": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "username": pc.setUser(n.Attributes["Value"].Value); break; case "customername": pc.setCust(n.Attributes["Value"].Value); break; default: break; } goto Lp1; } else { nParms.Add(n.Attributes["LkeyName"].Value, n.Attributes["Value"].Value); } } catch (ArgumentOutOfRangeException ex) { // is missing } catch { } } Lp1 :; } ; } // Calling Configuration Class // dt = new DocDetails(xmldocProducts ); // dt.SetProducts(nProd); // dt.CallBudgetMethod(new sTheProducts()); if (bWebLog) { pc.LogEvent(sUnid, "Processing Completed", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Processing Completed", 0, pc.IBatchNo); } pc.Close(); FileInfo fi1 = new FileInfo(sTarget + "Cust.xml"); fi1.Delete(); fi1 = new FileInfo(sTarget + "Products.xml"); fi1.Delete(); Done: if (iSheetCnt == 0) { bError = true; Console.WriteLine("No Sheets were retrieved from WebService - Check Domino Sheet Selections"); } if (bError) { Console.WriteLine("An Install Error has Occurred! Please Contact Support desk @ 800 425 0720 or email [email protected]"); Console.WriteLine("Please note the following information Batch ID -> {0} and UNID -> {1}.", iBatchCl, sUnid); Console.WriteLine("Press Enter key to continue."); Console.ReadLine(); } if (!bError) { try { PartialInstaller.WSPartials.RemovePartialFlagsService rp = new PartialInstaller.WSPartials.RemovePartialFlagsService(); NetworkCredential cc = new NetworkCredential(@"mmoen", @"bobbob1", ""); rp.Credentials = cc; rp.REMOVEPARTIALFLAGS("Changeor.nsf", "XMLOUTPUT", sUnid); } catch { } } Console.WriteLine("Installer Processing Completed!"); if (bWebLog) { pc.LogEvent(sUnid, " Installer Closing", 11000, pc.IBatchNo); } else { pc.FileLog(sUnid, " Installer Closing", 11000, pc.IBatchNo); } return; }
static void Main(string[] args) { // Initialize the program // Set starting conditions bool bError = false; int iCnt = 0; Console.WriteLine("Installer Begins. {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); string sQuote = "\""; string sCmdLine = ""; /* Arguments * 0 Install Location \\server\share\ - Install * 1 target directory \\server\share\ - tied to unid * 2 unid * 3 email * 4 officesw */ try { sHost = args[0]; if (sHost.Contains("$")) { sHost = sHost.Replace("$", ""); } sTarget = args[1]; if (sTarget.Contains("$")) { sTarget = sTarget.Replace("$", ""); } if (sTarget.EndsWith("\\")) { } else { sTarget += "\\"; } sUnid = args[2]; sEmail = args[3]; sOfficeSw = args[4]; Console.WriteLine("Email is {0}", sEmail); string currentAssemblyDirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } catch { sHost = @"\\Unknown"; sTarget = @"C:\AS400DA\"; sUnid = ""; sEmail = "*****@*****.**"; sOfficeSw = "2007"; } iBatchCl = -999; // Lets Id the box PcId pc = new PcId(sUnid, sTarget, sEmail); // 21 Jan 2011 - Added support for godaddy webservice and Id on box try { pc.LogEvent(); iBatchCl = pc.IBatchNo; bWebLog = true; if (iBatchCl == -1) { // logging is not available bWebLog = false; pc.CreateLogFile(sTarget); } } catch (Exception ex) { bWebLog = false; pc.CreateLogFile(sTarget); } try { Directory.CreateDirectory(sTarget); } catch { } ArrayList nProd = new ArrayList(); //if (args.GetUpperBound(0) > 0) // sUnid = args[0]; // make sure our work directory exists // Clear out old sheets string[] sFiles = Directory.GetFiles(sTarget); foreach (string f in sFiles) { FileInfo fd = new FileInfo(f); if (fd.Extension == ".xls" || fd.Extension == ".xlsm") { fd.IsReadOnly = false; fd.Delete(); } } if (!Directory.Exists(sTarget)) { Directory.CreateDirectory(sTarget); } else { sFiles = Directory.GetFiles(sTarget); foreach (string f in sFiles) { FileInfo fd = new FileInfo(f); if (fd.Extension == ".xls" || fd.Extension == ".xlsm") { fd.IsReadOnly = false; fd.Delete(); } } } try { string sFileName = ""; sFileName = sHost + @"Install\Xml\Products.xml"; Console.WriteLine("Getting file {0}", sFileName); DownLoadASheet(sFileName, sTarget + @"Products.Xml"); if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete on " + sTarget + @"Products.Xml", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete on " + sTarget + @"Products.Xml", 0, pc.IBatchNo); } sFileName = sHost + @"Install\Xml\" + sUnid + @"\Cust.Xml"; Console.WriteLine("Getting file {0}", sFileName); DownLoadASheet(sFileName, sTarget + @"Cust.Xml"); if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete on " + sTarget + @"Cust.Xml", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete on " + sTarget + @"Cust.Xml", 0, pc.IBatchNo); } } catch (Exception ex) { if (bWebLog) { pc.LogEvent(sUnid, ex.Message + " - Program Abort", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + " - Program Abort", -1, pc.IBatchNo); } try { pc.Close(); } catch { } Console.WriteLine("Program Stopping - " + ex.Message); return; } if (bWebLog) { pc.LogEvent(sUnid, "File Download Complete", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "File Download Complete", 0, pc.IBatchNo); } // Process the xmlDoc XmlDocument xmldoc = new XmlDocument(); XmlDocument xmldocProducts = new XmlDocument(); xmldocProducts.Load(sTarget + @"\Products.Xml"); System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string sContents; StreamReader sr = new StreamReader(sTarget + @"Cust.Xml"); sContents = sr.ReadToEnd(); sr.Close(); sr.Dispose(); byte[] b = Convert.FromBase64String(sContents); sContents = System.Text.Encoding.UTF8.GetString(b); //Byte[] sb1 = str.GetBytes(sContents); //sContents = Convert.ToBase64String(sb1); //sContents = Convert.ToString(sb1); StreamWriter sw = new StreamWriter(sTarget + @"Cust.Xml", false); sw.Write(sContents); sw.Close(); sw.Dispose(); xmldoc.Load(sTarget + @"Cust.Xml"); NameValueCollection nMethods = new NameValueCollection(); // LoadMethods(ref nMethods, xmldocMethods); // Call the Config Clas DocDetails dt = new DocDetails(xmldocProducts); dt.SetProducts(nProd); NameValueCollection nParms = new NameValueCollection(); XmlNode root; root = xmldoc.DocumentElement; XmlNodeList nodes; // nodes = root.SelectNodes("Customer/Parms[@Sheet='Y']"); nodes = root.SelectNodes("Customer/Parms"); // Build all the nodes, mark which are sheets, which are parms. // Match it by queryand and sheet to determine the parms. string sQryP = "", sQry = ""; foreach (XmlNode n in nodes) { if (n.Name == "Parms") { try { if (sQry == "") { sQryP = n.Attributes["queryend"].Value; } } catch (Exception ex) { } } foreach (XmlAttribute att in n.Attributes) { Debug.Print("att value={0} Attribute Name{1}", att.Value, att.Name); if (att.Name == "Product" && att.Value == "Y") { Debug.Print("Got a Product{0}", n.Attributes["Value"].Value); // string sRemoteName = "http://localhost/sheets/" + n.Attributes["Value"].Value + ".xls"; // string sLocalName = @"C:\cci\" + n.Attributes["Value"].Value + ".xls"; try { char[] delimiterChars = { ',' }; string[] sqrysplit; try { if (sQryP == "") { sQryP = nParms.Get("queryend").ToString(); sqrysplit = sQryP.Split(delimiterChars); sQryP = sqrysplit[0]; } } catch (Exception ex) { sQryP = @"070110"; } string sQueryEnd; // logic is there is a node queryend attribute use it // else use the file queryend if (sQry == "") { sQueryEnd = sQryP; } else { sQueryEnd = sQry; } NameValueCollection tParms = FindParmSet(n.Attributes["Value"].Value, sQueryEnd, dt.cSheetColl, nParms); string sFile = FindLiveFile(n.Attributes["Value"].Value, sQueryEnd, dt.cSheetColl); string sRemoteName = sHost + @"Install\sheets\version\" + sQueryEnd + @"\" + sFile; //HttpUtility.UrlPathEncode(sFile); string sLocalName = sTarget + sFile; if (bWebLog) { pc.LogEvent(sUnid, "Downloading Sheet" + sRemoteName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Downloading Sheet" + sRemoteName, 0, pc.IBatchNo); } iDotCount = 0; sCurrentFile = sRemoteName; if (File.Exists(sLocalName)) { FileInfo fi2 = new FileInfo(sLocalName); fi2.Delete(); } Console.WriteLine("Getting file {0}", sRemoteName); DownLoadASheet(sRemoteName, sLocalName); if (bWebLog) { pc.LogEvent(sUnid, "Download Complete Sheet" + sRemoteName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Download Complete Sheet" + sRemoteName, 0, pc.IBatchNo); } // Call Configure on it! // ConfigureASheet(sLocalName, ref dt.cSheetColl, n.Value, sQry, nParms, dt); FileInfo fi; bool bProcess = false; fi = new FileInfo(sLocalName); if (File.Exists(sLocalName) && fi.Length > 0) { try { // inc the logger iLogCount += 1; if (bWebLog) { pc.LogEvent(sUnid, "Trying to configure" + sLocalName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Trying to configure" + sLocalName, 0, pc.IBatchNo); } ConfigureASheet(sLocalName, ref dt.cSheetColl, n.Attributes["Value"].Value, sQueryEnd, tParms, dt, ref pc); if (bWebLog) { pc.LogEvent(sUnid, "Configuring " + sLocalName, 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Configuring " + sLocalName, 0, pc.IBatchNo); } sQry = ""; } catch (Exception ex) { pc.LogEvent(sUnid, ex.Message + " - Configuring Sheet Fails", -1, pc.IBatchNo); } } else { fi.Delete(); } break; } catch (Exception ex) { if (bWebLog) { pc.LogEvent(sUnid, ex.Message + " - Downloading Sheet", -1, pc.IBatchNo); } else { pc.FileLog(sUnid, ex.Message + " - Downloading Sheet", -1, pc.IBatchNo); } Console.WriteLine("Error - " + ex.Message); } } else { // it is not a sheet try { if (nParms.Get(n.Attributes["LkeyName"].Value) != null) {//skip it string sKeyName = n.Attributes["LkeyName"].Value; string sKeyValue = n.Attributes["Value"].Value; string sCurrentVal = nParms.Get(n.Attributes["LkeyName"].Value); Debug.Print("Atrib {0} ", n.Attributes["Value"].Value); Debug.Print("Key name is {0}", sKeyName); if (sKeyName == "queryend" && sQryP == "") { sQryP = n.Attributes["Value"].Value; } switch (sKeyName) { //salariedcodes //salariedwithsupp //certifiedcodes //princodes //suppcodes case "suppcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "princodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "certifiedcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "salariedwithsupp": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "salariedcodes": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "otherdepts": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "budgetind": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; case "specialind": nParms.Remove(n.Attributes["LkeyName"].Value); nParms.Add(n.Attributes["LkeyName"].Value , sCurrentVal + "," + sKeyValue); break; default: break; } goto Lp1; } else { nParms.Add(n.Attributes["LkeyName"].Value, n.Attributes["Value"].Value); } } catch (ArgumentOutOfRangeException ex) { // is missing } catch { } } Lp1 :; } ; } // Calling Configuration Class // dt = new DocDetails(xmldocProducts ); // dt.SetProducts(nProd); // dt.CallBudgetMethod(new sTheProducts()); Done: if (bError) { } if (bWebLog) { pc.LogEvent(sUnid, "Processing Completed", 0, pc.IBatchNo); } else { pc.FileLog(sUnid, "Processing Completed", 0, pc.IBatchNo); } pc.Close(); FileInfo fi1 = new FileInfo(sTarget + @"\Cust.xml"); fi1.Delete(); fi1 = new FileInfo(sTarget + @"\Products.xml"); fi1.Delete(); Console.WriteLine("Installer Processing Completed!"); }
public void CallXlConfigure(Products pd, string sFileName, NameValueCollection nParms, string sQry, ref PcId pc) { Microsoft.Office.Interop.Excel.Workbook wb; Microsoft.Office.Interop.Excel.ApplicationClass xl; xl = new Microsoft.Office.Interop.Excel.ApplicationClass(); xl.DisplayAlerts = false; // sFileName = @"C:\cci\"; // + sp.sFileName; // Build the call to setset the Excel Sheet try { // 2 August Late open excel after parm binding //if (pd.sVisible == "Y") xl.Visible = true; //else xl.Visible = false; //xl.Interactive = false; ////Microsoft.Office.Core.MsoAutomationSecurity secAuto = (MsoAutomationSecurity)MsoAutomationSecurity.msoAutomationSecurityLow; ////xl.Application.AutomationSecurity = secAuto; //wb = xl.Workbooks.Open( // sFileName // , 2 // , false, // 5, // "", // "", // true, // Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, // "\t", // false, // false, // 0, // true, // 1, // 0); int iSize = nParms.Count + 1; System.Threading.AutoResetEvent waiter = new System.Threading.AutoResetEvent(false); while (xl.Ready != true) { waiter.WaitOne(60 * 1000); } ; object[] oParms = new object[] { pd.sMethodCall }; // ,"Hello World!" // ,nvpKeys.Get("SystemNm") // ,nvpKeys.Get("FinanceType") // , null // }; int ix = 1; Array.Resize(ref oParms, iSize); foreach (string skey in nParms.Keys) { string sVal = ""; sVal = nParms.Get(Convert.ToString(skey)); if (sVal != null) { if (sVal.Contains(",")) {// is an array object[] sTarget; sTarget = processstring(sVal); oParms[ix] = sTarget; } else { oParms[ix] = nParms.Get(skey); if (skey == "queryend") { oParms[ix] = sQry; } // oParms[ix] = nParms.Get(skey); } } else { oParms[ix] = nParms.Get(skey) == null ? "" : nParms.Get(skey); if ( skey == "specialind" || skey == "budgetind" || skey == "otherdepts" || skey == "salariedcodes" || skey == "salariedwithsupp" || skey == "certifiedcodes" || skey == "princodes" || skey == "suppcodes" ) { oParms[ix] = new object[] { "" }; } } ix += 1; } if (oParms[0].ToString().Length + oParms[1].ToString().Length + oParms[2].ToString().Length == 0) { // pc.LogEvent( throw new Exception("The parms are empty from cust.xml"); } // 2 august 2012 if (pd.sVisible == "Y") { xl.Visible = true; } else { xl.Visible = false; } xl.Interactive = false; //Microsoft.Office.Core.MsoAutomationSecurity secAuto = (MsoAutomationSecurity)MsoAutomationSecurity.msoAutomationSecurityLow; //xl.Application.AutomationSecurity = secAuto; wb = xl.Workbooks.Open( sFileName , 2 , false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); // 2 august 2012 // Sub SetSheet(ConnectionNm As String, SystemNm As String, SystemType As String, FinanceType As String, UserType As String, ProcPrefix As String, QueryEnd As String) // //tcookcci: Added another tag called Maintenance in the XML //(Y or N) - if they are not on Maintenance, it will be blank for now. // The current QueryEnd is 070109 - once we are ready to update, it will change to 070110 try { if (pd.sMethodCall.Length > 0 && pd.sMethodCall != "None") { RunMacro(xl, oParms); } } catch (Exception ex) { xl.Quit(); throw ex; } Debug.Print(xl.Version); try { Type type = xl.GetType(); PropertyInfo prop = type.GetProperty("CheckCompatibility"); Console.WriteLine("Retrieved Xl Property"); prop.SetValue(xl, false, null); } catch { } string sFTarget = this.sTarget + pd.sProduct; if (String.Compare(xl.Version, "11.0") > 0) { if (File.Exists(sFTarget + ".xlsm")) { FileInfo fi2 = new FileInfo(sFTarget + ".xlsm"); fi2.IsReadOnly = false; fi2.Delete(); } string sPth1 = sTarget + pd.sProduct + ".xlsm"; Console.WriteLine("Path to XL file is {0}", sPth1); wb.SaveAs(sTarget + pd.sProduct + ".xlsm" , 52, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } else { string sPth1 = sTarget + pd.sProduct + ".xlsm"; Console.WriteLine("Path to XL file is {0}", sPth1); if (File.Exists(sFTarget + ".xls")) { FileInfo fi2 = new FileInfo(sFTarget + ".xls"); fi2.IsReadOnly = false; fi2.Delete(); } wb.SaveAs(sTarget + pd.sProduct + ".xls" , XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } xl.Quit(); } catch (Exception ex) { if (xl != null) { xl.Quit(); } throw ex; } finally { try { xl.Quit(); } catch { } } }