Пример #1
0
        /// <summary>
        /// The get activity items by activity assembly item.
        /// </summary>
        /// <param name="activityAssemblyItem">
        /// The activity assembly item.
        /// </param>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <returns>
        /// ActivityItems contained in ActivityAssembly
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        public static List<ActivityItem> GetActivityItemsByActivityAssemblyItem(ActivityAssemblyItem activityAssemblyItem, IWorkflowsQueryService client)
        {
            var request = new GetActivitiesByActivityLibraryNameAndVersionRequestDC
                {
                    Name = activityAssemblyItem.Name,
                    VersionNumber = activityAssemblyItem.Version.ToString(),
                    Incaller = Environment.UserName,
                    IncallerVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                };
            var activityItems = client.GetActivitiesByActivityLibraryNameAndVersion(request).List;

            var activityItemCollection = new List<ActivityItem>();

            foreach (StoreActivitiesDC item in activityItems)
            {
                activityItemCollection.Add(DataContractTranslator.StoreActivitiyDCToActivityItem(item, activityAssemblyItem));
            }

            activityAssemblyItem.ActivityItems = new ObservableCollection<ActivityItem>(activityItemCollection);

            foreach (ActivityItem ai in activityItemCollection)
            {
                ai.ParentAssemblyItem = activityAssemblyItem;
            }

            return activityItemCollection;
        }
Пример #2
0
        /// <summary>
        /// Loads an assembly to check for its references and activities.
        /// </summary>
        /// <param name="assemblyPath">Location of the assembly</param>
        /// <param name="item">Assembly item loaded with reflection and xaml buildtask analysis</param>
        public void LoadReflectedInfoInSubdomain(string assemblyPath, out ActivityAssemblyItem item)
        {
            List<AssemblyName> xamlReferences = new List<AssemblyName>();

            item = null;

            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException("assemblyPath");
            }

            assemblyFullPath = assemblyPath;

            // Get assembly and use it to compute activities and references.
            // Any exception in this method should be caught in the inspection service for exception  bubbling.
            var assembly = Assembly.ReflectionOnlyLoadFrom(assemblyFullPath);
            item = new ActivityAssemblyItem(assembly);

            if (assembly.GetType("XamlStaticHelperNamespace._XamlStaticHelper") != null)
            {
                xamlReferences = GetXamlReferences();
            }

            var reflectedReferencedAssemblies = (from assemblyName in assembly.GetReferencedAssemblies()
                                                 select assemblyName)
                                                .Union(xamlReferences);

            //Store the references of the current assembly
            item.ReferencedAssemblies = new ObservableCollection<AssemblyName>(reflectedReferencedAssemblies);
        }
Пример #3
0
        public static void AddToCaching(string assemblyFilePath)
        {
            AssemblyInspectionService.CheckAssemblyPath(assemblyFilePath);
            var assemblyItem = new ActivityAssemblyItem(AssemblyName.GetAssemblyName(assemblyFilePath))
            {
                Location = assemblyFilePath,
                Category = "Unassigned",
            };

            var inspection = Utility.GetAssemblyInspectionService();
            if (!inspection.Inspect(assemblyFilePath))
            {
                throw new UserFacingException(inspection.OperationException.Message, inspection.OperationException);
            }

            assemblyItem.ReferencedAssemblies = new ObservableCollection<AssemblyName>(inspection.ReferencedAssemblies.Select(r => r.AssemblyName));
            assemblyItem.ActivityItems = inspection.SourceAssembly.ActivityItems;
            assemblyItem.UserSelected = true;
            assemblyItem.ActivityItems.ToList().ForEach(i =>
            {
                i.UserSelected = true;
                i.Category = "Unassigned";
            });

            Caching.CacheAssembly(new [] { assemblyItem }.ToList());
            Caching.Refresh();
        }
        private bool isResolved = false; // Backing for the IsResolved property, which determines if the Location was missing at the start but is now filled in.

        #endregion Fields

        #region Constructors

        public ActivityAssemblyItemViewModel(ActivityAssemblyItem item)
        {
            assemblyItem = item;
            activityItems =
                new ReadOnlyObservableCollection<ActivityItem>(new ObservableCollection<ActivityItem>(item.ActivityItems));
            referencedAssemblies = new ReadOnlyObservableCollection<AssemblyName>(new ObservableCollection<AssemblyName>(item.ReferencedAssemblies));
            ReviewAssemblyCommand = new DelegateCommand(ReviewAssemblyCommandExecute, CanReviewAssemblyCommandExecute);
        }
Пример #5
0
 /// <summary>
 /// Prepare to query for an assembly's dependencies
 /// </summary>
 /// <param name="assembly"></param>
 /// <returns></returns>
 public static StoreActivityLibrariesDependenciesDC ActivityAssemblyItemToStoreActivityLibrariesDependenciesDC(ActivityAssemblyItem assembly)
 {
     // Create the request
     return new StoreActivityLibrariesDependenciesDC()
     {
         Incaller = Utility.GetCallerName(),
         IncallerVersion = Utility.GetCallerVersion(),
         StoreDependenciesRootActiveLibrary = new StoreDependenciesRootActiveLibrary
         {
             activityLibraryName = assembly.Name,
             activityLibraryVersionNumber = assembly.Version.ToString()
         }
     };
 }
Пример #6
0
        private string selectedCategory = String.Empty; // Selected category (default) for the assemblies to import

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Default constructor for the class
        /// </summary>
        public ImportAssemblyViewModel(string assemblyFilePath)
        {
            Utility.DoTaskWithBusyCaption("Loading", () =>
            {
                if (string.IsNullOrEmpty(assemblyFilePath))
                {
                    throw new ArgumentNullException("assemblyFilePath");
                }

                AssemblyInspectionService.CheckAssemblyPath(assemblyFilePath);

                StartAddingCategoryCommand = new DelegateCommand(() => { IsAddingCategory = true; });
                StopAddingCategoryCommand = new DelegateCommand(() => { IsAddingCategory = false; });
                ImportCommand = new DelegateCommand(ImportCommandExecute, CanImportCommandExecute);
                AddNewCategoryCommand = new DelegateCommand(AddNewCategoryCommandExecute, CanAddNewCategoryCommandExecute);

                var item = new ActivityAssemblyItem(AssemblyName.GetAssemblyName(assemblyFilePath)) { Location = assemblyFilePath };
                mainAssemblyItem = item;
                Initialize();
            });
        }
Пример #7
0
        /// <summary>
        /// Opens a store activity from server and checks if messages should be popped up
        /// </summary>
        /// <param name="workflowDC"></param>
        /// <param name="fakeLibrary"></param>
        public void OpenStoreActivitiesDC(
            StoreActivitiesDC workflowDC,
            ActivityAssemblyItem fakeLibrary,
            List<ActivityAssemblyItem> references = null,
            bool isTask = false)
        {
            bool isReadOnly = false;
            bool isAdministrator = AuthorizationService.IsAdministrator(AuthorizationService.CurrentPrincipalFunc());

            if (!workflowDC.Locked ||
                (isAdministrator) ||
                (!isAdministrator && workflowDC.Locked && workflowDC.LockedBy == Environment.UserName))
            {
                MessageBoxResult result = MessageBoxService.OpenActivity(workflowDC.Name);
                if (result == MessageBoxResult.Yes)
                {
                    //open workflow for edit mode
                    isReadOnly = false;
                }
                else if (result == MessageBoxResult.No)
                {
                    //open worflow for readonly mode
                    isReadOnly = true;
                }
                else //cancel
                {
                    return;
                }
            }
            else
            {
                if (MessageBoxService.OpenLockedActivityByNonAdmin(workflowDC.LockedBy) == MessageBoxResult.OK)
                    isReadOnly = true;
                else
                    return;
            }

            Utility.DoTaskWithBusyCaption("UI may not respond. Please wait...", () =>
            {
                if (!isReadOnly)
                {
                    StoreActivitesSetLock(workflowDC);
                }

                CheckIsAlreadyInListOrAdd(DataContractTranslator.StoreActivitiyDCToWorkflowItem(workflowDC, fakeLibrary, references, isTask: isTask));
            }, false);

            FocusedWorkflowItem.IsReadOnly = isReadOnly;
            FocusedWorkflowItem.IsSavedToServer = true;
            FocusedWorkflowItem.IsDataDirty = false;
        }
Пример #8
0
 /// <summary>
 /// Compute ActivityAssemblyItem dependencies
 /// </summary>
 /// <param name="client"></param>
 /// <param name="assembly"></param>
 /// <returns></returns>
 public static List<ActivityAssemblyItem> ComputeDependencies(IWorkflowsQueryService client, ActivityAssemblyItem assembly)
 {
     return ComputeDependencies(client, new[] { assembly }.ToList());
 }
Пример #9
0
 /// <summary>
 /// Try to retrieve a cached assembly
 /// </summary>
 /// <param name="assemblyName"></param>
 /// <param name="cachedAssembly"></param>
 /// <returns></returns>
 public static bool LoadCachedAssembly(
     IEnumerable<ActivityAssemblyItem> activityAssemblyItems,
     AssemblyName assemblyName,
     out ActivityAssemblyItem cachedAssembly)
 {
     cachedAssembly = activityAssemblyItems.FirstOrDefault(assembly => assembly.Matches(assemblyName));
     return cachedAssembly != null;
 }
Пример #10
0
        public static WorkflowItem StoreActivitiyDCToWorkflowItem(
            StoreActivitiesDC dc,
            ActivityAssemblyItem parentAssemblyItem,
            List<ActivityAssemblyItem> references = null,
            bool isTask = false)
        {
            var workflowItem = new WorkflowItem(dc.Name, dc.Name, dc.Xaml, dc.WorkflowTypeName, references);

            workflowItem.CachingStatus = CachingStatus.None;
            workflowItem.Category = dc.ActivityCategoryName;

            workflowItem.CreateDateTime = dc.InsertedDateTime;
            workflowItem.CreatedBy = dc.InsertedByUserAlias;
            workflowItem.Description = dc.Description;
            workflowItem.FullName = dc.Name;
            workflowItem.Name = dc.Name;
            workflowItem.DisplayName = dc.ShortName ?? dc.Name;
            workflowItem.HasCodeBehind = dc.IsCodeBeside;
            workflowItem.ParentAssemblyItem = parentAssemblyItem;
            workflowItem.Status = dc.StatusCodeName;
            workflowItem.UpdatedBy = dc.UpdatedByUserAlias;
            workflowItem.UpdateDateTime = dc.UpdatedDateTime;
            workflowItem.IsSavedToServer = true;
            workflowItem.Version = workflowItem.OldVersion = dc.Version;
            workflowItem.IsDataDirty = false;
            workflowItem.Tags = dc.MetaTags;
            workflowItem.XamlCode = dc.Xaml;
            workflowItem.WorkflowType = dc.WorkflowTypeName;
            workflowItem.IsOpenFromServer = true;
            workflowItem.IsTask = isTask;
            return workflowItem;
        }
        /// <summary>
        /// The get activity items by activity assembly item.
        /// </summary>
        /// <param name="client"> </param>
        /// <param name="activityAssemblyItem">
        /// The activity assembly item.
        /// </param>
        public void GetActivityItemsByActivityAssemblyItem(IWorkflowsQueryService client, ActivityAssemblyItem activityAssemblyItem)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (activityAssemblyItem == null)
            {
                throw new ArgumentNullException("activityAssemblyItem");
            }

            CurrentActivityAssemblyItem = activityAssemblyItem;

            if (activityAssemblyItem.ActivityItems != null && activityAssemblyItem.ActivityItems.Count == 0)
            {
                AssemblyDownloader.GetActivityItemsByActivityAssemblyItem(activityAssemblyItem, client);
                WorkflowsQueryServiceUtility.UsingClient(LoadLiveData);
            }
        }
Пример #12
0
 /// <summary>
 /// Save downloaded projects to local machine
 /// </summary>
 /// <param name="wfs"></param>
 /// <param name="filePath"></param>
 public void SaveProjectsToLocal(StoreActivitiesDC activity, List<ActivityAssemblyItem> references)
 {
     if (activity == null)
         return;
     try
     {
         string targetFileName = Utility.GetProjectsDirectoryPath() + "\\" + activity.ActivityLibraryName + "_" + activity.ActivityLibraryVersion + ".wf";
         using (var stream = File.Open(targetFileName, FileMode.Create))
         {
             var formatter = new BinaryFormatter();
             WorkflowItem wfItem = null;
             ActivityAssemblyItem assembly = new ActivityAssemblyItem { Name = activity.Name, Version = System.Version.Parse(activity.Version) };
             wfItem = DataContractTranslator.StoreActivitiyDCToWorkflowItem(activity, assembly, references);
             formatter.Serialize(stream, wfItem);
         }
     }
     catch (Exception ex)//net work exception
     {
         MarketplaceExceptionHandler.HandleSaveProjectsException(ex);
     }
 }
Пример #13
0
        /// <summary>
        /// The assembly name local location location to activity library dc.
        /// </summary>
        /// <param name="aai">
        /// The  assemblyLocationItems.
        /// </param>
        /// <returns>
        /// Converted ActivityLibraryDC instance
        /// </returns>
        public static ActivityLibraryDC AssemblyItemToActivityLibraryDataContract(ActivityAssemblyItem aai)
        {
            var activityLibrary = new ActivityLibraryDC();
            activityLibrary.Name = aai.AssemblyName.Name;
            activityLibrary.VersionNumber = aai.Version.ToString();

            // TODO: remove these
            activityLibrary.Incaller = Utility.GetCallerName();
            activityLibrary.IncallerVersion = Utility.GetCallerVersion();
            activityLibrary.Guid = Guid.NewGuid();
            activityLibrary.AuthGroupName = aai.AuthorityGroup;
            activityLibrary.CategoryName = aai.Category ?? "OAS Basic Controls";
            activityLibrary.Category = Guid.Empty;
            activityLibrary.Executable = new byte[4];
            activityLibrary.HasActivities = false;
            activityLibrary.ImportedBy = Utility.GetCurrentUserName();
            activityLibrary.Description = aai.Description;
            activityLibrary.Status = 1;

            return activityLibrary;
        }
Пример #14
0
 public bool Matches(ActivityAssemblyItem item)
 {
     return this.Name == item.Name
         && this.Version == item.Version;
 }
Пример #15
0
        /// <summary>
        /// Method gets the Executable that this Activity Library represents
        /// </summary>
        /// <param name="client">The WCF Service</param>
        /// <param name="aai">The ActivityAssemblyItem</param>
        /// <returns>a Byte[]</returns>
        public static byte[] GetExecutableBytes(IWorkflowsQueryService client, ActivityAssemblyItem aai)
        {
            List<ActivityLibraryDC> replyList;

            if (aai == null)
            {
                throw new Exception("aai");
            }

            byte[] sourceFileBytes = null;

            var request = new ActivityLibraryDC
            {
                Name = aai.Name,
                VersionNumber = aai.Version.ToString(),
                Incaller = Environment.UserName,
                IncallerVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString()
            };

            try
            {
                replyList = client.ActivityLibraryGet(request);
            }
            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);
            }

            if ((null != replyList) && (0 < replyList.Count))
            {
                sourceFileBytes = replyList[0].Executable;
            }

            return sourceFileBytes;
        }
Пример #16
0
 /// <summary>
 /// The register metadata in assembly.
 /// </summary>
 /// <param name="assembly">
 /// The assembly.
 /// </param>
 private static void RegisterMetadtaInAssembly(ActivityAssemblyItem activityAssemblyItem)
 {
     var allMetadataTypes = activityAssemblyItem.Assembly
                                                   .GetAsManyTypesAsPossible(activityAssemblyItem)
                                                   .Where(t => t.GetInterface("IRegisterMetadata") != null)
                                                   .ToArray();
     foreach (var type in allMetadataTypes)
     {
         object instance = Activator.CreateInstance(type, null);
         MethodInfo registerMethodInfo = type.GetMethod("Register");
         registerMethodInfo.Invoke(instance, null);
     }
 }
Пример #17
0
 private ActivityAssemblyItem GetActivityAssemblyItem(string activityLibraryName, string versionNumber)
 {
     Version version;
     ActivityAssemblyItem activityAssemblyItem = new ActivityAssemblyItem();
     activityAssemblyItem.Assembly = null;
     activityAssemblyItem.AssemblyName = new AssemblyName(activityLibraryName);
     System.Version.TryParse(versionNumber, out version);
     activityAssemblyItem.Version = version;
     return activityAssemblyItem;
 }
        private bool CheckIfConflict(ActivityAssemblyItem item)
        {
            if (item.Name == focusedWorkflow.Name)
            {
                MessageBoxService.CannotCheckAssemblyForItselfSelected(item.Name);
                return true;
            }

            ActivityAssemblyItem conflictAssembly = Assemblies.SingleOrDefault(a => a.UserSelected && a.Name == item.Name && a.Version != item.Version);
            if (conflictAssembly != null)
            {
                MessageBoxService.CannotCheckAssemblyForAnotherVersionSelected(
                    item.Name, item.Version.ToString(), conflictAssembly.Version.ToString());
                return true;
            }

            return false;
        }
        private bool CheckIfAnyConflict(ActivityAssemblyItem item)
        {
            if (CheckIfConflict(item))
                return true;

            bool hasConflicts = false;
            if (item.ReferencedAssemblies != null && item.ReferencedAssemblies.Count > 0)
            {
                foreach (AssemblyName assemblyName in item.ReferencedAssemblies)
                {
                    if (!Utility.AssemblyIsBuiltIn(assemblyName))
                    {
                        ActivityAssemblyItem refItem = Assemblies.Single(i => i.Name == assemblyName.Name && i.Version == assemblyName.Version);
                        if (CheckIfConflict(refItem))
                        {
                            hasConflicts = true;
                            break;
                        }
                    }
                }
            }
            return hasConflicts;
        }
        private void CheckAssemblyDependencies(ActivityAssemblyItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }

            if (item.UserSelected)
            {
                if (CheckIfAnyConflict(item))
                {
                    item.UserSelected = false;
                }
                else
                {
                    if (item.ReferencedAssemblies != null && item.ReferencedAssemblies.Count > 0)
                    {
                        foreach (AssemblyName assemblyName in item.ReferencedAssemblies)
                        {
                            if (!Utility.AssemblyIsBuiltIn(assemblyName))
                            {
                                ActivityAssemblyItem refItem = Assemblies.Single(i => i.Name == assemblyName.Name && i.Version == assemblyName.Version);
                                if (referencedAssemblies.ContainsKey(refItem))
                                {
                                    if (!referencedAssemblies[refItem].Contains(item))
                                        referencedAssemblies[refItem].Add(item);
                                }
                                else
                                {
                                    referencedAssemblies.Add(refItem, new[] { item }.ToList());
                                }
                                refItem.UserSelected = true;
                            }
                        }
                    }
                }
            }
            else
            {
                if (referencedAssemblies.ContainsKey(item)
                    && referencedAssemblies[item].Any())
                {
                    MessageBoxService.CannotUncheckAssemblyForReferenced(item.AssemblyName, referencedAssemblies[item].Select(a => a.AssemblyName).ToArray());
                    item.UserSelected = true;
                }
                else
                {
                    if (item.ReferencedAssemblies != null && item.ReferencedAssemblies.Count > 0)
                    {
                        foreach (AssemblyName assemblyName in item.ReferencedAssemblies)
                        {
                            if (!Utility.AssemblyIsBuiltIn(assemblyName))
                            {
                                ActivityAssemblyItem refItem = Assemblies.Single(i => i.Name == assemblyName.Name && i.Version == assemblyName.Version);
                                if (referencedAssemblies.ContainsKey(refItem))
                                    referencedAssemblies[refItem].Remove(item);
                            }
                        }
                    }
                }
            }
        }
Пример #21
0
        /// <summary>
        /// Download MarketplaceAsset that AssetType is equal to Activities
        /// </summary>
        /// <param name="assets"></param>
        /// <param name="assetType"></param>
        public void DownloadActivities(IWorkflowsQueryService client)
        {
            var downloadedAssemblies = new List<ActivityAssemblyItem>();
            foreach (MarketplaceAssetModel model in this.activities)
            {
                if (IsCancelDownload)
                {
                    CancelDownload();
                    return;
                }

                ActivityAssemblyItem toDownloadAssembly = new ActivityAssemblyItem { Name = model.Name, Version = System.Version.Parse(model.Version) };
                AssemblyDownloader.GetActivityItemsByActivityAssemblyItem(toDownloadAssembly, client);

                //download dependendies
                var dependecies = Caching.ComputeDependencies(client, toDownloadAssembly);
                dependecies.Add(toDownloadAssembly);

                var toCachedAssembly = Caching.DownloadAssemblies(client, dependecies);
                toCachedAssembly.ToList().ForEach(i => i.UserSelected = model.IsAddToToolbox);

                downloadedAssemblies.AddRange(toCachedAssembly);

                //set download progress
                currentDownloadingNumber++;
                SetDownloadProgress();
            }

            if (!IsCancelDownload)
            {
                Caching.CacheAssembly(downloadedAssemblies);
                Caching.Refresh();
                if (this.currentWorkflow != null)
                {
                    ObservableCollection<ActivityAssemblyItem> importAssemblies = new ObservableCollection<ActivityAssemblyItem>(this.currentWorkflow.WorkflowDesigner.DependencyAssemblies);
                    downloadedAssemblies.ForEach(i =>
                    {
                        if (importAssemblies.SingleOrDefault(item => item.FullName != i.FullName) == null)
                            importAssemblies.Add(i);
                    });
                    this.currentWorkflow.WorkflowDesigner.ImportAssemblies(importAssemblies.ToList());
                }
                this.activities.ForEach(
                    m => m.Location = Caching.ActivityAssemblyItems
                        .Where(i => i.Name == m.Name && i.Version.ToString() == m.Version)
                        .First().Location);
            }
        }
Пример #22
0
        private void OpenActivityFromServer(StoreActivitiesDC activity, bool ShouldDownloadDependencies, bool isTask = false)
        {
            StoreActivitiesDC selectedWorkflowDC;
            ActivityAssemblyItem assembly = null;
            string activityLibraryName;
            string version;
            selectedWorkflowDC = activity;
            if (selectedWorkflowDC != null) // will be null if user cancelled
            {
                activityLibraryName = selectedWorkflowDC.ActivityLibraryName;
                version = selectedWorkflowDC.ActivityLibraryVersion;

                assembly = new ActivityAssemblyItem { Name = activityLibraryName, Version = System.Version.Parse(version) };
                List<ActivityAssemblyItem> references = new List<ActivityAssemblyItem>();

                Utility.WithContactServerUI(() =>
                {
                    using (var client = WorkflowsQueryServiceUtility.GetWorkflowQueryServiceClient())
                    {
                        List<ActivityAssemblyItem> referencedItems = Caching.ComputeDependencies(client, assembly);
                        if (ShouldDownloadDependencies)
                        {
                            references = Caching.CacheAndDownloadAssembly(client, referencedItems);
                        }
                        else
                        {
                            references = Caching.Match(referencedItems);
                        }
                    }
                });
                OpenStoreActivitiesDC(selectedWorkflowDC, assembly, references, isTask: isTask);
            }
        }
Пример #23
0
        /// <summary>
        /// Download MarketplaceAsset assettype = Projects
        /// </summary>
        /// <param name="assets"></param>
        /// <returns></returns>
        public void DownloadProjects(IWorkflowsQueryService client)
        {
            List<StoreActivitiesDC> request = this.projects.Select(item =>
            {
                return new StoreActivitiesDC
                {
                    Name = item.Name,
                    Version = item.Version,
                    Incaller = Environment.UserName,
                    IncallerVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                };
            }).ToList<StoreActivitiesDC>();

            foreach (StoreActivitiesDC item in request)
            {
                if (IsCancelDownload)
                {
                    CancelDownload();
                    return;
                }
                var result = client.StoreActivitiesGet(item);
                if (result.Any())
                {
                    StoreActivitiesDC dc = result[0];
                    ActivityAssemblyItem assembly = new ActivityAssemblyItem { Name = dc.ActivityLibraryName, Version = System.Version.Parse(dc.Version) };
                    List<ActivityAssemblyItem> references = Caching.CacheAndDownloadAssembly(client, Caching.ComputeDependencies(client, assembly));
                    this.SaveProjectsToLocal(dc, references);
                    currentDownloadingNumber++;
                    SetDownloadProgress();
                }
            }
        }
Пример #24
0
        /// <summary>
        /// Resolve the references of an assembly using the assembly loader
        /// </summary>
        /// <param name="assemblyLoader">Assembly loader object created in the app domain</param>
        /// <param name="assemblyPath">Path to the assembly</param>
        /// <param name="assemblyVersion">Version of the assembly to search for</param>
        /// <param name="isRootAssembly">Indicates if the assembly to analize is the main assembly of this inspection.</param>
        /// <returns></returns>
        private void ResolveReferences(AssemblyLoader assemblyLoader, string assemblyPath, Version assemblyVersion, bool isRootAssembly)
        {
            try
            {
                //Load the assembly in subdomain to analyze it with reflection.
                ActivityAssemblyItem assemblyItem;

                assemblyLoader.LoadReflectedInfoInSubdomain(assemblyPath, out assemblyItem);

                //Store root assembly information to return it to the main app domain
                if (isRootAssembly)
                {
                    sourceAssembly = assemblyItem;
                }
                else
                {
                    referencedAssemblies.Add(assemblyItem);
                }

                //Add the list of references discovered through reflection
                //to analyze them as part of the import process.
                foreach (var item in assemblyItem.ReferencedAssemblies.Where(item => !AssemblyIsBuiltIn(item)))
                {
                    if (!referencesToCheck.ContainsKey(Tuple.Create(item.Name, item.Version)) &&
                        (!analyzedReferences.ContainsKey(Tuple.Create(item.Name, item.Version))))
                    {
                        referencesToCheck.Add(Tuple.Create(item.Name, item.Version), null);
                    }
                }

                //if the inspection produced some references that were not resolved, add them too.
                if (assemblyLoader.ReferencedAssemblies.Any())
                {
                    foreach (var item in assemblyLoader.ReferencedAssemblies.Where(item => !AssemblyIsBuiltIn(item)))
                    {
                        if (!referencesToCheck.ContainsKey(Tuple.Create(item.Name, item.Version)) &&
                            (!analyzedReferences.ContainsKey(Tuple.Create(item.Name, item.Version))))
                        {
                            referencesToCheck.Add(Tuple.Create(item.Name, item.Version), null);
                        }
                    }
                }

            }
            catch (FileNotFoundException ex)
            {
                // assemblyName was not found.
                throw new AssemblyInspectionException(ex.Message, ex);
            }
            catch (TypeLoadException ex)
            {
                //typeName was not found in assemblyName.
                throw new AssemblyInspectionException(ex.Message, ex);
            }
            catch (BadImageFormatException ex)
            {
                //assemblyName is not a valid assembly.
                throw new AssemblyInspectionException(ex.Message, ex);
            }
            catch (FileLoadException ex)
            {
                //An assembly or module was loaded twice with two different evidences.
                throw new AssemblyInspectionException(ex.Message, ex);
            }
            catch (PathTooLongException ex)
            {
                //An assembly or module was loaded twice with two different evidences.
                throw new AssemblyInspectionException(ex.Message, ex);
            }
        }
Пример #25
0
        /// <summary>
        /// The activity library dc to activity assembly item.
        /// </summary>
        /// <param name="activityLibraryDC">
        /// The activity library dc.
        /// </param>
        /// <param name="assemblyReferences">
        /// Referenced assemblies for this ActivityLibraryDC. Use this parameter when you are actually downloading the library
        /// to cache and use, vs. just displaying it in a Select screen. It would be great if this info were actually part of
        /// ActivityLibraryDC but it isn't so we have to collect it separately.
        /// </param>
        /// <returns>
        /// Converted ActivityAssemblyItem instance
        /// </returns>
        public static ActivityAssemblyItem ActivityLibraryDCToActivityAssemblyItem(ActivityLibraryDC activityLibraryDC,
            IEnumerable<AssemblyName> assemblyReferences = null)
        {
            var activityAssemblyItem = new ActivityAssemblyItem();
            Version version;

            activityAssemblyItem.ActivityItems = new ObservableCollection<ActivityItem>();
            activityAssemblyItem.Assembly = null;
            activityAssemblyItem.AssemblyName = new AssemblyName(activityLibraryDC.Name);
            System.Version.TryParse(activityLibraryDC.VersionNumber, out version);
            activityAssemblyItem.Version = version;
            activityAssemblyItem.AuthorityGroup = activityLibraryDC.AuthGroupName;
            activityAssemblyItem.CachingStatus = CachingStatus.None;
            activityAssemblyItem.Category = activityLibraryDC.CategoryName;

            activityAssemblyItem.Description = activityLibraryDC.Description;
            activityAssemblyItem.DisplayName = activityLibraryDC.Name;
            activityAssemblyItem.Status = activityLibraryDC.StatusName;
            activityAssemblyItem.Tags = activityLibraryDC.MetaTags;

            if (assemblyReferences != null)
            {
                activityAssemblyItem.SetDatabaseReferences(assemblyReferences);
            }

            activityAssemblyItem.UserSelected = false;
            activityAssemblyItem.ReleaseNotes = activityLibraryDC.ReleaseNotes;
            activityAssemblyItem.FriendlyName = activityLibraryDC.FriendlyName;

            return activityAssemblyItem;
        }
Пример #26
0
 /// <summary>
 /// Prevent adding multiple version of an activity in add-in
 /// </summary>
 /// <returns></returns>
 private static bool CheckVersionForConflict(ActivityAssemblyItem left, ActivityAssemblyItem right)
 {
     return left.Name == right.Name
         && left.Version != right.Version;
 }
Пример #27
0
        /// <summary>
        /// The store activity dc to activity item.
        /// </summary>
        /// <param name="dc">
        /// The StoreActivitiesDC data contract instance.
        /// </param>
        /// <param name="parentAssemblyItem">
        /// The parent assembly item.
        /// </param>
        /// <returns>
        /// Converted ActivityItem instance
        /// </returns>
        public static ActivityItem StoreActivitiyDCToActivityItem(
            StoreActivitiesDC dc, ActivityAssemblyItem parentAssemblyItem)
        {
            var activityItem = new ActivityItem();

            activityItem.CachingStatus = CachingStatus.None;
            activityItem.Category = dc.ActivityCategoryName;

            activityItem.CreateDateTime = dc.InsertedDateTime;
            activityItem.CreatedBy = dc.InsertedByUserAlias;
            activityItem.Description = dc.Description;
            activityItem.FullName = dc.Name;
            activityItem.Name = dc.ShortName ?? dc.Name;
            activityItem.DisplayName = dc.ShortName ?? dc.Name;
            activityItem.HasCodeBehind = dc.IsCodeBeside;
            activityItem.IsReadOnly = true; // TODO: Need to find out where this is in the Model
            activityItem.IsUserFavorite = false; // TODO: This needs to be added to the Database, DAL, BAL and/or DataContract reply
            activityItem.ParentAssemblyItem = parentAssemblyItem;

            activityItem.Status = dc.StatusCodeName;
            activityItem.UpdatedBy = dc.UpdatedByUserAlias;
            activityItem.UpdateDateTime = dc.UpdatedDateTime;
            activityItem.UserSelected = true;  // TODO: Why is this set to true?
            activityItem.Version = activityItem.OldVersion = dc.Version;
            activityItem.XamlCode = dc.Xaml;
            return activityItem;
        }
Пример #28
0
 private static bool CheckVersionForConflicts(IEnumerable<ActivityAssemblyItem> collection, ActivityAssemblyItem obj)
 {
     return (from c in collection
             where CheckVersionForConflict(c, obj)
             select c).Any();
 }
Пример #29
0
        /// <summary>
        /// Analizes an assembly (specified in the parameter), to discover all its references and
        /// the activities contained on it. 
        /// </summary>
        /// <param name="assemblyPath">Path of the assembly to analize</param>
        public bool Inspect(string assemblyPath)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException("assemblyPath");
            }

            //Create a new appdomain, so we don't load assemblies in the main app domain and
            //we can unload the assemblies from memory when the operation finishes.
            var appDomain = CreateTempAppDomain(AppDomain.CurrentDomain);

            // Setup
            var typeName = typeof(AssemblyLoader).FullName;
            var location = typeof(AssemblyLoader).Assembly.Location;

            if (!String.IsNullOrEmpty(typeName) && !String.IsNullOrEmpty(location))
            {
                // Run computation and tear down AppDomain
                var subloader = (AssemblyLoader)appDomain.CreateInstanceFromAndUnwrap(location, typeName);

                try
                {
                    ResolveReferences(subloader, assemblyPath, null, true);
                }
                catch (AssemblyInspectionException ex)
                {
                    //Could not analyze the main assembly, so we encapsulate the exception to return it as a result.
                    OperationException = ex;
                    return false;
                }

                string directory = Path.GetDirectoryName(assemblyPath);
                while (referencesToCheck.Any())
                {
                    Tuple<string, Version> element = referencesToCheck.First().Key;
                    string referenceName = element.Item1;
                    string referencePath = referenceName+".dll"; //referenceName + ".dll";
                    string referenceVersion = element.Item2.ToString();
                    if (!string.IsNullOrEmpty(directory))
                    {
                        //Look for the missing assembly in the selected location and the subfolders
                        var matchesInDirectory = Directory.EnumerateFiles(directory, referencePath, SearchOption.AllDirectories);
                        if (matchesInDirectory.Any())
                        {
                            referencePath = Path.Combine(matchesInDirectory.First());
                        }
                        else
                        {
                            //var matchesInTargetDirectory = Directory.EnumerateFiles(FileService.GetAssembliesDirectoryPath(), referencePath, SearchOption.AllDirectories);
                            //if (matchesInTargetDirectory.Any())
                            //{
                            //    referencePath = Path.Combine(matchesInDirectory.First());
                            //}
                            referencePath = FileService.GetAssembliesDirectoryPath() + "\\" + referenceName + "\\" + referenceVersion + "\\" + referencePath;
                        }

                    }

                    try
                    {
                        if (File.Exists(referencePath))
                        {
                            ResolveReferences(subloader, referencePath, element.Item2, false);
                            analyzedReferences.Add(element, referencePath);
                        }
                        else
                        {
                            analyzedReferences.Add(element, null);
                            string name = Path.GetFileNameWithoutExtension(referencePath);
                            if (!string.IsNullOrEmpty(name))
                            {
                                var item = new ActivityAssemblyItem(new AssemblyName(name)) { Version = element.Item2 };
                                referencedAssemblies.Add(item);
                            }
                        }

                    }
                    catch (AssemblyInspectionException)
                    {
                        //Error resolving one reference, in this case we can continue the analysis because it's not the
                        //main assembly being analyzed. We add the assembly with an empty location to the collection.
                        analyzedReferences.Add(element, null);

                        //Assembly is not the main element being analyzed, so we just add it with empty properties to the list
                        //(the inspection should continue for the other references).
                        string name = Path.GetFileNameWithoutExtension(referencePath);
                        if (!string.IsNullOrEmpty(name))
                        {
                            var item = new ActivityAssemblyItem(new AssemblyName(name)) { Version = element.Item2 };
                            referencedAssemblies.Add(item);
                        }
                    }

                    referencesToCheck.Remove(element);
                }

                AppDomain.Unload(appDomain);
            }

            return true;
        }
Пример #30
0
 /// <summary>
 /// Try to retrieve a cached assembly
 /// </summary>
 /// <param name="assemblyName"></param>
 /// <param name="cachedAssembly"></param>
 /// <returns></returns>
 public static bool LoadCachedAssembly(AssemblyName assemblyName,out ActivityAssemblyItem cachedAssembly)
 {
     return Utility.LoadCachedAssembly(ActivityAssemblyItems, assemblyName, out cachedAssembly);
 }