Beispiel #1
0
        /// <summary>
        /// Delete Label
        /// </summary>
        /// <param name="label">The Label</param>
        public void DeleteLabel(DataContract.Metadata.Label label)
        {
            try
            {
                if (label == null)
                {
                    throw new ArgumentNullException("label");
                }

                /*
                 * First need to lookup the label entity from the database
                 */
                var labelEntity = _dataRepository.LabelRepository.GetLabelByID(label.ID).FirstOrDefault();
                if (labelEntity == null)
                {
                    throw new ApplicationException("Label does not exist");
                }

                /*
                 * Then we just have to remove the label
                 */
                _dataRepository.LabelRepository.DeleteLabel(labelEntity);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Deleting Label", caught);
                throw;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Refresh Macros For A Particular Label
        /// </summary>
        /// <param name="label">The Label</param>
        public void RefreshMacros(DataContract.Metadata.Label label)
        {
            try
            {
                if (label == null)
                {
                    throw new ArgumentNullException("label");
                }

                ListView.SuspendLayout();
                var macrosByLabel = _macroManagementService.GetMacrosByLabel(label);
                ListView.Items.Clear();

                foreach (var macro in macrosByLabel)
                {
                    var macroListItem = new MacroListViewItems.MacroListViewItem(macro);
                    ListView.Items.Add(macroListItem);
                }

                ListView.ResumeLayout();
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Refreshing Macros For Label", caught);
                throw;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Update Label
        /// </summary>
        /// <param name="label">The Label</param>
        public void UpdateLabel(DataContract.Metadata.Label label)
        {
            try
            {
                if (label == null)
                {
                    throw new ArgumentNullException("label");
                }

                /*
                 * First need to lookup the label entity from the database, using the label ID
                 */
                var labelEntity = _dataRepository.LabelRepository.GetLabelByID(label.ID).FirstOrDefault();
                if (labelEntity == null)
                {
                    throw new ApplicationException("Label does not exist");
                }

                /*
                 * Then we update the entity accordingly and persist the changes
                 */
                labelEntity.ParentID = label.ParentID;
                labelEntity.Name     = label.Name;
                _dataRepository.LabelRepository.UpdateLabel(labelEntity);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Updating Label", caught);
                throw;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Initialize Label TreeNode
 /// </summary>
 /// <param name="label">The Label</param>
 public LabelTreeNode(DataContract.Metadata.Label label) : this()
 {
     try
     {
         BoundLabel = label ?? throw new ArgumentNullException("label");
         Text       = BoundLabel.Name;
         Name       = Convert.ToString(BoundLabel.ID);
     }
     catch (Exception caught)
     {
         logger.Error("Unexpected Error Initializing Label TreeNode", caught);
         throw;
     }
 }
Beispiel #5
0
 /// <summary>
 /// Initialize Edit Label Button
 /// </summary>
 /// <param name="label">The Label to Edit</param>
 public EditLabelForm(Model.Metadata.Label label)
 {
     try
     {
         InitializeComponent();
         BoundLabel = label;
         //TODO: Deal with the Parent Label Display and selection
         LabelNameTextBox.DataBindings.Add("Text", BoundLabel, "Name");
     }
     catch (Exception caught)
     {
         logger.Error("Unexpected Error Initializing Edit Label Form", caught);
         throw;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Create Label
        /// </summary>
        /// <param name="label">The Label</param>
        /// <remarks>
        /// This should return the label as it's created.
        /// This would greatly simplify the service's usage, and make
        /// the UI much snappier.
        /// </remarks>
        public DataContract.Metadata.Label CreateLabel(DataContract.Metadata.Label label)
        {
            try
            {
                if (label == null)
                {
                    throw new ArgumentNullException("label");
                }

                var newLabel = BuildLabelDataContract(_dataRepository.LabelRepository.CreateLabel(label.ParentID, label.Name));
                return(newLabel);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Creating Label", caught);
                throw;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Get Child Labels
        /// </summary>
        /// <param name="parentLabel">The Parent Label</param>
        /// <returns></returns>
        public IEnumerable <DataContract.Metadata.Label> GetChildLabels(DataContract.Metadata.Label parentLabel)
        {
            try
            {
                if (parentLabel == null)
                {
                    throw new ArgumentNullException("parentLabel");
                }

                var labels  = _dataRepository.LabelRepository.GetChildLabels(parentLabel.ID);
                var results = new List <DataContract.Metadata.Label>();
                labels.ToList().ForEach(l => results.Add(BuildLabelDataContract(l)));
                return(results);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Getting Child Labels", caught);
                throw;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Get Macros by Label
        /// </summary>
        /// <param name="label">The Label</param>
        /// <returns></returns>
        public IEnumerable <Models.Macro.Macro> GetMacrosByLabel(Models.Metadata.Label label)
        {
            try
            {
                if (label == null)
                {
                    throw new ArgumentNullException("label");
                }

                var macros  = _dataRepository.MacroRepository.GetMacrosByLabelID(label.ID);
                var results = new List <Models.Macro.Macro>();
                macros.ToList().ForEach(me => results.Add(BuildMacroDataContract(me)));
                return(results);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Getting Macros by Label", caught);
                throw;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Build Macro Data Contract
        /// </summary>
        /// <param name="macroEntity">The Macro Data Entity</param>
        /// <returns>The Macro Data Contract</returns>
        private Models.Macro.Macro BuildMacroDataContract(DataEntity.IMacro macroEntity)
        {
            try
            {
                if (macroEntity == null)
                {
                    throw new ArgumentNullException("macroEntity");
                }

                Models.Metadata.Label label = null;
                if (macroEntity.LabelID != null)
                {
                    var labelResults = _dataRepository.LabelRepository.GetLabelByID(macroEntity.LabelID.Value).FirstOrDefault();
                    if (labelResults != null)
                    {
                        label = new Models.Metadata.Label {
                            ID = labelResults.ID, ParentID = labelResults.ParentID, Name = labelResults.Name
                        };
                    }
                }

                var macro = new Models.Macro.Macro
                {
                    ID        = macroEntity.ID,
                    Label     = label,
                    Name      = macroEntity.Name,
                    ListOrder = macroEntity.ListOrder,
                    Enabled   = macroEntity.Enabled
                };

                return(macro);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Building Macro Data Contract", caught);
                throw;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Attach Child Label to TreeNode
        /// </summary>
        /// <param name="parentNode">The Parent TreeNode</param>
        /// <param name="label">The Child Label</param>
        private void AttachChildLabelToNode(TreeNode parentNode, DataContract.Metadata.Label label)
        {
            try
            {
                if (parentNode == null)
                {
                    throw new ArgumentNullException("parentNode");
                }
                if (label == null)
                {
                    throw new ArgumentNullException("label");
                }

                var newChildLabelNode = new NavigationTreeNodes.LabelTreeNode(label);
                parentNode.Nodes.Add(newChildLabelNode);
                TreeView.SelectedNode = newChildLabelNode;
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Attaching Child Label to TreeNode", caught);
                throw;
            }
        }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="labelEntity"></param>
        /// <returns></returns>
        private DataContract.Metadata.Label BuildLabelDataContract(DataEntity.ILabel labelEntity)
        {
            try
            {
                if (labelEntity == null)
                {
                    throw new ArgumentNullException("labelEntity");
                }

                var label = new DataContract.Metadata.Label
                {
                    ID       = labelEntity.ID,
                    ParentID = labelEntity.ParentID,
                    Name     = labelEntity.Name
                };
                return(label);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Building Label Data Contract", caught);
                throw;
            }
        }
Beispiel #12
0
        /// <summary>
        /// Build Macro Action Assembly
        /// </summary>
        /// <param name="provider">The Provider</param>
        /// <param name="label">The Label to Associate new Macro With</param>
        /// <param name="source">The External Macro Source</param>
        /// <returns>The Macro</returns>
        public Model.Macro.Macro BuildMacroFromSource(Model.Metadata.ExternalProvider provider, Model.Metadata.Label label, string source)
        {
            try
            {
                if (provider == null)
                {
                    throw new ArgumentNullException("provider");
                }
                if (string.IsNullOrWhiteSpace(source))
                {
                    throw new ArgumentNullException("source");
                }
                // The label should be able to be null, no problem.  This would cause new macro to not be categorized with anything, it would show up under all macros

                var externalProvider = _installedProviders[provider.Code];

                //Create Macro Header
                var macro = new Model.Macro.Macro();
                macro.Label     = label;
                macro.ListOrder = 0;
                macro.Name      = "New Macro";

                //Create External source, and associate source and macro
                var externalSource = new Model.Macro.MacroExternalSource();
                macro.ExternalSources.Add(externalSource);
                externalSource.Macro = macro;

                externalSource.CreateDate    = DateTime.UtcNow;
                externalSource.Provider      = provider;
                externalSource.QualifiedName = externalProvider.GenerateQualifiedName();
                externalSource.MacroSource   = source;

                var assembler = externalProvider.Assembler;
                try
                {
                    var assembly        = assembler.Build(source);
                    var orderedAssembly = assembly.OrderBy(ma => ma.ActionDelay);
                    orderedAssembly.ToList().ForEach(ma => macro.Assembly.Add(ma));
                    externalSource.DesignerSupported = true;
                }
                catch (Exception assemblerCaught)
                {
                    logger.Warn("Macro Source Is Not Understood", assemblerCaught);
                    externalSource.DesignerSupported = false;
                }
                return(macro);
            }
            catch (Exception caught)
            {
                logger.Error("unexpected Error Building Macro From Source", caught);
                throw;
            }
        }