protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Entity webresource = _repository.Get("webresource", Id, new string[] { "content" });

            switch (this.ParameterSetName)
            {
            case ImportWebresourceFromValueParameterSet:
                string contentAsBase64 = Convert.ToBase64String(Value);
                webresource.Attributes["content"] = contentAsBase64;
                break;

            case ImportWebresourceFromPathParameterSet:
                FileContentReaderWriter fcrw = new FileContentReaderWriter(LiteralPath, _contentParameters.EncodingType, _contentParameters.UsingByteEncoding);
                byte[] fileAsBytes           = fcrw.ReadAsBytes();
                string fileContentAsBase64   = Convert.ToBase64String(fileAsBytes);
                webresource.Attributes["content"] = fileContentAsBase64;
                break;
            }

            _repository.Update(webresource);

            if (PassThru)
            {
                WriteObject(_repository.Get("webresource", Id));
            }
        }
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Entity newWebResource = new Entity("webresource")
            {
                Attributes = new AttributeCollection()
            };

            newWebResource.Attributes.Add("name", Name);
            newWebResource.Attributes.Add("webresourcetype", new OptionSetValue(GetWebresourceTypeFromEnum(WebresourceType)));

            if (!string.IsNullOrWhiteSpace(DisplayName))
            {
                newWebResource.Attributes.Add("displayname", DisplayName);
            }
            if (!string.IsNullOrWhiteSpace(Description))
            {
                newWebResource.Attributes.Add("description", Description);
            }
            if (IsCustomizable.HasValue)
            {
                newWebResource.Attributes.Add("iscustomizable", IsCustomizable.Value);
            }

            switch (this.ParameterSetName)
            {
            case NewWebresourceFromContentParameterSet:
                string contentAsBase64 = Convert.ToBase64String(Content);
                newWebResource.Attributes.Add("content", contentAsBase64);
                break;

            case NewWebresourceFromPathParameterSet:
                FileContentReaderWriter fcrw = new FileContentReaderWriter(LiteralPath, _contentParameters.EncodingType, _contentParameters.UsingByteEncoding);
                byte[] fileAsBytes           = fcrw.ReadAsBytes();
                string fileContentAsBase64   = Convert.ToBase64String(fileAsBytes);
                newWebResource.Attributes.Add("content", fileContentAsBase64);
                break;

            default:
                break;
            }

            Guid newId = _repository.Add(newWebResource);

            if (PassThru)
            {
                WriteObject(_repository.Get("webresource", newId, null));
            }
        }
示例#3
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Entity webresource = _repository.Get("webresource", Id, null);

            if (!string.IsNullOrWhiteSpace(DisplayName))
            {
                if (webresource.Contains("displayname"))
                {
                    webresource.Attributes["displayname"] = DisplayName;
                }
                else
                {
                    webresource.Attributes.Add("displayname", DisplayName);
                }
            }

            if (!string.IsNullOrWhiteSpace(Description))
            {
                if (webresource.Contains("description"))
                {
                    webresource.Attributes["description"] = Description;
                }
                else
                {
                    webresource.Attributes.Add("description", Description);
                }
            }

            if (IsCustomizable.HasValue)
            {
                if (webresource.Contains("iscustomizable"))
                {
                    webresource.Attributes["iscustomizable"] = IsCustomizable.Value;
                }
                else
                {
                    webresource.Attributes.Add("iscustomizable", IsCustomizable.Value);
                }
            }

            switch (this.ParameterSetName)
            {
            case SetWebresourceFromContentParameterSet:
                string contentAsBase64 = Convert.ToBase64String(Content);
                webresource.Attributes["content"] = contentAsBase64;
                break;

            case SetWebresourceFromPathParameterSet:
                FileContentReaderWriter fcrw = new FileContentReaderWriter(LiteralPath, _contentParameters.EncodingType, _contentParameters.UsingByteEncoding);
                byte[] fileAsBytes           = fcrw.ReadAsBytes();
                string fileContentAsBase64   = Convert.ToBase64String(fileAsBytes);
                webresource.Attributes["content"] = fileContentAsBase64;
                break;

            default:
                break;
            }

            _repository.Update(webresource);

            if (PassThru)
            {
                WriteObject(_repository.Get("webresource", Id));
            }
        }