我正在尝试使用docker和boot2docker创建一个VM.我做了以下Dockerfile,我试图通过命令行运行
docker run Dockerfile
Run Code Online (Sandbox Code Playgroud)
Immidiatly它正是这样说的:
Unable to find image 'Dockerfile:latest' locally
FATA[0000] Invalid repository name <Dockerfile>, only [a-z0-9_.] are allowed
Run Code Online (Sandbox Code Playgroud)
FROM ubuntu:latest
#Oracle Java7 install
RUN apt-get install software-properties-common -y
RUN apt-get update
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java7-installer
#Jenkins install
RUN wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
RUN sudo echo "deb http://pkg.jenkins-ci.org/debian binary/" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get …Run Code Online (Sandbox Code Playgroud) 我正在尝试从javascript应用程序发送JSON请求,并在我的SQL DB中创建此对象(HourRegistration),但由于某种原因,我无法将日期从json解析为有效的DateTime.
来自JS的JSON日期
hourRegistration.Date = "12/08/2015";
Run Code Online (Sandbox Code Playgroud)
所以 dd/MM/yyyy
我试图像这样解析:
Date = DateTime.ParseExact(hourRegistration.Date, "dd/MM/yyyy", CultureInfo.InvariantCulture)
Run Code Online (Sandbox Code Playgroud)
整个方法
public void CreateHours(HourRegistrationDTO hourRegistration)
{
DAO.Instance.HourRegistration.Add(new HourRegistration()
{
Date = DateTime.ParseExact(hourRegistration.Date, "dd/MM/yyyy", CultureInfo.InvariantCulture),
Cust_ID = hourRegistration.Cust_id,
Login_ID = hourRegistration.Login_id,
Hours = hourRegistration.Hours,
Comment = hourRegistration.Comment
});
DAO.Instance.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
ToCharArray()
我真的不知道为什么这不起作用.据我所知,这应该有用吗?
我正在尝试在当前上下文中找到所有项目的单个项目,但我似乎经常收到此错误消息:
请求失败.远程服务器返回错误:(401)未经授权.
首先,我设置一切以访问交换服务:
var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationResult authenticationResult = null;
AuthenticationContext authenticationContext = new AuthenticationContext(
SettingsHelper.Authority, new model.ADALTokenCache(signInUserId));
authenticationResult = authenticationContext.AcquireToken(
SettingsHelper.ServerName,
new ClientCredential(SettingsHelper.ClientId, SettingsHelper.ClientSecret));
ExchangeService exchange = new ExchangeService(ExchangeVersion.Exchange2013);
exchange.Url = new Uri(SettingsHelper.ServerName + "ews/exchange.asmx");
exchange.TraceEnabled = true;
exchange.TraceFlags = TraceFlags.All;
exchange.Credentials = new OAuthCredentials(authenticationResult.AccessToken);
Run Code Online (Sandbox Code Playgroud)
然后我定义了我想要接收的项目(通过ID):
ItemView view = new ItemView(5);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
var tempId = id.Replace('-', '/').Replace('_', '+');
SearchFilter.IsEqualTo searchid = new SearchFilter.IsEqualTo(ItemSchema.Id, tempId);
Run Code Online (Sandbox Code Playgroud)
最后但并非最不重要的是,我尝试在我的项目中搜索此项目:
FindItemsResults<Microsoft.Exchange.WebServices.Data.Item> results = exchange.FindItems(WellKnownFolderName.Inbox, searchid, view); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用浏览器中的内置下载来下载Excel文件.在我在控制器中创建Excel文件后,基本上下载工作正常,但是当我尝试在Excel中打开此文件时,我被告知该文件已损坏:
Excel无法打开文件"Report.xlsx",因为文件格式或文件扩展名无效.验证文件是否已损坏,以及文件扩展名是否与文件格式匹配.
强制文件在Excel中打开时,工作表只是空的.我不知道为什么会这样.
码
我没有展示我是如何创建Excel文件的,因为这是无关紧要的(它在使用内存流之前工作正常).
var stream = wBook.WriteXLSX(); // Return a MemoryStream (Using DTG.Spreadsheet)
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx");
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现EF提供的分页功能.我想,我只需要添加的简单Skip()和Take()进入我的查询,但后来我得到这个消息:
错误4'System.Linq.IOrderedQueryable'不包含'Skip'的定义和最佳扩展方法重载'System.Linq.Queryable.Skip(System.Linq.IQueryable,int)'有一些无效的参数D:\ Biblioteker\HourRegistrationApplication\HourRegistrationService\HourRegistrationWCF\Service.cs 190 24 HourRegistrationWCF
我不太确定我需要做什么?我用谷歌搜索了一下,但没有找到任何有用的东西.
GetAllCustomers()
public List<CustomerDTO> GetAllCustomers(string take, string skip)
{
var custList = new List<CustomerDTO>();
var list = DAO.TDKanBanInstance.Customer.OrderBy(x => x.Name).Skip(skip).Take(take).ToList();
foreach (var cust in list)
{
custList.Add(new CustomerDTO()
{
Name = cust.Name
});
}
return custList;
}
Run Code Online (Sandbox Code Playgroud)
工作解决方案
在take和skip需要是int当然的.
public List<CustomerDTO> GetAllCustomers(string take, string skip)
{
int skipInt = Int32.Parse(skip);
int takeInt = Int32.Parse(take);
var custList = new List<CustomerDTO>();
var list = DAO.TDKanBanInstance.Customer.OrderBy(x => …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Entity Framework向我的DbContext添加单例模式.我总是使用单例模式,之前从未遇到过这个错误.我知道单身人士是最佳做法 (显然不是),但如果你们有时间有空,你能否解释为什么单身人士是最佳做法?
问题
除此之外,我收到此错误:
底层提供程序在打开时失败
我们来看看我的代码吧
DAO.cs
public class DAO
{
private static HourRegistrationEntities hourRegInstance;
public static HourRegistrationEntities HourRegInstance { get { return hourRegInstance = hourRegInstance ?? new HourRegistrationEntities(); } }
}
Run Code Online (Sandbox Code Playgroud)
Service.cs(示例方法)
/// <summary>
/// Return a list of all denied Hour Registration for the Login with the given stringId
/// </summary>
/// <param name="stringId"></param>
/// <returns>A list of HourRegistrationDTO</returns>
public List<HourRegistrationDTO> GetAllDeniedHoursForLogin(string stringId)
{
var id = Int32.Parse(stringId);
using (var db = DAO.HourRegInstance)
{ …Run Code Online (Sandbox Code Playgroud) 那里有大量的SO,但有一个我不明白的事情,因此创造了这个SO.
采用以下连接字符串mongodb//admin:1234@10.0.125.1/my_database.使用此连接字符串,我希望我能够连接到MongoDB实例和特定数据库my_database.
遵循几个SO和其他rarticle,这应该工作,但如果我查看MongoDB的官方文档,该database选项是我想要验证的数据库.
/ database是要登录的数据库的名称,因此仅在使用username:password @ syntax时才相关.如果未指定,则默认使用"admin"数据库.
我希望我的用户可以通过管理数据库进行身份验证(就像我的用户所在的那样),但我想访问数据库my_database.我希望这个程序有效:
private static string _connectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ToString();
public static IMongoDatabase GetDatabase()
{
var _url = MongoUrl.Create(_connectionString);
var _databaseName = _url.DatabaseName;
return new MongoClient(_connectionString).GetDatabase(_databaseName);
}
Run Code Online (Sandbox Code Playgroud)
但每当我这样做时,我都会收到对MongoDB进行任何调用的超时.一个例子是:
public List<SomeObject> GetAllObjects()
{
var database = DatabaseInstance.GetDatabase();
// Error is thrown here (timout after 30000ms)
var objects = database.Getcollection<SomeObject>("SomeObjects").Find(Builders<SomeObject>.Filter.Empty).Find();
return objects;
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我要从连接字符串中删除数据库并硬编码我的数据库名称return new MongoClient(_connectionString).GetDatabase("my_database");,一切都按预期工作.
这是我不理解连接字符串中的/ database选项的地方.如果有人能对此有所了解,我真的很感激.
我正在尝试创建一些动态的ExpandoObject。我遇到了一个问题。
由于我不知道对象中这些不同属性的名称是什么,所以我不能这样:
var list = new ArrayList();
var obj = new ExpandoObject();
obj.ID = 1,
obj.Product = "Pie",
obj.Days = 1,
obj.QTY = 65
list.Add(obj);
Run Code Online (Sandbox Code Playgroud)
让我解释一下我的情况:我希望从随机数据库中获取数据(我不知道该数据,而是根据从UI中获得的信息构建一个连接字符串),因此我不知道我需要获取哪些数据。这可能是数据库表的示例
表销售
这可能是另一个例子:
桌上足球吧
如您所见,我不知道数据库是什么样的(这是100%匿名的,因此它必须是100%动态的),并且我要返回的数据应该看起来像一个构造良好的JSON,如下所示:
[
{
"ID": 1,
"Product": "Pie"
"Days": 1,
"QTY": 65
},
{
"ID": 2,
"Product": "Melons"
"Days": 5,
"QTY": 12
}
]
Run Code Online (Sandbox Code Playgroud)
或者,使用另一个示例:
[
{
"ID": 1,
"Days": 2,
"QTY": 56,
"Product_Id": 5,
"Department_Id": 2
}
{
"ID": 2, …Run Code Online (Sandbox Code Playgroud) 我有enum以下扩展名:
public static class EnumExtension
{
public static SelectList ToSelectList(this Enum en)
{
var list = (from Enum d in Enum.GetValues(en.GetType())
select new SelectListItem { Value = d.ToString(("d")), Text = Enum.GetName(en.GetType(), d) }).ToList();
var selectedValue = (int) Enum.Parse(en.GetType(), Enum.GetName(en.GetType(), en));
return new SelectList(list, "Value", "Text", selectedValue);
}
}
Run Code Online (Sandbox Code Playgroud)
这是enum我在说的:
public enum BillingInterval
{
Monthly = 1,
Quarterly = 2,
Yearly = 3
}
Run Code Online (Sandbox Code Playgroud)
有了这个enum和扩展,就可以做到以下几点
public ActionResult Test()
{
var vm = new CustomerViewModel();
vm.BillingIntervalOptions …Run Code Online (Sandbox Code Playgroud) 我试图找出HourRegistrations其中
HourRegistration.Date == //withint the last 3 months
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样(在网上找到了这个解决方案,但它似乎不起作用)
var dbHourRegs = db.HourRegistration
.Where(x => DateTime.Compare(x.Date, DateTime.Today.AddMonths(-3)) >= 0)
.ToList();
Run Code Online (Sandbox Code Playgroud)
但正如标题所说,我不断收到此错误:
LINQ to Entities 无法识别“System.DateTime AddMonths(Int32)”方法,并且该方法无法转换为存储表达式。
该如何进行呢?或者更确切地说,我如何完成这项任务?
我试图绕过这个数字
6.079084800080882E-5
Run Code Online (Sandbox Code Playgroud)
但每当我运行应用程序时,结果就是这样
X = 0.0
Run Code Online (Sandbox Code Playgroud)
这是我的代码
tmp = 6.079084800080882E-5;
x = (double)Math.round(tmp);
Run Code Online (Sandbox Code Playgroud)
我不只是输入一个随机数(6.079084800080882E-5),但这是一个由一些计算产生的nuber.这些计算无关紧要,因为这是我想要的数字.