示例#1
0
        public static IDeclaredElement DeclaredElementAsTypeMember(this MockFactory factory, string typename, string member, 
            string location)
        {
            var elt = factory.Create<IDeclaredElement>();
            var typeMember = elt.As<ITypeMember>();

            var module = factory.Create<IAssemblyPsiModule>();

            var file = factory.Create<IAssemblyFile>();

            var path = new FileSystemPath(location);
            var type = factory.Create<ITypeElement>();

            typeMember.Setup(tm => tm.GetContainingType()).Returns(type.Object);
            typeMember.Setup(tm => tm.ShortName).Returns(member);

            type.Setup(t => t.CLRName).Returns(typename);

            file.Setup(f => f.Location).Returns(path);

            module.Setup(m => m.Assembly.GetFiles()).Returns(
                new[] { file.Object });

            typeMember.Setup(te => te.Module).Returns(module.Object);

            return elt.Object;
        }
示例#2
0
        public static IDeclaredElement DeclaredElementAsTypeOwner(this MockFactory factory, string typename, 
           string location)
        {
            var elt = factory.Create<IDeclaredElement>();
            var typeOwner = elt.As<ITypeOwner>();
            var type = factory.Create<IType>();
            var declaredType = type.As<IDeclaredType>();
            var typeElement = factory.Create<ITypeElement>();

            typeOwner.SetupGet(tm => tm.Type).Returns(type.Object);

            var module = factory.Create<IAssemblyPsiModule>();

            var file = factory.Create<IAssemblyFile>();

            var path = new FileSystemPath(location);

            declaredType.Setup(dt => dt.GetTypeElement()).Returns(
                typeElement.Object);

            typeElement.Setup(dt => dt.CLRName).Returns(typename);

            file.Setup(f => f.Location).Returns(path);

            module.Setup(m => m.Assembly.GetFiles()).Returns(
                new[] { file.Object });

            typeElement.Setup(dt => dt.Module).Returns(module.Object);

            return elt.Object;
        }
示例#3
0
 public static KeyValuePair<DictGroup, IEnumerable<DictValue>> CreateDictGroup(this DAL<MainDbContext> dal, DictGroup dictGroup, IEnumerable<DictValue> values)
 {
     var newDictGroup = dal.Create<DictGroup>(dictGroup);
     foreach (var value in values)
     {
         value.DictGroup = newDictGroup;
         dal.Create(value);
     }
     return new KeyValuePair<DictGroup, IEnumerable<DictValue>>(newDictGroup, values);
 }
示例#4
0
        public static ofTask CreatePickupAndDelivery(this ofTaskService taskService, ofTaskCreateOptions pickupTaskCreateOptions, ofTaskCreateOptions deliveryTaskCreateOptions, ofRequestOptions requestOptions = null)
        {
            pickupTaskCreateOptions.PickupTask = true;

            var pickupTask = taskService.Create(pickupTaskCreateOptions, requestOptions);
            deliveryTaskCreateOptions.Dependencies = new List<string> { pickupTask.Id };
            var deliveryTask = taskService.Create(deliveryTaskCreateOptions, requestOptions);

            return deliveryTask;
        }
 //Original idea : http://www.extensionmethod.net/Details.aspx?ID=108
 public static void Create(this DirectoryInfo dirInfo, bool createParentDirectories)
 {
     if (!createParentDirectories)
         dirInfo.Create();
     else
     {
         if (dirInfo.Parent != null)
             Create(dirInfo.Parent, true);
         if (!dirInfo.Exists)
             dirInfo.Create();
     }
 }
        public static ulong Create(this Sequences sequences, IList<ulong[]> groupedSequence)
        {
            var finalSequence = new ulong[groupedSequence.Count];

            for (var i = 0; i < finalSequence.Length; i++)
            {
                var part = groupedSequence[i];
                finalSequence[i] = part.Length == 1 ? part[0] : sequences.Create(part);
            }

            return sequences.Create(finalSequence);
        }
 //�Public�Methods�(7)
 /// <summary>
 /// Create directory if not there
 /// </summary>
 /// <param name="instance"></param>
 public static void CreateIfNotExists(this DirectoryInfo instance)
 {
     if (!instance.Exists)
         {
             instance.Create();
         }
 }
示例#8
0
		public static WritingSystemDefinition CreateAndWarnUserIfOutOfDate(this IWritingSystemFactory wsFactory, string langTag)
		{
			WritingSystemDefinition ws;
			bool upToDate;
			WaitCursor.Show();
			try
			{
				upToDate = wsFactory.Create(langTag, out ws);
			}
			finally
			{
				WaitCursor.Hide();
			}

			if (!upToDate)
			{
				if (MessageBox.Show(Form.ActiveForm, LocalizationManager.GetString("WritingSystemSetupView.UnableToConnectToSldrText", "The application is unable to connect to the SIL Locale Data Repository to retrieve the latest information about this language. If you create this writing system, the default settings might be incorrect or out of date. Are you sure you want to create a new writing system?"),
					LocalizationManager.GetString("WritingSystemSetupView.UnableToConnectToSldrCaption", "Unable to connect to SLDR"),
					MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
				{
					return null;
				}
			}

			return ws;
		}
示例#9
0
文件: Extensions.cs 项目: habb0/IHI-1
        /// <summary>
        ///   Creates a directory if it doesn't exist, creating all non-existing parent directories in the process.
        /// </summary>
        /// <param name = "directory">The directory to create.</param>
        /// <returns>True if the directory was created or already exists, false otherwise.</returns>
        public static bool EnsureExists(this DirectoryInfo directory)
        {
            if (!directory.Exists)
                directory.Create();

            return true;
        }
示例#10
0
        public static bool CreateIfNotExist(this CloudBlobContainer container,bool validateCreation)
        {
            int maxAttempts = 60;
            int attempts = 0;

            Boolean created = false;
            while (true)
            {
                try
                {
                    container.Create();
                    created = true;
                    break;
                }
                catch (StorageClientException e)
                {
                    if (e.ErrorCode == StorageErrorCode.ContainerAlreadyExists)
                    {
                        created = false;
                        break;
                    }
                }

                if (++attempts >= maxAttempts)
                    break;

                Thread.Sleep(1000);
            }

            return created;
        }
示例#11
0
        public static ofTask CreateWithDestinationAndWorker(this ofTaskService taskService, ofTaskCreateOptions taskCreateOptions, string address, string workerID, ofRecipientsCreateOptions recipientCreateOptions = null, ofRequestOptions requestOptions = null)
        {
            ofDestinationCreateOptions destinationCreateOptions = new ofDestinationCreateOptions
            {
                Address = new ofAddress
                {
                    Unparsed = address
                }
            };

            ofDestinationService destinationService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofDestinationService() : new ofDestinationService(taskService.ApiKey);

            ofDestination destination = destinationService.Create(destinationCreateOptions, requestOptions);

            taskCreateOptions.DestinationId = destination.Id;

            if (recipientCreateOptions != null)
            {
                ofRecipientService recipientService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofRecipientService() : new ofRecipientService(taskService.ApiKey);
                var recipient = recipientService.Create(recipientCreateOptions, requestOptions);
                taskCreateOptions.Recipients = new List<string> { recipient.Id };
            }

            var task = taskService.Create(taskCreateOptions, requestOptions);

            ofWorkerService workerService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofWorkerService() : new ofWorkerService(taskService.ApiKey);
            ofWorkerUpdateOptions workerUpdateOptions = new ofWorkerUpdateOptions{
                Tasks = new List<string>{ task.Id}
            };
            workerService.Update(workerID, workerUpdateOptions, requestOptions);

            return taskService.Get(task.Id, requestOptions);
        }
        public static DirectoryInfo CreateIfDoesNotExists(this DirectoryInfo directoryInfo)
        {
            if (!directoryInfo.Exists)
                directoryInfo.Create();

            return directoryInfo;
        }
示例#13
0
        public static DirectoryInfo CreateIfNotExists(this DirectoryInfo directory)
        {
            if (!directory.Exists)
                directory.Create();

            return directory;
        }
示例#14
0
        public static IEnumerable<TsDescriptor> Parse(this ITsDescriptorFactory factory, byte[] buffer, int offset, int length)
        {
            while (length > 0)
            {
                if (length < 2)
                {
                    Debug.WriteLine("Unused buffer " + length);
                    break;
                }

                var code = buffer[offset];
                var descriptorLength = buffer[offset + 1];

                offset += 2;
                length -= 2;

                if (length < descriptorLength)
                {
                    Debug.WriteLine(" " + descriptorLength + " exceeds buffer (" + length + " remaining)");
                    break;
                }

                var descriptor = factory.Create(code, buffer, offset, descriptorLength);

                if (null != descriptor)
                    yield return descriptor;

                length -= descriptorLength;
                offset += descriptorLength;
            }
        }
        public static Mock<IDbDataParameter> CreateIDbDataParameter(this MockRepository repository)
        {
            var parameter = repository.Create<IDbDataParameter>();
            parameter.SetupAllProperties();

            return parameter;
        }
示例#16
0
 /// <summary>
 /// Recursively create directory
 /// </summary>
 /// <param name="dirInfo">Folder path to create.</param>
 public static void CreateDirectory(this DirectoryInfo dirInfo)
 {
     if (dirInfo.Parent != null)
         CreateDirectory(dirInfo.Parent);
     if (!dirInfo.Exists)
         dirInfo.Create();
 }
 internal static bool Produce(this ZooKeeper zk, int i, string path)
 {
     var buffer = new Stack<byte>();
     buffer.Push(byte.Parse(i.ToString()));
     zk.Create(path + "/element", buffer.ToArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.EphemeralSequential);
     return true;
 }
示例#18
0
        /// <summary>
        /// DataTable
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="spName"></param>
        /// <param name="sqlParameter"></param>
        /// <param name="dt"></param>
        public static void ExecuteStoredProcedure(this ISqlRepository repository, string spName, SqlParameter[] sqlParameter, DataTable dt)
        {
            using (var conn = repository.Create())
            {
                SqlCommand command = new SqlCommand(spName, conn);
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Clear();
                command.Parameters.AddRange(sqlParameter);
                try
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    conn.Open();

                    sw.Stop();
                    var connOpen = sw.Elapsed.TotalSeconds;
                    sw.Restart();

                    SqlDataAdapter sqlDA = new SqlDataAdapter(command);
                    sqlDA.Fill(dt);

                    sw.Stop();
                    //var execute = sw.Elapsed.TotalSeconds;
                    //Log.SqlServerPerformaceAnalysis(command, connOpen, execute);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
示例#19
0
        public static void EnsureParentExists(this DirectoryInfo directory)
        {
            if (directory.Parent != null)
                EnsureParentExists(directory.Parent);

            if (!directory.Exists)
                directory.Create();
        }
示例#20
0
 /// <summary>
 /// Emits a Console.WriteLine call to using the current CilWorker that will only be called if the contents
 /// of the target variable are null at runtime.
 /// </summary>
 /// <param name="IL">The target CilWorker.</param>
 /// <param name="text">The text that will be written to the console.</param>
 /// <param name="targetVariable">The target variable that will be checked for null at runtime.</param>
 public static void EmitWriteLineIfNull(this CilWorker IL, string text, VariableDefinition targetVariable)
 {
     var skipWrite = IL.Create(OpCodes.Nop);
     IL.Emit(OpCodes.Ldloc, targetVariable);
     IL.Emit(OpCodes.Brtrue, skipWrite);
     IL.EmitWriteLine(text);
     IL.Append(skipWrite);
 }
示例#21
0
 public static DirectoryInfo CreateWithContent(this DirectoryInfo info, IFixture fixture)
 {
     info.Create();
     var path = Path.Combine(info.FullName, fixture.Create<string>());
     using (var sw = new StreamWriter(new FileInfo(path).Open(FileMode.Create)))
         sw.WriteLine(fixture.Create<string>());
     return info;
 }
示例#22
0
 //BUG: Well, not sure if this is a bug or not really but there's currently only 1 way to get the root HiveId for an IO
 // entity and thats to get Hive to return the entity based on a '/' Id.
 public static HiveId GetRootNodeId(this GroupUnitFactory<IFileStore> factory)
 {
     using (var uow = factory.Create())
     {
         var e = uow.Repositories.Get<File>(new HiveId("/"));
         return e.Id;
     }
 }
        public static IPipelineReader ReadFile(this PipelineFactory factory, string path)
        {
            var reader = factory.Create();

            var file = new FileReader(reader);
            file.OpenReadFile(path);
            return file;
        }
        public static WebRequest CreateXmlRequest(this IWebRequestCreate creator, Uri uri, ICredentials credentials)
        {
            var request = (HttpWebRequest)creator.Create(uri);
            request.Accept = "text/xml, application/xml";
            request.Credentials = credentials;

            return request.FixUsernameHandling();
        }
示例#25
0
        public static ZlpDirectoryInfo CheckCreate(this ZlpDirectoryInfo folder)
        {
            if( folder==null) throw new ArgumentNullException(@"folder");

            if (!folder.Exists) folder.Create();

            return folder;
        }
示例#26
0
        public static Instruction Copy(this ILProcessor processor, Instruction toCopy)
        {
            if (toCopy.OpCode.OperandType != OperandType.InlineNone)
            {
                throw new ArgumentException("Can't this instruction", "toCopy");
            }

            return processor.Create(toCopy.OpCode);
        }
        public static Mock<IDbConnection> CreateIDbConnection(this MockRepository repository)
        {
            var connection = repository.Create<IDbConnection>();

            connection.SetupAllProperties();
            connection.Setup(c => c.CreateCommand()).Returns(() => repository.CreateIDbCommand().Object);

            return connection;
        }
    public static Deployment DeployRelease(this IOctopusSession session, Release release, DeploymentEnvironment environment, bool forceRedeploymentOfExistingPackages = false)
    {
        var deployment = new Deployment();
        deployment.EnvironmentId = environment.Id;
        deployment.ReleaseId = release.Id;
        deployment.ForceRedeployment = forceRedeploymentOfExistingPackages;

        return session.Create(release.Link("Deployments"), deployment);
    }
 /// <summary>
 /// Delete and create the folder if it already exists
 /// </summary>
 public static void Recreate(this DirectoryInfo self)
 {
     self.Refresh();
     if (self.Exists)
     {
         self.Delete(true);
     }
     self.Create();
 }
 /// <summary>
 /// The create.
 /// </summary>
 /// <param name="repository">
 /// The repository.
 /// </param>
 /// <param name="from">
 /// The from.
 /// </param>
 /// <param name="to">
 /// The to.
 /// </param>
 /// <param name="subject">
 /// The subject.
 /// </param>
 /// <param name="body">
 /// The body.
 /// </param>
 public static void Create(
     this IRepository<Mail> repository,
     string from,
     string to,
     string subject,
     string body)
 {
     repository.Create(from, null, to, null, subject, body, null, 0, null);
 }