def _produce_asm_file(extension): # unique assembly filename for this package ext_asm_fileid = _make_ext_asm_fileid(extension) ext_asm_file_path = appdata.get_data_file(file_id=ext_asm_fileid, file_ext=ASSEMBLY_FILE_TYPE) # make unique assembly name for this package ext_asm_file_name = get_file_name(ext_asm_file_path) if _is_pyrevit_ext_already_loaded(ext_asm_file_name): logger.debug('Extension assembly is already loaded: {}'.format(ext_asm_file_name)) _update_component_cmd_types(extension) return ExtensionAssemblyInfo(ext_asm_file_name, ext_asm_file_path, True) elif appdata.is_data_file_available(file_id=ext_asm_fileid, file_ext=ASSEMBLY_FILE_TYPE): logger.debug('Extension assembly file already exists: {}'.format(ext_asm_file_path)) try: loaded_assm = load_asm_file(ext_asm_file_path) for asm_name in loaded_assm.GetReferencedAssemblies(): logger.debug('Checking referenced assembly: {}'.format(asm_name)) ref_asm_file_path = appdata.is_file_available(file_name=asm_name.Name, file_ext=ASSEMBLY_FILE_TYPE) if ref_asm_file_path: logger.debug('Loading referenced assembly: {}'.format(ref_asm_file_path)) try: load_asm_file(ref_asm_file_path) except Exception as load_err: logger.error('Error loading referenced assembly: {} | {}'.format(ref_asm_file_path, load_err)) _update_component_cmd_types(extension) return ExtensionAssemblyInfo(ext_asm_file_name, ext_asm_file_path, False) except Exception as ext_asm_load_err: logger.error('Error loading extension assembly: {} | {}'.format(ext_asm_file_path, ext_asm_load_err)) else: return _create_asm_file(extension, ext_asm_file_name, ext_asm_file_path)
def _get_csharp_cmd_asm(cmd_component): """ Args: cmd_component (pyrevit.extensions.genericcomps.GenericUICommand): Returns: """ script_path = cmd_component.get_full_script_address() source = read_source_file(script_path) script_hash = get_str_hash(source)[:HASH_CUTOFF_LENGTH] command_assm_file_id = '{}_{}'\ .format(script_hash, cmd_component.unique_name) # check to see if compiled c# command assembly is already loaded compiled_assm_list = find_loaded_asm(command_assm_file_id, by_partial_name=True) if len(compiled_assm_list) > 0: return compiled_assm_list[0] # if not already loaded, check to see if the assembly file exits compiled_assm_path = \ appdata.is_data_file_available(file_id=command_assm_file_id, file_ext=ASSEMBLY_FILE_TYPE) if compiled_assm_path: return load_asm_file(compiled_assm_path) # else, let's compile the script and make the types command_assm_file = \ appdata.get_data_file(file_id=command_assm_file_id, file_ext=ASSEMBLY_FILE_TYPE) logger.debug('Compiling script {} to {}'.format(cmd_component, command_assm_file)) compiled_assm_path = compile_csharp([script_path], command_assm_file, reference_list=_get_references()) return load_asm_file(compiled_assm_path)
def _get_base_classes_asm(): if appdata.is_data_file_available(file_id=BASE_TYPES_ASM_FILE_ID, file_ext=ASSEMBLY_FILE_TYPE): return load_asm_file(BASE_TYPES_ASM_FILE) else: return _generate_base_classes_asm()
def _get_runtime_asm(): if appdata.is_data_file_available(file_id=RUNTIME_ASSM_FILE_ID, file_ext=framework.ASSEMBLY_FILE_TYPE): return assmutils.load_asm_file(RUNTIME_ASSM_FILE) else: return _generate_runtime_asm()