Search Results

Search found 5 results on 1 pages for 'ierror'.

Page 1/1 | 1 

  • Having trouble getting MEF imports to be resolved

    - by Dave
    This is sort of a continuation of one of my earlier posts, which involves the resolving of modules in my WPF application. This question is specifically related to the effect of interdependencies of modules and the method of constructing those modules (i.e. via MEF or through new) on MEF's ability to resolve relationships. First of all, here is a simple UML diagram of my test application: I have tried two approaches: left approach: the App implements IError right approach: the App has a member that implements IError Left approach My code behind looked like this (just the MEF-related stuff): // app.cs [Export(typeof(IError))] public partial class Window1 : Window, IError { [Import] public CandyCo.Shared.LibraryInterfaces.IPlugin Plugin { get; set; } [Export] public CandyCo.Shared.LibraryInterfaces.ICandySettings Settings { get; set; } private ICandySettings Settings; public Window1() { // I create the preferences here with new, instead of using MEF. I wonder // if that's my whole problem? If I use MEF, and want to have parameters // going to the constructor, then do I have to [Export] a POCO (i.e. string)? Settings = new CandySettings( "Settings", @"c:\settings.xml"); var catalog = new DirectoryCatalog( "."); var container = new CompositionContainer( catalog); try { container.ComposeParts( this); } catch( CompositionException ex) { foreach( CompositionError e in ex.Errors) { string description = e.Description; string details = e.Exception.Message; } throw; } } } // plugin.cs [Export(typeof(IPlugin))] public class Plugin : IPlugin { [Import] public CandyCo.Shared.LibraryInterfaces.ICandySettings CandySettings { get; set; } [Import] public CandyCo.Shared.LibraryInterfaces.IError ErrorInterface { get; set; } [ImportingConstructor] public Plugin( ICandySettings candy_settings, IError error_interface) { CandySettings = candy_settings; ErrorInterface = error_interface; } } // candysettings.cs [Export(typeof(ICandySettings))] public class CandySettings : ICandySettings { ... } Right-side approach Basically the same as the left-side approach, except that I created a class that inherits from IError in the same assembly as Window1. I then used an [Import] to try to get MEF to resolve that for me. Can anyone explain how the two ways I have approached MEF here are flawed? I have been in the dark for so long that instead of reading about MEF and trying different suggestions, I've added MEF to my solution and am stepping into the code. The part where it looks like it fails is when it calls partManager.GetSavedImport(). For some reason, the importCache is null, which I don't understand. All the way up to this point, it's been looking at the part (Window1) and trying to resolve two imported interfaces -- IError and IPlugin. I would have expected it to enter code that looks at other assemblies in the same executable folder, and then check it for exports so that it knows how to resolve the imports...

    Read the article

  • How to write to a varchar(max) column using ODBC

    - by andyjohnson
    Summary: I'm trying to write a text string to a column of type varchar(max) using ODBC and SQL Server 2005. It fails if the length of the string is greater than 8000. Help! I have some C++ code that uses ODBC (SQL Native Client) to write a text string to a table. If I change the column from, say, varchar(100) to varchar(max) and try to write a string with length greater than 8000, the write fails with the following error [Microsoft][ODBC SQL Server Driver]String data, right truncation So, can anyone advise me on if this can be done, and how? Some example (not production) code that shows what I'm trying to do: SQLHENV hEnv = NULL; SQLRETURN iError = SQLAllocEnv(&hEnv); HDBC hDbc = NULL; SQLAllocConnect(hEnv, &hDbc); const char* pszConnStr = "Driver={SQL Server};Server=127.0.0.1;Database=MyTestDB"; UCHAR szConnectOut[SQL_MAX_MESSAGE_LENGTH]; SWORD iConnectOutLen = 0; iError = SQLDriverConnect(hDbc, NULL, (unsigned char*)pszConnStr, SQL_NTS, szConnectOut, (SQL_MAX_MESSAGE_LENGTH-1), &iConnectOutLen, SQL_DRIVER_COMPLETE); HSTMT hStmt = NULL; iError = SQLAllocStmt(hDbc, &hStmt); const char* pszSQL = "INSERT INTO MyTestTable (LongStr) VALUES (?)"; iError = SQLPrepare(hStmt, (SQLCHAR*)pszSQL, SQL_NTS); char* pszBigString = AllocBigString(8001); iError = SQLSetParam(hStmt, 1, SQL_C_CHAR, SQL_VARCHAR, 0, 0, (SQLPOINTER)pszBigString, NULL); iError = SQLExecute(hStmt); // Returns SQL_ERROR if pszBigString len > 8000 The table MyTestTable contains a single colum defined as varchar(max). The function AllocBigString (not shown) creates a string of arbitrary length. I understand that previous versions of SQL Server had an 8000 character limit to varchars, but not why is this happening in SQL 2005? Thanks, Andy

    Read the article

  • Getting JSON object from php authentication objective c

    - by iError
    I am trying to authenticate using the below code NSString *urlAsString =[NSString stringWithFormat:@"http://www.myurl.com/abc/authenticate.php"]; NSURL *url = [NSURL URLWithString:urlAsString]; NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; [urlRequest setTimeoutInterval:30.0f]; [urlRequest setHTTPMethod:@"POST"]; [urlRequest addValue:@"test" forHTTPHeaderField:@"m_username" ]; [urlRequest addValue:@"123" forHTTPHeaderField:@"m_password" ]; [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response,NSData *data, NSError *error) { if ([data length] >0 && error == nil){ html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"HTML = %@", html); receivedData = [NSMutableData data]; } else if ([data length] == 0 && error == nil){ NSLog(@"Nothing was downloaded."); } else if (error != nil){ NSLog(@"Error happened = %@", error); } }]; // Start loading data NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; if (theConnection) { // Create the NSMutableData to hold the received data receivedData = [NSMutableData data]; } else { // Inform the user the connection failed. } My username password is correct, I think I am not making the proper call thats why I dont get the desired results and the web service is receiving the null parameters. What can be the issue? Any help appreciated.

    Read the article

  • powermock : ProcessBuilder redirectErrorStream giving nullPointerException

    - by kaustubh9
    I am using powermock to mock some native command invocation using process builder. the strange thing is these test pass sometimes and fail sometimes giving a NPE. Is this a powermock issue or some gotcha in the program. the snippet of the class under test is.. public void method1(String jsonString, String filename) { try { JSONObject jObj = new JSONObject(jsonString); JSONArray jArr = jObj.getJSONArray("something"); String cmd = "/home/y/bin/perl <perlscript>.pl<someConstant>" + " -k " + <someConstant> + " -t " + <someConstant>; cmd += vmArr.getJSONObject(i).getString("jsonKey"); ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd); pb.redirectErrorStream(false); Process shell = pb.start(); shell.waitFor(); if (shell.exitValue() != 0) { throw new RuntimeException("Error in Collecting the logs. cmd="+cmd); } StringBuilder error = new StringBuilder(); InputStream iError = shell.getErrorStream(); BufferedReader bfr = new BufferedReader( new InputStreamReader(iError)); String line = null; while ((line = bfr.readLine()) != null) { error.append(line + "\n"); } if (!error.toString().isEmpty()) { LOGGER.error(error`enter code here`); } iError.close(); bfr.close(); } catch (Exception e) { throw new RuntimeException(e); } and the unit test case is .. @PrepareForTest( {.class, ProcessBuilder.class,Process.class, InputStream.class,InputStreamReader.class, BufferedReader.class} ) @Test(sequential=true) public class TestClass { @Test(groups = {"unit"}) public void testMethod() { try { ProcessBuilder prBuilderMock = createMock(ProcessBuilder.class); Process processMock = createMock(Process.class); InputStream iStreamMock = createMock(InputStream.class); InputStreamReader iStrRdrMock = createMock(InputStreamReader.class); BufferedReader bRdrMock = createMock(BufferedReader.class); String errorStr =" Error occured"; String json = <jsonStringInput>; String cmd = "/home/y/bin/perl <perlscript>.pl -k "+<someConstant>+" -t "+<someConstant>+" "+<jsonValue>; expectNew(ProcessBuilder.class, "bash", "-c", cmd).andReturn(prBuilderMock); expect(prBuilderMock.redirectErrorStream(false)).andReturn(prBuilderMock); expect(prBuilderMock.start()).andReturn(processMock); expect(processMock.waitFor()).andReturn(0); expect(processMock.exitValue()).andReturn(0); expect(processMock.getErrorStream()).andReturn(iStreamMock); expectNew(InputStreamReader.class, iStreamMock) .andReturn(iStrRdrMock); expectNew(BufferedReader.class, iStrRdrMock) .andReturn(bRdrMock); expect(bRdrMock.readLine()).andReturn(errorStr); expect(bRdrMock.readLine()).andReturn(null); iStreamMock.close(); bRdrMock.close(); expectLastCall().once(); replayAll(); <ClassToBeTested> instance = new <ClassToBeTested>(); instance.method1(json, fileName); verifyAll(); } catch (Exception e) { Assert.fail("failed while collecting log.", e); } } I get an error on execution an the test case fails.. Caused by: java.lang.NullPointerException at java.lang.ProcessBuilder.start(ProcessBuilder.java:438) Note : I do not get this error on all executions. Sometimes it passes and sometimes it fails. I am not able to understand this behavior.

    Read the article

  • Android Java writing text file to sd card

    - by Paul
    I have a strange problem I've come across. My app can write a simple textfile to SD card and sometimes it works for some people but not for others and I have no idea why. Some people it force closes if they put some characters like "..." in it and such. I cannot seem to reproduce it as I've had no troubles but this is the code that handles it. Can anyone think of something that may lead to problems or a better to way to do it? public void generateNoteOnSD(String sFileName, String sBody){ try { File root = new File(Environment.getExternalStorageDirectory(), "Notes"); if (!root.exists()) { root.mkdirs(); } File gpxfile = new File(root, sFileName); FileWriter writer = new FileWriter(gpxfile); writer.append(sBody); writer.flush(); writer.close(); Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show(); } catch(IOException e) { e.printStackTrace(); importError = e.getMessage(); iError(); } }

    Read the article

1