Inheritance: Aurora.Framework.ConnectorBase, IAssetService, IService
        public void TestGoodAssetStoreRequest()
        {
            TestHelpers.InMethod();

            UUID assetId = TestHelpers.ParseTail(0x1);

            IConfigSource config = new IniConfigSource();         
            config.AddConfig("AssetService");           
            config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");

            AssetService assetService = new AssetService(config);

            AssetServerPostHandler asph = new AssetServerPostHandler(assetService);

            AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World");

            MemoryStream buffer = new MemoryStream();

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Encoding = Encoding.UTF8;

            using (XmlWriter writer = XmlWriter.Create(buffer, settings))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(AssetBase));
                serializer.Serialize(writer, asset);
                writer.Flush();
            }            

            buffer.Position = 0;
            asph.Handle(null, buffer, null, null);

            AssetBase retrievedAsset = assetService.Get(assetId.ToString());

            Assert.That(retrievedAsset, Is.Not.Null);
        }
Example #2
0
        public AssetService(IConfigSource config) : base(config)
        {
            if (m_RootInstance == null)
            {
                m_RootInstance = this;

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                                                         "show digest",
                                                         "show digest <ID>",
                                                         "Show asset digest", HandleShowDigest);

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                                                         "delete asset",
                                                         "delete asset <ID>",
                                                         "Delete asset from database", HandleDeleteAsset);

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                                                         "dump asset",
                                                         "dump asset <ID>",
                                                         "Dump asset to a file",
                                                         "The filename is the same as the ID given.",
                                                         HandleDumpAsset);

                if (m_AssetLoader != null)
                {
                    IConfig assetConfig = config.Configs["AssetService"];
                    if (assetConfig == null)
                    {
                        throw new Exception("No AssetService configuration");
                    }

                    string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
                                                              String.Empty);

                    bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);

                    if (assetLoaderEnabled)
                    {
                        m_log.DebugFormat("[ASSET]: Loading default asset set from {0}", loaderArgs);

                        m_AssetLoader.ForEachDefaultXmlAsset(
                            loaderArgs,
                            delegate(AssetBase a)
                        {
                            AssetBase existingAsset = Get(a.ID);
//                                AssetMetadata existingMetadata = GetMetadata(a.ID);

                            if (existingAsset == null || Util.SHA1Hash(existingAsset.Data) != Util.SHA1Hash(a.Data))
                            {
//                                    m_log.DebugFormat("[ASSET]: Storing {0} {1}", a.Name, a.ID);
                                Store(a);
                            }
                        });
                    }

                    m_log.Debug("[ASSET SERVICE]: Local asset service enabled");
                }
            }
        }
Example #3
0
        public AssetService(IConfigSource config) : base(config)
        {
            if (m_RootInstance == null)
            {
                m_RootInstance = this;

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                        "show digest",
                        "show digest <ID>",
                        "Show asset digest", HandleShowDigest);

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                        "delete asset",
                        "delete asset <ID>",
                        "Delete asset from database", HandleDeleteAsset);
                
                MainConsole.Instance.Commands.AddCommand("kfs", false,
                        "dump asset",
                        "dump asset <ID>",
                        "Dump asset to a file", 
                        "The filename is the same as the ID given.", 
                        HandleDumpAsset);

                if (m_AssetLoader != null)
                {
                    IConfig assetConfig = config.Configs["AssetService"];
                    if (assetConfig == null)
                        throw new Exception("No AssetService configuration");

                    string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
                            String.Empty);

                    bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);

                    if (assetLoaderEnabled)
                    {
                        m_log.InfoFormat("[ASSET]: Loading default asset set from {0}", loaderArgs);

                        m_AssetLoader.ForEachDefaultXmlAsset(
                            loaderArgs,
                            delegate(AssetBase a)
                            {
                                AssetBase existingAsset = Get(a.ID);
//                                AssetMetadata existingMetadata = GetMetadata(a.ID);

                                if (existingAsset == null || Util.SHA1Hash(existingAsset.Data) != Util.SHA1Hash(a.Data))
                                {
//                                    m_log.DebugFormat("[ASSET]: Storing {0} {1}", a.Name, a.ID);
                                    Store(a);
                                }
                            });
                    }

                    m_log.Info("[ASSET SERVICE]: Local asset service enabled");
                }
            }
        }
Example #4
0
        public AssetService(IConfigSource config) : base(config)
        {
            if (m_RootInstance == null)
            {
                m_RootInstance = this;

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                                                         "show digest",
                                                         "show digest <ID>",
                                                         "Show asset digest", HandleShowDigest);

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                                                         "delete asset",
                                                         "delete asset <ID>",
                                                         "Delete asset from database", HandleDeleteAsset);

                if (m_AssetLoader != null)
                {
                    IConfig assetConfig = config.Configs["AssetService"];
                    if (assetConfig == null)
                    {
                        throw new Exception("No AssetService configuration");
                    }

                    string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
                                                              String.Empty);

                    bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);

                    if (assetLoaderEnabled)
                    {
                        m_log.InfoFormat("[ASSET]: Loading default asset set from {0}", loaderArgs);
                        m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs,
                                                             delegate(AssetBase a)
                        {
                            Store(a);
                        });
                    }

                    m_log.Info("[ASSET SERVICE]: Local asset service enabled");
                }
            }
        }
        public AssetService(IConfigSource config, string configName)
            : base(config, configName)
        {
            if (m_RootInstance == null)
            {
                m_RootInstance = this;

                if (m_AssetLoader != null)
                {
                    IConfig assetConfig = config.Configs[m_ConfigName];
                    if (assetConfig == null)
                    {
                        throw new Exception("No " + m_ConfigName + " configuration");
                    }

                    string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
                                                              String.Empty);

                    bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);

                    if (assetLoaderEnabled)
                    {
                        m_log.DebugFormat("[ASSET SERVICE]: Loading default asset set from {0}", loaderArgs);

                        m_AssetLoader.ForEachDefaultXmlAsset(
                            loaderArgs,
                            delegate(AssetBase a)
                        {
                            AssetBase existingAsset = Get(a.ID);
                            //                                AssetMetadata existingMetadata = GetMetadata(a.ID);

                            if (existingAsset == null || Util.SHA1Hash(existingAsset.Data) != Util.SHA1Hash(a.Data))
                            {
                                //                                    m_log.DebugFormat("[ASSET]: Storing {0} {1}", a.Name, a.ID);
                                Store(a);
                            }
                        });
                    }

                    m_log.Debug("[ASSET SERVICE]: Local asset service enabled");
                }
            }
        }
        public AssetService(IConfigSource config) : base(config)
        {
            if (m_RootInstance == null)
            {
                m_RootInstance = this;

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                        "show digest",
                        "show digest <ID>",
                        "Show asset digest", HandleShowDigest);

                MainConsole.Instance.Commands.AddCommand("kfs", false,
                        "delete asset",
                        "delete asset <ID>",
                        "Delete asset from database", HandleDeleteAsset);

                if (m_AssetLoader != null)
                {
                    IConfig assetConfig = config.Configs["AssetService"];
                    if (assetConfig == null)
                        throw new Exception("No AssetService configuration");

                    string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
                            String.Empty);

                    bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);

                    if (assetLoaderEnabled)
                    {
                        m_log.InfoFormat("[ASSET]: Loading default asset set from {0}", loaderArgs);
                        m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs,
                                delegate(AssetBase a)
                                {
                                    Store(a);
                                });
                    }

                    m_log.Info("[ASSET SERVICE]: Local asset service enabled");
                }
            }
        }
Example #7
0
        public AssetService(IConfigSource config, string configName) : base(config, configName)
        {
            if (m_RootInstance == null)
            {
                m_RootInstance = this;

                if (m_AssetLoader != null)
                {
                    IConfig assetConfig = config.Configs[m_ConfigName];
                    if (assetConfig == null)
                        throw new Exception("No " + m_ConfigName + " configuration");

                    string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
                            String.Empty);

                    bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);

                    if (assetLoaderEnabled)
                    {
                        m_log.DebugFormat("[ASSET SERVICE]: Loading default asset set from {0}", loaderArgs);

                        m_AssetLoader.ForEachDefaultXmlAsset(
                            loaderArgs,
                            delegate(AssetBase a)
                            {
                                AssetBase existingAsset = Get(a.ID);
//                                AssetMetadata existingMetadata = GetMetadata(a.ID);

                                if (existingAsset == null || Util.SHA1Hash(existingAsset.Data) != Util.SHA1Hash(a.Data))
                                {
//                                    m_log.DebugFormat("[ASSET]: Storing {0} {1}", a.Name, a.ID);
                                    Store(a);
                                }
                            });
                    }

                    m_log.Debug("[ASSET SERVICE]: Local asset service enabled");
                }
            }
        }
        public void TestBadXmlAssetStoreRequest()
        {
            TestHelpers.InMethod();

            IConfigSource config = new IniConfigSource();         
            config.AddConfig("AssetService");           
            config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");

            AssetService assetService = new AssetService(config);

            AssetServerPostHandler asph = new AssetServerPostHandler(assetService);          

            MemoryStream buffer = new MemoryStream();
            byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
            buffer.Write(badData, 0, badData.Length);
            buffer.Position = 0;

            TestOSHttpResponse response = new TestOSHttpResponse();
            asph.Handle(null, buffer, null, response);

            Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest));
        }