예제 #1
0
파일: Put.cs 프로젝트: pedro2555/Eve.NET
        public void AcceptEndpointAndObjectReturnHttpResponse()
        {
            var message = EveClient.PutAsync(Endpoint, Original).Result;

            Assert.AreEqual(HttpStatusCode.OK, message.StatusCode);
            ValidateReturnedHttpResponse(message, Original);
        }
예제 #2
0
        /// <summary>
        /// Occurs on every second, when the timer ticks.
        /// </summary>
        private static void OnOneSecondTimerTick()
        {
            // Updates the eve client
            EveClient.UpdateOnOneSecondTick();

            // Check for scheduled operations before now
            List <Action> actionsToInvoke = new List <Action>();

            lock (m_syncLock)
            {
                // Collect all the actions scheduled before now
                var now = DateTime.UtcNow;
                foreach (var pair in m_delayedOperations)
                {
                    if (pair.Key > now)
                    {
                        break;
                    }

                    actionsToInvoke.Add(pair.Value);
                }

                // Remove those actions
                for (int i = 0; i < actionsToInvoke.Count; i++)
                {
                    m_delayedOperations.RemoveAt(0);
                }
            }

            // Execute the entries (we're already on the proper thread)
            foreach (var action in actionsToInvoke)
            {
                action.Invoke();
            }
        }
예제 #3
0
        public void Init()
        {
            // In order to run the test suite you need an instance of Eve.NET-testbed running.
            // This is a python application, and you have a few options to run it.

            // 1) Clone the repo at: https://github.com/nicolaiarocci/Eve.NET-testbed, then
            // run the webservice. By default it will run on "http://localhost:5000", so you can
            // set the EveTestServer environment variable accordingly.

            // In my case, I am running Windows in a VirtualBox VM so in order to access the
            // OSX Host 'localhost', where a local instance of the REST API is running, I use
            // the standard "http://10.0.2.2:5000" address. This is the default when no envvar
            // has been set.

            // 2) If you don't have or don't want to run a local Eve.NET-testbed instance, then
            // you can run the tests against a remote testbed instance, which is available online.
            // Tests will be  slower and please, don't overuse this feature: the webservice runs on
            // very limited resources (for free), and we want everyone to keep enjoying it. To hit
            // the remote test server simply set 'EveTestServer' envvar to "http://evenet-testbed.herokuapp.com";

            Service = Environment.GetEnvironmentVariable("EveTestServer") ?? "http://10.0.2.2:5000";

            // Make sure remote remote endpoint is completely empty.
            // We use the standard HttpClient for this (we aren't testing anything yet).
            var hc = new HttpClient {
                BaseAddress = new Uri(Service)
            };

            Assert.IsTrue(hc.DeleteAsync(Endpoint).Result.StatusCode == HttpStatusCode.NoContent);

            // Ok let's roll now.
            EveClient = new EveClient(Service);
        }
예제 #4
0
        public void AcceptIdReturnObject()
        {
            var result = EveClient.GetAsync <Company>(Endpoint, Original.UniqueId).Result;

            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            ValidateAreEquals(Original, result);
        }
예제 #5
0
파일: Post.cs 프로젝트: pedro2555/Eve.NET
        public void AcceptEndpointAndObject()
        {
            var result = EveClient.PostAsync <Company>(Endpoint, Original).Result;

            Assert.AreEqual(HttpStatusCode.Created, EveClient.HttpResponse.StatusCode);
            ValidateReturnedObject(result, Original);
        }
예제 #6
0
파일: Post.cs 프로젝트: pedro2555/Eve.NET
        public void AcceptObjectReturnHttpResponse()
        {
            EveClient.ResourceName = Endpoint;
            var message = EveClient.PostAsync(Original).Result;

            ValidateReturnedHttpResponse(message, Original);
        }
예제 #7
0
        /// <summary>
        /// Handles an exception through the Unhandled Exception window
        /// </summary>
        /// <param name="ex">Exception to display</param>
        private static void HandleUnhandledException(Exception ex)
        {
            if (!Debugger.IsAttached)
            {
                if (s_showWindowOnError)
                {
                    s_showWindowOnError = false;

                    // Shutdown EveClient timer incase that was causing the crash
                    // so we don't get multiple crashes
                    try
                    {
                        EveClient.Shutdown();
                        using (UnhandledExceptionWindow f = new UnhandledExceptionWindow(ex))
                        {
                            f.ShowDialog(s_mainWindow);
                        }
                    }
                    catch
                    {
                        StringBuilder MessageBuilder = new StringBuilder();
                        MessageBuilder.AppendLine("An error occured and EVEMon was unable to handle the error message gracefully");
                        MessageBuilder.AppendLine();
                        MessageBuilder.AppendFormat("The exception encountered was '{0}'.", ex.Message);
                        MessageBuilder.AppendLine();
                        MessageBuilder.AppendLine();
                        MessageBuilder.AppendLine("Please report this on the EVEMon forums.");
                        MessageBox.Show(MessageBuilder.ToString(), "EVEMon Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    Environment.Exit(1);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Add the given entry
        /// </summary>
        /// <param name="entry"></param>
        public static void Remove(ScheduleEntry entry)
        {
            s_schedule.Remove(entry);

            // Notify to subscribers
            EveClient.OnSchedulerChanged();
        }
예제 #9
0
파일: Put.cs 프로젝트: pedro2555/Eve.NET
        public void AcceptObject()
        {
            EveClient.ResourceName = Endpoint;
            var result = EveClient.PutAsync <Company>(Original).Result;

            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            ValidateReturnedObject(result, Original);
        }
예제 #10
0
        public void AcceptEndpoint()
        {
            var result = EveClient.GetAsync <Company>(Endpoint).Result;

            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.AreEqual(result.Count, 2);
            ValidateAreEquals(Original, result[0]);
            ValidateAreEquals(Original2, result[1]);
        }
예제 #11
0
        private static void Main()
        {
            // Sets isDebugBuild variable to true if this is a debug build
            CheckIsDebug();

            // Quits non-debug builds if another instance already exists
            if (!s_isDebugBuild && !IsInstanceUnique)
            {
                return;
            }

            // Subscribe application's events (especially the unhandled exceptions management for the crash box)
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.ThreadException += Application_ThreadException;
            Application.ApplicationExit += ApplicationExitCallback;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            // Find our files
            EveClient.InitializeFileSystemPaths();

            // Creates a trace file
            EveClient.StartTraceLogging();
            EveClient.Trace("Starting up");

            // Make our windows nice
            MakeWindowsJuicy();

            // Check arguments
            bool startMinimized = Environment.GetCommandLineArgs().Contains("-startMinimized");

            // Initialization
            EveClient.Initialize();
            Settings.InitializeFromFile();

            // Did something requested an exit before we entered Run() ?
            if (s_exitRequested)
            {
                return;
            }

            // Fires the main window
            try
            {
                EveClient.Trace("Main loop - start");
                Application.Run(new MainWindow(startMinimized));
                EveClient.Trace("Main loop - done");
            }
            // Save before we quit
            finally
            {
                Settings.SaveImmediate();
                EveIDtoName.Save();
                BCAPI.UploadSettingsFile();
                EveClient.Trace("Closed");
                EveClient.StopTraceLogging();
            }
        }
예제 #12
0
        public void AcceptEndpointAndObject()
        {
            var message = EveClient.DeleteAsync(Endpoint, Original).Result;

            Assert.AreEqual(HttpStatusCode.NoContent, message.StatusCode);

            // confirm that item has been deleted on remote
            message = EveClient.GetAsync(string.Format("{0}/{1}", Endpoint, Original.UniqueId)).Result;
            Assert.AreEqual(HttpStatusCode.NotFound, message.StatusCode);
        }
예제 #13
0
        public void DerivedInit()
        {
            Init();

            // POST in order to get a valid ETag
            Original = EveClient.PostAsync <Company> (Endpoint, new Company {
                Name = "Name"
            }).Result;
            Assert.AreEqual(HttpStatusCode.Created, EveClient.HttpResponse.StatusCode);
        }
예제 #14
0
        public void UseResourceName()
        {
            EveClient.ResourceName = Endpoint;
            var result = EveClient.GetAsync <Company>().Result;

            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.AreEqual(result.Count, 2);
            ValidateAreEquals(Original, result[0]);
            ValidateAreEquals(Original2, result[1]);
        }
예제 #15
0
        public void AcceptIdReturnHttpResponseConsiderETag()
        {
            // Get returns NotModified as the etag matches the one on the service.
            var result = EveClient.GetAsync(string.Format("{0}/{1}", Endpoint, Original.UniqueId), Original.ETag).Result;

            Assert.AreEqual(HttpStatusCode.NotModified, result.StatusCode);

            // GET returns OK since the etag does not match the one on the service and all object is retrieved.
            result = EveClient.GetAsync(string.Format("{0}/{1}", Endpoint, Original.UniqueId), "not really").Result;
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
예제 #16
0
        public void DeleteEndpointContent()
        {
            var message = EveClient.DeleteAsync(Endpoint).Result;

            Assert.AreEqual(HttpStatusCode.NoContent, message.StatusCode);

            // confirm that item has been deleted on remote
            var companies = EveClient.GetAsync <Company>(Endpoint).Result;

            Assert.AreEqual(HttpStatusCode.NoContent, message.StatusCode);
            Assert.AreEqual(0, companies.Count);
        }
예제 #17
0
        /// <summary>
        /// Pops up a window for the user to select their EVE portrait cache folder.
        /// </summary>
        private static bool ChangeEVEPortraitCache()
        {
            using (EveFolderWindow f = new EveFolderWindow())
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    EveClient.SetEvePortraitCacheFolder(f.EVEPortraitCacheFolder);
                    return(true);
                }
            }

            return(false);
        }
예제 #18
0
        public void Init()
        {
            // Make sure remote remote endpoint is completely empty.
            // We use the standard HttpClient for this (we aren't testing anything yet).
            var hc = new HttpClient {
                BaseAddress = new Uri(Service)
            };

            Assert.IsTrue(hc.DeleteAsync(Endpoint).Result.StatusCode == HttpStatusCode.OK);

            // Ok let's roll now.
            EveClient = new EveClient(Service);
        }
예제 #19
0
        public void AcceptIdReturnObjectConsiderETag()
        {
            // GET will return NotModified and null object since etag still matches the one on the service.
            var result = EveClient.GetAsync <Company>(Endpoint, Original.UniqueId, Original.ETag).Result;

            Assert.AreEqual(HttpStatusCode.NotModified, EveClient.HttpResponse.StatusCode);
            Assert.IsNull(result);

            // GET will return OK and equal object since etag does not match the one on the service.
            result = EveClient.GetAsync <Company>(Endpoint, Original.UniqueId, "not really").Result;
            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.NotNull(result);
            Assert.AreEqual(Original.UniqueId, result.UniqueId);
        }
예제 #20
0
        /// <summary>
        /// Gets the station wtih the provided ID.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Station GetStation(int id)
        {
            EnsureInitialized();
            Station result = null;

            s_stationsByID.TryGetValue(id, out result);
            if (result == null)
            {
                EveClient.Trace("Could not find station id {0}", id);
                s_stationsByID.TryGetValue(60013747, out result);
                EveClient.Trace("Setting to {0}", result.Name);
            }
            return(result);
        }
예제 #21
0
파일: Post.cs 프로젝트: pedro2555/Eve.NET
        public async Task BulkPostValidationException()
        {
            var c1 = new Company();
            var c2 = new Company {
                Name = "c2"
            };
            var objs = new List <Company> {
                c1, c2
            };

            var retObjs = await EveClient.PostAsync(Endpoint, objs);

            Assert.That(retObjs, Is.Null);
        }
예제 #22
0
        public void AcceptObjectReturnObjectConsiderETag()
        {
            // GET will return NotModified and identical object since etag still matches the one on the service.
            var result = EveClient.GetAsync <Company>(Endpoint, Original).Result;

            Assert.AreEqual(HttpStatusCode.NotModified, EveClient.HttpResponse.StatusCode);
            ValidateAreEquals(Original, result);

            // GET will return OK and different object since etag does not match the one on the service.
            Original.ETag = "not really";
            result        = EveClient.GetAsync <Company>(Endpoint, Original).Result;
            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.NotNull(result);
            Assert.AreEqual(Original.UniqueId, result.UniqueId);
        }
예제 #23
0
 /// <summary>
 /// Starts the LCD display.
 /// </summary>
 private static void Start()
 {
     try
     {
         s_lcd = Lcdisplay.Instance();
         s_lcd.SwitchState(LcdState.SplashScreen);
         s_running = true;
     }
     catch (Exception ex)
     {
         EveClient.Trace(ex.Message);
         s_startupError = true;
         s_running      = false;
     }
 }
예제 #24
0
 /// <summary>
 /// Stop the LCD display.
 /// </summary>
 private static void Stop()
 {
     try
     {
         s_lcd.Dispose();
     }
     catch (Exception ex)
     {
         EveClient.Trace(ex.Message);
     }
     finally
     {
         s_lcd     = null;
         s_running = false;
     }
 }
예제 #25
0
        /// <summary>
        /// Imports data from the given serialization object.
        /// </summary>
        /// <param name="serial"></param>
        internal static void Import(SerializableScheduler serial)
        {
            m_schedule.Clear();
            foreach (var serialEntry in serial.Entries)
            {
                if (serialEntry is SerializableSimpleScheduleEntry)
                {
                    m_schedule.Add(new SimpleScheduleEntry(serialEntry as SerializableSimpleScheduleEntry));
                }
                else
                {
                    m_schedule.Add(new RecurringScheduleEntry(serialEntry as SerializableRecurringScheduleEntry));
                }
            }

            EveClient.OnSchedulerChanged();
        }
예제 #26
0
        public void AcceptEndpointConsiderIms()
        {
            System.Threading.Thread.Sleep(1000);

            // POST in order to get a valid ETag
            var original3 = EveClient.PostAsync <Company>(Endpoint, new Company {
                Name = "Name3"
            }).Result;

            Assert.AreEqual(HttpStatusCode.Created, EveClient.HttpResponse.StatusCode);

            var result = EveClient.GetAsync <Company>(Endpoint, original3.Updated).Result;

            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.AreEqual(result.Count, 1);
            ValidateAreEquals(original3, result[0]);
        }
예제 #27
0
파일: Post.cs 프로젝트: pedro2555/Eve.NET
        public async Task BulkPost()
        {
            var c1 = new Company {
                Name = "c1", Password = "******", StateOrProvince = "state1"
            };
            var c2 = new Company {
                Name = "c2", Password = "******", StateOrProvince = "state2"
            };
            var objs = new List <Company> {
                c1, c2
            };

            var retObjs = await EveClient.PostAsync(Endpoint, objs);

            Assert.That(retObjs.Count, Is.EqualTo(2));
            ValidateReturnedObject(retObjs[0], c1);
            ValidateReturnedObject(retObjs[1], c2);
        }
예제 #28
0
        /// <summary>
        /// Clears all the expired entries.
        /// </summary>
        public static void ClearExpired()
        {
            // Removed the expired entries
            int i = 0;

            while (i < m_schedule.Count)
            {
                var entry = m_schedule[i];
                if (entry.Expired)
                {
                    m_schedule.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }

            // Notify to subscribers
            EveClient.OnSchedulerChanged();
        }
예제 #29
0
        /// <summary>
        /// Save the specified image to the EVEMon cache as this character's portrait
        /// </summary>
        /// <param name="newImage">The new portrait image.</param>
        private void SavePortraitToCache(Image newImage)
        {
            // If this control only has a character ID, we just update the picture box right now
            if (m_character == null)
            {
                pictureBox.Image = newImage;
                this.IsUpdating  = false;
                return;
            }

            // Save to the portraits cache and notify we changed this character's portrait
            try
            {
                // Save the image to a temp file
                string tempFileName = Path.GetTempFileName();
                using (FileStream fs = new FileStream(tempFileName, FileMode.Create))
                {
                    newImage.Save(fs, ImageFormat.Png);
                    fs.Flush();
                }

                // Overwrite the portrait cache file
                FileHelper.OverwriteOrWarnTheUser(tempFileName, this.CachePath, OverwriteOperation.Move);

                // Notify the other controls we updated this portrait
                EveClient.OnCharacterPortraitChanged(m_character);
            }
            catch (Exception e)
            {
                // TODO : Add a tooltip here
                ExceptionHandler.LogException(e, false);
            }
            finally
            {
                // Release the updating flag
                IsUpdating = false;
            }
        }
예제 #30
0
        public void AcceptEndpointConsiderImsAndSoftDeleteAndQuery()
        {
            System.Threading.Thread.Sleep(1000);

            var rawQuery = @"{""name"": ""Name2""}";
            var result   = EveClient.GetAsync <Company>(Endpoint, null, rawQuery: rawQuery).Result;

            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.AreEqual(result.Count, 1);

            var original3 = EveClient.PostAsync <Company>(Endpoint, new Company {
                Name = "Name3"
            }).Result;

            Assert.AreEqual(HttpStatusCode.Created, EveClient.HttpResponse.StatusCode);

            rawQuery = @"{""name"": ""Name3""}";
            result   = EveClient.GetAsync <Company>(Endpoint, null, rawQuery: rawQuery).Result;
            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.AreEqual(result.Count, 1);

            result = EveClient.GetAsync <Company>(Endpoint, original3.Updated, rawQuery).Result;
            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.AreEqual(result.Count, 0);

            result = EveClient.GetAsync <Company>(Endpoint, Original2.Updated, rawQuery).Result;
            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.AreEqual(result.Count, 1);

            var r = EveClient.DeleteAsync(Endpoint, original3).Result;

            Assert.AreEqual(HttpStatusCode.NoContent, r.StatusCode);

            result = EveClient.GetAsync <Company>(Endpoint, Original2.Updated, true).Result;
            Assert.AreEqual(HttpStatusCode.OK, EveClient.HttpResponse.StatusCode);
            Assert.AreEqual(1, result.Count);
            Assert.IsTrue(result[0].Deleted);
        }