Exemplo n.º 1
0
        private void ThrowIfUnsupportedContentType()
        {
            var matchAllContentType = ContentTypes?.FirstOrDefault(
                contentType => contentType.MatchesAllSubTypes || contentType.MatchesAllTypes);

            if (matchAllContentType != null)
            {
                throw new InvalidOperationException(
                          Resources.FormatObjectResult_MatchAllContentType(matchAllContentType, nameof(ContentTypes)));
            }
        }
        public void UpdateLanguageCountryVersion()
        {
            var systemContentType = ContentTypes.FirstOrDefault(p => p.Label.Equals("_System"));

            systemContentType.LoadEntries(true);
            //This returns only one field value , this is becuase of the currently selected country
            //which is good and acts as a second safeguard to updating values for only the country involved
            var currentCountry = AvailableCountries[SelectedCountryIndex];
            var rowData        = systemContentType.GetRowData();
            var entry          = systemContentType.Entries[0];

            if (entry.FieldData["country"].Equals(currentCountry))
            {
                var value     = entry.FieldData["value"];
                var valueData = value.Split('.');
                if (valueData.Length != 2)
                {
                    MessageBox.Show("Error", "Error : system versioning for " + currentCountry + "does not conform to the required {date}.{version} format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var valDate    = valueData[0];
                int valVersion = 0;
                try
                {
                    valVersion = int.Parse(valueData[1]);
                }
                catch { }

                var currentDateString = DateTime.Now.ToString("yyyy-MM-dd");
                if (!valDate.Equals(currentDateString))
                {
                    valVersion = 0;
                }
                valVersion = valVersion + 1;
                string newValueString = currentDateString + "." + valVersion;
                if (valVersion < 10)
                {
                    newValueString = currentDateString + ".0" + valVersion;
                }


                entry.FieldData["value"] = newValueString;

                var dynUpdate = entry.GetDynamicEntry(systemContentType.ContentFullType.Fields.ToArray());

                UpdateContent(dynUpdate, systemContentType.TypeID);
            }
        }