Parallel Processing to Extract Data Using Revit API - revit-api

As I understand, you are not supposed to use parallel processing to do stuff in Revit through its API. More information is available at
http://thebuildingcoder.typepad.com/blog/2014/11/the-revit-api-is-never-ever-thread-safe.html
However, I am currently dealing with a problem of getting (and only getting) and then examining a lot of data to make some decisions. A sample code using TPL is given below, that seems to be working:
Parallel.ForEach<Element>(allDocumentElementsNotVisibleInCurrentView,
parallelOptions,
element =>
{
MyDerivedElement iaElement = new MyDerivedElement(uiDocument.Document, element, ElementStatusInView.Found);
// The following condition line does the real heavy lifting and can be a lengthy process, involving data extraction from Revit, such as bounding boxes, geometry and curves
if (iaElement.IsContained(iaView))
lock (result)
result.Add(iaElement);
});
So my question is, given that the above seems to work in tests, is it a good idea to let this one pass on parallel processing?
Thank you for your help!

The Revit API cannot be used outside a valid Revit API context, and such a context is only provided by a Revit event notification to be processed within a Revit event handler. The most common event is the external command Execute method. In the past, this requirement was not strictly enforced. However, use of the Revit API outside a valid Revit API context can lead to a crash and data corruption. Read-only access may still work, but is risky. I certainly would not store the Element instance itself. Storing the ElementId seems like a safer bet. Please expect to crash at any time.
My recommendation would be to reduce the Revit API interaction and processing to an absolute minimimum, collect all the data required for processing, terminate the Revit API interaction after collecting the data, and then run the pure calculations with no further Revit API interaction in a separate thread or several threads at a later point after leaving the Revit API context.

Related

How to create a event source system with nodejs and mongodb

I am quite new to event source concept but got glimpse that i need to divide my each task or operation to event and save those, but my basic do but is if for each request if you save each step as event then should not be the db size increase and large in short time also how to read it properly.
I just like to know if there any any blog or article or example that you guys could provide for reference and answer the above concerns.
I'm not sure if you are doing that for learning or for a real project, but in both cases I would suggest you to have a look at https://www.eventstore.com.
It is a db modeled to do event sourcing, also if not using it studying how it works will tell you what things you need to have in order to do it

posting to same URL but using 2 different functions

a portion of my application involves creating tests (i.e., picking x-number of questions from a filtered set of questions). The user is able to determine how big they want the test but to do so I need to calculate on the server how many questions are available. The function which creates the test is sent through this post:
app.post('/user/create_test', users.create_test);
As the user changes filters, I would like to determine the number of questions available... All I can think of is to use AJAX post to send the filter information but it will be passed to the same function as creating a test would... is there any way to post to the same URL but determine which function you execute?
Consider creating another function. - The best way to do Restful API's.
Consider renaming to app.post('/user/test').
The second function could be app.post('/user/test/filters').
Or make a single POST request and make sure your function does both creating and filtering.
In general, the design of the app lacks maturity. Rethink the client-server communications.

Clojure Security: Information Flow + Capability System

Summary
Is there something like http://en.wikipedia.org/wiki/E_programming_language as a DSL inside of Clojure?
Background
I'm aware of:
http://bit.ly/N4jnTI and http://bit.ly/Lm3SSD
However, neither provides what I want.
Context
I'm a big fan of both capability systems and information flow. And I'm wondering if anyone has developed Clojure DSLs for these two techniques. The following would be ideal:
all objects have some tag (say in it's meta table) that lists who has read access to the object
when I want to run a query as user "foo", I set some context var saying "now, use only the capabilities of foo" -- then the function, when it tries to reach objects, either gets the object (if foo has access to it) or nil (if foo does not have access to it). Leaking information bout the existence of objects is not a big deal to me at the moment.
Question
So the question is -- is this something easy to do as a Clojure DSL? Where each object has some capability tag, and we can execute pieces of function/code under certain tags, and the runtime system makes sure that no one gets access to things they're not supposed to access.
Thanks!
you can do this with metadata and preconditions and then create macros to add a DSL/syntax to it, though I would recommend skipping the macros and going for just preconditions and metadata.
Each object would have a piece of metadata with a list of it's capabilities.
Each function would have a precondition that checked the metadata.

Code generation against Sprocs?

I'm trying to understand choices for code generation tools/ORM tools and discover what solution will best meet the requirements that I have and the limitations present.
I'm creating a foundational solution to be used for new projects. It consists of ASP.NET MVC 3.0, layers for business logic and data access. The data access layer will need to go against Oracle for now, and then switch to SQL this year as the db migration is finished.
From a DTO standpoint mapping to custom types in the solution, what ORM/code generation tool will work with creating my needed code but can ONLY access Stored Procs in Oracle and SQL.?
Meaning, I need to generate the custom objects that are the artifacts from and being pushed to the stored procedures as the parameters, I don't need to generate the sprocs themselves, they already exist. I'm looking for the representation of what the sproc needs and gives back to be generated into DTOs. In some cases I can go against views and generate DTOs. I'm assuming most tools already do this. But for 90% of the time, I don't have access directly to any tables or views, only stored procs.
Does this make sense?
ORMs are best at mapping objects to tables (and/or views), not mapping objects to sprocs.
Very few tools can do automated code generation against whatever output a sproc may generate, depending on the complexity of the sproc. It's much more straight-forward to code generate the input to a sproc as that is generally well defined and clear.
I would say if you are stuck with sprocs, your options for using third party code to help reduce your development and maintenance time are severely limited.
I believe either LinqToSql or EntityFramework (or both?) are capable of some magic with regards to SQL Server to try to mostly automatically figure out what a sproc may be returning. I don't think it works all the time, it's just sophisticated guess work and I seriously doubt it would work with Oracle. I am not aware of anything else software-wise that even attempts to figure out what a sproc may return.
A sproc can return multiple diverse record sets that can be built dynamically by the sproc depending on the input and data in the database. A technical solution to automatically anticipating sproc output seems like it would require the following:
A static set of underlying data in the database
The ability to pass all possible inputs to the sproc and execute the sproc without any negative impact or side effects
That would give you a static set of possible outputs for any given valid input. A small change in the data in the database could invalidate everything.
If I recall correctly, the magic Microsoft did was something like calling the sproc passing NULL for all input parameters and assuming the output is always exactly the first recordset that comes back from the database. That is clearly an incomplete solution to the problem, but in simple cases it appears to be magic because it can work very well some of the time.

Is it possible to make cradle calls synchronously?

I'm using Express for a project, and I've been trying out the CouchDB database using Cradle. While the idea of asynchronous execution is cool for performance reasons, it's making my code really a mess for routines where I need to make several database calls in a row.
Is it possible to make cradle calls without using a callback? Or, I suppose more correctly, is there a better way to organize the code that doesn't involve nesting 3 or 4 anonymous functions within one another just to get at database query results? The code is only used in one place, so it doesn't make sense to me to use named functions that will only be called once.
Is it possible to make cradle calls without using a callback?
As far as I know cradle has only asynchronous API.
Or, I suppose more correctly, is there a better way to organize the
code that doesn't involve nesting 3 or 4 anonymous functions within
one another just to get at database query results?
I would first recommend to read following articles on flow control topic in order to get a bigger picture of what's going on:
Understanding Event-driven Programming
Asynchronous Code Design with Node.js
Understanding event loops and writing great code for Node.js
Node.js: Asynchronous I/O for Fun and Profit
Control Flow in Node
Control Flow in Node Part II
Control Flow in Node Part III
Asynchronous code in node.js
Then you can make things simple and take advantage of several flow control libraries which deals with issues of asynchronous code in node.js:
async
step

Resources