نظرات مطالب
Defensive Programming - بازگشت نتایج قابل پیش بینی توسط متدها
باید عرض کنم بله وقتی کاربری یافت نشد چه کاری می‌توانیم انجام دهیم؟ 
مطلب پایه‌ای در مورد صدور استثناءها در اینجا هست: Dont Use Exceptions For Flow Control و قسمتی از آن به این صورت است:
 Errors should be handled via exceptions, but successes shouldn't
 مشکلی که در اینجا هست این است که بازگشت null یک کاربر در یک کوئری، یک error نیست؛ یک بازگشت و عملیات موفقیت آمیز است. به همین جهت صدور استثناء برای دریافت آن نباید رخ دهد:  
The typical meaning of the word "exception" is an event that is unexpected rather than part of normal operation; otherwise people would just say "event" 
و اینکه نتیجه‌ی یک متد باید در همان متد به صورت استثناء درنظر گرفته شود، غیرضروری است و این تصمیم گیری باید به عهده‌ی فراخوان گذاشته شود. گاهی می‌خواهیم بررسی کنیم کاربری در دیتابیس هست؟ اگر بله، آ‌‌ن‌را تکراری ثبت نکنیم. گاهی می‌خواهیم بررسی کنیم اگر در دیتابیس هست، اطلاعات او را به روز رسانی کنیم. اینکه کوئری مدنظر نال بر می‌گرداند، تصمیم گیری در مورد اهمیت آن ربطی به آن متد ندارد و صرفا به عهده‌ی فراخوان است:
Methods should have a way to indicate various kinds of results. Whether those results are treated as exceptional should depend on the caller.  
اشتراک‌ها
کتابخانه jQuery-Responsive-Multi-Level-Menu-Plugin-Dlmenu با افکت های زیبا

An extremely simple and responsive jQuery plugin that allows you to create multi-level drop down menu with subtle effects (sliding, fading, scale up, or scale down).  Each sub-menu in this menu will be shown in its own context, making the “parent” level disappear, good for saving space for menus which have a lot of content

کتابخانه jQuery-Responsive-Multi-Level-Menu-Plugin-Dlmenu با افکت های زیبا
اشتراک‌ها
بررسی Blazor و Razor Component

WHAT IS BLAZOR?

Blazor is a single-page app framework for building interactive client-side Web apps with .NET. Blazor uses open web standards without plugins or code transpilation. Blazor works in all modern web browsers, including mobile browsers. 

بررسی Blazor و Razor Component
اشتراک‌ها
Authentication بوسیله گوگل در ASP.NET Core 2.0

Sometimes, we want users to log in to our application using their existing credentials from third-party applications, such as Facebook, Twitter, Google, etc. In this article, we are going to look into the authentication of ASP.NET Core app using a Google account. 

Authentication بوسیله گوگل در ASP.NET Core 2.0
اشتراک‌ها
کتاب رایگان HBase Succinctly
Description

Use HBase to improve your control of big data. In HBase Succinctly, author Elton Stoneman will detail what makes HBase different from other databases and teach you about its signature features. With this knowledge, you will be able to jump into big data management.

Table of Contents
  1. Introducing HBase
  2. Hbase and the HBase Shell
  3. HBase Table Design
  4. Connecting with the Java API
  5. Connecting with Python and Thrift
  6. Connecting with .NET and Stargate
  7. The Architecture of HBase
  8. Inside the Region Server
  9. Monitoring and Administering HBase
کتاب رایگان HBase Succinctly
مطالب
دسترسی به Collectionها در یک ترد دیگر در WPF
اگر در WPF سعی کنیم آیتمی را به مجموعه اعضای یک Collection مانند یک List یا ObservableCollection از طریق تردی دیگر اضافه کنیم، با خطای ذیل متوقف خواهیم شد:
 This type of CollectionView does not support changes to its SourceCollection
from a thread different from the Dispatcher thread
راه حلی که برای آن تا دات نت 4 در اکثر سایت‌ها توصیه می‌شد به نحو ذیل است:
Adding to an ObservableCollection from a background thread


مشکل!
اگر همین برنامه را که برای دات نت 4 کامپایل شده‌است، بر روی سیستمی که دات نت 4.5 بر روی آن نصب است اجرا کنیم، برنامه با خطای ذیل متوقف می‌شود:
 System.InvalidOperationException: This exception was thrown because the generator for control
'System.Windows.Controls.ListView Items.Count:62' with name '(unnamed)' has received sequence of
CollectionChanged events that do not agree with the current state of the Items collection.
The following differences were detected:  Accumulated count 61 is different from actual count 62.


مشکل از کجاست؟
در دات نت 4 و نیم، دیگر نیازی به استفاده از کلاس MTObservableCollection یاد شده نیست و به صورت توکار امکان کار با Collectionها از طریق تردی دیگر میسر است. فقط برای فعال سازی آن باید نوشت:
 private static object _lock = new object();
//...
BindingOperations.EnableCollectionSynchronization(persons, _lock);
پس از اینکه برای نمونه، مجموعه‌ی فرضی persons وهله سازی شد، تنها کافی است متد جدید EnableCollectionSynchronization بر روی آن فراخوانی شود.


برای برنامه‌ی دات نت 4 ایی که قرار است در سیستم‌های مختلف اجرا شود چطور؟

در اینجا باید از Reflection کمک گرفت. اگر متد EnableCollectionSynchronization بر روی کلاس BindingOperations یافت شد، یعنی برنامه‌ی دات نت 4، در محیط جدید در حال اجرا است:
public static void EnableCollectionSynchronization(IEnumerable collection, object lockObject)
{
      MethodInfo method = typeof(BindingOperations).GetMethod("EnableCollectionSynchronization",
             new Type[] { typeof(IEnumerable), typeof(object) });
      if (method != null)
      {
         method.Invoke(null, new object[] { collection, lockObject });
      }
}
در این حالت فقط کافی است این متد جدید یافت شده را بر روی Collection مدنظر فراخوانی کنیم.
همچنین اگر بخواهیم کلاس MTObservableCollection معرفی شده را جهت سازگاری با دات نت 4 و نیم به روز کنیم، به کلاس ذیل خواهیم رسید. این کلاس با دات نت 4 و 4.5 سازگار است و جهت کار با ObservableCollectionها از طریق تردهای مختلف تهیه شده‌است:
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Windows.Data;
using System.Windows.Threading;

namespace WpfAsyncCollection
{
    public class AsyncObservableCollection<T> : ObservableCollection<T>
    {
        public override event NotifyCollectionChangedEventHandler CollectionChanged;
        private static object _syncLock = new object();

        public AsyncObservableCollection()
        {
            enableCollectionSynchronization(this, _syncLock);
        }

        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            using (BlockReentrancy())
            {
                var eh = CollectionChanged;
                if (eh == null) return;

                var dispatcher = (from NotifyCollectionChangedEventHandler nh in eh.GetInvocationList()
                                  let dpo = nh.Target as DispatcherObject
                                  where dpo != null
                                  select dpo.Dispatcher).FirstOrDefault();

                if (dispatcher != null && dispatcher.CheckAccess() == false)
                {
                    dispatcher.Invoke(DispatcherPriority.DataBind, (Action)(() => OnCollectionChanged(e)));
                }
                else
                {
                    foreach (NotifyCollectionChangedEventHandler nh in eh.GetInvocationList())
                        nh.Invoke(this, e);
                }
            }
        }

        private static void enableCollectionSynchronization(IEnumerable collection, object lockObject)
        {
            var method = typeof(BindingOperations).GetMethod("EnableCollectionSynchronization", 
                                    new Type[] { typeof(IEnumerable), typeof(object) });
            if (method != null)
            {
                // It's .NET 4.5
                method.Invoke(null, new object[] { collection, lockObject });
            }
        }
    }
}
در این کلاس، در سازنده‌ی آن متد عمومی enableCollectionSynchronization فراخوانی می‌شود. اگر برنامه در محیط دات نت 4 فراخوانی شود، تاثیری نخواهد داشت چون method در حال بررسی نال است. در غیراینصورت، برنامه در حالت سازگار با دات نت 4.5 اجرا خواهد شد.
اشتراک‌ها
دوره مقدماتی Microservices در دات نت

In this beginner level course, you will learn the foundational elements of a microservices architecture by incrementally building a real microservices based application with the .NET platform, step by step. 

دوره مقدماتی Microservices در دات نت