public void ExecuteEmptyTopLevelSiteRelativeUrlTest()
        {
            SPSite fakeSite = Isolate.Fake.Instance <SPSite>(Members.ReturnRecursiveFakes);

            Isolate.Swap.NextInstance <SPSite>().With(fakeSite);
            SPWeb fakeWeb = fakeSite.RootWeb.Webs.Add("", "", "", uint.MinValue, "", false, false);

            Isolate.WhenCalled(() => fakeWeb.Url).WillReturn("http://localhost/unittest");
            SPPropertyBag fakePropertyBag = fakeWeb.Properties;

            CreateSubSiteActivity_Accessor target = new CreateSubSiteActivity_Accessor();

            target.BusinessEvent      = "unittest";
            target.BusinessEventId    = "1";
            target.BusinessEventIdKey = "unittestid";
            target.SiteCollectionUrl  = "http://localhost";
            target.SiteTemplateName   = "testtemplate";

            ActivityExecutionContext executionContext = null;

            ActivityExecutionStatus expected = new ActivityExecutionStatus();

            expected = ActivityExecutionStatus.Closed;
            ActivityExecutionStatus actual;

            actual = target.Execute(executionContext);

            Isolate.Verify.WasCalledWithAnyArguments(() => fakeSite.RootWeb.Webs.Add("", "", "", uint.MinValue, "", false, false));
            Isolate.Verify.WasCalledWithExactArguments(() => fakePropertyBag["unittestid"] = "1");
            Isolate.Verify.WasCalledWithAnyArguments(() => fakePropertyBag.Update());
            Assert.AreEqual(target.SubSiteUrl, "http://localhost/unittest");
            Assert.AreEqual(expected, actual);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            using (GlymaConfiguration configuration = new GlymaConfiguration(Identity, this))
            {
                if (string.IsNullOrEmpty(configuration.SecurityDbName) || string.IsNullOrEmpty(configuration.SecurityDbServer))
                {
                    WriteWarning("The provided site doesn't have a valid Security database server or Security database name declared. Aborting securable context creation.");
                    return;
                }

                string connectionString = "Data Source=" + configuration.SecurityDbServer + ";Initial Catalog=" + configuration.SecurityDbName + ";Integrated Security=True";

                using (SecurityDatabaseDataContext dataContext = new SecurityDatabaseDataContext(connectionString))
                {
                    SecurableContext securableContext = new SecurableContext();
                    securableContext.SecurableContextName = SecurableContextName;
                    securableContext.SecurableContextUid  = Guid.NewGuid();
                    securableContext.SiteSPID             = configuration.Site.ID;

                    dataContext.SecurableContexts.InsertOnSubmit(securableContext);
                    dataContext.SubmitChanges();

                    SPPropertyBag properties = configuration.SecurityWeb.Properties;

                    properties["Glyma.SecurableContextId"] = securableContext.SecurableContextId.ToString();
                    properties.Update();
                    configuration.SecurityWeb.Update();
                }
            }
        }
        public SPPropertyBagInstance(ObjectInstance prototype, SPPropertyBag propertyBag)
            : this(prototype)
        {
            if (propertyBag == null)
            {
                throw new ArgumentNullException("propertyBag");
            }

            m_propertyBag = propertyBag;
        }
Beispiel #4
0
        public PropertyBagCollection(object parent, SPPropertyBag property)
        {
            this.Text = SPMLocalization.GetString("PropertyBag_Text");
            this.ToolTipText = SPMLocalization.GetString("PropertyBag_ToolTip");
            this.Name = "Property Bag";
            this.Tag = property;
            this.SPParent = parent;

            int index = Program.Window.Explorer.AddImage(this.ImageUrl());
            this.ImageIndex = index;
            this.SelectedImageIndex = index;

            this.Nodes.Add("Dummy");
        }
        public PropertyBagCollection(object parent, SPPropertyBag property)
        {
            this.Text        = SPMLocalization.GetString("PropertyBag_Text");
            this.ToolTipText = SPMLocalization.GetString("PropertyBag_ToolTip");
            this.Name        = "Property Bag";
            this.Tag         = property;
            this.SPParent    = parent;

            int index = Program.Window.Explorer.AddImage(this.ImageUrl());

            this.ImageIndex         = index;
            this.SelectedImageIndex = index;

            this.Nodes.Add("Dummy");
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            SPWeb webToConfigure = GetWebFromIdentity(Identity);

            if (webToConfigure == null)
            {
                WriteWarning("No valid 'Identity' specified. Identity must be a SPSite, SPWeb, site/web URL, or site colleciton ID.");
            }

            string transactionDatabaseServer;

            if (string.IsNullOrEmpty(TransactionDatabaseServer))
            {
                transactionDatabaseServer = DatabaseServer;
            }
            else
            {
                transactionDatabaseServer = TransactionDatabaseServer;
            }

            string securityDatabaseServer;

            if (string.IsNullOrEmpty(SecurityDatabaseServer))
            {
                securityDatabaseServer = DatabaseServer;
            }
            else
            {
                securityDatabaseServer = TransactionDatabaseServer;
            }

            SPPropertyBag propertyBag = webToConfigure.Properties;

            propertyBag["Glyma.DatabaseServer"]            = DatabaseServer;
            propertyBag["Glyma.DatabaseName"]              = MapDatabaseName;
            propertyBag["Glyma.TransactionDatabaseServer"] = transactionDatabaseServer;
            propertyBag["Glyma.TransactionDatabaseName"]   = TransactionDatabaseName;
            propertyBag["Glyma.SecurityDatabaseServer"]    = securityDatabaseServer;
            propertyBag["Glyma.SecurityDatabaseName"]      = SecurityDatabaseName;
            propertyBag["Glyma.DefaultPage"] = DefaultPageUrl;

            propertyBag.Update();
            webToConfigure.Update();
        }
Beispiel #7
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);
        }
Beispiel #8
0
        /// <summary>
        /// Get the Blacklist Items from PropertyBag as String Array
        /// </summary>
        /// <param name="siteUrl">The Url of the Site Collection</param>
        /// <returns></returns>
        public static string[] GetBlackList(string siteUrl)
        {
            using (SPSite site = new SPSite(siteUrl))
            {
                SPPropertyBag props = site.RootWeb.Properties;

                // Property is already there
                if (props.ContainsKey(Names.PROPBAG_BLACKLIST_KEY))
                {
                    return(props[Names.PROPBAG_BLACKLIST_KEY].Split(';'));
                }
                // Property is not set -> set it from default Value
                else
                {
                    props.Add(Names.PROPBAG_BLACKLIST_KEY, string.Join(";", Names.BLACKLIST_DOCUMENTLIBRARIES));
                    props.Update();

                    return(Names.BLACKLIST_DOCUMENTLIBRARIES);
                }
            }
        }
        public void ExecuteTest()
        {
            SPSite fakeSite = Isolate.Fake.Instance <SPSite>(Members.ReturnRecursiveFakes);

            Isolate.Swap.NextInstance <SPSite>().With(fakeSite);
            SPWeb         fakeWeb         = fakeSite.OpenWeb();
            SPPropertyBag fakePropertyBag = fakeWeb.Properties;

            SynchronizeStatusActivity_Accessor target = new SynchronizeStatusActivity_Accessor();

            target.Status       = "active";
            target.TargetWebUrl = "http://localhost";


            ActivityExecutionContext executionContext = null;
            ActivityExecutionStatus  expected         = ActivityExecutionStatus.Closed;
            ActivityExecutionStatus  actual;

            actual = target.Execute(executionContext);

            Isolate.Verify.WasCalledWithExactArguments(() => fakePropertyBag["Status"] = "active");
            Isolate.Verify.WasCalledWithAnyArguments(() => fakePropertyBag.Update());
            Assert.AreEqual(expected, actual);
        }
Beispiel #10
0
        private void AddGoalToPiwikAndWriteToPropertyBag(PiwikPROServiceOperations pso, bool?goalTrack, string idSite, string propBagName, string goalAction, SPPropertyBag currentBag, SPWeb webToPropertyBag)
        {
            try
            {
                // if (goalTrack != null && goalTrack == true)
                // {
                // int DocumentAddedGoalId = pso.AddGoalToPiwik(idSite, goalAction);

                if (currentBag.ContainsKey(propBagName) && currentBag[propBagName] != null)
                {
                    if (String.IsNullOrEmpty(currentBag[propBagName]))
                    {
                        int DocumentAddedGoalId = pso.AddGoalToPiwik(idSite, goalAction);
                        currentBag[propBagName] = Convert.ToString(DocumentAddedGoalId);
                        currentBag.Update();
                    }
                    // currentBag[propBagName] = Convert.ToString(DocumentAddedGoalId);
                    // currentBag.Update();
                    // webToPropertyBag.Properties.Update();
                    // webToPropertyBag.Update();
                }
                else
                {
                    int DocumentAddedGoalId = pso.AddGoalToPiwik(idSite, goalAction);
                    currentBag.Add(propBagName, Convert.ToString(DocumentAddedGoalId));
                    currentBag.Update();
                }
                // }
            }
            catch (Exception ex)
            {
                //Logger.WriteLog(Logger.Category.Unexpected, "Piwik AddGoalToPiwikAndWriteToPropertyBag", ex.Message);
            }
        }
Beispiel #11
0
        public override void Execute(Guid contentDbId)
        {
            try {
                PropertyBagOperations pbo = new PropertyBagOperations();
                // using (SPWeb web = new SPSite(ConfigValues.PiwikPro_PiwikAdminSiteUrl).OpenWeb())
                // using (SPWeb web = new SPSite(pbo.GetPropertyValueFromListByKey("piwik_adminsiteurl")).OpenWeb())
                // {
                Configuration cfg           = new Configuration();
                ClientContext clientContext = new ClientContext(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ServiceUrl));
                ListProcessor sdlo          = new ListProcessor(clientContext, cfg);

                //Get all Sites with status "New" and put it to Piwik
                foreach (ListItem item in sdlo.GetAllNewSites())
                {
                    //connect to service and create new site
                    PiwikPROServiceOperations pso = new PiwikPROServiceOperations(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientID),
                                                                                  pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientSecret),
                                                                                  pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ServiceUrl),
                                                                                  pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_OldApiToken));
                    SPFieldUrlValue valueUrl             = new SPFieldUrlValue(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url]));
                    string          idSite               = string.Empty;
                    bool            isSiteAlreadyOnPiwik = false;
                    if (!string.IsNullOrEmpty(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID])))
                    {
                        isSiteAlreadyOnPiwik = pso.CheckIfPageIsAlreadyOnPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]));
                    }
                    if (isSiteAlreadyOnPiwik)
                    {
                        idSite = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]);
                        pso.ChangeNameSiteInPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), idSite);
                    }
                    else
                    {
                        idSite = pso.AddSiteToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), valueUrl.Url);
                    }

                    if (idSite.Contains("Error: "))
                    {
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_Status]   = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error;
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite;
                    }
                    else
                    {
                        try
                        {
                            bool?ShouldTrackDocumentAddedGoal = null;
                            bool?ShouldTrackPageAddedGoal     = null;
                            bool?ShouldTrackPageEditedGoal    = null;

                            using (SPWeb webToPropertyBag = new SPSite(valueUrl.Url).OpenWeb())
                            {
                                bool oldAllowUnsafeUpdates = webToPropertyBag.AllowUnsafeUpdates;
                                webToPropertyBag.AllowUnsafeUpdates = true;

                                //create/update values in propbag
                                SPPropertyBag currentBag = webToPropertyBag.Properties;
                                if (isSiteAlreadyOnPiwik)
                                {
                                    //operations if site was active before
                                }
                                else
                                {
                                    //copy template values from piwikadmin
                                    foreach (PropertyBagEntity pbe in pbo.PropertyBagList)
                                    {
                                        if (pbe.PropertyTitle.StartsWith("Template"))
                                        {
                                            CreateOrUpdateValueInPropertyBag(pbe.PropertyValue, webToPropertyBag, currentBag, pbe.PropertyName.Replace("template", ""));
                                        }
                                    }
                                }

                                CreateOrUpdateValueInPropertyBag(idSite, webToPropertyBag, currentBag, ConfigValues.PiwikPro_PropertyBag_SiteId);
                                CreateOrUpdateValueInPropertyBag("true", webToPropertyBag, currentBag, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive);

                                //set gdpr off
                                pso.SetSetGdprOffInPiwik(idSite);

                                //Prepare goals
                                ShouldTrackDocumentAddedGoal = CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackDocumentAddedGoal]);
                                ShouldTrackPageAddedGoal     = CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageAddedGoal]);
                                ShouldTrackPageEditedGoal    = CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageEditedGoal]);


                                //Add goals to Piwik site
                                AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackDocumentAddedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_DocumentAddedGoalId, "Document added", currentBag, webToPropertyBag);
                                AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackPageAddedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_PageAddedGoalId, "Page added", currentBag, webToPropertyBag);
                                AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackPageEditedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_PageEditedGoalId, "Page edited", currentBag, webToPropertyBag);

                                AddPropBagValuesToIndexedProperties(webToPropertyBag);

                                webToPropertyBag.AllowUnsafeUpdates = oldAllowUnsafeUpdates;
                            }
                        }
                        catch (Exception exp)
                        {
                            item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = exp.Message;
                        }

                        item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Active;
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID] = idSite;
                    }

                    item.Update();
                    //PiwikPROServiceOperations pso = new PiwikPROServiceOperations();
                    // pso.RemoveSiteFromPiwik("4206f53d-c12a-4d63-a87c-677760ea58d8");
                }

                //Get all sites with status "Deactivating" and remove from Piwik
                foreach (ListItem item in sdlo.GetAllDeactivatingSites())
                {
                    //connect to service and deactivate
                    PiwikPROServiceOperations pso = new PiwikPROServiceOperations();
                    string          idSite        = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]);
                    SPFieldUrlValue valueUrl      = new SPFieldUrlValue(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url]));
                    //idSite = pso.RemoveSiteFromPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]));
                    pso.ChangeNameSiteInPiwik("Inactive - " + Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), idSite);
                    if (idSite.Contains("Error: "))
                    {
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_Status]   = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error;
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite;
                    }
                    else
                    {
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_NoActive;
                    }

                    item.Update();

                    using (SPWeb webToPropertyBag = new SPSite(valueUrl.Url).OpenWeb())
                    {
                        bool oldAllowUnsafeUpdates = webToPropertyBag.AllowUnsafeUpdates;
                        webToPropertyBag.AllowUnsafeUpdates = true;

                        //create/update values in propbag
                        SPPropertyBag currentBag = webToPropertyBag.Properties;
                        CreateOrUpdateValueInPropertyBag("false", webToPropertyBag, currentBag, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive);

                        webToPropertyBag.AllowUnsafeUpdates = oldAllowUnsafeUpdates;
                    }
                }

                //Get all sites with status "Settings updated" and update goals in Piwik
                foreach (ListItem item in sdlo.GetAllSettingsUpdatedSites())
                {
                    //connect to service and deactivate
                    PiwikPROServiceOperations pso = new PiwikPROServiceOperations();
                    string idSite = string.Empty;
                    idSite = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]);
                    SPFieldUrlValue valueUrl         = new SPFieldUrlValue(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url]));
                    string          pwkChangedValues = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_PropChanged]);
                    using (SPWeb webToPropertyBag = new SPSite(valueUrl.Url).OpenWeb())
                    {
                        SPPropertyBag currentBag = webToPropertyBag.Properties;

                        foreach (string pwkValue in pwkChangedValues.Split(';'))
                        {
                            if (pwkValue != null)
                            {
                                if (pwkValue.Split('|')[0] == "ShouldTrackDocumentAddedGoal" && pwkValue.Split('|')[1].ToLower() == "true")
                                {
                                    AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_DocumentAddedGoalId, "Document added", currentBag, webToPropertyBag);
                                }
                                if (pwkValue.Split('|')[0] == "ShouldTrackPageAddedGoal" && pwkValue.Split('|')[1].ToLower() == "true")
                                {
                                    AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_PageAddedGoalId, "Page added", currentBag, webToPropertyBag);
                                }
                                if (pwkValue.Split('|')[0] == "ShouldTrackPageEditedGoal" && pwkValue.Split('|')[1].ToLower() == "true")
                                {
                                    AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_PageEditedGoalId, "Page edited", currentBag, webToPropertyBag);
                                }
                            }
                        }
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_PropChanged] = "";

                        //pso.UpdateGoalToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]), "Document added", currentBag[ConfigValues.PiwikPro_PropertyBag_DocumentAddedGoalId], CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackDocumentAddedGoal]));
                        //pso.UpdateGoalToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]), "Page added", currentBag[ConfigValues.PiwikPro_PropertyBag_PageAddedGoalId], CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageAddedGoal]));
                        //pso.UpdateGoalToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]), "Page edited", currentBag[ConfigValues.PiwikPro_PropertyBag_PageEditedGoalId], CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageEditedGoal]));
                    }
                    if (idSite.Contains("Error: "))
                    {
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_Status]   = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error;
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite;
                    }
                    else
                    {
                        item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Active;
                    }

                    item.Update();
                }


                //}
            } catch (Exception ex) {
                // Logger.WriteLog(Logger.Category.Unexpected, "Piwik Execute TimerJob", ex.Message);
            }
        }
Beispiel #12
0
 private static void CreateOrUpdateValueInPropertyBag(string value, SPWeb webToPropertyBag, SPPropertyBag currentBag, string propertyBagKey)
 {
     if (currentBag.ContainsKey(propertyBagKey) && currentBag[propertyBagKey] != null)
     {
         currentBag[propertyBagKey] = value;
         currentBag.Update();
         webToPropertyBag.Properties.Update();
         webToPropertyBag.Update();
     }
     else
     {
         currentBag.Add(propertyBagKey, value);
         currentBag.Update();
     }
 }
Beispiel #13
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            SPWeb webToConfigure = GetRootWebFromIdentity(Identity);

            if (webToConfigure == null)
            {
                WriteWarning("No valid 'Identity' specified. Identity must be a SPSite, SPWeb, site/web URL, or site colleciton ID.");
            }

            bool hasProjectManagerRole = false;
            bool hasMapManagerRole     = false;
            bool hasAuthorRole         = false;
            bool hasReaderRole         = false;

            foreach (SPRoleDefinition definition in webToConfigure.RoleDefinitions)
            {
                if (definition.Name == GlymaProjectManagerRoleName)
                {
                    hasProjectManagerRole = true;
                }

                if (definition.Name == GlymaMapManagerRoleName)
                {
                    hasMapManagerRole = true;
                }

                if (definition.Name == GlymaAuthorRoleName)
                {
                    hasAuthorRole = true;
                }

                if (definition.Name == GlymaReaderRoleName)
                {
                    hasReaderRole = true;
                }

                if (hasProjectManagerRole && hasMapManagerRole && hasReaderRole && hasAuthorRole)
                {
                    break;
                }
            }

            if (!hasProjectManagerRole)
            {
                SPRoleDefinition glymaProjectManagerRole = new SPRoleDefinition();
                glymaProjectManagerRole.Name            = GlymaProjectManagerRoleName;
                glymaProjectManagerRole.Description     = "Users have access to create and modify projects in a Glyma map database.";
                glymaProjectManagerRole.BasePermissions = SPBasePermissions.EmptyMask;

                webToConfigure.RoleDefinitions.Add(glymaProjectManagerRole);
            }

            if (!hasMapManagerRole)
            {
                SPRoleDefinition glymaMapManagerRole = new SPRoleDefinition();
                glymaMapManagerRole.Name            = GlymaMapManagerRoleName;
                glymaMapManagerRole.Description     = "Users have access to create and modify root maps in a Glyma Project.";
                glymaMapManagerRole.BasePermissions = SPBasePermissions.EmptyMask;

                webToConfigure.RoleDefinitions.Add(glymaMapManagerRole);
            }

            if (!hasAuthorRole)
            {
                SPRoleDefinition glymaAuthorRole = new SPRoleDefinition();
                glymaAuthorRole.Name            = GlymaAuthorRoleName;
                glymaAuthorRole.Description     = "Users have access to create and modify Glyma maps.";
                glymaAuthorRole.BasePermissions = SPBasePermissions.EmptyMask;

                webToConfigure.RoleDefinitions.Add(glymaAuthorRole);
            }

            if (!hasReaderRole)
            {
                SPRoleDefinition glymaReaderRole = new SPRoleDefinition();
                glymaReaderRole.Name            = GlymaReaderRoleName;
                glymaReaderRole.Description     = "Users have access to read Glyma maps.";
                glymaReaderRole.BasePermissions = SPBasePermissions.EmptyMask;

                webToConfigure.RoleDefinitions.Add(glymaReaderRole);
            }

            SPPropertyBag propertyBag = webToConfigure.Properties;

            propertyBag["Glyma.RolesDefined"] = "true";

            propertyBag.Update();

            if (!hasReaderRole || !hasAuthorRole)
            {
                webToConfigure.Update();
            }
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            const string
            //requestUrl = "http://nozhenko-s8k/",
                requestUrl = "http://tba/",
            //SPWeb = "DocNet",
                SPWeb      = "TBADocNet",
                SPListName = "Чернетки внутрішніх документів", //"Внутрішні документи", //"Задачі", //"TaskReports",
                FieldName  = "dn_ct_ProjectDocument";

            using (SPSite spSite = new SPSite(requestUrl))
            {
                #if TEST_UPDATE
                TestUpdate(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_LOAD_ITEM
                TestLoadItem(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_FILE
                TestFile(spSite.AllWebs[SPWeb]);
                #endif

                #if GET_INFO
                GetInfo(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_DETAIL_VIEW
                TestDetailView(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_CUSTOM_FIELD
                TestCustomField(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_CONTENT_TYPE
                TestContentType(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_EVENTS
                TestEvents(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_VIEW_FIELDS
                TestViewFields(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_FIELD
                TestField(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_USERS
                SPList spListUsers = spSite.RootWeb.Lists["User Information List" /*"Список відомостей про користувачів"*/ /*"_catalogs/users"*/];
                ShowFields(spListUsers);
                SPListItem spListItemUser = spListUsers.GetItemById(1);

                foreach (SPUser spUser in spSite.AllWebs[SPWeb].AllUsers)
                {
                    Console.WriteLine("{{ID: {0}, Name: {1}, LoginName: {2}}}", spUser.ID, spUser.Name, spUser.LoginName);
                }
                #endif

                #if TEST_LOOKUP_FIELDS
                TestLookupFields(spSite.AllWebs[SPWeb]);
                #endif

                #if TEST_SPQUERY
                TestSPQuery(spSite.AllWebs[SPWeb]);
                #endif

                #if SHOW_INFO
                SPWebCollection
                    spWebCollection = spSite.AllWebs;

                foreach (SPWeb spWeb in spWebCollection)
                {
                    Console.WriteLine("Name: \"{0}\"", spWeb.Name);

                    SPListCollection
                        spListCollection = spWeb.Lists;

                    foreach (SPList _spList in spListCollection)
                    {
                        Console.WriteLine("\tTitle: \"{0}\"", _spList.Title);
                    }
                }
                #endif

                SPPropertyBag
                    props = spSite.AllWebs[SPWeb].Properties;

                foreach (DictionaryEntry de in props)
                {
                    Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
                }

                SPList
                    spList = spSite.AllWebs[SPWeb].Lists[SPListName];

                #if SHOW_INFO
                foreach (SPField f in spList.Fields)
                {
                    Console.WriteLine("Title: {0}", f.Title);
                }
                #endif

                SPListItemCollection
                    spListItemCollection = spList.Items;

                bool
                    ShowAll = false;

                foreach (SPListItem item in spListItemCollection)
                {
                    if (item[FieldName] != null)
                    {
                        SPFieldLookupValue
                                    spFieldLookupValue = (SPFieldLookupValue)item[FieldName];

                        string
                            tmpString = item[FieldName].ToString();

                        Console.WriteLine("{0}\t{1}", tmpString, spFieldLookupValue.LookupId);
                    }

                    if (ShowAll)
                    {
                        Console.WriteLine();
                        foreach (SPField f in item.Fields)
                        {
                            Console.WriteLine("\"{0}\" = \"{1}\"", f.Title, item[f.Title]);
                        }
                        Console.WriteLine();

                        ShowAll = false;
                    }
                }
            }

            Console.ReadLine();
        }
Beispiel #15
0
        public void AddRoleDefinitions()
        {
            bool hasProjectManagerRole = false;
            bool hasMapManagerRole     = false;
            bool hasAuthorRole         = false;
            bool hasReaderRole         = false;

            foreach (SPRoleDefinition definition in Site.RoleDefinitions)
            {
                if (definition.Name == GlymaProjectManagerRoleName)
                {
                    hasProjectManagerRole = true;
                }

                if (definition.Name == GlymaMapManagerRoleName)
                {
                    hasMapManagerRole = true;
                }

                if (definition.Name == GlymaAuthorRoleName)
                {
                    hasAuthorRole = true;
                }

                if (definition.Name == GlymaReaderRoleName)
                {
                    hasReaderRole = true;
                }

                if (hasProjectManagerRole && hasMapManagerRole && hasReaderRole && hasAuthorRole)
                {
                    break;
                }
            }

            if (!hasProjectManagerRole)
            {
                SPRoleDefinition glymaProjectManagerRole = new SPRoleDefinition();
                glymaProjectManagerRole.Name            = GlymaProjectManagerRoleName;
                glymaProjectManagerRole.Description     = "Users have access to create and modify projects in a Glyma map database.";
                glymaProjectManagerRole.BasePermissions = SPBasePermissions.EmptyMask;

                Site.RoleDefinitions.Add(glymaProjectManagerRole);
            }

            if (!hasMapManagerRole)
            {
                SPRoleDefinition glymaMapManagerRole = new SPRoleDefinition();
                glymaMapManagerRole.Name            = GlymaMapManagerRoleName;
                glymaMapManagerRole.Description     = "Users have access to create and modify root maps in a Glyma Project.";
                glymaMapManagerRole.BasePermissions = SPBasePermissions.EmptyMask;

                Site.RoleDefinitions.Add(glymaMapManagerRole);
            }

            if (!hasAuthorRole)
            {
                SPRoleDefinition glymaAuthorRole = new SPRoleDefinition();
                glymaAuthorRole.Name            = GlymaAuthorRoleName;
                glymaAuthorRole.Description     = "Users have access to create and modify Glyma maps.";
                glymaAuthorRole.BasePermissions = SPBasePermissions.EmptyMask;

                Site.RoleDefinitions.Add(glymaAuthorRole);
            }

            if (!hasReaderRole)
            {
                SPRoleDefinition glymaReaderRole = new SPRoleDefinition();
                glymaReaderRole.Name            = GlymaReaderRoleName;
                glymaReaderRole.Description     = "Users have access to read Glyma maps.";
                glymaReaderRole.BasePermissions = SPBasePermissions.EmptyMask;

                Site.RoleDefinitions.Add(glymaReaderRole);
            }

            SPPropertyBag propertyBag = Site.Properties;

            propertyBag["Glyma.RolesDefined"] = "true";

            propertyBag.Update();

            if (!hasReaderRole || !hasAuthorRole)
            {
                Site.Update();
            }
        }
Beispiel #16
0
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            try
            {
                SPListItem item = properties.ListItem;
                if (item != null)
                {
                    //check if item is master file
                    if (properties.ListItem.File.Name.ToLower().EndsWith(".master"))
                    {
                        //in case of publish
                        if (Convert.ToString(properties.AfterProperties["vti_doclibmodstat"]) == Convert.ToString((int)SPModerationStatusType.Approved))
                        {
                            //in case if the list requires check out of document
                            if (properties.List.ForceCheckout)
                            {
                                AddJSToMasterFileAndCheckinAndPublish(properties, true, true);
                            }
                            else
                            {
                                AddJSToMasterFileAndCheckinAndPublish(properties, false, true);
                            }
                        }
                        //in case of upload new doc
                        else
                        {
                            //in case if the list requires check out of document
                            if (properties.List.ForceCheckout)
                            {
                                if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null &&
                                    properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
                                {
                                    AddJSToMasterFileAndCheckinAndPublish(properties, true, false);
                                }
                            }
                            else
                            {
                                SPPropertyBag currentBag = item.Web.Properties;
                                string        docID      = item.UniqueId.ToString();
                                if ((currentBag.ContainsKey(docID) && currentBag[docID] != null) || properties.ListItem.File.Versions.Count == 0)
                                {
                                    currentBag[docID] = null;
                                    currentBag.Update();
                                    item.Web.Update();
                                    AddJSToMasterFileAndCheckinAndPublish(properties, false, false);
                                }
                                else
                                {
                                    currentBag.Add(docID, "added");
                                    currentBag.Update();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(Logger.Category.Unexpected, "Piwik ItemUpdated", ex.Message);
            }

            base.ItemUpdated(properties);
        }