PDA

View Full Version : سوال: کار با کلاس Sytem.addin در دات نت 3.5 به بالا و ایجاد برنامه های توسعه پذیر



john smithair
جمعه 23 تیر 1391, 19:02 عصر
سلام دوستان
من یک چند وقتی هست که میخوام یک برنامه توسعه پذیر با استفاده از کلاس system.addin و یا به عبارت بهتر با استفاده از فریم ورک maf ایجاد کنم. msdn و خیلی از سایت ها رو زیر و رو کردم اطلاعات مفیدی بدست اوردم ولی نمونه یا آموزشی که بتونم باهاش یک برنامه درست کنم که run شه پیدا نکردم. خیلی حیاتی و مهمه برام. کسی هست که بتونه بهم کمک کنه، یک آموزشی، کتابی، نمونه کدی یا حتی تجربیاتشون.
با تشکر

tooraj_azizi_1035
جمعه 23 تیر 1391, 20:20 عصر
سلام
دقیقاً چه برنامه ای می خوای بنویسی مثال Calculator رو تو MSDN اگه دیده باشی مثال خوبی هست.

john smithair
جمعه 23 تیر 1391, 23:21 عصر
سلام
ممنون که پاسخ دادید.
من باید یه نمونه برنامه توسعه پذیر با استفاده از این فریم ورک بنویسم. مهم نیست چی باشه. یه جورایی برای معرفی این فریم ورک. ولی خب خودم باید اول یادش بگیرم.
من یه مثال calculator تو msdn رو دیدم ولی فکر کنم که اون با استفاد از تکنولوژی mef بود نه maf. برای maf یه مثال خیلی پیچیده تر بود که همه اش رو هم نوشتم ولی نتونستم باز کامپایلش کنم.:ناراحت:

john smithair
شنبه 24 تیر 1391, 10:36 صبح
سلام
دوستان کسی نیست که کمک کنه؟
من تو تالار هم یه سرچی زدم اما مطالب همه خیلی قدیمی بود و کسی هم در اون پست ها به صحبت راحع به این فریم ورک نپرداخته بود همه راه حل های خیلی سخت تری رو پیش رو گرفته بودن. اگه کسی تا حالا کار کرده کمک کنه خیلی ممنون میشم.

tooraj_azizi_1035
شنبه 24 تیر 1391, 11:41 صبح
یک همچین مدلی برای ارتباط برنامه Host و Add-In وجود دارد:

http://i.msdn.microsoft.com/dynimg/IC49383.png

سوالت مربوط به بحث Pipeline Development هست آیا این منبع کافیه؟ http://msdn.microsoft.com/en-us/library/bb384201.aspx

john smithair
شنبه 24 تیر 1391, 17:13 عصر
این مطالب رو همه رو خوندم. یه مثالی حالا پیدا کردم ببینم میتونم با اونا کار کنم یا نه. باز اگه منبع یا مثال خوبی داشتید ممنون میشم که بزارید.
با تشکر

john smithair
یک شنبه 25 تیر 1391, 11:51 صبح
خیلی ممنون از کمکاتون تا اینجا
من دو تا سوال دیگه هم برام پیش اومده که اگه کمک کنید خیلی ممنون میشم.:لبخندساده:
الان تو این فریم ورک maf هنگام فعال کردن یه addin باید براش یک سطح امنیتی مشخص کنیم که مثلا internet، interanet،host و فکر کنم یکی یا دو تا سطح دیگه هم داره. که من اصلا نمیفهمم این سطوح امنیتی برای چیه؟:افسرده: کسی میدونه اینا برای چیه؟
یکی دیگه ام اینکه این فریم ورک یه چیزی داره به اسم lifetime management که من اصلا نمیفهمم برای چیه؟ اگر کسی یه توضیحی بده که این برا چیه خیلی ممنون میشم.
با تشکر از لطف همه!!

tooraj_azizi_1035
یک شنبه 25 تیر 1391, 13:02 عصر
Security Level برمی گرده به Permission ها یا مجوز هایی که یک Assembly در دات نت اجازه دستیابی به اونها رو دارد که از CAS (Code Access Security) تنظیم میشه.
سطوح ممکن:
Host: یعنی Addin مربوطه همون مجوز هایی رو داره که Host داره.

ببخشید می خوام خود متن اصلی رو بذارم:
Internet: Use the Internet security level for add-ins that have a low trust level.
Intranet: Use the Intranet security level for add-ins that are located on a company's intranet. These add-ins can have a greater trust level because the servers and information are within a company's firewall.
FullTrust: Use the full trust security level for add-ins that are allowed to read and write to the local file system, create network connections, and read from the registry. This security level grants full access to the add-in's code access security (CAS) by applying the Unrestricted (http://msdn.microsoft.com/en-us/library/system.security.permissions.permissionstate.aspx) field.
Host: Use the host security level to give the add-in the same permissions currently granted to the hosting code. This setting has two purposes:


It represents the maximum permission set a host can grant to its add-ins.
It allows a ClickOnce or an Extensible Application Markup Language (XAML) Browser Application (XBAP) host to propagate its site of origin to its add-ins, which enables them to contact the server.

tooraj_azizi_1035
یک شنبه 25 تیر 1391, 13:08 عصر
و lifetime management بر می گرده به مفهوم حضور Addin در حافظه.
ببین صرف ترجمه این متن من یکی که نمی تونم متوجه منظور نویسنده بشم اگه کسی می تونه این متن رو شرح بده:


Lifetime Management


The add-in model's remoting capabilities complicate lifetime management. Because garbage collection does not adequately support reclaiming objects in multiple application domains, the add-in model provides its own system of lifetime management. This management system uses a reference-counting system and the common language runtime's remoting services.
The add-in model's lifetime management system can span multiple application domains and isolated processes to make sure that objects, contracts, and add-ins are disposed and their application domains are unloaded. The system does this by maintaining a token handle (ContractHandle (http://msdn.microsoft.com/en-us/library/system.addin.pipeline.contracthandle.aspx)) to the add-in during the time that the add-in services a call from the host.

Lifetime Management Implementation


To implement lifetime management, you must acquire a lifetime token whenever a contract is used in a contract-to-view adapter and then revoke the lifetime token when the adapter is finished with it. The ContractHandle (http://msdn.microsoft.com/en-us/library/system.addin.pipeline.contracthandle.aspx) class does this work for you if you use it in your adapters. If your pipeline passes custom types, you must acquire the token handle in all contract-to-view adapter classes that you implement. For more information about contract-to-view adapters, see Contracts, Views, and Adapters (http://msdn.microsoft.com/en-us/library/bb384205.aspx).
The ContractHandle (http://msdn.microsoft.com/en-us/library/system.addin.pipeline.contracthandle.aspx) class takes the contract as its constructor. The following example shows how to set the lifetime token handle in a host-side adapter.
http://i.msdn.microsoft.com/areas/global/content/clear.gif Important The ContractHandle (http://msdn.microsoft.com/en-us/library/system.addin.pipeline.contracthandle.aspx) is critical to lifetime management. If you fail to keep a reference to the ContractHandle (http://msdn.microsoft.com/en-us/library/system.addin.pipeline.contracthandle.aspx) object, garbage collection will reclaim it, and the pipeline will shut down when your program does not expect it. This can lead to errors that are difficult to diagnose, such as AppDomainUnloadedException (http://msdn.microsoft.com/en-us/library/system.appdomainunloadedexception.aspx). Shutdown is a normal stage in the life of a pipeline, so there is no way for the lifetime management code to detect that this condition is an error.


private CalculatorContracts.ICalc2Contract _contract;

private System.AddIn.Pipeline.ContractHandle _handle;

public CalculatorContractToViewHostAdapter(ICalc2Contract contract) {
_contract = contract;
_handle = new System.AddIn.Pipeline.ContractHandle(contract);
}


Once you acquire the token handle, the system takes care of all lifetime management functions and requires no additional programming.
Under the add-in model, the host and add-ins operate as if their own lifetime management was controlled by the garbage collector. Their local references get disposed and that causes any remote references to be disposed and collected.

john smithair
یک شنبه 25 تیر 1391, 15:02 عصر
toorj جان خیلی ممنون از توجه و کمکت.
آره من هم این متن انگلیسی رو دیدم ولی مثل شما اصلا منظور نویسنده ارو متوجه نشدم. اگر کسی متوجه میشه کمک کنه خیلی خوب میشه.
بعد فقط یه کم میشه راجع به اون مبحث اول که گفتی:

مجوز هایی که یک Assembly در دات نت اجازه دستیابی به اونها رو دارد که از CAS (Code Access Security) تنظیم میشه.
یه کم توضیح بدی؟
من کلا اطلاعات زیادی راجع به اسمبلی ها تو دات نت ندارم چه برسه به سطوح دسترسی شون.
خیلی خیلی ممنون!

tooraj_azizi_1035
یک شنبه 25 تیر 1391, 17:43 عصر
خب موضوع بر می گرده به Code Access Security.
می دونی هر کسی می تونه متن MSDN رو ترجمه کنه نهایتش از Babylon کمک می گیره اما موضوع اینه که باید دقیقاً فهمید نویسنده چه منظوری داره که سخت ترین جای کار همینه.
به ناچار مجبورم هر چی از این لینک فهمیدم برات بذارم: http://msdn.microsoft.com/en-us/library/930b76w0%28v=vs.71%29.aspx

هنگامی که یک Application اجرا میشه توسط runtime's security system مجوزهایی به اون برنامه داده میشه. به تبع اون برنامه یا درست اجرا میشه یا یک SecurityException تولید میشه. این Exception به این خاطر تولید میشه که برنامه در حال اجرا سعی داره کاری رو انجام بده که مجوز اون رو نداره مثل اجرای یک script یا دسترسی به منبعی که مجوزش رو نداره. در دنیای برنامه نویسی Unmanaged هست که هیچ نگرانی در مورد مجوز ها وجود نداره.

این همش نبود باید بیشتر مطالعه کنم.