Exemple #1
0
        /// <summary>
        /// Using an existing proxy, upload any assemblies which are not already present on server as activity libraries
        /// </summary>
        /// <param name="assemblies"></param>
        /// <param name="proxy"></param>
        public static void Upload(IWorkflowsQueryService proxy, IEnumerable<ActivityAssemblyItem> assemblies)
        {
            List<ActivityLibraryDC> assembliesMissingInStore;

            //If the assemblies list is blank or all the assemblies are built-in, there is no need to check the data store and upload dependencies.
            if (assemblies.All(item => AssemblyInspectionService.AssemblyIsBuiltIn(item.AssemblyName)))
            {
                return;
            }

            try
            {
                var request = new GetMissingActivityLibrariesRequest();

                request.Incaller = Assembly.GetExecutingAssembly().GetName().Name;
                request.IncallerVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                request.ActivityLibrariesList = new List<ActivityLibraryDC>();

                foreach (var assemblyItem in assemblies.Where(item => !AssemblyInspectionService.AssemblyIsBuiltIn(item.AssemblyName)))
                {
                    request.ActivityLibrariesList.Add(DataContractTranslator.AssemblyItemToActivityLibraryDataContract(assemblyItem));
                }

                var reply = proxy.GetMissingActivityLibraries(request.SetIncaller());
                assembliesMissingInStore = reply.MissingActivityLibraries;
            }
            catch (FaultException<ServiceFault> ex)
            {
                throw new CommunicationException(ex.Detail.ErrorMessage);
            }
            catch (FaultException<ValidationFault> ex)
            {
                throw new BusinessValidationException(ex.Detail.ErrorMessage);
            }
            catch (Exception ex)
            {
                throw new CommunicationException(ex.Message);
            }

            //Upload anything not already on the server
            var assembliesToUpload = assemblies.Where(assembly => assembliesMissingInStore.Exists(
                serverItem => serverItem.Name == assembly.Name
                              && serverItem.VersionNumber == assembly.Version.ToString()))
                .ToList();

            // Iteratively upload assemblies with no un-uploaded dependencies until there are no more
            while (assembliesToUpload.Any())
            {
                var assembliesWithNoDependencies = from assembly in assembliesToUpload
                                                   where assembly.ReferencedAssemblies == null
                                                         || !assembly.ReferencedAssemblies.Any(
                                                             dependency =>
                                                             {
                                                                 // if the dependency is in assembliesToUpload
                                                                 // we can't upload assembly yet
                                                                 bool dependencyNotUploadedYet = assembliesToUpload.Any(assembly1 => assembly1.AssemblyName.FullName == dependency.FullName);
                                                                 return dependencyNotUploadedYet;
                                                             })
                                                   select assembly;

                foreach (var assembly in assembliesWithNoDependencies)
                {
                    // Get the dependencies for this particular assembly, by filtering based on ReferencedAssemblies
                    var referencedNames = assembly.ReferencedAssemblies.IfNotNull(refs => refs.Select(assembly1 => assembly1.FullName));
                    var dependencies = from cached in Caching.ActivityAssemblyItems
                                       where referencedNames.IfNotNull(reference => reference.Contains(cached.AssemblyName.FullName))
                                       select cached;

                    // Upload it to the server
                    var request = assembly.ToStoreLibraryAndActivitiesRequestDC(dependencies);
                    request.EnforceVersionRules = false;

                    request.StoreActivitiesList.ForEach(item => item.StatusCodeName = MarketplaceStatus.Public.ToString());
                    request.ActivityLibrary.StatusName = MarketplaceStatus.Public.ToString();

                    var result = proxy.UploadActivityLibraryAndDependentActivities(request);
                    result[0].StatusReply.CheckErrors();
                }

                // assembliesToUpload -= assemblies that were just uploaded
                assembliesToUpload = assembliesToUpload.Except(assembliesWithNoDependencies).ToList();
                if (!assembliesWithNoDependencies.Any())
                {
                    throw new DevFacingException(CommonMessages.CyclicDependenciesOnUpload);
                }
            }
        }
        /// <summary>
        /// Get a list of activity libraries that don't exist in the repository based on an initial list to check.
        /// </summary>
        /// <param name="request">ActivityLibraryDC</param>
        /// <returns>List of activity libraries.</returns>
        public static List<ActivityLibraryDC> GetMissingActivityLibraries(GetMissingActivityLibrariesRequest request)
        {
            var resultCollection = new List<ActivityLibraryDC>();
            var status = new StatusReplyDC();
            Database database = null;

            try
            {
                database = DatabaseFactory.CreateDatabase();

                using (var connection = new SqlConnection(database.ConnectionString))
                {
                    using (var command = new SqlCommand(StoredProcNames.ActivityLibraryGetMissing, connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;

                        //Create a table
                        var table = new DataTable("temp");
                        var nameColumn = new DataColumn("Name", typeof(string));
                        var versionColumn = new DataColumn("Version", typeof(string));

                        table.Columns.Add(nameColumn);
                        table.Columns.Add(versionColumn);

                        //Populate the table
                        foreach (var assemblyItem in request.ActivityLibrariesList)
                        {
                            var rowValues = new object[2];
                            rowValues[0] = assemblyItem.Name;
                            rowValues[1] = assemblyItem.VersionNumber;
                            table.Rows.Add(rowValues);
                        }

                        //Send the table-valued parameter to the stored proc
                        SqlParameter parameter = command.Parameters.AddWithValue("@inActivityLibraries", table);
                        parameter.SqlDbType = SqlDbType.Structured;
                        parameter.TypeName = "[dbo].[ActivityLibraryTableType]";

                        connection.Open();

                        SqlDataReader reader = command.ExecuteReader();

                        //Read results from stored proc
                        while (reader.Read())
                        {
                            ActivityLibraryDC activityLibrary =
                                request.ActivityLibrariesList.Find(item =>
                                                                   item.Name == reader.GetString(0) &&
                                                                   item.VersionNumber == reader.GetString(1));
                            if (activityLibrary != null)
                            {
                                resultCollection.Add(activityLibrary);
                            }
                        }

                        reader.Close();
                    }

                }
            }
            catch (SqlException ex)
            {
                ex.HandleException();
            }

            return resultCollection;
        }
        /// <summary>
        /// Performs input validation and gets a list of activity libraries that don't exist in 
        /// the data store based on an initial list to check.
        /// </summary>
        /// <param name="request">ActivityLibrariesCheckExistsRequest data contract.</param>
        /// <returns>List of ActivityLibraryDC.</returns>
        public static GetMissingActivityLibrariesReply GetMissingActivityLibraries(GetMissingActivityLibrariesRequest request)
        {
            var reply = new GetMissingActivityLibrariesReply();

            try
            {
                // Validates the input and throws ValidationException for any issues found.
                request.ValidateRequest();

                // Gets the activity libraries that are not present in the asset store and match the name and version criteria.
                reply.MissingActivityLibraries = ActivityLibraryRepositoryService.GetMissingActivityLibraries(request);
            }
            catch (ValidationException e)
            {
                e.HandleException();
            }
            catch (DataAccessException e)
            {
                e.HandleException();
            }

            return reply;
        }
Exemple #4
0
        public void GetMissingActivityLibraries()
        {
            var request = new CWF.DataContracts.GetMissingActivityLibrariesRequest();
            var reply = new List<CWF.DataContracts.ActivityLibraryDC>();

            CWF.DataContracts.ActivityLibraryDC activityLibraryDC = new CWF.DataContracts.ActivityLibraryDC();
            activityLibraryDC.IncallerVersion = INCALLERVERSION;
            activityLibraryDC.Incaller = INCALLER;
            activityLibraryDC.Name = "OASP.Core2";
            activityLibraryDC.VersionNumber = "1.0.0.0";
            activityLibraryDC.Id = 0;

            request.Incaller = INCALLER;
            request.IncallerVersion = INCALLERVERSION;
            request.ActivityLibrariesList = new List<ActivityLibraryDC> { activityLibraryDC };

            try
            {
                reply = ActivityLibraryRepositoryService.GetMissingActivityLibraries(request);
            }
            catch (Exception ex)
            {
                string faultMessage = ex.Message;
                Assert.Fail(faultMessage + "-catch (Exception ex) on reply = CWF.BAL.StoreActivityLibraryDependencies.StoreActivityLibraryDependencyList(request);");
            }

            Assert.IsNotNull(reply);
        }