예제 #1
0
        private int GetCurrentUserLanguageCode()
        {
            var pluginContext = this.PluginContext;

            if (this.currentUserLangCode != null)
            {
                return(this.currentUserLangCode.Value);
            }

            return((int)(this.currentUserLangCode = UserSettingUtils.GetCurrentUserLanguageCode(pluginContext)));
        }
        private XElement BuildControlSection()
        {
            var       pluginContext       = this.PluginContext;
            var       langCode            = UserSettingUtils.GetCurrentUserLanguageCode(pluginContext);
            var       ctrl                = this.control;
            var       sectionId           = Guid.NewGuid().ToString("B");
            var       controlCellId       = Guid.NewGuid().ToString("B");
            var       bottomRowsXmlString = string.Concat(Enumerable.Repeat(@"<row/>", ctrl.NumberOfRows - 1));
            const int HtmlType            = 1;
            var       webResourceId       =
                pluginContext.OrgCtx.WebResourceSet
                .Where(r =>
                       // ReSharper disable once RedundantBoolCompare
                       r.IsCustomizable != null && r.IsCustomizable.Value == true &&
                       r.IsHidden != null && r.IsHidden.Value == false &&
                       r.WebResourceType != null && r.WebResourceType.Value == HtmlType &&
                       r.Name == ctrl.WebResource)
                .Select(r => r.WebResourceId)
                .FirstOrDefault();

            if (webResourceId == null)
            {
                throw new InvalidPluginExecutionException($"Web Resource {ctrl.WebResource} is not found in the system.");
            }

            var webResourceIdString = webResourceId.Value.ToString("P").ToUpperInvariant();

            var dummySavingAttributeCellId = Guid.NewGuid().ToString("B");
            var showLabel        = ctrl.ShowLabel.ToString().ToLowerInvariant();
            var showLine         = ctrl.ShowLine.ToString().ToLowerInvariant();
            var sectionXmlString = $@"
        <section name=""{ctrl.NewSectionName}"" showlabel=""{showLabel}"" showbar=""{showLine}"" locklevel=""0"" id=""{sectionId}"" IsUserDefined=""0"" layout=""varwidth"" columns=""1"" labelwidth=""115"" celllabelalignment=""Left"" celllabelposition=""Left"">
          <labels>
	          <label description=""{ctrl.NewSectionLabel}"" languagecode=""{langCode}"" />
          </labels>
          <rows>
	        <row>
	          <cell id=""{controlCellId}"" showlabel=""false"" colspan=""1"" auto=""false"" rowspan=""{ctrl.NumberOfRows}"">
		        <labels>
		          <label description=""."" languagecode=""{langCode}"" />
		        </labels>
		        <control id=""{"WebResource_" + ctrl.NewSectionName}"" classid=""{{9FDF5F91-88B1-47f4-AD53-C11EFC01A01D}}"">
		          <parameters>
			          <Url>{ctrl.WebResource}</Url>
			          <Data>itemsetname=""{ctrl.ItemSetName}""</Data>
			          <PassParameters>true</PassParameters>
			          <ShowOnMobileClient>false</ShowOnMobileClient>
			          <Security>false</Security>
			          <Scrolling>auto</Scrolling>
			          <Border>false</Border>
			          <WebResourceId>{webResourceIdString}</WebResourceId>
		          </parameters>
		        </control>
		        <events>
		          <event name=""onload"" application=""0"">
			        <dependencies />
		          </event>
		        </events>
	          </cell>
	        </row>
	        {bottomRowsXmlString}
	        <row>
	          <cell id=""{dummySavingAttributeCellId}"" showlabel=""true"" locklevel=""0"" visible=""false"">
		        <labels>
		          <label description=""Hidden Dummy Saving Attribute"" languagecode=""{langCode}"" />
		        </labels>
		        <control id=""{ctrl.SavingAttributeName}"" classid=""{{4273EDBD-AC1D-40d3-9FB2-095C621B552D}}"" datafieldname=""{ctrl.SavingAttributeName}"" disabled=""false"" />
	          </cell>
	        </row>
          </rows>
        </section>";

            // TODO: check if the field has the same id for the same datafieldname

            return(XDocument.Parse(sectionXmlString).Root);
        }