コード例 #1
0
ファイル: ObservableList.cs プロジェクト: svendster/Ginger
        public void LoadLazyInfo()
        {
            if (!mLazyLoad)
            {
                return;
            }
            if (loadingata) // //since several functions can call in parallel we might enter when status is already loadingdata, so we wait for it to complete, then return
            {
                int count = 0;
                while (loadingata && count < 1000)  // Max 10 seconds
                {
                    Thread.Sleep(10);
                    count++;
                }
                return;
            }

            //since several function can try to get data we need to lock and verify before we convert
            lock (this)
            {
                loadingata = true;
                // We need 2nd check as it might changed after lock released

                if (!mLazyLoad)
                {
                    return;               //since several functions can try to get data we need to lock and verify before we convert
                }
                //Option 1
                string s = mStringData;

                // Option 2
                // string s = StringCompressor.DecompressString(mStringData);

                //Option 3
                // string s = StringCompressor.DecompressStringFromBytes(mMemoryStream, mDataLen);

                ObservableList <T> l = new ObservableList <T>();
                try
                {
                    NewRepositorySerializer.DeserializeObservableListFromText(this, s);
                }
                catch (Exception ex)
                {
                    string serlizedStringToShowInLog = s;
                    if (string.IsNullOrEmpty(serlizedStringToShowInLog) == false && serlizedStringToShowInLog.Length > 1000)
                    {
                        serlizedStringToShowInLog = serlizedStringToShowInLog.Substring(0, 1000) + "...";
                    }
                    Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to Deserialize the lazy load section: '{0}'", serlizedStringToShowInLog), ex);
                }

                mStringData = null;
                //mMemoryStream.Dispose();
                //mMemoryStream = null;
                mLazyLoad      = false;
                loadingata     = false;
                mAvoidLazyLoad = true;
            }
        }
コード例 #2
0
ファイル: ObservableList.cs プロジェクト: ramizil/Ginger
        public void GetItemsInfo()
        {
            if (!mLazyLoad)
            {
                return;
            }
            if (loadingata) // //since several functions can call in parallel we might enter when status is already loadingdata, so we wait for it to complete, then return
            {
                int count = 0;
                while (loadingata && count < 1000)  // Max 10 seconds
                {
                    Thread.Sleep(10);
                    count++;
                }
                return;
            }

            //since several function can try to get data we need to lock and verify before we convert
            lock (this)
            {
                loadingata = true;
                // We need 2nd check as it might changed after lock released

                if (!mLazyLoad)
                {
                    return;               //since several functions can try to get data we need to lock and verify before we convert
                }
                //Option 1
                string s = mStringData;

                // Option 2
                // string s = StringCompressor.DecompressString(mStringData);

                //Option 3
                // string s = StringCompressor.DecompressStringFromBytes(mMemoryStream, mDataLen);

                ObservableList <T> l = new ObservableList <T>();
                NewRepositorySerializer.DeserializeObservableListFromText(this, s);

                mStringData = null;
                //mMemoryStream.Dispose();
                //mMemoryStream = null;
                mLazyLoad  = false;
                loadingata = false;
            }
        }
コード例 #3
0
        public void LoadLazyInfo()
        {
            if (!LazyLoad)
            {
                return;
            }
            if (loadingata) // //since several functions can call in parallel we might enter when status is already loadingdata, so we wait for it to complete, then return
            {
                int count = 0;
                while (loadingata && count < 1000)  // Max 10 seconds
                {
                    Thread.Sleep(10);
                    count++;
                }
                return;
            }

            //since several function can try to get data we need to lock and verify before we convert
            lock (this)
            {
                loadingata = true;
                // We need 2nd check as it might changed after lock released
                if (!LazyLoad)
                {
                    return;              //since several functions can try to get data we need to lock and verify before we convert
                }
                try
                {
                    NewRepositorySerializer.DeserializeObservableListFromText(this, LazyLoadDetails.DataAsString);
                }
                catch (Exception ex)
                {
                    Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to Deserialize the lazy load list '{0}' from file '{1}'", LazyLoadDetails.Config.ListName, LazyLoadDetails.XmlFilePath), ex);
                }

                LazyLoadDetails.DataAsString  = null;
                LazyLoadDetails.DataWasLoaded = true;
                loadingata     = false;
                mAvoidLazyLoad = true;
            }
        }