Exemple #1
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));
                }
            }
        }
Exemple #2
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 #3
0
        /* Keeping a user logged in indefinitely solves one issue.
         * How do we handle host accessibility issues?
         * Ping Fishbowl server periodically so that we can
         * automatically reconnect when it's back online.
         * TODO: Verify that this works.
         */
        public static void WatchDog()
        {
            Console.WriteLine("WatchDog() started");

            // Grab Fishbowl host address
            string FishbowlServer = ConfigurationManager.AppSettings.Get("FishbowlServer");

            Ping        pingSender = new Ping();
            PingOptions options    = new PingOptions();

            // Use the default TTL value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "****RESTfulFish Gateway Ping****";

            byte[] buffer  = Encoding.ASCII.GetBytes(data);
            int    timeout = 120;

            while (true)
            {
                try
                {
                    PingReply reply = pingSender.Send(FishbowlServer, timeout, buffer, options);

                    if (reply.Status == IPStatus.DestinationHostUnreachable)
                    {
                        // Tell KeepAlive() and everyone else to stop sending data to Fishbowl since it's down.
                        FishbowlServerDown = true;

                        Console.WriteLine("Fishbowl server is down!");
                        Console.WriteLine("Checking if Fishbowl server is up in 5 seconds.");
                        Thread.Sleep(5000);

                        // TODO: Verify that pinging a specific port signifies that an
                        // application (Fishbowl) is listening on it and not just the OS responding.
                        while (!ConnectionObject.IsFishbowlPortOpen())
                        {
                            Console.WriteLine("Fishbowl server is still down, chaecking again in 5 seconds.");
                            // Wait five seconds before checking again
                            Thread.Sleep(5000);
                        }

                        // TODO: Determine best option. Restart app or recall methods/functions?
                        // Restart app
                        System.Diagnostics.Process.Start(Assembly.GetExecutingAssembly().Location);
                        Environment.Exit(0);
                    }
                    // Ping every 2 seconds
                    Thread.Sleep(2000);
                }
                catch (Exception e)
                {
                    Misc.ExceptionMessage("WatchDog", e, null, false);
                }
            }

            // Reconnect
        }