Sebekerga / native_api_1c

Crate for simple implementation of Component for Native API 1C:Enterprise written in rust
https://crates.io/crates/native_api_1c
62 stars 13 forks source link

The property does not work #4

Closed Toveal closed 1 year ago

Toveal commented 1 year ago

Hello. I added a property to the example from the repository. The function works, the property does not

use native_api_1c::{native_api_1c_core::ffi::connection::Connection, native_api_1c_macro::AddIn};
use std::{
    fs::{metadata, File},
    io::Read,
    sync::Arc,
};

#[derive(AddIn)]
pub struct ByteReader {
    #[add_in_con] // соединение с 1С для вызова внешних событий
    connection: Arc<Option<&'static Connection>>, // Arc для возможности многопоточности

    #[add_in_func(name = "ReadBytes", name_ru = "ПрочитатьБайты")]
    #[arg(Str)]
    #[returns(Blob, result)]
    read_bytes: fn(&Self, String) -> Result<Vec<u8>, Box<dyn std::error::Error>>,

    #[add_in_prop(name = "TestProp", name_ru = "ТестПроп", readable, writable)]
    pub my_prop: i32,
}

impl ByteReader {
    pub fn new() -> Self {
        Self {
            connection: Arc::new(None),
            read_bytes: Self::read_bytes,
            my_prop: 230,
        }
    }

    pub fn read_bytes(&self, path: String) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
        let mut f = File::open(&path)?;
        let metadata = metadata(&path)?;
        let mut buffer = vec![0; metadata.len() as usize];
        f.read(&mut buffer)?;
        Ok(buffer)
    }
}

1C does not see the property and does not want to overwrite it Cleared the cache. Moved the processing to the configuration. Tried different platforms. Tried it on other PCs

Sebekerga commented 1 year ago

Hey!

  1. What version of crate do you use?
  2. Can you share part of your 1С code, that works with property?
  3. Can you try both Russian and English names of property?
Sebekerga commented 1 year ago

Alright, I checked and there was a bug, where name_ru option get's ignore, fixed it in main branch. You can get this fix if you change your dependency in Cargo.toml to this:

[dependencies]
#...
native_api_1c = { git = "https://github.com/Sebekerga/native_api_1c" }

And then run cargo update.

I'll push it as v0.10.4 to crates.io later too.

Toveal commented 1 year ago

Hey!

  1. What version of crate do you use?
  2. Can you share part of your 1С code, that works with property?
  3. Can you try both Russian and English names of property?
  1. 0.10.3
  2. InstallAddIn("CommonTemplate.ByteReader");
    
    If Not AttachAddIn("CommonTemplate.ByteReader", "MyAddin", AddInType.Native) Then
        Raise("Error");
        Return;       
    EndIf;
    
    ObjectAddin = New("Addin.MyAddin.ByteReader"); 
    Bytes = ObjectAddin.ReadBytes("E:\.gitignore");
    
    PropValueRu = ObjectAddin.ТестПроп;
    ObjectAddin.ТестПроп = 304;
    
    PropValueEn = ObjectAddin.TestProp;
    ObjectAddin.TestProp = 505;
  3. Yeah, I've tried both Russian names and English names.
Sebekerga commented 1 year ago

Nice! Thanks for detailed reportings :)

Sebekerga commented 1 year ago

@Toveal you can use 0.10.5 now instead of git