예제 #1
0
        /// <summary>
        /// Create a new webressource
        /// </summary>
        /// <param name="webResourceInfo"></param>
        public Guid?Create(XElement webResourceInfo)
        {
            try
            {
                var type =
                    (int)ResourceExtensions.ConvertStringExtension(webResourceInfo?.Attribute(WebResource.Type)?.Value);
                var optionsetValue = new OptionSetValue(type);
                var fullName       = GetWebResourceFullNameIncludingPrefix(webResourceInfo);
                //Create the Web Resource.
                var wr = new Entities.WebResource
                {
                    Content         = GetEncodedFileContents(webResourceInfo?.Attribute(WebResource.FilePath)?.Value),
                    DisplayName     = webResourceInfo?.Attribute(WebResource.DisplayName)?.Value,
                    Description     = webResourceInfo?.Attribute(WebResource.Description)?.Value,
                    LogicalName     = Entities.WebResource.EntityLogicalName,
                    Name            = fullName,
                    WebResourceType = optionsetValue
                };

                var guid = Service.Create(wr);

                //If not the "Default Solution", create a SolutionComponent to assure it gets
                //associated with the ActiveSolution. Web Resources are automatically added
                //as SolutionComponents to the Default Solution.
                if (ActiveSolution.UniqueName != "Default")
                {
                    var scRequest =
                        new AddSolutionComponentRequest
                    {
                        ComponentType      = (int)SolutionComponent.OptionSet.ComponentType.WebResource,
                        SolutionUniqueName = ActiveSolution.UniqueName,
                        ComponentId        = guid
                    };
                    Service.Execute(scRequest);
                }

                return(guid);
            }
            catch (Exception e)
            {
                err.Error("Error: " + e.Message);
                return(null);
            }
        }
예제 #2
0
 /// <summary>
 /// Updates a webressource
 /// </summary>
 /// <param name="webResourceInfo"></param>
 /// <param name="existingResource"></param>
 public void Update(XElement webResourceInfo, Entities.WebResource existingResource)
 {
     try
     {
         var fullName = GetWebResourceFullNameIncludingPrefix(webResourceInfo);
         var wr       = new Entities.WebResource
         {
             Content       = GetEncodedFileContents(webResourceInfo?.Attribute(WebResource.FilePath)?.Value),
             DisplayName   = webResourceInfo?.Attribute(WebResource.DisplayName)?.Value,
             Description   = webResourceInfo?.Attribute(WebResource.Description)?.Value,
             Name          = fullName,
             WebResourceId = existingResource.WebResourceId
         };
         Service.Update(wr);
     }
     catch (Exception e)
     {
         err.Error("Error: " + e.Message);
     }
 }