static void SaveDataTableToXML(string outFilename) { //save to XML MemoryStream content = new MemoryStream();; dt.WriteXml(content, XmlWriteMode.WriteSchema); //XML data source library Microsoft.SharePoint.Administration.SPAdministrationWebApplication caApp = SPAdministrationWebApplication.Local; using (SPSite caSite = caApp.Sites[0]) { using (SPWeb caWeb = caSite.OpenWeb()) { caWeb.AllowUnsafeUpdates = true; //attempt to locate SPList listSPDash = caWeb.Lists.TryGetList("SPDash"); if (listSPDash == null) { //create if missing caWeb.Lists.Add("SPDash", "* DO NOT DELETE - storage of XML files for dashboard", SPListTemplateType.DocumentLibrary); listSPDash = caWeb.Lists.TryGetList("SPDash"); } listSPDash.RootFolder.Files.Add(outFilename + ".xml", content, true); caWeb.AllowUnsafeUpdates = false; } } }
// Uncomment the method below to handle the event raised after a feature has been activated. //public override void FeatureActivated(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised before a feature is deactivated. //public override void FeatureDeactivating(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised after a feature has been installed. public override void FeatureInstalled(SPFeatureReceiverProperties properties) { try { //active feature for CA web app during install //SPDashFeature = beba7f1a-f972-4759-89fe-8777a539a4cb //SPDashTimerJobFeature = 753f6c7b-95fb-41de-977f-489689d4902c Logger.LogInfo("FeatureInstalled - SPDashFeature beba7f1a-f972-4759-89fe-8777a539a4cb"); Microsoft.SharePoint.Administration.SPAdministrationWebApplication caApp = SPAdministrationWebApplication.Local; string caUrl = caApp.Sites[0].Url; string caCmd = string.Format("Start-Sleep 10; Enable-SPFeature 753f6c7b-95fb-41de-977f-489689d4902c -Url " + caUrl + "; Enable-SPFeature beba7f1a-f972-4759-89fe-8777a539a4cb -Url " + caUrl); Logger.LogInfo("caUrl = " + caUrl); Logger.LogInfo("caCmd = " + caCmd); //empty CA library (if found from previous install) using (SPSite caSite = caApp.Sites[0]) { using (SPWeb caWeb = caSite.OpenWeb()) { caWeb.AllowUnsafeUpdates = true; //attempt to find SPList listSPDash = caWeb.Lists.TryGetList("SPDash"); if (listSPDash != null) { SPListItemCollection items = listSPDash.Items; for (int i = items.Count - 1; i > -1; i--) { items.Delete(i); } } caWeb.AllowUnsafeUpdates = false; } } //start cmd ProcessStartInfo startinfo = new ProcessStartInfo(); startinfo.FileName = "powershell.exe"; startinfo.Arguments = caCmd; startinfo.UseShellExecute = false; startinfo.CreateNoWindow = true; Process process; process = Process.Start(startinfo); Logger.LogInfo("FeatureInstalled - OK"); //execute first population Engine.main(); } catch (Exception x) { Logger.LogError(String.Format("SPDash Feature Activation error: {0}", x.Message)); } }
static public void main() { //download config XML from Central Admin site Microsoft.SharePoint.Administration.SPAdministrationWebApplication caApp = SPAdministrationWebApplication.Local; using (SPSite caSite = caApp.Sites[0]) { using (SPWeb caWeb = caSite.OpenWeb()) { caWeb.AllowUnsafeUpdates = true; //attempt to find SPList listSPDash = caWeb.Lists.TryGetList("SPDash"); if (listSPDash != null) { SPFile configXML = caWeb.GetFile(listSPDash.RootFolder.ServerRelativeUrl + "/" + configFilename); if (configXML.Exists) { //save locally byte[] content = configXML.OpenBinary(); FileStream stream = new FileStream(configLocalFile, FileMode.Create); BinaryWriter bw = new BinaryWriter(stream); bw.Write(content); bw.Close(); stream.Close(); } else { //upload from local byte[] content = File.ReadAllBytes(configLocalFile); listSPDash.RootFolder.Files.Add(configFilename, content); } } caWeb.AllowUnsafeUpdates = false; } } //read config XmlSerializer serializer = new XmlSerializer(typeof(SPDashTimerJobConfig)); using (FileStream file = new FileStream(configLocalFile, FileMode.Open)) { config = serializer.Deserialize(file) as SPDashTimerJobConfig; file.Close(); } //gather data sources string[] data = { "Add Remove Programs", "WEB PART files in INETPUB", "FEATURE folder in SP hive", "File Versions", "Global Assembly Cache (GAC)", "Local Admins", "Logical Disks", "Kerberos SPN", "Open TCP Ports", "SYS files (pagefile,hiberfil)", "Windows Services", "XPath web.config", "XPath apphost.config", "WMI" }; foreach (string d in data) { GatherData(d); } }
public string UpdateFarmPropertyCentral(string propName, string propValue) { string returner = "true"; try { SPSecurity.RunWithElevatedPrivileges(delegate() { System.Web.HttpContext.Current.Items["FormDigestValidated"] = true; Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb = SPAdministrationWebApplication.Local; string centralAdminUrl = centralWeb.Sites[0].Url; string callCommandUrl = centralAdminUrl + "/_vti_bin/CUSTOM/PiwikPROFarmOperationsServiceCentral.svc/UpdateFarmProperty?propName=" + propName + "&propValue=" + propValue; string json = "{ \"propName\" : \"" + propName + "\", \"propValue\" : \"" + propValue + "\" }"; ServicePointManager.Expect100Continue = true; if (centralAdminUrl.ToString().Contains("https")) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; } HttpWebRequest HttpRequest = (HttpWebRequest)HttpWebRequest.Create(callCommandUrl); HttpRequest.Method = "POST"; HttpRequest.Accept = "application/json; odata=verbose"; HttpRequest.ContentType = "application/json;odata=verbose"; HttpRequest.ContentLength = json.Length; HttpRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); HttpRequest.Credentials = CredentialCache.DefaultNetworkCredentials; HttpRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); using (var streamWriter = new StreamWriter(HttpRequest.GetRequestStream())) { streamWriter.Write(json); } WebResponse response = HttpRequest.GetResponse(); string returnerXml = string.Empty; using (var streamReader = new StreamReader(response.GetResponseStream())) { returnerXml = streamReader.ReadToEnd(); } returner = returnerXml; }); } catch (Exception ex) { Logger.WriteLog(Logger.Category.Unexpected, "Piwik UpdateFarmPropertyCentral", ex.Message); returner = ex.Message; } return(returner); }