示例#1
0
        /// <summary>
        /// In comments below this method is a method that will attempt to load the
        /// .nuspec file as an XDocument and process it as such. This seems to be a
        /// bit of overkill in that MS has very nicely included a default .nuspec
        /// file if the nuget "spec" command is executed in the same directory as
        /// the target .csproj file. Since this is the case AND said .nuspec file
        /// contains replaceable tokens, it's really easier to simply load the
        /// entire file into a StringBuilder, replace the desired tokens with the
        /// established values and then write the thing back out to the drive, thus
        /// this method.
        /// </summary>
        private void ProcessFullFrameworkNuSpecFileForPack()
        {
            const StringComparison COMPARISON =
                StringComparison.InvariantCultureIgnoreCase;

            NoOp = !File.Exists(NuSpecFilePath) || NoOp;
            if (NoOp)
            {
                return;
            }
            string        vPath        = NuSpecFilePath;
            StringBuilder vContent     = new StringBuilder(File.ReadAllText(vPath));
            int           vChangeCount = 0;
            string        vLookFor;

            if (_HandleConfiguration.NuGetNuSpecSettings.ForceAuthors)
            {
                vLookFor =
                    AUTHOR_KEY + AUTHORS.AsToken();
                vContent.Replace
                (
                    vLookFor
                    , AUTHOR_KEY
                    + _HandleConfiguration.NuGetNuSpecSettings.Authors
                );
                vChangeCount++;
            }
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceCopyright)
            {
                vLookFor = $"{COPYRIGHT} {DateTime.Now.Year}";
                vContent.Replace
                (
                    vLookFor.AsToken()
                    , _HandleConfiguration.NuGetNuSpecSettings.Copyright
                );
                vChangeCount++;
            }
            vLookFor = DESCRIPTION.AsToken();
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceDescription)
            {
                vContent.Replace
                (
                    vLookFor.AsToken()
                    , _HandleConfiguration.NuGetNuSpecSettings.Description
                );
                vChangeCount++;
            }
            else
            {
                string vFind =
                    DESCRIPTION_KEY_START
                    + DEFAULT_DESCRIPTION
                    + DESCRIPTION_KEY_END
                    + "\r\n";
                string vReplaceWith =
                    DESCRIPTION_KEY_START
                    + DEFAULT_DESCRIPTION
                    + DateTime.Now.ToLongDateString()
                    + DESCRIPTION_KEY_END
                    + "\r\n";
                vContent.Replace(vFind, vReplaceWith);
                vChangeCount++;
            }
            vLookFor =
                ICON_URL_KEY + ICON_URL_OR_DELETE_THIS;
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceIconUrl)
            {
                vContent.Replace
                    (vLookFor, _HandleConfiguration.NuGetNuSpecSettings.IconUrl);
                vChangeCount++;
            }
            else
            {
                string vFind =
                    ICON_URL_KEY
                    + ICON_URL_OR_DELETE_THIS
                    + ICON_URL_KEY_END
                    + "\r\n";
                vContent.Replace(vFind, String.Empty);
                vChangeCount++;
            }
            vLookFor = LICENSE_URL;
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceLicenseUrl)
            {
                vContent.Replace
                (
                    vLookFor.AsToken(),
                    _HandleConfiguration.NuGetNuSpecSettings.LicenseUrl
                );
                vChangeCount++;
            }
            else
            {
                string vFind =
                    LICENSE_URL_KEY
                    + LICENSE_URL_OR_DELETE_THIS
                    + LICENSE_URL_KEY_END
                    + "\r\n";
                vContent.Replace(vFind, String.Empty);
                vChangeCount++;
            }
            vLookFor = PROJECT_URL;
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceProjectUrl)
            {
                vContent.Replace
                (
                    vLookFor.AsToken(),
                    _HandleConfiguration.NuGetNuSpecSettings.ProjectUrl
                );
                vChangeCount++;
            }
            else
            {
                string vFind =
                    PROJECT_URL_KEY
                    + PROJECT_URL_OR_DELETE_THIS
                    + PROJECT_URL_KEY_END
                    + "\r\n";
                vContent.Replace(vFind, String.Empty);
                vChangeCount++;
            }
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceOwners)
            {
                vLookFor =
                    OWNER_KEY + AUTHORS.AsToken();
                vContent.Replace
                (
                    vLookFor
                    , OWNER_KEY
                    + _HandleConfiguration.NuGetNuSpecSettings.Owners
                );
                vChangeCount++;
            }
            vLookFor = DEFAULT_RELEASE_NOTES;
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceReleaseNotes)
            {
                if (_HandleConfiguration.AppSettingsValues.RequireReleaseNotesFile)
                {
                    vContent.Replace(vLookFor, ExtractReleaseNotes());
                    vChangeCount++;
                }
            }
            else
            {
                string vFind =
                    RELEASE_NOTES_KEY
                    + DEFAULT_RELEASE_NOTES
                    + RELEASE_NOTES_KEY_END
                    + "\r\n";
                vContent.Replace(vFind, String.Empty);
                vChangeCount++;
            }
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceRequireLicenseAcceptance)
            {
                vLookFor =
                    REQUIRE_LICENSE_ACCEPTANCE_KEY
                    + DEFAULT_REQUIRE_LICENSE_ACCEPTANCE;
                vContent.Replace
                (
                    vLookFor,
                    _HandleConfiguration.NuGetNuSpecSettings.RequireLicenseAcceptance
                );
                vChangeCount++;
            }
            if (_HandleConfiguration.AppSettingsValues.RequireSummaryFile)
            {
                vLookFor = SUMMARY_KEY;
                string vContentAsString = vContent.ToString();
                int    vIndex           = vContentAsString.IndexOf(vLookFor, COMPARISON);
                if (vIndex < 0)
                {
                    vIndex = vContentAsString.IndexOf
                                 (METADATA_END, COMPARISON);
                    string vNewKey =
                        SUMMARY_KEY
                        + ExtractNuGetSummary()
                        + SUMMARY_KEY_END;
                    vContent.Insert(vIndex, vNewKey);
                    vChangeCount++;
                }
                else
                {
                    // This shouldn't ever have to be executed, but just in case MS
                    // changes how nuget.exe functions...
                    int vEndIndex =
                        vContentAsString.IndexOf
                            (SUMMARY_KEY_END, COMPARISON);
                    vIndex = vIndex + SUMMARY_KEY.Length;
                    int vHowMuch = vEndIndex - vIndex + 1;
                    vContentAsString = vContentAsString.Remove(vIndex, vHowMuch);
                    vContentAsString = vContentAsString.Insert(vIndex, ExtractNuGetSummary());
                    vContent.Clear();
                    vContent.Append(vContentAsString);
                    vChangeCount++;
                }
            }
            vLookFor = DEFAULT_TAGS;
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceTags)
            {
                vContent.Replace(vLookFor, _HandleConfiguration.NuGetNuSpecSettings.Tags);
                vChangeCount++;
            }
            else
            {
                string vFind =
                    TAGS_KEY_START
                    + DEFAULT_TAGS
                    + TAGS_KEY_END
                    + "\r\n";
                vContent.Replace(vFind, String.Empty);
                vChangeCount++;
            }
            if (_HandleConfiguration.NuGetNuSpecSettings.ForceTitle)
            {
                vLookFor = TITLE.AsToken();
                vContent.Replace
                    (vLookFor, _HandleConfiguration.NuGetNuSpecSettings.Title);
                vChangeCount++;
            }
            if (_HandleConfiguration.AppSettingsValues.ForceVersionOverride)
            {
                vLookFor = DotNetCSProjKeys.VERSION;
                vContent.Replace
                    (vLookFor, _HandleConfiguration.AppSettingsValues.VersionOverride);
                vChangeCount++;
            }
            if (vChangeCount > 0)
            {
                File.WriteAllText(vPath, vContent.ToString());
            }
        }
示例#2
0
        /// <summary>
        /// Method used to add a property to the instance. Will be placed in the correct class Property.
        /// </summary>
        /// <param name="input">The vCard.Property to add.</param>
        public void AddProperty(Props.IProperty input)
        {
            if (input == null || input.IsValueNull)
            {
                return;
            }

            switch (input.Property)
            {
            case KnownProperties.ADR:
                ADR.AddIfNotNull(input as Props.ADR);
                break;

            case KnownProperties.ANNIVERSARY:
                ANNIVERSARY = input as Props.ANNIVERSARY;
                break;

            case KnownProperties.BDAY:
                BDAY = input as Props.BDAY;
                break;

            case KnownProperties.CALADRURI:
                CALADRURI.AddIfNotNull(input as Props.CALADRURI);
                break;

            case KnownProperties.CALURI:
                CALURI.AddIfNotNull(input as Props.CALURI);
                break;

            case KnownProperties.CATEGORIES:
                CATEGORIES.AddIfNotNull(input as Props.CATEGORIES);
                break;

            case KnownProperties.CLIENTPIDMAP:
                CLIENTPIDMAP.AddIfNotNull(input as Props.CLIENTPIDMAP);
                break;

            case KnownProperties.EMAIL:
                EMAIL.AddIfNotNull(input as Props.EMAIL);
                break;

            case KnownProperties.FBURL:
                FBURL.AddIfNotNull(input as Props.FBURL);
                break;

            case KnownProperties.FN:
                FN.AddIfNotNull(input as Props.FN);
                break;

            case KnownProperties.GENDER:
                GENDER = input as Props.GENDER;
                break;

            case KnownProperties.GEO:
                GEO.AddIfNotNull(input as Props.GEO);
                break;

            case KnownProperties.IMPP:
                IMPP.AddIfNotNull(input as Props.IMPP);
                break;

            case KnownProperties.KEY:
                KEY.AddIfNotNull(input as Props.KEY);
                break;

            case KnownProperties.KIND: {
                char k = (input as Props.KIND).Value.ToLower()[0];
                if (k == 'i')
                {
                    KIND = Kinds.Individual;
                }
                else if (k == 'g')
                {
                    KIND = Kinds.Group;
                }
                else if (k == 'o')
                {
                    KIND = Kinds.Org;
                }
                else if (k == 'l')
                {
                    KIND = Kinds.Location;
                }
                else
                {
                    KIND = Kinds.Individual;
                }
                break;
            }

            case KnownProperties.LANG:
                LANG.AddIfNotNull(input as Props.LANG);
                break;

            case KnownProperties.LOGO:
                LOGO.AddIfNotNull(input as Props.LOGO);
                break;

            case KnownProperties.MEMBER:
                MEMBER.AddIfNotNull(input as Props.MEMBER);
                break;

            case KnownProperties.N:
                N = input as Props.N;
                break;

            case KnownProperties.NICKNAME:
                NICKNAME.AddIfNotNull(input as Props.NICKNAME);
                break;

            case KnownProperties.NOTE:
                NOTE.AddIfNotNull(input as Props.NOTE);
                break;

            case KnownProperties.ORG:
                ORG.AddIfNotNull(input as Props.ORG);
                break;

            case KnownProperties.PHOTO:
                PHOTO.AddIfNotNull(input as Props.PHOTO);
                break;

            case KnownProperties.PRODID:
                PRODID = input as Props.PRODID;
                break;

            case KnownProperties.RELATED:
                RELATED.AddIfNotNull(input as Props.RELATED);
                break;

            case KnownProperties.REV:
                REV = input as Props.REV;
                break;

            case KnownProperties.ROLE:
                ROLE.AddIfNotNull(input as Props.ROLE);
                break;

            case KnownProperties.SOUND:
                SOUND.AddIfNotNull(input as Props.SOUND);
                break;

            case KnownProperties.SOURCE:
                SOURCE.AddIfNotNull(input as Props.SOURCE);
                break;

            case KnownProperties.TEL:
                TEL.AddIfNotNull(input as Props.TEL);
                break;

            case KnownProperties.TITLE:
                TITLE.AddIfNotNull(input as Props.TITLE);
                break;

            case KnownProperties.TZ:
                TZ.AddIfNotNull(input as Props.TZ);
                break;

            case KnownProperties.UID:
                UID = input as Props.UID;
                break;

            case KnownProperties.URL:
                URL.AddIfNotNull(input as Props.URL);
                break;

            case KnownProperties.VERSION:
                VERSION = input as Props.VERSION;
                break;

            case KnownProperties.XML:
                XML.AddIfNotNull(input as Props.XML);
                break;

            default:
                return;
            }
        }