private IRecord GetRecordToDeployInto(string recordType, string nameToMatch, string containingFolderParentName)
        {
            nameToMatch = nameToMatch?.Replace("∕", "/");

            var conditions = new List <Condition>
            {
                new Condition(Service.GetPrimaryField(recordType), ConditionType.Equal, nameToMatch)
            };

            if (recordType == Entities.adx_webpage)
            {
                conditions.Add(new Condition(Fields.adx_webpage_.adx_rootwebpageid, ConditionType.NotNull));
            }

            IRecord matchingRecord  = null;
            var     matchingRecords = Service.RetrieveAllAndClauses(recordType, conditions);

            if (matchingRecords.Count() == 0)
            {
                throw new NullReferenceException($"Could not find {Service.GetDisplayName(recordType)} named {nameToMatch} to update");
            }
            else if (matchingRecords.Count() == 1)
            {
                matchingRecord = matchingRecords.First();
            }
            else
            {
                if (containingFolderParentName == null)
                {
                    throw new NullReferenceException($"There are multiple {Service.GetCollectionName(recordType)} named {nameToMatch} and the parents parent folder does not provide the name of a {Service.GetDisplayName(Entities.adx_website)} to deploy into");
                }
                else
                {
                    var websiteLookupFields = Service
                                              .GetFields(recordType)
                                              .Where(f => Service.GetLookupTargetType(f, recordType) == Entities.adx_website)
                                              .ToArray();
                    if (websiteLookupFields.Count() != 1)
                    {
                        throw new NullReferenceException($"There are multiple {Service.GetCollectionName(recordType)} named {nameToMatch} but the type does not contain 1 lookup field referencing the {Service.GetDisplayName(Entities.adx_website)} to deploy into");
                    }
                    var websiteFieldName = websiteLookupFields.First();
                    matchingRecords = matchingRecords.Where(r => r.GetLookupName(websiteFieldName)?.ToLower() == containingFolderParentName.ToLower());
                    if (matchingRecords.Count() == 0)
                    {
                        throw new NullReferenceException($"There are multiple {Service.GetCollectionName(recordType)} named {nameToMatch} but none of them are linked to a {Service.GetDisplayName(Entities.adx_website)} named {containingFolderParentName}");
                    }
                    if (matchingRecords.Count() > 1)
                    {
                        throw new NullReferenceException($"There are multiple {Service.GetCollectionName(recordType)} named {nameToMatch} linked to a {Service.GetDisplayName(Entities.adx_website)} named {containingFolderParentName}");
                    }
                    matchingRecord = matchingRecords.First();
                }
            }

            return(matchingRecord);
        }
Example #2
0
        private string GetTargetField(FileInfo fileInfo, string recordType)
        {
            //adx_webtemplate -> adx_source (Source)
            //adx_entitylist -> adx_registerstartupscript (Custom JavaScript)
            //adx_webpage -> adx_customjavascript (Custom JavaScript)
            //adx_webpage -> adx_customcss (Custom CSS)

            if (recordType == "adx_webfile")
            {
                return("adx_source");
            }
            if (fileInfo.Name.EndsWith("css"))
            {
                var matchingFields = Service.GetFields(recordType).Where(f => f.Contains("css"));
                if (matchingFields.Count() != 1)
                {
                    throw new Exception($"Could not find unique field in {recordType} with name containing 'css'");
                }
                return(matchingFields.First());
            }
            if (fileInfo.Name.EndsWith("js"))
            {
                var matchingFields = Service.GetFields(recordType).Where(f => Service.GetFieldLabel(f, recordType)?.ToLower()?.Contains("javascript") ?? false);
                if (matchingFields.Count() != 1)
                {
                    throw new Exception($"Could not find unique field in {recordType} where label contains 'javascript'");
                }
                return(matchingFields.First());
            }
            if (fileInfo.Name.EndsWith("htm") || fileInfo.Name.EndsWith("html"))
            {
                var matchingFields = Service.GetFields(recordType).Where(f => f.Contains("source"));
                if (matchingFields.Count() != 1)
                {
                    throw new Exception($"Could not find unique field in {recordType} with name containing 'source'");
                }
                return(matchingFields.First());
            }
            throw new NotImplementedException($"The file extention {fileInfo.Extension} is not implemented");
        }