Beispiel #1
0
 /// <summary>
 /// Gets the uri of the specified template name.
 /// </summary>
 /// <param name="templateIdentity">The fully qualified template name</param>
 /// <returns>The template uri</returns>
 public virtual string GetGalleryTemplateFile(string templateIdentity)
 {
     try
     {
         DefinitionTemplates definitionTemplates = GalleryClient.Items.Get(templateIdentity).Item.DefinitionTemplates;
         return(definitionTemplates.DeploymentTemplateFileUrls[definitionTemplates.DefaultDeploymentTemplateId]);
     }
     catch (CloudException)
     {
         throw new ArgumentException(string.Format(ProjectResources.InvalidTemplateIdentity, templateIdentity));
     }
 }
Beispiel #2
0
        /// <summary>
        /// Your documentation here.  (see
        /// http://msdn.microsoft.com/en-us/library/windowsazure/XXXXX.aspx
        /// for more information)
        /// </summary>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Your documentation here.
        /// </returns>
        public async Task <PublicGalleryItemListResult> ListAllAsync(CancellationToken cancellationToken)
        {
            // Validate

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                TracingAdapter.Enter(invocationId, this, "ListAllAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/providers/Microsoft.Gallery/galleryitems";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=" + Uri.EscapeDataString(this.Client.ApiVersion));
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    PublicGalleryItemListResult result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new PublicGalleryItemListResult();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            JToken galleryItemsArray = responseDoc;
                            if (galleryItemsArray != null && galleryItemsArray.Type != JTokenType.Null)
                            {
                                foreach (JToken galleryItemsValue in ((JArray)galleryItemsArray))
                                {
                                    GalleryItem galleryItemInstance = new GalleryItem();
                                    result.GalleryItems.Add(galleryItemInstance);

                                    JToken additionalPropertiesSequenceElement = ((JToken)galleryItemsValue["additionalProperties"]);
                                    if (additionalPropertiesSequenceElement != null && additionalPropertiesSequenceElement.Type != JTokenType.Null)
                                    {
                                        foreach (JProperty property in additionalPropertiesSequenceElement)
                                        {
                                            string additionalPropertiesKey   = ((string)property.Name);
                                            string additionalPropertiesValue = ((string)property.Value);
                                            galleryItemInstance.AdditionalProperties.Add(additionalPropertiesKey, additionalPropertiesValue);
                                        }
                                    }

                                    JToken categoryIdsArray = galleryItemsValue["categoryIds"];
                                    if (categoryIdsArray != null && categoryIdsArray.Type != JTokenType.Null)
                                    {
                                        foreach (JToken categoryIdsValue in ((JArray)categoryIdsArray))
                                        {
                                            galleryItemInstance.CategoryIds.Add(((string)categoryIdsValue));
                                        }
                                    }

                                    JToken definitionTemplatesValue = galleryItemsValue["definitionTemplates"];
                                    if (definitionTemplatesValue != null && definitionTemplatesValue.Type != JTokenType.Null)
                                    {
                                        DefinitionTemplates definitionTemplatesInstance = new DefinitionTemplates();
                                        galleryItemInstance.DefinitionTemplates = definitionTemplatesInstance;

                                        JToken defaultDeploymentTemplateIdValue = definitionTemplatesValue["defaultDeploymentTemplateId"];
                                        if (defaultDeploymentTemplateIdValue != null && defaultDeploymentTemplateIdValue.Type != JTokenType.Null)
                                        {
                                            string defaultDeploymentTemplateIdInstance = ((string)defaultDeploymentTemplateIdValue);
                                            definitionTemplatesInstance.DefaultDeploymentTemplateId = defaultDeploymentTemplateIdInstance;
                                        }

                                        JToken deploymentFragmentFileUrisSequenceElement = ((JToken)definitionTemplatesValue["deploymentFragmentFileUris"]);
                                        if (deploymentFragmentFileUrisSequenceElement != null && deploymentFragmentFileUrisSequenceElement.Type != JTokenType.Null)
                                        {
                                            foreach (JProperty property2 in deploymentFragmentFileUrisSequenceElement)
                                            {
                                                string deploymentFragmentFileUrisKey   = ((string)property2.Name);
                                                string deploymentFragmentFileUrisValue = ((string)property2.Value);
                                                definitionTemplatesInstance.DeploymentFragmentFileUris.Add(deploymentFragmentFileUrisKey, deploymentFragmentFileUrisValue);
                                            }
                                        }

                                        JToken deploymentTemplateFileUrisSequenceElement = ((JToken)definitionTemplatesValue["deploymentTemplateFileUris"]);
                                        if (deploymentTemplateFileUrisSequenceElement != null && deploymentTemplateFileUrisSequenceElement.Type != JTokenType.Null)
                                        {
                                            foreach (JProperty property3 in deploymentTemplateFileUrisSequenceElement)
                                            {
                                                string deploymentTemplateFileUrisKey   = ((string)property3.Name);
                                                string deploymentTemplateFileUrisValue = ((string)property3.Value);
                                                definitionTemplatesInstance.DeploymentTemplateFileUris.Add(deploymentTemplateFileUrisKey, deploymentTemplateFileUrisValue);
                                            }
                                        }

                                        JToken uiDefinitionFileUriValue = definitionTemplatesValue["uiDefinitionFileUri"];
                                        if (uiDefinitionFileUriValue != null && uiDefinitionFileUriValue.Type != JTokenType.Null)
                                        {
                                            string uiDefinitionFileUriInstance = ((string)uiDefinitionFileUriValue);
                                            definitionTemplatesInstance.UiDefinitionFileUri = uiDefinitionFileUriInstance;
                                        }
                                    }

                                    JToken descriptionValue = galleryItemsValue["description"];
                                    if (descriptionValue != null && descriptionValue.Type != JTokenType.Null)
                                    {
                                        string descriptionInstance = ((string)descriptionValue);
                                        galleryItemInstance.Description = descriptionInstance;
                                    }

                                    JToken identityValue = galleryItemsValue["identity"];
                                    if (identityValue != null && identityValue.Type != JTokenType.Null)
                                    {
                                        string identityInstance = ((string)identityValue);
                                        galleryItemInstance.Identity = identityInstance;
                                    }

                                    JToken itemDisplayNameValue = galleryItemsValue["itemDisplayName"];
                                    if (itemDisplayNameValue != null && itemDisplayNameValue.Type != JTokenType.Null)
                                    {
                                        string itemDisplayNameInstance = ((string)itemDisplayNameValue);
                                        galleryItemInstance.ItemDisplayName = itemDisplayNameInstance;
                                    }

                                    JToken itemNameValue = galleryItemsValue["itemName"];
                                    if (itemNameValue != null && itemNameValue.Type != JTokenType.Null)
                                    {
                                        string itemNameInstance = ((string)itemNameValue);
                                        galleryItemInstance.ItemName = itemNameInstance;
                                    }

                                    JToken linksArray = galleryItemsValue["links"];
                                    if (linksArray != null && linksArray.Type != JTokenType.Null)
                                    {
                                        foreach (JToken linksValue in ((JArray)linksArray))
                                        {
                                            LinkProperties linkPropertiesInstance = new LinkProperties();
                                            galleryItemInstance.Links.Add(linkPropertiesInstance);

                                            JToken displayNameValue = linksValue["displayName"];
                                            if (displayNameValue != null && displayNameValue.Type != JTokenType.Null)
                                            {
                                                string displayNameInstance = ((string)displayNameValue);
                                                linkPropertiesInstance.DisplayName = displayNameInstance;
                                            }

                                            JToken idValue = linksValue["id"];
                                            if (idValue != null && idValue.Type != JTokenType.Null)
                                            {
                                                string idInstance = ((string)idValue);
                                                linkPropertiesInstance.Id = idInstance;
                                            }

                                            JToken uriValue = linksValue["uri"];
                                            if (uriValue != null && uriValue.Type != JTokenType.Null)
                                            {
                                                string uriInstance = ((string)uriValue);
                                                linkPropertiesInstance.Uri = uriInstance;
                                            }
                                        }
                                    }

                                    JToken longSummaryValue = galleryItemsValue["longSummary"];
                                    if (longSummaryValue != null && longSummaryValue.Type != JTokenType.Null)
                                    {
                                        string longSummaryInstance = ((string)longSummaryValue);
                                        galleryItemInstance.LongSummary = longSummaryInstance;
                                    }

                                    JToken publisherValue = galleryItemsValue["publisher"];
                                    if (publisherValue != null && publisherValue.Type != JTokenType.Null)
                                    {
                                        string publisherInstance = ((string)publisherValue);
                                        galleryItemInstance.Publisher = publisherInstance;
                                    }

                                    JToken publisherDisplayNameValue = galleryItemsValue["publisherDisplayName"];
                                    if (publisherDisplayNameValue != null && publisherDisplayNameValue.Type != JTokenType.Null)
                                    {
                                        string publisherDisplayNameInstance = ((string)publisherDisplayNameValue);
                                        galleryItemInstance.PublisherDisplayName = publisherDisplayNameInstance;
                                    }

                                    JToken resourceGroupNameValue = galleryItemsValue["resourceGroupName"];
                                    if (resourceGroupNameValue != null && resourceGroupNameValue.Type != JTokenType.Null)
                                    {
                                        string resourceGroupNameInstance = ((string)resourceGroupNameValue);
                                        galleryItemInstance.ResourceGroupName = resourceGroupNameInstance;
                                    }

                                    JToken screenshotUrisArray = galleryItemsValue["screenshotUris"];
                                    if (screenshotUrisArray != null && screenshotUrisArray.Type != JTokenType.Null)
                                    {
                                        foreach (JToken screenshotUrisValue in ((JArray)screenshotUrisArray))
                                        {
                                            galleryItemInstance.ScreenshotUris.Add(((string)screenshotUrisValue));
                                        }
                                    }

                                    JToken summaryValue = galleryItemsValue["summary"];
                                    if (summaryValue != null && summaryValue.Type != JTokenType.Null)
                                    {
                                        string summaryInstance = ((string)summaryValue);
                                        galleryItemInstance.Summary = summaryInstance;
                                    }

                                    JToken versionValue = galleryItemsValue["version"];
                                    if (versionValue != null && versionValue.Type != JTokenType.Null)
                                    {
                                        string versionInstance = ((string)versionValue);
                                        galleryItemInstance.Version = versionInstance;
                                    }
                                }
                            }
                        }
                    }
                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates the backend sections. Adds edit/preview controls to the detailView
        /// </summary>
        /// <param name="detailView">The detail view.</param>
        /// <param name="displayMode">The display mode.</param>
        private static void CreateBackendSections(DetailFormViewElement detailView, FieldDisplayMode displayMode)
        {
            // define main content section
            var mainSection = new ContentViewSectionElement(detailView.Sections)
            {
                Name     = "MainSection",
                CssClass = "sfFirstForm"
            };

            #region Title Field

            // define title field element
            var titleField = new TextFieldDefinitionElement(mainSection.Fields)
            {
                ID            = "titleFieldControl",
                DataFieldName = displayMode == FieldDisplayMode.Write ? "Title.PersistedValue" : "Title",
                DisplayMode   = displayMode,
                Title         = "Title",
                CssClass      = "sfTitleField",
                WrapperTag    = HtmlTextWriterTag.Li,
            };

            // add validation
            titleField.ValidatorConfig = new ValidatorDefinitionElement(titleField)
            {
                Required                 = true,
                MessageCssClass          = "sfError",
                RequiredViolationMessage = "Title field is required"
            };

            // add field to section
            mainSection.Fields.Add(titleField);

            #endregion

            #region Content

            var contentField = new HtmlFieldElement(mainSection.Fields)
            {
                ID                           = "contentFieldControl",
                DataFieldName                = displayMode == FieldDisplayMode.Write ? "Content.PersistedValue" : "Content",
                DisplayMode                  = displayMode,
                CssClass                     = "sfFormSeparator sfContentField",
                WrapperTag                   = HtmlTextWriterTag.Li,
                EditorContentFilters         = Telerik.Web.UI.EditorFilters.DefaultFilters,
                EditorStripFormattingOptions = (EditorStripFormattingOptions?)(EditorStripFormattingOptions.MSWord | EditorStripFormattingOptions.Css | EditorStripFormattingOptions.Font | EditorStripFormattingOptions.Span | EditorStripFormattingOptions.ConvertWordLists)
            };
            mainSection.Fields.Add(contentField);

            #endregion

            #region Address fields

            // Address field
            var addressField = new TextFieldDefinitionElement(mainSection.Fields)
            {
                ID            = "addressFieldControl",
                DataFieldName = "Address",
                DisplayMode   = displayMode,
                Title         = "Address",
                CssClass      = "sfTitleField",
                WrapperTag    = HtmlTextWriterTag.Li
            };
            addressField.ValidatorConfig = new ValidatorDefinitionElement(addressField)
            {
                Required                 = true,
                MessageCssClass          = "sfError",
                RequiredViolationMessage = "Location address is required"
            };
            mainSection.Fields.Add(addressField);

            // City field
            var cityField = new TextFieldDefinitionElement(mainSection.Fields)
            {
                ID            = "cityFieldControl",
                DataFieldName = "City",
                DisplayMode   = displayMode,
                Title         = "City",
                CssClass      = "sfTitleField",
                WrapperTag    = HtmlTextWriterTag.Li
            };
            mainSection.Fields.Add(cityField);

            // State / Region field
            var regionField = new TextFieldDefinitionElement(mainSection.Fields)
            {
                ID            = "regionFieldControl",
                DataFieldName = "Region",
                DisplayMode   = displayMode,
                Title         = "State / Region",
                CssClass      = "sfTitleField",
                WrapperTag    = HtmlTextWriterTag.Li
            };
            regionField.ValidatorConfig = new ValidatorDefinitionElement(regionField)
            {
                Required                 = true,
                MessageCssClass          = "sfError",
                RequiredViolationMessage = "State / Region is a required field"
            };
            mainSection.Fields.Add(regionField);

            // Postal Code field
            var postalCodeField = new TextFieldDefinitionElement(mainSection.Fields)
            {
                ID            = "postalCodeFieldControl",
                DataFieldName = "PostalCode",
                DisplayMode   = displayMode,
                Title         = "Postal Code",
                CssClass      = "sfTitleField",
                WrapperTag    = HtmlTextWriterTag.Li
            };
            postalCodeField.ValidatorConfig = new ValidatorDefinitionElement(postalCodeField)
            {
                Required                 = true,
                MessageCssClass          = "sfError",
                RequiredViolationMessage = "Postal code is a required field"
            };
            mainSection.Fields.Add(postalCodeField);

            // Country field
            var countryField = new TextFieldDefinitionElement(mainSection.Fields)
            {
                ID            = "countryFieldControl",
                DataFieldName = "Country",
                DisplayMode   = displayMode,
                Title         = "Country",
                CssClass      = "sfTitleField",
                WrapperTag    = HtmlTextWriterTag.Li
            };

            countryField.ValidatorConfig = new ValidatorDefinitionElement(countryField)
            {
                Required                 = true,
                MessageCssClass          = "sfError",
                RequiredViolationMessage = "Country is a required field"
            };

            mainSection.Fields.Add(countryField);

            // add section to view
            detailView.Sections.Add(mainSection);

            #endregion

            #region Categories and Tags Section

            // define new section
            var taxonSection = new ContentViewSectionElement(detailView.Sections)
            {
                Name     = "TaxonSection",
                Title    = "Categories and Tags",
                CssClass = "sfExpandableForm",
                ExpandableDefinitionConfig =
                {
                    Expanded = false
                }
            };

            // add categories field to section
            var categories = DefinitionTemplates.CategoriesFieldWriteMode(taxonSection.Fields);
            categories.DisplayMode = displayMode;

            // add categories section to view
            taxonSection.Fields.Add(categories);

            // add tags field to section
            var tags = DefinitionTemplates.TagsFieldWriteMode(taxonSection.Fields);
            tags.DisplayMode = displayMode;
            tags.CssClass    = "sfFormSeparator";
            tags.ExpandableDefinition.Expanded = true;
            tags.Description = "TagsFieldInstructions";
            taxonSection.Fields.Add(tags);

            // add tags section to view
            detailView.Sections.Add(taxonSection);

            #endregion

            #region More options Section

            // define new section
            var moreOptionsSection = new ContentViewSectionElement(detailView.Sections)
            {
                Name     = "MoreOptionsSection",
                Title    = "More Options",
                CssClass = "sfExpandableForm",
                ExpandableDefinitionConfig =
                {
                    Expanded = false
                }
            };

            // Url field for insert view
            if (displayMode == FieldDisplayMode.Write)
            {
                var urlName = new MirrorTextFieldElement(moreOptionsSection.Fields)
                {
                    Title                   = "URL",
                    ID                      = "urlName",
                    MirroredControlId       = titleField.ID,
                    DataFieldName           = "UrlName.PersistedValue",
                    DisplayMode             = displayMode,
                    RegularExpressionFilter = DefinitionsHelper.UrlRegularExpressionFilter,
                    WrapperTag              = HtmlTextWriterTag.Li,
                    ReplaceWith             = "-"
                };
                var validationDef = new ValidatorDefinitionElement(urlName)
                {
                    Required                          = true,
                    MessageCssClass                   = "sfError",
                    RequiredViolationMessage          = "Url cannot be empty",
                    RegularExpression                 = DefinitionsHelper.UrlRegularExpressionFilterForValidator,
                    RegularExpressionViolationMessage = "Invalid Url"
                };
                urlName.ValidatorConfig = validationDef;

                moreOptionsSection.Fields.Add(urlName);
            }

            // add url section to view
            detailView.Sections.Add(moreOptionsSection);

            #endregion
        }