Пример #1
0
        public static ObservableCollection <CrmAssembly> CreateCrmAssemblyView(EntityCollection assemblies)
        {
            ObservableCollection <CrmAssembly> crmAssemblies = new ObservableCollection <CrmAssembly>();

            foreach (Entity assembly in assemblies.Entities)
            {
                CrmAssembly crmAssembly = new CrmAssembly
                {
                    AssemblyId  = assembly.Id,
                    Name        = assembly.GetAttributeValue <string>("name"),
                    Version     = assembly.GetAttributeValue <string>("version"),
                    DisplayName = $"{assembly.GetAttributeValue<string>("name")} ({assembly.GetAttributeValue<string>("version")})",
                    SolutionId  = ((EntityReference)assembly.GetAttributeValue <AliasedValue>("solutioncomponent.solutionid").Value).Id
                };

                if (assembly.Contains("plugintype.isworkflowactivity"))
                {
                    crmAssembly.IsWorkflow = (bool)assembly.GetAttributeValue <AliasedValue>("plugintype.isworkflowactivity").Value;
                }

                crmAssemblies.Add(crmAssembly);
            }

            crmAssemblies.Insert(0, new CrmAssembly
            {
                AssemblyId  = Guid.Empty,
                Name        = string.Empty,
                Version     = string.Empty,
                DisplayName = String.Empty
            });

            return(crmAssemblies);
        }
        public static List <CrmAssembly> CreateCrmAssemblyView(EntityCollection assemblies)
        {
            List <CrmAssembly> crmAssemblies = new List <CrmAssembly>();

            foreach (Entity assembly in assemblies.Entities)
            {
                CrmAssembly crmAssembly = new CrmAssembly
                {
                    AssemblyId  = assembly.Id,
                    Name        = assembly.GetAttributeValue <string>("name"),
                    Version     = Version.Parse(assembly.GetAttributeValue <string>("version")),
                    DisplayName = assembly.GetAttributeValue <string>("name") + " (" + assembly.GetAttributeValue <string>("version") + ")"
                                  //,
                                  //SolutionId = new Guid(assembly.GetAttributeValue<AliasedValue>("solutioncomponent.solutionid").Value.ToString())
                };

                if (assembly.Contains("plugintype.isworkflowactivity"))
                {
                    crmAssembly.IsWorkflow = (bool)assembly.GetAttributeValue <AliasedValue>("plugintype.isworkflowactivity").Value;
                }

                crmAssemblies.Add(crmAssembly);
            }

            return(crmAssemblies);
        }
        public static bool UpdateCrmAssembly(CrmServiceClient client, CrmAssembly crmAssembly, string assebmlyPath)
        {
            try
            {
                Entity assembly = new Entity("pluginassembly")
                {
                    Id          = crmAssembly.AssemblyId,
                    ["content"] = Convert.ToBase64String(CrmDeveloperExtensions2.Core.FileSystem.GetFileBytes(assebmlyPath))
                };

                client.Update(assembly);

                return(true);
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                OutputLogger.WriteToOutputWindow(
                    "Error Updating Assembly In CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error);
                return(false);
            }
            catch (Exception ex)
            {
                OutputLogger.WriteToOutputWindow(
                    "Error Updating Assembly In CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error);
                return(false);
            }
        }
Пример #4
0
        public static CrmAssembly CreateCrmAssembly(string projectAssemblyName, string assemblyFilePath,
                                                    string[] assemblyProperties)
        {
            CrmAssembly assembly = new CrmAssembly
            {
                Name           = projectAssemblyName,
                AssemblyPath   = assemblyFilePath,
                Version        = assemblyProperties[2],
                Culture        = assemblyProperties[4],
                PublicKeyToken = assemblyProperties[6],
                //TODO: option to make none?
                IsolationMode = IsolationModeEnum.Sandbox
            };

            return(assembly);
        }
Пример #5
0
        public static Guid UpdateCrmAssembly(CrmServiceClient client, CrmAssembly crmAssembly)
        {
            try
            {
                var assembly = new Entity("pluginassembly")
                {
                    ["content"]        = Convert.ToBase64String(FileSystem.GetFileBytes(crmAssembly.AssemblyPath)),
                    ["name"]           = crmAssembly.Name,
                    ["culture"]        = crmAssembly.Culture,
                    ["version"]        = crmAssembly.Version,
                    ["publickeytoken"] = crmAssembly.PublicKeyToken,
                    ["sourcetype"]     = new OptionSetValue(0), // database
                    ["isolationmode"]  = crmAssembly.IsolationMode == IsolationModeEnum.Sandbox
                    ? new OptionSetValue(2)                     // 2 = sandbox
                    : new OptionSetValue(1)                     // 1= none
                };

                if (crmAssembly.AssemblyId == Guid.Empty)
                {
                    var newId = client.Create(assembly);
                    ExLogger.LogToFile(Logger, $"{Resource.Message_CreatedAssembly}: {crmAssembly.Name}|{newId}", LogLevel.Info);
                    OutputLogger.WriteToOutputWindow($"{Resource.Message_CreatedAssembly}: {crmAssembly.Name}|{newId}", MessageType.Info);
                    return(newId);
                }

                assembly.Id = crmAssembly.AssemblyId;
                client.Update(assembly);

                ExLogger.LogToFile(Logger, $"{Resource.Message_UpdatedAssembly}: {crmAssembly.Name}|{crmAssembly.AssemblyId}", LogLevel.Info);
                OutputLogger.WriteToOutputWindow($"{Resource.Message_UpdatedAssembly}: {crmAssembly.Name}|{crmAssembly.AssemblyId}", MessageType.Info);

                return(crmAssembly.AssemblyId);
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogException(Logger, Resource.ErrorMessage_ErrorCreatingOrUpdatingAssembly, ex);

                return(Guid.Empty);
            }
        }
Пример #6
0
        private void Publish_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Overlay.ShowMessage(_dte, "Deploying...", vsStatusAnimation.vsStatusAnimationDeploy);

                if (CrmAssemblyList.SelectedIndex == -1)
                {
                    return;
                }

                var service = (IOrganizationService)ConnPane.CrmService.OrganizationServiceProxy;
                var ctx     = new OrganizationServiceContext(service);

                ProjectWorker.BuildProject(ConnPane.SelectedProject);

                using (ctx)
                {
                    PluginRegistraton pluginRegistraton = new PluginRegistraton(service, ctx, new TraceLogger());

                    string path = ProjectWorker.GetAssemblyPath(ConnPane.SelectedProject);

                    CrmAssembly assembly = (CrmAssembly)CrmAssemblyList.SelectedItem;
                    if (assembly.IsWorkflow)
                    {
                        pluginRegistraton.RegisterWorkflowActivities(path);
                    }
                    else
                    {
                        pluginRegistraton.RegisterPlugin(path);
                    }
                }
            }
            finally
            {
                Overlay.HideMessage(_dte, vsStatusAnimation.vsStatusAnimationDeploy);
            }
        }
Пример #7
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            //Not connected
            bool hasConnected = Boolean.TryParse(values[0]?.ToString(), out bool isConnected);

            if (!hasConnected)
            {
                return(false);
            }
            if (!isConnected)
            {
                return(false);
            }

            //CrmAssembly
            CrmAssembly crmAssembly = null;

            if (values[1] != null)
            {
                crmAssembly = (CrmAssembly)values[1];
            }

            //DeploymentType
            bool hasDeploymentType = Int32.TryParse(values[2]?.ToString(), out int deploymentType);

            if (!hasDeploymentType)
            {
                return(false);
            }

            if (deploymentType == 1)
            {
                return(true);
            }

            return(crmAssembly != null && crmAssembly.AssemblyId != Guid.Empty);
        }