protected static bool ValidateDescription(DataItemBase item) { bool success; item.Feedback.ValidateLength(item.DataControl as TextBox, item.Description, 1, 90, out success); return(success); }
private void fastListViewMain_DrawItem(object sender, DrawListViewItemEventArgs e) { if (e.ItemIndex == -1) { return; } Debug.WriteLine("listview drawItem {0}", e.ItemIndex); var bound = e.Bounds; DataItemBase item = (DataItemBase)e.Item.Tag; bool isSelected = e.Item.Selected; // draw background if (isSelected) { // normal background e.Graphics.FillRectangle(e.ItemIndex % 2 == 1 ? this.fastListViewMain.AlternateBackColorBrush : this.fastListViewMain.SelectionBackColorBrush, bound); } else { // level background if (Settings.Default.Display_ColoredLevel) { var level = item.Level; var index = level == LogLevels.Critical ? 0 : (level == LogLevels.Error ? 1 : (level == LogLevels.Warning ? 2 : (level == LogLevels.Info ? 3 : (level == LogLevels.Verbose ? 4 : 5)))); if (index < this.fastListViewMain.LevelBrushes.Count) { e.Graphics.FillRectangle(this.fastListViewMain.LevelBrushes[index], bound); } else { e.DrawBackground(); } } else { e.DrawBackground(); } } // draw lines e.Graphics.DrawLine(this.fastListViewMain.GridLineColorPen, bound.X, bound.Y + bound.Height - 1, bound.X + bound.Width, bound.Y + bound.Height - 1); e.DrawFocusRectangle(); }
private void AllSettings_Load(object sender, EventArgs e) { // first page: this.checkBoxColorLevel.Checked = Settings.Default.Display_ColoredLevel; if (Settings.Default.Display_LevelColors == null) { Settings.Default.Display_LevelColors = new LevelColors(); } this.propertyGridLevelColor.SelectedObject = Settings.Default.Display_LevelColors.Clone(); if (Settings.Default.Display_TagColors == null) { Settings.Default.Display_TagColors = new TagColors(); } this.propertyGridTagColors.SelectedObject = Settings.Default.Display_TagColors.Clone(); this.checkBoxBoldParameter.Checked = Settings.Default.Display_BoldParameter; this.checkBoxHighlightMatch.Checked = Settings.Default.Display_HighlightFind; this.checkBoxFastRendering.Checked = Settings.Default.Display_FastRendering; this.textBoxIndentSize.Text = Settings.Default.Indent_Size.ToString(); // second page: this.checkBoxAutoLoad.Checked = Settings.Default.Behavior_AutoLoad; this.checkBoxAutoScroll.Checked = Settings.Default.Behavior_AutoScroll; this.checkBoxDataVirtual.Checked = Settings.Default.Behavior_DataVirtualization; this.checkBoxCompression.Checked = Settings.Default.Behavior_EnabledCompression; // third page: this.checkBoxAllowReordering.Checked = Settings.Default.Behavior_AllowColumnReorder; this.checkedListBoxColumns.Items.AddRange( DataItemBase.GetColumnInfos(DataItemBase.GetPropertyInfos <DataItemBase>()).Select(c => (object)c.Name).ToArray()); var hidenColumns = new HashSet <string>(); foreach (var c in Settings.Default.Display_HidenColumns) { hidenColumns.Add(c); } for (var i = 0; i < this.checkedListBoxColumns.Items.Count; i++) { this.checkedListBoxColumns.SetItemChecked(i, !hidenColumns.Contains((string)this.checkedListBoxColumns.Items[i])); } // hotkeys page foreach (var k in HotKeys.Instance) { this.dataGridViewHotKeys.Rows.Add(k.Value, k.Key); } }
private void LoadDefaultDeadlines() { var defaultElectionKey = Elections.GetDefaultElectionKeyFromKey(GetElectionKey()); var defaults = ElectionsDefaults.GetData(defaultElectionKey).FirstOrDefault(); foreach (var item in _ChangeDeadlinesTabInfo) { if (DataItemBase.FindControl(this, "Default" + ChangeDeadlinesTabItem.GroupName + item.Column) is HtmlContainerControl defaultControl) { var val = (DateTime?)defaults?[item.Column] ?? DefaultDbDate; var str = val == DefaultDbDate ? "<none>" : val.ToString("d"); defaultControl.InnerText = $"Default: {str}"; } } }
protected override void DoWork() { float nMidValue = -1.0F; while (true) { while (NeedToPause()) { Thread.Sleep(1000); } if (NeedToStop()) { break; } // get memory usage float value = mCounter.NextValue(); if (nMidValue < 0) { nMidValue = value; // IDataItem <float> item = new DataItemBase <float>(); item.set(value); mStorage.Add(item); } else { // check 10% treshold float delta = Math.Abs(value - nMidValue); float proc = (nMidValue > 0) ? delta / nMidValue : 1.0F; // procent of var if (proc > 0.1F && delta > 50.0F) // 10% relative and 50ла absolute value of memory usage delta { nMidValue = 0.5F * (nMidValue + value); // tune mid value; // store to base IDataItem <float> item = new DataItemBase <float>(); item.set(value); mStorage.Add(item); } } Thread.Sleep(1000); } }
private static bool ValidateUniqueEmail(DataItemBase item) { var success = ValidateRequired(item); if (success) { var newValue = item.DataControl.GetValue(); var oldValue = GetCurrentValue(item); if (newValue.IsNeIgnoreCase(oldValue) && PartiesEmails.PartyEmailExists(item.DataControl.GetValue())) { item.Feedback.PostValidationError(item.DataControl, "The new email address already exists."); success = false; } } return(success); }
private void LoadDefaultText() { var defaultElectionKey = Elections.GetDefaultElectionKeyFromKey(GetElectionKey()); var defaults = ElectionsDefaults.GetData(defaultElectionKey).FirstOrDefault(); foreach (var item in _ChangeInfoTabInfo) { if (DataItemBase.FindControl(this, $"Default{ChangeInfoTabItem.GroupName}{item.Column}") is HtmlContainerControl defaultControl) { var val = defaults?[item.Column] as string; var str = IsNullOrWhiteSpace(val) ? "<none>" : val; defaultControl.InnerText = $"Default: {str}"; defaultControl.Attributes["title"] = WebUtility.HtmlEncode(defaultControl.InnerText); } } }
protected void ButtonEditVolunteer_OnClick(object sender, EventArgs e) { switch (EditVolunteerReloading.Value) { case "reloading": { EditVolunteerReloading.Value = Empty; RefreshReport.Value = "N"; var stateCode = VolunteersView.GetStateCode(GetVolunteerToEdit()).SafeString(); StateCache.Populate(ControlEditVolunteerStateCode, stateCode); Parties.PopulateNationalParties(ControlEditVolunteerPartyCode, true, null, true, null); //LoadEditParties(stateCode); _EditVolunteerDialogInfo.LoadControls(); //LoadEditUndos(); FeedbackEditVolunteer.AddInfo("Volunteer information loaded."); } break; case "": { // normal update _EditVolunteerDialogInfo.ClearValidationErrors(); _EditVolunteerDialogInfo.Update(FeedbackEditVolunteer); var emailItem = _EditVolunteerDialogInfo.FirstOrDefault(i => i.Column == "Email"); if (!emailItem?.DataControl.HasClass("error") == true) { VolunteerToEdit.Value = DataItemBase.GetCurrentValue(emailItem); } RefreshReport.Value = "Y"; //LoadEditUndos(); } break; default: throw new VoteException( $"Unknown reloading option: '{EditVolunteerReloading.Value}'"); } }
private static bool ValidateIncumbents(DataItemBase item) { var tabItem = item as AddCandidatesTabItem; Debug.Assert(tabItem != null, nameof(tabItem) + " != null"); if (tabItem._ThisControl.Mode != DataMode.ManageCandidates) { return(true); } // make sure there aren't too many incumbents var newCandidates = UpdateParse(tabItem.GetControlValue()); var officeKey = tabItem._ThisControl.SafeGetOfficeKey(); var checkedIncumbents = newCandidates.Count(c => c.ShowAsIncumbent); var allowedIncumbents = Offices.GetIncumbents(officeKey, 0); if (checkedIncumbents <= allowedIncumbents) { return(true); } item.Feedback.AddError($"Warning: There are too many incumbents: {checkedIncumbents} checked, " + $"{allowedIncumbents} allowed"); return(true); }
private static bool ValidateCountySupervisors(DataItemBase item) { var thisItem = item as SetupCountySupervisorsTabItem; Debug.Assert(thisItem != null, "thisItem != null"); var submitted = thisItem._Submitted; var feedback = thisItem.Feedback; var control = item.DataControl; var stateCode = thisItem.Page.StateCode; var countyCode = thisItem.Page.CountyCode; // pre-trim names and ids foreach (var s in submitted) { s.Id = s.Id.Trim(); s.Name = s.Name.Trim(); } // ids must exist var missingIds = submitted.Where(s => s.Id == string.Empty).ToList(); if (missingIds.Count > 0) { feedback.PostValidationError(control, "Every entry must have a Shapefile Id."); foreach (var e in missingIds) { e.SetError("Id"); } } // ids must be 5 characters, all numeric var invalidIds = submitted .Where(s => s.Id != string.Empty && s.Id.Length != 5 || !s.Id.IsDigits()) .ToList(); if (invalidIds.Count > 0) { feedback.PostValidationError(control, "Invalid Shapefile Id(s). Ids must be 5 numeric characters."); foreach (var e in missingIds) { e.SetError("Id"); } } // ids must be unique var duplicateIds = submitted.GroupBy(s => s.Id).Where(g => g.Count() > 1).ToList(); if (duplicateIds.Count > 0) { feedback.PostValidationError(control, "Shapefile Ids must be unique."); foreach (var g in duplicateIds) { foreach (var e in g) { e.SetError("Id"); } } } // except for DC, ids must begin with the county code if (stateCode != "DC") { var missingCounties = submitted.Where(s => !s.Id.StartsWith(countyCode)).ToList(); if (missingCounties.Count > 0) { feedback.PostValidationError(control, "Shapefile Ids must begin with the CountyCode (except DC)."); foreach (var e in missingCounties) { e.SetError("Id"); } } } // all items except deletes must have a name var missingNames = submitted.Where(s => !s.Delete && s.Name == string.Empty) .ToList(); if (missingNames.Count > 0) { feedback.PostValidationError(control, "Missing District Name(s)."); foreach (var e in missingNames) { e.SetError("Name"); } } if (feedback.ValidationErrorCount == 0) { return(true); } // there were errors thisItem.Page.LoadCountySupervisorDistricts(submitted); return(false); }
private void fastListViewMain_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { // Debug.WriteLine("Redrawing Row {0} Column {1}", e.ItemIndex, e.ColumnIndex); // draw contents. var bound = e.Bounds; DataItemBase item = (DataItemBase)e.Item.Tag; if (item == null) { return; } var isSelected = e.Item.Selected; StringFormat format = new StringFormat(StringFormatFlags.NoWrap) { // Alignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, LineAlignment = StringAlignment.Center, }; if (Settings.Default.Display_FastRendering) { e.Graphics.SmoothingMode = SmoothingMode.HighSpeed; e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel; } Brush foreBrush = isSelected ? this.fastListViewMain.SelectionForeColorBrush : this.fastListViewMain.ForeColorBrush; switch (e.ColumnIndex) { case 5: bool isIndented = this.CurrentView?.IsThreadIndented(item.ThreadId) ?? false; if (!isIndented) { isIndented = this.CurrentView?.IsActivityIndented(item.ActivityIdIndex) ?? false; } if (isIndented) { bound.Width -= 100; bound.X += 100; } var paramString = (ParametricString)e.SubItem.Tag; foreach (var token in paramString.GetTokens()) { const int multiLineSignWidth = 25; var str = token.Key; var pos = str.IndexOf(Environment.NewLine, StringComparison.Ordinal); if (pos >= 0) { str = str.Substring(0, pos); bound.Width -= multiLineSignWidth; if (bound.Width < 0) { bound.Width = 0; } } str = str.Replace("\n", " "); var currentFont = token.Value && Settings.Default.Display_BoldParameter ? this.fastListViewMain.BoldFont : this.fastListViewMain.NormalFont; if (str.Length > 0 && bound.Width > 0) { e.Graphics.DrawString( str, currentFont, isSelected ? this.fastListViewMain.SelectionForeColorBrush : this.fastListViewMain.ForeColorBrush, bound, this.DefaultStringFormat); } if (pos > 0) { bound = e.Bounds; bound.X += bound.Width - multiLineSignWidth; bound.Width = multiLineSignWidth; // draw a >> sign to indicate multiline e.Graphics.DrawString( "↓↓↓", currentFont, isSelected ? this.fastListViewMain.SelectionForeColorBrush : this.fastListViewMain.ForeColorBrush, bound, this.DefaultStringFormat); break; } var length = e.Graphics.MeasureString(str, currentFont).Width + 0.5f; bound.Width -= (int)length; if (bound.Width <= 0) { break; } bound.X += (int)length; } break; case 4: var colorList = (List <int>)e.SubItem.Tag; var rect = e.Bounds; rect.X += 4; rect.Y += 4; rect.Height -= 8; rect.Width = rect.Height; for (var j = 0; j < this.TagBrushes.Count; j++) { if (colorList.Contains(j)) { e.Graphics.FillRectangle(this.TagBrushes[j], rect); } rect.X += rect.Width + 2; } break; default: e.Graphics.DrawString(this.CurrentView?.GetColumnValue((DataItemBase)e.Item.Tag, this.columnDataIndexMapping[e.ColumnIndex]).ToString(), e.SubItem.Font, foreBrush, bound, format); break; } }
private void Consolidate() { try { var key1Item = _MasterOnlyTabInfo.Single(i => i.Column == "Key1"); var key2Item = _MasterOnlyTabInfo.Single(i => i.Column == "Key2"); var jurisdictionKey = JurisdictionalKey; var success = true; success &= DataItemBase.ValidateRequired(key1Item); var key1Office = key1Item.DataControl.GetValue().Trim(); success &= DataItemBase.ValidateRequired(key2Item); var key2Office = key2Item.DataControl.GetValue().Trim(); if (success && key1Office.IsEqIgnoreCase(key2Office)) { key2Item.Feedback.PostValidationError(key2Item.DataControl, key2Item.Description + " is identical to " + key1Item.Description); success = false; } var officeKey1 = jurisdictionKey + key1Office; var officeKey2 = jurisdictionKey + key2Office; if (!success) { return; } // do the consolidation var updateCount = 0; if (Offices.OfficeKeyExists(officeKey1)) { updateCount += Offices.DeleteByOfficeKey(officeKey2); } else { updateCount += Offices.UpdateOfficeKey(officeKey1, officeKey2); } foreach (var row in ElectionsOffices.GetDataByOfficeKey(officeKey2)) { if (ElectionsOffices.ElectionKeyOfficeKeyExists(row.ElectionKey, officeKey1)) { updateCount += ElectionsOffices.DeleteByElectionKeyOfficeKey(row.ElectionKey, officeKey2); } else { updateCount += ElectionsOffices.UpdateOfficeKeyByElectionKeyOfficeKey(officeKey1, row.ElectionKey, officeKey2); } } foreach (var row in ElectionsPoliticians.GetDataByOfficeKey(officeKey2)) { if (ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists(row.ElectionKey, officeKey1, row.PoliticianKey)) { updateCount += ElectionsPoliticians.DeleteByElectionKeyOfficeKeyPoliticianKey( row.ElectionKey, officeKey2, row.PoliticianKey); } else { updateCount += ElectionsPoliticians.UpdateOfficeKeyByElectionKeyOfficeKeyPoliticianKey( officeKey1, row.ElectionKey, officeKey2, row.PoliticianKey); } } foreach (var row in OfficesOfficials.GetDataByOfficeKey(officeKey2)) { if (OfficesOfficials.OfficeKeyPoliticianKeyExists(officeKey1, row.PoliticianKey)) { updateCount += OfficesOfficials.DeleteByOfficeKeyPoliticianKey(officeKey2, row.PoliticianKey); } else { updateCount += OfficesOfficials.UpdateOfficeKeyByOfficeKeyPoliticianKey(officeKey1, officeKey2, row.PoliticianKey); } } foreach (var row in ElectionsIncumbentsRemoved.GetDataByOfficeKey(officeKey2)) { if (ElectionsIncumbentsRemoved.ElectionKeyOfficeKeyPoliticianKeyExists(row.ElectionKey, officeKey1, row.PoliticianKey)) { updateCount += ElectionsIncumbentsRemoved.DeleteByElectionKeyOfficeKeyPoliticianKey( row.ElectionKey, officeKey2, row.PoliticianKey); } else { updateCount += ElectionsIncumbentsRemoved .UpdateOfficeKeyByElectionKeyOfficeKeyPoliticianKey( officeKey1, row.ElectionKey, officeKey2, row.PoliticianKey); } } updateCount += Politicians.UpdateOfficeKeyByOfficeKey(officeKey1, officeKey2); var msg = $"{updateCount} instances of the second office key {officeKey2} were found."; if (updateCount > 0) { msg += $" They were all changed to the first office key {officeKey1}."; } FeedbackMasterOnly.AddInfo(msg); ResetMasterOnlySubTab(MasterOnlySubTab.Consolidate); } catch (Exception ex) { FeedbackMasterOnly.PostValidationError(ControlMasterOnlyNewKey, "The office keys could not be consolidated: " + ex.Message); } }
private void ChangeOfficeKey() { try { var oldKeyItem = _MasterOnlyTabInfo.Single(i => i.Column == "OldKey"); var newKeyItem = _MasterOnlyTabInfo.Single(i => i.Column == "NewKey"); var jurisdictionKey = JurisdictionalKey; var success = true; success &= DataItemBase.ValidateRequired(oldKeyItem); var oldKeyOffice = oldKeyItem.DataControl.GetValue().Trim(); success &= DataItemBase.ValidateRequired(newKeyItem); var newKeyOffice = newKeyItem.DataControl.GetValue().Trim(); if (!string.IsNullOrWhiteSpace(newKeyOffice)) { // get rid of all non-alphanumerics newKeyOffice = Regex.Replace(newKeyOffice, @"[^\dA-Z]", string.Empty, RegexOptions.IgnoreCase); // get rid of leading numerics newKeyOffice = Regex.Replace(newKeyOffice, @"^\d+", string.Empty); var maxLength = Offices.OfficeKeyMaxLength - jurisdictionKey.Length; if (newKeyOffice.Length > maxLength) { newKeyItem.Feedback.PostValidationError(newKeyItem.DataControl, newKeyItem.Description + " is too long by " + (newKeyOffice.Length - maxLength) + " characters."); success = false; } if (newKeyOffice.Length == 0) { newKeyItem.Feedback.PostValidationError(newKeyItem.DataControl, newKeyItem.Description + " consists entirely of non-key characters."); success = false; } } if (success && (oldKeyOffice == newKeyOffice)) { newKeyItem.Feedback.PostValidationError(newKeyItem.DataControl, newKeyItem.Description + " is identical to the Old Office Key."); success = false; } var oldOfficeKey = jurisdictionKey + oldKeyOffice; var newOfficeKey = jurisdictionKey + newKeyOffice; var caseChangeOnly = oldOfficeKey.IsEqIgnoreCase(newOfficeKey); if (success && !caseChangeOnly) { // Make sure the new office key doesn't already exist var existsInTables = new List <string>(); if (Offices.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(Offices.TableName); } if (ElectionsOffices.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(ElectionsOffices.TableName); } if (ElectionsPoliticians.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(ElectionsPoliticians.TableName); } if (OfficesOfficials.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(OfficesOfficials.TableName); } if (ElectionsIncumbentsRemoved.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(ElectionsIncumbentsRemoved.TableName); } if (Politicians.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(Politicians.TableName); } if (existsInTables.Count > 0) { newKeyItem.Feedback.PostValidationError(newKeyItem.DataControl, newKeyItem.Description + " already exists in the following tables: " + string.Join(", ", existsInTables)); success = false; } } if (!success) { return; } // do the replacement var updateCount = 0; updateCount += Offices.UpdateOfficeKey(newOfficeKey, oldOfficeKey); updateCount += ElectionsOffices.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); updateCount += ElectionsPoliticians.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); updateCount += OfficesOfficials.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); updateCount += ElectionsIncumbentsRemoved.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); updateCount += Politicians.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); var msg = $"{updateCount} instances of the old office key {oldOfficeKey} were found."; if (updateCount > 0) { msg += $" They were all changed to the new office key {newOfficeKey}."; } FeedbackMasterOnly.AddInfo(msg); ResetMasterOnlySubTab(MasterOnlySubTab.ChangeKey); } catch (Exception ex) { FeedbackMasterOnly.PostValidationError(ControlMasterOnlyNewKey, "The office key could not be changed: " + ex.Message); } }
private static bool ValidateCityCouncil(DataItemBase item) { var thisItem = item as SetupCityCouncilTabItem; Debug.Assert(thisItem != null, "thisItem != null"); var submitted = thisItem._Submitted; var feedback = thisItem.Feedback; var control = item.DataControl; // pre-trim districts, names and ids foreach (var s in submitted) { s.Id = s.Id.Trim(); s.District = s.District.Trim(); s.Name = s.Name.Trim(); } // ids must exist var missingIds = submitted.Where(s => s.Id == Empty).ToList(); if (missingIds.Count > 0) { feedback.PostValidationError(control, "Every entry must have a Shapefile Id."); foreach (var e in missingIds) { e.SetError(nameof(CityCouncilItem.Id)); } } // ids must be 5 characters, all numeric var invalidIds = submitted .Where(s => s.Id != Empty && (s.Id.Length != 5 || !char.IsUpper(s.Id[0]) && !char.IsDigit(s.Id[0]) || !s.Id.Substring(1, 4).IsDigits())).ToList(); if (invalidIds.Count > 0) { feedback.PostValidationError(control, //"Invalid Shapefile Id(s). Ids must be 5 numeric characters."); "Invalid Shapefile Id(s). Ids must be 5 alphanumeric characters, the last 4 numeric."); foreach (var e in missingIds) { e.SetError(nameof(CityCouncilItem.Id)); } } // ids must be unique var duplicateIds = submitted.GroupBy(s => s.Id).Where(g => g.Count() > 1).ToList(); if (duplicateIds.Count > 0) { feedback.PostValidationError(control, "Shapefile Ids must be unique."); foreach (var g in duplicateIds) { foreach (var e in g) { e.SetError(nameof(CityCouncilItem.Id)); } } } // ids must begin with the designated prefix var missingPrefixes = submitted .Where(s => !s.Id.StartsWith(thisItem.Page.CityCouncilPrefix.Text)).ToList(); if (missingPrefixes.Count > 0) { feedback.PostValidationError(control, "Shapefile Ids must begin with the City Council Prefix."); foreach (var e in missingPrefixes) { e.SetError(nameof(CityCouncilItem.Id)); } } // all items except deletes must have a name var missingNames = submitted.Where(s => !s.Delete && s.Name == Empty).ToList(); if (missingNames.Count > 0) { feedback.PostValidationError(control, "Missing District Name(s)."); foreach (var e in missingNames) { e.SetError(nameof(CityCouncilItem.Name)); } } // all items except deletes must have a district var missingDistricts = submitted.Where(s => !s.Delete && s.District == Empty).ToList(); if (missingDistricts.Count > 0) { feedback.PostValidationError(control, "Missing District(s)."); foreach (var e in missingDistricts) { e.SetError(nameof(CityCouncilItem.District)); } } if (feedback.ValidationErrorCount == 0) { return(true); } // there were errors thisItem.Page.LoadCityCouncilDistricts(submitted); return(false); }
private static bool ValidateYouTubeAddress(DataItemBase item) { string message = null; var value = item.DataControl.GetValue(); if (!string.IsNullOrWhiteSpace(value)) { if (value.IsValidYouTubeVideoUrl()) { var id = value.GetYouTubeVideoId(); var info = YouTubeUtility.GetVideoInfo(id, true, 1); if (!info.IsValid) { message = YouTubeInfo.VideoIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeInfo.VideoNotPublicMessage; } } else if (value.IsValidYouTubePlaylistUrl()) { var id = value.GetYouTubePlaylistId(); var info = YouTubeUtility.GetPlaylistInfo(id, true, 1); if (!info.IsValid) { message = YouTubeInfo.PlaylistIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeInfo.PlaylistNotPublicMessage; } } else if (value.IsValidYouTubeChannelUrl() || value.IsValidYouTubeCustomChannelUrl() || value.IsValidYouTubeUserChannelUrl()) { var id = YouTubeUtility.LookupChannelId(value, 1); if (string.IsNullOrWhiteSpace(id)) { message = YouTubeInfo.ChannelIdNotFoundMessage; } else { var info = YouTubeUtility.GetChannelInfo(id, true, 1); if (!info.IsValid) { message = YouTubeInfo.ChannelIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeInfo.ChannelNotPublicMessage; } } } else { message = "The URL is not a valid YouTube channel, playlist or video URL"; } } if (string.IsNullOrWhiteSpace(message)) { item.DataControl.SetValue( Validation.StripWebProtocol(value)); } else { item.Feedback.PostValidationError(item.DataControl, message); } return(string.IsNullOrWhiteSpace(message)); }