Пример #1
0
        static string SOAPActionGetUri(SOAPAction action)
        {
            switch (action)
            {
            case SOAPAction.GetFirstMonth:
                return("http://www.inflationinrussia.com/WebServices/GetFirstMonth");

            case SOAPAction.GetLastMonth:
                return("http://www.inflationinrussia.com/WebServices/GetLastMonth");

            case SOAPAction.GetInflation:
                return("http://www.inflationinrussia.com/WebServices/GetInflation");

            case SOAPAction.GetValueChange:
                return("http://www.inflationinrussia.com/WebServices/GetValueChange");

            case SOAPAction.GetPriceChange:
                return("http://www.inflationinrussia.com/WebServices/GetPriceChange");

            // base uri to perform request
            case SOAPAction.BaseUri:
                return("http://inflationinrussia.com/DesktopModules/WebServices.asmx");

            // debug purposes
            default:
                return("error: SOAPActionGetUri returned default case.");

                ;
            }
        }
Пример #2
0
        static string PerformWebRequest(XmlDocument xml, SOAPAction action)
        {
            WebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(SOAPActionGetUri(SOAPAction.BaseUri));

            httpWebRequest.ContentType = "application/json; charset=utf-8";
            httpWebRequest.Method      = "POST";
            httpWebRequest.Headers.Add("SOAPAction", SOAPActionGetUri(action));

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                return(streamReader.ReadToEnd());
            }
        }
Пример #3
0
        /// <summary>
        /// Executes the Browse action.
        /// </summary>
        /// <param name="objectID">In value for the ObjectID action parameter.</param>
        /// <param name="browseFlag">In value for the BrowseFlag action parameter.</param>
        /// <param name="filter">In value for the Filter action parameter.</param>
        /// <param name="startingIndex">In value for the StartingIndex action parameter.</param>
        /// <param name="requestedCount">In value for the RequestedCount action parameter.</param>
        /// <param name="sortCriteria">In value for the SortCriteria action parameter.</param>
        /// <param name="result">Out value for the Result action parameter.</param>
        /// <param name="numberReturned">Out value for the NumberReturned action parameter.</param>
        /// <param name="totalMatches">Out value for the TotalMatches action parameter.</param>
        /// <param name="updateID">Out value for the UpdateID action parameter.</param>
        public async Task <BrowseResult <T> > Browse <T>(String objectID, BrowseFlag browseFlag, String filter, UInt32 startingIndex, UInt32 requestedCount, String sortCriteria)
        {
            object[] loIn = new object[6];

            loIn[0] = objectID;
            loIn[1] = Extensions.ContendDirectoryExtensions.ToStringAARGTYPEBrowseFlag(browseFlag);
            loIn[2] = filter;
            loIn[3] = startingIndex;
            loIn[4] = requestedCount;
            loIn[5] = sortCriteria;
            var action = new SOAPAction()
            {
                ArgNames           = new string[] { "ObjectID", "BrowseFlag", "Filter", "StartingIndex", "RequestedCount", "SortCriteria" },
                Name               = csAction_Browse,
                ExpectedReplyCount = 4
            };
            var result = await InvokeActionAsync(action, loIn);

            if (result.Error == null)
            {
                var bResult = new BrowseResult <T>(result.Data);

                // TEMP
                if (typeof(T).Equals(typeof(QueueItem)))
                {
                    foreach (var item in bResult.Result)
                    {
                        QueueItem q = (QueueItem)(object)item;
                        q.AlbumArtUri = base.Description.BaseAddress.Scheme + "://" +
                                        base.Description.BaseAddress.Host + ":" +
                                        base.Description.BaseAddress.Port + q.AlbumArtUri;
                    }
                }

                return(bResult);
            }

            return(new BrowseResult <T>());
        }
Пример #4
0
        /// <summary>
        ///     Reads a config file, parses it, and populates itself with the data it reads.
        ///     Returns a SOAPViewerConfig with all the details from the config file.
        /// </summary>
        /// <param name="file">filename to parse data from</param>
        /// <returns></returns>
        public static SOAPViewerConfig LoadFromFile(string file)
        {
            SOAPViewerConfig Config = new SOAPViewerConfig();

            Config.Services = new List <SOAPService>();
            XDocument ConfigContents = XDocument.Load(file);

            // for each service node
            List <XElement> services = ConfigContents.Descendants("services").Elements("service").ToList();

            for (int s = 0; s < services.Count; s++)
            {
                // read the service details
                SOAPService Service = new SOAPService();
                Service.Name      = services[s].Element("name").Value;
                Service.URL       = services[s].Element("url").Value;
                Service.NameSpace = services[s].Element("namespace").Value;
                Service.Actions   = new List <SOAPAction>();
                // for each action node in this service
                List <XElement> Actions = services[s].Elements("action").ToList();
                for (int a = 0; a < Actions.Count; a++)
                {
                    // read the action details
                    SOAPAction Action = new SOAPAction();
                    Action.Name = Actions[a].Element("name").Value;
                    Action.DisplayProperties =
                        Actions[a].Elements("resultproperties")
                        .Select(z =>
                    {
                        SOAPAction.ResultDisplayProperties displayProperties = new SOAPAction.ResultDisplayProperties();
                        if (z.Element("add_line_breaks_on_all_elements") != null)
                        {
                            displayProperties.AddSpacingOnAllElements = bool.Parse(z.Element("add_line_breaks_on_all_elements").Value);
                        }
                        if (z.Element("trim_all_spacing") != null)
                        {
                            displayProperties.TrimAllWhitespace = bool.Parse(z.Element("trim_all_spacing").Value);
                        }
                        if (z.Element("ignore_elements") != null)
                        {
                            displayProperties.IgnoreElementList = z.Element("ignore_elements").Value.Split(',').ToList();
                        }
                        if (z.Element("add_prefix_for_elements") != null)
                        {
                            Dictionary <string, string> addPrefixForElementList = new Dictionary <string, string>();
                            var prefixList = z.Element("add_prefix_for_elements").Value.Split('|').ToList();
                            foreach (var prefixCombo in prefixList)
                            {
                                string value = prefixCombo.Split(',')[0];
                                string key   = prefixCombo.Split(',')[1];
                                addPrefixForElementList.Add(key, value);
                            }
                            displayProperties.AddPrefixForElementList = addPrefixForElementList;
                        }

                        return(displayProperties);
                    }).FirstOrDefault();
                    if (Action.DisplayProperties == null)
                    {
                        Action.DisplayProperties = new SOAPAction.ResultDisplayProperties();
                    }
                    Action.Parameters = new List <SOAPParameter>();

                    // for each parameter node in this action
                    List <XElement> Parameters = Actions[a].Elements("parameter").ToList();
                    for (int p = 0; p < Parameters.Count; p++)
                    {
                        // read the parameter details
                        SOAPParameter Parameter = new SOAPParameter();
                        Parameter.DataName = Parameters[p].Element("dataName").Value;
                        Parameter.UIName   = Parameters[p].Element("uiName").Value;
                        Parameter.DataType = Parameters[p].Element("type").Value;

                        Parameter.ListSource = null;
                        if (Parameter.DataType == "list")
                        {
                            XElement ListSource = Parameters[p].Element("listsource");
                            Parameter.ListSource               = new SOAPParameter.ArgumentListSource();
                            Parameter.ListSource.ServiceName   = ListSource.Element("servicename").Value;
                            Parameter.ListSource.DisplayMember = ListSource.Element("displaymember").Value;
                            Parameter.ListSource.DataMember    = ListSource.Element("datamember").Value;
                        }

                        Parameter.CustomValidationExpressions =
                            Parameters[p].Elements()
                            .Where(f => f.Name == "custom_validation")
                            .Any()
                            ?
                            Parameters[p].Element("custom_validation").Elements()
                            .Select(b => string.Format("{0},{1}", b.Name.ToString(), b.Value))
                            .ToList()
                            :
                            new List <string>();
                        // add the parameter details to the Action
                        Action.Parameters.Add(Parameter);
                    }
                    // Add the action to the service
                    Service.Actions.Add(Action);
                }
                // add the ervice to the list of supported services
                Config.Services.Add(Service);
            }

            //return the populated object
            return(Config);
        }