public PassThroughContext ToPassthroughContext()
        {
            IOrganizationService organizationService = OrganizationServiceFactory.CreateOrganizationService(CallingUserId);
            var passThroughContext = new PassThroughContext(organizationService, TracingService);

            return(passThroughContext);
        }
예제 #2
0
        private void Initialize()
        {
            ThrowsException = ThrowsException.HasValue ? ThrowsException.Value : true;
            Stopwatch       = Stopwatch.StartNew();
            TracingService  = (ITracingService)ServiceProvider.GetService(typeof(ITracingService));
            if (TracingService == null)
            {
                throw new InvalidPluginExecutionException(TracingServiceMessage);
            }

            PluginExecutionContext = (IPluginExecutionContext)ServiceProvider.GetService(typeof(IPluginExecutionContext));
            if (PluginExecutionContext == null)
            {
                throw new InvalidPluginExecutionException(PluginExecutionContextMessage);
            }

            OrganizationServiceFactory = (IOrganizationServiceFactory)ServiceProvider.GetService(typeof(IOrganizationServiceFactory));
            if (OrganizationServiceFactory == null)
            {
                throw new InvalidPluginExecutionException(OrganizationServiceFactoryMessage);
            }

            OrganizationService = OrganizationServiceFactory.CreateOrganizationService(PluginExecutionContext.UserId);
            if (OrganizationService == null)
            {
                throw new InvalidPluginExecutionException(OrganizationServiceMessage);
            }

            ElevatedOrganizationService = OrganizationServiceFactory.CreateOrganizationService(null);
            if (ElevatedOrganizationService == null)
            {
                throw new InvalidPluginExecutionException(ImpersonatedOrganizationServiceMessage);
            }
        }
예제 #3
0
        public void CreateRequiredRecords()
        {
            var orgFactory = new OrganizationServiceFactory();
            var orgSrv     = orgFactory.GetNewOrganizationService();
            var context    = new XrmServiceContext(orgSrv);

            var accFac = new AccountFactory();

            context.AddObject(accFac.CurrentEntity);

            var conFac = new ContactFactory();

            context.AddRelatedObject(accFac.CurrentEntity, new Relationship("contact_customer_accounts"), conFac.CurrentEntity);

            context.SaveChanges();

            var incFac = new IncidentFactory();

            incFac.CurrentEntity.CustomerId = accFac.CurrentEntity.ToEntityReference();
            context.AddObject(incFac.CurrentEntity);
            context.Attach(accFac.CurrentEntity);

            var wpFac = new WorkPackageFactory();

            context.AddRelatedObject(accFac.CurrentEntity, new Relationship("a24_account_workpackage_customer_ref"), wpFac.CurrentEntity);
            wpFac.CurrentEntity.a24_customer_ref = accFac.CurrentEntity.ToEntityReference();

            context.SaveChanges();
        }
예제 #4
0
 internal protected PluginExecutionBundle(IServiceProvider serviceProvider)
 {
     ServiceProvider            = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     TracingService             = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
     PluginExecutionContext     = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
     OrganizationServiceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
     OrganizationService        = OrganizationServiceFactory.CreateOrganizationService(PluginExecutionContext.UserId);
 }
 internal protected WorkflowActivityExecutionBundle(CodeActivityContext codeActivityContext)
 {
     CodeActivityContext        = codeActivityContext ?? throw new ArgumentNullException(nameof(codeActivityContext));
     TracingService             = codeActivityContext.GetExtension <ITracingService>();
     WorkflowContext            = codeActivityContext.GetExtension <IWorkflowContext>();
     OrganizationServiceFactory = codeActivityContext.GetExtension <IOrganizationServiceFactory>();
     OrganizationService        = OrganizationServiceFactory.CreateOrganizationService(WorkflowContext.UserId);
 }
예제 #6
0
        /// <summary>
        /// Here it all begins
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var log = new ConsoleLogger(typeof(Program));

            CmdArgs parsedArgs;

            try
            {
                parsedArgs = Args.Parse <CmdArgs>(args);
            }
            catch (ArgException e)
            {
                Console.WriteLine(ArgUsage.GenerateUsageFromTemplate <CmdArgs>( ));
                log.Error($"Failed to parse arguments: {e.Message}");
                return;
            }

            try
            {
                IOrganizationService sourceService = null;
                var destinationSystem = parsedArgs.DestinationSystem;
                IOrganizationService destinationService = OrganizationServiceFactory.ConnectByConnectionString(destinationSystem);
                if (parsedArgs.SourceSystem != null)
                {
                    sourceService = OrganizationServiceFactory.ConnectByConnectionString(parsedArgs.SourceSystem + "RequireNewInstance = True;");
                }

                var deployer = new PluginDeployer(sourceService, destinationService, parsedArgs.Prefix, log);

                if (!deployer.LoadAssembly(parsedArgs.AssemblyPath))
                {
                    return;
                }

                var assemblyName        = deployer.AssemblyPlugin.GetName( ).Name;
                var destinationAssembly = deployer.RetrievePluginAssembly(destinationService, assemblyName);

                var createFromScratch = parsedArgs.Create;

                if (createFromScratch)
                {
                    deployer.CreateFromScratch(parsedArgs, destinationAssembly);
                }
                else
                {
                    deployer.UpdateSystem(parsedArgs, destinationAssembly);
                }
            }
            catch (Exception ex)
            {
                log.Error($"Exception occured, terminating. Exception: {GetAllExceptionMessages( ex )}\n\n");
                log.Error($"Stacktrace: {ex.StackTrace}");
            }
        }
        public WebResourceDeployer(CmdArgs args, ILog log, ILog err)
        {
            var packagesFilename = string.IsNullOrEmpty(args.PackagesXml) ? throw new Exception("Package.xml path was not given, please provide path.") : args.PackagesXml;

            Args = args;

            this.log = log;
            this.err = err;

            Service           = OrganizationServiceFactory.ConnectByConnectionString(args.ConnectionString);
            PackageCollection = FileLoader.LoadPackages(packagesFilename);
        }
예제 #8
0
        internal void InitializeSolutionFilterService()
        {
            var solutions = FilterConfiguration.Solutions
                            .Where(s => !string.IsNullOrEmpty(s.SolutionName))
                            .Select(s => s.SolutionName)
                            .ToArray();

            if (solutions?.Length > 0)
            {
                var service = new OrganizationServiceFactory().Create();
                solutionEntities = GetSolutionEntities(solutions, service);
            }
        }
예제 #9
0
        public PluginContext(IServiceProvider serviceProvider)
        {
            this.EnsureNotNull(serviceProvider);

            ServiceProvider = serviceProvider;

            ExecutionContext           = serviceProvider.GetService <IPluginExecutionContext>();
            OrganizationServiceFactory = serviceProvider.GetService <IOrganizationServiceFactory>();
            OrganizationService        = OrganizationServiceFactory.CreateOrganizationService(ExecutionContext.UserId);
            TracingService             = new Diagnostics.TracingServiceWrapper(serviceProvider.GetService <ITracingService>());

            OrganizationServiceContext = new Lazy <OrganizationServiceContext>(() =>
            {
                if (_disposed)
                {
                    throw new ObjectDisposedException(nameof(OrganizationServiceContext));
                }

                return(new OrganizationServiceContext(OrganizationService));
            });
        }
예제 #10
0
        private void Initialize()
        {
            ThrowsException = ThrowsException.HasValue ? ThrowsException.Value : true;

            Stopwatch = Stopwatch.StartNew();

            TracingService = CodeActivityContext.GetExtension <ITracingService>();
            if (TracingService == null)
            {
                throw new InvalidPluginExecutionException(TracingExtensionMessage);
            }

            WorkflowContext = CodeActivityContext.GetExtension <IWorkflowContext>();
            if (WorkflowContext == null)
            {
                throw new InvalidPluginExecutionException(WorkflowExtensionMessage);
            }

            OrganizationServiceFactory = CodeActivityContext.GetExtension <IOrganizationServiceFactory>();
            if (OrganizationServiceFactory == null)
            {
                throw new InvalidPluginExecutionException(OrganizationServiceFactoryExtensionMessage);
            }

            OrganizationService = OrganizationServiceFactory.CreateOrganizationService(WorkflowContext.UserId);
            if (OrganizationService == null)
            {
                throw new InvalidPluginExecutionException(OrganizationServiceMessage);
            }

            ElevatedOrganizationService = OrganizationServiceFactory.CreateOrganizationService(null);
            if (ElevatedOrganizationService == null)
            {
                throw new InvalidPluginExecutionException(ImpersonatedOrganizationServiceMessage);
            }
        }
예제 #11
0
 protected void SetupMockResponseForOrganizationServiceFactory()
 {
     OrganizationServiceFactory.Stub(x => x.CreateOrganizationService(WorkflowContext.UserId)).Return(OrganizationService);
     OrganizationServiceFactory.Stub(x => x.CreateOrganizationService(null)).Return(ImpersonatedOrganizationService);
 }