using System;\r
using System.Collections.Generic;\r
using System.Drawing;\r
+using System.IO;\r
using System.Linq;\r
using System.Windows.Forms;\r
using TrafficClient;\r
public partial class MaestroForm {\r
private ISource source;\r
private SourceInfo selectedSource;\r
- private string startingName;\r
private List<DataGridViewRow> selectedSourceRows = new List<DataGridViewRow>();\r
\r
- public SourceIDType SourceIDType { get; set; }\r
-\r
public SourceInfo SelectedSource {\r
get {\r
return selectedSource;\r
set {\r
selectedSource = value;\r
textSelectedSource.Text = selectedSource.Name;\r
+ UpdateProcessorButtonsEnabled();\r
+ UpdateDefineSegmentEnabled();\r
UpdateEditArchiveMetadataEnabled();\r
+ UpdateLookupMetadataEnabled();\r
}\r
}\r
\r
\r
source.Startup(localAddress);\r
bindingSource.DataSource = source;\r
- dataGridSource.Columns.AddRange(new DataGridViewCheckBoxColumn());\r
+ //dataGridSource.Columns.AddRange(new DataGridViewCheckBoxColumn());\r
dataGridSource.Columns.AddRange(source.Columns);\r
}\r
\r
}\r
\r
private void OnFileInvolved(FileActionMsg m) {\r
- UpdateSelectedSources();\r
+ //UpdateSelectedSources();\r
}\r
\r
private void dataGridSource_CellMouseEnter(object sender, DataGridViewCellEventArgs e) {\r
if (selectedrows == null)\r
return;\r
if (e.ColumnIndex == 0) {\r
- UpdateSelectedSources();\r
+ UpdateCheckStates(selectedrows);\r
return;\r
}\r
if (IsPlayColumn(e.ColumnIndex)) {\r
}\r
}\r
\r
- private void UpdateSelectedSources() {\r
- String name;\r
- var selectedRows = dataGridSource.SelectedRows;\r
- bool valueOfCheckBoxes = GetValueOfCheckBoxes(selectedRows);\r
- int nameIndex = dataGridSource.Columns.Cast<DataGridViewColumn>().Where(x => x.HeaderText == StringResources.NEV).SingleOrDefault().Index;\r
- int checkBoxIndex = dataGridSource.Columns.Cast<DataGridViewColumn>().Where(x => x.GetType() == typeof(DataGridViewCheckBoxColumn)).SingleOrDefault().Index;\r
- foreach (DataGridViewRow actualRow in selectedRows) {\r
- var cells = actualRow.Cells;\r
- if (cells.Count <= 0)\r
- return;\r
- name = cells[nameIndex].Value as string;\r
+ private bool GetHasChecked(DataGridViewSelectedRowCollection selectedRows) {\r
+ foreach (DataGridViewRow row in selectedRows) {\r
+ DataGridViewCheckBoxCell checkBoxCell = row.Cells[0] as DataGridViewCheckBoxCell;\r
+ if (true.Equals(checkBoxCell.Value))\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ private void UpdateCheckStates(DataGridViewSelectedRowCollection rows) {\r
+ bool hasChecked = GetHasChecked(rows);\r
+ var nameColumn = dataGridSource.Columns.Cast<DataGridViewColumn>().Where(x => x.HeaderText == StringResources.NEV).FirstOrDefault();\r
+ if (nameColumn == null)\r
+ return;\r
+ int nameCellIndex = nameColumn.Index;\r
+ foreach (DataGridViewRow row in rows) {\r
+ String name = row.Cells[nameCellIndex].Value as string;\r
if (String.IsNullOrEmpty(name))\r
- return;\r
- DataGridViewCheckBoxCell checkBoxCell = cells[checkBoxIndex] as DataGridViewCheckBoxCell;\r
- if (selectedRows.Count > 1)\r
- checkBoxCell.Value = valueOfCheckBoxes;\r
+ continue;\r
+ DataGridViewCheckBoxCell checkBoxCell = row.Cells[0] as DataGridViewCheckBoxCell;\r
+ if (rows.Count > 1)\r
+ checkBoxCell.Value = !hasChecked;\r
else\r
checkBoxCell.Value = (checkBoxCell.Value == null || checkBoxCell.Value.Equals(false)) ? true : false;\r
+\r
if (checkBoxCell.Value.Equals(false))\r
- selectedSourceRows.Remove(actualRow);\r
- else {\r
- if (!selectedSourceRows.Contains(actualRow))\r
- selectedSourceRows.Add(actualRow);\r
- }\r
- SetTextSelectedSourceTextFromCheckBoxes();\r
- SetMetadataButtonEnabled((bool)checkBoxCell.Value);\r
+ selectedSourceRows.Remove(row);\r
+ else\r
+ selectedSourceRows.Add(row);\r
}\r
+ SetSelectedSource(nameCellIndex);\r
}\r
\r
- private bool GetValueOfCheckBoxes(DataGridViewSelectedRowCollection selectedRows) {\r
- bool result = true;\r
- int index = dataGridSource.Columns.Cast<DataGridViewColumn>().Where(x => x.GetType() == typeof(DataGridViewCheckBoxColumn)).SingleOrDefault().Index;\r
- foreach (DataGridViewRow actualRow in selectedRows) {\r
- var cells = actualRow.Cells;\r
- DataGridViewCheckBoxCell checkBoxCell = cells[index] as DataGridViewCheckBoxCell;\r
- if (checkBoxCell.Value != null && checkBoxCell.Value.Equals(true))\r
- result = false;\r
- else { result = true; return result; }\r
- }\r
- return result;\r
+ private string GetPrefix(string name) {\r
+ string[] byHyphen = name.Replace('_', '-').Replace('.', '-').Split('-');\r
+ return byHyphen.Length > 0 ? byHyphen[0] : null;\r
}\r
\r
- private void SetMetadataButtonEnabled(bool checkBox) {\r
- SetStartingName(checkBox);\r
- if (selectedSourceRows == null || selectedSourceRows.Count == 0) {\r
- buttonMetadata.Enabled = false;\r
- \r
- //IsSelectedFileAnID();\r
- return;\r
- }\r
- if (selectedSourceRows.Count == 1) {\r
- buttonMetadata.Enabled = true;\r
- //IsSelectedFileAnID();\r
- return;\r
- }\r
- int index = dataGridSource.Columns.Cast<DataGridViewColumn>().Where(x => x.HeaderText == StringResources.NEV).SingleOrDefault().Index;\r
+ private void SetSelectedSource(int nameCellIndex) {\r
+ string selectionPrefix = null;\r
+ string selectedNames = String.Empty;\r
foreach (DataGridViewRow actual in selectedSourceRows) {\r
- string name = actual.Cells[index].Value as string;\r
- if (!name.StartsWith(String.Format("{0}-", startingName)) &&\r
- !name.StartsWith(String.Format("{0}_", startingName)) &&\r
- !name.StartsWith(String.Format("{0}.", startingName))) {\r
- buttonMetadata.Enabled = false;\r
- return;\r
- }\r
- }\r
- buttonMetadata.Enabled = true;\r
- //IsSelectedFileAnID();\r
- }\r
-\r
- private void SetStartingName(bool checkBox) {\r
- if (!checkBox)\r
- if (selectedSourceRows == null || selectedSourceRows.Count == 0) {\r
- startingName = null;\r
- return;\r
- }\r
- int index = dataGridSource.Columns.Cast<DataGridViewColumn>().Where(x => x.HeaderText == StringResources.NEV).SingleOrDefault().Index;\r
- string query = selectedSourceRows[0].Cells[index].Value as string;\r
- int separatorPosition = query.IndexOf("-");\r
- int separatorPosition2 = query.IndexOf("_");\r
- int realseparatorPosition = 0;\r
- if (separatorPosition < 0)\r
- realseparatorPosition = separatorPosition2;\r
- else if (separatorPosition2 < 0)\r
- realseparatorPosition = separatorPosition;\r
- else\r
- realseparatorPosition = separatorPosition < separatorPosition2 ? separatorPosition : separatorPosition2;\r
- int dotPosition = query.IndexOf(".");\r
- if (realseparatorPosition > 0) {\r
- startingName = realseparatorPosition < 0 ? query : query.Substring(0, realseparatorPosition);\r
- } else {\r
- if (dotPosition < 0)\r
- startingName = realseparatorPosition < 0 ? query : query.Substring(0, realseparatorPosition);\r
+ string name = actual.Cells[nameCellIndex].Value as string;\r
+ selectedNames += name + " ";\r
+ string currentPrefix = GetPrefix(name);\r
+ if (selectionPrefix == null)\r
+ selectionPrefix = currentPrefix;\r
else\r
- startingName = query.Substring(0, dotPosition);\r
+ selectionPrefix = currentPrefix.Equals(selectionPrefix) ? selectionPrefix : null;\r
}\r
-\r
- SourceIDType = GetSourceType(startingName);\r
- UpdateDetectMetadataEnabled();\r
- }\r
-\r
- private void SetTextSelectedSourceTextFromCheckBoxes() {\r
- String selectedNames = "";\r
- int index = dataGridSource.Columns.Cast<DataGridViewColumn>().Where(x => x.HeaderText == StringResources.NEV).SingleOrDefault().Index;\r
- foreach (DataGridViewRow actual in selectedSourceRows) \r
- selectedNames += actual.Cells[index].Value + " ";\r
SelectedSource = new SourceInfo() {\r
- Name = selectedNames\r
+ Name = selectedNames,\r
+ FileInfo = GetSelectedSourceFileInfo(nameCellIndex),\r
+ Prefix = selectionPrefix\r
};\r
- SetSelectedSourceFileInfo(SelectedSource);\r
- ApplyProcessorButtonsLogicWithoutArchiveMetadataButton();\r
}\r
\r
- private void SetSelectedSourceFileInfo(SourceInfo selectedSource) {\r
+ private FileInfo GetSelectedSourceFileInfo(int nameCellIndex) {\r
if (Configuration.Source.GetType() == typeof(NEXIOSource))\r
- selectedSource.FileInfo = null;\r
- else if (selectedSourceRows.Count == 1) {\r
- int index = dataGridSource.Columns.Cast<DataGridViewColumn>().Where(x => x.HeaderText == StringResources.NEV).SingleOrDefault().Index;\r
- string name = selectedSourceRows[0].Cells[index].Value as string;\r
- Uri inputUri = new Uri(String.Format("{0}/{1}", Configuration.Source.Local.Address.LocalPath, name));\r
- selectedSource.FileInfo = new System.IO.FileInfo(inputUri.LocalPath);\r
- }\r
+ return null;\r
+ if (selectedSourceRows.Count != 1)\r
+ return null;\r
+ string name = selectedSourceRows[0].Cells[nameCellIndex].Value as string;\r
+ Uri inputUri = new Uri(String.Format("{0}/{1}", Configuration.Source.Local.Address.LocalPath, name));\r
+ return new FileInfo(inputUri.LocalPath);\r
}\r
\r
private void dataGridSource_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {\r
private void dataGridSource_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) {\r
if (e.RowIndex < 0)\r
return;\r
- UpdateSelectedSources();\r
+ UpdateCheckStates(dataGridSource.SelectedRows);\r
}\r
\r
private void dataGridSource_KeyDown(object sender, KeyEventArgs e) {\r
if (e.KeyCode != Keys.Space || dataGridSource.CurrentCell.GetType() == typeof(DataGridViewCheckBoxCell))\r
return;\r
- UpdateSelectedSources();\r
+ UpdateCheckStates(dataGridSource.SelectedRows);\r
}\r
\r
private void buttonMetadata_Click(object sender, EventArgs e) {\r
- switch (SourceIDType) {\r
+ switch (GetSourceType(SelectedSource?.Prefix)) {\r
case SourceIDType.TrafficID:\r
LookupTraffic();\r
break;\r
TrafficAPI api = trafficIDSelector.trafficAPI;\r
Cursor.Current = Cursors.WaitCursor;\r
List<TrafficItem> result = null;\r
- MetadataType metadataType = GetTrafficMetadataType(startingName);\r
+ MetadataType metadataType = GetTrafficMetadataType(SelectedSource?.Prefix);\r
switch (metadataType) {\r
case MetadataType.TrafficMaterial:\r
- result = api.GetMaterials(startingName, false);\r
+ result = api.GetMaterials(SelectedSource?.Prefix, false);\r
break;\r
case MetadataType.TrafficPromo:\r
- result = api.GetPromos(startingName, false);\r
+ result = api.GetPromos(SelectedSource?.Prefix, false);\r
break;\r
case MetadataType.TrafficAD:\r
- result = api.GetADs(startingName, false);\r
+ result = api.GetADs(SelectedSource?.Prefix, false);\r
break;\r
}\r
if (result == null || result.Count == 0) {\r
private void LookupOctopus() {\r
OctopusAPI api = octopusIDSelector.GetClient();\r
Cursor.Current = Cursors.WaitCursor;\r
- IEnumerable<Story> stories = api.GetStoriesById(startingName);\r
+ IEnumerable<Story> stories = api.GetStoriesById(SelectedSource?.Prefix);\r
if (stories == null || stories.Count() == 0) {\r
LookupOctopusMOS(api);\r
Cursor.Current = Cursors.Default;\r
}\r
\r
private void LookupOctopusMOS(OctopusAPI api) {\r
- IEnumerable<MosObject> mosIDs = api.GetMosObjectsByID(startingName);\r
+ IEnumerable<MosObject> mosIDs = api.GetMosObjectsByID(SelectedSource?.Prefix);\r
if (mosIDs == null) {\r
MessageBox.Show(this, StringResources.NINCS_TALALAT);\r
return;\r
box.ShowDialog();\r
}\r
\r
- private void UpdateDetectMetadataEnabled() {\r
- buttonMetadata.Enabled = SourceIDType != SourceIDType.MediaCube;\r
+ private void UpdateLookupMetadataEnabled() {\r
+ buttonMetadata.Enabled = !String.IsNullOrEmpty(SelectedSource?.Prefix) && GetSourceType(SelectedSource?.Prefix) != SourceIDType.MediaCube;\r
}\r
\r
}\r
using System.Collections.Generic;\r
using System.ComponentModel;\r
using System.Drawing;\r
+using System.Runtime.InteropServices;\r
\r
namespace OctopusClient {\r
public delegate void OnSelectedIDChanged(string ID);\r
public delegate void ClearCheckBox();\r
public delegate void OctopusErrorReporterDelegate(DateTime time, String level, String message, Color color);\r
\r
+\r
+\r
public partial class OctopusIDSelector : UserControl {\r
private static Logger logger = LogManager.GetCurrentClassLogger();\r
private string id;\r
foreach (var story in stories) {\r
string name = story.Name == null ? "<UnNamed>" : story.Name;\r
TreeNode actualNode = treeOctopus.Nodes.Add(story.ID, String.Format($"{story.ID} {story.Name}"));\r
+ HideCheckBox(treeOctopus, actualNode);\r
MosObject[] mosObjects = story.MosObjects;\r
- foreach (MosObject mosObject in mosObjects)\r
+ foreach (MosObject mosObject in mosObjects) {\r
actualNode.Nodes.Add(mosObject.ID, mosObject.ID);\r
+ }\r
}\r
selectedRundownIndex = comboRudowns.SelectedIndex;\r
}\r
return;\r
foreach (var story in stories) {\r
TreeNode actualNode = treeOctopus.Nodes.Add(story.ID, String.Format($"{story.ID} {story.Name}"));\r
+ HideCheckBox(treeOctopus, actualNode);\r
MosObject[] mosObjects = story.MosObjects;\r
foreach (MosObject mosObject in mosObjects)\r
actualNode.Nodes.Add(mosObject.ID, mosObject.ID);\r
}\r
\r
private void treeContent_KeyDown(object sender, KeyEventArgs e) {\r
- this.OnKeyDown(e);\r
+ //this.OnKeyDown(e);\r
}\r
\r
private void OnTreeAfterCheck(object sender, TreeViewEventArgs e) {\r
logger.Debug("Handling {0} {1}", e.Node.Name, e.Node.Text);\r
+ if (e.Node.Level == 0) {\r
+ if (e.Node.Checked) {\r
+ e.Node.Checked = false;\r
+ HideCheckBox(treeOctopus, e.Node);\r
+ }\r
+ return;\r
+ }\r
if (!e.Node.Equals(selectedNode)) {\r
ClearSelection();\r
selectedNode = e.Node;\r
public OctopusAPI GetClient() {\r
return client;\r
}\r
+\r
+\r
+ private const int TVIF_STATE = 0x8;\r
+ private const int TVIS_STATEIMAGEMASK = 0xF000;\r
+ private const int TV_FIRST = 0x1100;\r
+ private const int TVM_SETITEM = TV_FIRST + 63;\r
+\r
+ [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)]\r
+ private struct TVITEM {\r
+ public int mask;\r
+ public IntPtr hItem;\r
+ public int state;\r
+ public int stateMask;\r
+ [MarshalAs(UnmanagedType.LPTStr)]\r
+ public string lpszText;\r
+ public int cchTextMax;\r
+ public int iImage;\r
+ public int iSelectedImage;\r
+ public int cChildren;\r
+ public IntPtr lParam;\r
+ }\r
+\r
+ [DllImport("user32.dll", CharSet = CharSet.Auto)]\r
+ private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam,\r
+ ref TVITEM lParam);\r
+\r
+ /// <summary>\r
+ /// Hides the checkbox for the specified node on a TreeView control.\r
+ /// </summary>\r
+ private void HideCheckBox(TreeView tvw, TreeNode node) {\r
+ TVITEM tvi = new TVITEM();\r
+ tvi.hItem = node.Handle;\r
+ tvi.mask = TVIF_STATE;\r
+ tvi.stateMask = TVIS_STATEIMAGEMASK;\r
+ tvi.state = 0;\r
+ SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);\r
+ }\r
}\r
}\r