Exemple #1
0
        /* Login using the appropiate request (FishbowlRequests or FishbowlLegacyRequest)
         */
        public static void LogInRESTfulFish()
        {
            // Get Fishbowl username, password, host, and port from app.config
            Misc.ReadAllSettings();

            // Grab Fishbowl username and password from ConfigurationManager.AppSettings object
            string FishbowlUser     = ConfigurationManager.AppSettings.Get("FishbowlUser");
            string FishbowlPassword = ConfigurationManager.AppSettings.Get("FishbowlPassword");

            ConnectionObject.Connect();

            String loginCommand = FishbowlLegacyRequests.LoginRq("3565",
                                                                 "RESTfulFish Gateway", FishbowlUser, "RESTfulFish Gateway", FishbowlPassword);


            /* Send login command once to get fishbowl server to recognize the connection attempt
             * or pull the key off the line if already connected.
             */
            Console.WriteLine("Misc.LogInRESTfulFish(): Client Started...");

            Key = FishbowlLegacy.PullKey(ConnectionObject.sendCommand(loginCommand));

            while (Misc.Key == "null")
            {
                Console.WriteLine("Please accept the connection attempt on the fisbowl server and press Enter.");
                Console.WriteLine("Refer to 'Integrated Apps tab' in https://www.fishbowlinventory.com/wiki/Settings");
                Console.ReadLine();
                Misc.Key = FishbowlLegacy.PullKey(ConnectionObject.sendCommand(loginCommand));
            }
        }
Exemple #2
0
        /* We know that we can be logged into Fishbowl indefinitely by continously
         * requesting data while logged in.
         * The frequency at which to request data needs to be less than the
         * inactivity time defined by Fishbowl.
         * Refer to https://www.fishbowlinventory.com/wiki/Support#Extend_the_Client_Inactivity_Time
         * We will assume the inactivity time to be 10 minutes,
         * so we will request data every 5 minutes.
         */
        public static void KeepAlive()
        {
            Console.WriteLine("KeepAlive(): started");

            while (!Misc.FishbowlServerDown)
            {
                // Wait KeepAliveSleep (from App.config) minutes.
                Thread.Sleep(Misc.KeepAliveSleep);
                Console.WriteLine("{0} KeepAlive(): Sending...", DateTime.Now.ToString());
                // Stop all requests via the REST HTTP interface until we are done getting a response back.
                HoldAllFishbowlRequests = true;
                // Wait one second before proceeding.
                Thread.Sleep(1000);
                string statusCode = FishbowlLegacy.PullStatusCode(
                    ConnectionObject.sendCommand(FishbowlLegacyRequests.CustomerNameListRq(Misc.Key)));
                // Wait one second before allowing all other requests to be processed.
                Thread.Sleep(1000);
                // Lift the hold.
                HoldAllFishbowlRequests = false;

                // Make sure Fishbowl is responding with a statusCode of 1000.
                if (statusCode != "1000")
                {
                    Console.WriteLine("Uh oh! We might have an issue.");
                    Console.WriteLine("KeepAlive(): Fishbowl server returned a statusCode of {0}!", statusCode);
                    Console.WriteLine("KeepAlive(): {0}: {1}", statusCode, StatusCode(statusCode));
                }
            }
        }
        /*
         * Send the JSON/XML request string
         */
        public static String sendCommand(string command)
        {
            try
            {
                bw = new EndianBinaryWriter(new BigEndianBitConverter(), tcS);
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                byte[] bytes = encoding.GetBytes(command);
                bw.Write(bytes.Length);
                bw.Write(bytes);
                bw.Flush();
                Thread.Sleep(1000);
                br = new EndianBinaryReader(new BigEndianBitConverter(), tcS);
                int    i      = br.ReadInt32();
                byte[] bytess = new byte[i];
                br.Read(bytess, 0, i);
                String response = encoding.GetString(bytess, 0, i);

                return(response);
            }
            catch (Exception e)
            {
                return(FishbowlLegacy.GenericXMLError(e.ToString()));
            }
        }