예제 #1
0
 static MyClass()
 {
     // Load functions and set them up as delegates
     MessageBox = (MessageBoxDelegate)
                  FunctionLoader.LoadFunction <MessageBoxDelegate>(
         @"c:\windows\system32\user32.dll", "MessageBoxA");
 }
예제 #2
0
    public GifskiInterop()
    {
        #region Get Gifski version

        var info = new FileInfo(UserSettings.All.GifskiLocation);
        info.Refresh();

        //I really need another way to differentiate gifski versions.
        switch (info.Length)
        {
        case 524_752:
            Version = new Version(1, 2, 0);
            break;

        case 502_720:
            Version = new Version(0, 10, 2);
            break;

        case 502_208:
            Version = new Version(0, 9, 3);
            break;

        default:
            Version = new Version(1, 2, 0);
            break;
        }

        #endregion

        #region Load functions

        _new         = FunctionLoader.LoadFunction <NewDelegate>(UserSettings.All.GifskiLocation, "gifski_new");
        _addPngFrame = FunctionLoader.LoadFunction <AddPngFrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_png_file");
        //_addRgbaFrame = (AddRgbaFrameDelegate)FunctionLoader.LoadFunction<AddRgbaFrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_rgba");

        if (Version.Major == 0 && Version.Minor < 10)
        {
            _addRgbFrame = FunctionLoader.LoadFunction <AddRgbFrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_rgb");
        }
        else
        {
            _addRgb2Frame = FunctionLoader.LoadFunction <AddRgb2FrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_rgb");
        }

        if (Version.Major == 0 && Version.Minor < 9)
        {
            //Older versions of the library.
            _endAddingFrames = FunctionLoader.LoadFunction <EndAddingFramesDelegate>(UserSettings.All.GifskiLocation, "gifski_end_adding_frames");
            _write           = FunctionLoader.LoadFunction <WriteDelegate>(UserSettings.All.GifskiLocation, "gifski_write");
            _drop            = FunctionLoader.LoadFunction <DropDelegate>(UserSettings.All.GifskiLocation, "gifski_drop");
        }
        else
        {
            //Newer versions.
            _setFileOutput = FunctionLoader.LoadFunction <SetFileOutputDelegate>(UserSettings.All.GifskiLocation, "gifski_set_file_output");
            _finish        = FunctionLoader.LoadFunction <FinishDelegate>(UserSettings.All.GifskiLocation, "gifski_finish");
        }

        #endregion
    }
예제 #3
0
 static MyClass()
 {
     // Load functions and set them up as delegates
     // This is just an example - you could load the .dll from any path,
     // and you could even determine the file location at runtime.
     MessageBox = (MessageBoxDelegate)
                  FunctionLoader.LoadFunction <MessageBoxDelegate>(
         @"c:\windows\system32\user32.dll", "MessageBoxA");
 }
예제 #4
0
        public void ParseErrorInScriptFileShouldBeDetected()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithParseError.ps1");
            var entryPointToUse     = string.Empty;
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var exception = Assert.Throws <ArgumentException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("parsing errors", exception.Message);
        }
예제 #5
0
        public void EntryPointIsSupportedWithPsm1FileOnly()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "BasicFuncScript.ps1");
            var entryPointToUse     = "Run";
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var exception = Assert.Throws <ArgumentException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("entryPoint", exception.Message);
            Assert.Contains("(.psm1)", exception.Message);
        }
예제 #6
0
        public void Psm1IsSupportedWithEntryPointOnly()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithEntryPoint.psm1");
            var entryPointToUse     = string.Empty;
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var exception = Assert.Throws <ArgumentException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("entryPoint", exception.Message);
            Assert.Contains("(.psm1)", exception.Message);
        }
예제 #7
0
        private static (AzFunctionInfo, PowerShellManager) PrepareFunction(string scriptFile, string entryPoint)
        {
            s_functionLoadRequest.Metadata.ScriptFile = scriptFile;
            s_functionLoadRequest.Metadata.EntryPoint = entryPoint;
            s_functionLoadRequest.Metadata.Directory  = Path.GetDirectoryName(scriptFile);

            FunctionLoader.LoadFunction(s_functionLoadRequest);
            var funcInfo  = FunctionLoader.GetFunctionInfo(s_functionLoadRequest.FunctionId);
            var psManager = NewTestPowerShellManager(s_testLogger);

            return(funcInfo, psManager);
        }
예제 #8
0
        public void EntryPointNeedToHaveParameters()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithEntryPoint.psm1");
            var entryPointToUse     = "Zoo";
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var exception = Assert.Throws <InvalidOperationException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("req", exception.Message);
            Assert.Contains("inputBlob", exception.Message);
        }
예제 #9
0
        public void MultipleEntryPointFunctionsShouldBeDetected()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithMultiEntryPoints.psm1");
            var entryPointToUse     = "Run";
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var exception = Assert.Throws <ArgumentException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("Run", exception.Message);
            Assert.Contains("FuncWithMultiEntryPoints.psm1", exception.Message);
        }
예제 #10
0
        public void EntryPointFunctionShouldExist()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithEntryPoint.psm1");
            var entryPointToUse     = "CallMe";
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var exception = Assert.Throws <ArgumentException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("CallMe", exception.Message);
            Assert.Contains("FuncWithEntryPoint.psm1", exception.Message);
        }
예제 #11
0
        public void InOutBindingIsNotSupported()
        {
            var scriptFileToUse = Path.Join(_functionDirectory, "BasicFuncScript.ps1");
            var entryPointToUse = string.Empty;

            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            functionLoadRequest.Metadata.Bindings.Add("inoutBinding", new BindingInfo {
                Direction = BindingInfo.Types.Direction.Inout, Type = "queue"
            });

            var exception = Assert.Throws <InvalidOperationException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("inoutBinding", exception.Message);
            Assert.Contains("InOut", exception.Message);
        }
예제 #12
0
        public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude, ISettings settings, AuthTicket authTicket = null)
        {
            _authToken  = authToken;
            _authType   = authType;
            _latitude   = latitude;
            _longitude  = longitude;
            _altitude   = altitude;
            _settings   = settings;
            _authTicket = authTicket;
            if (!InternalWatch.IsRunning)
            {
                InternalWatch.Start();
            }

            var hashBytes = new byte[16];

            RandomDevice.NextBytes(hashBytes);

            _sessionHash = ByteString.CopyFrom(hashBytes);

            if (_encryptNative != null)
            {
                return;
            }
            if (IntPtr.Size == 4)
            {
                _encryptNativeInit = (EncryptInitDelegate)
                                     FunctionLoader.LoadFunction <EncryptInitDelegate>(
                    @"Resources\encrypt32.dll", "MobBot");

                _encryptNative = (EncryptDelegate)
                                 FunctionLoader.LoadFunction <EncryptDelegate>(
                    @"Resources\encrypt32.dll", "encryptMobBot");
            }
            else
            {
                _encryptNativeInit = (EncryptInitDelegate)
                                     FunctionLoader.LoadFunction <EncryptInitDelegate>(
                    @"Resources\encrypt64.dll", "MobBot");

                _encryptNative = (EncryptDelegate)
                                 FunctionLoader.LoadFunction <EncryptDelegate>(
                    @"Resources\encrypt64.dll", "encryptMobBot");
            }
        }
예제 #13
0
        public void EntryPointParametersShouldMatchInputBindingWithTriggerMetadataParam()
        {
            var scriptFileToUse = Path.Join(_functionDirectory, "FuncWithEntryPointAndTriggerMetadata.psm1");
            var entryPointToUse = "Run";

            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            functionLoadRequest.Metadata.Bindings.Add("inputTable", new BindingInfo {
                Direction = BindingInfo.Types.Direction.In, Type = "tableTrigger"
            });
            functionLoadRequest.Metadata.Bindings.Remove("inputBlob");

            var exception = Assert.Throws <InvalidOperationException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("inputTable", exception.Message);
            Assert.Contains("inputBlob", exception.Message);
        }
        public void ParametersShouldMatchInputBindingWithSingleParam(string paramName)
        {
            var scriptFileToUse = Path.Join(_functionDirectory, $"BasicFuncScriptWith{paramName}.ps1");
            var entryPointToUse = string.Empty;

            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            functionLoadRequest.Metadata.Bindings.Add("inputTable", new BindingInfo {
                Direction = BindingInfo.Types.Direction.In, Type = "tableTrigger"
            });
            functionLoadRequest.Metadata.Bindings.Remove("inputBlob");

            var exception = Assert.Throws <InvalidOperationException>(
                () => FunctionLoader.LoadFunction(functionLoadRequest));

            Assert.Contains("inputTable", exception.Message);
            Assert.Contains("inputBlob", exception.Message);
        }
예제 #15
0
        public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude, ISettings settings, AuthTicket authTicket = null)
        {
            _authToken  = authToken;
            _authType   = authType;
            _latitude   = latitude;
            _longitude  = longitude;
            _altitude   = altitude;
            _settings   = settings;
            _authTicket = authTicket;
            if (!InternalWatch.IsRunning)
            {
                InternalWatch.Start();
            }

            if (SessionHash == null)
            {
                GenerateNewHash();
            }

            if (_encryptNative != null)
            {
                return;
            }
            if (IntPtr.Size == 4)
            {
                _encryptNativeInit = (EncryptInitDelegate)
                                     FunctionLoader.LoadFunction <EncryptInitDelegate>(
                    @"Resources\encrypt32.dll", "MobBot");

                _encryptNative = (EncryptDelegate)
                                 FunctionLoader.LoadFunction <EncryptDelegate>(
                    @"Resources\encrypt32.dll", "encryptMobBot");
            }
            else
            {
                _encryptNativeInit = (EncryptInitDelegate)
                                     FunctionLoader.LoadFunction <EncryptInitDelegate>(
                    @"Resources\encrypt64.dll", "MobBot");

                _encryptNative = (EncryptDelegate)
                                 FunctionLoader.LoadFunction <EncryptDelegate>(
                    @"Resources\encrypt64.dll", "encryptMobBot");
            }
        }
예제 #16
0
        public void TestFunctionLoaderGetFuncWithRequires()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithRequires.ps1");
            var entryPointToUse     = string.Empty;
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            FunctionLoader.LoadFunction(functionLoadRequest);
            var funcInfo = FunctionLoader.GetFunctionInfo(functionLoadRequest.FunctionId);

            Assert.Equal(scriptFileToUse, funcInfo.ScriptPath);
            Assert.Equal(string.Empty, funcInfo.EntryPoint);

            Assert.Null(funcInfo.FuncScriptBlock);

            Assert.Equal(2, funcInfo.FuncParameters.Count);
            Assert.True(funcInfo.FuncParameters.ContainsKey("req"));
            Assert.True(funcInfo.FuncParameters.ContainsKey("inputBlob"));

            Assert.Equal(3, funcInfo.AllBindings.Count);
            Assert.Equal(2, funcInfo.InputBindings.Count);
            Assert.Single(funcInfo.OutputBindings);
        }
        public void TestFunctionLoaderGetFuncWithEntryPoint()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithEntryPoint.psm1");
            var entryPointToUse     = "Run";
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var functionLoader = new FunctionLoader();

            functionLoader.LoadFunction(functionLoadRequest);

            var funcInfo = functionLoader.GetFunctionInfo(functionLoadRequest.FunctionId);

            Assert.Equal(scriptFileToUse, funcInfo.ScriptPath);
            Assert.Equal(entryPointToUse, funcInfo.EntryPoint);

            Assert.Equal(2, funcInfo.FuncParameters.Count);
            Assert.True(funcInfo.FuncParameters.ContainsKey("req"));
            Assert.True(funcInfo.FuncParameters.ContainsKey("inputBlob"));

            Assert.Equal(3, funcInfo.AllBindings.Count);
            Assert.Equal(2, funcInfo.InputBindings.Count);
            Assert.Single(funcInfo.OutputBindings);
        }
예제 #18
0
        public void TestFunctionLoaderGetFunc()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "BasicFuncScript.ps1");
            var entryPointToUse     = string.Empty;
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var functionLoader = new FunctionLoader();

            functionLoader.LoadFunction(functionLoadRequest);

            var funcInfo = functionLoader.GetFunctionInfo(functionLoadRequest.FunctionId);

            Assert.Equal(scriptFileToUse, funcInfo.ScriptPath);
            Assert.Equal(string.Empty, funcInfo.EntryPoint);

            Assert.Equal(2, funcInfo.FuncParameters.Count);
            Assert.Contains("req", funcInfo.FuncParameters);
            Assert.Contains("inputBlob", funcInfo.FuncParameters);

            Assert.Equal(3, funcInfo.AllBindings.Count);
            Assert.Equal(2, funcInfo.InputBindings.Count);
            Assert.Single(funcInfo.OutputBindings);
        }