コード例 #1
0
        private static async Task Main()
        {
            Console.WriteLine("Main start");

            await PluginGenerator.Save();

            await GameGenerator.Save();

            Console.WriteLine("Main done");
        }
コード例 #2
0
        public void Execute(IServiceProvider serviceProvider)
        {
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            FaultException ex1 = new FaultException();
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
                                              serviceProvider.GetService(typeof(IPluginExecutionContext));

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parameters.
                Entity entity = (Entity)context.InputParameters["Target"];
                if (entity.Attributes.Contains("egcs_name"))
                {
                    try
                    {
                        //// Obtain the organization service reference.
                        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                        IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                        //before creating any of these, check if they already exist. If yes, do nothing or throw an error to user like already is configured.
                        var entityName = entity.GetAttributeValue <string>("egcs_name");

                        var newPluginCreate           = new PluginGenerator(service, entityName, "CrmGC.Plugins.MultiLingualPluginCreate", (int)CrmPluginStepStage.PostOperation, "create step for multilingual plugin for entity: " + entityName, SdkMessageName.Create.ToString(), "creating", "update name field on create").generatePlugin();
                        var newPluginUpdate           = new PluginGenerator(service, entityName, "CrmGC.Plugins.MultiLingualPluginUpdate", (int)CrmPluginStepStage.PostOperation, "update step for multilingual plugin for entity: " + entityName, SdkMessageName.Update.ToString(), "updating", "update name field on update").generatePlugin();
                        var newPluginRetrieve         = new PluginGenerator(service, entityName, "CrmGC.Plugins.MultiLingualPluginRetrieve", (int)CrmPluginStepStage.PostOperation, "retrieve step for multilingual plugin for entity: " + entityName, SdkMessageName.Retrieve.ToString(), "Retrieving", "Retrieve based on localization").generatePlugin();
                        var newPluginRetrieveMultiple = new PluginGenerator(service, entityName, "CrmGC.Plugins.MultiLingualPluginRetrieveMultiple", (int)CrmPluginStepStage.PostOperation, "retrieve multiple step for multilingual plugin for entity: " + entityName, SdkMessageName.RetrieveMultiple.ToString(), "Retrieving All", "Retrieve based on localization").generatePlugin();

                        //update the plugin guids add to pluginid field. Use this plugin id when deleting to remove the step
                    }
                    catch (FaultException <OrganizationServiceFault> ex)
                    {
                        throw new InvalidPluginExecutionException("An error occurred in the FollowupPlugin plug-in.", ex);
                    }

                    catch (Exception ex)
                    {
                        tracingService.Trace("FollowupPlugin: {0}", ex.ToString());
                        throw;
                    }
                }
            }
        }
コード例 #3
0
        public bool generatePluginSteps()
        {
            FaultException ex1  = new FaultException();
            Guid           plug = new PluginGenerator(_service, "PreventDuplicateExtension.Plugins", _entityName, "PreventDuplicateExtension.Plugins.PreventDuplicatePlugin", (int)CrmPluginStepStage.PostOperation,
                                                      "create step for prevent duplicate plugin for entity: " + _entityName, SdkMessageName.Create.ToString(),
                                                      "Create plugin prevent duplicate", "validate no duplicate").generatePluginStep();

            //throw new InvalidPluginExecutionException(plug.ToString(), ex1);
            if (plug != null)
            {
                Guid plugUpdate = new PluginGenerator(_service, "PreventDuplicateExtension.Plugins", _entityName, "PreventDuplicateExtension.Plugins.PreventDuplicatePlugin", (int)CrmPluginStepStage.PostOperation,
                                                      "update step for prevent duplicate plugin for entity: " + _entityName, SdkMessageName.Update.ToString(),
                                                      "Update plugin prevent duplicate", "validate no duplicate").generatePluginStep();
                //throw new InvalidPluginExecutionException(plug.ToString(), ex1);
                if (plugUpdate != null)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
        public bool generatePluginSteps()
        {
            FaultException ex1 = new FaultException();
            //CHECK IF ENTITY FP NAME, AND ITS FIELD NAMES ARE VALID!!!
            Guid plug = new PluginGenerator(_service, "NamePopulatorExtension.Plugins", _entityName, "NamePopulatorExtension.Plugins.PopulatorPlugin", (int)CrmPluginStepStage.PostOperation,
                                            "create step for name populator plugin for entity: " + _entityName, SdkMessageName.Create.ToString(),
                                            "Create plugin populator", "update name field on create").generatePluginStep();

            //throw new InvalidPluginExecutionException(plug.ToString(), ex1);
            if (plug != null)
            {
                Guid plugUpdate = new PluginGenerator(_service, "NamePopulatorExtension.Plugins", _entityName, "NamePopulatorExtension.Plugins.PopulatorPlugin", (int)CrmPluginStepStage.PostOperation,
                                                      "update step for name populator plugin for entity: " + _entityName, SdkMessageName.Update.ToString(),
                                                      "Update plugin populator", "update name field on update").generatePluginStep();
                //throw new InvalidPluginExecutionException(plug.ToString(), ex1);
                if (plugUpdate != null)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
 public bool destroyPluginSteps()
 {
     try
     {
         var plugReg    = new PluginGenerator();
         var createStep = "create step for prevent duplicate plugin for entity: " + _entityName;
         var updateStep = "update step for prevent duplicate plugin for entity: " + _entityName;
         if (!plugReg.destroyStep(_service, _entityName, createStep))
         {
             return(false);
         }
         ;
         if (!plugReg.destroyStep(_service, _entityName, updateStep))
         {
             return(false);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #6
0
        private void onGenerate(object sender, EventArgs e)
        {
            try
            {
                // check text boxes content
                if (!ValidateControlContent())
                {
                    return; // invalid content
                }
                // save some control content
                Registry.SetValue(@"HKEY_CURRENT_USER\Software\TreeDim\PicSharp", "PluginCompany", txtCompany.Text);

                // instantiate plugin generator and compile
                PluginGenerator generator = new PluginGenerator();
                generator.AssemblyTitle       = txtName.Text;
                generator.AssemblyDescription = txtDescription.Text;
                generator.AssemblyVersion     = PluginVersion;
                generator.AssemblyCompany     = txtCompany.Text;
                generator.DrawingName         = txtName.Text;
                generator.DrawingDescription  = txtDescription.Text;
                generator.Guid        = new Guid(txtGuid.Text);
                generator.DrawingCode = codeEditorCtrl.Text;
                if (chbThumbnail.Checked)
                {
                    generator.ThumbnailPath = fileSelectCtrl.FileName;
                }
                generator.OutputDirectory = Path.GetTempPath();
                CompilerResults res = generator.Build();
                // show any errors in list view control
                lvwErrors.Items.Clear();
                foreach (CompilerError err in res.Errors)
                {
                    ListViewItem lvi = new ListViewItem(err.ErrorText);
                    lvi.SubItems.Add((err.Line - generator.LineOffset).ToString());
                    lvwErrors.Items.Add(lvi);
                }
                // send event if no errors were found
                if (res.Errors.Count == 0)
                {
                    using (PluginViewer frmPluginViewer = new PluginViewer(_componentSearchMethod, res.PathToAssembly))
                    {
                        if (frmPluginViewer.ShowDialog() == DialogResult.OK)
                        {
                            try
                            {
                                File.Copy(
                                    res.PathToAssembly
                                    , OutputPath
                                    , true /*overwrite*/
                                    );
                            }
                            catch (System.IO.IOException /*ex*/)
                            {
                                MessageBox.Show(string.Format("File {0} appears to be locked. Please, provide a different path for copy", OutputPath), Application.ProductName, MessageBoxButtons.OK);
                                OpenFileDialog fd = new OpenFileDialog();
                                fd.FileName    = OutputPath;
                                fd.Filter      = "Component (*.dll)|*.dll|All Files|*.*";
                                fd.FilterIndex = 0;

                                if (DialogResult.OK == fd.ShowDialog())
                                {
                                    File.Copy(
                                        res.PathToAssembly
                                        , fd.FileName
                                        , true /*overwrite*/
                                        );
                                }
                                else
                                {
                                    return;
                                }
                            }
                            // emit event if an event handler was defined
                            if (null != PluginValidated)
                            {
                                PluginValidated(this, new GeneratorCtrlEventArgs(OutputPath));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: treeDiM/PackLib4ES
        static void Main(string[] args)
        {
            string folderDlls    = ConfigurationManager.AppSettings.Get("FolderComponentFiles");
            string folderSources = ConfigurationManager.AppSettings.Get("FolderComponentSources");

            IComponentSearchMethod sm = new ComponentSearchDirectory(folderDlls);

            foreach (string filePath in Directory.GetFiles(folderSources, "*.cs", SearchOption.AllDirectories))
            {
                ReplaceString(filePath, "\"Perfo\"", "\"1-2-x-1-2-cut\"");

                string sAuthor      = string.Empty;
                string sName        = string.Empty;
                string sDescription = string.Empty;
                string sVersion     = string.Empty;
                string sGuid        = string.Empty;
                bool   hasThumbnail = false;
                string sDate        = string.Empty;

                var    fileLines = File.ReadAllLines(filePath);
                int    lineIndex = 0;
                string str       = fileLines[lineIndex++];
                if (str.Contains("GUID"))
                {
                    sGuid = str.Substring(str.IndexOf(':') + 2).Trim();
                }
                str = fileLines[lineIndex++];
                if (str.Contains("Name"))
                {
                    sName = str.Substring(str.IndexOf(':') + 2).Trim();
                }
                str = fileLines[lineIndex++];
                if (str.Contains("Description"))
                {
                    sDescription = str.Substring(str.IndexOf(':') + 2).Trim();
                }
                str = fileLines[lineIndex++];
                if (str.Contains("Author"))
                {
                    sAuthor = str.Substring(str.IndexOf(':') + 2).Trim();
                }
                str = fileLines[lineIndex++];
                if (str.Contains("Version"))
                {
                    sVersion = str.Substring(str.IndexOf(':') + 2).Trim();
                }
                str = fileLines[lineIndex++];
                if (str.Contains("Thumbnail"))
                {
                    hasThumbnail = str.Substring(str.IndexOf(':') + 2).Trim() == "true";
                }
                str = fileLines[lineIndex++];
                if (str.Contains("Date"))
                {
                    sDate = str.Substring(str.IndexOf(':') + 2).Trim();
                }

                lineIndex += 1;

                StringBuilder sb = new StringBuilder();
                for (int i = lineIndex; i < fileLines.Count(); ++i)
                {
                    sb.AppendLine(fileLines[i]);
                }

                try
                {
                    string outName = Path.GetFileName(Path.ChangeExtension(filePath, "dll"));
                    {
                        Console.Write($"Compiling {outName}");

                        // instantiate PluginGenerator
                        PluginGenerator generator = new PluginGenerator
                        {
                            AssemblyCompany     = sAuthor,
                            AssemblyDescription = sDescription,
                            AssemblyVersion     = sVersion,
                            DrawingName         = sName,
                            DrawingDescription  = sDescription,
                            Guid            = Guid.Parse(sGuid),
                            DrawingCode     = sb.ToString(),
                            OutputName      = outName,
                            OutputDirectory = folderDlls
                        };
                        string filePathBmp = Path.ChangeExtension(filePath, "bmp");
                        if (File.Exists(filePathBmp))
                        {
                            // set thumbnail path in generator
                            generator.ThumbnailPath = filePathBmp;
                        }
                        CompilerResults res = generator.Build();
                        if (res.Errors.Count > 0)
                        {
                            Console.WriteLine($" -> Failed");
                            for (int i = 0; i < res.Errors.Count; ++i)
                            {
                                Console.WriteLine($"{res.Errors[i].Line} : {res.Errors[i].ErrorText}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($" -> Done");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
コード例 #8
0
        public void GenerateAdapters()
        {
            // Step 4: The graph is valid, emit generated adapters.
            var generatedTypes = new HashSet <TypeDefinition>(new TypeReferenceComparer());
            var generators     = new Queue <Generator>();

            foreach (var g in moduleGenerators)
            {
                generators.Enqueue(g);
            }

            foreach (var g in injectGenerators)
            {
                generators.Enqueue(g);
            }

            foreach (var g in lazyGenerators)
            {
                generators.Enqueue(g);
            }

            foreach (var g in providerGenerators)
            {
                generators.Enqueue(g);
            }

            while (generators.Count > 0)
            {
                var current = generators.Dequeue();
                var newType = current.Generate(errorReporter);

                // generators that are placeholders for non-injectable entry points (e.g. bool)
                // don't emit any types, so make sure we check that.
                if (newType == null)
                {
                    continue;
                }

                if (!generatedTypes.Add(newType))
                {
                    continue;
                }

                if (newType.DeclaringType != null)
                {
                    newType.DeclaringType.NestedTypes.Add(newType);
                }
                else
                {
                    moduleDefinition.Types.Add(newType);
                }
            }

            var pluginGenerator = new PluginGenerator(
                moduleDefinition,
                references,
                injectGenerators.Where(gen => gen.IsVisibleToPlugin).Select(gen => gen.GetKeyedCtor()).Where(ctor => ctor != null),
                lazyGenerators.Select(gen => gen.GetKeyedCtor()),
                providerGenerators.Select(gen => gen.GetKeyedCtor()),
                moduleGenerators.Where(gen => gen.IsVisibleToPlugin).Select(gen => gen.GetModuleTypeAndGeneratedCtor()));

            moduleDefinition.Types.Add(pluginGenerator.Generate(errorReporter));

            CompiledPluginConstructor = pluginGenerator.GeneratedCtor;

            moduleDefinition.CustomAttributes.Add(new CustomAttribute(references.ProcessedAssemblyAttribute_Ctor));
        }