Pages

Thursday, June 27, 2024

Populate ISelectionFactory with values from another block's properties

Create a Block to hold selection options

using EPiServer.Cms.Shell.UI.ObjectEditing.EditorDescriptors;

using EPiServer.PlugIn;

using EPiServer.Shell.ObjectEditing;

using System.ComponentModel.DataAnnotations;

namespace MyApp.Models.Blocks

{

    [ContentType(DisplayName = "Select Options Block", Description = "")]

    public class SelectOptionsBlock : BlockData

    {

        [CultureSpecific]     

        [Display(Name = "Selection Options", Description = "List of options for the selection list.",  GroupName = SystemTabNames.Content, Order = 100)]

        [EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<SelectionOption>))]

        public virtual IList<SelectionOption> SelectionOptions { get; set; }

    }

    public class SelectionOption

    {

        public string Text { get; set; }

        public string Value { get; set; }

    }

    [PropertyDefinitionTypePlugIn]

    public class SelectionOptionProperty : PropertyList<SelectionOption> { }

}

Create a page where you want to have the selection list and add the following 2 properties

namespace MyApp.Models.Pages

{

    [ContentType(DisplayName = "SelectionList Page", Description = "Page with a selection list populated from a block.", GroupName = SiteGroupNames.Specialized)]

    public class SelectionListPage : PageData

    {

        [CultureSpecific]

        [Display(

           Name = "Select Options Block", Description = "", GroupName = SystemTabNames.Content, Order = 1)]

        [AllowedTypes(typeof(SelectOptionsBlock))]

        public virtual ContentReference SelectOptionsBlockContent { get; set; }


        [CultureSpecific]

        [Display(Name = "Select List", Description = "",  GroupName = SystemTabNames.Content,

            Order = 1)]

        [SelectOne(SelectionFactoryType = typeof(ItemSelectionFactory))]

        public virtual string SelectList { get; set; }

    }

}

Now create a selection list factory

using EPiServer.ServiceLocation;

using EPiServer.Shell.ObjectEditing;

using SVP.Models.Blocks;

namespace MyApp.Business.SelectionFactories

{

    public class ItemSelectionFactory : ISelectionFactory

    {

        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)

        {

            var loader = ServiceLocator.Current.GetInstance<IContentLoader>();

            var list = new List<SelectItem>();            

            dynamic contentMetadata = metadata;

            var ownerContent = contentMetadata.OwnerContent as IContent;            

            //create a dynamic object of current content type

            dynamic parentItem = ownerContent;

            //check if the block containing the select options is added to the current content (page or block)

            if (parentItem.SelectOptionsBlockContent != null)

            {

                //Get the block containing select options

                var optionsBlock = loader.Get<SelectOptionsBlock> parentItem.SelectOptionsBlockContent);

                //check if the optionsBlock has any items

                if (optionsBlock.SelectionOptions != null && optionsBlock.SelectionOptions.Count > 0)

                {

                    foreach (var listItem in optionsBlock.SelectionOptions)

                    {

                        list.Add(new SelectItem() { Text = listItem.Text, Value = listItem.Value });

                    }

                }

            }

            return list;

        }

    }

}


From the CMS, create a new block of type SelectOptionsBlock and add the necessary select options and publish it.

Select this newly created block in your page that you have created to have the selection list and publish the page.

Tuesday, December 13, 2022

Shrink SQL Server Database

The following example reduces the size of the data and log files in the UserDB user database to allow for 10 percent free space in the database.

 DBCC SHRINKDATABASE (UserDB, 10);


The following example shrinks the data and log files in the AdventureWorks2022 sample database to the last assigned extent.

DBCC SHRINKDATABASE (AdventureWorks2022, TRUNCATEONLY);


The following example shrinks the size of a data file named DataFile1 in the UserDB user database to 7 MB.

USE UserDB; GO DBCC SHRINKFILE (DataFile1, 7); GO


The following example shrinks the log file in the AdventureWorks2022 database to 1 MB. To allow the DBCC SHRINKFILE command to shrink the file, the file is first truncated by setting the database recovery model to SIMPLE.

USE AdventureWorks2022; GO -- Truncate the log by changing the database recovery model to SIMPLE. ALTER DATABASE AdventureWorks2022 SET RECOVERY SIMPLE; GO -- Shrink the truncated log file to 1 MB. DBCC SHRINKFILE (AdventureWorks2022_Log, 1); GO -- Reset the database recovery model. ALTER DATABASE AdventureWorks2022 SET RECOVERY FULL; GO


The following example truncates the primary data file in the AdventureWorks2022 database. The sys.database_files catalog view is queried to obtain the file_id of the data file.

USE AdventureWorks2022; GO SELECT file_id, name FROM sys.database_files; GO DBCC SHRINKFILE (1, TRUNCATEONLY);


The following example demonstrates emptying a file so it can be removed from the database. For this example's purposes, a data file is first created and contains data.

USE AdventureWorks2022; GO -- Create a data file and assume it contains data. ALTER DATABASE AdventureWorks2022 ADD FILE ( NAME = Test1data, FILENAME = 'C:\t1data.ndf', SIZE = 5MB ); GO -- Empty the data file. DBCC SHRINKFILE (Test1data, EMPTYFILE); GO -- Remove the data file from the database. ALTER DATABASE AdventureWorks2022 REMOVE FILE Test1data; GO


The following example attempts to shrink the size of a data file in the current user database to 1 MB. The sys.database_files catalog view is queried to obtain the file_id of the data file, in this example, file_id 5. If a lock can't be obtained within one minute, the shrink operation will abort.

USE AdventureWorks2022; GO SELECT file_id, name FROM sys.database_files; GO DBCC SHRINKFILE (5, 1) WITH WAIT_AT_LOW_PRIORITY (ABORT_AFTER_WAIT = SELF);


Wednesday, November 23, 2022

Delete a language and its content from Optimizely CMS from the backend

You can download the database of the specific environment from the PAAS portal and install it locally 

To find the language id in your database run the SQL:

 
SELECT TOP 1000 [pkID]
     ,[LanguageID]
     ,[Name]
     ,[SortIndex]
     ,[SystemIconPath]
     ,[URLSegment]
     ,[ACL]
     ,[Enabled]
 FROM [YOUR_DB].[dbo].[tblLanguageBranch]
 
Example of deleting language - 7 is Spanish in my database

DELETE FROM [YOUR_DB].[dbo].[tblContentLanguage]
  WHERE fkLanguageBranchID = 7

   DELETE FROM [ YOUR_DB].[dbo].[tblContentLanguageSetting]
WHERE fkLanguageBranchID = 7

DELETE FROM [YOUR_DB].[dbo].[tblContentProperty]
  WHERE [fkContentID] IN (SELECT [pkID] FROM [YOUR_DB].[dbo].[tblContent] WHERE [fkMasterLanguageBranchID] = 7)

DELETE FROM [YOUR_DB].[dbo].[tblContentSoftlink]
  WHERE [fkOwnerContentID] IN (SELECT [pkID] FROM [YOUR_DB].[dbo].[tblContent] WHERE [fkMasterLanguageBranchID] = 7)

 DELETE FROM [YOUR_DB].[dbo].[tblContent]
  WHERE [fkMasterLanguageBranchID] = 7
 
 DELETE FROM [ YOUR_DB].[dbo].[tblLanguageBranch]
WHERE pkID = 7

After you confirm that it works locally, create a ticket with the customer support and then have them run these sql queries

Thursday, November 3, 2022

Left join using LINQ to SQL

 public IActionResult GetDealerByReference(string countryCode, string dealerId)

{

    if (string.IsNullOrEmpty(countryCode))

    return BadRequest("country code cannot be empty");

    if (string.IsNullOrEmpty(dealerId))

        return BadRequest("dealerId cannot be empty");

    string toBeReplaced = "'INSPIRA', 'OTHER', ";

    // this is of type System.Linq.IQueryable 

    var webDealerItemRestrictions = _repository.CacheJdeDealerItemRestriction.FindAll();

    // this is of type System.Linq.IQueryable 

    var webDealerAddresses = _repository.CacheJdeDealerAddress.FindAll();

    //left join webDealerAddresses with webDealerItemRestrictions

    var result = (from addresses in webDealerAddresses.Where(x => x.DealerID == dealerId &&                         x.CountryCode == countryCode)

            from restrictions in webDealerItemRestrictions

            .Where(x => addresses.DealerID == x.DealerID)

            .DefaultIfEmpty()

             select new { addresses, restrictions }).FirstOrDefault();

   if (result == null) return NotFound("Not Found");

   var webDealer = new WebDealers()

   {

    Code = result.restrictions.Code,

    Address1 = result.addresses.Address1,

    Address2 = result.addresses.Address2,

   AreaCode = result.addresses.AreaCode,

   Brands = result.addresses.BrandListing.Replace(toBeReplaced, ""),

   CountryCode = result.addresses.CountryCode,

   DealerName = result.addresses.DealerName,

   EmailAddress = result.addresses.EMailaddress,

   PhoneNumber = result.addresses.PhoneNumber

  };

  return Ok(JsonConvert.SerializeObject(new List<WebDealers>() { webDealer }));

}

Thursday, October 20, 2016

Keys

Resharper Ultimate 2015

sunilkumar / eEI2es4C2Y7964dndo9xg5De0PPhLwd6


Monday, April 2, 2012

Log out a user remotely using command prompt

The command is logoff 2 /server:servername

2 is the session id of the user to be logged out.
servername is the name of the server.

Monday, June 6, 2011

Teamsite: Hide/show the DCT save and generate buttons dynamically

//Generate Button
var generateButton = parent.datacapture_buttonframe.document.getElementById('iw.ccpro.datacapture.edi t_form.generate.link');
generateButton.style.display = 'none';


//Save Button
var saveButton = parent.datacapture_buttonframe.document.getElementById('iw.ccpro.datacapture.edi t_form.save.link');
saveButton.style.display = 'none';