private void LoadDefault()
        {
            var config = DevKitCrmConfigHelper.GetDevKitCrmConfig(DTE);

            cboCrmVersion.Text = config.DefaultCrmVersion;
            cboNetVersion.Text = config.DefaultNetVersion;
        }
Esempio n. 2
0
 private void LoadConnections()
 {
     Config = DevKitCrmConfigHelper.GetDevKitCrmConfig(DTE);
     cboConnection.DataSource = Config.CrmConnections;
     cboConnection.Text       = Config.DefaultCrmConnection;
     btnOk.Enabled            = cboConnection.Items.Count > 0;
 }
Esempio n. 3
0
        private void btnConnect_Click(object sender, System.EventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            btnConnect.Enabled = false;
            Cursor             = Cursors.WaitCursor;
            var uri = new Uri(txtUrl.Text);
            var clientCredentials = new ClientCredentials();

            clientCredentials.UserName.UserName = txtUserName.Text;
            clientCredentials.UserName.Password = txtPassword.Text;
            CrmService = new OrganizationServiceProxy(uri, null, clientCredentials, null);
            var connected = false;

            try
            {
                var who = (WhoAmIResponse)CrmService.Execute(new WhoAmIRequest());
                connected = true;
            }
            catch
            {
                connected = false;
            }
            if (!connected)
            {
                MessageBox.Show("Something wrong with your connection. Please try it again");
                Cursor             = Cursors.Default;
                btnConnect.Enabled = true;
                CrmService         = null;
            }
            else
            {
                var config        = DevKitCrmConfigHelper.GetDevKitCrmConfig(DTE);
                var crmConnection = new CrmConnection
                {
                    Name     = txtName.Text,
                    Url      = txtUrl.Text,
                    UserName = txtUserName.Text,
                    Password = txtPassword.Text
                };
                if (config.CrmConnections == null)
                {
                    config.CrmConnections = new List <CrmConnection>();
                }
                config.CrmConnections.Add(crmConnection);
                config.DefaultCrmConnection = txtName.Text;
                DevKitCrmConfigHelper.SetDevKitCrmConfig(DTE, config);
                txtName.Text     = "";
                txtUrl.Text      = "http://???/XRMServices/2011/Organization.svc";
                txtUserName.Text = "";
                txtPassword.Text = "";
                LoadConnections();
                Cursor             = Cursors.Default;
                btnConnect.Enabled = true;
            }
        }
 private void btnDefaultNetVersion_Click(object sender, System.EventArgs e)
 {
     if (MessageBox.Show("Are you sure to make this default ?", "Confirm?", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         var config = DevKitCrmConfigHelper.GetDevKitCrmConfig(DTE);
         config.DefaultNetVersion = cboNetVersion.Text;
         DevKitCrmConfigHelper.SetDevKitCrmConfig(DTE, config);
     }
 }
Esempio n. 5
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            btnConnect.Enabled = false;
            Cursor             = Cursors.WaitCursor;
            bool connected;

            try
            {
                var uri = new Uri(txtUrl.Text);
                var clientCredentials = new ClientCredentials();
                clientCredentials.UserName.UserName = txtUserName.Text;
                clientCredentials.UserName.Password = txtPassword.Text;
                var crmService = new OrganizationServiceProxy(uri, null, clientCredentials, null);
                crmService.Execute(new WhoAmIRequest());
                connected = true;
            }
            catch
            {
                connected = false;
            }
            if (!connected)
            {
                MessageBox.Show(@"Something wrong with your connection. Please try it again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var crmConnection = new CrmConnection
                {
                    Name     = txtName.Text,
                    Url      = txtUrl.Text,
                    UserName = txtUserName.Text,
                    Password = EncryptDecrypt.EncryptString(txtPassword.Text)
                };
                if (Config.CrmConnections == null)
                {
                    Config.CrmConnections = new List <CrmConnection>();
                }
                Config.CrmConnections.Add(crmConnection);
                Config.DefaultCrmConnection = txtName.Text;
                DevKitCrmConfigHelper.SetDevKitCrmConfig(DTE, Config);
                txtName.Text     = "";
                txtUrl.Text      = @"http://???/XRMServices/2011/Organization.svc";
                txtUserName.Text = "";
                txtPassword.Text = "";
                LoadConnections();
            }
            Cursor             = Cursors.Default;
            btnConnect.Enabled = true;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (Check == "1")
            {
                var executingAssembly = Assembly.GetExecutingAssembly();
                var fInfo             = new System.IO.FileInfo(executingAssembly.Location);
                var checkFile         = $"{fInfo.Directory.FullName}\\Microsoft.Xrm.Tooling.Ui.Styles.dll";
                if (System.IO.File.Exists(checkFile))
                {
                    Assembly.LoadFrom(checkFile);
                }
                DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                Cursor = Cursors.WaitCursor;
                EnabledControl(false);

                CrmConnection = (CrmConnection)cboConnection.SelectedValue;
                var password = string.Empty;
                if (CrmConnection.Type != "ClientSecret")
                {
                    try
                    {
                        password = EncryptDecrypt.DecryptString(CrmConnection.Password);
                    }
                    catch
                    {
                        password = CrmConnection.Password;
                    }
                    CrmConnection.Password = password;
                }
                if (CanConnect(CrmConnection))
                {
                    if (CrmConnection.Type != "ClientSecret")
                    {
                        CrmConnection.Password = EncryptDecrypt.EncryptString(password);
                    }
                    Config.DefaultCrmConnection = cboConnection.Text;
                    DevKitCrmConfigHelper.SetDevKitCrmConfig(DTE, Config);
                    DialogResult = DialogResult.OK;
                    Cursor       = Cursors.Default;
                    Close();
                }
                else
                {
                    Cursor = Cursors.Default;
                    MessageBox.Show(@"Something wrong with your connection. Please try it again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                EnabledControl(true);
            }
        }
Esempio n. 7
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            DialogResult          = DialogResult.OK;
            btnOk.Enabled         = false;
            btnCancel.Enabled     = false;
            cboConnection.Enabled = false;
            txtName.Enabled       = false;
            txtUrl.Enabled        = false;
            txtUserName.Enabled   = false;
            txtPassword.Enabled   = false;
            btnConnect.Enabled    = false;
            CrmConnection         = (CrmConnection)cboConnection.SelectedValue;
            var uri = new Uri(CrmConnection.Url);
            var clientCredentials = new ClientCredentials();

            clientCredentials.UserName.UserName = CrmConnection.UserName;
            var password = string.Empty;

            try
            {
                password = EncryptDecrypt.DecryptString(CrmConnection.Password);
            }
            catch
            {
                password = CrmConnection.Password;
                CrmConnection.Password = EncryptDecrypt.EncryptString(password);
                DevKitCrmConfigHelper.SetDevKitCrmConfig(Dte, CrmConnection);
            }
            clientCredentials.UserName.Password = EncryptDecrypt.DecryptString(CrmConnection.Password);
            try
            {
                CrmService = new OrganizationServiceProxy(uri, null, clientCredentials, null);
            }
            catch
            {
                MessageBox.Show(@"Something wrong with your connection. Please try it again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Config.DefaultCrmConnection = cboConnection.Text;
            DevKitCrmConfigHelper.SetDevKitCrmConfig(Dte, Config);

            Close();
        }
Esempio n. 8
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            EnabledControl(false);

            CrmConnection = (CrmConnection)cboConnection.SelectedValue;
            var password = string.Empty;

            if (CrmConnection.Type != "ClientSecret")
            {
                try
                {
                    password = EncryptDecrypt.DecryptString(CrmConnection.Password);
                }
                catch
                {
                    password = CrmConnection.Password;
                }
                CrmConnection.Password = password;
            }
            if (CanConnect(CrmConnection))
            {
                if (CrmConnection.Type != "ClientSecret")
                {
                    CrmConnection.Password = EncryptDecrypt.EncryptString(password);
                }
                Config.DefaultCrmConnection = cboConnection.Text;
                DevKitCrmConfigHelper.SetDevKitCrmConfig(DTE, Config);
                DialogResult = DialogResult.OK;
                Cursor       = Cursors.Default;
                Close();
            }
            else
            {
                Cursor = Cursors.Default;
                MessageBox.Show(@"Something wrong with your connection. Please try it again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            EnabledControl(true);
        }
Esempio n. 9
0
        private void SaveConnection()
        {
            var crmConnection = new CrmConnection
            {
                Name     = txtName.Text,
                Url      = txtUrl.Text,
                UserName = txtUserName.Text,
                Password = txtPassword.Text,
                Type     = cboType.Text,
            };

            if (crmConnection.Type != "ClientSecret")
            {
                crmConnection.Password = EncryptDecrypt.EncryptString(crmConnection.Password);
            }
            if (Config.CrmConnections == null)
            {
                Config.CrmConnections = new List <CrmConnection>();
            }
            Config.CrmConnections.Add(crmConnection);
            Config.DefaultCrmConnection = txtName.Text;
            DevKitCrmConfigHelper.SetDevKitCrmConfig(DTE, Config);
        }
Esempio n. 10
0
        private static void ExecuteWebResource(AsyncPackage package)
        {
            Dte.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
            var activeDocument      = Dte.ActiveDocument;
            var solutionFullName    = Dte.Solution.FullName;
            var fInfo               = new FileInfo(solutionFullName);
            var devKitCrmConfigFile = $"{fInfo.DirectoryName}\\PL.DynamicsCrm.DevKit.json";

            Dte.StatusBar.Text = "Reading PL.DynamicsCrm.DevKit.json config";
            if (Config == null)
            {
                Config = DevKitCrmConfigHelper.GetDevKitCrmConfig(Dte);
            }
            var defaultConnection = Config.CrmConnections.Where(conn => conn.Name == Config.DefaultCrmConnection).FirstOrDefault();

            Dte.StatusBar.Text = "Connecting to Dynamics 365";
            if (defaultConnection == null)
            {
                Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                Dte.StatusBar.Text = "   !!! Connection to Dynamics 365 failed   !!!   ";
                MessageBox.Show("Default Crm connection not found!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (Config.SolutionPrefix == null)
            {
                Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                Dte.StatusBar.Text = "   !!! Connection to Dynamics 365 failed   !!!   ";
                MessageBox.Show("PL.DynamicsCrm.DevKit.json config not found SolutionPrefix data", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var check = SharedGlobals.GetGlobal("CrmService", Dte);

            if (check == null)
            {
                try
                {
                    var uri = new Uri(defaultConnection.Url);
                    var clientCredentials = new ClientCredentials();
                    clientCredentials.UserName.UserName = defaultConnection.UserName;
                    clientCredentials.UserName.Password = TryDecryptPassword(defaultConnection.Password);
                    check = new OrganizationServiceProxy(uri, null, clientCredentials, null);
                    SharedGlobals.SetGlobal("CrmService", check, Dte);
                }
                catch
                {
                    Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                    Dte.StatusBar.Text = "   !!! Connection to Dynamics 365 fail   !!!   ";
                    MessageBox.Show("Connection to Dynamics 365 fail!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            var crmService = (OrganizationServiceProxy)SharedGlobals.GetGlobal("CrmService", Dte);

            Dte.StatusBar.Text = "   !!!   Connected Dynamics 365  !!!   ";
            var fileName  = activeDocument.FullName;
            var parts     = fileName.Split("\\".ToCharArray());
            var condition = string.Empty;

            for (var i = 1; i < parts.Length; i++)
            {
                var value = $"{Config.SolutionPrefix}/{parts[i]}/";
                for (var j = i + 1; j < parts.Length; j++)
                {
                    value += $"{parts[j]}/";
                }
                if (value.EndsWith("/"))
                {
                    value = value.TrimEnd("/".ToCharArray());
                }
                if (value.StartsWith("/"))
                {
                    value = value.Substring(1);
                }
                condition += $"<condition attribute='name' operator='ends-with' value='{value}'/>";
            }
            var fetchXml = $@"
<fetch>
  <entity name='webresource'>
    <attribute name='name' />
    <filter type='or'>
      {condition}
    </filter>
  </entity>
</fetch>";
            var rows     = crmService.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                Dte.StatusBar.Text = "   !!!   WebResource not found   !!!   ";
                MessageBox.Show("WebResource not found!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var webResourceId = rows.Entities[0].Id;

            try
            {
                var emRequest = new ExecuteMultipleRequest
                {
                    Requests = new OrganizationRequestCollection(),
                    Settings = new ExecuteMultipleSettings
                    {
                        ContinueOnError = false,
                        ReturnResponses = true
                    }
                };
                var requests    = new OrganizationRequestCollection();
                var publishXml  = "<importexportxml><webresources>";
                var webResource = new Entity("webresource")
                {
                    Id = webResourceId
                };
                var content = File.ReadAllText(fileName);
                webResource["content"] = EncodeString(content);
                var request = new UpdateRequest {
                    Target = webResource
                };
                requests.Add(request);
                publishXml += "<webresource>{" + webResource.Id + "}</webresource>";
                publishXml += "</webresources></importexportxml>";
                var pubRequest = new PublishXmlRequest {
                    ParameterXml = publishXml
                };
                requests.Add(pubRequest);
                emRequest.Requests = requests;
                Dte.StatusBar.Text = "Updating & publishing WebResource ... ";
                var emResponse = (ExecuteMultipleResponse)crmService.Execute(emRequest);
                var wasError   = false;
                foreach (var responseItem in emResponse.Responses)
                {
                    if (responseItem.Fault == null)
                    {
                        continue;
                    }
                    wasError = true;
                }
                if (wasError)
                {
                    Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                    Dte.StatusBar.Text = "   !!!   Deploy WebResource failed   !!!   ";
                    MessageBox.Show("Deploy WebResource failed.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                    Dte.StatusBar.Text = "   !!!   Deploy WebResource succeeded   !!!   ";
                    return;
                }
            }
            catch (FaultException <OrganizationServiceFault> )
            {
                Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                Dte.StatusBar.Text = "   !!!   Deploy WebResource failed   !!!   ";
                MessageBox.Show("Deploy WebResource failed.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            catch
            {
                Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                Dte.StatusBar.Text = "   !!!   Deploy WebResource failed   !!!   ";
                MessageBox.Show("Deploy WebResource failed.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Esempio n. 11
0
        private static void BuildEvents_OnBuildProjConfigDone(string Project, string ProjectConfig, string Platform, string SolutionConfig, bool Success)
        {
            Dte.Events.BuildEvents.OnBuildProjConfigDone -= BuildEvents_OnBuildProjConfigDone;
            if (!Success || !ProjectUniqueName.EndsWith(Project))
            {
                return;
            }
            Dte.StatusBar.Text = "Build project report succeeded!";
#if DEBUG
            ProjectUniqueName = @"C:\src\github\phuocle\Dynamics-Crm-DevKit\test\TestReport\Test.Abc.Report.2015\Test.Abc.Report.2015.rptproj";
#endif
            var xml  = File.ReadAllText(ProjectUniqueName);
            var xdoc = XDocument.Parse(xml);
            //Fist check for project VS2015
            var node = (from x in xdoc?.Descendants("Project")?.Descendants("Configurations")?.Elements("Configuration")
                        where x?.Element("Name")?.Value == ProjectConfig
                        select x)?.FirstOrDefault();
            var outputPath = node?.Descendants("Options")?.FirstOrDefault()?.Element("OutputPath")?.Value;
            //if null, then check for project VS2017
            if (outputPath == null)
            {
                var nodes = (from x in xdoc?.Root.Elements()
                             where x?.Name?.LocalName == "PropertyGroup"
                             select x);
                foreach (var n in nodes)
                {
                    if (n.Elements().Where(x => x?.Name?.LocalName == "FullPath" && x?.Value == "Debug").Any())
                    {
                        outputPath = n.Elements().Where(x => x?.Name?.LocalName == "OutputPath").FirstOrDefault()?.Value;
                        break;
                    }
                }
            }
            if (outputPath == null)
            {
                throw new Exception("Cannot read the Output directory of the current report project");
            }
            var folderOutput = Path.Combine(Path.GetDirectoryName(ProjectUniqueName), outputPath);
            var fileName     = Path.GetFileName(Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]);
            var deployFile   = Path.Combine(folderOutput, fileName);
            if (!File.Exists(deployFile))
            {
                throw new Exception($"Cannot find deployable report: {deployFile}");
            }
            Dte.StatusBar.Text = "Connecting to Dynamics 365";
            var check = SharedGlobals.GetGlobal("CrmService", Dte);
            if (check == null)
            {
                var activeDocument      = Dte.ActiveDocument;
                var solutionFullName    = Dte.Solution.FullName;
                var fInfo               = new FileInfo(solutionFullName);
                var devKitCrmConfigFile = $"{fInfo.DirectoryName}\\PL.DynamicsCrm.DevKit.json";
                Dte.StatusBar.Text = "Reading PL.DynamicsCrm.DevKit.json config";
                if (Config == null)
                {
                    Config = DevKitCrmConfigHelper.GetDevKitCrmConfig(Dte);
                }
                var defaultConnection = Config.CrmConnections.Where(conn => conn.Name == Config.DefaultCrmConnection).FirstOrDefault();
                if (defaultConnection == null)
                {
                    Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                    Dte.StatusBar.Text = "   !!! Connection to Dynamics 365 failed   !!!   ";
                    MessageBox.Show("Default Crm connection not found!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                try
                {
                    var uri = new Uri(defaultConnection.Url);
                    var clientCredentials = new ClientCredentials();
                    clientCredentials.UserName.UserName = defaultConnection.UserName;
                    clientCredentials.UserName.Password = TryDecryptPassword(defaultConnection.Password);
                    check = new OrganizationServiceProxy(uri, null, clientCredentials, null);
                    SharedGlobals.SetGlobal("CrmService", check, Dte);
                    Dte.StatusBar.Text = "   !!!   Connected Dynamics 365  !!!   ";
                }
                catch
                {
                    Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                    Dte.StatusBar.Text = "   !!! Connection to Dynamics 365 failed   !!!   ";
                    MessageBox.Show("Connecting to Dynamics 365 failed!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                Dte.StatusBar.Text = "   !!!   Connected Dynamics 365   !!!   ";
            }
            var crmService = (OrganizationServiceProxy)SharedGlobals.GetGlobal("CrmService", Dte);
            var fetchData  = new
            {
                ismanaged = "0",
                filename  = fileName
            };
            var fetchXml = $@"
<fetch>
  <entity name='report'>
    <attribute name='reportid' />
    <filter type='and'>
      <condition attribute='ismanaged' operator='eq' value='{fetchData.ismanaged/*0*/}'/>
      <condition attribute='filename' operator='eq' value='{fetchData.filename/*ReportTemplate.rdl*/}'/>
    </filter>
  </entity>
</fetch>";
            var rows     = crmService.RetrieveMultiple(new FetchExpression(fetchXml));
            if (rows.Entities.Count == 0)
            {
                throw new Exception("Please deploy this report first by Dynamics 365");
            }
            if (rows.Entities.Count != 1)
            {
                throw new Exception($"Found {rows.Entities.Count} reports file name: {fileName} in the system. Cannot deploy.");
            }
            Dte.StatusBar.Text = "Deploying Report ...";
            var update = new Entity("report", rows.Entities[0].Id);
            update["bodytext"] = File.ReadAllText(deployFile);
            crmService.Update(update);
            Dte.StatusBar.Text = "   !!!   Deploy Report succeeded   !!!   ";
            Dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
        }
Esempio n. 12
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var dte = (EnvDTE.DTE) this.ServiceProvider.GetService(typeof(EnvDTE.DTE));

            dte.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
            var activeDocument      = dte.ActiveDocument;
            var solutionFullName    = dte.Solution.FullName;
            var fInfo               = new FileInfo(solutionFullName);
            var devKitCrmConfigFile = $"{fInfo.DirectoryName}\\PL.DynamicsCrm.DevKit.json";

            dte.StatusBar.Text = "Read PL.DynamicsCrm.DevKit.json config";
            var config            = DevKitCrmConfigHelper.GetDevKitCrmConfig(dte);
            var defaultConnection = config.CrmConnections.Where(conn => conn.Name == config.DefaultCrmConnection).FirstOrDefault();

            if (defaultConnection == null)
            {
                ShowError("Default Crm connection not found!");
                goto CLEAR_STATUS;
            }
            if (string.IsNullOrEmpty(config.SolutionPrefix))
            {
                ShowError("PL.DynamicsCrm.DevKit.json config not found SolutionPrefix data");
                goto CLEAR_STATUS;
            }
            dte.StatusBar.Text = "Connecting ...";
            var check = SharedGlobals.GetGlobal("CrmService", dte);

            if (check == null)
            {
                try
                {
                    var uri = new Uri(defaultConnection.Url);
                    var clientCredentials = new ClientCredentials();
                    clientCredentials.UserName.UserName = defaultConnection.UserName;
                    clientCredentials.UserName.Password = defaultConnection.Password;
                    check = new OrganizationServiceProxy(uri, null, clientCredentials, null);
                    SharedGlobals.SetGlobal("CrmService", check, dte);
                }
                catch
                {
                    ShowError("Connecting Fail!");
                    goto CLEAR_STATUS;
                }
            }
            var crmService = (OrganizationServiceProxy)SharedGlobals.GetGlobal("CrmService", dte);

            dte.StatusBar.Text = "Connected ...";

            var fileName  = activeDocument.FullName;
            var parts     = fileName.Split("\\".ToCharArray());
            var condition = string.Empty;

            for (var i = 1; i < parts.Length; i++)
            {
                var value = $"{config.SolutionPrefix}/{parts[i]}/";
                for (var j = i + 1; j < parts.Length; j++)
                {
                    value += $"{parts[j]}/";
                }
                if (value.EndsWith("/"))
                {
                    value = value.TrimEnd("/".ToCharArray());
                }
                condition += $"<condition attribute='name' operator='ends-with' value='{value}'/>";
            }
            var fetchXml = $@"
<fetch>
  <entity name='webresource'>
    <attribute name='name' />
    <filter type='or'>
      {condition}
    </filter>
  </entity>
</fetch>";
            var rows     = crmService.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                ShowError("Web resource not found!");
                goto CLEAR_STATUS;
            }
            var webResourceId = rows.Entities[0].Id;

            try
            {
                ExecuteMultipleRequest emRequest = new ExecuteMultipleRequest
                {
                    Requests = new OrganizationRequestCollection(),
                    Settings = new ExecuteMultipleSettings
                    {
                        ContinueOnError = false,
                        ReturnResponses = true
                    }
                };
                OrganizationRequestCollection requests = new OrganizationRequestCollection();
                string publishXml  = "<importexportxml><webresources>";
                Entity webResource = new Entity("webresource")
                {
                    Id = webResourceId
                };
                string content = File.ReadAllText(fileName);
                webResource["content"] = EncodeString(content);
                UpdateRequest request = new UpdateRequest {
                    Target = webResource
                };
                requests.Add(request);
                publishXml += "<webresource>{" + webResource.Id + "}</webresource>";
                publishXml += "</webresources></importexportxml>";
                PublishXmlRequest pubRequest = new PublishXmlRequest {
                    ParameterXml = publishXml
                };
                requests.Add(pubRequest);
                emRequest.Requests = requests;
                dte.StatusBar.Text = "Updating & publishing web resource...";

                ExecuteMultipleResponse emResponse = (ExecuteMultipleResponse)crmService.Execute(emRequest);
                bool wasError = false;
                foreach (var responseItem in emResponse.Responses)
                {
                    if (responseItem.Fault == null)
                    {
                        continue;
                    }
                    wasError = true;
                }
                if (wasError)
                {
                    ShowError("Error Updating And Publishing Web Resources To CRM. See the Output Window for additional details.");
                    goto CLEAR_STATUS;
                }
                else
                {
                    dte.StatusBar.Text = "Updated And Published Web Resource";
                    goto CLEAR_STATUS;
                }
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                ShowError("Error Updating And Publishing Web Resource To CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace);
                goto CLEAR_STATUS;
            }
            catch (Exception ex)
            {
                ShowError("Error Updating And Publishing Web Resource To CRM: " + ex.Message + Environment.NewLine + ex.StackTrace);
            }
CLEAR_STATUS:
            dte.StatusBar.Clear();
            dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
        }