|
Thanks very much
|
|
|
|
|
Movies are a form of entertainment and not meant to educate. If you seek knowledge, find yourself a book on the topic and lock yourself in your room.
If you are new to Computer Science, I'd recommend "Introduction to Computer Science: A Textbook for Beginners in Informatics".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thank you very much for your guidance.I will seriously study "Introduction to Computer Science".
|
|
|
|
|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
Short circuit - unless somebody already posted that.
|
|
|
|
|
I've never worked with concurrency in SQL before.
I'm working on a WPF app hitting SQL through a Web API.
What's the right way to handle a concurrency violation? Do I need to check the timestamp myself in my DAL's update methods? Or will SQL throw an exception? If I have to check it myself, is throwing an exception the best way? What exception(s) are used for this?
What I'm really interested in here is the full workflow from the time the user clicks Save to either the data is saved or a violation is handled in the front end?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
A DBConcurrencyException[^] is thrown. This[^] shows how it is handled.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks.
Seems to me that after catching the DBConcurrencyException the only choice is to notify the user and reload the record.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Yes, since you do not know wheter the old record has been modified, or even still there. Would obviously not be happening often, since mostly there's not a lot of people working on the same record at the same moment.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Kevin Marois wrote: I've never worked with concurrency in SQL before.
What makes you think that the business (not technology) needs of the business will lead to a situation where, for whatever business reason, two updates might occur on the same record?
Note that I using "business" very specifically in the above. I am not referring to hypothetical scenarios.
And in general modern databases themselves do not have "concurrency" issues.
|
|
|
|
|
I've read the docs and it seems that processes writing to a single log file requires socket implementation. Really? is it not possible to create a static singelton class and logger instance, in a module, and import that single instance object into each module as the logger and use that? In either case, how might this be done simply and without extravagance.
|
|
|
|
|
"Static" or singleton have boundaries in which they work, in these cases the applications themselves. To do it simply, use the "Debug.WriteLine" methods. To see the log, simply attach a debugger.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi everybody. I have a question about Memento pattern.
Let's suppose we have a class which's state has to be saved and later restored, and we resorted to the Memento pattern for that.
What if the state includes resources that have to be explicitly released (like file handles, OpenGL textures etc)?
Should I make them part of the saved state? This necessitates to handle memento objects in a special manner: if memento was restored, then it's up to the originator class to handle the resources, if memento is dropped, then it has to clean up itself. Pretty entangled logic.
How would you implement Memento when state has resources to be released?
Should I apply Memento at all when object state includes OS resources that have to be released?
|
|
|
|
|
Member 13897152 wrote: What if the state includes resources that have to be explicitly released (like file handles, OpenGL textures etc)? I don't think it's a good idea to keep such things in a class that needs to be saved, since they will not be valid on restore.
|
|
|
|
|
You "save" things that may change. You don't simply save "everything" related to an object instance; things like "resources" are usually "common" to the class / assembly and are not "saved" for each object.
"Saving" is independent of any "cleaning up" you do "after" saving (key data).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Member 13897152 wrote: How would you implement Memento when state has resources to be released? Not; the originator has to release those - the memento itself is just there to hold an internal state.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Keep in mind that a resource that needs to be released is, by definition, an object, and is therefore tracked by your object as a memory reference.
This should inform the design decisions made on your originator. Do not use handles to track files, use paths. Do not load a texture into the originator; apply a method for locating a texture based on a primitive type. Don't contain streams in the originator, instead contain values that will help re-initialize them.
A lot of these issues are a big part of the reason why Model classes and MVC-like patterns have come into such heavy use in recent years.
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
So I have this design in Python2.7. Basically it is an EPG app that can read EPG programme events from 1 or more XMLTV sources. I would like to be able to use a generic code base and switch-in the XMLTV parsing code. For example, in 'C' I can use:
epg.c:
#ifdef _XMLTV_rytec
#include ./xmltv/rytec.h
#endif
#ifdef _XMLTTV_bbc
#include ./xmltv/bbc.h
#endif
...
...
load_xmltv()
...
... So what i can do here is define the preprocessor macros (_XMLTV_*) at make time, use the compiler directives to pull in the appropriate definitions for the desired xmltv parser, and switch in the corresponding source/object module (rytec.c/rytec.o and bbc.c/bbc.o) using the Makefile. Here for example, if XMLTV is not defined outside the Makefile at build (i.e. command line option) then the default rytec module is built in.
Makefile:
..
XMLTV_OBJS = ./src/xmltv/rytec.o
EPG_OBJS = epg.o $(XMLTV_OBJS)
..
obj/%.o:%.c
gcc -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
epg: $(EPG_OBJS) \
gcc -o $@ $(CFLAGS) $(EPG_OBJS) $(LDFLAGS) $(LDLIBS)
.. How can I achieve the same thing in Python please?
modified 3-Jul-18 6:27am.
|
|
|
|
|
if XMLTV = 'something':
import xmltva
else:
import xmltvb
|
|
|
|
|
you're kidding!! that easy. Well, i tried and it the interpreter complains about XMLTV not being set. So on my linux box...
XMLTV='bbc' python test.py
It's not picking up the XMLTV but i bet there is a way to get this from the OS shell ?? I'll search..
**EDIT**:
if os.environ['XMLTV'] == 'bbc':
import xmltv.bbc PERFECT! works a treat.
My god this Python is simple it's actually quite hard to learn coming from such a typesafe statically synataxically tight langauge as C !!
modified 3-Jul-18 9:37am.
|
|
|
|
|
Remember, Python is interpreted, not compiled and linked, so the mechanics of it are quite different from C/C++ etc.
|
|
|
|
|
agreed... I'm getting there
and Richard
this time
THANKS
|
|
|
|
|
Appreciated; happy to help.
|
|
|
|
|
I'm starting a new project. I've always used Linq-to-SQL. This time I'm going to use EF and the Repository pattern. Also, I'm really new to Web API's, so if I made a mistake, please let me know.
So I spent the last few days researching EF and the Repository Pattern/Unit of Work. I understand the Unit of Work concept and that EF is by design a Unit of Work. Having said that, here is what I've come up with. I'd like your opinion.
Repository Interface
public interface IRepository<TEntity> where TEntity : class
{
TEntity Get(int id);
IEnumerable<TEntity> GetAll();
IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate);
void Add(TEntity entity);
void AddRange(IEnumerable<TEntity> entities);
void Remove(TEntity entity);
void RemoveRange(IEnumerable<TEntity> entities);
}
Repository Base Class
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class
{
protected DbContext Context { get; private set; }
public Repository(DbContext context)
{
Context = context;
}
public TEntity Get(int id)
{
return Context.Set<TEntity>().Find(id);
}
public void Add(TEntity entity)
{
Context.Set<TEntity>().Add(entity);
}
}
Projects Interface and Repository
This class allows me to add specialized project-related data functions.
public interface IProjectsRepository : IRepository<Project>
{
IEnumerable<Project> FindProjectsByName(string name);
}
public class ProjectsRepository : Repository<Project>, IProjectsRepository
{
FalconContext _context;
public ProjectsRepository(FalconContext context)
: base(context)
{
_context = context;
}
public IEnumerable<Project> FindProjectsByName(string name)
{
Expression<Func<Project, bool>> nameFilter = e => e.ProjectName.Contains(name);
return Find(nameFilter);
}
}
Biz Layer
This class is the only class that knows about the data later. The controllers all call into here. That allows me to apply business logic in true Units of Work:
public class BizObject : IBizObject
{
private IProjectsRepository projectsRepository;
public void AddProject(Project entity)
{
using (var dc = new FalconContext())
{
var projectRepo = new ProjectsRepository(dc);
var projectTaskRepo = new ProjectsTaskRepository(dc);
var test = projectRepo.FindProjectsByName(entity.ProjectName);
if (test != null)
{
projectRepo.Add(entity);
foreach (var task in entity.Tasks)
{
projectTaskRepo.Add(task);
}
dc.SaveChanges();
}
else
{
throw new DuplicateProjectException(entity.ProjectName);
}
}
}
}
Controller
public class ProjectsController : ApiController
{
private IBizObject _bo;
public IHttpActionResult AddProject(Project entity)
{
_bo = new BizObject();
_bo.AddProject(entity);
return Ok();
}
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|