我有一个C#解决方案,其中有2个项目,我需要从代码生成类图.
我知道Visual Studio中有一个内置的图表工具,但我使用的是2010快递,但它没有.有没有能够创建它的免费软件?我只关注类层次结构的图片,仅此而已.
我有ASP.NET与MVC和Razor标记网站,我想在我的Linux VPS上运行它.
我有单声道3.2.8和xsp4 3.0.0.0版本,都来自Ubuntu存储库(已安装使用apt-get install mono-complete mono-xsp4)
当我将我的网站上传到服务器并在网站的文件夹中运行xsp4时,它会启动并打印出它正在侦听端口8080.但是,当我使用我的Web浏览器导航到我的网站时,它会显示运行时错误,xsp4会将此输出到控制台
Missing method System.Web.HttpApplication::RegisterModule(Type) in assembly
/usr/lib/mono/gac/System.Web/4.0.0.0__b03f5f7f11d50a3a/System.Web.dll, referenced
in assembly /tmp/root-temp-aspnet-0/55726984/
assembly/shadow/df4b0596/52105b83_8d5b5e15_00000001/Microsoft.Owin.Host.SystemWeb.dll
Missing method RegisterAllAreas in assembly /tmp/root-temp-aspnet-
0/55726984/assembly/shadow/dc5a60b8/51013ead_8d5b5e15_00000001/<website_name>.dll, type
System.Web.Mvc.AreaRegistration
Run Code Online (Sandbox Code Playgroud)
这是一个全新的Ubuntu 14.04安装.我正在使用Visual Studio 2013在Windows上开发我的网站.任何想法如何解决这些错误?
我有一个矩阵类,使用[] []来访问元素.当一个(或两个)索引超出范围时,我必须抛出CIndexException.它是以"无效索引[a] [b]"格式存储文本的类,其中a和b是数字.
这是我当前实现的CIndexException类
class CIndexException
{
string text;
public:
CIndexException (int a, int b)
{
ostringstream oss;
oss << "Invalid index [";
oss << a;
oss << "][";
oss << b;
oss < "]";
text = oss.str();
}
string get() const
{
return text;
}
};
Run Code Online (Sandbox Code Playgroud)
Matrix表示为二维的二维数组,它在构造函数中初始化:
CMatrix(int r, int c)
{
colls = c;
rows = r;
mat = new double * [rows];
for (int i = 0; i < rows; i++)
{
mat[i] = new double [colls]; …Run Code Online (Sandbox Code Playgroud) 我正在学习SFML,我在程序中有这些代码:
if (!texture.loadFromFile("Textures/plane.png"))
{
std::cout << "Error loading texture plane.png" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我在文件夹Text文件中的文件plane.png与可执行文件位于同一文件夹中.当我通过Windows资源管理器运行可执行文件时,纹理加载没有任何问题,但当我在VS中运行它作为调试时,我得到这个输出:
Failed to load image "Textures/plane.png". Reason: Unable to open file
Error loading texture plane.png
Run Code Online (Sandbox Code Playgroud)
第一行来自SFML,第二行来自我的程序.
有没有办法来解决这个问题?我还尝试将textures文件夹放到项目根文件夹中的几个不同位置,但没有更改.
我正在关注一本关于SFML游戏开发的书,但我卡在第二章,因为我无法编译我刚刚写的代码。
它几乎是书中的逐字复制(除了成员变量名称和异常文本)。我有使用 C++ 和模板的经验,但我以前从未见过这个错误,我已经盯着这个看了几个小时,我没有发现这段代码有什么问题。
这是我的 *.h 文件:
#pragma once
#include <map>
#include <memory>
#include <string>
#include <stdexcept>
#include <cassert>
#include "enumFile.h"
template <typename Resource, typename Identifier>
class ResourceHolder
{
public:
ResourceHolder(void);
~ResourceHolder(void);
void load(Identifier id, const std::string & filename);
template <typename Parameter>
void load(Identifier id, const std::string & filename,
const Parameter& secondParam);
Resource & get(Identifier id);
const Resource & get(Identifier id) const;
private:
std::map<Identifier, std::unique_ptr<Resource>> resourceMap;
};
#include "ResourceHolder.inl"
Run Code Online (Sandbox Code Playgroud)
这是我的 *.inl 文件:
template <typename Resource, typename Identifier>
void ResourceHolder<Resource, Identifier>::load(Identifier …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的域模型(剥离了一些不重要的属性)
public class User
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual int UserId { get; set; }
private ICollection<Recipe> _recipes;
public virtual ICollection<Recipe> Recipes
{
get { return _recipes ?? new List<Recipe>(); }
set { _recipes = value; }
}
}
public class Recipe
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int RecipeId { get; set; }
private ICollection<Ingredient> _ingredients;
public virtual ICollection<Ingredient> Ingredients
{
get { return _ingredients ?? new List<Ingredient>(); }
set { _ingredients = value; }
}
public User User { get; …Run Code Online (Sandbox Code Playgroud) 我有一个类和两个方法:
public:
bool Search ( const string & oName, const string & oAddr,
string & cName, string & cAddr ) const
{
Company ctmp;
ctmp.own = oName + "|" + oAddr;
int place = searchDupl(ctmp,currentsize,0);
if (place < 0)
return false;
else
{
size_t pos = c[place].cmpn.find(' ');
cName = c[place].cmpn.substr(0,pos);
cAddr = c[place].cmpn.substr(pos+1);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
在私下里,我有searchDupl:
int searchDupl(Company cmp,int imax,int imin)
{
if (imax < imin)
return -1;
else
{
int mid = imin + ((imax - …Run Code Online (Sandbox Code Playgroud) 我有一个创建多个线程的类,每个线程在构造函数中获取一个套接字作为参数.
我需要同步线程,以便只有一个线程在给定时间访问套接字流.
以下是我需要的快速草稿:
class MyClass{
Socket socket;
public MyClass() {
socket = new Socket(address, port);
}
void createThread(){
Worker worker = new Worker(socket);
Thread t = new Thread(worker);
t.start();
}
void doStuff(){
InputStream is = socket.getInputStream();
/* ... */
}
}
class Worker implements Runnable{
Socket socket;
public Worker(Socket socket){
this.socket = socket;
}
@Override
public void run() {
InputStream is = socket.getInputStream();
/* ... */
}
}
Run Code Online (Sandbox Code Playgroud)
现在,可能多个线程可以同时访问套接字输入流,这将是非常糟糕的.
现在我的问题是:synchronized关键字是否适用于此案例?
我有一个看起来像这样的类结构:
class Bar
{
public:
Bar & AddPart(int size, const string & name)
{
partitions.insert(pair<string, int>(name,size));
return *this;
}
void PrintParts(ostream & os) const
{
map<string, int>::const_iterator it;
for (it = partitions.begin(); it != partitions.end(); ++it)
{
os << it->first << " " << it->second << endl;
}
}
private:
std::map<string, int> parts;
}
class Foo
{
public:
Foo & AddElement(Bar &a)
{
elements.push_back(&a);
return *this;
}
private:
vector<Bar *> elements;
};
Run Code Online (Sandbox Code Playgroud)
我返回当前类实例的原因是能够链接方法调用,如下所示:
Foo f();
f.AddElement(Bar().AddPart(10,"abcd").AddPart(5,"xyz").AddPart(20, "jklm"));
Run Code Online (Sandbox Code Playgroud)
问题是,当我调用这些链式方法然后尝试打印数据时,它已损坏.而不是得到预期的输出,这应该是这样的:
abcd 10 …Run Code Online (Sandbox Code Playgroud) 我最近学会了如何使用堆和heapsort的美丽.我决定将heapsort与C++中的std :: sort和Java中的Arrays.sort()进行比较.我整理了一个整数数组,每个整数随机生成在<0; 20亿)
我在Java中用数组生成100,000,000个整数,并运行Arrays.sort(),然后生成新的随机序列并运行我的heapSort().这是我的Java程序的输出:
Arrays.sort time: 10.923 seconds.
Heap sort time: 1.402 seconds.
Run Code Online (Sandbox Code Playgroud)
所以heapsort大约快8倍.
然后我在C++中运行类似的代码,这次使用std :: vector作为我的容器(由于std :: sort需要两个迭代器).
C++结果:
Heapsort: 3.213
std::sort: 37.264
Run Code Online (Sandbox Code Playgroud)
所以在我的程序中,std :: sort大约慢了12倍.
在Java中,我使用System.currentTimeMilis()测量时间,在C++中我使用了clock().
这是在Windows 7,四核英特尔i5 2500k上进行测试,超频至4.8GHz.C++是用-Wall -pedantic标志编译的.
谁能告诉我发生了什么事?heapsort真的那么快吗?或者我在代码中犯了错误?我不希望用大量代码充斥这篇文章,所以我将在本文末尾链接它.
顺便说一句:是的,我知道Arrays.sort()是稳定的,而heapsort则不是.Java没有不稳定的排序(至少,我还没有找到).这就是我在C++中使用std :: sort的原因,看看它是否与稳定性有关.
源代码,包括C++和Java:https://gist.github.com/anonymous/7475399
我正在使用Entity Framework从数据库加载数据.我有一个ASP MVC控制器,每页应显示10个元素,其中页码是传递给控制器的参数:
public ActionResult Blog([DefaultValue(0)] int page)
{
var blogPosts = db.BlogPosts.ToList()
.OrderByDescending(i => i.PublishTime)
.ToList()
.GetRange(page * 10, 10);
return View(blogPosts);
}
Run Code Online (Sandbox Code Playgroud)
这里,GetRange(page * 10, 10) 调用可以在多种情况下抛出异常,例如,当列表少于10个元素或者page * 10索引超出范围时.
这可以通过大量绑定检查来解决.我想知道,有更优雅的解决方法吗?我正在寻找能够在可能的情况下返回10个元素的解决方案,否则返回尽可能多的元素或null /空列表.
例如,27个元素的列表,第一个和第二个页面(page == 0 || page == 1)将返回包含10个元素的列表,第三个页面(page == 2)将返回7个元素,第四个页面(page == 3)将返回null /空列表.