Esempio n. 1
0
        /// <summary>
        /// A site is being deleted.
        /// </summary>
        public override void SiteDeleting(SPWebEventProperties properties)
        {
            try
            {
                SPWeb         web        = properties.Web as SPWeb;
                SPPropertyBag currentBag = web.Properties;
                if (currentBag.ContainsKey(ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive) && currentBag[ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive] != null)
                {
                    string siteId             = currentBag[ConfigValues.PiwikPro_PropertyBag_SiteId];
                    string siteTitle          = string.Empty;
                    PropertyBagOperations pbo = new PropertyBagOperations();
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        // using (SPWeb web = new SPSite(ConfigValues.PiwikPro_PiwikAdminSiteUrl).OpenWeb())
                        // using (SPWeb webz = new SPSite(pbo.GetPropertyValueFromListByKey("piwik_adminsiteurl")).OpenWeb())
                        //{
                        ClientContext context = new ClientContext(pbo.GetPropertyValueFromListByKey(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_AdminSiteUrl)));
                        Configuration cfg     = new Configuration();
                        ListProcessor sdlo    = new ListProcessor(context, cfg, new SPLogger());
                        ListItem item         = sdlo.CheckIfElementIsAlreadyOnList(context.Web.ServerRelativeUrl);
                        if (item != null)
                        {
                            item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Deleted;
                            siteTitle = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]);
                            item.Update();
                        }
                        //}

                        PiwikPROServiceOperations pso = new PiwikPROServiceOperations(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientID),
                                                                                      pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientSecret),
                                                                                      pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_OldApiToken),
                                                                                      pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ServiceUrl), new SPLogger());
                        pso.ChangeNameSiteInPiwik("Deleted - " + Convert.ToString(siteTitle), siteId);
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(Logger.Category.Unexpected, "Piwik WebDeleting", ex.Message);
            }

            base.SiteDeleting(properties);
        }
Esempio n. 2
0
        private void AddJSToMasterFileAndCheckinAndPublish(SPItemEventProperties properties, bool isCheckOut, bool publishOrNot)
        {
            bool allowunsafeUpdates = properties.Web.AllowUnsafeUpdates;

            //File.Versions[properties.ListItem.File.Versions.Count - 1]
            System.Text.ASCIIEncoding enc           = new System.Text.ASCIIEncoding();
            EventDisabler             eventDisabler = new EventDisabler();
            SPFile file = properties.ListItem.File;

            byte[] byteArrayOfFile = file.OpenBinary();
            if (byteArrayOfFile.Length > 0)
            {
                PropertyBagOperations pbo    = new PropertyBagOperations();
                string trackerJSScriptUrl    = pbo.GetPropertyValueFromListByKey("piwik_trackerjsscripturl");
                string strFileContentsBefore = enc.GetString(byteArrayOfFile);
                //check if javascript exists
                if (!strFileContentsBefore.ToLower().Contains(trackerJSScriptUrl.ToLower()))
                {
                    string newStr = AddJSRefToFile(strFileContentsBefore, trackerJSScriptUrl);
                    byte[] byteArrayFileContentsAfter = null;
                    if (!newStr.Equals(""))
                    {
                        //after binary to string there are ??? chars at the first line, this is the action to replace it:
                        if (newStr.Substring(0, 3).Equals("???"))
                        {
                            newStr = newStr.Replace("???", "");
                        }
                        byteArrayFileContentsAfter = enc.GetBytes(newStr);
                        eventDisabler.DisableEvents();
                        this.EventFiringEnabled = false;
                        if (isCheckOut)
                        {
                            properties.ListItem.File.CheckOut();
                        }
                        properties.ListItem.File.SaveBinary(byteArrayFileContentsAfter);

                        properties.ListItem.File.Update();

                        try
                        {
                            properties.Web.AllowUnsafeUpdates = true;
                            // Checks if the File is checked out by a user
                            if (properties.ListItem.File.Level == SPFileLevel.Checkout)
                            {
                                // Check in if its checked out
                                properties.ListItem.File.CheckIn("", SPCheckinType.MajorCheckIn);
                            }
                            // Publish / Approve the file...
                            if (publishOrNot && properties.ListItem.File.Level == SPFileLevel.Draft)
                            {
                                if (properties.ListItem.File.DocumentLibrary.EnableModeration)
                                {
                                    properties.ListItem.File.Approve("");
                                }
                                else
                                {
                                    properties.ListItem.File.Publish("");
                                }
                            }
                            properties.ListItem.File.Update();
                        }
                        catch (Exception ex)
                        {
                            Logger.WriteLog(Logger.Category.Unexpected, "Piwik AddJSToMasterFileAndCheckinAndPublish", ex.Message);
                        }
                        finally
                        {
                            this.EventFiringEnabled = true;
                        }
                    }
                }
            }
            properties.Web.AllowUnsafeUpdates = allowunsafeUpdates;
        }
Esempio n. 3
0
 public Configuration()
 {
     this.pbo = new PropertyBagOperations();
 }