Пример #1
0
        public static void LogMessage(ActivityExecutionContext executionContext, SPWorkflowHistoryEventType eventType, string outcome, string message, int userID, bool ccULS)
        {
            try
            {
                //write to Workflow History List
                ISharePointService spService = (ISharePointService)executionContext.GetService(typeof(ISharePointService));
                spService.LogToHistoryList(executionContext.ContextGuid, eventType, userID, TimeSpan.MinValue, outcome, message, message);

                //Write to ULS trace log
                if (ccULS)
                {
                    string source = executionContext.Activity.Name;
                    TraceProvider.TraceSeverity traceSeverity = TraceProvider.TraceSeverity.InformationEvent;

                    if (eventType == SPWorkflowHistoryEventType.WorkflowError)
                    {
                        traceSeverity = TraceProvider.TraceSeverity.Exception;
                    }

                    ULS.LogMessage(source, message, "Site Management", traceSeverity);
                }
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("SiteManagementActivity", "History Logging Failed:" + ex.ToString());
            }
        }
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
#if DEBUG
            Debugger.Break();
#endif
            ULS.LogMessage(ULS_PRODUCT_NAME, string.Format("Started Activation of {0} feature", FEATURE_NAME), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
            SPSite siteCollection = properties.Feature.Parent as SPSite;
            if (siteCollection != null)
            {
                ULS.LogMessage(ULS_PRODUCT_NAME, string.Format("Started Activation of {0} feature for {1}", FEATURE_NAME, siteCollection.Port), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
                SPWeb topLevelSite = siteCollection.RootWeb;

                // Calculate relative path to site from Web Application root.
                string WebAppRelativePath = topLevelSite.ServerRelativeUrl;
                if (!WebAppRelativePath.EndsWith("/"))
                {
                    WebAppRelativePath += "/";
                }

                ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Processed: {0}", topLevelSite.Title), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);

                // Enumerate through each site and apply branding.
                foreach (SPWeb site in siteCollection.AllWebs)
                {
                    try
                    {
                        ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Started Activating {0} Feature in the {1} site ", FEATURE_NAME, site.Name), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
                        site.AllowUnsafeUpdates = true;
                        site.MasterUrl          = WebAppRelativePath + customizedMasterUrl;
                        site.CustomMasterUrl    = WebAppRelativePath + customizedMasterUrl;
                        site.AlternateCssUrl    = WebAppRelativePath + alternateCSSUrl;
                        //site.SiteLogoUrl = WebAppRelativePath + "Style%20Library/Branding101/Images/Logo.gif";
                        site.SiteLogoUrl = "";
                        site.UIVersion   = 4;
                        site.Update();
                        site.AllowUnsafeUpdates = false;
                    }
                    catch (Exception ex)
                    {
                        ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("{0};{1}", ex.Message, ex.StackTrace), Microsoft.SharePoint.Administration.TraceSeverity.Unexpected, Microsoft.SharePoint.Administration.EventSeverity.Error);
                    }
                    finally
                    {
                        if (site != null)
                        {
                            site.Dispose();
                        }
                        ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Finished Activating {0} Feature in the {1} site ", FEATURE_NAME, site.Name), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Get the application name that corresponds to the fully qualified domain name.
        /// </summary>
        /// <param name="fqdn">The fully qualified domain name.</param>
        /// <param name="connString">The connection string for this provider.</param>
        /// <returns>The application name.</returns>
        private string GetMappedAppName(string fqdn, string connString)
        {
            string        appName    = string.Empty;
            SqlConnection connection = null;
            SqlCommand    command    = null;

            try
            {
                connection          = new SqlConnection(connString);
                command             = new SqlCommand("dbo.aspnet_Sitemaps_GetApplicationNameByFQDN", connection);
                command.CommandType = CommandType.StoredProcedure;
                SqlParameter parameter = command.Parameters.Add("@fqdn", SqlDbType.NVarChar);
                parameter.Value = fqdn;

                // elevate permissions to allow user to read database.
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    connection.Open();
                    appName = command.ExecuteScalar() as string;
                });
                if (string.IsNullOrEmpty(appName))
                {
                    ULS.LogMessage("SQLSiteMembershipProvider.GetMappedAppName", "Could Not Get Mapped Application Name for FQDN: " + fqdn, "Membership", TraceProvider.TraceSeverity.CriticalEvent);
                }
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
                if (command != null)
                {
                    command.Dispose();
                }
            }
            return(appName);
        }
Пример #4
0
 /// <summary>
 /// When this feature is deactivated, it removes the connection string,
 /// membership provider, and role provider information from the web.config
 /// for the web application.  The People picker setting for the web app
 /// is left as is because we don't know what the correct state would be.
 /// </summary>
 public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
 {
     try
     {
         SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
         if (webApp != null)
         {
             WebConfigManager.WebConfigManager.RemoveConfiguration(webApp, _MODIFICATIONOWNER);
             ULS.LogMessage("SecProviderFeatureReceiver.FeatureDeactivating", "Feature Deactivated on web app: " + webApp.Name, "Membership", TraceProvider.TraceSeverity.InformationEvent);
         }
         else
         {
             ULS.LogMessage("SecProviderFeatureReceiver.FeatureDeactivating", "Not able to retrieve SPWebApplication", "Membership", TraceProvider.TraceSeverity.CriticalEvent);
         }
     }
     catch (Exception ex)
     {
         ULS.LogError("SecProviderFeatureReceiver.FeatureDeactivating", ex);
         throw ex;
     }
 }
Пример #5
0
 /// <summary>
 /// When this feature is activated it adds connection string, membership
 /// provider, and role provider entries into the web.config for the
 /// web application.
 ///
 /// It also sets the web application's people picker to only search within
 /// the current site collection
 /// </summary>
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
 {
     try
     {
         SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
         if (webApp != null)
         {
             WebConfigManager.WebConfigManager.AddConfigModifications(webApp, _MODIFICATIONOWNER, GetWebConfigMods());
             webApp.PeoplePickerSettings.OnlySearchWithinSiteCollection = true;
             ULS.LogMessage("SecProviderFeatureReceiver.FeatureActivated", "Feature Activated on web app: " + webApp.Name, "Membership", TraceProvider.TraceSeverity.InformationEvent);
         }
         else
         {
             ULS.LogMessage("SecProviderFeatureReceiver.FeatureActivated", "Not able to retrieve SPWebApplication", "Membership", TraceProvider.TraceSeverity.CriticalEvent);
         }
     }
     catch (Exception ex)
     {
         ULS.LogError("SecProviderFeatureReceiver.FeatureActivated", ex);
         throw ex;
     }
 }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
#if DEBUG
            Debugger.Break();
#endif
            ULS.LogMessage(ULS_PRODUCT_NAME, string.Format("Started De-activating {0}", FEATURE_NAME), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
            SPSite siteCollection = properties.Feature.Parent as SPSite;
            if (siteCollection != null)
            {
                SPWeb topLevelSite = siteCollection.RootWeb;

                ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Started De-activating {0} Feature in {1} portal ", FEATURE_NAME, siteCollection.PortalName), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);

                // Calculate relative path of site from Web Application root.
                string WebAppRelativePath = topLevelSite.ServerRelativeUrl;
                if (!WebAppRelativePath.EndsWith("/"))
                {
                    WebAppRelativePath += "/";
                }

                ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Processed: {0}", topLevelSite.Title), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);

                // Enumerate through each site and remove custom branding.
                foreach (SPWeb site in siteCollection.AllWebs)
                {
                    try
                    {
                        ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Started De-activating {0} Feature in the {1} site ", FEATURE_NAME, site.Name), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
                        site.MasterUrl       = WebAppRelativePath + defaultMasterUrl;
                        site.CustomMasterUrl = WebAppRelativePath + defaultMasterUrl;
                        site.AlternateCssUrl = "";
                        site.SiteLogoUrl     = "";
                        site.Update();
                    }
                    catch (Exception ex)
                    {
                        ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("{0};{1}", ex.Message, ex.StackTrace), Microsoft.SharePoint.Administration.TraceSeverity.Unexpected, Microsoft.SharePoint.Administration.EventSeverity.Error);
                    }
                    finally
                    {
                        if (site != null)
                        {
                            site.Dispose();
                        }
                        ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Finished De-activating {0} Feature in the {1} site ", FEATURE_NAME, site.Name), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
                    }
                }

                // Now delete the master page
                string serverRelPath = topLevelSite.ServerRelativeUrl;
                if (!serverRelPath.EndsWith("/"))
                {
                    serverRelPath += "/";
                }
                string customUrlToUse = serverRelPath + customizedMasterUrl;
                try
                {
                    using (SPWeb web = siteCollection.OpenWeb())
                    {
                        SPFile file = web.GetFile(customUrlToUse);
                        ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Started Deleting the old master page in in the {0} site ", web.Title), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
                        SPFolder masterPageGallery = file.ParentFolder;
                        SPFolder temp        = masterPageGallery.SubFolders.Add("Temp");
                        string   newFilePath = String.Format("{0}/{1}", temp.Url, file.Name);
                        file.MoveTo(newFilePath, SPMoveOperations.Overwrite);
                        SPFile movedFile = web.GetFile(newFilePath);
                        movedFile.Delete();
                        ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Finished deleting the old master page in in the {0} site ", web.Title), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
                    }
                }
                catch (Exception ex)
                {
                    ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("{0};{1}", ex.Message, ex.StackTrace), Microsoft.SharePoint.Administration.TraceSeverity.Unexpected, Microsoft.SharePoint.Administration.EventSeverity.Error);
                }
                finally
                {
                    ULS.LogMessage(ULS_PRODUCT_NAME, String.Format("Finished De-activating {0} Feature in {0} portal ", FEATURE_NAME, siteCollection.PortalName), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
                }
            }
            ULS.LogMessage(ULS_PRODUCT_NAME, string.Format("Started De-activating {0}", FEATURE_NAME), Microsoft.SharePoint.Administration.TraceSeverity.Verbose, Microsoft.SharePoint.Administration.EventSeverity.Information);
        }
Пример #7
0
        static void Main(string[] args)
        {
            try
            {
                string host                = ConfigurationManager.AppSettings.Get("popHost");
                int    port                = Convert.ToInt32(ConfigurationManager.AppSettings.Get("popPort"));
                bool   useSSL              = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("useSSL"));
                string username            = ConfigurationManager.AppSettings.Get("popUser");
                string password            = ConfigurationManager.AppSettings.Get("popPassword");
                string dropPath            = ConfigurationManager.AppSettings.Get("dropFolderPath");
                bool   traceToConsole      = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("traceToConsole"));
                bool   deleteAfterRetrieve = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("deleteAfterRetrieve"));

                TraceProvider.RegisterTraceProvider();

                using (Pop3Client popClient = new Pop3Client(host, port, useSSL, username, password))
                {
                    if (traceToConsole)
                    {
                        popClient.Trace += new Action <string>(Console.WriteLine);
                    }

                    //connects to Pop3 Server, Executes POP3 USER and PASS
                    popClient.Authenticate();
                    popClient.Stat();

                    System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
                    smtpClient.DeliveryMethod          = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = dropPath;
                    StringBuilder traceMessage = new StringBuilder("Messages To Retrieve: " + popClient.List().Count);
                    Console.WriteLine(traceMessage.ToString());
                    ULS.LogMessage("Pop Client", traceMessage.ToString(), "E-Mail", TraceProvider.TraceSeverity.InformationEvent);
                    foreach (Pop3ListItem item in popClient.List())
                    {
                        using (MailMessageEx popMessage = popClient.RetrMailMessageEx(item))
                        {
                            using (System.Net.Mail.MailMessage smtpMessage = new System.Net.Mail.MailMessage())
                            {
                                if (traceToConsole)
                                {
                                    foreach (System.Net.Mail.MailAddress toAddress in popMessage.To)
                                    {
                                        Console.WriteLine("To:  " + toAddress.Address);
                                    }
                                    Console.WriteLine("From: " + popMessage.From.Address);
                                    Console.WriteLine("Subject: " + popMessage.Subject);
                                    Console.WriteLine("Attachments: " + popMessage.Attachments.Count);
                                    foreach (System.Net.Mail.Attachment attachment in popMessage.Attachments)
                                    {
                                        Console.WriteLine("Attachment: " + attachment.Name);
                                    }
                                    Console.Write("Body: " + popMessage.Body + "\n");
                                }

                                smtpMessage.From            = popMessage.From;
                                smtpMessage.Subject         = popMessage.Subject;
                                smtpMessage.SubjectEncoding = popMessage.SubjectEncoding;
                                smtpMessage.Body            = popMessage.Body;
                                smtpMessage.BodyEncoding    = popMessage.BodyEncoding;
                                smtpMessage.Sender          = popMessage.Sender;

                                traceMessage = new StringBuilder("Message Processed:<br/>\n");

                                foreach (System.Net.Mail.MailAddress toAddress in popMessage.To)
                                {
                                    traceMessage.Append("To: " + toAddress + "<br/>\n");
                                    smtpMessage.To.Add(toAddress);
                                }
                                foreach (System.Net.Mail.MailAddress ccAddress in popMessage.CC)
                                {
                                    traceMessage.Append("CC: " + ccAddress + "<br/>\n");
                                    smtpMessage.CC.Add(ccAddress);
                                }
                                traceMessage.Append("From: " + popMessage.From.Address + "<br/>\n");
                                traceMessage.Append("Subject: " + popMessage.Subject + "<br/>\n");

                                foreach (System.Net.Mail.Attachment attachment in popMessage.Attachments)
                                {
                                    smtpMessage.Attachments.Add(attachment);
                                    traceMessage.Append("Attachment: " + attachment.Name + "<br/>\n");
                                }

                                smtpMessage.IsBodyHtml = popMessage.IsBodyHtml;

                                foreach (string key in popMessage.Headers.AllKeys)
                                {
                                    smtpMessage.Headers.Add(key, popMessage.Headers[key]);
                                }

                                ULS.LogMessage("Pop Client", traceMessage.ToString(), "E-Mail", TraceProvider.TraceSeverity.InformationEvent);

                                smtpClient.Send(smtpMessage);

                                if (deleteAfterRetrieve)
                                {
                                    popClient.Dele(item);
                                }
                            }
                        }
                    }
                    popClient.Noop();
                    if (!deleteAfterRetrieve)
                    {
                        popClient.Rset();
                    }
                    popClient.Quit();
                }
            }
            catch (Exception ex)
            {
                ULS.LogError("Pop Client", ex.ToString(), "E-Mail");
            }
            TraceProvider.UnregisterTraceProvider();
        }