Ejemplo n.º 1
0
 public MockServiceTabPage(RestServerData data) : base(data.Name)
 {
     m_RestServerData            = data;
     m_MockRestServerUserControl = new MockRestServer(data);
     this.Controls.Add(m_MockRestServerUserControl);
     m_MockRestServerUserControl.Dock = DockStyle.Fill;
 }
Ejemplo n.º 2
0
        public LogDialog(RestServerData data)
        {
            InitializeComponent();

            m_RestServerData = data;

            this.Text = $"Restward - {data.Name} Log View";

            ProjectData.RestServerManager.OnRestServerTrace += RestServerManager_OnRestServerTrace;
        }
Ejemplo n.º 3
0
 //Event Handlers
 private void toolStripButtonAdd_Click(object sender, EventArgs e)
 {
     using (AddMockServiceDialog AMSD = new AddMockServiceDialog())
     {
         if (AMSD.ShowDialog() == DialogResult.OK)
         {
             RestServerData newData = new RestServerData(AMSD.MockServiceName);
             ProjectData.AddRestServer(newData);
         }
     }
 }
Ejemplo n.º 4
0
        public void StopServer(RestServerData data)
        {
            RestServer targetRestServer = m_RestServerList.Where(c => c.RestServerData == data).FirstOrDefault();

            if (targetRestServer != null)
            {
                targetRestServer.Close();
                m_RestServerList.Remove(targetRestServer);

                //OnRestServerStopped?.Invoke(this, new OnRestServerStoppedEventArgs(data));
            }
        }
Ejemplo n.º 5
0
        private RestServer CreateRestServer(RestServerData data)
        {
            try
            {
                RestServer newRestServer = new RestServer(data);

                newRestServer.OnRestServerTrace   += RestServer_OnRestServerTrace;
                newRestServer.OnRestServerStarted += RestServer_OnRestServerStarted;
                newRestServer.OnRestServerStopped += RestServer_OnRestServerStopped;
                m_RestServerList.Add(newRestServer);

                return(newRestServer);
            }
            catch (Exception ex)
            {
                TraceWriteLine(ex.ToString());
            }

            return(null);
        }
Ejemplo n.º 6
0
        public void StartServer(RestServerData data)
        {
            RestServer targetRestServer = m_RestServerList.Where(c => c.RestServerData == data).FirstOrDefault();

            if (targetRestServer != null)
            {
                try
                {
                    TraceWriteLine($"Rest Server {targetRestServer.Name} initializing run routine");
                    targetRestServer.Run();
                    TraceWriteLine($"Rest Server {targetRestServer.Name} leaving run routine");

                    TraceWriteLine($"Rest server {data.Name} running");

                    //OnRestServerStarted?.Invoke(this, new OnRestServerStartedEventArgs(data));
                }
                catch (Exception ex)
                {
                    TraceWriteLine(ex.ToString());
                }
            }
            else
            {
                targetRestServer = CreateRestServer(data);
                try
                {
                    TraceWriteLine($"Rest Server {targetRestServer.Name} initializing run routine");
                    targetRestServer.Run();
                    TraceWriteLine($"Rest Server {targetRestServer.Name} leaving run routine");

                    TraceWriteLine($"Rest server {data.Name} running");

                    //OnRestServerStarted?.Invoke(this, new OnRestServerStartedEventArgs(data));
                }
                catch (Exception ex)
                {
                    TraceWriteLine(ex.ToString());
                }
            }
        }
Ejemplo n.º 7
0
 private void refresh()
 {
     maintenanceList = RestServerData.getMaintenanceList();
 }
Ejemplo n.º 8
0
 private void refresh()
 {
     reservationList = RestServerData.getCheckedReservationList();
 }
Ejemplo n.º 9
0
 private void refresh()
 {
     serviceList = RestServerData.getServiceList();
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="commManager"></param>
        /// <param name="xmlConfig"></param>
        /// <param name="accepts"></param>
        public RestServer(RestServerData data, int accepts = 4)
        {
            m_RestServerData = data;

            m_BaseAddress = data.ListenerAddress;
            if (m_BaseAddress == string.Empty)
            {
                throw new RestServerDataException(data,
                                                  "BaseAddress",
                                                  "base address is required");
            }
            else
            {
                //adjust base address to replace ip address with *
                //this is needed to accept external requests
                Uri baseAddressUri = new Uri(m_BaseAddress);

                //validate base address
                if (baseAddressUri.Scheme != "http" && baseAddressUri.Scheme != "https")
                {
                    throw new RestServerDataException(data,
                                                      "BaseAddress",
                                                      "base address requires a defined URI scheme, either http or https");
                }
                else if (baseAddressUri.IsDefaultPort)
                {
                    throw new RestServerDataException(data,
                                                      "BaseAddress",
                                                      string.Format("base address requires a defined port other than the default of {0}", baseAddressUri.Port));
                }

                m_PrefixAddress = string.Format("{0}://*:{1}{2}", baseAddressUri.Scheme, baseAddressUri.Port, baseAddressUri.AbsolutePath);
            }

            m_ServerName = data.Name;
            if (m_ServerName == string.Empty)
            {
                throw new RestServerDataException(data,
                                                  "Name",
                                                  "name is a required attribute");
            }

            m_ConcurrentConnections = 4;//xmlConfig["concurrent_connections", 4];

            //m_EndpointTimeout = 5000;//xmlConfig["timeout", 5000];

            if (data.UseAuth)
            {
                m_UseBasicAuth = true;
            }

            foreach (EndpointData endpoint in data.Endpoints)
            {
                foreach (PatternData pattern in endpoint.Patterns)
                {
                    try
                    {
                        m_Endpoints.Add(new RestEndpoint(endpoint, pattern, m_BaseAddress));
                    }
                    catch (Exception ex)
                    {
                        throw new RestServerDataException(data, "Endpoint", $"Endpoint with address {endpoint.HttpEndpointAddress} failed to initialize.\n{ex.ToString()}");
                    }
                }
            }

            listener.IgnoreWriteExceptions = true;

            // Multiply by number of cores:
            this.m_ConcurrentConnections = accepts * Environment.ProcessorCount;
        }
Ejemplo n.º 11
0
        public MockRestServer(RestServerData data)
        {
            InitializeComponent();

            m_RestServerData = data;

            GradientToolStripRenderer GradientRenderer = new GradientToolStripRenderer(Color.FromArgb(195, 195, 195), Color.FromArgb(110, 110, 110));

            GradientRenderer.RoundedEdges = false;

            toolStripMain.Renderer      = GradientRenderer;
            toolStripEndpoints.Renderer = GradientRenderer;

            Assembly ThisAssembly           = Assembly.GetExecutingAssembly();
            Stream   XButtonRedImageStream  = ThisAssembly.GetManifestResourceStream("Restward.Resources.CloseRed.png");
            Stream   XButtonGrayImageStream = ThisAssembly.GetManifestResourceStream("Restward.Resources.CloseGray.png");
            Image    XButtonRedImage        = Image.FromStream(XButtonRedImageStream);
            Image    XButtonGrayImage       = Image.FromStream(XButtonGrayImageStream);

            Stream WorkspaceImageStream = ThisAssembly.GetManifestResourceStream("Restward.Resources.WorkspaceBackground.png");
            Image  WorkspaceImage       = Image.FromStream(WorkspaceImageStream);

            this.tabControlEndpoints.CloseButtonActive   = XButtonRedImage;
            this.tabControlEndpoints.CloseButtonInactive = XButtonGrayImage;

            //this.scMain.Panel2.BackgroundImage = WorkspaceImage;
            //this.scMain.Panel2.BackgroundImageLayout = ImageLayout.Tile;

            this.scEndpoints.Panel2.BackgroundImage       = WorkspaceImage;
            this.scEndpoints.Panel2.BackgroundImageLayout = ImageLayout.Tile;

            txtPort.Text        = data.Port.ToString();
            txtBaseAddress.Text = data.BaseAddress;
            switch (data.Protocol)
            {
            case HttpProtocol.HTTP:
                rbHttp.Checked = true;
                break;

            case HttpProtocol.HTTPS:
                rbHttps.Checked = true;
                break;
            }

            UpdateListener();

            SetAuthEnables(false);

            tabControlEndpoints.TabPages.Clear();

            if (data.Endpoints.Count() > 0)
            {
                foreach (EndpointData endpoint in data.Endpoints)
                {
                    AddEndpoint(endpoint);
                }
            }

            m_RestServerData.OnEndpointAdded   += RestServerData_OnEndpointAdded;
            m_RestServerData.OnEndpointRemoved += RestServerData_OnEndpointRemoved;
            m_RestServerData.OnEndpointChanged += RestServerData_OnEndpointChanged;
            m_RestServerData.PropertyChanged   += RestServerData_PropertyChanged;
            ProjectData.RestServerManager.OnRestServerTrace   += RestServerManager_OnRestServerTrace;
            ProjectData.RestServerManager.OnRestServerStarted += RestServerManager_OnRestServerStarted;
            ProjectData.RestServerManager.OnRestServerStopped += RestServerManager_OnRestServerStopped;
        }