/// <summary>
        /// Load an OutputFileServerDevice from a file
        /// </summary>
        static public OutputDevice LoadFromFile(string path, bool ignoreException)
        {
            OutputFileServerDevice result = null;

            try
            {
                path = FileHelper.ConvertOSFilePath(path);
                if (!File.Exists(path))
                {
                    throw new Exception("File not found: " + path);
                }

                XmlSerializer serializer = new XmlSerializer(typeof(OutputFileServerDevice));
                using (XmlReader xr = XmlReader.Create(path))
                {
                    result = (OutputFileServerDevice)serializer.Deserialize(xr);
                }
                result.Name             = Path.GetFileNameWithoutExtension(path);
                result.FilePath         = path;
                result.LastModification = File.GetLastWriteTime(path);
            }
            catch (Exception ex)
            {
                if (!ignoreException)
                {
                    throw new Exception(string.Format("Unable to read the file '{0}'.\r\n{1}", path, ex.Message));
                }
            }
            return(result);
        }
        /// <summary>
        /// Create a basic OutputFolderDevice
        /// </summary>
        static public OutputFileServerDevice Create()
        {
            var result = new OutputFileServerDevice()
            {
                GUID = Guid.NewGuid().ToString()
            };

            result.Name = "File Server Device";
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Init the repository from a given path
        /// </summary>
        public void Init(string path)
        {
            RepositoryPath = path;
            RepositoryServer.ViewsFolder          = ViewsFolder;
            RepositoryServer.TableTemplatesFolder = TableTemplatesFolder;

            CheckFolders();
            //Data sources
            if (Sources.Count == 0)
            {
                foreach (var file in Directory.GetFiles(SourcesFolder, "*." + SealConfigurationFileExtension))
                {
                    try
                    {
                        var source = MetaSource.LoadFromFile(file);
                        Sources.Add(source);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                foreach (var source in Sources)
                {
                    source.InitReferences(this);
                }
            }

            if (Devices.Count == 0)
            {
                //Devices, add a default folder device, then the other devices
                Devices.Add(OutputFolderDevice.Create());
                foreach (var file in Directory.GetFiles(DevicesEmailFolder, "*." + SealConfigurationFileExtension))
                {
                    try
                    {
                        Devices.Add(OutputEmailDevice.LoadFromFile(file, true));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
                foreach (var file in Directory.GetFiles(DevicesFileServerFolder, "*." + SealConfigurationFileExtension))
                {
                    try
                    {
                        Devices.Add(OutputFileServerDevice.LoadFromFile(file, true));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }

            if (!_assembliesLoaded)
            {
                //Load extra assemblies defined in Repository
                var assemblies = Directory.GetFiles(AssembliesFolder, "*.dll");
                foreach (var assembly in assemblies)
                {
                    try
                    {
                        Assembly.LoadFrom(assembly);
                    }
                    catch (Exception Exception)
                    {
                        Debug.WriteLine(Exception.Message);
                    }
                }

                //Add this assembly resolve necessary when executing Razor scripts
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);

                _assembliesLoaded = true;
            }
        }