Example #1
0
        public AddPortalCodeRequest()
        {
            IncludeHtml       = true;
            IncludeCss        = true;
            IncludeJavaScript = true;

            var exportConfigs = AddPortalCodeConfiguration.GetExportConfigs();

            var typesToInclude = new List <PortalRecordsToExport>();

            foreach (var item in exportConfigs.OrderBy(c => c.RecordType))
            {
                typesToInclude.Add(new PortalRecordsToExport
                {
                    RecordType = new RecordType(item.RecordType, item.RecordType)
                });
            }
            RecordsToExport = typesToInclude;
        }
        public override void ExecuteExtention(AddPortalCodeRequest request, AddPortalCodeResponse response,
                                              ServiceRequestController controller)
        {
            var project = VisualStudioService.GetProject(request.ProjectName);

            var exportConfigs = AddPortalCodeConfiguration.GetExportConfigs()
                                .Where(c => request.IncludeType(c.RecordType))
                                .ToArray();
            var toDo = exportConfigs.Count();
            var done = 0;

            //okay so lets iterate the configurations
            //and for each item not null add somehting to the vs solution
            foreach (var config in exportConfigs)
            {
                controller.UpdateProgress(done++, toDo, "Exporting " + config.RecordType + " Code");
                var results = AddPortalCodeConfiguration.GetRecordsForConfig(config.RecordType, Service, request.WebSite.Id);
                results = request.FilterInclusionForType(config.RecordType, results);
                var toDo2 = results.Count();
                var done2 = 0;
                foreach (var result in results)
                {
                    ++done2;
                    if (config.RecordType == Entities.adx_webfile)
                    {
                        controller.UpdateLevel2Progress(done2, toDo2, $"Processing {done2}/{toDo2}");
                    }
                    var recordName           = result.GetStringField(Service.GetPrimaryField(config.RecordType));
                    var thisTypesFolderLabel = Service.GetDisplayName(config.RecordType);
                    var path = new List <string>();
                    if (request.CreateFolderForWebsiteName)
                    {
                        path.Add(request.WebSite.Name);
                    }
                    path.Add(thisTypesFolderLabel);
                    try
                    {
                        if (config.RecordType == Entities.adx_webfile)
                        {
                            var notes = Service.GetLinkedRecords(Entities.annotation, config.RecordType, Fields.annotation_.objectid, result.Id);
                            if (notes.Count() > 1)
                            {
                                throw new Exception("There is more than 1 note attached to the file. You will need to delete the excess notes to export");
                            }
                            else if (notes.Any() || request.ExportWhereFieldEmpty)
                            {
                                string fileContent = notes.Any()
                                    ? notes.First().GetStringField(Fields.annotation_.documentbody)
                                    : null;
                                if (fileContent != null)
                                {
                                    var data = Convert.FromBase64String(fileContent);
                                    fileContent = Encoding.UTF8.GetString(data);
                                }
                                var fileName = recordName;
                                if (IncludeExtention(request, fileName))
                                {
                                    project.AddItem(fileName, fileContent, path.ToArray());
                                }
                            }
                        }
                        else
                        {
                            foreach (var field in config.FieldsToExport)
                            {
                                var content = result.GetStringField(field.FieldName);
                                if (content != null || request.ExportWhereFieldEmpty)
                                {
                                    var fileExtention = field.Extention;
                                    var fileName      = recordName + "." + fileExtention;
                                    //https://superuser.com/questions/187469/how-would-i-go-about-creating-a-filename-with-invalid-characters-such-as
                                    // / -you can use a division symbol ∕
                                    // : -you can use the modifier letter colon ꞉
                                    fileName = fileName?.Replace("/", "∕");
                                    fileName = fileName?.Replace(":", "꞉");
                                    if (IncludeExtention(request, fileName))
                                    {
                                        project.AddItem(fileName, content, path.ToArray());
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        response.AddResponseItem(new AddPortalCodeResponseItem()
                        {
                            RecordType = config.RecordType, RecordName = recordName, Exception = ex
                        });
                    }
                }
                controller.TurnOffLevel2();
            }
            response.Message = "Export Completed";
        }
Example #3
0
        private void AddRecordsForSelectionInAddPortalRecords()
        {
            var customFunction = new OnChangeFunction((RecordEntryViewModelBase revm, string changedField) =>
            {
                switch (changedField)
                {
                case nameof(AddPortalCodeRequest.PortalRecordsToExport.IncludeAll):
                    {
                        if (!revm.GetBooleanFieldFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.IncludeAll)).Value)
                        {
                            var parentForm = revm.ParentForm;
                            if (parentForm == null)
                            {
                                throw new Exception("Cannot get parent form");
                            }
                            parentForm.LoadingViewModel.IsLoading = true;
                            revm.DoOnAsynchThread(() =>
                            {
                                try
                                {
                                    var recordType = revm.GetRecordTypeFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.RecordType)).Value?.Key;
                                    if (recordType == null)
                                    {
                                        throw new NullReferenceException($"Error {nameof(AddPortalCodeRequest.PortalRecordsToExport.RecordType)} is null");
                                    }
                                    var lookupService = revm.RecordService.LookupService;
                                    var websiteId     = parentForm.GetLookupFieldFieldViewModel(nameof(AddPortalCodeRequest.WebSite)).Value?.Id;
                                    if (websiteId == null)
                                    {
                                        revm.GetBooleanFieldFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.IncludeAll)).Value = true;
                                        revm.ApplicationController.UserMessage("Please Select The Website Before Selecting Records For Inclusion");
                                        return;
                                    }

                                    var results = AddPortalCodeConfiguration.GetRecordsForConfig(recordType, lookupService, websiteId);
                                    if (!results.Any())
                                    {
                                        revm.GetBooleanFieldFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.IncludeAll)).Value = true;
                                        revm.ApplicationController.UserMessage("Sorry There No Records Of This Type Were Identified For Selection");
                                    }
                                    else
                                    {
                                        var grid              = revm.GetEnumerableFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.RecordsToInclude));
                                        var nameField         = lookupService.GetPrimaryField(recordType);
                                        var itemsForSelection = results
                                                                .Select(r => new AddPortalCodeRequest.PortalRecordsToExport.SelectableRecordToInclude(r.Id, r.GetStringField(nameField)))
                                                                .ToArray();
                                        revm.GetFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.RecordsToInclude)).ValueObject = itemsForSelection;
                                        revm.OnPropertyChanged(nameof(AddPortalCodeRequest.PortalRecordsToExport.RecordsToInclude));

                                        //okay so lets autoload the multi select
                                        //if user has selected not to inlude all, then naturally they will have to select which specific ones
                                        //so lets save a click!
                                        grid.BulkAddButton.Invoke();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    revm.ApplicationController.ThrowException(ex);
                                }
                                finally
                                {
                                    parentForm.LoadingViewModel.IsLoading = false;
                                }
                            });
                        }
                        break;
                    }
                }
            });

            this.AddOnChangeFunction(customFunction, typeof(AddPortalCodeRequest.PortalRecordsToExport));
        }