Ejemplo n.º 1
0
        public static bool AddWebResourceToSolution(CrmServiceClient client, string uniqueName, Guid webResourceId)
        {
            try
            {
                AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest
                {
                    ComponentType      = 61,
                    SolutionUniqueName = uniqueName,
                    ComponentId        = webResourceId
                };
                AddSolutionComponentResponse response =
                    (AddSolutionComponentResponse)client.Execute(scRequest);

                OutputLogger.WriteToOutputWindow("New Web Resource Added To Solution: " + response.id, MessageType.Info);

                return(true);
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                OutputLogger.WriteToOutputWindow(
                    "Error adding web resource to solution: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error);
                return(false);
            }
            catch (Exception ex)
            {
                OutputLogger.WriteToOutputWindow(
                    "Error adding web resource to solution: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error);
                return(false);
            }
        }
Ejemplo n.º 2
0
        private bool CreateReport(Guid solutionId, string uniqueName, string name, string filePath, string relativePath, int viewableIndex)
        {
            try
            {
                CrmConnection connection = CrmConnection.Parse(_connection.ConnectionString);

                using (_orgService = new OrganizationService(connection))
                {
                    Entity report = new Entity("report");
                    report["name"]           = name;
                    report["bodytext"]       = File.ReadAllText(filePath);
                    report["reporttypecode"] = new OptionSetValue(1); //ReportingServicesReport
                    report["filename"]       = Path.GetFileName(filePath);
                    report["languagecode"]   = 1033;                  //TODO: handle multiple
                    report["ispersonal"]     = (viewableIndex == 0);

                    Guid id = _orgService.Create(report);

                    _logger.WriteToOutputWindow("Report Created: " + id, Logger.MessageType.Info);

                    //Add to the choosen solution (not default)
                    if (solutionId != new Guid("FD140AAF-4DF4-11DD-BD17-0019B9312238"))
                    {
                        AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest
                        {
                            ComponentType      = 31,
                            SolutionUniqueName = uniqueName,
                            ComponentId        = id
                        };
                        AddSolutionComponentResponse response =
                            (AddSolutionComponentResponse)_orgService.Execute(scRequest);

                        _logger.WriteToOutputWindow("New Report Added To Solution: " + response.id, Logger.MessageType.Info);
                    }

                    NewId         = id;
                    NewName       = name;
                    NewBoudndFile = relativePath;

                    return(true);
                }
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                _logger.WriteToOutputWindow("Error Creating Report: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, Logger.MessageType.Error);
                return(false);
            }
            catch (Exception ex)
            {
                _logger.WriteToOutputWindow("Error Creating Report: " + ex.Message + Environment.NewLine + ex.StackTrace, Logger.MessageType.Error);
                return(false);
            }
        }
Ejemplo n.º 3
0
        private bool CreateWebResource(Guid solutionId, string uniqueName, int type, string prefix, string name, string displayName, string filePath, string relativePath)
        {
            try
            {
                var    client      = new CrmServiceClient(_connection.ConnectionString);
                Entity webResource = new Entity("webresource");
                webResource["name"]            = prefix + name;
                webResource["webresourcetype"] = new OptionSetValue(type);
                if (!string.IsNullOrEmpty(displayName))
                {
                    webResource["displayname"] = displayName;
                }

                if (type == 8)
                {
                    webResource["silverlightversion"] = "4.0";
                }

                string extension = Path.GetExtension(filePath);

                List <string> imageExs = new List <string>()
                {
                    ".ICO", ".PNG", ".GIF", ".JPG"
                };
                string content;
                //TypeScript
                if (extension != null && (extension.ToUpper() == ".TS"))
                {
                    content = File.ReadAllText(Path.ChangeExtension(filePath, ".js"));
                    webResource["content"] = EncodeString(content);
                }
                //Images
                else if (extension != null && imageExs.Any(s => extension.ToUpper().EndsWith(s)))
                {
                    content = EncodedImage(filePath, extension);
                    webResource["content"] = content;
                }
                //Everything else
                else
                {
                    content = File.ReadAllText(filePath);
                    webResource["content"] = EncodeString(content);
                }

                Guid id = client.OrganizationServiceProxy.Create(webResource);

                _logger.WriteToOutputWindow("New Web Resource Created: " + id, Logger.MessageType.Info);

                //Add to the choosen solution (not default)
                if (solutionId != new Guid("FD140AAF-4DF4-11DD-BD17-0019B9312238"))
                {
                    AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest
                    {
                        ComponentType      = 61,
                        SolutionUniqueName = uniqueName,
                        ComponentId        = id
                    };
                    AddSolutionComponentResponse response =
                        (AddSolutionComponentResponse)client.OrganizationServiceProxy.Execute(scRequest);

                    _logger.WriteToOutputWindow("New Web Resource Added To Solution: " + response.id, Logger.MessageType.Info);
                }

                NewId   = id;
                NewType = type;
                NewName = prefix + name;
                if (!string.IsNullOrEmpty(displayName))
                {
                    NewDisplayName = displayName;
                }
                NewBoundFile  = relativePath;
                NewSolutionId = solutionId;

                return(true);
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                _logger.WriteToOutputWindow("Error Creating Web Resource: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, Logger.MessageType.Error);
                return(false);
            }
            catch (Exception ex)
            {
                _logger.WriteToOutputWindow("Error Creating Web Resource: " + ex.Message + Environment.NewLine + ex.StackTrace, Logger.MessageType.Error);
                return(false);
            }
        }
Ejemplo n.º 4
0
        private bool CreateWebResource(Guid solutionId, string uniqueName, int type, string prefix, string name, string displayName, string filePath, string relativePath)
        {
            try
            {
                CrmConnection connection = CrmConnection.Parse(_connection.ConnectionString);

                using (_orgService = new OrganizationService(connection))
                {
                    Entity webResource = new Entity("webresource");
                    webResource["name"]            = prefix + name;
                    webResource["webresourcetype"] = new OptionSetValue(type);
                    if (!string.IsNullOrEmpty(displayName))
                    {
                        webResource["displayname"] = displayName;
                    }

                    if (type == 8)
                    {
                        webResource["silverlightversion"] = "4.0";
                    }

                    string content = File.ReadAllText(filePath);
                    webResource["content"] = EncodeString(content);

                    Guid id = _orgService.Create(webResource);

                    _logger.WriteToOutputWindow("New Web Resource Created: " + id, Logger.MessageType.Info);

                    //Add to the choosen solution (not default)
                    if (solutionId != new Guid("FD140AAF-4DF4-11DD-BD17-0019B9312238"))
                    {
                        AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest
                        {
                            ComponentType      = 61,
                            SolutionUniqueName = uniqueName,
                            ComponentId        = id
                        };
                        AddSolutionComponentResponse response =
                            (AddSolutionComponentResponse)_orgService.Execute(scRequest);

                        _logger.WriteToOutputWindow("New Web Resource Added To Solution: " + response.id, Logger.MessageType.Info);
                    }

                    NewId         = id;
                    NewType       = type;
                    NewName       = prefix + name;
                    NewBoudndFile = relativePath;

                    return(true);
                }
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                _logger.WriteToOutputWindow("Error Creating Web Resource: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, Logger.MessageType.Error);
                return(false);
            }
            catch (Exception ex)
            {
                _logger.WriteToOutputWindow("Error Creating Web Resource: " + ex.Message + Environment.NewLine + ex.StackTrace, Logger.MessageType.Error);
                return(false);
            }
        }