コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReviewActivityViewModel"/> class.
        /// </summary>
        /// <param name="activityAssemblyItem">
        /// The activity assembly item.
        /// </param>
        public ReviewActivityViewModel(ActivityAssemblyItemViewModel activityAssemblyItem)
        {
            ReviewAssemblyCommand = new DelegateCommand(ReviewAssemblyCommandExecute);
            ActivityAssemblyItem = activityAssemblyItem;
            Title = string.Format("Review Activities in {0}", activityAssemblyItem.Name);

            foreach (ActivityItem activityItem in activityAssemblyItem.ActivityItems)
            {
                activityItem.Category = activityAssemblyItem.Category;
                activityItem.Version = activityAssemblyItem.Version;
            }
        }
コード例 #2
0
        private void MarkResolvedAssembly(ActivityAssemblyItemViewModel newAssembly)
        {
            if (newAssembly.Location != SelectedActivityAssemblyItem.Location) // we don't want to mark the main item we're importing as 'resolved'
                resolvedAssemblies.Add(newAssembly.Location);

            AssembliesToImport
                  .Where(item => resolvedAssemblies.Contains(item.Location))
                  .ToList()
                  .ForEach(item => item.IsResolved = true);
        }
コード例 #3
0
        /// <summary>
        /// Starts the inspection of one assembly to get all its references and contained activities
        /// </summary>
        /// <param name="assemblyPath">Path of the assembly to import</param>
        public void InspectAssembly(string assemblyPath)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException("assemblyPath");
            }

            AssemblyInspectionService.CheckAssemblyPath(assemblyPath);

            var assemblyName = AssemblyName.GetAssemblyName(assemblyPath);

            if (AssembliesToImport.Any(item => item.Name == assemblyName.Name
                                               && item.Version == assemblyName.Version.ToString()
                                               && !string.IsNullOrEmpty(item.Location)))
            {
                MessageBoxService.Show(ImportMessages.AssemblyAlreadyInListToImport,
                                       Assembly.GetExecutingAssembly().GetName().Name,
                                       MessageBoxButton.OK,
                                       MessageBoxImage.Information);
                return;
            }

            var inspection = Utility.GetAssemblyInspectionService();

            if (!inspection.Inspect(assemblyPath))
            {
                throw new UserFacingException(inspection.OperationException.Message, inspection.OperationException);
            }

            if (AssembliesToImport.Any())
            {
                //Remove the assembly without location that we just analyzed
                AssembliesToImport.Remove(item => item.Name == inspection.SourceAssembly.Name &&
                                                  item.Version == inspection.SourceAssembly.Version.ToString() &&
                                                  string.IsNullOrEmpty(item.Location));
            }

            var newAssembly = new ActivityAssemblyItemViewModel(inspection.SourceAssembly);
            AssembliesToImport.Add(newAssembly);

            if (SelectedActivityAssemblyItem == null)
            {
                SelectedActivityAssemblyItem = AssembliesToImport[0];
            }

            if (inspection.ReferencedAssemblies.Any())
            {
                //Check if we have already located the missing assemblies in the last reference inspection, and remove them.
                AssembliesToImport.Remove(item => string.IsNullOrEmpty(item.Location) &&
                                                  inspection.ReferencedAssemblies.Any(
                                                      element => element.Name == item.Name &&
                                                                 element.Version.ToString() == item.Version &&
                                                                 !string.IsNullOrEmpty(element.Location)));

                foreach (var item in inspection.ReferencedAssemblies)
                {
                    //Check to verify assembly is not already in the list
                    if (!AssembliesToImport.Any(element => element.Name == item.Name && element.Version == item.Version.ToString()))
                    {
                        var viewModel = new ActivityAssemblyItemViewModel(item);
                        AssembliesToImport.Add(viewModel);
                    }
                }
            }

            MarkResolvedAssembly(newAssembly);
            SortAssembliesToImport();
        }
コード例 #4
0
        /// <summary>
        /// Updates the location of one of the Assemblies to be imported. 
        /// </summary>
        /// <param name="activityAssemblyItem"></param>
        /// <param name="assemblyPath"></param>
        public void UpdateReferenceLocation(ActivityAssemblyItemViewModel activityAssemblyItem, string assemblyPath)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException("assemblyPath");
            }

            AssemblyInspectionService.CheckAssemblyPath(assemblyPath);

            // Validate assembly, inspect if its valid
            if (ValidateLocation(activityAssemblyItem, assemblyPath))
            {
                activityAssemblyItem.IsReviewed = false; //user will have to review it again
                InspectAssembly(assemblyPath);
            }
        }
コード例 #5
0
        /// <summary>
        /// Validates one assembly to check if a file path corresponds to one of our assembly items (name,version)
        /// </summary>
        /// <param name="activityAssemblyItem"></param>
        /// <param name="location"></param>
        /// <param name="throwOnFailure">true for user-facing operations which must give feedback about reasons for failure, false for programmatic operations that must be fast</param>
        /// <returns>True on success</returns>
        public static bool ValidateLocation(ActivityAssemblyItemViewModel activityAssemblyItem, string location, bool throwOnFailure = true)
        {
            AssemblyName name;

            if (null == activityAssemblyItem)
            {
                if (!throwOnFailure)
                    return false;
                throw new ArgumentNullException("activityAssemblyItem");
            }
            try
            {
                name = AssemblyName.GetAssemblyName(location);
            }
            catch
            {
                if (!throwOnFailure)
                    return false;
                throw new UserFacingException(string.Format(ImportMessages.NotADotNetAssembly, location));
            }

            AssemblyName assemblyName = ActivityAssemblyItem.TreatUnsignedAsUnversioned(name);

            if (assemblyName.Name != activityAssemblyItem.Name)
            {
                if (!throwOnFailure)
                    return false;
                throw new UserFacingException(string.Format("The file '{0}' does not contain the required assembly '{1}'", location, activityAssemblyItem.Name));
            }

            if (assemblyName.Version != activityAssemblyItem.AssemblyName.Version)
            {
                if (!throwOnFailure)
                    return false;
                // ideally this message would tell you WHO requires it
                throw new UserFacingException(string.Format("The file '{0}' is {1}, but {2} is required",
                    location, assemblyName.Version.IfNotNull(v => "v" + v.ToString()) ?? "unsigned",
                    activityAssemblyItem.AssemblyName.Version.IfNotNull(v => "v" + v.ToString()) ?? "an unsigned assembly"));
            }

            return true;
        }