Example #1
0
        static void Main(string[] args)
        {
            bool isLoggedIn = false;

            using (RetsSession retssession = new RetsSession("http://www.eele-rets.com:6160/rets/login"))
            {
                retssession.UseHttpGet(true);
                //retssession.
                isLoggedIn = retssession.Login("corcoran", "JDXzmkGa");

                if (isLoggedIn)
                {
                    var urls = retssession.GetCapabilityUrls();
                    Console.WriteLine(urls.GetLoginUrl());

                    RetsMetadata metadata  = retssession.GetMetadata();
                    IEnumerable  resources = metadata.GetAllResources();

                    using (SearchRequest searchRequest = retssession.CreateSearchRequest(
                               "Property",
                               "CLISTINGS",
                               "(Modified=2016-12-12T00:00:00+)"))
                    {
                        searchRequest.SetQueryType(SearchRequest.QueryType.DMQL2);
                        searchRequest.SetStandardNames(false);
                        searchRequest.SetOffset(SearchRequest.OFFSET_NONE);
                        SearchResultSet results = retssession.Search(searchRequest);
                        Console.WriteLine("Record count: " + results.GetCount());
                        Console.WriteLine();
                        IEnumerable columns = results.GetColumns();
                        while (results.HasNext())
                        {
                            foreach (string column in columns)
                            {
                                Console.WriteLine(column + ": " + results.GetString(column));
                            }
                            Console.WriteLine();
                        }
                    }
                }
            }
        }
Example #2
0
    static void Main(string[] args)
    {
        Options options = new Options();

        if (!options.Parse(args))
        {
            Environment.Exit(1);
        }

        RetsSession session = options.SessionFactory();

        try {
            if (!session.Login(options.user_name, options.user_password))
            {
                Console.WriteLine("Invalid login");
                Environment.Exit(1);
            }
        } catch (Exception e)
        {
            Console.WriteLine("RetsException: " + e);
            Environment.Exit(1);
        }

        SearchRequest searchRequest = session.CreateSearchRequest(
            options.search_type, options.search_class, options.query);

        searchRequest.SetSelect(options.select);
        searchRequest.SetLimit(options.limit);
        searchRequest.SetOffset(options.offset);
        searchRequest.SetCountType(options.count);
        searchRequest.SetStandardNames(options.standard_names);

        try
        {
            Stream  outputStream = File.OpenWrite("rawsearch.xml");
            byte [] data         = session.SearchAsArray(searchRequest);
            outputStream.Write(data, 0, data.Length);
            outputStream.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine("RetsException: " + e);
            session.Logout();
            Environment.Exit(1);
        }

        session.Logout();

        try
        {
            // I'd rather use ReadAllBytes, but it doesn't exist in all versions.
            // byte [] data = File.ReadAllBytes("rawsearch.xml");
            //
            FileInfo   info        = new FileInfo("rawsearch.xml");
            int        len         = (int)info.Length;
            byte []    data        = new byte [len];
            FileStream inputStream = info.OpenRead();
            inputStream.Read(data, 0, len);

            SearchResultSet results = new SearchResultSet();

            results.SetEncoding(options.encoding);
            results.SetDataAsArray(data);

            Console.WriteLine("Record count: " + results.GetCount());
            Console.WriteLine();
            IEnumerable columns = null;

            while (results.HasNext())
            {
                if (columns == null)
                {
                    columns = results.GetColumns();
                }
                foreach (string column in columns)
                {
                    Console.WriteLine(column + ": " + results.GetString(column));
                }
                Console.WriteLine();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("RetsException: " + e);
            session.Logout();
            Environment.Exit(1);
        }
    }
Example #3
0
    static void Main(string[] args)
    {
        Options options = new Options();

        if (!options.Parse(args))
        {
            Environment.Exit(1);
        }

        RetsSession session = options.SessionFactory();

        try {
            if (!session.Login(options.user_name, options.user_password))
            {
                Console.WriteLine("Invalid login");
                Environment.Exit(1);
            }
        } catch (Exception e)
        {
            Console.WriteLine("RetsException: " + e);
            Environment.Exit(1);
        }

        Console.WriteLine("Action: " + session.GetAction());
        RetsVersion version = session.GetDetectedRetsVersion();

        Console.WriteLine("RETS Version: " +
                          ((version == RetsVersion.RETS_1_5) ? "1.5" :
                           ((version == RetsVersion.RETS_1_7) ? "1.7" : "1.0")));

        SearchRequest searchRequest = session.CreateSearchRequest(
            options.search_type, options.search_class, options.query);

        searchRequest.SetSelect(options.select);
        searchRequest.SetLimit(options.limit);
        searchRequest.SetOffset(options.offset);
        searchRequest.SetCountType(options.count);
        searchRequest.SetStandardNames(options.standard_names);
        searchRequest.SetRestrictedIndicator("XXXX");
        searchRequest.SetFormatType(SearchRequest.FormatType.COMPACT);
        SearchResultSet results = session.Search(searchRequest);

        Console.WriteLine("Record count: " + results.GetCount());
        Console.WriteLine();
        IEnumerable columns = null;

        while (results.HasNext())
        {
            if (columns == null)
            {
                columns = results.GetColumns();
            }
            foreach (string column in columns)
            {
                Console.WriteLine(column + ": " + results.GetString(column));
            }
            Console.WriteLine();
        }

        LogoutResponse logout = session.Logout();

        Console.WriteLine("Billing info: " + logout.GetBillingInfo());
        Console.WriteLine("Logout message: " + logout.GetLogoutMessage());
        Console.WriteLine("Connect time: " + logout.GetConnectTime());
    }
Example #4
0
    /*
     * This class demonstrates the interleaving of search transactions.
     */
    static void Main(string[] args)
    {
        Options options = new Options();

        if (!options.Parse(args))
        {
            Environment.Exit(1);
        }

        RetsSession session = options.SessionFactory();

        try {
            if (!session.Login(options.user_name, options.user_password))
            {
                Console.WriteLine("Invalid login");
                Environment.Exit(1);
            }
        } catch (Exception e)
        {
            Console.WriteLine("RetsException: " + e);
            Environment.Exit(1);
        }

        RetsVersion version = session.GetDetectedRetsVersion();

        Console.WriteLine("RETS Version: " +
                          ((version == RetsVersion.RETS_1_5) ? "1.5" :
                           ((version == RetsVersion.RETS_1_7) ? "1.7" : "1.0")));

        /*
         * Find the key field for the resource.
         */
        RetsMetadata     metadata         = session.GetMetadata();
        MetadataResource metadataResource = metadata.GetResource(options.search_type);

        if (metadataResource == null)
        {
            Console.WriteLine("Invalid resource: " + options.search_type);
            session.Logout();
            Environment.Exit(1);
        }

        string keyField = metadataResource.GetKeyField();

        /*
         * Find the timestamp field if it is known (RETS 1.7 and later). If
         * not known, then the user must provide it.
         */
        MetadataClass metadataClass = metadata.GetClass(options.search_type, options.search_class);

        if (metadataClass == null)
        {
            Console.WriteLine("Invalid resource:class: " + options.search_type + ":" + options.search_class);
            session.Logout();
            Environment.Exit(2);
        }

        if (options.classTimeStamp != null && options.classTimeStamp.Length == 0)
        {
            options.classTimeStamp = metadataClass.GetStringAttribute("ClassTimeStamp");
        }

        if (options.classTimeStamp == null || options.classTimeStamp.Length == 0)
        {
            Console.WriteLine("Class " + options.search_type +
                              ":" + options.search_class +
                              " has no ClassTimeStamp specified in the metadata.");
            Console.WriteLine("Please manually provide one using the --timetsamp switch.");
            session.Logout();
            Environment.Exit(2);
        }

        /*
         * See if the last modified timestamp has been provided. If not, use yesterday.
         */
        if (options.lastModified == null || options.lastModified.Length == 0)
        {
            DateTime ts = DateTime.Now;

            options.lastModified = ts.AddDays(-1).ToString("yyyy-MM-dd");
        }

        /*
         * OK - let's find all listings that have changed since the lastModified date.
         */

        SearchRequest searchRequest = session.CreateSearchRequest(
            options.search_type,
            options.search_class,
            "(" +
            options.classTimeStamp.ToString() +
            "=" +
            options.lastModified.ToString() +
            "+)");

        searchRequest.SetSelect(keyField);
        searchRequest.SetLimit(SearchRequest.LIMIT_NONE);
        searchRequest.SetOffset(SearchRequest.OFFSET_NONE);
        searchRequest.SetCountType(SearchRequest.CountType.RECORD_COUNT_AND_RESULTS);
        searchRequest.SetStandardNames(false);

        /*
         * This starts the outer search.
         */
        SearchResultSet results = session.Search(searchRequest);

        Console.WriteLine("Record count: " + results.GetCount());
        Console.WriteLine();

        while (results.HasNext())
        {
            /*
             * Fetch the listing detail and media. This will cause a separate search transaction
             * to be open within the outer search transaction.
             */
            SearchRequest listingRequest = session.CreateSearchRequest(
                options.search_type,
                options.search_class,
                "(" +
                keyField +
                "=" +
                results.GetString(keyField) +
                ")");
            listingRequest.SetStandardNames(false);
            listingRequest.SetLimit(SearchRequest.LIMIT_DEFAULT);
            listingRequest.SetOffset(SearchRequest.OFFSET_NONE);
            listingRequest.SetCountType(SearchRequest.CountType.NO_RECORD_COUNT);
            listingRequest.SetFormatType(SearchRequest.FormatType.COMPACT);

            SearchResultSet listingResult = session.Search(listingRequest);
            IEnumerable     columns       = null;

            while (listingResult.HasNext())
            {
                if (columns == null)
                {
                    columns = listingResult.GetColumns();
                }

                /*
                 * Show the listing detail.
                 */
                foreach (string column in columns)
                {
                    Console.WriteLine("{0,15}: {1}", column, listingResult.GetString(column));
                }
                Console.WriteLine();

                /*
                 * Now set up to fetch the objects associated with this listing.
                 */
                GetObjectRequest getObjectRequest = new GetObjectRequest(options.search_type, "Photo");
                getObjectRequest.AddAllObjects(listingResult.GetString(keyField));

                GetObjectResponse getObjectResponse = session.GetObject(getObjectRequest);

                foreach (ObjectDescriptor objectDescriptor in getObjectResponse)
                {
                    /*
                     * Report the object details.
                     */
                    string objectKey = objectDescriptor.GetObjectKey();
                    int    objectId  = objectDescriptor.GetObjectId();
                    //string  contentType = objectDescriptor.GetContentType();
                    string description = objectDescriptor.GetDescription();

                    Console.Write("Object " + objectKey + ":" + objectId.ToString());
                    if (description.Length > 0)
                    {
                        Console.Write(", description: " + description);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("=================");
            }
        }

        session.Logout();
    }
Example #5
0
    static void Main(string[] args)
    {
        Options options  = new Options();

        if (!options.Parse(args))
            Environment.Exit(1);

        RetsSession session = options.SessionFactory();

        try {

        if (!session.Login(options.user_name, options.user_password))
        {
            Console.WriteLine("Invalid login");
            Environment.Exit(1);
        }
        } catch (Exception e)
        {
            Console.WriteLine("RetsException: " + e);
            Environment.Exit(1);
        }

        SearchRequest searchRequest = session.CreateSearchRequest(
            options.search_type, options.search_class, options.query);

        searchRequest.SetSelect(options.select);
        searchRequest.SetLimit(options.limit);
        searchRequest.SetOffset(options.offset);
        searchRequest.SetCountType(options.count);
        searchRequest.SetStandardNames(options.standard_names);

        try
        {
            Stream outputStream = File.OpenWrite("rawsearch.xml");
            byte [] data = session.SearchAsArray(searchRequest);
            outputStream.Write(data, 0, data.Length);
            outputStream.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine("RetsException: " + e);
            session.Logout();
            Environment.Exit(1);
        }

        session.Logout();

        try
        {
            // I'd rather use ReadAllBytes, but it doesn't exist in all versions.
            // byte [] data = File.ReadAllBytes("rawsearch.xml");
            //
            FileInfo info = new FileInfo("rawsearch.xml");
            int len = (int)info.Length;
            byte [] data = new byte [len];
            FileStream inputStream = info.OpenRead();
            inputStream.Read(data,0,len);

            SearchResultSet results = new SearchResultSet();

            results.SetEncoding(options.encoding);
            results.SetDataAsArray(data);

            Console.WriteLine("Record count: " + results.GetCount());
            Console.WriteLine();
            IEnumerable columns = null;

            while (results.HasNext())
            {
                if (columns == null)
                {
                    columns = results.GetColumns();
                }
                foreach (string column in columns)
                {
                    Console.WriteLine(column + ": " + results.GetString(column));
                }
                Console.WriteLine();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("RetsException: " + e);
            session.Logout();
            Environment.Exit(1);
        }
    }