コード例 #1
0
ファイル: RestServer.cs プロジェクト: NateRobinHood/Restward
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="xmlConfig"></param>
        /// <param name="baseAddress"></param>
        public RestEndpoint(EndpointData data, PatternData pattern, string baseAddress)
        {
            m_RestJobConfig = data;
            m_Pattern       = pattern;

            m_BaseAddress = baseAddress;

            m_Address = data.HttpEndpointAddress;//xmlConfig["endpoint_address", string.Empty].Trim();
            if (m_Address == string.Empty)
            {
                throw new EndpointDataException(data,
                                                "HttpEndpointAddress",
                                                "endpoint address is required");
            }

            m_ContentType = DataEnums.GetDescriptorText(pattern.ResponseData.ContentType);//xmlConfig["content_type", string.Empty].Trim();
            if (m_ContentType == string.Empty)
            {
                throw new EndpointDataException(data,
                                                "ContentType",
                                                "content type is required");
            }
            else
            {
                if (m_ContentType.ToLower() == "json")
                {
                    m_ContentType = RestServer.MIME_TYPE_JSON;
                }
                if (m_ContentType.ToLower() == "xml")
                {
                    m_ContentType = RestServer.MIME_TYPE_XML;
                }
            }

            m_HttpMethod = DataEnums.GetDescriptorText(pattern.HttpMethod); //xmlConfig["http_method", string.Empty].Trim();

            m_Timeout = -1;                                                 //xmlConfig["timeout", -1];

            //XmlHelper restJob = xmlConfig.FindNodeHelper("rest_job");
            //m_RestJobConfig = restJob;

            //m_Assembly =
            //restJob["job_assembly", String.Empty].Trim();
            //Assembly endpointAssembly;   // If 'session_assembly' attribute
            //                             // found,
            //if (m_Assembly.Length > 0)
            //{
            //    // If assembly file does not contain a
            //    // path,
            //    if (m_Assembly.IndexOf(
            //        Path.DirectorySeparatorChar) < 0)
            //    {
            //        // Prepend path for current application
            //        m_Assembly = PlatformCore.AppBaseDirectory +
            //            m_Assembly;
            //    }
            //    try                     // Load assembly from specified  file
            //    {
            //        endpointAssembly = Assembly.LoadFrom(
            //            m_Assembly);
            //    }
            //    catch (Exception innerException)
            //    {
            //        // Throw exception without logging it
            //        throw new XmlHelperException(innerException,
            //            restJob.AttributeSource("job_assembly"),
            //            "Exception loading assembly from file '" +
            //            m_Assembly + "':  " +
            //            innerException.Message);
            //    }
            //}
            //else                        // Else 'session_assembly' attribute not
            //{                           // found
            //                            // Get currently executing assembly
            //    endpointAssembly = Assembly.GetExecutingAssembly();
            //}
            //// Get session class
            //m_Class =
            //    restJob["job_class", String.Empty].Trim();
            //// If missing 'session_class'
            //// attribute,
            //if (m_Class.Length == 0)
            //{
            //    // Throw exception without logging it
            //    throw new XmlHelperException(null,
            //        restJob.AttributeSource("job_class"), "Element <" +
            //        xmlConfig.Name + "> missing 'session_class' attribute");
            //}
            //// If session class full name does not
            //// contain '.',
            //if (m_Class.IndexOf('.') < 0)
            //{
            //    // Prepend default path to class name
            //    m_Class =
            //        "Intelligrated.Common.CommLibrary." +
            //        m_Class;
            //}
            //// Get type for session class
            //try
            //{
            //    m_ClassType = endpointAssembly.GetType(
            //        m_Class);
            //}
            //catch (Exception innerException)
            //{
            //    // Throw exception without logging it
            //    throw new XmlHelperException(innerException,
            //        restJob.AttributeSource("job_class"),
            //        "Exception getting class type for " + m_Class +
            //        ":  " + innerException.Message);
            //}
            //// If class not found,
            //if (m_ClassType == null)
            //{
            //    // Throw exception without logging it
            //    throw new XmlHelperException(null,
            //        restJob.AttributeSource("job_class"),
            //        "Could not find class '" + m_Class +
            //        "' in assembly '" + endpointAssembly.FullName + "'");
            //}

            //m_Method = restJob["job_method", string.Empty].Trim();
            //if (m_Method == string.Empty)
            //{
            //    throw new XmlHelperException(null,
            //            restJob.AttributeSource("job_method"),
            //            "endpoint method is a required attribute");
            //}

            //if (m_ClassType.IsSubclassOf(typeof(RestJob)))
            //{
            //    m_RestJobInstance = (RestJob)Activator.CreateInstance(m_ClassType);
            //}
            //else
            //{
            //    throw new ArgumentException(string.Format("Class {0} doesn't inherit from RestJob", m_ClassType.FullName));
            //}

            ////Check that method has no additional parameters
            //if(ValidateMethod() == false)
            //{
            //    throw new ArgumentException(string.Format("Method {0} has invalid parameters. UriArgs parameter must be of type NameValueCollection and payload parameter must be named payload, there can not be more than two parameters.", m_Method));
            //}
        }
コード例 #2
0
        public MockEndpoint(EndpointData data)
        {
            InitializeComponent();

            m_EndpointData = data;

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

            GradientRenderer.RoundedEdges = false;

            toolStripMain.Renderer = GradientRenderer;

            comboBoxStatusCode.DataSource    = DataEnums.GetEnumWrappers <HttpStatusCode>();
            comboBoxStatusCode.DisplayMember = "Descriptor";
            comboBoxStatusCode.ValueMember   = "Value";

            comboBoxHttpMethod.DataSource    = DataEnums.GetEnumWrappers <HttpMethod>();
            comboBoxHttpMethod.DisplayMember = "Descriptor";
            comboBoxHttpMethod.ValueMember   = "Value";

            comboBoxContentType.DataSource    = DataEnums.GetEnumWrappers <ContentType>();
            comboBoxContentType.DisplayMember = "Descriptor";
            comboBoxContentType.ValueMember   = "Value";

            txtResponseDelay.Enabled = false;

            SetReponseEnables(false);

            if (data.Patterns.Count() > 0)
            {
                foreach (PatternData pattern in data.Patterns)
                {
                    AddPattern(pattern);
                }
            }


            if (data.HttpEndpointAddress != string.Empty)
            {
                txtAddress.Text         = data.HttpEndpointAddress;
                lblListenerAddress.Text = m_EndpointData.Owner.ListenerAddress + data.HttpEndpointAddress;
            }
            else
            {
                lblListenerAddress.Text = m_EndpointData.Owner.ListenerAddress;
            }

            ProjectData.OnRestServerChanged += ProjectData_OnRestServerChanged;
            ProjectData.RestServerManager.OnRestServerStarted += RestServerManager_OnRestServerStarted;
            ProjectData.RestServerManager.OnRestServerStopped += RestServerManager_OnRestServerStopped;
            m_EndpointData.OnPatternAdded   += EndpointData_OnPatternAdded;
            m_EndpointData.OnPatternRemoved += EndpointData_OnPatternRemoved;
            m_EndpointData.OnPatternChanged += EndpointData_OnPatternChanged;

            Restward.RestServer.RestServer thisRestServer = ProjectData.RestServerManager.RestServers.Where(c => c.RestServerData == data.Owner).FirstOrDefault();
            if (thisRestServer != null)
            {
                m_RestServerRunning = thisRestServer.IsServerRunning;
                if (m_RestServerRunning)
                {
                    SetRestServerEnables(false);
                }
            }
        }
コード例 #3
0
 public TagModel(DataEnums tagType, string value)
 {
     TagType = tagType;
     Value   = value;
 }