将通用Windows应用程序转换为Windows窗体应用程序

时间:2016-11-11 10:14:02

标签: c# winforms uwp

正如您在标题中看到的,我想知道如何将UW应用程序转换为Windows窗体应用程序..我有一个使用Web服务的天气应用程序,我获取设备当前位置并获得温度和降水量在那个位置。

function pwr = my_fcn()

    % Parameters
    n0 = 1;      % air
    n1 = 1.4;    % layer 1
    n2 = 2.62;   % layer 2
    n3 = 3.5;    % silicon
    L0 = 650e-9; % centre wavelength

    % Reflection coefficients
    r01 = (n0 - n1)/(n0 + n1); 
    r12 = (n1 - n2)/(n1 + n2); 
    r23 = (n2 - n3)/(n2 + n3); 

    % Transmission coefficients
    t01 = (2*n0) / (n0 + n1); 
    t12 = (2*n1) / (n1 + n2); 
    t23 = (2*n2) / (n2 + n3);

    % Quality factors
    Q1  = [1 r01; r01 1];
    Q2  = [1 r12; r12 1];
    Q3  = [1 r23; r23 1];

    % Initial & Final wavelengths
    L_initial = 200e-9;
    L_final   = 2200e-9;

    % plot reflectivity for selected lambda range
    plot_reflectivity(L_initial, L_final, 1000);

    % Compute power production
    pwr = quadgk(@power_production, L_initial, L_final);


    % Helper functions
    % ========================================

    % Graph of lambda vs reflectivity
    function plot_reflectivity(L_initial, L_final, N)

        L = linspace(L_initial, L_final, N);

        R = zeros(size(L));
        for ii = 1:numel(L)

            % Transmission
            T = transmittivity(L(ii));

            % Percent reflectivity
            R(ii) = 100 * abs(T(2,1)/T(1,1))^2 ;

        end

        plot(L, R)
        title('Percent Reflectance vs. wavelength for 2 Layers')
        xlabel('Wavelength (m)')
        ylabel('Reflectance (%)')

    end

    % Compute transmittivity matrix for a single wavelength
    function T = transmittivity(L)

        % Layer phase thickness with variable Lamda
        y  = pi/2 * L0/L;

        % Matrix P with variable Lambda
        P1 = [exp(+1j*y) 0
              0           exp(-1j*y)];

        % Transmittivity matrix T1
        T = 1/(t01*t12*t23) * Q1*P1*Q2*P1*Q3;

    end

    % Power for a specific wavelength. Note that this function 
    % accepts vector-valued wavelengths; needed for quadgk()
    function pwr = power_production(L)

        pwr = zeros(size(L));

        for ii = 1:numel(L)

            % Transmittivity matrix
            T1 = transmittivity(L(ii));

            % Blackbody Irradiance
            I  = 6.16^(15) / ( (L(ii)*1e+9)^5 * (exp(2484/(L(ii)*1e+9)) - 1) );

            % final transmittivity
            Tf2 = abs(1/T1(1))^2 * n3/n0;

            % Power before integration
            pwr(ii) = Tf2 * I;   

        end

    end

end

还有这个位置经理:

public class OpenWeatherMapProxy
    {
        public async static Task<RootObject> GetWeather(double lat, double lon)
        {
            var http = new HttpClient();
            var url = String.Format("http://api.openweathermap.org/data/2.5/weather?lat={0}&lon={1}&units=metric&&appid=0bf2c880eef0aeccb66c4d403f9c5a7e", lat, lon);
            var response = await http.GetAsync(url);
            var result = await response.Content.ReadAsStringAsync();
            var serializer = new DataContractJsonSerializer(typeof(RootObject));

            var ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
            var data =  (RootObject)serializer.ReadObject(ms);

            return data;
        }
    }

我打电话给他们是这样的:

class LocationManager
    {
        public async static Task<Geoposition> GetPosition()
        {
            var accessStatus = await Geolocator.RequestAccessAsync();

            if (accessStatus != GeolocationAccessStatus.Allowed) throw new Exception();

            var geolocator = new Geolocator { DesiredAccuracyInMeters = 0 };

            var position =  await geolocator.GetGeopositionAsync();

            return position;
        }
    }

0 个答案:

没有答案