示例#1
0
        /// <summary>
        /// Deleting Macro
        /// </summary>
        /// <param name="macro">The Macro Data Contract</param>
        public void DeleteMacro(Models.Macro.Macro macro)
        {
            try
            {
                if (macro == null)
                {
                    throw new ArgumentNullException("macro");
                }

                //TODO: Implement this after refactor

                throw new NotImplementedException();

                ///*
                // * First need to lookup the macro entity from the database, using the qualified name
                // */
                //var macroEntity = _dataRepository.MacroRepository.GetMacroByQualifiedName(macro.QualifiedName).FirstOrDefault();
                //if (macroEntity == null)
                //{
                //    throw new ApplicationException("Macro does not exist");
                //}

                ///*
                // * Then just remove the Macro
                // */
                //_dataRepository.MacroRepository.DeleteMacro(macroEntity);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Deleting Macro", caught);
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Create Imported Macro ListViewItem
        /// </summary>
        /// <param name="importedMacro">The Imported Macro</param>
        /// <returns>The Imported Macro ListViewItem</returns>
        private ListViewItem CreateImportedMacroListViewItem(Model.Macro.Macro importedMacro)
        {
            try
            {
                if (importedMacro == null)
                {
                    throw new ArgumentNullException("importedMacro");
                }

                var macroExternalSource = importedMacro.ExternalSources.FirstOrDefault();
                if (macroExternalSource == null)
                {
                    logger.Warn("Imported Macro Has no Source.  This shouldn't have happened, but since it did, ignoring it");
                    return(null);
                }
                var lvi = new ListViewItem(new[] {
                    importedMacro.Name,
                    macroExternalSource.Provider.Name,
                    macroExternalSource.QualifiedName,
                    macroExternalSource.CreateDate.ToShortDateString()
                });
                lvi.Tag        = importedMacro;
                lvi.ImageIndex = 0;
                return(lvi);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Creating Imported Macro ListViewItem", caught);
                throw;
            }
        }
示例#3
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;
            }
        }
示例#4
0
 /// <summary>
 /// Initialize Macro ListViewItem
 /// </summary>
 /// <param name="macro">The Macro</param>
 public MacroListViewItem(DataContract.Macro.Macro macro) : this()
 {
     try
     {
         BoundMacro = macro;
         RefreshMacroInformation();
     }
     catch (Exception caught)
     {
         logger.Error("Unexpected Error Initializingt Macro ListViewItem", caught);
         throw;
     }
 }
示例#5
0
        /// <summary>
        /// Create Macro
        /// </summary>
        /// <param name="macro">The Macro Data Contract</param>
        /// <remarks>The Created Macro</remarks>
        public Models.Macro.Macro CreateMacro(Models.Macro.Macro macro)
        {
            try
            {
                if (macro == null)
                {
                    throw new ArgumentNullException("macro");
                }

                //TODO: Implement Create Macro with new model

                var newMacro = _dataRepository.MacroRepository.CreateMacro(
                    macro.Label == null ? null as long? : macro.Label.ID,
                    macro.Name,
                    macro.ListOrder,
                    DateTime.UtcNow,
                    macro.Enabled
                    );

                foreach (var macroAction in macro.Assembly)
                {
                    _dataRepository.MacroRepository.CreateMacroAssemblyAction(newMacro,
                                                                              macroAction.ActionType == Models.Macro.ActionType.Screen ? 0 : 1,
                                                                              macroAction.ScreenResolution.Y,
                                                                              macroAction.ScreenResolution.X,
                                                                              macroAction.ScreenPosition.X,
                                                                              macroAction.ScreenPosition.Y,
                                                                              macroAction.ActionDelay
                                                                              );
                }



                return(BuildMacroDataContract(newMacro));
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Creating Macro", caught);
                throw;
            }
        }
示例#6
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;
            }
        }
示例#7
0
        /// <summary>
        /// Update Macro
        /// </summary>
        /// <param name="macro">The Macro Data Contract</param>
        public void UpdateMacro(Models.Macro.Macro macro)
        {
            try
            {
                if (macro == null)
                {
                    throw new ArgumentNullException("macro");
                }

                //TODO: Implement this since re-structure
                throw new NotImplementedException();

                ///*
                // * First need to lookup the macro entity from the database, using the qualified name
                // */
                //var macroEntity = _dataRepository.MacroRepository.GetMacroByQualifiedName(macro.QualifiedName).FirstOrDefault();
                //if (macroEntity == null)
                //{
                //    throw new ApplicationException("Macro does not exist");
                //}
                ///*
                // * Then we update the entity accordingly and persist the changes in the repository
                // */
                //macroEntity.LabelID = macro.LabelID;
                //macroEntity.Name = macro.Name;
                //macroEntity.ListOrder = macro.ListOrder;
                //macroEntity.ExternalProvider = macro.ExternalProvider;
                //macroEntity.Enabled = macro.Enabled;
                //_dataRepository.MacroRepository.UpdateMacro(macroEntity);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Updating Macro", caught);
                throw;
            }
        }
示例#8
0
        /// <summary>
        /// Build Macro from External Macro Model
        /// </summary>
        /// <param name="provider">The Provider</param>
        /// <param name="externalMacroModel">The External Macro Model</param>
        /// <returns>The Macro</returns>
        private Model.Macro.Macro BuildMacroFromExternalMacroModel(IProvider provider, External.Models.IExternalMacroModel externalMacroModel)
        {
            try
            {
                if (provider == null)
                {
                    throw new ArgumentNullException("provider");
                }
                if (externalMacroModel == null)
                {
                    throw new ArgumentNullException("externalMacroModel");
                }
                var externalProvider      = _installedProviders[provider.ProviderCode];
                var externalProviderModel = BuildExternalProviderModel(externalProvider);
                var existingMacro         = _macroManagementService.GetMacroByQualifiedName(externalProviderModel, externalMacroModel.QualifiedName).FirstOrDefault();

                //If the existing macro is null, we must build it fresh
                if (existingMacro == null)
                {
                    existingMacro = new Model.Macro.Macro();
                }
                existingMacro.Name      = externalMacroModel.FriendlyName;
                existingMacro.ListOrder = externalMacroModel.ListOrder;

                /*
                 * Now that we have an existing macro, either newly created or updated
                 * we should attempt to pull the external source.
                 * This will typically be an update for an existing macro, or a new external source if
                 * this is a newly created macro
                 */
                var externalSource = (from es in existingMacro.ExternalSources
                                      where es.Provider.Code == provider.ProviderCode
                                      select es).FirstOrDefault();
                if (externalSource == null)
                {
                    externalSource = new Model.Macro.MacroExternalSource();
                    existingMacro.ExternalSources.Add(externalSource);
                    externalSource.Macro    = existingMacro;
                    externalSource.Provider = BuildExternalProviderModel(externalProvider);
                }
                externalSource.QualifiedName = externalMacroModel.QualifiedName;
                externalSource.CreateDate    = externalMacroModel.CreateDate;
                externalSource.Accelerator   = externalMacroModel.Accelerator;
                externalSource.Interval      = externalMacroModel.Interval;
                externalSource.Mode          = externalMacroModel.Mode;
                externalSource.PlaySeconds   = externalMacroModel.PlaySeconds;
                externalSource.RepeatTimes   = externalMacroModel.RepeatTimes;

                externalSource.MacroSource = externalMacroModel.MacroSource;

                /*
                 * Regenerate the macro assembly
                 */

                existingMacro.Assembly.Clear();
                var assembler = externalProvider.Assembler;
                try
                {
                    var assembly        = assembler.Build(externalSource.MacroSource);
                    var orderedAssembly = assembly.OrderBy(ma => ma.ActionDelay);
                    orderedAssembly.ToList().ForEach(ma => existingMacro.Assembly.Add(ma));
                    externalSource.DesignerSupported = true;
                }
                catch (Exception assemblerCaught)
                {
                    logger.Warn("Macro Source Is Not Understood", assemblerCaught);
                    externalSource.DesignerSupported = false;
                }

                //TODO: Consider if we will have to ever support or update other external providers

                return(existingMacro);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Building Macro from External Macro Model", caught);
                throw;
            }
        }
示例#9
0
        /// <summary>
        /// Get Macro Action Assembly Source
        /// </summary>
        /// <param name="providerCode">The Provider</param>
        /// <param name="macro">The Macro</param>
        /// <returns>The Updated Macro</returns>
        public Model.Macro.Macro RegenerateMacroSource(Model.Metadata.ExternalProvider provider, Model.Macro.Macro macro)
        {
            try
            {
                if (provider == null)
                {
                    throw new ArgumentNullException("provider");
                }
                if (macro == null)
                {
                    throw new ArgumentNullException("macro");
                }
                var externalProvider = _installedProviders[provider.Code];

                var externalSource = (from es in macro.ExternalSources
                                      where es.Provider.Code == provider.Code
                                      select es).FirstOrDefault();
                if (externalSource == null)
                {
                    externalSource = new Model.Macro.MacroExternalSource();
                    macro.ExternalSources.Add(externalSource);
                    externalSource.Macro = macro;

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

                var assembler           = externalProvider.Assembler;
                var dissassembledSource = assembler.Disassemble(macro.Assembly);
                externalSource.MacroSource = dissassembledSource;

                return(macro);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Regenerating Macro Source", caught);
                throw;
            }
        }
示例#10
0
        /// <summary>
        /// Rebuild Macro from Source
        /// </summary>
        /// <param name="provider">The Provider</param>
        /// <param name="macro">The Macro to Rebuild</param>
        /// <param name="source">The New Macro Source</param>
        /// <returns>The Rebuilt Macro</returns>
        public Model.Macro.Macro ReBuildMacroFromSource(Model.Metadata.ExternalProvider provider, Model.Macro.Macro macro, string source)
        {
            try
            {
                if (provider == null)
                {
                    throw new ArgumentNullException("provider");
                }
                if (macro == null)
                {
                    throw new ArgumentNullException("macro");
                }
                if (string.IsNullOrWhiteSpace(source))
                {
                    throw new ArgumentNullException("source");
                }

                var externalProvider = _installedProviders[provider.Code];

                /*
                 * We look to see if the macro already has an external source for this provider
                 * if it does we can update that, and if it doesn't we can simply create a new one for
                 * the provider.
                 */
                var externalSource = (from es in macro.ExternalSources
                                      where es.Provider.Code == provider.Code
                                      select es).FirstOrDefault();
                if (externalSource == null)
                {
                    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;

                macro.Assembly.Clear();

                //TODO: There may be a need to re-generate the source from the assembly for each other provider registered with this macro
                //This is low priority because at the moment only Nox is offially supported
                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 Rebuilding Macro from Source", caught);
                throw;
            }
        }
示例#11
0
        /// <summary>
        /// Initialize Macro Editor Form
        /// </summary>
        /// <param name="externalIntegrationService">The External Integration Service</param>
        /// <param name="sourceMacro">The Source Macro</param>
        public MacroEditorForm(IExternalIntegrationService externalIntegrationService, Model.Macro.Macro sourceMacro)
        {
            try
            {
                InitializeComponent();
                SourceMacro = sourceMacro ?? throw new ArgumentNullException("macro");
                _externalIntegrationService = externalIntegrationService ?? throw new ArgumentNullException("externalIntegrationService");


                //TODO: Adjust this, this is a band-aid

                /*
                 * Moving to a model where multiple external providers are go be supported, and
                 * at the current state, this form is no longer adequate.  So for the moment, this
                 * component is being forced in as the first provider to allow macro code generation
                 * when switching between designer and source.
                 *
                 * Once the external push integration is finally re-inabled, this will be less important, a
                 * and the form will only be concerned with modifying the intent model.
                 *
                 * Though there will likely be a live update feature, and at that point the intended target will
                 * be selected by a drop down or another similar widget.
                 */
                ExternalProvider = _externalIntegrationService.GetInstalledProviders().FirstOrDefault();
                if (ExternalProvider == null)
                {
                    throw new ApplicationException("External Provider Not Installed");
                }
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Initializing Macro Editor Form", caught);
                throw;
            }
        }