예제 #1
0
		/// <summary>
		///     Try get a new <see cref="IAbsoluteFilePath" /> object from this string.
		/// </summary>
		/// <returns>
		///     <i>true</i> if <paramref name="path" /> is a valid absolute file path and as a consequence, the returned
		///     <paramref name="absolutePath" /> is not null.
		/// </returns>
		/// <remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
		/// <param name="path">Represents the path string.</param>
		/// <param name="absolutePath">If this method returns <i>true</i>, this is the returned path object.</param>
		/// <param name="failureMessage">If this method returns <i>false</i>, this is the plain english description of the failure.</param>
		public static bool TryGetAbsoluteFilePath(this string path, out IAbsoluteFilePath absolutePath, out string failureMessage)
		{
			absolutePath = null;

			if (IsNullOrEmpty(() => path, out failureMessage))
			{
				return false;
			}

			if (!path.IsValidAbsoluteFilePath(out failureMessage))
			{
				return false;
			}

			absolutePath = new AbsoluteFilePath(path);

			return true;
		}
예제 #2
0
 ///<summary>
 ///Try get a new <see cref="IAbsoluteFilePath"/> object from this string.
 ///</summary>
 ///<returns><i>true</i> if <paramref name="pathString"/> is a valid absolute file path and as a consequence, the returned <paramref name="absoluteFilePath"/> is not null.</returns>
 ///<remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
 ///<param name="pathString">Represents the path string.</param>
 ///<param name="absoluteFilePath">If this method returns <i>true</i>, this is the returned path object.</param>
 ///<param name="failureReason">If this method returns <i>false</i>, this is the plain english description of the failure.</param>
 public static bool TryGetAbsoluteFilePath(this string pathString, out IAbsoluteFilePath absoluteFilePath, out string failureReason) {
    absoluteFilePath = null;
    if (pathString.IsPathStringNullOrEmpty(out failureReason)) { return false; }
    if (!pathString.IsValidAbsoluteFilePath(out failureReason)) { return false; }
    absoluteFilePath = new AbsoluteFilePath(pathString);
    return true;
 }
예제 #3
0
 public static AbsoluteFilePath ToAbsoluteFilePath(this NSUrl url)
 {
     return(AbsoluteFilePath.Parse(url.Path));
 }
예제 #4
0
 public static NSUrl ToNSUrl(this AbsoluteFilePath path)
 {
     return(new NSUrl(new Uri(path.NativePath).AbsoluteUri));
 }
예제 #5
0
 public static IEnumerable <SuggestItem> Do(ICompiler compiler, AbsoluteFilePath filePath, string code, int caret)
 {
     return(new CreateUXSuggestions().CreateSuggestionsInternal(compiler, filePath, code, caret));
 }
예제 #6
0
 /// <summary>
 /// Gets whether the file is an executable based upon its file extension alone.
 /// </summary>
 /// <returns>Returns true if the file is an executable file, else it returns false</returns>
 public bool IsExe(AbsoluteFilePath filePath)
 {
     return(".exe".Equals(filePath.Filename.Extension, StringComparison.OrdinalIgnoreCase));
 }
예제 #7
0
 /// <summary>
 /// Gets whether the file is an executable based upon its file extension alone.
 /// </summary>
 /// <returns>Returns true if the file is an executable file, else it returns false</returns>
 public static bool IsExe(AbsoluteFilePath filePath)
 {
     return(Api.IsExe(filePath));
 }
예제 #8
0
 internal IEnumerable <IFilePath> SketchFilePaths(AbsoluteFilePath sketchListFilePath)
 {
     return(SketchImportUtils.SketchFilePaths(sketchListFilePath, _logger));
 }
 public UnknownDocumentOrProjectType(AbsoluteFilePath path)
 {
     Path = path;
 }
예제 #10
0
 public static void AssertFileExists(this AbsoluteFilePath absoluteFilePath)
 {
     XIO.Api.Paths.AssertFileExists(absoluteFilePath);
 }
예제 #11
0
        public static LiveDocument Open(
            AbsoluteFilePath path,
            IFileSystem fs,
            IObservable <ILookup <ObjectIdentifier, ObjectIdentifier> > metadata,
            BehaviorSubject <Dictionary <ObjectIdentifier, IElement> > idToElement,
            IObserver <IBinaryMessage> mutations,
            IScheduler scheduler)
        {
            IDocument <byte[]> fileOnDisk = new FileWatchingDocument(fs, path);


            var parsingErrors = new BehaviorSubject <Optional <Exception> >(Optional.None());

            var invalidated = new Subject <Unit>();

            var root = new LiveElement(
                file: path,
                metadata: metadata,
                isReadOnly: fileOnDisk.ErrorsDuringLoading.Or(parsingErrors)
                .Select(e => e.HasValue)
                .DistinctUntilChanged()
                .Replay(1).RefCount(),
                invalidated: invalidated,
                mutations: mutations,
                getElement: id =>
                idToElement.Value.TryGetValue(id).Or(Element.Empty));

            Optional <XElement> xElementForSaving = Optional.None <XElement>();

            var allElements = root.Subtree().Replay(1);

            var source = new ReplaySubject <SourceFragment>(1);

            return(new LiveDocument
            {
                _garbage = Disposable.Combine(

                    // Save on internal changes
                    invalidated
                    .Select(_ =>
                {
                    if (xElementForSaving.HasValue)
                    {
                        var sourceFragment = SourceFragment.FromXml(xElementForSaving.Value);
                        source.OnNext(sourceFragment);
                        return Optional.Some(sourceFragment);
                    }
                    return Optional.None();
                })
                    .NotNone()
                    .Throttle(TimeSpan.FromSeconds(0.5), scheduler)
                    .Select(sourceFragment =>
                            Observable.FromAsync(async() =>
                                                 await fileOnDisk.Save(sourceFragment.ToBytes())))
                    .Concat()
                    .Subscribe(),

                    // Load on external changes
                    fileOnDisk.ExternalChanges
                    .ObserveOn(Application.MainThread)
                    .Subscribe(reload =>
                {
                    var sourceFragment = SourceFragment.FromBytes(reload);
                    source.OnNext(sourceFragment);

                    try
                    {
                        var simulatorWasFaulted = parsingErrors.Value.HasValue;

                        var newDocument = sourceFragment.ToXml();
                        parsingErrors.OnNext(Optional.None());

                        xElementForSaving = Optional.None();
                        Console.WriteLine("Reloading " + path + " from disk...");
                        root.UpdateFrom(newDocument);                                                 // no known reasons to throw
                        xElementForSaving = Optional.Some(newDocument);

                        // hack to clear errors from the simulator,
                        // since UpdateFrom() doesn't know that the simulator
                        // have failed and will try to emit incremental updates
                        if (simulatorWasFaulted)
                        {
                            mutations.OnNext(new ReifyRequired());
                        }
                    }
                    catch (Exception e)
                    {
                        parsingErrors.OnNext(e);

                        // hack to get errors from the simulator
                        mutations.OnNext(new ReifyRequired());
                    }
                }),

                    // Share subscription to Eleements
                    allElements.Connect(),

                    // Dispose fileOnDisk when disposed
                    fileOnDisk),

                FilePath = Observable.Return(path),

                Errors = fileOnDisk.Errors.Or(parsingErrors),

                SimulatorIdPrefix = path.NativePath,

                Source = source,

                Root = root,
                Elements = allElements,

                _root = root,
                _path = path,
                _idToElement = idToElement,
            });
        }