示例#1
0
        /// <summary>
        /// Loads one item by its id.
        /// Uses session from constructor.
        /// </summary>
        /// <param name="id">The item id.</param>
        /// <returns>Loaded item with given id or null.</returns>
        public TEntity LoadItem(string id)
        {
            Guard.ArgumentNotNullOrEmptyString(id, "id");

            TikConnectorQueryFilterDictionary filter = new TikConnectorQueryFilterDictionary();
            filter.Add(".id", id);

            List<TEntity> loadedItems = LoadItemsInternal(filter, session);
            if (loadedItems.Count > 1)
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "More than one item with id {0} returned in {1}.", id, GetType()));
            else if (loadedItems.Count == 0)
                return default(TEntity); 
            else
                return loadedItems[0];
        }
示例#2
0
        private List <ITikEntityRow> ExecuteReaderInternal(string command, IEnumerable <string> propertyList,
                                                           TikConnectorQueryFilterDictionary filter, Dictionary <string, string> parameters)
        {
            // ip/address/print
            // =detail=
            // =.proplist=..,..,..,..
            // ?address=10.10.10.10

            Dictionary <string, string> allParameters;

            //parameters
            if (parameters != null)
            {
                allParameters = new Dictionary <string, string>(parameters);
            }
            else
            {
                allParameters = new Dictionary <string, string>();
            }

            //propList
            if ((propertyList != null) && propertyList.Any()) //.proplist  (if specified)
            {
                allParameters.Add("=.proplist", string.Join(",", propertyList.ToArray()));
            }

            //filter
            if (filter != null) //filter (if specified)
            {
                foreach (KeyValuePair <string, string> fltPair in filter)
                {
                    allParameters.Add("?" + fltPair.Key, fltPair.Value); //TODO - convert from internal expression!!!
                }
            }

            List <string> response = ExecuteAndReadResponse(command, allParameters, false, null, doneRegex, dataRowRegex);

            List <ApiEntityRow> result = new List <ApiEntityRow>(response.Count - 1);

            for (int i = 0; i < response.Count - 1; i++)
            {
                result.Add(new ApiEntityRow(response[i]));
            }

            return(result.Cast <ITikEntityRow>().ToList());
        }
示例#3
0
        private List<TEntity> LoadItemsInternal(TikConnectorQueryFilterDictionary filter, TikSession session)
        {
            List<TEntity> result = new List<TEntity>();

            TikEntityMetadata entityMetadata = TikEntityMetadata.Get(typeof(TEntity));
            IEnumerable<ITikEntityRow> response;
            if (filter != null)
                response = session.Connector.ExecuteReader(entityMetadata.EntityPath, entityMetadata.ReaderBehavior, entityMetadata.PropertyNames, filter);
            else
                response = session.Connector.ExecuteReader(entityMetadata.EntityPath, entityMetadata.ReaderBehavior, entityMetadata.PropertyNames);

            VerifyResponseRows(response);

            foreach (ITikEntityRow entityRow in response)
            {
                TEntity item = new TEntity();
                item.LoadFromEntityRow(entityRow);
                result.Add(item);
            }

            logger.DebugFormat("{0} items loaded.", result.Count);
            return result;
        }
示例#4
0
        /// <summary>
        /// See <see cref="ITikConnector.ExecuteReader(string, ExecuteReaderBehaviors,IEnumerable{string},TikConnectorQueryFilterDictionary)"/> for details.
        /// </summary>
        public IEnumerable <ITikEntityRow> ExecuteReader(string entityPath, ExecuteReaderBehaviors readerBehavior, IEnumerable <string> propertyList, TikConnectorQueryFilterDictionary filter)
        {
            Guard.ArgumentNotNullOrEmptyString(entityPath, "entityPath");
            //Guard.ArgumentNotNull(filter, "filter");
            EnsureLoggedOn();

            Dictionary <string, string> parameters = new Dictionary <string, string>();

            if ((readerBehavior & ExecuteReaderBehaviors.ExcludeDetails) == 0)
            {
                parameters.Add("=detail", "");
            }

            List <ITikEntityRow> result = ExecuteReaderInternal(string.Format(CultureInfo.InvariantCulture, "{0}/print", entityPath),
                                                                propertyList, filter, parameters);

            return(result);
        }
示例#5
0
 /// <summary>
 /// Loads the list (with given filter).
 /// </summary>
 /// <param name="filter">The list filter.</param>
 protected void LoadInternal(TikConnectorQueryFilterDictionary filter)
 {
     Clear();
     items.AddRange(LoadItemsInternal(filter, session));
 }
示例#6
0
        private List<ITikEntityRow> ExecuteReaderInternal(string command, IEnumerable<string> propertyList, 
            TikConnectorQueryFilterDictionary filter, Dictionary<string, string> parameters)
        {
            // ip/address/print
            // =detail=
            // =.proplist=..,..,..,..
            // ?address=10.10.10.10

            Dictionary<string, string> allParameters;
            //parameters
            if (parameters != null)
                allParameters = new Dictionary<string,string>(parameters);
            else
                allParameters = new Dictionary<string, string>();

            //propList
            if ((propertyList != null) && propertyList.Any()) //.proplist  (if specified)
                allParameters.Add("=.proplist", string.Join(",", propertyList.ToArray()));

            //filter
            if (filter != null) //filter (if specified)
            {
                foreach(KeyValuePair<string, string> fltPair in filter)
                {
                    allParameters.Add("?" + fltPair.Key, fltPair.Value); //TODO - convert from internal expression!!!
                }
            }

            List<string> response = ExecuteAndReadResponse(command, allParameters, false, null, doneRegex, dataRowRegex);

            List<ApiEntityRow> result = new List<ApiEntityRow>(response.Count - 1);
            for (int i = 0; i < response.Count - 1; i++)
            {
                result.Add(new ApiEntityRow(response[i]));
            }

            return result.Cast<ITikEntityRow>().ToList();
        }
示例#7
0
        /// <summary>
        /// See <see cref="ITikConnector.ExecuteReader(string, ExecuteReaderBehaviors,IEnumerable{string},TikConnectorQueryFilterDictionary)"/> for details.
        /// </summary>
        public IEnumerable<ITikEntityRow> ExecuteReader(string entityPath, ExecuteReaderBehaviors readerBehavior, IEnumerable<string> propertyList, TikConnectorQueryFilterDictionary filter)
        {
            Guard.ArgumentNotNullOrEmptyString(entityPath, "entityPath");
            //Guard.ArgumentNotNull(filter, "filter");
            EnsureLoggedOn();

            Dictionary<string, string> parameters = new Dictionary<string, string>();
            if ((readerBehavior & ExecuteReaderBehaviors.ExcludeDetails) == 0)
                parameters.Add("=detail", "");

            List<ITikEntityRow> result = ExecuteReaderInternal(string.Format(CultureInfo.InvariantCulture, "{0}/print", entityPath),
                propertyList, filter, parameters);

            return result;
        }