Esempio n. 1
0
 public bool ExtractValue(DAE.Runtime.Data.Row row)
 {
     try
     {
         if (_value != null)
         {
             ((DAE.Runtime.Data.Scalar)row.GetValue(_columnName)).AsString = _value;
         }
         else
         {
             ((DAE.Runtime.Data.Scalar)row.GetValue(_columnName)).AsString = String.Empty;                       // Assume that if we are included in the search, that we are blank
         }
         _conversionFailed = false;
         return(true);
     }
     catch
     {
         _conversionFailed = true;
         return(false);
     }
 }
Esempio n. 2
0
        private IScalar LoadWithCache(string document, IServerProcess process)
        {
            IScalar result = null;

            lock (Cache)
            {
                uint cRC32 = Cache.GetCRC32(document);
                if (cRC32 > 0)
                {
                    try
                    {
                        result = LoadFromCache(document, process);
                    }
                    catch
                    {
                        result = null;
                        cRC32  = 0;
                    }
                }

                using
                (
                    DAE.Runtime.Data.Row row = (DAE.Runtime.Data.Row)process.Evaluate
                                               (
                        String.Format
                        (
                            "LoadIfNecessary('{0}', {1})",
                            document.Replace("'", "''"),
                            ((int)cRC32).ToString()
                        ),
                        null
                                               )
                )

                    if (!(bool)row["CRCMatches"])
                    {
                        using (DAE.Runtime.Data.Scalar value = row.GetValue("Value") as DAE.Runtime.Data.Scalar)
                        {
                            SaveToCache(document, process, value, (uint)(int)row["ActualCRC32"]);
                            result = (DAE.Runtime.Data.Scalar)value.Copy();
                        }
                    }
            }

            return(result);
        }
Esempio n. 3
0
 public void AsyncLoad()
 {
     try
     {
         uint cRC32 = 0;
         if (System.IO.File.Exists(_fileName))
         {
             // compute the CRC of the existing file
             using (FileStream stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read))
                 cRC32 = CRC32Utility.GetCRC32(stream);
         }
         using
         (
             DAE.Runtime.Data.Row row = (DAE.Runtime.Data.Row)_process.Evaluate
                                        (
                 String.Format
                 (
                     "LoadIfNecessary('{0}', {1})",
                     _document.Replace("'", "''"),
                     ((int)cRC32).ToString()
                 ),
                 null
                                        )
         )
         {
             if (!(bool)row["CRCMatches"])
             {
                 Directory.CreateDirectory(Path.GetDirectoryName(_fileName));
                 using (Stream sourceStream = row.GetValue("Value").OpenStream())
                     using (FileStream targetStream = new FileStream(_fileName, FileMode.Create, FileAccess.Write))
                         StreamUtility.CopyStream(sourceStream, targetStream);
             }
         }
         Session.SafelyInvoke(new AsyncFinishHandler(AsyncFinish), new object[] { true });
     }
     catch
     {
         Session.SafelyInvoke(new AsyncFinishHandler(AsyncFinish), new object[] { false });
         // Don't allow exceptions to go unhandled... the framework will abort the application
     }
 }
Esempio n. 4
0
        public override string SetApplication(string applicationID, string clientType)
        {
            // Reset our current settings
            _theme = null;
            DisposeDefaultIcon();
            ClearDocumentCache();
            ClearImageCache();
            int documentCacheSize = CDefaultDocumentCacheSize;
            int imageCacheSize    = CDefaultImageCacheSize;

            // Optimistically load the settings
            try
            {
                DAE.Runtime.DataParams paramsValue = new DAE.Runtime.DataParams();
                paramsValue.Add(DAE.Runtime.DataParam.Create(Pipe.Process, "AApplicationID", applicationID));

                using (DAE.Runtime.Data.Row row = (DAE.Runtime.Data.Row)Evaluate(Pipe.Process, SettingsExpression, paramsValue))
                {
                    if (row != null)
                    {
                        // Load the theme
                        if (row.HasValue("Theme"))
                        {
                            _theme = (Theme) new BOP.Deserializer().Deserialize((string)row["Theme"], null);
                        }

                        // Load the default form icon
                        if (row.HasValue("IconImage"))
                        {
                            using (Stream iconStream = row.GetValue("IconImage").OpenStream())
                            {
                                Bitmap bitmap = System.Drawing.Image.FromStream(iconStream) as Bitmap;
                                if (bitmap != null)
                                {
                                    _defaultIcon = Icon.FromHandle(bitmap.GetHicon());                                          // TODO: Should this bitmap be disposed after this?
                                }
                            }
                        }

                        // Load the document cache size
                        if (row.HasValue("DocumentCacheSize"))
                        {
                            documentCacheSize = (int)row["DocumentCacheSize"];
                        }

                        // Load the image cache size
                        if (row.HasValue("ImageCacheSize"))
                        {
                            imageCacheSize = (int)row["ImageCacheSize"];
                        }

                        // Load the help file
                        if (row.HasValue("HelpDocument"))
                        {
                            string document = (string)row["HelpDocument"];
                            if (document != String.Empty)
                            {
                                LoadHelpDocument(document);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                HandleException(new ClientException(ClientException.Codes.ErrorLoadingSettings, exception));
            }
            finally
            {
                if (_theme == null)
                {
                    _theme = new Theme();
                }
            }

            // Setup the image cache
            try
            {
                if (imageCacheSize > 0)
                {
                    Pipe.ImageCache = new FixedSizeCache <string, byte[]>(imageCacheSize);
                }
            }
            catch (Exception exception)
            {
                HandleException(exception);                     // Don't fail, just warn
            }

            // Set up the client-side document cache
            try
            {
                if (documentCacheSize > 0)
                {
                    Pipe.Cache =
                        new DocumentCache
                        (
                            Path.Combine
                            (
                                Path.Combine(System.IO.Path.GetTempPath(), CCachePath),
                                @"App" + applicationID.ToString()
                            ),
                            documentCacheSize
                        );
                }
            }
                        #if DEBUG
            catch (Exception exception)
                        #else
            catch
                        #endif
            {
                                #if DEBUG
                HandleException(exception);                     // Don't fail if we can't do this and only show something if under debug
                                #endif
            }

            return(base.SetApplication(applicationID, clientType));
        }