Outlook Addin duplicated attachment - outlook

I have an Outlook addin written in unmanaged C++ which uses Outlook Object Model API.
The code copies Microsoft Office files (doc, docx, xls, xlsx, etc...) and PDF attachments to the temporary folder. Then the code manipulates those files, and after that, it deletes the original attachment files and attaches the processed files.
Recently one of our customers reported duplicate attachment issue. I put some additional diagnostics, and here is what I see:
Here is the pseudo code of the diagnostic function:
bool COutlookAttachmentHelper::AreThereDuplicatesOnInput(long count)
{
std::vector<std::wstring> vFileNames;
for(int i = count; i > 0; i--)
{
//get attachment filename
.....
// try to find it in the vector defined above
std::vector<std::wstring>::iterator findIter = std::find(vFileNames.begin(), vFileNames.end(), strFileName);
// if not found push it into the vector and return false
// if found, write the filename to the log file, pop up the message
// box, return true (cancel email).
}
}
If the duplicates aren't found, then the code executes another loop to copy the files of interest to the temporary folder
the for loop is constructed the same way:
Here is what I see in my diagnostic log file:
Searching for the duplicates
Some Word Document.DOC
image003.gif
image002.png
image001.png
End of Searching for the duplicates
// Below is the output from the second loop
// I'm filtering out non Office and non PDF files
Some Word Document.DOC
Some Word Document.DOC
We can't reproduce the issue in our labs and none of the other customers report it.
Anyone have a clue?
Regards,
Michael

Related

Photoshop script .DS_Store

I'm using Photoshop script. I get files from folders. My problem is that when I get the files and place them in an array the array contains hidden files that are in the folder for example ".DS_Store". I can get around this by using:
if (folders[i] != "~/Downloads/start/.DS_Store"){}
But I would like to use something better as I sometimes look in lots of folders and don't know the "~/Downloads/start/" part.
I tried to use indexOf but Photoshop script does not allow indexOf. Does anybody know of a way to check if ".DS_Store" is in the string "~/Downloads/start/.DS_Store" that works in Photoshop script?
I see this answer but I don't know how to use it to test: Photoshop script to ignore .ds_store
For anyone else looking for a solution to this problem, rather than explicitly trying to skip hidden files like .DS_Store, you can use the Folder Object's getFiles() method and pass an expression to build an array of file types you actually want to open. A simple way to use this method is as follows:
// this expression will match strings that end with .jpg, .tif, or .psd and ignore the case
var fileTypes = new RegExp(/\.(jpg|tif|psd)$/i);
// declare our path
var myFolder = new Folder("~/Downloads/start/");
// create array of files utilizing the expression to filter file types
var myFiles = myFolder.getFiles(fileTypes);
// loop through all the files in our array and do something
for (i = 0; i < myFiles.length; i++) {
var fileToOpen = myFiles[i];
open(fileToOpen);
// do stuff...
}
For anybody looking I used the Polyfill found here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
indexOf() was added to the ECMA-262 standard in the 5th edition; as
such it may not be present in all browsers. You can work around this
by utilizing the following code at the beginning of your scripts. This
will allow you to use indexOf() when there is still no native support.
This algorithm matches the one specified in ECMA-262, 5th edition,
assuming TypeError and Math.abs() have their original values.

Counting number of files from folder on Windows Phone

I have a folder with a number of .wav files inside. I need to dynamically count these files in order to generate the sound in a random way. I need this dynamically, so I don't need to update code everytime I update the sound folder with another sound.
I searched how to do it, but could only found examples for Windows. Here's the code I came up with:
string path = string.Format("/Sound/{0}", sourceSound);
return Directory.GetFiles(path, ".wav").Length;
I tried running it, but VS gives me the error:
"Unable to step. The code is currently unavailable."
Is there anything I'm doing wrong, or any other case how can we count the number of files inside a folder?
Thanks.
Try
using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
var i = myIsolatedStorage.GetFileNames("*.wav").Length;
}
For some reason I couldn't make the example Vitalii gave me work. I was never able to get the count of files I have in the volder.
Looking over the internet, I stumbled upon this link:
confused about resources and GetManifestResourceNames()
The answer Zack gave on this thread, gave the insight I needed to make my App work.
I used Embedded Resource to find all the count of files I needed and, then, play the with a SoundEffectInstance.
The following link helped on this:
http://matthiasshapiro.com/2011/01/10/embedding-a-sound-file-in-windows-phone-7-app-silverlight/
Here's how I managed to make it work:
soundCount = GetSoundCount();
private int GetSoundCount()
{
return Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(name => name.Contains(sourceImg)).Count();
}
With these few lines I managed to get the exact number of files I have in my App.
To make the sound play, I used the second link as an example and produced the code below:
if(soundInstance != null)
soundInstance.Stop();
this.soundInstance = SetNextSource();
soundInstance.Play();
private SoundEffectInstance SetNextSource()
{
Random random = new Random();
Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(string.Format("Assembly Name.Folder.{0}.{1}.wav", SubFolder, FileName + random.Next(soundCount)));
SoundEffect se = SoundEffect.FromStream(stream);
return se.CreateInstance();
}
Well after a few days o research finally managed to make it work.
Hope this thread helps people facing the same problem I did.
Thanks.

Using ExtAudioFileWrite to write at the end of a file

I'm trying to open a file and append data to it using ExtAudioFileWrite. Now, creating/initial writing(on creation)/converting works just fine, but unfortunately I can't seem to be able to open the file for writing afterwards. There is only one function that seems to open the file: ExAudioFileOpenURL but only for reading. So, how can I write at the end of a file if I'm not able to open the file for writing?
I might be wrong, or not fully understanding your question. But, once you start writing to the file using ExtAudioFileWrite you can keep writing to it by calling the ExtAudioFileWrite again. I am about to venture into coding with no compiler, hopefully you will get the idea
Example:
....variables declaration and your logic.....
//1.Create File to write output
ExtAudioFileRef outputFile;
//+++++++ LOOP to append as many files as you want +++++++//
//2.Create file reference to files you want to merge
ExtAudioFileRef audioFileObject = 0;
//3.open the first file
ExtAudioFileOpenURL (firstFileURL, &audioFileObject);
//4.get file properties
AudioStreamBasicDescription AudioFileFormat = 0;
UInt64 numberOfPacketsToReadInCurrentFile = 0;
ExtAudioFileGetProperty(audioFileObject,
kExtAudioFileProperty_FileLengthFrames,
sizeof(numberOfPacketsToReadInCurrentFile),
&numberOfPacketsToReadInCurrentFile
);
ExtAudioFileGetProperty(audioFileObject,
kExtAudioFileProperty_FileDataFormat,
sizeof(AudioFileFormat),
&AudioFileFormat
);
//5.Set destination ASBD
ExtAudioFileSetProperty(audioFileObject,
kExtAudioFileProperty_ClientDataFormat,
sizeof (importFormat),
&importFormat
);
//6.Set/Create/Allocate Some Buffers
//use AudioFileFormat to setup your buffers accordingly
AudioBufferList theBufferList = 0 // bufferList setup (I dont remember that)
//7.Read the file into the buffer
ExtAudioFileRead(audioFileObject,&numberOfPacketsToReadInCurrentFile,theBufferList);
//8.Write the buffer to a File
ExtAudioFileWrite(outputFile, numberOfPacketsToReadInCurrentFile, theBufferList);
free(theBufferList);
//if you want to append more files go to point 2 with the next file URL
//+++++++CLOSE LOOP+++++++++//
//once you are done.. just dispose the file and clean up everything left
ExtAudioFileDispose(outputFile);
This will not compile, I guess. But hopefully will help you get the idea.

Validation : how to check if the file being uploaded is in excel format? - Apache POI

Is there any way I can check if the file being uploaded is in excel format? I am using Apache POI library to read excel, and checking the uploaded file extension while reading the file.
Code snippet for getting the extension
String suffix = FilenameUtils.getExtension(uploadedFile.getName());
courtesy BalusC : uploading-files-with-jsf
String fileExtension = FilenameUtils.getExtension(uploadedFile.getName());
if ("xls".equals(fileExtension)) {
//rest of the code
}
I am sure, this is not the proper way of validation.
Sample code for browse button
<h:inputFileUpload id="file" value="#{sampleInterface.uploadedFile}"
valueChangeListener="#{sampleInterface.uploadedFile}" />
Sample code for upload button
<h:commandButton action="#{sampleInterface.sampleMethod}" id="upload"
value="upload"/>
User could change an extension of a doc or a movie file to "xls" and upload,then it would certainly throw an exception while reading the file.
Just hoping somebody could throw some input my way.
You can't check that before feeding it to POI. Just catch the exception which POI can throw during parsing. If it throws an exception then you can just show a FacesMessage to the enduser that the uploaded file is not in the supported excel format.
Please try to be more helpful to the poster. Of course you can test before poi.
Regular tests, to be performed before the try/catch, include the following. I suggest a fail-fast approach.
Is it a "good" file?
if file.isDirectory() -> die and exit.
if !file.isReadable() -> die and exit.
if file.available <= 100 -> die and exit (includes file size zero)
if file.size >= some ridiculous large number (check your biggest excel file and multiply by 10)
File seems good, but is contents like Excel?
Does it start with "ÐÏà" -> if not, die.
Does it contain the text "Sheet"-> if not, die
Some other internal excel bytes that I expected from you guys here.

VS2010 save array/collection data to a file while debugging

Is there some way to save array/list/collection data to a file while debugging in VS2010?
For example, in this code:
var addressGraphs = from a in context.Addresses
where a.CountryRegion == "Canada"
select new { a, a.Contact };
foreach(var ag in addressGraphs) {
Console.WriteLine("LastName: {0}, Addresses: {1}", ag.Contact.LastName.Trim(),
ag.Contact.Addresses.Count());
foreach(var Address in ag.Contact.Addresses) {
Console.WriteLine("...{0} {1}", Address.Street1, Address.City);
}
}
I'd like to set a breakpoint on the first 'foreach' line and then save the data in 'addressGraph' to a file.
where 'a' contains fields such as:
int addressID
string Street1
string City
<Ect.>
and 'Contact' contains fields such as:
string FirstName
string LastName
int contactID
<Ect.>
I'd like the file to contain the values of each of the fields for each item in the collection.
I don't see an obvious way to do this. Is it possible?
When your breakpoint is hit, open up the Immediate window and use Tools.LogCommandWindowOutput to dump the output to a file:
>Tools.LogCommandWindowOutput c:\temp\temp.log
?addressGraphs
>Tools.LogCommandWindowOutput /off
Note: You can use Log which is an alias for Tools.LogCommandWindowOutput
Update:
The > character is important. Also, the log alias is case sensitive.
See screenshot:
I also encoutered such a question, but in VS2013. I have to save a content of array while debugging.
For example, I need to save a content of double array named "trimmedInput". I do so:
Open QuickWatch Window from Debug menu (Ctrl+D, Q).
Put your variable in Expression and push Recalculate Button
You'll see all the values. Now you could select them all (Ctrl+A) and copy (Ctrl+C).
Paste (Ctrl+V) them in your favorite editor. Notepad, for example. And use them.
That's the simples way that I know. Without additional efforts. Hope that my description helps you!
P.S. Sorry for non English interface on screenshots. All necessary information are written in the text.
Something similar is possible with this method:
I built an extension method that I use in all of my projects that is a general and more powerful ToString() method that shows the content of any object.
I included the source code in this link:
https://rapidshare.com/files/1791655092/FormatExtensions.cs
UPDATE:
You just have to put FormatExtensions.cs in your project and change the Namespace of FormatExtensions to coincide to the base Namespace of your project. So when you are in your breakpoint you can type in your watch window:
myCustomCollection.ToStringExtended()
And copy the output wherever you want
On Visual studio Gallery search for: Object Exporter Extension.
be aware: as far as I worked with, it has a bug that block you from exporting object once in a while.
You can also call methods in the Immediate Window, and so I think your best bet would be to use an ObjectDumper object, like the one in the LINQ samples or this one, and then write something like this in the Immediate Window:
File.WriteAllText("myFileName.txt", ObjectDumper.Dump(addressGraph));
Depending on which ObjectDumper you decide to use, you may be able to customize it to suit your needs, and to be able to tell it how many levels deep you want it to dig into your object when it's dumping it.
Here's a solution that takes care of collections. It's a VS visualizer that will display the collection values in a grid while debugging as well as save to the clipboard and csv, xml and text files. I'm using it in VS2010 Ultimate. While I haven't tested it extensively, I have tried it on List and Dictionary.
http://tinyurl.com/87sf6l7
It handles the following collections:
•System.Collections classes
◦System.Collections.ArrayList
◦System.Collections.BitArray
◦System.Collections.HashTable
◦System.Collections.Queue
◦System.Collections.SortedList
◦System.Collections.Stack
◦All classes derived from System.Collections.CollectionBase
•System.Collections.Specialized classes
◦System.Collections.Specialized.HybridDictionary
◦System.Collections.Specialized.ListDictionary
◦System.Collections.Specialized.NameValueCollection
◦System.Collections.Specialized.OrderedDictionary
◦System.Collections.Specialized.StringCollection
◦System.Collections.Specialized.StringDictionary
◦All classes derived from System.Collections.Specialized.NameObjectCollectionBase
•System.Collections.Generic classes
◦System.Collections.Generic.Dictionary
◦System.Collections.Generic.List
◦System.Collections.Generic.LinkedList
◦System.Collections.Generic.Queue
◦System.Collections.Generic.SortedDictionary
◦System.Collections.Generic.SortedList
◦System.Collections.Generic.Stack
•IIS classes, as used by
◦System.Web.HttpRequest.Cookies
◦System.Web.HttpRequest.Files
◦System.Web.HttpRequest.Form
◦System.Web.HttpRequest.Headers
◦System.Web.HttpRequest.Params
◦System.Web.HttpRequest.QueryString
◦System.Web.HttpRequest.ServerVariables
◦System.Web.HttpResponse.Cookies
As well as a couple of VB6-compatible collections
In "Immediate Window" print following to get the binary dump:
byte[] myArray = { 02,01,81,00,05,F6,05,02,01,01,00,BA };
myArray
.Select(b => string.Format("{0:X2}", b))
.Aggregate((s1, s2) => s1 + s2)
This will print something like:
0201810005F60502010100BA
Change the '.Aggregate(...)' call to add blanks between bytes, or what ever you like.

Resources