public CompiledTemplate Compile(Type templateBaseType, IList <IViewSource> templateViewSources, object context) { Invariant.ArgumentNotNull(templateBaseType, "templateBaseType"); templateBaseType = ProxyExtracter.GetNonProxiedType(templateBaseType); var templateCacheKey = new StringBuilder(); foreach (var layoutTemplatePath in templateViewSources) { templateCacheKey.AppendFormat("{0}, ", layoutTemplatePath.Path); } CompiledTemplate compiledTemplate; lock ( _compiledTemplateCache ) { var key = templateCacheKey.ToString(); if (!_compiledTemplateCache.TryGetValue(key, out compiledTemplate)) { compiledTemplate = new CompiledTemplate(Options, templateViewSources, templateBaseType, context); _compiledTemplateCache.Add(key, compiledTemplate); return(compiledTemplate); } } if (Options.AutoRecompile) { compiledTemplate.Recompile(); } return(compiledTemplate); }
public static void Normalize(ref string userName, ref string domain) { Invariant.ArgumentNotNull((object)userName, "userName"); if (!string.IsNullOrEmpty(domain)) { return; } int length1 = userName.IndexOf('\\'); if (length1 < 0) { int length2 = userName.IndexOf('@'); if (length2 < 0) { domain = string.Empty; } else { domain = userName.Substring(length2 + 1); userName = userName.Substring(0, length2); } } else { domain = userName.Substring(0, length1); userName = userName.Substring(length1 + 1); } }
public static IEnumerable <TSource> Do <TSource>(this IEnumerable <TSource> source, Action <TSource> onNext, Action onCompleted) { Invariant.ArgumentNotNull((object)source, "source"); Invariant.ArgumentNotNull((object)onNext, "onNext"); Invariant.ArgumentNotNull((object)onCompleted, "onCompleted"); return(source.DoHelper <TSource>(onNext, (Action <Exception>)(error => { }), onCompleted)); }
public Host(IComputerSystem host, ILogger logger) { Invariant.ArgumentNotNull((object)host, "host IComputerSystem object"); Invariant.ArgumentNotNull((object)((IWMICommon)host).Object, "Host ComputerSystem instance"); this._Host = host; this._Logger = logger; }
public static bool IsEquivalentTo <T>(this IEnumerable <T> left, IEnumerable <T> right) { Invariant.ArgumentNotNull((object)left, "left"); Invariant.ArgumentNotNull((object)right, "right"); if (left == right) { return(true); } bool?nullable = EnumerableExtensions.TryVerifyCollectionCountsAreEqual <T>(left, right); if (nullable.HasValue && !nullable.Value) { return(false); } int nullCount1; Dictionary <T, int> itemCounts1 = EnumerableExtensions.GetItemCounts <T>(left, out nullCount1); int nullCount2; Dictionary <T, int> itemCounts2 = EnumerableExtensions.GetItemCounts <T>(right, out nullCount2); if (nullCount1 != nullCount2 || itemCounts1.Count != itemCounts2.Count) { return(false); } foreach (KeyValuePair <T, int> keyValuePair in itemCounts1) { int num; if (!itemCounts2.TryGetValue(keyValuePair.Key, out num) || num != keyValuePair.Value) { return(false); } } return(true); }
public IViewSource GetViewSource(string templateName, IList <IViewSource> parentViewSourceList) { Invariant.ArgumentNotEmpty(templateName, "templateName"); Invariant.ArgumentNotNull(parentViewSourceList, "parentViewSourceList"); templateName = SuffixWithHaml(templateName); var fileInfo = CreateFileInfo(templateName); if (fileInfo != null && fileInfo.Exists) { return(new FileViewSource(fileInfo)); } for (var index = 0; index < parentViewSourceList.Count; index++) { var source = parentViewSourceList[index]; //search where the current parent template exists var parentDirectory = Path.GetDirectoryName(source.Path); var combine = Path.Combine(parentDirectory, templateName); if (File.Exists(combine)) { return(new FileViewSource(new FileInfo(combine))); } } throw new FileNotFoundException(string.Format("Could not find template '{0}'.", templateName)); }
public KeyedComparer(Func <T, TKey> keySelector, IComparer <TKey> keyComparer) { Invariant.ArgumentNotNull(keySelector, "keySelector"); Invariant.ArgumentNotNull(keyComparer, "keyComparer"); this.keySelector = keySelector; this.keyComparer = keyComparer; }
public static IProcess CreateProcess(this IProcessFactory factory, string fileName, string arguments, NetworkCredential credentials) { Invariant.ArgumentNotNull((object)factory, "factory"); Invariant.ArgumentNotNullOrEmpty(fileName, "fileName"); Invariant.ArgumentNotNull((object)credentials, "credentials"); return(factory.CreateProcess(fileName, arguments, credentials.UserName, ProcessFactoryExtensions.SecurePassword(credentials.Password), credentials.Domain)); }
public static IEnumerable <TSource> Do <TSource>(this IEnumerable <TSource> source, Action <TSource> onNext, Action <Exception> onError) { Invariant.ArgumentNotNull((object)source, "source"); Invariant.ArgumentNotNull((object)onNext, "onNext"); Invariant.ArgumentNotNull((object)onError, "onError"); return(source.DoHelper <TSource>(onNext, onError, (Action)(() => { }))); }
public static IResourceAllocationSettingData GetDefaultEmulatedIDEController(IComputerSystem host) { IResourcePool resource = ResourcePool.Query(host, "ResourceSubType = 'Microsoft:Hyper-V:Emulated IDE Controller' and Primordial = True").FirstOrDefault <IResourcePool>(); Invariant.ArgumentNotNull((object)resource, "Emulated IDE Controller"); using (resource) return(ResourceAllocationSettingData.GetDefaultFromResourcePool(resource)); }
public static IStorageAllocationSettingData GetDefaultVirtualHardDiskStorageAllocationSettingData(IComputerSystem host) { using (IResourcePool resource = ResourcePool.Query(host, "ResourceSubType = 'Microsoft:Hyper-V:Virtual Hard Disk' and Primordial = True").FirstOrDefault <IResourcePool>()) { Invariant.ArgumentNotNull((object)resource, "Couldn't find the resource pool for Virtual Hard Disk"); return(StorageAllocationSettingData.GetDefaultFromResourcePool(resource)); } }
protected HamlNodeWalker(ITemplateClassBuilder classBuilder, HamlHtmlOptions options) { Invariant.ArgumentNotNull(options, "options"); Invariant.ArgumentNotNull(classBuilder, "classBuilder"); ClassBuilder = classBuilder; Options = options; }
public void Init(IControllerContext controllerContext, IEngineContext engineContext) { Invariant.ArgumentNotNull(controllerContext, "controllerContext"); ViewContext = engineContext; PropertyBag = controllerContext.PropertyBag; }
public static IResourceAllocationSettingData GetDefaultSyntheticDVDDrive(IComputerSystem host) { IResourcePool resource = ResourcePool.Query(host, "ResourceSubType = 'Microsoft:Hyper-V:Synthetic DVD Drive' and Primordial = True").FirstOrDefault <IResourcePool>(); Invariant.ArgumentNotNull((object)resource, "Synthetic DVD Drive not found"); using (resource) return(ResourceAllocationSettingData.GetDefaultFromResourcePool(resource)); }
public static IEnumerable <LowLevelStateData> ToLowLevelStates(this List <ErrorInfo> details) { Invariant.ArgumentNotNull((object)details, "details"); return(details.Select <ErrorInfo, LowLevelStateData>((Func <ErrorInfo, LowLevelStateData>)(errInfo => new LowLevelStateData() { Health = errInfo.Health, MessageId = errInfo.Message, HighLevelState = HighLevelState.Protecting }))); }
public static IEmulatedEthernetPortSettingData GetDefaultLegacyAdapter(IComputerSystem host) { IResourcePool resource = ResourcePool.Query(host, "ResourceSubType = 'Microsoft:Hyper-V:Emulated Ethernet Port' and Primordial = True").FirstOrDefault <IResourcePool>(); Invariant.ArgumentNotNull((object)resource, "Legacy Adapter not found"); using (resource) return(EmulatedEthernetPortSettingData.GetDefaultFromResourcePool(resource)); }
public void Render(TextWriter writer, HtmlVersion htmlVersion, IDictionary <string, object> viewData) { Invariant.ArgumentNotNull(writer, "textWriter"); _htmlVersion = htmlVersion; ViewData = viewData; HasCodeBlockRepeated = false; CoreRender(writer); }
public TaskContext(PrepareVmInformation bootInfo, ILogger logger, IServiceResolver serviceResolver) { Invariant.ArgumentNotNull((object)bootInfo, "bootInfo"); this.ServiceResolver = serviceResolver; this._JobInfo = new JobInfo(); this._JobInfo.Options = new JobOptions(); this._JobInfo.Options.OculiOptions = new OculiOptions(); this._JobInfo.Options.ClusterOptions = new ClusterOptions(); this._JobInfo.JobPersistedState = new JobPersistedState(); this._JobInfo.JobPersistedState.OculiPersistedState = new OculiPersistedState(); this._JobInfo.JobPersistedState.OculiPersistedState.SourceMachineInfo = new MachineInfo(); this._JobInfo.JobPersistedState.OculiPersistedState.SourceMachineInfo.ServerInfo = new ServerInfo(); this._JobInfo.JobPersistedState.OculiPersistedState.SourceMachineInfo.ServerInfo.OperatingSystem = new OperatingSystemInfo(); this._JobInfo.JobPersistedState.OculiPersistedState.SourceMachineInfo.ProductInfo = new ProductInfo(); this._JobInfo.JobPersistedState.OculiPersistedState.State = new JobState() { HasError = false, HighLevel = "CREATED", IsInSync = false, LowLevel = "Created" }; this._Logger = (ILogger) new LoggerWrapper(logger); this._JobInfoWrapper = (ITaskInfoWrapper) new Oculi.Jobs.Context.TaskInfoWrapper(this._JobInfo, (IOculiCredentialHelper)null); this._StateContext = new JobStateContext(this); this.Factory = (ICommandFactory) new CommandFactory(this); this.Invoker = (ICommandInvoker) new CommandInvoker(this.Factory); this.LocalDiskManagement = new LocalDiskManagement(this); this._JobInfo.JobPersistedState.OculiPersistedState.SourceMachineInfo.ServerInfo.OperatingSystem.Version = bootInfo.OSVersion; this._JobInfo.JobPersistedState.OculiPersistedState.SourceMachineInfo.ServerInfo.OperatingSystem.Architecture = bootInfo.CPUArchitecture; this._JobInfo.Options.OculiOptions.Hypervisor = bootInfo.Hypervisor; this._JobInfo.JobType = "Oculi"; this._JobInfo.Options.ClusterOptions.TargetIsCluster = false; this._JobInfo.Options.OculiOptions.IsSourceHostCluster = false; this._JobInfo.JobPersistedState.OculiPersistedState.Nics = ((IEnumerable <VirtualNetworkInterfaceInfo>)bootInfo.NetworkInterfaceInfo).Select <VirtualNetworkInterfaceInfo, OculiInternalVirtualNetworkInterfaceInfo>((Func <VirtualNetworkInterfaceInfo, OculiInternalVirtualNetworkInterfaceInfo>)(nic => OculiInternalVirtualNetworkInterfaceInfo.Create(nic))).ToArray <OculiInternalVirtualNetworkInterfaceInfo>(); this._JobInfo.JobPersistedState.OculiPersistedState.VmVersion = bootInfo.VmVersion; OculiPersistedState vraPersistedState = this._JobInfo.JobPersistedState.OculiPersistedState; OculiVolumePersistedState[] volumePersistedStateArray = new OculiVolumePersistedState[1]; int index = 0; OculiVolumePersistedState volumePersistedState = new OculiVolumePersistedState(); volumePersistedState.MountPoint = bootInfo.SystemVolumeMountPath; int num = 1; volumePersistedState.IsSystemDrive = num != 0; string str = bootInfo.WindowsDir.Substring(0, 1); volumePersistedState.Name = str; volumePersistedStateArray[index] = volumePersistedState; vraPersistedState.VolumePersistedState = volumePersistedStateArray; this.LocalDiskManagement.FillVolumeInfoFromMountPath(this.JobInfoWrapper.VolumePersistedState[0]); this._JobInfo.JobPersistedState.OculiPersistedState.SourceMachineInfo.ServerInfo.SystemRoot = bootInfo.WindowsDir; this._JobInfo.JobPersistedState.OculiPersistedState.SourceMachineInfo.ServerInfo.SystemVolume = bootInfo.WindowsDir.Substring(0, 2); this._JobInfo.JobPersistedState.OculiPersistedState.OculiVirtualizationConnectionInfo = new VirtualizationConnectionInfo(); this._JobInfo.JobPersistedState.OculiPersistedState.OculiVirtualizationConnectionInfo.RepsetName = ""; this._JobInfo.Options.OculiOptions.VMInfo = new VMInfo(); this._JobInfoWrapper.TargetOSVersion = OculiService.TargetHostOperatingSystemInfo.Version; }
private static IPEndPoint InternalParse(string endpointString, bool tryParse) { Invariant.ArgumentNotNull((object)endpointString, "endpointString"); string[] strArray = endpointString.Split(':'); if (strArray.Length == 1) { if (tryParse) { return((IPEndPoint)null); } throw new FormatException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Invalid IP endpoint format: '{0}'", new object[1] { (object)endpointString })); } string ipString; string s; if (strArray.Length == 2) { ipString = strArray[0]; s = strArray[1]; } else { ipString = string.Join(":", ((IEnumerable <string>)strArray).Take <string>(strArray.Length - 1).ToArray <string>()); s = strArray[strArray.Length - 1]; } IPAddress address; try { address = IPAddress.Parse(ipString); } catch (FormatException ex) { if (tryParse) { return((IPEndPoint)null); } throw new FormatException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Invalid IP endpoint format: '{0}'", new object[1] { (object)endpointString }), (Exception)ex); } int result; if (int.TryParse(s, out result) && result >= 0 && result <= (int)ushort.MaxValue) { return(new IPEndPoint(address, result)); } if (tryParse) { return((IPEndPoint)null); } throw new FormatException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Invalid IP endpoint port: '{0}'", new object[1] { (object)s })); }
public static NetworkCredential ApplyCryptor(this NetworkCredential toEncrypt, Func <string, string> cryptor) { Invariant.ArgumentNotNull((object)toEncrypt, "toEncrypt"); Invariant.ArgumentNotNull((object)cryptor, "cryptor"); return(new NetworkCredential() { Domain = toEncrypt.Domain, Password = cryptor(toEncrypt.Password), UserName = toEncrypt.UserName }); }
public string GetArchivePath(string path) { Invariant.ArgumentNotNull((object)path, "path"); string str = DateTime.Now.ToString(LogArchive.ArchiveDateTimeFormat, (IFormatProvider)CultureInfo.InvariantCulture); int maxSequenceNumber = this.GetMaxSequenceNumber(path); string extension = string.Format("{0}{1}{2}", (object)str, maxSequenceNumber == -1 ? (object)"" : (object)("." + (object)(maxSequenceNumber + 1)), (object)Path.GetExtension(path)); return(Path.ChangeExtension(path, extension)); }
public static OculiOAuth2Token ApplyCryptor(this OculiOAuth2Token toEncrypt, Func <string, string> cryptor) { Invariant.ArgumentNotNull((object)toEncrypt, "toEncrypt"); Invariant.ArgumentNotNull((object)cryptor, "cryptor"); return(new OculiOAuth2Token() { accesstoken = cryptor(toEncrypt.accesstoken), uid = toEncrypt.uid, coreengine_id = toEncrypt.coreengine_id }); }
public static IProcess CreateProcess(this IProcessFactory factory, string fileName, string arguments, string userName, SecureString password, string domain) { Invariant.ArgumentNotNull((object)factory, "factory"); Invariant.ArgumentNotNullOrEmpty(fileName, "fileName"); return(factory.CreateProcess(new ProcessStartInfo(fileName, arguments) { UseShellExecute = false, UserName = userName, Password = password, Domain = domain })); }
public static LogicalOperation Create(Guid activityId, string activityNameFormat, params object[] parameters) { Invariant.ArgumentNotNull(activityNameFormat, "activityNameFormat"); if (activityId == Guid.Empty) { throw new ArgumentException(string.Concat("ActivityId may not be set to ", activityId.ToString()), "activityId"); } return(new LogicalOperation(string.Format(CultureInfo.InvariantCulture, activityNameFormat, parameters), activityId)); }
public static LogicalOperation Create(Guid activityId, object data) { Invariant.ArgumentNotNull(data, "data"); if (activityId == Guid.Empty) { throw new ArgumentException(string.Concat("ActivityId may not be set to ", activityId.ToString()), "activityId"); } return(new LogicalOperation(data, activityId)); }
int IList.Add(object value) { Invariant.ArgumentNotNull(value, "item"); if (SortedCollection <T> .IsCompatibleObject(value)) { return(this.InternalAdd((T)value)); } return(-1); }
public void AddRule(MarkupRule markupRule) { Invariant.ArgumentNotNull(markupRule, "markupRule"); if (MarkupRules.Find(x => x.Signifier == markupRule.Signifier) != null) { throw new ArgumentException(string.Format("A MarkupRule with the signifier '{0}' has already been added.", markupRule.Signifier)); } MarkupRules.Add(markupRule); MarkupRules.Sort((x, y) => x.Signifier.Length.CompareTo(y.Signifier.Length)); }
public void Render(TextWriter textWriter) { Invariant.ArgumentNotNull(textWriter, "textWriter"); Output.TextWriter = textWriter; PreRender(Output); CoreRender(textWriter); PostRender(Output); }
public void ConnectUsingID(string virtualSwitchID) { NIC.tracer.TraceInformation(string.Format("Connecting using ID {0}", (object)virtualSwitchID)); using (VirtualEthernetSwitchManagementService.GetVirtualEthernetSwitchManagementService(this._Host)) { using (IVirtualSystemManagementService managmentService = VirtualSystemManagementService.GetVirtualSystemManagmentService(this._Host)) { using (IVirtualSystemSettingData systemSettingData = this._Vm.GetVirtualSystemSettingData()) { using (IVirtualEthernetSwitch virtualEthernetSwitch = VirtualEthernetSwitch.GetAllVirtualEthernetSwitches(this._Host).DisposingUnless <IVirtualEthernetSwitch>((Func <IVirtualEthernetSwitch, bool>)(v => v.Name == virtualSwitchID)).FirstOrDefault <IVirtualEthernetSwitch>()) { using (IEthernetPortAllocationSettingData allocationSettingData1 = EthernetPortAllocationSettingData.GetRelated(systemSettingData).Where <IEthernetPortAllocationSettingData>((Func <IEthernetPortAllocationSettingData, bool>)(e => e.Parent == ((IWMICommon)this._AdapterSettingData).Object.Path.Path)).FirstOrDefault <IEthernetPortAllocationSettingData>()) { if (allocationSettingData1 == null) { NIC.tracer.TraceInformation(string.Format("Did not find existing Ethernet port allocation setting data for {0}", (object)virtualSwitchID)); using (IEthernetPortAllocationSettingData allocationSettingData2 = EthernetPortAllocationSettingData.GetDefaultEthernetPortAllocationSettingData(this._Host)) { Invariant.ArgumentNotNull((object)allocationSettingData2, "Switch port not found"); Invariant.ArgumentNotNull((object)virtualEthernetSwitch, "Virtual switch '" + virtualSwitchID + "' not found"); allocationSettingData2.Parent = ((IWMICommon)this._AdapterSettingData).Object.Path.Path; NIC.tracer.TraceInformation(string.Format("Switch port parent {0}", (object)allocationSettingData2.Parent)); allocationSettingData2.HostResource = new string[1] { ((IWMICommon)virtualEthernetSwitch).Object.Path.Path }; NIC.tracer.TraceInformation(string.Format("Switch port host resource {0}", (object[])allocationSettingData2.HostResource)); NIC.tracer.TraceInformation(string.Format("Adding resource settings to VM: {0}", (object)((IWMICommon)allocationSettingData2).Object.GetText(TextFormat.WmiDtd20))); managmentService.AddResourceSettings(systemSettingData, new string[1] { ((IWMICommon)allocationSettingData2).Object.GetText(TextFormat.WmiDtd20) }).FirstOrDefault <IResourceAllocationSettingData>().TryDispose(); } } else { NIC.tracer.TraceInformation(string.Format("Found existing Ethernet port allocation setting data for {0}", (object)virtualSwitchID)); allocationSettingData1.EnabledState = (ushort)2; allocationSettingData1.HostResource = new string[1] { ((IWMICommon)virtualEthernetSwitch).Object.Path.Path }; NIC.tracer.TraceInformation(string.Format("Ethernet port allocation setting data for {0} set to {1}", (object)virtualSwitchID, (object)((IEnumerable <string>)allocationSettingData1.HostResource).FirstOrDefault <string>())); NIC.tracer.TraceInformation(string.Format("Modifying resource settings: {0}", (object)((IWMICommon)allocationSettingData1).Object.GetText(TextFormat.WmiDtd20))); managmentService.ModifyResourceSettings(new string[1] { ((IWMICommon)allocationSettingData1).Object.GetText(TextFormat.WmiDtd20) }).ForEach <IResourceAllocationSettingData>((Action <IResourceAllocationSettingData>)(v => v.Dispose())); } } } } } } }
public void Write(LogEntry logEntry) { Invariant.ArgumentNotNull((object)logEntry, "logEntry"); try { this.TextWriter.WriteLine(logEntry.ToString()); } catch { } }