Ejemplo n.º 1
0
        /// <summary>
        /// Import Macros
        /// </summary>
        /// <param name="provider">The Provider</param>
        /// <returns>The Imported Macros</returns>
        public IEnumerable <Model.Macro.Macro> ImportMacros(Model.Metadata.ExternalProvider provider)
        {
            try
            {
                if (provider == null)
                {
                    throw new ArgumentNullException("provider");
                }

                var externalProvider    = _installedProviders[provider.Code];
                var importer            = externalProvider.Importer;
                var externalMacroModels = importer.ImportMacros();

                var importedMacros = new List <Model.Macro.Macro>();
                foreach (var externalMacroModel in externalMacroModels)
                {
                    var importedMacroModel = BuildMacroFromExternalMacroModel(externalProvider, externalMacroModel);
                    importedMacros.Add(importedMacroModel);
                }
                return(importedMacros);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Importing Macros", caught);
                throw;
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Build External Provider Model
 /// </summary>
 /// <param name="provider">The Provider</param>
 /// <returns>The External Provider Model</returns>
 private Model.Metadata.ExternalProvider BuildExternalProviderModel(IProvider provider)
 {
     try
     {
         var externalProviderModel = new Model.Metadata.ExternalProvider();
         externalProviderModel.Code = provider.ProviderCode;
         externalProviderModel.Name = provider.ProviderName;
         return(externalProviderModel);
     }
     catch (Exception caught)
     {
         logger.Error("Unexpected Error Building External Provider Model", caught);
         throw;
     }
 }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Get Macro by Qualified Name
 /// </summary>
 /// <param name="provider">The Provider</param>
 /// <param name="qualifiedName">The Qualified Macro Name</param>
 /// <returns>The Macro</returns>
 public IEnumerable <Models.Macro.Macro> GetMacroByQualifiedName(Models.Metadata.ExternalProvider provider, string qualifiedName)
 {
     try
     {
         if (provider == null)
         {
             throw new ArgumentNullException("provider");
         }
         if (string.IsNullOrWhiteSpace(qualifiedName))
         {
             throw new ArgumentNullException("qualifiedName");
         }
         var macros  = _dataRepository.MacroRepository.GetMacroByQualifiedName(provider.Code, qualifiedName);
         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 Macro by Qualified Name", caught);
         throw;
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Export Macros (overwrite)
 /// </summary>
 /// <param name="provider">The Provider</param>
 public void ExportMacros(Model.Metadata.ExternalProvider provider)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
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;
            }
        }