public static void DbgReadSolution(string solution_file)
{
var wrapperContent = Microsoft.Build.BuildEngine.SolutionWrapperProject.
Generate(solution_file, toolsVersionOverride: null, projectBuildEventContext: null);
byte[] rawWrapperContent = Encoding.Unicode.GetBytes(wrapperContent.ToCharArray());
using (MemoryStream memStream = new MemoryStream(rawWrapperContent))
using (XmlTextReader xmlReader = new XmlTextReader(memStream))
{
var proj = ProjectCollection.GlobalProjectCollection.LoadProject(xmlReader);
int i = 0;
foreach (ProjectItem referencedProjectNode in GetOrderedProjectReferencesFromWrapper(proj))
{
Log.Info(String.Format("{0}{1}: {2}", Environment.NewLine, i++, referencedProjectNode.EvaluatedInclude));
string referencedProjectPath = Path.Combine(Path.GetDirectoryName(solution_file), referencedProjectNode.EvaluatedInclude);
var referencedProject = ProjectCollection.GlobalProjectCollection.LoadProject(referencedProjectPath);
Log.Info("\tReferenced Assemblies:");
foreach (ProjectItem referencedAssembly in GetReferencedAssemblies(referencedProject))
{
Log.Info("\t\t{0}", referencedAssembly.EvaluatedInclude);
}
Log.Info(String.Format("{0}\tSource Files:", Environment.NewLine));
foreach (ProjectItem includedSourceFile in GetSourceFiles(referencedProject))
{
Log.Info("\t\t{0}", includedSourceFile.EvaluatedInclude);
}
}
ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
}
}
var list = new List<string>();
FillFolderList("C:\\", list, 0, 3, 3);
public static void FillFolderList(string path, List<string> list, int current_level, int depth, int width)
{
list.Add(path);
if (current_level >= depth) return;
int current_width = 0;
try
{
foreach (var subdir in Directory.GetDirectories(path))
{
FillFolderList(subdir, list, current_level + 1, depth, width);
current_width++;
if (current_width > width) break;
}
}
catch (Exception)
{
}
}
public class Sample
{
public Guid Id;
public bool Equals(Sample other)
{
if ((object)this == (object)other)
return true;
if (this == null)
throw new NullReferenceException();
if (other == null)
return false;
if (ReferenceEquals(this, other))
return true;
if (this.GetType() != other.GetType())
return false;
return Id == other.Id;
}
public override bool Equals(object obj)
{
return Equals(obj as Sample);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
}
public interface IRepository<T>
where T: IEntity
{
T Get(Guid Id);
void Post(T entity);
void Remove(Guid id);
}
public class EFRepository<T>: IRepository<T>
where T: IEntity
{
/*Логика для EF*/
}
internal class TemporaryObject
{
private static long _counter = 0;
public long Key { get; private set; }
public TemporaryObject()
{
Key = Interlocked.Increment(ref _counter);
}
/// <summary>
/// Событие при завершении ожидания
/// </summary>
public Action Callback;
/// <summary>
/// Срок истечения ожидания
/// </summary>
public DateTime ExpirationDate;
/// <summary>
/// Следующий объект с ближайшей датой окончания ожидания
/// </summary>
public TemporaryObject Next;
}
public class TemporaryObjectPool
{
private readonly object _locker = new object();
/// <summary>
/// Таймер. Один на всех
/// </summary>
private Timer _timer;
/// <summary>
/// Объект с ближайшей датой окончания ожидания
/// </summary>
private TemporaryObject _current = null;
/// <summary>
/// Переустановка таймера
/// </summary>
private void ResetTimer()
{
if (null != _current)
{
var diff = (_current.ExpirationDate - DateTime.Now).TotalMilliseconds;
if (diff < 0) diff = 0;
_timer.Change((int)diff, Timeout.Infinite);
}
else
{
_timer.Change(Timeout.Infinite, Timeout.Infinite);
}
}
public TemporaryObjectPool()
{
_timer = new Timer(state =>
{
Action action = null;
lock (_locker)
{
if (null != _current)
{
// Получаем событие для исполнения
action = _current.Callback;
// Находим следующий ожидающий объект
_current = _current.Next;
// Перезадание таймера
ResetTimer();
}
}
// Вызов события ожидавшего даты
if (null != action)
{
ThreadPool.QueueUserWorkItem(s => action());
}
}, null, Timeout.Infinite, Timeout.Infinite);
}
/// <summary>
/// Добавление ожидающего объекта
/// </summary>
/// <param name="insert"></param>
internal long Push(TemporaryObject insert)
{
lock (_locker)
{
// Если пул пуст, то добавляемое событие становится корневым
if (null == _current)
{
_current = insert;
}
else
{
// Если пул не пуст
var cursor = _current;
TemporaryObject prev = null;
// Поиск места для вставки, сложность вставки O(n) в худшем случае
do
{
if (DateTime.Compare(cursor.ExpirationDate, insert.ExpirationDate) > 0)
{
insert.Next = cursor;
if (null == prev)
{
_current = insert;
}
else
{
prev.Next = insert;
}
break;
}
prev = cursor;
cursor = cursor.Next;
if (cursor == null)
{
prev.Next = insert;
}
} while (cursor != null);
}
ResetTimer();
}
return insert.Key;
}
public void Remove(long key)
{
lock (_locker)
{
if (_current == null) return;
bool removed = false;
if (_current.Key == key)
{
_current = _current.Next;
removed = true;
}
else
{
var prev = _current;
var next = _current.Next;
while (next != null)
{
if (next.Key == key)
{
prev.Next = next.Next;
removed = true;
break;
}
prev = next;
next = next.Next;
}
}
if (removed)
{
ResetTimer();
}
}
}
}
var pool = new TemporaryObjectPool();
pool.Push(new TemporaryObject { Callback = () => Console.WriteLine("#1 removed"), ExpirationDate = DateTime.Now.AddSeconds(5) });
pool.Push(new TemporaryObject { Callback = () => Console.WriteLine("#2 removed"), ExpirationDate = DateTime.Now.AddSeconds(10) });
pool.Push(new TemporaryObject { Callback = () => Console.WriteLine("#3 removed"), ExpirationDate = DateTime.Now.AddSeconds(15) });
public abstract class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public abstract int GetShopPrice(City city);
}
public sealed class SimpleProduct : Product
{
public override int GetShopPrice(City city)
{
//логика
}
}
public sealed class ModuleProduct : Product
{
public override int GetShopPrice(City city)
{
//логика
}
}
UPDATE [TABLE_NAME] SET [COLUMN_NAME]=@COLUMN_DEFAULT_VALUE
ALTER TABLE [TABLE_NAME] ALTER COLUMN [COLUMN_NAME] COLUMN_TYPE NOT NULL