本文整理汇总了C#中Model.List.First方法的典型用法代码示例。如果您正苦于以下问题:C# List.First方法的具体用法?C# List.First怎么用?C# List.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model.List
的用法示例。
在下文中一共展示了List.First方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildFailureMessage
private static string BuildFailureMessage(List<Build> builds)
{
var failedBuilds = builds.Where(b => !IsSuccesfullBuild(b)).ToList();
var build = builds.First();
var stringBuilder = new StringBuilder();
stringBuilder
.AppendFormat( //todo externalize this in settings
@"<img src='http://ci.innoveo.com/img/buildStates/buildFailed.png' height='16' width='16'/><strong>Failed</strong> to build {0} branch {1} with build number <a href=""{2}""><strong>{3}</strong></a>. Failed build(s) ",
build.projectName, build.branchName, build.buildStatusUrl, build.buildNumber);
stringBuilder.Append(
string.Join(", ",
failedBuilds.Select(fb => string.Format(@"<a href=""{0}""><strong>{1}</strong></a>", fb.buildStatusUrl, fb.buildName))));
return stringBuilder.ToString();
}
示例2: GetExchangePeriodsMergedByMovementDirectoryFromEndDate
/// <summary>
/// Metoda zwracająca listę okresów notowań połączonych, jeżeli mają ten sam kierunek trendu. Metoda ta rozpoczyna wyznaczanie od parametru periodsEndDate i zmierza ku przeszłości.
/// </summary>
/// <param name="DesiredNumberOfPeriods">Oczekiwana liczba okresów.</param>
/// <param name="periodsEndDate">Ostatnia data okresów.</param>
/// <param name="periodsStartDate">Data będąca granicą wyznaczania kolejnych okresów.</param>
/// <param name="daysInterval">Liczba określająca długość okresu w dniach.</param>
/// <returns>Lista okresów notowań połaczonych, jeżeli mają ten sam kierunek trendu.</returns>
public List<ExchangePeriod> GetExchangePeriodsMergedByMovementDirectoryFromEndDate(int DesiredNumberOfPeriods, DateTime periodsEndDate, DateTime periodsStartDate, int daysInterval)
{
DateTime iterationDate = periodsEndDate.Date;
string dataPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\data\\";
List<ExchangePeriod> periodList = new List<ExchangePeriod>();
while (iterationDate >= periodsStartDate)
{
DateTime periodStart;
if (iterationDate.AddDays(-daysInterval) > periodsStartDate)
{
periodStart = iterationDate.AddDays(-daysInterval);
}
else
{
periodStart = periodsStartDate.Date;
}
ExchangePeriod period = GetExchangePeriod(periodStart, iterationDate);
if (period != null)
{
period.PublicTrading -= GetExchangeDay(period.PeriodStart).PublicTrading;
if (periodList.Count != 0)
{
periodList.First().OpenRate = period.CloseRate;
//If percentage changes have the same sign.
if ((periodList.First().PercentageChange * period.PercentageChange) > 0 || periodList.First().PeriodStart == periodList.First().PeriodEnd)
{
periodList.First().PublicTrading += period.PublicTrading;
if (period.PeriodEnd != periodList.First().PeriodStart)
{
periodList.First().PublicTrading += GetExchangeDay(periodList.First().PeriodStart).PublicTrading;
}
periodList.First().PeriodStart = period.PeriodStart;
if ((periodList.Count > 1) && ((periodList[0].PercentageChange * periodList[1].PercentageChange) > 0))
{
periodList[1].OpenRate = periodList[0].OpenRate;
periodList[1].PeriodStart = periodList[0].PeriodStart;
periodList[1].PublicTrading += periodList[0].PublicTrading + GetExchangeDay(periodList[1].PeriodStart).PublicTrading;
periodList.RemoveAt(0);
}
}
else
{
if (periodList.Count == DesiredNumberOfPeriods + 1)
{
periodList.RemoveAt(0);
break;
}
periodList.Insert(0, period);
}
}
else
{
periodList.Add(period);
}
}
iterationDate = iterationDate.AddDays(-daysInterval);
}
return periodList;
}
示例3: AddEmptySaveEmailProperty
public long AddEmptySaveEmailProperty(Oasis.Models.EditRuleForEmailModel model)
{
var tables = tablesRepository.FindAll(w => w.AspNetUsers.Id.Equals(demoHelper.userId)).Select(l => l.Name).ToList();
var rule = emailParsingRulesRepository.Find(w => w.Id == model.Id);
long spreadsheetId = ParseHelper.GetSpreadsheetIdByName(demoHelper.userId, model.TableId);
List<SelectListItem> saveEmail = new List<SelectListItem>
{
new SelectListItem {Text = "Email without attachments", Value = "0"},
new SelectListItem {Text = "Email with attachments", Value = "1"}
};
if (rule != null)
{
rule.AuthorId_Id = demoHelper.userId;
rule.Email = HttpUtility.HtmlEncode(model.Email);
rule.Subject = HttpUtility.HtmlEncode(model.Subject);
rule.PlainContains = HttpUtility.HtmlEncode(model.PlainContains);
//rule.IsUpdatingRule = isUpdatingRule;
rule.Status = Model.Enums.RuleStatusEnums.Active.ToString();
rule.TableId = spreadsheetId;
List<SaveEmailProperty> saveEmailProperties = new List<SaveEmailProperty>();
if(model.SaveEmailProperties != null)
{
saveEmailProperties = model.SaveEmailProperties.Where(w => w.SaveEmailProp != null).ToList();
}
if (saveEmailProperties.Count == 0)
{
demoHelper.allSaveEmailProperties.Add(new Model.SaveEmailProperty()
{
TableId = tables[0],
Worksheet = "0",
Column = "A",
SaveEmailProp = saveEmail[0].Value,
EmailParsingRulesModelsId = rule.Id
});
}
else if (saveEmailProperties.Count > 0 && saveEmailProperties.First().Id == 0)
{
demoHelper.allSaveEmailProperties.Add(new Model.SaveEmailProperty()
{
TableId = model.SaveEmailProperties.First().TableId,
Worksheet = model.SaveEmailProperties.First().Worksheet,
Column = model.SaveEmailProperties.First().Column,
SaveEmailProp = saveEmail.Find(w => w.Text == model.SaveEmailProperties.First().SaveEmailProp).Value,
EmailParsingRulesModelsId = rule.Id
});
demoHelper.allSaveEmailProperties.Add(new Model.SaveEmailProperty()
{
TableId = tables[0],
Worksheet = "0",
Column = "A",
SaveEmailProp = saveEmail[0].Value,
EmailParsingRulesModelsId = rule.Id
});
}
else
{
foreach (var saveEmailProp in saveEmailProperties)
{
var saveProp = demoHelper.allSaveEmailProperties.Find(w => w.Id == saveEmailProp.Id);
saveProp.TableId = saveEmailProp.TableId;
saveProp.Worksheet = saveEmailProp.Worksheet;
saveProp.Column = saveEmailProp.Column;
saveProp.SaveEmailProp = saveEmail.Find(w => w.Text == saveEmailProp.SaveEmailProp).Value;
}
demoHelper.allSaveEmailProperties.Add(new Model.SaveEmailProperty()
{
TableId = tables[0],
Worksheet = "0",
Column = "A",
SaveEmailProp = saveEmail[0].Value,
EmailParsingRulesModelsId = rule.Id
});
}
return rule.Id;
// return RedirectToAction("AddNewDataRuleForEmails", new { ruleId = rule.Id });
}
return 0;
}
示例4: restock
/// <summary>
/// Restock
/// </summary>
/// <param name="PoDetailList">PoDetailList(PoID, ItemID, ActualQty)</param>
/// <returns></returns>
public bool restock(List<PurchaseOrderDetail> PoDetailList)
{
bool result = true;
//search for purchase order to obtain supplier ID
int poID = (int)PoDetailList.First().PoID;
PurchaseOrder po = ctx.PurchaseOrder.Where(x => x.PoID == poID).FirstOrDefault();
foreach(PurchaseOrderDetail poDetail in PoDetailList)
{
//Update the actual qty for every poDetail
PurchaseOrderDetail poDetailSearch = ctx.PurchaseOrderDetail
.Where(x => x.PoID == poDetail.PoID && x.ItemID == poDetail.ItemID)
.FirstOrDefault();
poDetailSearch.ActualQty = poDetail.ActualQty;
//update stock in item
Item item = ctx.Item.Where(x => x.ItemID == poDetail.ItemID).FirstOrDefault();
item.Stock += poDetail.ActualQty;
//update stock card
StockCard stockCard = new StockCard();
stockCard.ItemID = poDetail.ItemID;
stockCard.Date = DateTime.Now;
stockCard.Description = "Supplier - " + po.SupplierID;
stockCard.Qty = poDetail.ActualQty;
stockCard.Balance = item.Stock + poDetail.ActualQty;
ctx.StockCard.Add(stockCard);
}
//change status of purchase order to "Delivered"
po.Status = "DELIVERED";
try
{
ctx.SaveChanges();
}
catch
{
result = false;
}
return result;
}
示例5: UpdateEpisodeList
public void UpdateEpisodeList(
int podCastId,
IList<Episode> episodes)
{
IQueryable<DBEpisode> oldEpisodes;
try
{
oldEpisodes =
this.DB.All<DBEpisode>()
.Where(e => e.RefPodCastId == podCastId);
}
catch (Exception ex)
{
// TODO: EXCEPTION: Unknown SubSonic exception
throw new RepositoryException(
"Error reading existing episode list",
ex);
}
IList<Exception> exceptions = new List<Exception>();
foreach (var episode in episodes)
{
var oldEpisode =
oldEpisodes.Where(
e => e.EpisodeId == episode.Id)
.SingleOrDefault();
if (oldEpisode == null)
{
try
{
// Inserts new episode:
this.DB.Add<DBEpisode>(
episode.AsDB());
}
catch (Exception ex)
{
// TODO: EXCEPTION: Unknown SubSonic exception
exceptions.Add(ex);
}
}
else
{
try
{
// Updates old episode:
this.UpdateDBEpisode(episode, oldEpisode);
}
catch (RepositoryException ex)
{
exceptions.Add(ex);
}
}
}
if (exceptions.Count > 0)
{
string message =
string.Format(
CultureInfo.CurrentCulture,
"Errors during update of episode list: See Data property for all {0} inner exceptions",
exceptions.Count);
var exception =
new RepositoryException(
message,
exceptions.First());
exception.Data.Add(
"Inner exceptions",
exceptions);
throw exception;
}
}
示例6: CreateNetworks
//.........这里部分代码省略.........
testDataList.Add(td);
}
}
List<TrainingData> trainingDataList = new List<TrainingData>();
foreach (TrainingDataFileParameters file in fileList)
{
TrainingData td = new TrainingData();
if (td.ReadTrainFromFile(trainDataFolder.Split('\\').Last() + "\\" + file.FileName))
{
trainingDataList.Add(td);
}
}
string initStatus = this.InitializationStatus;
Directory.CreateDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + path);
List<Task> taskList = new List<Task>();
NeuralNet.CallbackType[] callbacksArray = new NeuralNet.CallbackType[this.MaxComputingThreads];
Semaphore threadProgressSemaphore = new Semaphore(1, 1);
Semaphore allSem = new Semaphore(1, 1);
TrainingData[] threadDataVars = new TrainingData[this.MaxComputingThreads];
for (int i = 1; i <= this.MaxComputingThreads; i++)
{
int taskNumber = i;
threadDataVars[i - 1] = new TrainingData();
Task t = new Task((Action)(
() =>
{
while (true)
{
allSem.WaitOne();
if (parameters.Count == 0)
{
this.InitializationStatus = initStatus + " " + numberOfNetworksToCreate.ToString() + " / " + numberOfNetworksToCreate.ToString();
this.InitializationProgress = 100;
break;
}
else
{
NeuralNetworkParameters usedParameters = parameters.First();
parameters.RemoveAt(0);
if (!File.Exists(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + path + usedParameters.FileName))
{
NeuralNet net = new NeuralNet();
List<uint> layers = new List<uint>();
layers.Add((uint)((usedParameters.fileParameters.NumberOfPeriods * 2) - 1)); // inputs
layers.Add((uint)(layers[0] * usedParameters.hiddenLayersMultiplier)); // hidden
layers.Add(3); // output
net.CreateStandardArray(layers.ToArray());
net.SetLearningRate((float)0.7);
net.SetActivationFunctionHidden(ActivationFunction.SigmoidSymmetric);
net.SetActivationFunctionOutput(ActivationFunction.SigmoidSymmetric);
net.Callback += callbacksArray[taskNumber - 1];
threadDataVars[taskNumber - 1] = trainingDataList.Find((e) => ((e.NumInputTrainData == layers[0]) && (e.Input.Length == usedParameters.fileParameters.NumberOfPatterns)));
allSem.Release();
net.TrainOnData(threadDataVars[taskNumber - 1],
usedParameters.maxEpochs, // max iterations
0,// iterations between report
0 //desired error
);
allSem.WaitOne();
net.TestData(testDataList.Find((e) => e.NumInputTrainData == layers[0]));
double mse = net.GetMSE();
if (lowestNetworkMSE == null || lowestNetworkMSE.MSE > mse)
{
lowestNetworkMSE = new NetworkMSE()
{
MSE = mse,
NetworkFileName = usedParameters.FileName
};
StringWriter writer = new StringWriter();
XmlSerializer serializer = new XmlSerializer(typeof(NetworkMSE));
serializer.Serialize(writer, lowestNetworkMSE);
File.WriteAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + path + "LowestMSENetwork.xml", writer.ToString());
}
net.Save(path + usedParameters.FileName);
}
this.InitializationStatus = initStatus + " " + numberOfCreatedNetworks.ToString() + " / " + numberOfNetworksToCreate.ToString();
numberOfCreatedNetworks++;
this.InitializationProgress = (numberOfCreatedNetworks * methodProgressPart / numberOfNetworksToCreate) + methodStartProgress;
}
allSem.Release();
}
}
), TaskCreationOptions.LongRunning
);
taskList.Add(t);
}
foreach (Task t in taskList)
{
t.Start();
}
}
示例7: createRequisition
/// <summary>
/// CreateRequisition
/// </summary>
/// <param name="itemList">CartItems List (EmpID, ItemID, Qty)</param>
/// <returns></returns>
public int createRequisition(List<CartItems> itemList)
{
int result = 0;
int ReqID = 0;
if (itemList.FirstOrDefault() != null)
{
//create and add new requisition
Requisition req = new Requisition();
req.EmpID = itemList.First().EmpID;
int empid = itemList.First().EmpID;
req.DeptID = ctx.Employee.Where(x => x.EmpID == empid).First().DeptID;
req.Date = DateTime.Now;
req.StatusID = 1;
ctx.Requisition.Add(req);
ctx.SaveChanges();
//obtain the ReqID of the newly added requisition
List<Requisition> reqList = ctx.Requisition.Where(x => x.EmpID == empid).ToList();
ReqID = reqList.Last().ReqID ;
//create and add new requisition details
foreach (CartItems item in itemList)
{
RequisitionDetail reqDetail = new RequisitionDetail();
reqDetail.ReqID = ReqID;
reqDetail.ItemID = item.ItemID;
reqDetail.RequestQty = item.Qty;
ctx.RequisitionDetail.Add(reqDetail);
}
//delete items from request cart
foreach (CartItems item in itemList)
{
CartItems cartItem = ctx.CartItems.Where(x => x.EmpID == item.EmpID && x.ItemID == item.ItemID).FirstOrDefault();
ctx.CartItems.Remove(cartItem);
}
}
int count = ctx.SaveChanges();
if (count > 0)
result = ReqID;
if (result == ReqID)
{
//send notification:
NotificationController nt = new NotificationController();
nt.sendNotification(1, itemList.First().EmpID, Convert.ToString(ReqID));
}
return result;
}
示例8: GenerateCreationContext
public virtual CreationContext GenerateCreationContext(IRegistration registration, ResolverContext context)
{
var componentType = registration.Implementor;
var constructors = componentType.GetConstructors()
.OrderByDescending(p => p.GetParameters().Count());
IList<DependencyMissingException> missingDependencies = new List<DependencyMissingException>();
foreach (var info in constructors)
{
missingDependencies = new List<DependencyMissingException>();
var parameters = info.GetParameters();
if (parameters.Length == 0) //Fast way out.
return CreateReturnContext(componentType, null);
IList<object> resolvedParameters = new List<object>();
foreach (var parameter in parameters)
{
string explicitDependencyName = null;
var parameterName = parameter.Name;
if (registration.Parameters.ContainsKey(parameterName))
explicitDependencyName = registration.Parameters[parameterName];
Type type = parameter.ParameterType;
try
{
var query = new Query {ServiceType = type, Name = explicitDependencyName};
resolvedParameters.Add(CreateType(query, context));
}
catch (ServiceNotFoundException exception)
{
missingDependencies.Add(new DependencyMissingException(exception.Message, registration.Service.Name));
}
}
if (resolvedParameters.Count == parameters.Length)
return CreateReturnContext(componentType, resolvedParameters.ToArray());
}
throw missingDependencies.First(); //TODO: Expose all missing dependencies
}
示例9: submit
/// <summary>
/// Submit
/// </summary>
/// <param name="retDetailList">RetrievalDetail List (RetID, ItemID, ActualQty)</param>
/// <returns></returns>
public bool submit(List<RetrievalDetail> retDetailList)
{
bool result = true;
foreach (RetrievalDetail retDetail in retDetailList)
{
//update actual quantity of retrieval detail
RetrievalDetail retDetailSearch = ctx.RetrievalDetail.Where(x => x.RetID == retDetail.RetID && x.ItemID == retDetail.ItemID).FirstOrDefault();
retDetailSearch.ActualQty = retDetail.ActualQty;
}
//update status of retrieval to "Retrieved"
int retid = (int)retDetailList.First().RetID;
Retrieval ret = ctx.Retrieval.Where(x => x.RetID == retid ).FirstOrDefault();
ret.Status = "RETRIEVED";
try
{
ctx.SaveChanges();
}
catch
{
result = false;
}
return result;
}
示例10: createRetrieval
/// <summary>
/// CreateRetrieval
/// </summary>
/// <param name="processRetList">ProcessRetrieval List (EmpID, ReqID)</param>
/// <returns></returns>
public int createRetrieval(List<ProcessRetrieval> processRetList)
{
int result = 0;
//create and add new retrieval
Retrieval ret = new Retrieval();
ret.Date = DateTime.Now;
ret.EmpID = processRetList.First().EmpID;
ret.Status = "PENDING";
ctx.Retrieval.Add(ret);
ctx.SaveChanges();
//obtain retID of newly added retrieval
int empID = processRetList.First().EmpID;
Retrieval retLast = ctx.Retrieval.Where(x=> x.EmpID == empID).ToList().Last();
int RetID = retLast.RetID;
//hashmap-like to store itemID and collated qty
Dictionary<string, int> itemQty = new Dictionary<string, int>();
foreach (ProcessRetrieval processRet in processRetList)
{
//update RetID of requisition
Requisition requisition = ctx.Requisition.Where(x => x.ReqID == processRet.ReqID).First();
requisition.RetID = RetID;
requisition.StatusID = 3;
//obtain requisition detail list
List<RequisitionDetail> reqDetailList = ctx.RequisitionDetail.Where(x => x.ReqID == processRet.ReqID).ToList();
foreach (RequisitionDetail reqDetail in reqDetailList)
{
//if itemQty does not contain the item, add item to itemQty
if (!itemQty.ContainsKey(reqDetail.ItemID))
{
itemQty.Add(reqDetail.ItemID, (int)reqDetail.RequestQty);
}
//else if itemQty contains item, add the qty to existing qty
else
{
itemQty[reqDetail.ItemID] += (int) reqDetail.RequestQty;
}
}
}
//extract all keys and values in itemQty
string[] itemQtyKeys = itemQty.Keys.ToArray();
int[] itemQtyValues = itemQty.Values.ToArray();
for (int i = 0; i < itemQty.Count; i++)
{
//create and add new retrieval detail
RetrievalDetail retrievalDetail = new RetrievalDetail();
retrievalDetail.RetID = RetID;
retrievalDetail.ItemID = itemQtyKeys[i];
retrievalDetail.RequestQty = itemQtyValues[i];
ctx.RetrievalDetail.Add(retrievalDetail);
}
int count = ctx.SaveChanges();
if (count > 0)
result = RetID;
if (result == RetID)
{
foreach (ProcessRetrieval processRet in processRetList)
{
//send notification:
NotificationController nt = new NotificationController();
nt.sendNotification(4, empID, Convert.ToString(processRet.ReqID));
}
}
return result;
}