Exemple #1
0
        private void OpenCreateWebResourceForm()
        {
            var path   = ProjectHelper.GetSelectedFilePath();
            var dialog = new CreateWebResourceForm(path);

            dialog.ShowDialog();
        }
        private async void OpenCreateWebResourceFormAsync()
        {
            var settings = await SettingsService.Instance.GetSettingsAsync();

            var project = await projectHelper.GetSelectedProjectAsync();

            var path = await projectHelper.GetSelectedFilePathAsync();

            var dialog = new CreateWebResourceForm(path, settings.SelectedConnection.SelectedSolution.PublisherPrefix);

            dialog.OnCreate = async(Entity webResource) =>
            {
                var connectionDetail = settings.SelectedConnection;
                if (connectionDetail.SelectedSolution.SolutionId == null)
                {
                    throw new ArgumentNullException("SolutionId");
                }
                WebRequest.GetSystemWebProxy();
                var service = await connectionDetail.GetCrmServiceClientAsync();

                var webresourceName = webResource["name"] as String;
                if (await this.IsResourceExistsAsync(service, webresourceName))
                {
                    MessageBox.Show("Webresource with name '" + webresourceName + "' already exist in CRM.", "Webresource already exists.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                try
                {
                    Cursor.Current = Cursors.Arrow;
                    var isMappingRequired = await mappingHelper.IsMappingRequiredAsync(project, path, webresourceName);

                    var isMappingFileReadOnly = mappingHelper.IsMappingFileReadOnly(project);
                    if (isMappingRequired && isMappingFileReadOnly)
                    {
                        var message = "Mapping record can't be created. File \"UploaderMapping.config\" is read-only. Do you want to proceed? \r\n\r\n" +
                                      "Schema name of the web resource you are creating is differ from the file name. " +
                                      "Because of that new mapping record has to be created in the file \"UploaderMapping.config\". " +
                                      "Unfortunately the file \"UploaderMapping.config\" is read-only (file might be under a source control), so mapping record cant be created. \r\n\r\n" +
                                      "Press OK to proceed without mapping record creation (You have to do that manually later). Press Cancel to fix problem and try later.";
                        var result = MessageBox.Show(message, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                        if (result == DialogResult.Cancel)
                        {
                            return;
                        }
                    }
                    if (isMappingRequired && !isMappingFileReadOnly)
                    {
                        mappingHelper.CreateMapping(project, path, webresourceName);
                    }
                    //TODO: Check solution name
                    this.CreateWebResource(service, webResource, settings.SelectedConnection.SelectedSolution.UniqueName);
                    await Logger.WriteLineAsync("Webresource '" + webresourceName + "' was successfully created");

                    dialog.Close();
                }
                catch (Exception ex)
                {
                    Cursor.Current = Cursors.Arrow;
                    MessageBox.Show("An error occured during web resource creation: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            };
            dialog.ShowDialog();
        }