public static void PerformImportDefinition(SoapClient soapClient,
            string ImportDefinitionCustomerKey)
        {
            ImportDefinition id = new ImportDefinition();
            id.CustomerKey = ImportDefinitionCustomerKey;

            string sStatus = "";
            string sStatusMessage = "";
            string sRequestId = "";

            PerformResult[] pResults = soapClient.Perform(new PerformOptions(), "start", new APIObject[] { id }, out sStatus, out sStatusMessage, out sRequestId);

            Console.WriteLine("Status: " + sStatus);
            Console.WriteLine("Status Message: " + sStatusMessage);
            Console.WriteLine("Request ID: " + sRequestId);

            foreach (PerformResult pr in pResults)
            {
                // Task.ID Value is needed in order to check status of import using follow-up call
                Console.WriteLine("TaskID: " + pr.Task.ID);
                Console.WriteLine("StatusCode: " + pr.StatusCode);
                Console.WriteLine("ErrorCode: " + pr.ErrorCode);
                Console.WriteLine("StatusMessage: " + pr.StatusMessage);
            }
        }
 public ConcreteTypeExportHandlerContext()
 {
     ConcreteTypeHandler = new ConcreteTypeExportHandler();
     var typeCatalog = new TypeCatalog(typeof(OrderProcessor));
     var orderProcessorContract = AttributedModelServices.GetContractName(typeof(OrderProcessor));
     var orderProcessPartDefinition = typeCatalog.Parts.Single(p => p.ExportDefinitions.Any(d => d.ContractName == orderProcessorContract));
     RepositoryImportDefinition = orderProcessPartDefinition.ImportDefinitions.First();
     Context();
 }
        public static void CreateImportDefinition(SoapClient soapClient,
            string iImportDefinitionName,
            string iImportDefinitionCustomerKey,
            string iTargetDataExtensionCustomerKey,
            string iImportFileName)
        {
            ImportDefinition id = new ImportDefinition();
            id.Name = iImportDefinitionName;
            id.CustomerKey = iImportDefinitionCustomerKey;

            // Optional value, if AllowErrors is true then it will not stop the import when
            // a single row has an error
            id.AllowErrors = true;
            id.AllowErrorsSpecified = true;

            // For this example, we are sending to a data extension
            // Value for CustomerKey will be for a data extension already created in your account
            DataExtension de = new DataExtension();
            de.CustomerKey = iTargetDataExtensionCustomerKey;
            id.DestinationObject = de;

            AsyncResponse ar = new AsyncResponse();
            ar.ResponseType = AsyncResponseType.email;
            ar.ResponseAddress = "*****@*****.**";
            id.Notification = ar;

            FileTransferLocation ftl = new FileTransferLocation();
            ftl.CustomerKey = "ExactTarget Enhanced FTP";
            id.RetrieveFileTransferLocation = ftl;

            // Specify how the import will be handled
            // If data extension has no primary key specified then only "Overwrite" will work
            id.UpdateType = ImportDefinitionUpdateType.AddAndUpdate;
            id.UpdateTypeSpecified = true;

            id.FieldMappingType = ImportDefinitionFieldMappingType.InferFromColumnHeadings;
            id.FieldMappingTypeSpecified = true;

            id.FileSpec = iImportFileName;

            id.FileType = FileType.CSV;
            id.FileTypeSpecified = true;

            string sStatus = "";
            string sRequestId = "";

            CreateResult[] aoResults = soapClient.Create(new CreateOptions(), new APIObject[] { id }, out sRequestId, out sStatus);

            Console.WriteLine("Status: " + sStatus);
            Console.WriteLine("Request ID: " + sRequestId);
            foreach (CreateResult cr in aoResults)
            {
                Console.WriteLine("StatusCode: " + cr.StatusCode);
                Console.WriteLine("ErrorCode: " + cr.ErrorCode);
                Console.WriteLine("StatusMessage: " + cr.StatusMessage);
            }
        }
Exemple #4
0
 public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
 {
     return(InnerCatalog.GetExports(definition));
 }
Exemple #5
0
 public override void SetImport(ImportDefinition definition, IEnumerable <Export> exports)
 {
 }
 Export[] GetExportsSatisfying(ImportDefinition importDefinition)
 {
     return(GetExports(importDefinition.ContractType)
            .Where(importDefinition.IsSatisfiableBy)
            .ToArray());
 }
        public Response Importar(string key, string ruta)
        {
            var response = new Response { Success = true, Warning = false };
            try
            {
                //Create a GUID to ensure a unique subscriber key
                string strGUID = System.Guid.NewGuid().ToString();

                //Create an Import Definition object
                ImportDefinition id = new ImportDefinition();
                id.Name = strGUID;
                id.CustomerKey = strGUID;

                //Optional
                id.AllowErrors = true;
                id.AllowErrorsSpecified = true;

                //Associate Data-Extenison to Import-Defintion
                DataExtension de = new DataExtension();
                de.CustomerKey = key;//required //The External Key of the Data Extension to import into

                id.DestinationObject = de;

                //Specify the notification type //optional
                id.Notification = new AsyncResponse();
                id.Notification.ResponseType = AsyncResponseType.email;
                id.Notification.ResponseAddress = "*****@*****.**";

                //Specify the File Transfer Location
                id.RetrieveFileTransferLocation = new FileTransferLocation(); // FTP IMPORT-BF_PERU
                //id.RetrieveFileTransferLocation.CustomerKey = "07292ee0-b2d5-4447-b3e9-31a2cefb6aee";//required
                id.RetrieveFileTransferLocation.CustomerKey = "FTP IMPORT-BF_PERU";//required

                //Optional
                id.UpdateType = ImportDefinitionUpdateType.AddAndDoNotUpdate;
                id.UpdateTypeSpecified = true;

                //Map fields
                id.FieldMappingType = ImportDefinitionFieldMappingType.InferFromColumnHeadings;//required
                id.FieldMappingTypeSpecified = true;

                //Specify the File naming Specifications
                id.FileSpec = ruta;

                //Specify the FileType
                id.FileType = FileType.TAB;//required
                id.FileTypeSpecified = true;

                try
                {
                    string cRequestID = String.Empty;
                    string cStatus = String.Empty;

                    //Call the Create method on the ImportDefinition object
                    CreateResult[] cResults = conexion.ETCliente.Create(new CreateOptions(), new APIObject[] { id }, out cRequestID, out cStatus);

                    if (Constantes.Error == cStatus)
                    {
                        response.Success = false;
                        foreach (CreateResult cr in cResults)
                        {
                            response.Message += "DataExtensionKey: " + key + " | Status Message: " + cr.StatusMessage + "| ";
                        }
                    }
                }
                catch (Exception exCreate)
                {
                    response.Success = false;
                    response.Message = exCreate.Message;
                }

            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
        /// <summary>
        ///     Returns the export definitions that match the constraint defined by the specified definition.
        /// </summary>
        /// <param name="definition">
        ///     The <see cref="ImportDefinition"/> that defines the conditions of the
        ///     <see cref="ExportDefinition"/> objects to return.
        /// </param>
        /// <returns>
        ///     An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the
        ///     <see cref="ExportDefinition"/> objects and their associated
        ///     <see cref="ComposablePartDefinition"/> for objects that match the constraint defined
        ///     by <paramref name="definition"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="definition"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="AggregateCatalog"/> has been disposed of.
        /// </exception>
        public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            ThrowIfDisposed();

            Requires.NotNull(definition, nameof(definition));

            // We optimize for the case where the result is comparible with the requested cardinality, though we do remain correct in all cases.
            // We do so to avoid any unnecessary allocations
            IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> >?result          = null;
            List <Tuple <ComposablePartDefinition, ExportDefinition> >?       aggregateResult = null;

            foreach (var catalog in _catalogs)
            {
                var catalogExports = catalog.GetExports(definition);
                if (catalogExports != ComposablePartCatalog._EmptyExportsList)
                {
                    // ideally this is the case we will always hit
                    if (result == null)
                    {
                        result = catalogExports;
                    }
                    else
                    {
                        // sadly the result has already been assigned, which means we are in the aggregate case
                        if (aggregateResult == null)
                        {
                            aggregateResult = new List <Tuple <ComposablePartDefinition, ExportDefinition> >(result);
                            result          = aggregateResult;
                        }
                        aggregateResult.AddRange(catalogExports);
                    }
                }
            }
            return(result ?? ComposablePartCatalog._EmptyExportsList);
        }
Exemple #9
0
        /// <summary>
        ///     Returns the export definitions that match the constraint defined by the specified definition.
        /// </summary>
        /// <param name="definition">
        ///     The <see cref="ImportDefinition"/> that defines the conditions of the
        ///     <see cref="ExportDefinition"/> objects to return.
        /// </param>
        /// <returns>
        ///     An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the
        ///     <see cref="ExportDefinition"/> objects and their associated
        ///     <see cref="ComposablePartDefinition"/> for objects that match the constraint defined
        ///     by <paramref name="definition"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="definition"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="DirectoryCatalog"/> has been disposed of.
        /// </exception>
        public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            ThrowIfDisposed();

            Requires.NotNull(definition, nameof(definition));

            return(InnerCatalog.GetExports(definition));
        }
        /// <summary>
        /// Returns the export definitions that match the constraint defined by the specified definition.
        /// </summary>
        /// <param name="definition">The <see cref="ImportDefinition"/> that defines the conditions of the
        /// <see cref="ExportDefinition"/> objects to return.</param>
        /// <returns>
        /// An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the
        /// <see cref="ExportDefinition"/> objects and their associated
        /// <see cref="ComposablePartDefinition"/> for objects that match the constraint defined
        /// by <paramref name="definition"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="definition"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="ComposablePartCatalog"/> has been disposed of.
        /// </exception>
        /// <remarks>
        /// <note type="inheritinfo">
        /// Overriders of this property should never return <see langword="null"/>, if no
        /// <see cref="ExportDefinition"/> match the conditions defined by
        /// <paramref name="definition"/>, return an empty <see cref="IEnumerable{T}"/>.
        /// </note>
        /// </remarks>
        public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            ThrowIfDisposed();
            Requires.NotNull(definition, nameof(definition));

            var exports = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();

            foreach (var export in _innerCatalog.GetExports(definition))
            {
                if (_filter(export.Item1))
                {
                    exports.Add(export);
                }
            }

            return(exports);
        }
        internal override bool TryGetExports(ImportDefinition definition, out Tuple <ComposablePartDefinition, ExportDefinition> singleMatch, out IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > multipleMatches)
        {
            if (this.IsGeneric())
            {
                singleMatch     = null;
                multipleMatches = null;

                List <Tuple <ComposablePartDefinition, ExportDefinition> > exports = null;

                var genericParameters = (definition.Metadata.Count > 0) ? definition.Metadata.GetValue <IEnumerable <object> >(CompositionConstants.GenericParametersMetadataName) : null;
                // if and only if generic parameters have been supplied can we attempt to "close" the generic
                if (genericParameters != null)
                {
                    Type[] genericTypeParameters = null;
                    // we only understand types
                    if (TryGetGenericTypeParameters(genericParameters, out genericTypeParameters))
                    {
                        HashSet <ComposablePartDefinition> candidates    = null;
                        ComposablePartDefinition           candidatePart = null;
                        ComposablePartDefinition           previousPart  = null;

                        // go through all orders of generic parameters that part exports allows
                        foreach (Type[] candidateParameters in GetCandidateParameters(genericTypeParameters))
                        {
                            if (TryMakeGenericPartDefinition(candidateParameters, out candidatePart))
                            {
                                bool alreadyProcessed = false;
                                if (candidates == null)
                                {
                                    if (previousPart != null)
                                    {
                                        if (candidatePart.Equals(previousPart))
                                        {
                                            alreadyProcessed = true;
                                        }
                                        else
                                        {
                                            candidates = new HashSet <ComposablePartDefinition>();
                                            candidates.Add(previousPart);
                                            candidates.Add(candidatePart);
                                        }
                                    }
                                    else
                                    {
                                        previousPart = candidatePart;
                                    }
                                }
                                else
                                {
                                    if (candidates.Contains(candidatePart))
                                    {
                                        alreadyProcessed = true;
                                    }
                                    else
                                    {
                                        candidates.Add(candidatePart);
                                    }
                                }
                                if (!alreadyProcessed)
                                {
                                    Tuple <ComposablePartDefinition, ExportDefinition> candidateSingleMatch;
                                    IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > candidateMultipleMatches;
                                    if (candidatePart.TryGetExports(definition, out candidateSingleMatch, out candidateMultipleMatches))
                                    {
                                        exports = exports.FastAppendToListAllowNulls(candidateSingleMatch, candidateMultipleMatches);
                                    }
                                }
                            }
                        }
                    }
                }
                if (exports != null)
                {
                    multipleMatches = exports;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(TryGetNonGenericExports(definition, out singleMatch, out multipleMatches));
            }
        }
Exemple #12
0
        static void Main(string[] args)
        {
            var retCode = ArgParser.Parse(args, new string[] { "-h", "-?", "/?" }, new string[] { "-a", "-d", "-pid" });

            ValidateArguments(retCode);

            string switchArg = ArgParser.Switches.FirstOrDefault();

            if (switchArg != null)
            {
                switch (switchArg)
                {
                case "-h":
                case "-?":
                case "/?":
                {
                    PrintSyntaxAndExit(retCode);
                    break;
                }
                }
            }

            var kvp = ArgParser.SwitchesWithValues.FirstOrDefault();

            if (!kvp.Equals(default(KeyValuePair <string, string>)))
            {
                switch (kvp.Key)
                {
                case "-a":
                {
                    var assemblies = kvp.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var assembly in assemblies)
                    {
                        ValidateFile(assembly);
                    }

                    var aggrCat = new AggregateCatalog(assemblies.Select(x => new AssemblyCatalog(x)));

                    var RESULT = new List <ReflectionComposablePart>();

                    using (var container = new CompositionContainer(aggrCat))
                    {
                        foreach (var part in container.Catalog.Parts)
                        {
                            var rfc = new ReflectionComposablePart();
                            rfc.TypeName = part.ToString();

                            foreach (var import in part.ImportDefinitions)
                            {
                                var      impDef = new ImportDefinition();
                                string[] s      = ParseImportDefinition(import.ToString());
                                impDef.ContractName         = s[0].Substring(s[0].IndexOf("\t") + 1);
                                impDef.RequiredTypeIdentity = s[1].Substring(s[1].IndexOf("\t") + 1);
                                rfc.Imports.Add(impDef);
                            }

                            foreach (var export in part.ExportDefinitions)
                            {
                                var expDef = new ExportDefinition();
                                expDef.ContractName = export.ContractName;
                                expDef.TypeIdentity = (string)export.Metadata[CONST_ExportTypeIdentity];
                                rfc.Exports.Add(expDef);
                            }

                            RESULT.Add(rfc);
                        }
                    }

                    DgmlHelper.CreateDgml($"{Guid.NewGuid().ToString()}.dgml", RESULT);
                    break;
                }

                case "-d":
                {
                    string dumpFile = kvp.Value;
                    ValidateFile(dumpFile);

                    var wrapper = ClrMdHelper.LoadDumpFile(dumpFile);
                    InitAndStartProcessing(wrapper);
                    break;
                }

                case "-pid":
                {
                    if (int.TryParse(kvp.Value, out int pid))
                    {
                        var wrapper = ClrMdHelper.AttachToLiveProcess(pid);
                        InitAndStartProcessing(wrapper);
                    }
                    else
                    {
                        Console.WriteLine($"ERROR: Invalid process id.");
                        Environment.Exit(1);
                    }
                    break;
                }
                }
            }
        }
 /// <summary>
 /// Method which can filter exports for given <see cref="ImportDefinition"/> or produce new exports.
 /// </summary>
 /// <param name="definition"><see cref="ImportDefinition"/> instance.</param>
 /// <returns>
 /// A collection of <see cref="ExportDefinition"/>
 /// instances along with their <see cref="ComposablePartDefinition"/> instances which match given <see cref="ImportDefinition"/>.
 /// </returns>
 public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
 {
     return(this.interceptingCatalog.GetExports(definition));
 }
Exemple #14
0
        /// <summary>
        /// Creates a part lifetime context for the given import definition.
        /// </summary>
        /// <typeparam name="TPart">The type of part to create.</typeparam>
        /// <param name="importDefinition">The import definition</param>
        /// <param name="provider">The export provider.</param>
        /// <param name="exportDefinition">The export definition.</param>
        /// <returns>A part lifetime context for the given import definition.</returns>
        protected static Func <PartLifetimeContext <TPart> > CreatePartlifeTimeContext <TPart>(ImportDefinition importDefinition, ExportProvider provider, ExportDefinition exportDefinition)
        {
            Func <PartLifetimeContext <TPart> > creator = () =>
            {
                var part = provider.GetExports(importDefinition)
                           .Single(e => e.Definition == exportDefinition);

                return(new PartLifetimeContext <TPart>((TPart)part.Value, () =>
                {
                    if (part is IDisposable)
                    {
                        ((IDisposable)part).Dispose();
                    }
                }));
            };

            return(creator);
        }
Exemple #15
0
        /// <summary>
        /// Creates a part factory with metadata.
        /// </summary>
        /// <typeparam name="TPart">The type of part.</typeparam>
        /// <param name="importDefinition">The import definition.</param>
        /// <param name="provider">The export provider.</param>
        /// <param name="exportDefinition">The export definition.</param>
        /// <returns>A part factory with metadata.</returns>
        protected static PartFactory <TPart> CreatePartCreatorOfT <TPart>(ImportDefinition importDefinition, ExportProvider provider, ExportDefinition exportDefinition)
        {
            Func <PartLifetimeContext <TPart> > creator = CreatePartlifeTimeContext <TPart>(importDefinition, provider, exportDefinition);

            return(new PartFactory <TPart>(creator));
        }
Exemple #16
0
        /// <summary>
        /// Creates a part factory with metadata.
        /// </summary>
        /// <typeparam name="TPart">The type of part.</typeparam>
        /// <typeparam name="TMetadata">The type of metadata.</typeparam>
        /// <param name="importDefinition">The import definition.</param>
        /// <param name="provider">The export provider.</param>
        /// <param name="exportDefinition">The export definition.</param>
        /// <returns>A part factory with metadata.</returns>
        protected static PartFactory <TPart> CreatePartCreatorOfTWithMetadata <TPart, TMetadata>(ImportDefinition importDefinition, ExportProvider provider, ExportDefinition exportDefinition)
        {
            Func <PartLifetimeContext <TPart> > creator = CreatePartlifeTimeContext <TPart>(importDefinition, provider, exportDefinition);

            return(new PartFactory <TPart, TMetadata>(creator, AttributedModelServices.GetMetadataView <TMetadata>(exportDefinition.Metadata)));
        }
Exemple #17
0
        /// <summary>
        ///     Returns the export definitions that match the constraint defined by the specified definition.
        /// </summary>
        /// <param name="definition">
        ///     The <see cref="ImportDefinition"/> that defines the conditions of the
        ///     <see cref="ExportDefinition"/> objects to return.
        /// </param>
        /// <returns>
        ///     An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the
        ///     <see cref="ExportDefinition"/> objects and their associated
        ///     <see cref="ComposablePartDefinition"/> for objects that match the constraint defined
        ///     by <paramref name="definition"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="definition"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="ComposablePartCatalog"/> has been disposed of.
        /// </exception>
        /// <remarks>
        ///     <note type="inheritinfo">
        ///         Overriders of this property should never return <see langword="null"/>, if no
        ///         <see cref="ExportDefinition"/> match the conditions defined by
        ///         <paramref name="definition"/>, return an empty <see cref="IEnumerable{T}"/>.
        ///     </note>
        /// </remarks>
        public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            this.ThrowIfDisposed();

            Requires.NotNull(definition, "definition");

            IEnumerable <ComposablePartDefinition> candidateParts = this.GetCandidateParts(definition);

            if (candidateParts == null)
            {
                return(Enumerable.Empty <Tuple <ComposablePartDefinition, ExportDefinition> >());
            }

            var exports = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();

            foreach (var part in candidateParts)
            {
                foreach (var export in part.ExportDefinitions)
                {
                    if (definition.IsConstraintSatisfiedBy(export))
                    {
                        exports.Add(new Tuple <ComposablePartDefinition, ExportDefinition>(part, export));
                    }
                }
            }
            return(exports);
        }
Exemple #18
0
 /// <summary>
 ///     Returns all exports that match the conditions of the specified import.
 /// </summary>
 /// <param name="definition">
 ///     The <see cref="ImportDefinition"/> that defines the conditions of the
 ///     <see cref="Export"/> objects to get.
 /// </param>
 /// <result>
 ///     An <see cref="IEnumerable{T}"/> of <see cref="Export"/> objects that match
 ///     the conditions defined by <see cref="ImportDefinition"/>, if found; otherwise, an
 ///     empty <see cref="IEnumerable{T}"/>.
 /// </result>
 /// <exception cref="ArgumentNullException">
 ///     <paramref name="definition"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="ImportCardinalityMismatchException">
 ///     <para>
 ///         <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ExactlyOne"/> and
 ///         there are zero <see cref="Export"/> objects that match the conditions of the specified
 ///         <see cref="ImportDefinition"/>.
 ///     </para>
 ///     -or-
 ///     <para>
 ///         <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ZeroOrOne"/> or
 ///         <see cref="ImportCardinality.ExactlyOne"/> and there are more than one <see cref="Export"/>
 ///         objects that match the conditions of the specified <see cref="ImportDefinition"/>.
 ///     </para>
 /// </exception>
 public IEnumerable <Export> GetExports(ImportDefinition definition)
 {
     return(GetExports(definition, null));
 }
Exemple #19
0
        /// <summary>
        ///     Returns the export definitions that match the constraint defined by the specified definition.
        /// </summary>
        /// <param name="definition">
        ///     The <see cref="ImportDefinition"/> that defines the conditions of the
        ///     <see cref="ExportDefinition"/> objects to return.
        /// </param>
        /// <returns>
        ///     An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the
        ///     <see cref="ExportDefinition"/> objects and their associated
        ///     <see cref="ComposablePartDefinition"/> for objects that match the constraint defined
        ///     by <paramref name="definition"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="definition"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="AggregateCatalog"/> has been disposed of.
        /// </exception>
        public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            this.ThrowIfDisposed();

            Requires.NotNull(definition, "definition");

            // delegate the query to each catalog and merge the results.
            var exports = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();

            foreach (var catalog in this._catalogs)
            {
                foreach (var export in catalog.GetExports(definition))
                {
                    exports.Add(export);
                }
            }
            return(exports);
        }
        /// <summary>
        ///     Returns the export definitions that match the constraint defined by the specified definition.
        /// </summary>
        /// <param name="definition">
        ///     The <see cref="ImportDefinition"/> that defines the conditions of the
        ///     <see cref="ExportDefinition"/> objects to return.
        /// </param>
        /// <returns>
        ///     An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the
        ///     <see cref="ExportDefinition"/> objects and their associated
        ///     <see cref="ComposablePartDefinition"/> for objects that match the constraint defined
        ///     by <paramref name="definition"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="definition"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="DirectoryCatalog"/> has been disposed of.
        /// </exception>
        public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            ThrowIfDisposed();

            Requires.NotNull(definition, nameof(definition));

            return(_catalogCollection.SelectMany(catalog => catalog.GetExports(definition)));
        }
 public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
 {
     return(this._exportsFunc.Invoke());
 }
 public override void SetImport(ImportDefinition definition, IEnumerable <Export> exports)
 {
     _imports[definition] = exports.First().Value;
 }
Exemple #23
0
 internal static bool IsRequiredImportForPreview(ImportDefinition import)
 {
     return(import.Cardinality == ImportCardinality.ExactlyOne);
 }
        private ImportDefinition TranslateImport(ReflectionImportDefinition reflectionImport, List <LazyMemberInfo> members, List <Lazy <ParameterInfo> > parameters)
        {
            bool isExportFactory = false;
            ContractBasedImportDefinition productImport = reflectionImport;

            IPartCreatorImportDefinition exportFactoryImportDefinition = reflectionImport as IPartCreatorImportDefinition;

            if (exportFactoryImportDefinition != null)
            {
                productImport   = exportFactoryImportDefinition.ProductImportDefinition;
                isExportFactory = true;
            }

            string contractName                   = Translate(productImport.ContractName);
            string requiredTypeIdentity           = Translate(productImport.RequiredTypeIdentity);
            IDictionary <string, object> metadata = TranslateImportMetadata(productImport);

            ReflectionMemberImportDefinition memberImport = reflectionImport as ReflectionMemberImportDefinition;
            ImportDefinition import = null;

            if (memberImport != null)
            {
                LazyMemberInfo lazyMember      = memberImport.ImportingLazyMember;
                LazyMemberInfo importingMember = new LazyMemberInfo(lazyMember.MemberType, () => GetAccessors(lazyMember));

                if (isExportFactory)
                {
                    import = new PartCreatorMemberImportDefinition(
                        importingMember,
                        ((ICompositionElement)memberImport).Origin,
                        new ContractBasedImportDefinition(
                            contractName,
                            requiredTypeIdentity,
                            productImport.RequiredMetadata,
                            productImport.Cardinality,
                            productImport.IsRecomposable,
                            false,
                            CreationPolicy.NonShared,
                            metadata));
                }
                else
                {
                    import = new ReflectionMemberImportDefinition(
                        importingMember,
                        contractName,
                        requiredTypeIdentity,
                        productImport.RequiredMetadata,
                        productImport.Cardinality,
                        productImport.IsRecomposable,
                        false,
                        productImport.RequiredCreationPolicy,
                        metadata,
                        ((ICompositionElement)memberImport).Origin);
                }

                members.Add(lazyMember);
            }
            else
            {
                ReflectionParameterImportDefinition parameterImport = reflectionImport as ReflectionParameterImportDefinition;
                if (parameterImport == null)
                {
                    throw new Exception(SR.Diagnostic_InternalExceptionMessage);
                }

                Lazy <ParameterInfo> lazyParameter = parameterImport.ImportingLazyParameter;
                Lazy <ParameterInfo> parameter     = new Lazy <ParameterInfo>(() => GetParameter(lazyParameter));

                if (isExportFactory)
                {
                    import = new PartCreatorParameterImportDefinition(
                        parameter,
                        ((ICompositionElement)parameterImport).Origin,
                        new ContractBasedImportDefinition(
                            contractName,
                            requiredTypeIdentity,
                            productImport.RequiredMetadata,
                            productImport.Cardinality,
                            false,
                            true,
                            CreationPolicy.NonShared,
                            metadata));
                }
                else
                {
                    import = new ReflectionParameterImportDefinition(
                        parameter,
                        contractName,
                        requiredTypeIdentity,
                        productImport.RequiredMetadata,
                        productImport.Cardinality,
                        productImport.RequiredCreationPolicy,
                        metadata,
                        ((ICompositionElement)parameterImport).Origin);
                }

                parameters.Add(lazyParameter);
            }

            return(import);
        }
        public string Importar(string key, string ruta)
        {
            string respuesta = string.Empty;
            try
            {
                //Create a GUID to ensure a unique subscriber key
                string strGUID = System.Guid.NewGuid().ToString();

                //Create an Import Definition object
                ImportDefinition id = new ImportDefinition();
                id.Name = strGUID;
                id.CustomerKey = strGUID;

                //Optional
                id.AllowErrors = true;
                id.AllowErrorsSpecified = true;

                //Associate Data-Extenison to Import-Defintion
                DataExtension de = new DataExtension();
                de.CustomerKey = key;//required //The External Key of the Data Extension to import into

                id.DestinationObject = de;

                //Specify the notification type //optional
                id.Notification = new AsyncResponse();
                id.Notification.ResponseType = AsyncResponseType.email;
                id.Notification.ResponseAddress = "*****@*****.**";

                //Specify the File Transfer Location
                id.RetrieveFileTransferLocation = new FileTransferLocation(); // FTP IMPORT-BF_PERU
                //id.RetrieveFileTransferLocation.CustomerKey = "07292ee0-b2d5-4447-b3e9-31a2cefb6aee";//required
                id.RetrieveFileTransferLocation.CustomerKey = "FTP IMPORT-BF_PERU";//required

                //Optional
                id.UpdateType = ImportDefinitionUpdateType.AddAndDoNotUpdate;
                id.UpdateTypeSpecified = true;

                //Map fields
                id.FieldMappingType = ImportDefinitionFieldMappingType.InferFromColumnHeadings;//required
                id.FieldMappingTypeSpecified = true;

                //Specify the File naming Specifications
                id.FileSpec = ruta;

                //Specify the FileType
                id.FileType = FileType.TAB;//required
                id.FileTypeSpecified = true;

                try
                {
                    string cRequestID = String.Empty;
                    string cStatus = String.Empty;

                    //Call the Create method on the ImportDefinition object
                    CreateResult[] cResults = conexion.ETCliente.Create(new CreateOptions(), new APIObject[] { id }, out cRequestID, out cStatus);

                    //Display Results
                    respuesta += "Overall Status: " + cStatus;
                    respuesta += "<br/>";
                    respuesta += "Number of Results: " + cResults.Length;
                    respuesta += "<br/>";

                    //Loop through each object returned and display the StatusMessage
                    foreach (CreateResult cr in cResults)
                    {
                        respuesta += "Status Message: " + cr.StatusMessage;
                        respuesta += "<br/>";
                    }
                }
                catch (Exception exCreate)
                {
                    //Set Message
                    respuesta += "<br/><br/>CREATE ERROR:<br/>" + exCreate.Message;
                }

            }
            catch (Exception exc)
            {
                //Set Message
                respuesta += "<br/><br/>CREATE ERROR:<br/>" + exc.Message;
            }

            return respuesta;
        }
Exemple #26
0
        private static CompositionResult <IEnumerable <Export> > TryGetExports(ExportProvider provider,
                                                                               ComposablePart part, ImportDefinition definition, AtomicComposition atomicComposition)
        {
            try
            {
                var exports = provider.GetExports(definition, atomicComposition).AsArray();
                return(new CompositionResult <IEnumerable <Export> >(exports));
            }
            catch (ImportCardinalityMismatchException ex)
            {
                // Either not enough or too many exports that match the definition
                CompositionException exception = new CompositionException(ErrorBuilder.CreateImportCardinalityMismatch(ex, definition));

                return(new CompositionResult <IEnumerable <Export> >(
                           ErrorBuilder.CreatePartCannotSetImport(part, definition, exception)));
            }
        }
 public override void SetImport(ImportDefinition definition, System.Collections.Generic.IEnumerable <Export> exports)
 {
 }
Exemple #28
0
 public IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition, IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > exports)
 {
     foreach (var export in exports)
     {
         if (export.Item1.Metadata.ContainsKey("ImportantPart") &&
             export.Item1.Metadata["ImportantPart"].Equals(true))
         {
             yield return(export);
         }
     }
 }
 public override void SetImport(ImportDefinition definition, IEnumerable <Export> exports)
 {
     throw ExceptionBuilder.CreateImportDefinitionNotOnThisComposablePart("definition");
 }
Exemple #30
0
        /// <summary>
        ///     Returns the export definitions that match the constraint defined by the specified definition.
        /// </summary>
        /// <param name="definition">
        ///     The <see cref="ImportDefinition"/> that defines the conditions of the
        ///     <see cref="ExportDefinition"/> objects to return.
        /// </param>
        /// <returns>
        ///     An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the
        ///     <see cref="ExportDefinition"/> objects and their associated
        ///     <see cref="ComposablePartDefinition"/> for objects that match the constraint defined
        ///     by <paramref name="definition"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="definition"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="DeploymentCatalog"/> has been disposed of.
        /// </exception>
        public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            this.ThrowIfDisposed();
            Requires.NotNull(definition, "definition");

            return(this._catalogCollection.GetExports(definition));
        }
        public static Expression <Func <ExportDefinition, bool> > CreatePartCreatorConstraint(Expression <Func <ExportDefinition, bool> > baseConstraint, ImportDefinition productImportDefinition)
        {
            ParameterExpression exportDefinitionParameter = baseConstraint.Parameters[0];

            // exportDefinition.Metadata
            Expression metadataExpression = Expression.Property(exportDefinitionParameter, ConstraintServices._exportDefinitionMetadataProperty);

            // exportDefinition.Metadata.ContainsKey("ProductDefinition")
            Expression containsProductExpression = Expression.Call(
                metadataExpression,
                ConstraintServices._metadataContainsKeyMethod,
                Expression.Constant(CompositionConstants.ProductDefinitionMetadataName));

            // exportDefinition.Metadata["ProductDefinition"]
            Expression productExportDefinitionExpression = Expression.Call(
                metadataExpression,
                ConstraintServices._metadataItemMethod,
                Expression.Constant(CompositionConstants.ProductDefinitionMetadataName));

            // ProductImportDefinition.Contraint((ExportDefinition)exportDefinition.Metadata["ProductDefinition"])
            Expression productMatchExpression =
                Expression.Invoke(productImportDefinition.Constraint,
                                  Expression.Convert(productExportDefinitionExpression, typeof(ExportDefinition)));

            // baseContraint(exportDefinition) &&
            // exportDefinition.Metadata.ContainsKey("ProductDefinition") &&
            // ProductImportDefinition.Contraint((ExportDefinition)exportDefinition.Metadata["ProductDefinition"])
            Expression <Func <ExportDefinition, bool> > constraint =
                Expression.Lambda <Func <ExportDefinition, bool> >(
                    Expression.AndAlso(
                        baseConstraint.Body,
                        Expression.AndAlso(
                            containsProductExpression,
                            productMatchExpression)),
                    exportDefinitionParameter);

            return(constraint);
        }
Exemple #32
0
 protected override IEnumerable <Export> GetExportsCore(ImportDefinition importDefinition)
 {
     return(GetExportsCore(Definitions, importDefinition.Constraint.Compile()));
 }
Exemple #33
0
        /// <summary>
        /// Gets a list of export definitions that match the constraint defined
        /// by the specified <see cref="ImportDefinition"/> object.
        /// </summary>
        /// <returns>
        /// A collection of <see cref="T:System.Tuple`2"/> containing the <see cref="ExportDefinition"/>
        /// objects and their associated <see cref="ComposablePartDefinition"/> objects for objects that match the constraint specified by <paramref name="definition"/>.
        /// </returns>
        /// <param name="definition">The conditions of the <see cref="ExportDefinition"/>
        /// objects to be returned.</param>
        /// <exception cref="ObjectDisposedException">The <see cref="ComposablePartCatalog"/> object has been disposed of.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="definition"/> is null.</exception>
        public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            var exports = base.GetExports(definition);

            foreach (var handler in this.configuration.ExportHandlers)
            {
                exports = handler.GetExports(definition, exports);
            }

            return(exports);
        }
Exemple #34
0
        public static bool IsExportFactoryImportDefinition(ImportDefinition importDefinition)
        {
            Requires.NotNull(importDefinition, nameof(importDefinition));

            return(importDefinition is IPartCreatorImportDefinition);
        }
Exemple #35
0
 /// <summary>
 ///     Returns all exports that match the constraint defined by the specified definition.
 /// </summary>
 /// <param name="definition">
 ///     The <see cref="ImportDefinition"/> that defines the conditions of the
 ///     <see cref="Export"/> objects to return.
 /// </param>
 /// <param name="atomicComposition">The transactional container for the composition.</param>
 /// <result>
 ///     An <see cref="IEnumerable{T}"/> of <see cref="Export"/> objects that match
 ///     the conditions defined by <see cref="ImportDefinition"/>, if found; otherwise, an
 ///     empty <see cref="IEnumerable{T}"/>.
 /// </result>
 /// <remarks>
 ///     <note type="inheritinfo">
 ///         Overriders of this method should not treat cardinality-related mismatches
 ///         as errors, and should not throw exceptions in those cases. For instance,
 ///         if <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ExactlyOne"/>
 ///         and there are zero <see cref="Export"/> objects that match the conditions of the
 ///         specified <see cref="ImportDefinition"/>, an <see cref="IEnumerable{T}"/> should be returned.
 ///     </note>
 /// </remarks>
 protected abstract IEnumerable <Export>?GetExportsCore(ImportDefinition definition, AtomicComposition?atomicComposition);