Getting a resource in Xamarin - c#

I am trying to do something very basic: Have an ImageButton load an image and an associated sound and have that sound play. I thought it would be easy to do, but I'm having two problems (although it probably is two symptoms of the same problem).
One, I don't see the images I added to the Resources/drawable folder show up in the Resource.Drawable class, all I see there is the default Icon from icon.png. I added 20 images with a .jpg extension and set them to AndroidResource in properties. They were numerically named, so I modified them to start with a letter (in case that was the problem), got rid of a dot in the name (in case that was the problem), and finally renamed them to .jpeg (in case that was it). These don't seem to be reasons why they don't show up.
The Resource.Designer.cs works, though, because the two mp3s I added to the Resources/raw do show up in the class.
The other problem I have is that I can't tell how to load them programatically, so I can pass them to
imageButton.SetImageResource(imageId);
I tried
var imageId = this.Resources.GetIdentifier("DigiBord.Sunete:i00011", null, null);
which didn't work, but maybe the items were not in the project. So I tried again with an item I knew was in the project:
var imageId = this.Resources.GetIdentifier("DigiBord.Sunete:Icon", null, null);
which again yielded 0. There must be a way to load them without knowing the int id of the item ahead of time.

Related

Filter elements in Revit and set parameter

Hello everybody,
around two or three month ago I started to learn Dynamo for Revit... finally :)
After learning and testing a lot, I got a few own scripts working. Then I learned Python, because I couldn't create the next script only with Dynamo-Nodes.
Then I thought "Let's see how difficult it is to get something done as a PlugIn".
I watched some Videos and read a lot of stuff.
Finally I got the Revit-AddIn-Wizard installed and made my first small Test-PlugIn.
Great...
Now I have a few problems which I do not understand... so I thought I will try my luck here... because I got so much information and help, reading through this site.
My goal was/is the following: (I tell you what I have now)
A form with a few buttons, comboboxes and a DataGridView.
I can load an Excelfile, click on "Show" to show it in the DataGridView.
The header of each row will be automatically put into 3 comboboxes.
In the first combobox you select the first search-parameter, in the second you CAN select another search-parameter and in the third combobox you select the parameter you want to set.
I have a checkbox to switch from type- to instance-parameter for the search- and the set-operation.
There is also a button which shows another small form with a list of categories (I won't search for ALL, only nearly all modelcategories).
PlugIn
I took me a lot of "watching Videos, reading through the internet, testing, testing and testing".
Thanks to this site here and a few others... I managed to get this whole PlugIn nearly 100% working.
But now I have a few strange issues and I have absolutely no clue on how to fix them or if it is possible. And I really hope that someone can help me.
First... I just tell you my problems and perhaps someone can say "this really IS an issue!" or that it is possible to get it done. Then I would post some code.
So... what do I do?!
1. I have a FilteredElementCollector which filters ALL elements.
2. Depending on my "Type/Instance-Checkboxes" I do .WhereElementIsElementType OR .WhereElementIsNotElementType.
3. Then it passes a MultiCategoryFilter to get the big list down to only the modelcategories.
4. Next, the collection passes one of ten different "methods" depending on all settings. There I filter this collection depending on the searchlists-comboboxes. When the combobox says "Familie" or "Typ" then it filters for ".BuiltInParameter.SymbolFamilyName" or ".Name" otherwise it just uses ".LookupParameter".
After that I have a collection with only the elements of selected categories which contains the values from the Excellist.
5. Depending on what my search- and set-settings are (e.g. search for type and set instance) I have to get the instances from the collected types or the other way around.
6. Then I pass it down to another method where I finally set the parameter.
So... Excelheader goes into comboboxes, depending on what you select in there it creates lists with the values of the selected rows.
I hope you all understand.
Now... where are my problems?
When I search for type-familynames or instance-parameter and set a typeparameter it works for ALL categories without any error.
1. When I try to set an instanceparameter (doesn't matter what my search-setting are) it works for all "normal" families but not for the systemfamilies (e.g. walls, floors, pipes etc.). No error, just nothing happens WHY? It seems that I cannot set an instance-parameter for system-families.
2. Roofs, Stairs, CurtainPanels and GenericModel make problems when I search for a typeparameter Error is something like "The object reference was not set to an object instance". Only with these 4 categories and it doesn't matter what I want to set... but when I search for family-/typeNAME or Instance-Parameter, then I can set type or instance and it works (except instance for sysfam).
3. When I try to search AND set an instance-parameter it works for ALL categories EXCEPT if one wall does not contain a search value... it really is enough that ONE wall does not have a search-param-value that everything will be cancelled.
I have a few other small problems... but I hope someone can help me with these problems... I would be extremely thankfull
greetings and have a nice day or night :)
Philipp
Tl; dr.
The three problems you describe sound like your own. I have no heard anybody else runAsk three separate questions and provide three separate minimal code snippets describing how they arise,. into those. I suggest that you create three separate independent minimal reproducible cases to demonstrate all three issues. Chances are, when you simplify and minimalise your code, the problem will go away. If it does not, it might just possibly be in a small and manageable enough state for other people to help you take a look at it. Given the long-winded description above, nobody in the world can help you.
Thank you for your answer Jeremy,
as I said, as a first start it is ok for me if you don't say "With theses categories, there are indeed some issues!"
I think I've managed to create 3 small examples of my problems.
For each problem I made a zip-file containing the complete visual-studio folder, a small exampleproject and a readme.txt with (I hope) enough information to understand everything in detail.
Problem1
Problem3
You only need to compile them or copy the .addin and .ddl files into the Revit AddIn folder. Then you get the new ribbons.
Short problem summary = I get problems when searching for parametervalues and setting values to another parameter.
Edit: I just solved the 2. problem when searching for familynames and setting system-families-parameter.
I used:
ElementClassFilter ecf = new ElementClassFilter(typeof(FamilyInstance));
FilteredElementColletor colle2 = new FilteredElementCollector(doc);
colle2.WherePasses(ecf);
I simply deleted the ClassFilter and do it now like in the other cases where I need instances.
FilteredElementCollector colle2 = new FilteredElementCollector(doc);
colle2.WhereElementIsNotElementType();
The 1. and 3. problem still exist :/
I would be thankful for any help someone can provide :)

Target and Copy selection from one Excel file to another - C#

Quite some time ago I created a Powershell script to do what I wrote in the title: Copying a selection from File-A to File-B. The way I need it (and the way I did it) is to open a "Template" file when the application starts, the user selects a range, then they have 4 option buttons. The most-used is "Copy Selection", which will copy the contents of the range selection to all of the Excel files in a specific directory. With Powershell this works (although it took a long time to figure out) with the following code:
$strRow = $Excel.ActiveCell.Row
$strColumn = $Excel.ActiveCell.Column
$Range = $sourceWorksheet.Cells.item($strRow,$strColumn)
$Range.Select
$Excel.Selection.Copy() | Out-Null
foreach ($item in $files)
{
$destinationPath = $item.FullName
$destinationWorkBook = $Excel.WorkBooks.Open($destinationPath)
$destinationWorkSheet = $destinationWorkBook.worksheets.item(1)
$destRange = $destinationWorkSheet.Cells.item($strRow,$strColumn)
$destRange.Select
$destRange.PasteSpecial() | Out-Null
$destinationWorkBook.Close($true)
}
That works fine, but I obviously want to get rid of Powershell. I've created a C# application using WPF that will look and work great, I just have to get the logic working. I can't seem to actually target a range selection. I've tried a number of methods and properties, and none seem to get what I need. I can get the actual "selection" cell, but I can't get any type of range. The object I retrieve generally have Rows and Columns properties, so if need-be I guess I could extrapolate that information...but there's gotta be a better way.
Right now the closest thing I have would be to use Application.ActiveCell.Copy(); (or Select), but it seems to have issues when I try pasting it.
Any ideas? I can't seem to figure out why this isn't working.
EDIT: I've solved my own issue...sorry if anyone wasted time looking at this.
I'm an idiot...I spent a bit more time and figured out how to do it. The below code works perfectly - the main issue I was running into is that using Worksheet.Cells.item requires a bracket. I still have to loop through the documents to apply to, but this should take care of the actual logic:
int intRow = myApp.ActiveCell.Row;
int intCol = myApp.ActiveCell.Column;
myApp.Selection.Copy();
Range destRange = mySheet.Cells.Item[intRow,intCol];
destRange.PasteSpecial();
Hope I didn't waste anyone's time and they can figure this out now!

Orchard CMS Compute Derived Field on Create / Update

I'm building an Orchard content part for location data which include latitude and longitude fields. Whenever content is saved (created or updated), I would like to compute the bounding lat/lng for various max distances (20 miles, 50 miles, etc.) and save for later reference to search within a given radius of a specific location.
I already have all the necessary calculations for geolocation. The problem at hand is actually computing the derived value upon save (create/update), and setting the derived values to new fields on the content part before persisting to its repository.
I have a feeling adding filters like OnCreated in the associated ContentHandler might be a step in the right direction, but wasn't able to quickly locate any discussion related to a similar use case. So, I just wanted to reach out to the community and hear your thoughts on this particular problem before I proceed.
Thanks all!
You are on the right track with adding an OnCreated filter!
You could use OnUpdateEditorShape if you are only bothered about detecting when the content item is updated via the dashboard (or more generally, when the content item is updated using IContentManager.UpdateEditor(...)).
OnVersioning/OnVersioned will give you access to the "before" and "after" versions of a content item when it is updated, if your record class inherits from ContentPartVersionRecord (this will work with ContentPartRecord, but the "before" and "after" parameters will be the same).
You might want to look at this similar question.
Edit: "before" and "after" versions are called Existing and Building in VersionContentContext.

Trying to work with Request.Files in WebMatrix

everyone,
I am trying to work with uploading images to my site, and I have successfully gotten it to work, however, I need to extend the functionality beyond that of one simple image. The examples I have seen use the WebMatrix File Helper (File Helper? Is that right? Oh well, it's a helper of some kind that auto plots the html necessary for the input=type"file" field). The line of code I have in the form:
#FileUpload.GetHtml(initialNumberOfFiles:1, allowMoreFilesToBeAdded:false, includeFormTag:false)
The line of code I have in (IsPost):
var UploadedPicture = Request.Files[0];
if(Path.GetFileName(UploadedPicture.FileName) != String.Empty)
{
var ContentType = UploadedPicture.ContentType;
var ContentLength = UploadedPicture.ContentLength;
var InputStream = UploadedPicture.InputStream;
Session["gMugshot"] = new byte[ContentLength];
InputStream.Read((byte[])Session["gMugshot"], 0, ContentLength);
}
else
{
Session["gMugshot"] = new byte[0];
}
More code in the (IsPost) after this stores it in the database as binary data, and I can get the image back on the page from that (I have no desire to save the actual image files in a folder on the server and use GUID, etc. etc. Binary data is fine, and I imagine takes up a lot less space).
I have it set up to click-ably scroll through pictures by using jQuery to read the clicks of manually created buttons and subsequently hide and unhide the divs that contain the images rendered by C# (which gets them from reading the database). Sorry if that's a little TMI, just trying to be thorough, but to refine the question: I don't know enough about file uploading to know how to work with the uploaded data that well yet. I tried researching this information, but I didn't find any information that seemed pertinent to me (actually, I didn't find much useful information on input type="file", or the FileUpload method, at all, really).
Would it be better to use input type="file" id="pic1id"? Is there something that I can use such as Request.Files["pic1id"] that could get the file from the id of the input element? Or does the program simply take all uploaded files, stick them in a logistical group somewhere waiting to be called by index like this: "Request.Files[0]". If so, what order does the index get put in? Do I need to use Request.Files.Count to test how many have been uploaded before I begin working with the data?
Please note that I want separate input type="file" fields (whether plotted by the helper or not). I do not want to accept multiple files in one input (mainly because of a lack of knowledge, e.g., I am afraid I won't know how to work with the data). So far, the plan is that the separate input type="file" fields will be within the divs that get hidden/unhidden upon scrolling through pictures, so each picture (space) will have its own input type="file" field. The hiding and unhiding of divs, (the one) picture being displayed, storing and receiving binary data from the database, and clicking through the picture placeholders all function great. Pretty much I just need to know how to work with more than one uploaded picture at a time for storage in their individual database "image" fields.
Any examples of the syntax I need to use will be much appreciated.
Sorry so many questions, but I just couldn't find much useful information on this at all.
Thanks to any who try to help!
Okay, in order to solve this, I had to test and test and test, until something finally worked for me. Here's what I did:
First, I abandoned my use of the part of the helper that plotted the html, that is I took out:
#FileUpload.GetHtml(initialNumberOfFiles:1, allowMoreFilesToBeAdded:false, includeFormTag:false)
And added a regular input type="file" with a certain id, such as id="pic1".
Next I was able to get the individual file post based on id, which was really the main thing I needed to know how to do, and it really was as simple as this:
Request.Files["pic1"];

C# Comparing images: Are the images' files the same

I have seen only one solution for comparing images. But this solution checks if EVERYTHING about the images is the same. But I want to check if the images are loaded from the same image file from the resources.
I tried with
`"<object>.image == < image from the resources>"`
and
"<object>.Equals(<image from the resources>)"
but it didn't work. The way I know it "==" is used to checks if the two variables or objects are in the same place in the memory (are they the same thing) and "Equals" checks if the two variables or objects have the same values (correct me if I'm wrong). I have investigated why it always returns false.
So, is there a way to check if the images of two objects are loaded from the same image in the resources (are they using the same resource)?
If not, I'll have to make a new object or variable containing the image's name (that's the first thing that comes to my mind), because I want to compare only one thing about the images, not everything. If you have a better solution that you want to share with me, share it! I'll be happy to try a different algorithm.
you should use md5 int the equals function to quick check if its the same file....

Categories