public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            // load FKs
            try
            {
                MetadataItem obj = foreignKeys.Parent.Object;

                string[] restrictions = new string[5];
                restrictions[2] = obj.Name;

                DataTable schemaTable = _connection.GetSchema(VistaDBConnection.SchemaConstants.SCHEMA_FOREIGNKEYCOLUMNS, restrictions);

                MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions);
                mrf.PkNameFieldName       = "FKEY_TO_TABLE";
                mrf.PkFieldName           = "FKEY_TO_COLUMN";
                mrf.FkFieldName           = "FKEY_FROM_COLUMN";
                mrf.ForeignKeyIdFieldName = "FKEY_TO_TABLE";
                mrf.Datatable             = schemaTable;

                mrf.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
        public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions)
        {
            if (databases.Parent.Server == null)
            {
                if (!Connected)
                {
                    Connect();
                }

                try
                {
                    DataTable schemaTable = _connection.GetSchema("Databases");

                    using (MetadataNamespacesFetcherFromDatatable mdf = new MetadataNamespacesFetcherFromDatatable(databases, MetadataType.Database, loadingOptions))
                    {
                        mdf.Datatable     = schemaTable;
                        mdf.NameFieldName = "database_name";

                        mdf.LoadMetadata();
                    }
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
        public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            // load FKs
            try
            {
                MetadataItem obj = foreignKeys.Parent.Object;

                string[] restrictions = new string[3];
                restrictions[2] = obj.Name;

                DataTable schemaTable = _connection.GetSchema("ForeignKeyColumns", restrictions);

                MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions);
                mrf.PkNameFieldName  = "REFERENCED_TABLE_NAME";
                mrf.PkFieldName      = "REFERENCED_COLUMN_NAME";
                mrf.FkFieldName      = "COLUMN_NAME";
                mrf.OrdinalFieldName = "ORDINAL_POSITION";
                mrf.TrimSpaces       = true;
                mrf.Datatable        = schemaTable;

                mrf.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
        private List <string> LoadMetadata(MetadataType type)
        {
            var loadingOptions = new MetadataLoadingOptions
            {
                LoadDefaultDatabaseOnly = type != MetadataType.Database,
                LoadSystemObjects       = true
            };

            var container = new MetadataContainer(TemporaryMetadataContainer.SQLContext)
            {
                LoadingOptions = loadingOptions
            };

            var list = new MetadataList(container);

            list.Load(type, false);
            //list.Load(MetadataType.Database, false);

            //if (type == MetadataType.Schema)
            //{
            //    var defaultDb = list.Databases.FirstOrDefault(x => x.Default);
            //    if (defaultDb != null)
            //    {
            //        defaultDb.Items.Load(type, false);
            //        list = defaultDb.Items;
            //    }
            //}

            return(list.Select(x => x.Name).ToList());
        }
        public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions)
        {
            MetadataItem obj = foreignKeys.Parent.Object;

            if (obj.Server == null)
            {
                MetadataItem database = obj.Database;
                try
                {
                    string[] restrictions = new string[5];
                    restrictions[0] = database != null ? database.Name : null;
                    restrictions[2] = obj.Name;
                    DataTable schemaTable = _connection.GetSchema("ForeignKeys", restrictions);
                    MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions)
                    {
                        PkDatabaseFieldName = "FKEY_TO_CATALOG",
                        PkNameFieldName     = "FKEY_TO_TABLE",
                        PkFieldName         = "FKEY_TO_COLUMN",
                        FkFieldName         = "FKEY_FROM_COLUMN",
                        OrdinalFieldName    = "FKEY_FROM_ORDINAL_POSITION",
                        Datatable           = schemaTable
                    };
                    mrf.LoadMetadata();
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
        private static bool TryContributeMetadataValue(this IDictionary <string, object> dictionary, string name, object value, Type valueType, bool allowsMultiple)
        {
            object metadataValue;

            if (!dictionary.TryGetValue(name, out metadataValue))
            {
                if (allowsMultiple)
                {
                    var list = new MetadataList();
                    list.Add(value, valueType);
                    value = list;
                }

                dictionary.Add(name, value);
            }
            else
            {
                var list = metadataValue as MetadataList;
                if (!allowsMultiple || list == null)
                {
                    // Either single value already found when should be multiple
                    // or a duplicate name already exists
                    dictionary.Remove(name);
                    return(false);
                }

                list.Add(value, valueType);
            }
            return(true);
        }
示例#7
0
        public void testMetadataProcess()
        {
            MetadataList ml = new MetadataList(examplesPath);

            Assert.AreEqual(14, ml.Files.Length);
            ml.processMetadataList();
            Assert.AreEqual(14, ml.List.Count);
        }
示例#8
0
 public void Clear()
 {
     Url     = null;
     RawHtml = null;
     Title   = null;
     MetadataList.Clear();
     AnchorList.Clear();
     ImageList.Clear();
 }
示例#9
0
        public void testMetadataPaths()
        {
            MetadataList ml = new MetadataList("c:\\windows");

            Assert.AreEqual(0, ml.Files.Length);
            // Non existant file
            ml = new MetadataList("c:\\xyz");
            Assert.AreEqual(0, ml.Files.Length);
        }
示例#10
0
        public void testProcessMetadata()
        {
            MetadataList ml = new MetadataList(examplesPath);
            Metadata     m  = ml.processFile(examplesPath + "graphviz.xslt");

            Assert.AreEqual("Graphviz", m.Get(Metadata.titleTag));
            Assert.IsNotNullOrEmpty(m.Get(Metadata.descriptionTag));
            Assert.IsTrue(m.Get(Metadata.descriptionTag).IndexOf("Graphviz") != -1);
        }
 /// <summary>
 /// Constructs a new ReadObjectStreamResponse
 /// </summary>
 /// <param name="s">The object content stream</param>
 /// <param name="contentType">The MIME type of the stream</param>
 /// <param name="length">The length.  Set to -1 if unknown.</param>
 /// <param name="meta">The object metadata</param>
 /// <param name="acl">The object's ACL</param>
 /// <param name="extent">The extent that was read, or null</param>
 /// <param name="response">the HTTP response object to close the connection</param>
 /// <param name="checksum">The content checksum if the Atmos server had one stored</param>
 public ReadObjectStreamResponse(Stream s, string contentType, long length, MetadataList meta, Acl acl, Extent extent, HttpWebResponse response, string checksum)
 {
     this.Content = s;
     this.ContentType = contentType;
     this.Length = length;
     this.Metadata = meta;
     this.Acl = acl;
     this.response = response;
     this.ContentChecksum = checksum;
 }
示例#12
0
        public void testMetadataTitle()
        {
            MetadataList ml = new MetadataList(examplesPath);
            Metadata     m  = ml.processFile(examplesPath + "text.xslt");

            Assert.IsNull(m.Get(Metadata.titleTag));
            string title = m.getTitle();

            Assert.AreEqual("text.xslt", title);
        }
示例#13
0
        public void loadListBox()
        {
            System.Windows.Forms.ListBox listbox = new System.Windows.Forms.ListBox();
            listbox.Items.Add("Item 1");
            Assert.AreEqual(1, listbox.Items.Count);
            MetadataList metadatalist = new MetadataList(examplesPath);

            metadatalist.processMetadataList();
            foreach (Metadata metadata in metadatalist.List)
            {
                listbox.Items.Add(metadata.getTitle());
            }
            Assert.AreEqual(15, listbox.Items.Count);  // 14 files plus first item
        }
        private void LoadDatabaseList()
        {
            DefaultDatabase = null;
            _databases      = null;

            if (Connection.MetadataProvider != null && Connection.SyntaxProvider.IsSupportDatabases())
            {
                _temporarySqlContext.MetadataProvider = Connection.MetadataProvider;
                _temporarySqlContext.SyntaxProvider   = Connection.SyntaxProvider;

                MetadataLoadingOptions oldOptions = new MetadataLoadingOptions();
                oldOptions.Assign(TemporaryMetadataContainer.LoadingOptions);

                MetadataLoadingOptions tempOptions = new MetadataLoadingOptions
                {
                    LoadDefaultDatabaseOnly = false,
                    LoadSystemObjects       = true
                };

                try
                {
                    TemporaryMetadataContainer.LoadingOptions = tempOptions;
                    MetadataList list = new MetadataList(TemporaryMetadataContainer);
                    list.Load(MetadataType.Database, false);
                    _databases = list.Databases;
                }
                finally
                {
                    TemporaryMetadataContainer.LoadingOptions = oldOptions;
                    tempOptions.Dispose();
                }
            }

            _wizardPageLoadOpts.ChecklistDatabases.Items.Clear();

            if (_databases == null)
            {
                return;
            }

            foreach (MetadataNamespace database in _databases)
            {
                if (database.Default)
                {
                    DefaultDatabase = database.Name;
                }

                _wizardPageLoadOpts.ChecklistDatabases.Items.Add(new DatabaseObjectForListbox(database.Name, database.Default));
            }
        }
        public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            // load from OLEDB catalogs
            try
            {
                DataTable schemaTable = _connection.GetSchema("Tables");

                string databaseFieldName = "TABLE_CATALOG";
                if (schemaTable.Columns[databaseFieldName] == null)
                {
                    databaseFieldName = "TABLE_CAT";
                }

                using (MetadataNamespacesFetcherFromDatatable mdf =
                           new MetadataNamespacesFetcherFromDatatable(databases, MetadataType.Database, loadingOptions))
                {
                    mdf.Datatable     = schemaTable;
                    mdf.NameFieldName = databaseFieldName;

                    mdf.LoadMetadata();
                }
            }
            catch
            {
                // loading from OLEDB catalog failed
            }

            // load default database
            string currentDatabase = Connection.Database;

            if (!string.IsNullOrEmpty(currentDatabase))
            {
                MetadataNamespace database = databases.FindItem <MetadataNamespace>(currentDatabase, MetadataType.Database);
                if (database == null)
                {
                    database      = new MetadataNamespace(databases, MetadataType.Database);
                    database.Name = currentDatabase;
                    databases.Add(database);
                }
                database.Default = true;
            }
        }
示例#16
0
        //this works for adding new items, but not for adding missing items or highlighting existing ones.  why?
        private void SetSelectedListItem(NotifyingMetadataItem selection)
        {
            if (selection != null)
            {
                CollectionViewSource cvs = (CollectionViewSource)FindResource("MetadatasCVS");
                if (cvs != null)
                {
                    cvs.View.MoveCurrentTo(selection);
                }

                //MetadataList.SelectedItem = selection;

                MetadataList.ScrollIntoView(selection);

                FocusHelper.Focus(FocusableItem);
            }
        }
示例#17
0
        } // createQueryBuilder(...)

        //
        internal void buildBindingList(bool loadDefaultDatabaseOnly, bool loadSystemObjects, bool withFields)
        {
            this._colQnBindingList = new BindingList <ColumnQN>();
            using (SQLContext sqlContext = new SQLContext())
            {
                sqlContext.Assign(this._qb.SQLContext);
                sqlContext.MetadataContainer.LoadingOptions.LoadDefaultDatabaseOnly = loadDefaultDatabaseOnly;
                sqlContext.MetadataContainer.LoadingOptions.LoadSystemObjects       = loadSystemObjects;

                using (MetadataList xList = new MetadataList(sqlContext.MetadataContainer))
                {
                    xList.Load(MetadataType.Server, false);
                    foreach (MetadataItem srv in xList)
                    {
                    }
                    xList.Load(MetadataType.Database, false);
                    foreach (MetadataItem db in xList)
                    {
                        using (MetadataList schemasList = new MetadataList(db))
                        {
                            schemasList.Load(MetadataType.Schema, false);
                            foreach (MetadataItem sch in schemasList)
                            {
                                using (MetadataList tablesList = new MetadataList(sch))
                                {
                                    tablesList.Load(MetadataType.Table, false);
                                    foreach (MetadataItem tbl in tablesList)
                                    {
                                        using (MetadataList columnsList = new MetadataList(tbl))
                                        {
                                            columnsList.Load(MetadataType.Field, false);

                                            foreach (MetadataItem col in columnsList)
                                            {
                                                MetadataItem mdi = col;
                                                this.TreatField(mdi);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } // buildBindingList(...)
示例#18
0
        public override void LoadSchemas(MetadataList schemas, MetadataLoadingOptions loadingOptions)
        {
            MetadataNamespace database = schemas.Parent.Database;

            if (schemas.Parent.Server == null && database != null)
            {
                if (!Connected)
                {
                    Connect();
                }

                try
                {
                    string[] restrictions = new string[1];
                    restrictions[0] = database.Name;

                    using (DataTable schemaTable = _connection.GetSchema("Tables", restrictions))
                    {
                        using (MetadataNamespacesFetcherFromDatatable mdf =
                                   new MetadataNamespacesFetcherFromDatatable(schemas, MetadataType.Schema, loadingOptions))
                        {
                            mdf.Datatable     = schemaTable;
                            mdf.NameFieldName = "TABLE_SCHEMA";

                            mdf.LoadMetadata();
                        }
                    }

                    using (DataTable schemaTable = _connection.GetSchema("Views", restrictions))
                    {
                        using (MetadataNamespacesFetcherFromDatatable mdf =
                                   new MetadataNamespacesFetcherFromDatatable(schemas, MetadataType.Schema, loadingOptions))
                        {
                            mdf.Datatable     = schemaTable;
                            mdf.NameFieldName = "TABLE_SCHEMA";

                            mdf.LoadMetadata();
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
        private List <string> LoadMetadata(MetadataType type)
        {
            var loadingOptions = new MetadataLoadingOptions
            {
                LoadDefaultDatabaseOnly = type != MetadataType.Database,
                LoadSystemObjects       = true
            };

            var container = new MetadataContainer(TemporaryMetadataContainer.SQLContext)
            {
                LoadingOptions = loadingOptions
            };

            var list = new MetadataList(container);

            list.Load(type, false);
            return(list.Select(x => x.Name).ToList());
        }
        public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            // load FKs
            try
            {
                MetadataItem obj      = foreignKeys.Parent.Object;
                MetadataItem database = obj.Database;

                string[] restrictions = new string[2];
                restrictions[0] = database != null ? database.Name : string.Empty;
                restrictions[1] = obj.Name;

                DataTable schemaTable = _connection.GetSchema("Foreign Key Columns", restrictions);

                MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions);

                if (foreignKeys.SQLContext.SyntaxProvider.IsSupportSchemas())
                {
                    mrf.PkSchemaFieldName = "TABLE_SCHEMA";
                }
                else
                {
                    mrf.PkDatabaseFieldName = "TABLE_SCHEMA";
                }

                mrf.PkNameFieldName  = "TABLE_NAME";
                mrf.PkFieldName      = "COLUMN_NAME";
                mrf.FkFieldName      = "REFERENCED_COLUMN_NAME";
                mrf.OrdinalFieldName = "ORDINAL_POSITION";
                mrf.Datatable        = schemaTable;

                mrf.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
        public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            MetadataItem obj = foreignKeys.Parent.Object;

            if (obj.Server == null)
            {
                MetadataItem schema   = obj.Schema;
                MetadataItem database = obj.Database;

                try
                {
                    object[] restrictions = new object[6];
                    restrictions[3] = database != null ? database.Name : null;
                    restrictions[4] = schema != null ? schema.Name : null;
                    restrictions[5] = obj.Name;

                    DataTable schemaTable = _connection.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, restrictions);

                    MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys,
                                                                                                              loadingOptions);

                    mrf.PkDatabaseFieldName = "PK_TABLE_CATALOG";
                    mrf.PkSchemaFieldName   = "PK_TABLE_SCHEMA";
                    mrf.PkNameFieldName     = "PK_TABLE_NAME";
                    mrf.PkFieldName         = "PK_COLUMN_NAME";
                    mrf.FkFieldName         = "FK_COLUMN_NAME";
                    mrf.OrdinalFieldName    = "ORDINAL";
                    mrf.Datatable           = schemaTable;

                    mrf.LoadMetadata();
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            try
            {
                // load tables and views
                DataTable schemaTable = _connection.GetSchema("Tables", null);

                MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                mof.NameFieldName   = "TABLE_NAME";
                mof.TypeFieldName   = "TABLE_TYPE";
                mof.TableType       = new string[] { "TABLE" };
                mof.SystemTableType = new string[] { "SYSTEM_TABLE" };
                mof.ViewType        = new string[] { "VIEW" };
                mof.TrimSpaces      = true;
                mof.Datatable       = schemaTable;

                mof.LoadMetadata();

                // load procedures
                schemaTable = _connection.GetSchema("Procedures", null);

                mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                mof.NameFieldName     = "PROCEDURE_NAME";
                mof.SystemFieldName   = "IS_SYSTEM_PROCEDURE";
                mof.SystemFieldValue  = 1;
                mof.TrimSpaces        = true;
                mof.Datatable         = schemaTable;
                mof.DefaultObjectType = MetadataType.Procedure;

                mof.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            MetadataItem obj = objects.Parent;

            if (obj.Schema == null && obj.Database == null && obj.Server == null)
            {
                if (!Connected)
                {
                    Connect();
                }

                try
                {
                    // load tables
                    DataTable schemaTable = _connection.GetSchema(VistaDBConnection.SchemaConstants.SCHEMA_TABLES);

                    MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                    mof.NameFieldName   = "TABLE_NAME";
                    mof.TypeFieldName   = "TABLE_TYPE";
                    mof.TableType       = new string[] { VistaDBConnection.UserTableType };
                    mof.SystemTableType = new string[] { VistaDBConnection.SystemTableType };
                    mof.Datatable       = schemaTable;

                    mof.LoadMetadata();

                    // load views
                    schemaTable = _connection.GetSchema(VistaDBConnection.SchemaConstants.SCHEMA_VIEWS, null);

                    mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                    mof.NameFieldName     = "TABLE_NAME";
                    mof.Datatable         = schemaTable;
                    mof.DefaultObjectType = MetadataType.View;

                    mof.LoadMetadata();
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
示例#24
0
        public static GetMetadataResponse CallGetMetadata(GetMetadataRequest request)
        {
            var response = new GetMetadataResponse();

            try
            {
                var tssFactory = TimeseriesSourceFactory.Factory;

                //TODO [jc]: what do we do with the requestmetadata?
                response.Responsemetadata.Add(request.Requestmetadata);
                response.Metadataheaders.Add(request.Metadataheaders);

                foreach (var ssKey in request.Keys)
                {
                    var tsList = tssFactory[ssKey.Sourcename].GetMetadata(
                        new[] { new TimeseriesKey(ssKey.Seriesname) },
                        request.Metadataheaders);

                    foreach (var ts in tsList)
                    {
                        var m = new MetadataList
                        {
                            Key = new SourceSeriesKey()
                            {
                                Sourcename = ts.SourceKey.Key.ToString(),
                                Seriesname = ts.SeriesKey.Key
                            }
                        };
                        m.Values.AddRange(ts.Metadata.Values);
                        response.Seriesdata.Add(m);
                    }
                }
            }
            catch (Exception ex)
            {
                IOCContainer.Logger.Error(ex.Message);
                throw;
            }
            IOCContainer.Logger.Info($"GetMetadataResponse: {response.Seriesdata.Count} series found");
            return(response);
        }
示例#25
0
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            MetadataNamespace database = objects.Parent.Database;
            MetadataNamespace schema   = objects.Parent.Schema;

            if (objects.Parent.Server == null && database != null && schema != null)
            {
                if (!Connected)
                {
                    Connect();
                }

                try
                {
                    string[] restrictions = new string[2];
                    restrictions[0] = database.Name;
                    restrictions[1] = schema.Name;

                    using (DataTable schemaTable = _connection.GetSchema("Tables", restrictions))
                    {
                        MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);

                        mof.Datatable     = schemaTable;
                        mof.NameFieldName = "TABLE_NAME";

                        mof.TypeFieldName = "TABLE_TYPE";
                        mof.TableType     = "BASE TABLE";
                        mof.ViewType      = "VIEW";

                        mof.DefaultObjectType = MetadataType.Table;

                        mof.LoadMetadata();
                    }
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
        public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions)
        {
            MetadataItem obj = foreignKeys.Parent.Object;

            if (obj.Server == null)
            {
                MetadataItem schema   = obj.Schema;
                MetadataItem database = obj.Database;

                try
                {
                    string[] restrictions = new string[6];
                    restrictions[3] = database != null ? database.Name : null;
                    restrictions[4] = schema != null ? schema.Name : null;
                    restrictions[5] = obj.Name;

                    DataTable schemaTable = _connection.GetSchema("ForeignKeys", restrictions);

                    if (schemaTable.Columns.Contains("PKTABLE_NAME") && schemaTable.Columns.Contains("PKCOLUMN_NAME") && schemaTable.Columns.Contains("FKCOLUMN_NAME"))
                    {
                        MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions);

                        mrf.PkDatabaseFieldName = "PKTABLE_CAT";
                        mrf.PkSchemaFieldName   = "PKTABLE_SCHEM";
                        mrf.PkNameFieldName     = "PKTABLE_NAME";
                        mrf.PkFieldName         = "PKCOLUMN_NAME";
                        mrf.FkFieldName         = "FKCOLUMN_NAME";
                        mrf.OrdinalFieldName    = "KEY_SEQ";
                        mrf.Datatable           = schemaTable;

                        mrf.LoadMetadata();
                    }
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
        public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            MetadataItem obj      = foreignKeys.Parent.Object;
            MetadataItem schema   = obj.Schema;
            MetadataItem database = obj.Database;

            try
            {
                string[] restrictions = new string[6];
                restrictions[3] = database != null ? database.Name : null;
                restrictions[4] = schema != null ? schema.Name : null;
                restrictions[5] = obj.Name;

                DataTable schemaTable = _connection.GetSchema(DB2MetaDataCollectionNames.ForeignKeys, restrictions);

                MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions);

                mrf.PkSchemaFieldName   = "PKTABLE_SCHEMA";
                mrf.PkDatabaseFieldName = "PKTABLE_CATALOG";
                mrf.PkNameFieldName     = "PKTABLE_NAME";
                mrf.FkFieldName         = "FKTABLE_NAME";
                mrf.PkFieldName         = "PKCOLUMN_NAME";
                mrf.FkFieldName         = "FKCOLUMN_NAME";
                mrf.OrdinalFieldName    = "KEY_SEQ";
                mrf.Datatable           = schemaTable;

                mrf.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
示例#28
0
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            try
            {
                // load tables
                DataTable schemaTable = _connection.GetSchema("Tables");

                MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                mof.NameFieldName   = "TABLE_NAME";
                mof.TypeFieldName   = "TABLE_TYPE";
                mof.TableType       = new string[] { "TABLE" };
                mof.SystemTableType = new string[] { "SYSTEM TABLE" };
                mof.Datatable       = schemaTable;

                mof.LoadMetadata();

                // load views
                schemaTable = _connection.GetSchema("Views");

                mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);

                mof.NameFieldName     = "TABLE_NAME";
                mof.DefaultObjectType = MetadataType.View;
                mof.Datatable         = schemaTable;

                mof.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
示例#29
0
        public override void LoadFields(MetadataList fields, MetadataLoadingOptions loadingOptions)
        {
            MetadataItem      obj      = fields.Parent.Object;
            MetadataNamespace schema   = obj.Schema;
            MetadataNamespace database = obj.Database;

            if (schema != null && database != null && obj.Server == null)
            {
                string[] restrictions = new string[3];
                restrictions[0] = database.Name;
                restrictions[1] = schema.Name;
                restrictions[2] = obj.Name;

                using (DataTable dataTable = _connection.GetSchema("Columns", restrictions))
                {
                    MetadataFieldsFetcherFromDatatable mff = new MetadataFieldsFetcherFromDatatable(fields.SQLContext);

                    mff.Datatable = dataTable;

                    mff.NameFieldName = "COLUMN_NAME";

                    mff.NullableFieldName = "IS_NULLABLE";
                    mff.NullableValue     = "YES";

                    mff.ServerTypeFieldName = "DATA_TYPE";
                    mff.SizeFieldName       = "CHARACTER_MAXIMUM_LENGTH";
                    mff.PrecisionFieldName  = "NUMERIC_PRECISION";
                    mff.ScaleFieldName      = "NUMERIC_SCALE";

                    mff.DefaultValueFieldName = "COLUMN_DEFAULT";

                    mff.LoadFields(fields);
                }

                base.LoadFields(fields, loadingOptions);
            }
        }
示例#30
0
        public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }
            try
            {
                MetadataNamespacesFetcherFromDatatable mnf = new MetadataNamespacesFetcherFromDatatable(databases, MetadataType.Database, loadingOptions);
                mnf.NameFieldName = "TABLE_CAT";

                using (DataTable schemaTable = _connection.GetSchema("Tables"))
                {
                    // pre-ODBC v3
                    if (schemaTable.Columns.IndexOf("TABLE_CAT") == -1)
                    {
                        // ODBC v2
                        if (schemaTable.Columns.IndexOf("TABLE_QUALIFIER") != -1)
                        {
                            mnf.NameFieldName = "TABLE_QUALIFIER";
                        }
                        // ODBC v1?
                        else if (schemaTable.Columns.IndexOf("QUALIFIERNAME") != -1)
                        {
                            mnf.NameFieldName = "QUALIFIERNAME";
                        }
                    }

                    mnf.Datatable = schemaTable;
                    mnf.LoadMetadata();
                }
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
示例#31
0
        public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions)
        {
            if (databases.Parent.Server == null)
            {
                if (!Connected)
                {
                    Connect();
                }

                string currentDatabase = Connection.Database;
                if (!String.IsNullOrEmpty(currentDatabase))
                {
                    MetadataNamespace database = databases.FindItem <MetadataNamespace>(currentDatabase, MetadataType.Database);
                    if (database == null)
                    {
                        database      = new MetadataNamespace(databases, MetadataType.Database);
                        database.Name = currentDatabase;
                        databases.Add(database);
                    }

                    database.Default = true;
                }
            }
        }
示例#32
0
        public void testListObjectsWithMetadata()
        {
            // Create an object
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata("listable", "foo", true);
            Metadata unlistable = new Metadata("unlistable", "bar", false);
            Metadata listable2 = new Metadata("listable2", "foo2 foo2", true);
            Metadata unlistable2 = new Metadata("unlistable2", "bar2 bar2", false);
            mlist.AddMetadata(listable);
            mlist.AddMetadata(unlistable);
            mlist.AddMetadata(listable2);
            mlist.AddMetadata(unlistable2);
            ObjectId id = this.esu.CreateObject(null, mlist, null, null);
            Assert.IsNotNull(id, "null ID returned");
            cleanup.Add(id);

            // List the objects.  Make sure the one we created is in the list
            ListOptions options = new ListOptions();
            options.IncludeMetadata = true;
            List<ObjectResult> objects = this.esu.ListObjects("listable", options);
            Assert.IsTrue(objects.Count > 0, "No objects returned");

            bool found = false;
            foreach (ObjectResult or in objects)
            {
                if (or.Id.Equals(id))
                {
                    found = true;
                    //Test metadata value
                    Assert.AreEqual("foo", or.meta.GetMetadata("listable").Value, "Metadata value wrong");
                }
            }

            Assert.IsTrue(found, "object not found in list");

            
        }
示例#33
0
        /// <summary>
        /// Updates an object in the cloud.
        /// </summary>
        /// <param name="id">The ID of the object to update</param>
        /// <param name="acl">Access control list for the new object. Optional, set to NULL to leave the ACL unchanged.</param>
        /// <param name="metadata">Metadata list for the new object.  Optional, set to NULL for no changes to the metadata.</param>
        /// <param name="extent">portion of the object to update.  May be null to indicate the whole object is to be replaced.  If not null, the extent size must match the data size.</param>
        /// <param name="data">The initial contents of the object.  Note that we only read 'streamLength' bytes from the stream and do not close the stream.</param>
        /// <param name="streamLength">The number of bytes to read from the stream.  Must be &lt;= the actual stream length.</param>
        /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
        /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
        public void UpdateObjectFromStream(Identifier id, Acl acl, MetadataList metadata, Extent extent, Stream data, long streamLength, string mimeType, Checksum checksum)
        {
            HttpWebResponse resp = null;
            try
            {
                string resource = getResourcePath(context, id);
                Uri u = buildUrl(resource);
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                // Figure out the mimetype
                if (mimeType == null)
                {
                    mimeType = "application/octet-stream";
                }

                headers.Add("Content-Type", mimeType);
                headers.Add("x-emc-uid", uid);
                if (id is ObjectKey) {
                    headers.Add("x-emc-pool", (id as ObjectKey).pool);
                }

                //Add extent if needed
                if (extent != null && !extent.Equals(Extent.ALL_CONTENT))
                {
                    long end = extent.Offset + (extent.Size - 1);
                    headers.Add("Range", "Bytes=" + extent.Offset + "-" + end);
                }

                // Process metadata
                if (metadata != null)
                {
                    processMetadata(metadata, headers);
                }

                // Add acl
                if (acl != null)
                {
                    processAcl(acl, headers);
                }

                // Add date
                addDateHeader(headers);

                // Checksum if required
                if (checksum != null)
                {
                    if (!data.CanSeek)
                    {
                        throw new EsuException("Cannot checksum a stream that does not support seeking");
                    }
                    long current = data.Position;
                    byte[] buffer = new byte[64 * 1024];
                    for (long i = 0; i < streamLength; i += buffer.Length)
                    {
                        if (i + buffer.Length > streamLength)
                        {
                            int bytesToRead = (int)(streamLength - i);
                            int count = data.Read(buffer, 0, bytesToRead);
                            checksum.Update(new ArraySegment<byte>(buffer, 0, count));
                        }
                        else
                        {
                            int count = data.Read(buffer, 0, buffer.Length);
                            checksum.Update(new ArraySegment<byte>(buffer, 0, count));
                        }
                    }
                    data.Seek(current, SeekOrigin.Begin);

                    //Checksum ckcopy = checksum.Clone();
                    headers.Add("x-emc-wschecksum", checksum.ToString());
                }

                // Sign request
                signRequest(con, "PUT", resource, headers);

                // post data
                writeRequestBodyFromStream(con, data, streamLength);

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if (statInt > 299)
                {
                    handleError(resp);
                }

            }
            catch (UriFormatException e)
            {
                throw new EsuException("Invalid URL", e);
            }
            catch (IOException e)
            {
                throw new EsuException("Error connecting to server", e);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if (resp != null)
                {
                    resp.Close();
                }
            }
        }
示例#34
0
 /// <summary>
 /// Creates a new object on the server with the contents of the given file,
 /// acl and metadata.
 /// </summary>
 /// <param name="path">The ObjectPath to create the new object on.</param>
 /// <param name="file">the path to the file to upload</param>
 /// <param name="acl">the ACL to assign to the new object.  Optional.  If null,
 /// the server will generate a default ACL for the file.</param>
 /// <param name="meta">The metadata to assign to the new object.
 /// Optional.  If null, no user metadata will be assigned to the new object.</param>
 /// <returns>the identifier of the newly-created object.</returns>
 public ObjectId CreateObjectOnPath(ObjectPath path, string file, Acl acl, MetadataList meta)
 {
     Stream s;
     // Open the file and call the streaming version
     try
     {
         totalBytes = new FileInfo(file).Length;
         s = File.OpenRead(file);
     }
     catch (FileNotFoundException e)
     {
         throw new EsuException("Could not open input file", e);
     }
     return CreateObjectOnPath(path, s, acl, meta, true);
 }
示例#35
0
        public void testListObjects()
        {
            // Create an object
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata("listable", "foo", true);
            Metadata unlistable = new Metadata("unlistable", "bar", false);
            Metadata listable2 = new Metadata("listable2", "foo2 foo2", true);
            Metadata unlistable2 = new Metadata("unlistable2", "bar2 bar2", false);
            mlist.AddMetadata(listable);
            mlist.AddMetadata(unlistable);
            mlist.AddMetadata(listable2);
            mlist.AddMetadata(unlistable2);
            ObjectId id = this.esu.CreateObject(null, mlist, null, null);
            Assert.IsNotNull(id, "null ID returned");
            cleanup.Add(id);

            // List the objects.  Make sure the one we created is in the list
            List<ObjectResult> objects = this.esu.ListObjects("listable", null);
            Assert.IsTrue(objects.Count > 0, "No objects returned");
            Assert.IsTrue(containsId(objects, id), "object not found in list");

            // Check for unlisted
            try
            {
                this.esu.ListObjects("unlistable", null);
                Assert.Fail("Exception not thrown!");
            }
            catch (EsuException e)
            {
                // This should happen.
                Assert.AreEqual(1003, e.Code, "Expected 1003 for not found");
            }
        }
示例#36
0
 /// <summary>
 /// Creates a new object in the cloud using a BufferSegment on the
 /// given path.
 /// </summary>
 /// <param name="path">the path to create the object on.</param>
 /// <param name="acl">Access control list for the new object.  May be null to use a default ACL</param>
 /// <param name="metadata">Metadata for the new object.  May be null for no metadata.</param>
 /// <param name="data">The initial contents of the object.  May be appended to later.  May be null to create an object with no content or a directory.</param>
 /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
 /// <returns>the ObjectId of the newly-created object for references by ID.</returns>
 public ObjectId CreateObjectFromSegmentOnPath(ObjectPath path,
     Acl acl, MetadataList metadata,
     ArraySegment<byte> data, String mimeType)
 {
     return CreateObjectFromSegmentOnPath(path, acl, metadata, data, mimeType, null);
 }
示例#37
0
        /// <summary>
        /// Creates a new object in the cloud with the given key (and key-pool).
        /// </summary>
        /// <param name="key">the key-pool and key to use for the new object.</param>
        /// <param name="acl">Access control list for the new object.  May be null to use a default ACL</param>
        /// <param name="metadata">Metadata for the new object.  May be null for no metadata.</param>
        /// <param name="data">The initial contents of the object.  May be appended to later.  May be null to create an object with no content or a directory.</param>
        /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
        /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
        /// <returns>the ObjectId of the newly-created object for references by ID.</returns>
        public ObjectId CreateObjectFromSegmentWithKey(ObjectKey key, Acl acl, MetadataList metadata, ArraySegment<byte> data,
            String mimeType, Checksum checksum)
        {
            HttpWebResponse resp = null;
            try
            {
                string resource = getResourcePath(context, key);
                Uri u = buildUrl(resource);
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                // Figure out the mimetype
                if (mimeType == null)
                {
                    mimeType = "application/octet-stream";
                }

                headers.Add("Content-Type", mimeType);
                headers.Add("x-emc-uid", uid);
                headers.Add("x-emc-pool", key.pool);

                // Process metadata
                if (metadata != null)
                {
                    processMetadata(metadata, headers);
                }

                // Add acl
                if (acl != null)
                {
                    processAcl(acl, headers);
                }

                // Add date
                addDateHeader(headers);

                // Checksum if required
                if (checksum != null)
                {
                    checksum.Update(data);
                    headers.Add("x-emc-wschecksum", checksum.ToString());
                }

                // Sign request
                signRequest(con, "POST", resource, headers);

                // post data
                Stream s = null;
                try
                {
                    con.ContentLength = data.Count;
                    con.SendChunked = false;
                    s = con.GetRequestStream();
                    s.Write(data.Array, data.Offset, data.Count);
                    s.Close();
                }
                catch (IOException e)
                {
                    s.Close();
                    throw new EsuException("Error posting data", e);
                }

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if (statInt > 299)
                {
                    handleError(resp);
                }

                // The new object ID is returned in the location response header
                string location = resp.Headers["location"];

                // Parse the value out of the URL

                MatchCollection m = OBJECTID_EXTRACTOR.Matches(location);
                if (m.Count > 0)
                {
                    string id = m[0].Groups[1].Value;
                    log.TraceEvent(TraceEventType.Verbose, 0, "Id: " + id);
                    return new ObjectId(id);
                }
                else
                {
                    throw new EsuException("Could not find ObjectId in " + location);
                }
            }
            catch (UriFormatException e)
            {
                throw new EsuException("Invalid URL", e);
            }
            catch (IOException e)
            {
                throw new EsuException("Error connecting to server", e);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if (resp != null)
                {
                    resp.Close();
                }
            }
            return null;
        }
示例#38
0
        /// <summary>
        /// Returns all of an object's metadata and its ACL in
        /// one call.
        /// </summary>
        /// <param name="id">the object's identifier.</param>
        /// <returns>the object's metadata</returns>
        public ObjectMetadata GetAllMetadata( Identifier id )
        {
            HttpWebResponse resp = null;
            try {
                string resource = getResourcePath(context, id);
                Uri u = buildUrl(resource);
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                headers.Add("x-emc-uid", uid);
                if (utf8Enabled) headers.Add("x-emc-utf8", "true");
                if (id is ObjectKey) {
                    headers.Add("x-emc-pool", (id as ObjectKey).pool);
                }

                // Add date
                addDateHeader(headers);

                // Sign request
                signRequest(con, "HEAD", resource, headers);

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if (statInt > 299) {
                    handleError(resp);
                }

                // Parse return headers.  Regular metadata is in x-emc-meta and
                // listable metadata is in x-emc-listable-meta
                MetadataList meta = new MetadataList();
                readMetadata(meta, resp.Headers["x-emc-meta"], false);
                readMetadata(meta, resp.Headers["x-emc-listable-meta"], true);

                // Parse return headers.  User grants are in x-emc-useracl and
                // group grants are in x-emc-groupacl
                Acl acl = new Acl();
                readAcl(acl, resp.Headers["x-emc-useracl"], Grantee.GRANTEE_TYPE.USER);
                readAcl(acl, resp.Headers["x-emc-groupacl"], Grantee.GRANTEE_TYPE.GROUP);

                ObjectMetadata om = new ObjectMetadata();
                om.ACL = acl;
                om.Metadata = meta;

                return om;

            } catch (UriFormatException e) {
                throw new EsuException("Invalid URL", e);
            } catch (IOException e) {
                throw new EsuException("Error connecting to server", e);
            } catch (WebException e) {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if (resp != null) {
                    resp.Close();
                }
            }
            return null;
        }
示例#39
0
        private void processMetadata( MetadataList metadata, Dictionary<string, string> headers )
        {
            StringBuilder listable = new StringBuilder();
            StringBuilder nonListable = new StringBuilder();

            log.TraceEvent(TraceEventType.Verbose, 0,  "Processing " + metadata.Count() + " metadata entries" );

            foreach( Metadata meta in metadata ) {
                if( meta.Listable ) {
                    if( listable.Length > 0 ) {
                        listable.Append( ", " );
                    }
                    listable.Append( formatTag( meta ) );
                } else {
                    if( nonListable.Length > 0 ) {
                        nonListable.Append( ", " );
                    }
                    nonListable.Append( formatTag( meta ) );
                }
            }

            // Only set the headers if there's data
            if( listable.Length > 0 ) {
                headers.Add( "x-emc-listable-meta", listable.ToString() );
            }
            if( nonListable.Length > 0 ) {
                headers.Add( "x-emc-meta", nonListable.ToString() );
            }
            if (utf8Enabled && !headers.ContainsKey("x-emc-utf8")) {
                headers.Add("x-emc-utf8", "true");
            }
        }
示例#40
0
        /// <summary>
        /// Creates a new object on the server with the contents of the given stream,
        /// acl and metadata.
        /// </summary>
        /// <param name="path">The ObjectPath to create the object on.</param>
        /// <param name="stream">the stream to upload.  The stream will be read until
        /// an EOF is encountered.</param>
        /// <param name="acl">the ACL to assign to the new object.  Optional.  If null,
        /// the server will generate a default ACL for the file.</param>
        /// <param name="metadata">The metadata to assign to the new object.
        /// Optional.  If null, no user metadata will be assigned to the new object.</param>
        /// <param name="closeStream">if true, the stream will be closed after
        /// the transfer completes.  If false, the stream will not be closed.</param>
        /// <returns>the identifier of the newly-created object.</returns>
        public ObjectId CreateObjectOnPath(ObjectPath path, Stream stream, Acl acl,
                MetadataList metadata, bool closeStream)
        {

            this.currentBytes = 0;
            this.complete = false;
            this.failed = false;
            this.error = null;
            this.closeStream = closeStream;
            this.stream = stream;

            if (computeChecksums)
            {
                checksum = new Checksum(Checksum.Algorithm.SHA0);
            }
            else
            {
                checksum = null;
            }

            ObjectId id = null;

            // First call should be to create object
            try
            {
                bool eof = ReadChunk();
                id = this.esu.CreateObjectFromSegmentOnPath(path, acl, metadata, buffer, contentType, checksum);
                if (!eof)
                {
                    this.OnProgress(buffer.Count);
                }
                else
                {
                    // No data in file? Complete
                    this.OnComplete();
                    return id;
                }

                // Continue appending
                this.AppendChunks(path);

            }
            catch (EsuException e)
            {
                this.OnFail(e);
                throw e;
            }
            catch (IOException e)
            {
                this.OnFail(e);
                throw new EsuException("Error uploading object", e);
            }

            return id;
        }
示例#41
0
 /// <summary>
 /// Creates a new object in the cloud with the given key (and key-pool).
 /// </summary>
 /// <param name="key">the key-pool and key to use for the new object.</param>
 /// <param name="acl">Access control list for the new object.  May be null to use a default ACL</param>
 /// <param name="metadata">Metadata for the new object.  May be null for no metadata.</param>
 /// <param name="data">The initial contents of the object.  May be appended to later.  May be null to create an object with no content or a directory.</param>
 /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
 /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
 /// <returns>the ObjectId of the newly-created object for references by ID.</returns>
 public ObjectId CreateObjectWithKey(ObjectKey key, Acl acl, MetadataList metadata, byte[] data,
     String mimeType, Checksum checksum)
 {
     return CreateObjectFromSegmentWithKey(key, acl, metadata, new ArraySegment<byte>(data, 0, data.Length), mimeType, checksum);
 }
示例#42
0
        public void testListObjectsPaged()
        {
            // Create an object
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata("listable", "foo", true);
            Metadata unlistable = new Metadata("unlistable", "bar", false);
            Metadata listable2 = new Metadata("listable2", "foo2 foo2", true);
            Metadata unlistable2 = new Metadata("unlistable2", "bar2 bar2", false);
            mlist.AddMetadata(listable);
            mlist.AddMetadata(unlistable);
            mlist.AddMetadata(listable2);
            mlist.AddMetadata(unlistable2);
            ObjectId id = this.esu.CreateObject(null, mlist, null, null);
            ObjectId id2 = this.esu.CreateObject(null, mlist, null, null);
            Assert.IsNotNull(id, "null ID returned");
            cleanup.Add(id);
            cleanup.Add(id2);

            // List the objects.  Make sure the one we created is in the list
            ListOptions options = new ListOptions();
            options.Limit = 1;
            List<ObjectResult> objects = this.esu.ListObjects("listable", options);
            while (options.Token != null)
            {
                Debug.WriteLine("Continuing results with token " + options.Token);
                objects.AddRange(this.esu.ListObjects("listable", options));
            }
            Assert.IsTrue(objects.Count > 0, "No objects returned");
            Assert.IsTrue(containsId(objects, id), "object not found in list");
            Assert.IsTrue(containsId(objects, id2), "object2 not found in list");
        }
示例#43
0
 /// <summary>
 /// Updates an existing object with the contents of the given file, ACL, and
 /// metadata.
 /// </summary>
 /// <param name="id">the identifier of the object to update.</param>
 /// <param name="file">the path to the file to replace the object's current
 /// contents with</param>
 /// <param name="acl">the ACL to update the object with.  Optional.  If null,
 /// the ACL will not be modified.</param>
 /// <param name="metadata">The metadata to assign to the object.
 /// Optional.  If null, no user metadata will be modified.</param>
 public void UpdateObject( Identifier id, string file, Acl acl, MetadataList metadata ) {
     // Open the file and call the streaming version
     Stream s;
     try {
         s = File.OpenRead( file );
     } catch ( FileNotFoundException e ) {
         throw new EsuException( "Could not open input file", e );
     }
     totalBytes = new FileInfo( file ).Length;
     UpdateObject( id, s, acl, metadata, true );
 }
示例#44
0
        /// <summary>
        /// Updates an existing object with the contents of the given stream, ACL, and
        /// metadata.
        /// </summary>
        /// <param name="id">the identifier of the object to update.</param>
        /// <param name="stream">the stream to replace the object's current
        /// contents with.  The stream will be read until an EOF is encountered.</param>
        /// <param name="acl">the ACL to update the object with.  Optional.  If not
        /// specified, the ACL will not be modified.</param>
        /// <param name="metadata">The metadata to assign to the object.
        /// Optional.  If null, no user metadata will be modified.</param>
        /// <param name="closeStream">If true, the stream will be closed after
        /// the object is updated.</param>
        public void UpdateObject( Identifier id, Stream stream, Acl acl,
                MetadataList metadata, bool closeStream ) {

            this.currentBytes = 0;
            this.complete = false;
            this.failed = false;
            this.error = null;
            this.closeStream = closeStream;
            this.stream = stream;

            if (computeChecksums)
            {
                checksum = new Checksum(Checksum.Algorithm.SHA0);
            }
            else
            {
                checksum = null;
            }

            // First call uses a null extent to truncate the file.
            try {
                bool eof = ReadChunk();
                this.esu.UpdateObjectFromSegment( id, acl, metadata, null, buffer,
                        contentType, checksum );

                if ( !eof ) {
                    this.OnProgress( buffer.Count );
                } else {
                    // No data in file? Complete
                    this.OnComplete();
                    return;
                }

                // Continue appending
                this.AppendChunks( id );

            } catch ( EsuException e ) {
                this.OnFail( e );
                throw e;
            } catch ( IOException e ) {
                this.OnFail( e );
                throw new EsuException( "Error updating object", e );
            }

        }
示例#45
0
 /// <summary>
 /// Creates a new object in the cloud.
 /// </summary>
 /// <param name="acl">Access control list for the new object.  May be null to use a default ACL</param>
 /// <param name="metadata">Metadata for the new object.  May be null for no metadata.</param>
 /// <param name="data">The initial contents of the object.  May be appended to later.  May be null to create an object with no content.</param>
 /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
 /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
 /// <returns>Identifier of the newly created object.</returns>
 public ObjectId CreateObject(Acl acl, MetadataList metadata, byte[] data, string mimeType, Checksum checksum)
 {
     return CreateObjectFromSegment(acl, metadata,
         data == null ? new ArraySegment<byte>(new byte[0]) : new ArraySegment<byte>(data),
         mimeType, checksum);
 }
示例#46
0
        /// <summary>
        /// Fetches the user metadata for the object.
        /// </summary>
        /// <param name="id">the identifier of the object whose user metadata to fetch.</param>
        /// <param name="tags">A list of user metadata tags to fetch.  Optional.  If null, all user metadata will be fetched.</param>
        /// <returns>The list of user metadata for the object.</returns>
        public MetadataList GetUserMetadata( Identifier id, MetadataTags tags )
        {
            HttpWebResponse resp = null;
            try {
                string resource = getResourcePath(context, id) + "?metadata/user";
                Uri u = buildUrl( resource );
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                headers.Add( "x-emc-uid", uid );
                if (utf8Enabled) headers.Add("x-emc-utf8", "true");
                if (id is ObjectKey) {
                    headers.Add("x-emc-pool", (id as ObjectKey).pool);
                }

                // Add tags if needed
                if( tags != null ) {
                    processTags( tags, headers );
                }

                // Add date
                addDateHeader(headers);

                // Sign request
                signRequest( con, "GET", resource, headers );

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if( statInt > 299 ) {
                    handleError( resp );
                }

                // Parse return headers.  Regular metadata is in x-emc-meta and
                // listable metadata is in x-emc-listable-meta
                MetadataList meta = new MetadataList();
                readMetadata( meta, resp.Headers["x-emc-meta"], false );
                readMetadata( meta, resp.Headers["x-emc-listable-meta"], true );

                return meta;

            } catch( UriFormatException e ) {
                throw new EsuException( "Invalid URL", e );
            } catch( IOException e ) {
                throw new EsuException( "Error connecting to server", e );
            } catch( WebException e ) {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if( resp != null ) {
                    resp.Close();
                }
            }
            return null;
        }
示例#47
0
 /// <summary>
 /// Creates a new object in the cloud using an ArraySegment.
 /// </summary>
 /// <param name="acl">Access control list for the new object.  May be null to use a default ACL</param>
 /// <param name="metadata">Metadata for the new object.  May be null for no metadata.</param>
 /// <param name="data">The initial contents of the object.  May be appended to later.  May be null to create an object with no content.</param>
 /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
 /// <returns>Identifier of the newly created object.</returns>
 public ObjectId CreateObjectFromSegment(Acl acl, MetadataList metadata, ArraySegment<byte> data, string mimeType)
 {
     return CreateObjectFromSegment(acl, metadata, data, mimeType, null);
 }
示例#48
0
        /// <summary>
        /// Fetches object content as a stream
        /// </summary>
        /// <param name="id">the identifier of the object whose content to read.</param>
        /// <param name="extent">the portion of the object data to read.  Optional.  If null, the entire object will be read.</param>
        /// <returns></returns>
        public ReadObjectStreamResponse ReadObjectStream(Identifier id, Extent extent)
        {
            HttpWebResponse resp = null;
            try
            {
                string resource = getResourcePath(context, id);
                Uri u = buildUrl(resource);
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                headers.Add("x-emc-uid", uid);
                if (id is ObjectKey) {
                    headers.Add("x-emc-pool", (id as ObjectKey).pool);
                }

                //Add extent if needed
                if (extent != null && !extent.Equals(Extent.ALL_CONTENT))
                {
                    long end = extent.Offset + (extent.Size - 1);
                    headers.Add("Range", "Bytes=" + extent.Offset + "-" + end);
                }

                // Add date
                addDateHeader(headers);

                // Sign request
                signRequest(con, "GET", resource, headers);

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if (statInt > 299)
                {
                    handleError(resp);
                }

                string contentChecksum = resp.Headers["x-emc-wschecksum"];

                // Parse return headers.  Regular metadata is in x-emc-meta and
                // listable metadata is in x-emc-listable-meta
                MetadataList meta = new MetadataList();
                readMetadata(meta, resp.Headers["x-emc-meta"], false);
                readMetadata(meta, resp.Headers["x-emc-listable-meta"], true);

                // Parse return headers.  User grants are in x-emc-useracl and
                // group grants are in x-emc-groupacl
                Acl acl = new Acl();
                readAcl(acl, resp.Headers["x-emc-useracl"], Grantee.GRANTEE_TYPE.USER);
                readAcl(acl, resp.Headers["x-emc-groupacl"], Grantee.GRANTEE_TYPE.GROUP);

                long streamLength = resp.ContentLength;

                return new ReadObjectStreamResponse(resp.GetResponseStream(), resp.ContentType,
                    streamLength, meta, acl, extent, resp, contentChecksum);
            }
            catch (UriFormatException e)
            {
                throw new EsuException("Invalid URL", e);
            }
            catch (IOException e)
            {
                if (resp != null)
                {
                    resp.Close();
                }
                throw new EsuException("Error connecting to server", e);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                    if (resp != null)
                    {
                        resp.Close();
                    }
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }

            return null;
        }
示例#49
0
        private void readMetadata( MetadataList meta, string header, bool listable )
        {
            if( header == null ) {
                return;
            }

            string[] attrs = header.Split( new string[] { "," }, StringSplitOptions.RemoveEmptyEntries );
            for( int i = 0; i < attrs.Length; i++ ) {
                string[] nvpair = attrs[i].Split( new string[] { "=" }, 2, StringSplitOptions.RemoveEmptyEntries );
                string name = nvpair[0];
                string value = "";
                if (nvpair.Length > 1)
                {
                    value = nvpair[1];
                }

                name = name.Trim();

                if (utf8Enabled)
                {
                    name = utf8Decode(name);
                    value = utf8Decode(value);
                }

                Metadata m = new Metadata( name, value, listable );
                log.TraceEvent(TraceEventType.Verbose, 0,  "Meta: " + m );
                meta.AddMetadata( m );
            }
        }
示例#50
0
        /// <summary>
        /// Writes the metadata into the object. If the tag does not exist, it is created and set to the corresponding value. If the tag exists, the existing value is replaced. 
        /// </summary>
        /// <param name="id">The identifier of the object to update</param>
        /// <param name="metadata">Metadata to write to the object.</param>
        public void SetUserMetadata( Identifier id, MetadataList metadata )
        {
            HttpWebResponse resp = null;
            try {
                string resource = getResourcePath(context, id) + "?metadata/user";
                Uri u = buildUrl( resource );
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                headers.Add( "x-emc-uid", uid );
                if (id is ObjectKey) {
                    headers.Add("x-emc-pool", (id as ObjectKey).pool);
                }

                // Process metadata
                if( metadata != null ) {
                    processMetadata( metadata, headers );
                }

                // Add date
                addDateHeader(headers);

                // Sign request
                signRequest( con, "POST", resource, headers );

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if( statInt > 299 ) {
                    handleError( resp );
                }

            } catch( UriFormatException e ) {
                throw new EsuException( "Invalid URL", e );
            } catch( IOException e ) {
                throw new EsuException( "Error connecting to server", e );
            } catch( WebException e ) {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if( resp != null ) {
                    resp.Close();
                }
            }
        }
示例#51
0
 /// <summary>
 /// Creates a new object in the cloud with the given key (and key-pool).
 /// </summary>
 /// <param name="key">the key-pool and key to use for the new object.</param>
 /// <param name="acl">Access control list for the new object.  May be null to use a default ACL</param>
 /// <param name="metadata">Metadata for the new object.  May be null for no metadata.</param>
 /// <param name="data">The initial contents of the object.  May be appended to later.  May be null to create an object with no content or a directory.</param>
 /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
 /// <returns>the ObjectId of the newly-created object for references by ID.</returns>
 public ObjectId CreateObjectFromSegmentWithKey(ObjectKey key, Acl acl, MetadataList metadata,
     ArraySegment<byte> data, String mimeType)
 {
     return CreateObjectFromSegmentWithKey(key, acl, metadata, data, mimeType, null);
 }
示例#52
0
        public void testGetListableTags() {
            // Create an object
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata( "listable", "foo", true );
            Metadata unlistable = new Metadata( "unlistable", "bar", false );
            Metadata listable2 = new Metadata( "list/able/2", "foo2 foo2", true );
            Metadata unlistable2 = new Metadata( "list/able/not", "bar2 bar2", false );
            mlist.AddMetadata( listable );
            mlist.AddMetadata( unlistable );
            mlist.AddMetadata( listable2 );
            mlist.AddMetadata( unlistable2 );
            ObjectId id = this.esu.CreateObject( null, mlist, null, null );
            Assert.IsNotNull( id,"null ID returned" );
            cleanup.Add( id );

            // List tags.  Ensure our object's tags are in the list.
            MetadataTags tags = this.esu.GetListableTags( (string)null );
            Assert.IsTrue( tags.Contains( "listable" ), "listable tag not returned" );
            Assert.IsTrue( tags.Contains( "list" ), "list/able/2 root tag not returned" );
            Assert.IsFalse( tags.Contains( "list/able/not" ), "list/able/not tag returned" );

            // List child tags
            tags = this.esu.GetListableTags( "list/able" );
            Assert.IsFalse( tags.Contains( "listable" ), "non-child returned" );
            Assert.IsTrue( tags.Contains( "2" ), "list/able/2 tag not returned" );
            Assert.IsFalse( tags.Contains( "not" ), "list/able/not tag returned" );

        }
示例#53
0
        /// <summary>
        /// Creates a new object in the cloud reading the content a Stream.
        /// </summary>
        /// <param name="path">The path to create the new object on</param>
        /// <param name="acl">Access control list for the new object.  May be null to use a default ACL</param>
        /// <param name="metadata">Metadata for the new object.  May be null for no metadata.</param>
        /// <param name="data">The initial contents of the object.  Note that we only read 'streamLength' bytes from the stream and do not close the stream.</param>
        /// <param name="streamLength">The number of bytes to read from the stream.  Must be &lt;= the actual stream length.</param>
        /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
        /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
        /// <returns>Identifier of the newly created object.</returns>
        public ObjectId CreateObjectFromStreamOnPath(ObjectPath path, Acl acl, MetadataList metadata, Stream data, long streamLength, string mimeType, Checksum checksum)
        {
            HttpWebResponse resp = null;
            try
            {
                string resource = getResourcePath(context, path);
                Uri u = buildUrl(resource);
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                // Figure out the mimetype
                if (mimeType == null)
                {
                    mimeType = "application/octet-stream";
                }

                headers.Add("Content-Type", mimeType);
                headers.Add("x-emc-uid", uid);

                // Process metadata
                if (metadata != null)
                {
                    processMetadata(metadata, headers);
                }

                // Add acl
                if (acl != null)
                {
                    processAcl(acl, headers);
                }

                // Add date
                addDateHeader(headers);

                // Checksum if required
                if (checksum != null)
                {
                    if (!data.CanSeek)
                    {
                        throw new EsuException("Cannot checksum a stream that does not support seeking");
                    }
                    long current = data.Position;
                    byte[] buffer = new byte[64 * 1024];
                    for (long i = 0; i < streamLength; i += buffer.Length)
                    {
                        if (i + buffer.Length > streamLength)
                        {
                            int bytesToRead = (int)(streamLength - i);
                            int count = data.Read(buffer, 0, bytesToRead);
                            checksum.Update(new ArraySegment<byte>(buffer, 0, count));
                        }
                        else
                        {
                            int count = data.Read(buffer, 0, buffer.Length);
                            checksum.Update(new ArraySegment<byte>(buffer, 0, count));
                        }
                    }
                    data.Seek(current, SeekOrigin.Begin);

                    //Checksum ckcopy = checksum.Clone();
                    headers.Add("x-emc-wschecksum", checksum.ToString());
                }

                // Sign request
                signRequest(con, "POST", resource, headers);

                writeRequestBodyFromStream(con, data, streamLength);

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if (statInt > 299)
                {
                    handleError(resp);
                }

                // The new object ID is returned in the location response header
                string location = resp.Headers["location"];

                // Parse the value out of the URL

                MatchCollection m = OBJECTID_EXTRACTOR.Matches(location);
                if (m.Count > 0)
                {
                    string id = m[0].Groups[1].Value;
                    log.TraceEvent(TraceEventType.Verbose, 0, "Id: " + id);
                    return new ObjectId(id);
                }
                else
                {
                    throw new EsuException("Could not find ObjectId in " + location);
                }
            }
            catch (UriFormatException e)
            {
                throw new EsuException("Invalid URL", e);
            }
            catch (IOException e)
            {
                throw new EsuException("Error connecting to server", e);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if (resp != null)
                {
                    resp.Close();
                }
            }
            return null;
        }
示例#54
0
        public void testListUserMetadataTags() {
            // Create an object
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata( "listable", "foo", true );
            Metadata unlistable = new Metadata( "unlistable", "bar", false );
            Metadata listable2 = new Metadata( "list/able/2", "foo2 foo2", true );
            Metadata unlistable2 = new Metadata( "list/able/not", "bar2 bar2", false );
            mlist.AddMetadata( listable );
            mlist.AddMetadata( unlistable );
            mlist.AddMetadata( listable2 );
            mlist.AddMetadata( unlistable2 );
            ObjectId id = this.esu.CreateObject( null, mlist, null, null );
            Assert.IsNotNull( id,"null ID returned" );
            cleanup.Add( id );

            // List tags
            MetadataTags tags = this.esu.ListUserMetadataTags( id );
            Assert.IsTrue( tags.Contains( "listable" ), "listable tag not returned" );
            Assert.IsTrue( tags.Contains( "list/able/2" ), "list/able/2 tag not returned" );
            Assert.IsTrue( tags.Contains( "unlistable" ), "unlistable tag not returned" );
            Assert.IsTrue( tags.Contains( "list/able/not" ), "list/able/not tag not returned" );
            Assert.IsFalse( tags.Contains( "unknowntag" ), "unknown tag returned" );

            // Check listable flag
            Assert.IsTrue( tags.GetTag( "listable" ).Listable, "'listable' is not listable" );
            Assert.IsTrue( tags.GetTag( "list/able/2" ).Listable, "'list/able/2' is not listable" );
            Assert.IsFalse( tags.GetTag( "unlistable" ).Listable, "'unlistable' is listable" );
            Assert.IsFalse( tags.GetTag( "list/able/not" ).Listable, "'list/able/not' is listable" );
        }
示例#55
0
        public void testUpdateObjectMetadata() {
            // Create an object
            MetadataList mlist = new MetadataList();
            Metadata unlistable = new Metadata( "unlistable", "foo", false );
            mlist.AddMetadata( unlistable );
            ObjectId id = this.esu.CreateObject( null, mlist, Encoding.UTF8.GetBytes( "hello" ), null );
            Assert.IsNotNull( id,"null ID returned" );
            cleanup.Add( id );

            // Update the metadata
            unlistable.Value = "bar";
            this.esu.SetUserMetadata( id, mlist );

            // Re-read the metadata
            MetadataList meta = this.esu.GetUserMetadata( id, null );
            Assert.AreEqual( "bar", meta.GetMetadata( "unlistable" ).Value, "value of 'unlistable' wrong" );
            
            // Check that content was not modified
            string content = Encoding.UTF8.GetString( this.esu.ReadObject( id, null, null ) );
            Assert.AreEqual( "hello", content, "object content wrong" );

        }
示例#56
0
        /// <summary>
        /// Updates an object in the cloud.
        /// </summary>
        /// <param name="id">The ID of the object to update</param>
        /// <param name="acl">Access control list for the new object. Optional, set to NULL to leave the ACL unchanged.</param>
        /// <param name="metadata">Metadata list for the new object.  Optional, set to NULL for no changes to the metadata.</param>
        /// <param name="extent">portion of the object to update.  May be null to indicate the whole object is to be replaced.  If not null, the extent size must match the data size.</param>
        /// <param name="data">The new contents of the object.  May be appended to later. Optional, set to null for no content changes.</param>
        /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
        /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
        public void UpdateObjectFromSegment(Identifier id, Acl acl, MetadataList metadata, Extent extent, ArraySegment<byte> data, string mimeType, Checksum checksum)
        {
            HttpWebResponse resp = null;
            try {
                string resource = getResourcePath(context, id);
                Uri u = buildUrl( resource );
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                // Figure out the mimetype
                if( mimeType == null ) {
                    mimeType = "application/octet-stream";
                }

                headers.Add( "Content-Type", mimeType );
                headers.Add( "x-emc-uid", uid );
                if (id is ObjectKey) {
                    headers.Add( "x-emc-pool", (id as ObjectKey).pool );
                }

                //Add extent if needed
                if( extent != null && !extent.Equals( Extent.ALL_CONTENT ) ) {
                    long end = extent.Offset + (extent.Size - 1);
                    headers.Add( "Range", "Bytes=" + extent.Offset + "-" + end );
                }

                // Process metadata
                if( metadata != null ) {
                    processMetadata( metadata, headers );
                }

                // Add acl
                if( acl != null ) {
                    processAcl( acl, headers );
                }

                // Add date
                addDateHeader(headers);

                // Checksum if required
                if (checksum != null)
                {
                    checksum.Update(data);
                    headers.Add("x-emc-wschecksum", checksum.ToString());
                }

                // Sign request
                signRequest( con, "PUT", resource, headers );

                // post data
                Stream s = null;
                try {
                    s = con.GetRequestStream();
                    s.Write( data.Array, data.Offset, data.Count );
                    s.Close();
                } catch( IOException e ) {
                    s.Close();
                    throw new EsuException( "Error posting data", e );
                }

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if( statInt > 299 ) {
                    handleError( resp );
                }

            } catch( UriFormatException e ) {
                throw new EsuException( "Invalid URL", e );
            } catch( IOException e ) {
                throw new EsuException( "Error connecting to server", e );
            } catch( WebException e ) {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if( resp != null ) {
                    resp.Close();
                }
            }
        }
示例#57
0
 /// <summary>
 /// Updates an object in the cloud.
 /// </summary>
 /// <param name="id">The ID of the object to update</param>
 /// <param name="acl">Access control list for the new object. Optional, set to NULL to leave the ACL unchanged.</param>
 /// <param name="metadata">Metadata list for the new object.  Optional, set to NULL for no changes to the metadata.</param>
 /// <param name="extent">portion of the object to update.  May be null to indicate the whole object is to be replaced.  If not null, the extent size must match the data size.</param>
 /// <param name="data">The new contents of the object.  May be appended to later. Optional, set to null for no content changes.</param>
 /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
 /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
 public void UpdateObject(Identifier id, Acl acl, MetadataList metadata, Extent extent, byte[] data, string mimeType, Checksum checksum)
 {
     ArraySegment<byte> seg = new ArraySegment<byte>(data == null ? new byte[0] : data);
     UpdateObjectFromSegment(id, acl, metadata, extent, seg, mimeType, checksum);
 }
示例#58
0
        /// <summary>
        /// Test listing the versions of an object
        /// </summary>
        public void testDeleteVersion()
        {
            // Create an object
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata("listable", "foo", true);
            Metadata unlistable = new Metadata("unlistable", "bar", false);
            Metadata listable2 = new Metadata("listable2", "foo2 foo2", true);
            Metadata unlistable2 = new Metadata("unlistable2", "bar2 bar2", false);
            mlist.AddMetadata(listable);
            mlist.AddMetadata(unlistable);
            mlist.AddMetadata(listable2);
            mlist.AddMetadata(unlistable2);
            ObjectId id = this.esu.CreateObject(null, mlist, null, null);
            Assert.IsNotNull(id, "null ID returned");
            cleanup.Add(id);

            // Version the object
            ObjectId vid1 = this.esu.VersionObject(id);
            cleanup.Add(vid1);
            Assert.IsNotNull(vid1, "null version ID returned");
            ObjectId vid2 = this.esu.VersionObject(id);
            cleanup.Add(vid2);
            Assert.IsNotNull(vid2, "null version ID returned");

            // List the versions and ensure their IDs are correct
            List<ObjectId> versions = this.esu.ListVersions(id);
            Assert.AreEqual(3, versions.Count, "Wrong number of versions returned");
            Assert.IsTrue(versions.Contains(vid1), "version 1 not found in version list");
            Assert.IsTrue(versions.Contains(vid2), "version 2 not found in version list");
            Assert.IsTrue(versions.Contains(id), "base object not found in version list");

            // Delete a version
            this.esu.DeleteVersion(vid2);
            versions = this.esu.ListVersions(id);
            Assert.AreEqual(2, versions.Count, "Wrong number of versions returned");
            Assert.IsTrue(versions.Contains(vid1), "version 1 not found in version list");
            Assert.IsFalse(versions.Contains(vid2), "version 2 found in version list (should be deleted)");
            Assert.IsTrue(versions.Contains(id), "base object not found in version list");
        }
示例#59
0
 /// <summary>
 /// Creates a new object in the cloud on the
 /// given path.
 /// </summary>
 /// <param name="path">the path to create the object on.</param>
 /// <param name="acl">Access control list for the new object.  May be null to use a default ACL</param>
 /// <param name="metadata">Metadata for the new object.  May be null for no metadata.</param>
 /// <param name="data">The initial contents of the object.  May be appended to later.  May be null to create an object with no content or a directory.</param>
 /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
 /// <returns>the ObjectId of the newly-created object for references by ID.</returns>
 public ObjectId CreateObjectOnPath(ObjectPath path, Acl acl,
     MetadataList metadata,
     byte[] data, String mimeType)
 {
     return CreateObjectFromSegmentOnPath(path, acl, metadata,
         data == null ? new ArraySegment<byte>(new byte[0]) : new ArraySegment<byte>(data),
         mimeType, null);
 }
示例#60
0
 /// <summary>
 /// Updates an object in the cloud.
 /// </summary>
 /// <param name="id">The ID of the object to update</param>
 /// <param name="acl">Access control list for the new object. Optional, set to NULL to leave the ACL unchanged.</param>
 /// <param name="metadata">Metadata list for the new object.  Optional, set to NULL for no changes to the metadata.</param>
 /// <param name="extent">portion of the object to update.  May be null to indicate the whole object is to be replaced.  If not null, the extent size must match the data size.</param>
 /// <param name="data">The new contents of the object.  May be appended to later. Optional, set to null for no content changes.</param>
 /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
 public void UpdateObjectFromSegment(Identifier id, Acl acl, MetadataList metadata, Extent extent, ArraySegment<byte> data, string mimeType)
 {
     UpdateObjectFromSegment(id, acl, metadata, extent, data, mimeType, null);
 }