Ejemplo n.º 1
0
        public IEnumerable<IVertexView> Import(String myLocation,
            IGraphDB myGraphDB,
            IGraphQL myGraphQL,
            SecurityToken mySecurityToken,
            Int64 myTransactionToken,
            UInt32 myParallelTasks = 1U,
            IEnumerable<string> myComments = null,
            UInt64? myOffset = null,
            UInt64? myLimit = null,
            VerbosityTypes myVerbosityType = VerbosityTypes.Silent,
            Dictionary<string, string> myOptions = null)
        {
            if (myGraphDB == null)
                throw new ArgumentNullException("myGraphDB");

            if (myGraphQL == null)
                throw new ArgumentNullException("myGraphQL");

            if (!typeof(SonesGraphDB).Equals(myGraphDB.GetType()))
                throw new ArgumentException("FASTIMPORT is designed for SonesGraphDB only.");

            lock (_lock)
            {
                //if verbositiy is silent, we do not configure the logger, so it is an empty logger.
                if (myVerbosityType != VerbosityTypes.Silent)
                {
                    Level logLevel = (myVerbosityType == VerbosityTypes.Full)
                        ? Level.FINE
                        : Level.INFO;
                    LogManager.Instance.ConfigureLogger("FastImport", new FileLogger(_logpath, logLevel));
                }

                //store some arguments as fields, because there is at most one execution at any time.
                _logger = LogManager.Instance.GetLogger("FastImport");
                _db = myGraphDB;
                _ql = myGraphQL;
                _security = mySecurityToken;
                _transaction = myTransactionToken;
                _offset = myOffset;
                _limit = myLimit;
                _currentImport = 0L;
                _closed = false;
                _autoCreateIncomingEdges = false;

                if (myOptions != null)
                {
                    if (myOptions.ContainsKey("AutoCreateIncomingEdges"))
                        bool.TryParse(myOptions["AutoCreateIncomingEdges"], out _autoCreateIncomingEdges);
                }

                if (!_autoCreateIncomingEdges)
                    _sorter = new IncomingEdgeSorter(myOptions);

                try
                {
                    if (myLocation.ToLower().StartsWith(@"file:\\"))
                    {
                        stream = GetStreamFromFile(myLocation.Substring(@"file:\\".Length));
                    }
                    else
                    {
                        _logger.Log(Level.SEVERE, "Location does not start with file:\\\\.");
                        throw new InvalidImportLocationException(myLocation, @"file:\\");
                    }

                    #region Start import using the AGraphDBImport implementation and return the result

                    return Import();

                    #endregion
                }
                catch (Exception ex)
                {
                    //if something unexpected happens we log it and return a query result with failed.
                    _logger.Log(Level.SEVERE, "Exception thrown:\n", ex);
                    throw new ImportFailedException(ex);
                }
                finally
                {
                    if (stream != null)
                    {
                        _logger.Log(Level.FINE, "Stream closed");
                        stream.Dispose();
                        if (_sorter != null)
                            _sorter.Dispose();
                    }
                }
            }
        }