Beispiel #1
0
 public override bool LoadFromContents(NSObject contents, string typeName, out NSError outError)
 {
     try {
         var data = (NSData)contents;
         if (data.Length > 0)
         {
             using (var s = data.AsStream())
                 using (var r = new StreamReader(s)) {
                     Code     = r.ReadToEnd();
                     Encoding = r.CurrentEncoding;
                 }
         }
         else
         {
             Code = "";
         }
         outError = null;
         return(true);
     }
     catch (Exception ex) {
         Debug.WriteLine(ex);
         outError = NSError.FromDomain(new NSString("CEditor"), 1001);
         return(false);
     }
 }
 public override void StartLoading()
 {
     if (!UseCache)
     {
         var connectionRequest = (NSMutableUrlRequest)Request.MutableCopy;
         // we need to mark this request with our header so we know not to handle it in +[NSURLProtocol canInitWithRequest:].
         connectionRequest.SetValueForKey("", MtRnCachingUrlHeader);
         var connection = NSUrlConnection.FromRequest(connectionRequest, this);
         Connection = connection;
     }
     else
     {
         var cache = NSKeyedUnarchiver.UnarchiveFile(CachePathForRequest(this.Request)) as MtRnCachedData;
         if (cache != null)
         {
             var data            = cache.Data;
             var response        = cache.Response;
             var redirectRequest = cache.RedirectRequest;
             if (redirectRequest != null)
             {
                 this.Client.Redirected(this, redirectRequest, response);
             }
             else
             {
                 Client.ReceivedResponse(this, response, NSUrlCacheStoragePolicy.NotAllowed);
                 Client.DataLoaded(this, data);
                 Client.FinishedLoading(this);
             }
         }
         else
         {
             this.Client.FailedWithError(NSError.FromDomain("TODO", NSUrlError.CannotConnectToHost));
         }
     }
 }
Beispiel #3
0
        public override bool AllocateRenderResources(out NSError outError)
        {
            if (!base.AllocateRenderResources(out outError))
            {
                return(false);
            }

            if (outputBus.Format.ChannelCount != inputBus.Bus.Format.ChannelCount)
            {
                if (outError != null)
                {
                    outError = NSError.FromDomain(NSError.OsStatusErrorDomain, (int)AudioUnitStatus.FailedInitialization);
                }

                return(false);
            }

            inputBus.AllocateRenderResources(MaximumFramesToRender);

            Kernel.Init((int)outputBus.Format.ChannelCount, outputBus.Format.SampleRate);
            Kernel.Reset();

            var scheduleParameter = ScheduleParameterBlock;
            var rampTime          = 0.02 * outputBus.Format.SampleRate;

            ParameterTree.ImplementorValueObserver = (param, val) =>
                                                     scheduleParameter(AUEventSampleTime.Immediate, (uint)rampTime, param.Address, val);

            return(true);
        }
Beispiel #4
0
        //
        // Load support:
        //    Override one of ReadFromData, ReadFromFileWrapper or ReadFromUrl
        //
        public override bool ReadFromData(NSData data, string typeName, out NSError outError)
        {
            outError = null;
            Console.WriteLine("About to read data of type {0}", typeName);

            NSMutableArray newArray = null;

            try {
                newArray = (NSMutableArray)NSKeyedUnarchiver.UnarchiveObject(data);
            }
            catch (Exception ex) {
                Console.WriteLine("Error loading file: Exception: {0}", ex.Message);
                if (outError != null)
                {
                    NSDictionary d = NSDictionary.FromObjectAndKey(new NSString("The data is corrupted."), NSError.LocalizedFailureReasonErrorKey);
                    outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4, d);
                }
                return(false);
            }
            this.Cars = newArray;
            // For Revert to Saved. Have to point the array controller to the new array.
            if (arrayController != null)
            {
                arrayController.Content = this.Cars;
            }
            return(true);
        }
Beispiel #5
0
        //
        // Load support:
        //    Override one of ReadFromData, ReadFromFileWrapper or ReadFromUrl
        //
        public override bool ReadFromData(NSData data, string typeName, out NSError outError)
        {
            outError = null;
            Console.WriteLine("About to read data of type {0}", typeName);

            NSMutableArray newArray = null;

            try {
                newArray = (NSMutableArray)NSKeyedUnarchiver.UnarchiveObject(data);
            }
            catch (Exception ex) {
                Console.WriteLine("Error loading file: Exception: {0}", ex.Message);
                if (outError != null)
                {
                    NSDictionary d = NSDictionary.FromObjectAndKey(new NSString("The data is corrupted."), NSError.LocalizedFailureReasonErrorKey);
                    outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4, d);
                }
                return(false);
            }
            this.Employees = newArray;
            return(true);

            // Default template code
//			outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4);
//			return false;
        }
Beispiel #6
0
        public override void StartLoading()
        {
            try
            {
                string objName = Request.Url.Host;
                string dataraw = Request.Url.Query.Split('=')[1];
                string json    = System.Web.HttpUtility.UrlDecode(dataraw).Replace("&_", "");

                JsReturn result = JSBridge.RaiseEvent(JsTelegram.DeserializeObject(json));

                // indicate success.
                var data = NSData.FromString(result.Serialize());
                Console.WriteLine(data);
                using (var response = new NSUrlResponse(Request.Url, "application/json", Convert.ToInt32(data.Length), "utf-8"))
                {
                    Client.ReceivedResponse(this, response, NSUrlCacheStoragePolicy.NotAllowed);
                    Client.DataLoaded(this, data);
                    Client.FinishedLoading(this);
                }
            }
            catch (Exception)
            {
                Client.FailedWithError(this, NSError.FromDomain(new NSString("AppProtocolHandler"), Convert.ToInt32(NSUrlError.ResourceUnavailable)));
                Client.FinishedLoading(this);
            }
        }
Beispiel #7
0
        public static NSError ErrorWithCode(int errorCode, NSString description)
        {
            NSDictionary userinfo = null;

            if (description != null)
            {
                userinfo = NSDictionary.FromObjectAndKey(description, NSError.LocalizedDescriptionKey);
            }

            return(NSError.FromDomain(new NSString("WorkflowErrorDomain"), errorCode, userinfo));
        }
Beispiel #8
0
 public override NSData?GetAsData(string typeName, out NSError?outError)
 {
     try {
         var bytes = encoding.GetBytes(Code);
         var data  = NSData.FromArray(bytes);
         outError = null;
         return(data);
     }
     catch (Exception ex) {
         Console.WriteLine(ex);
         outError = NSError.FromDomain(new NSString("CEditor"), 101);
         return(null);
     }
 }
Beispiel #9
0
 public override NSObject ContentsForType(string typeName, out NSError outError)
 {
     try {
         var bytes = Encoding.GetBytes(Code);
         var data  = NSData.FromArray(bytes);
         outError = null;
         return(data);
     }
     catch (Exception ex) {
         Debug.WriteLine(ex);
         outError = NSError.FromDomain(new NSString("CEditor"), 1002);
         return(null);
     }
 }
Beispiel #10
0
 public override bool ReadFromUrl(NSUrl url, string typeName, out NSError outError)
 {
     try
     {
         DocName = url.Path;
         CreateApiMate();
         LoadFile(DocName);
     }
     catch (Exception ex)
     {
         outError = NSError.FromDomain((NSString)ex.Message, -1);
         return(false);
     }
     outError = null;
     return(true);
 }
        public override bool ReadFromUrl(NSUrl url, string typeName, out NSError outError)
        {
            outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4);

            InvokeOnMainThread(async() =>
            {
                if (App.Document != null)
                {
                    App.ResetDocument();
                }
                var outputText           = App.DocumentViewController.Messages;
                var sourcesProgress      = App.DocumentViewController.Sources;
                var individualsProgress  = App.DocumentViewController.Individuals;
                var familiesProgress     = App.DocumentViewController.Families;
                var relationshipProgress = App.DocumentViewController.Relationships;
                var stream   = new FileStream(url.Path, FileMode.Open, FileAccess.Read);
                var document = await Task.Run(() => _familyTree.LoadTreeHeader(url.Path, stream, outputText));
                if (document == null)
                {
                    App.DocumentViewController.Messages.Report($"\n\nUnable to load file {url.Path}\n");
                }
                else
                {
                    await Task.Run(() => _familyTree.LoadTreeSources(document, sourcesProgress, outputText));
                    await Task.Run(() => _familyTree.LoadTreeIndividuals(document, individualsProgress, outputText));
                    await Task.Run(() => _familyTree.LoadTreeFamilies(document, familiesProgress, outputText));
                    await Task.Run(() => _familyTree.LoadTreeRelationships(document, relationshipProgress, outputText));

                    App.DocumentViewController.Messages.Report($"\n\nFinished loading file {url.Path}\n");

                    PrintInfo.Orientation          = NSPrintingOrientation.Landscape;
                    PrintInfo.LeftMargin           = 45;
                    PrintInfo.RightMargin          = 30;
                    PrintInfo.TopMargin            = 30;
                    PrintInfo.BottomMargin         = 30;
                    PrintInfo.HorizontalPagination = NSPrintingPaginationMode.Auto;
                    PrintInfo.VerticallyCentered   = false;
                    PrintInfo.HorizontallyCentered = false;
                    App.Document = this;
                    App.SetMenus(true);
                    await Analytics.TrackAction(Analytics.MainFormAction, Analytics.LoadGEDCOMEvent);
                    UIHelpers.ShowMessage($"Gedcom file {url.Path} loaded.", "FTAnalyzer");
                }
            });
            RaiseDocumentModified(this);
            return(true);
        }
Beispiel #12
0
 public override bool ReadFromData(NSData data, string typeName, out NSError?outError)
 {
     try {
         using (var s = data.AsStream())
             using (var r = new StreamReader(s)) {
                 Code     = r.ReadToEnd();
                 encoding = r.CurrentEncoding;
             }
         outError = null;
         BeginInvokeOnMainThread(() => CodeChanged?.Invoke(this, EventArgs.Empty));
         return(true);
     }
     catch (Exception ex) {
         Console.WriteLine(ex);
         outError = NSError.FromDomain(new NSString("CEditor"), 101);
         return(false);
     }
 }
Beispiel #13
0
        //
        // Load support:
        //    Override one of ReadFromData, ReadFromFileWrapper or ReadFromUrl
        //
        public override bool ReadFromData(NSData data, string typeName, out NSError outError)
        {
            outError = null;
            Console.WriteLine("About to read data of type {0}", typeName);

            NSMutableArray newArray = null;

            try {
                newArray = (NSMutableArray)NSKeyedUnarchiver.UnarchiveObject(data);
            }
            catch (Exception ex) {
                Console.WriteLine("Error loading file: Exception: {0}", ex.Message);
                NSDictionary d = NSDictionary.FromObjectAndKey(new NSString(NSBundle.MainBundle.LocalizedString("DATA_CORRUPTED", null)), NSError.LocalizedFailureReasonErrorKey);
                outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4, d);
                return(false);
            }

            Ovals = NSArray.FromArray <Oval>(newArray).ToList <Oval>();
            return(true);
        }
 //
 // Load support:
 //    Override one of ReadFromData, ReadFromFileWrapper or ReadFromUrl
 //
 public override bool ReadFromData(NSData data, string typeName, out NSError outError)
 {
     outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4);
     return(false);
 }
 //
 // Save support:
 //    Override one of GetAsData, GetAsFileWrapper, or WriteToUrl.
 //
 // This method should store the contents of the document using the given typeName
 // on the return NSData value.
 public override NSData GetAsData(string documentType, out NSError outError)
 {
     outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4);
     return(null);
 }
Beispiel #16
0
 public override NSData GetAsData(string typeName, out NSError outError)
 {
     outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4);
     Logger.Debug("ReadFromData {0}", outError);
     return(null);
 }
        partial void Send(Foundation.NSObject sender)
        {
            NSError cancelError = NSError.FromDomain(NSError.CocoaErrorDomain, 3072, null);

            ExtensionContext.CancelRequest(cancelError);
        }
Beispiel #18
0
        public override bool ReadFromUrl(NSUrl url, string typeName, out NSError outError)
        {
            outError = null;
            // Which files are we getting the zipinfo for?
            string filename = url.Path;


            string lPath = "";
            string flags = "";

            Console.WriteLine("Type Name: {0}", typeName);
            switch (typeName)
            {
            case "public.zip-archive":
                lPath = "/usr/bin/zipinfo";
                flags = "-1";
                break;

            case "public.tar-archive":
                lPath = "/usr/bin/tar";
                flags = "tf";
                break;

            case "org.gnu.gnu-zip-tar-archive":
                lPath = "/usr/bin/tar";
                flags = "tzf";
                break;

            default:
                NSDictionary eDict = NSDictionary.FromObjectAndKey(new NSString("Archive type not supported"), NSError.LocalizedFailureReasonErrorKey);
                outError = NSError.FromDomain(NSError.OsStatusErrorDomain, 0, eDict);
                break;
            }

            // Prepare a task object
            NSTask task = new NSTask();

            task.LaunchPath = lPath;
            string[] args = { flags, filename };
            task.Arguments = args;

            // Create a pipe to read from
            NSPipe outPipe = new NSPipe();

            task.StandardOutput = outPipe;

            // Start the process
            task.Launch();

            // Read the output
            NSData data = outPipe.ReadHandle.ReadDataToEndOfFile();

            // Make sure the task terminates normally
            task.WaitUntilExit();
            int status = task.TerminationStatus;

            // Check status
            if (status != 0)
            {
                if (outError != null)
                {
                    NSDictionary eDict = NSDictionary.FromObjectAndKey(new NSString("zipinfo failed"), NSError.LocalizedFailureReasonErrorKey);
                    outError = NSError.FromDomain(NSError.OsStatusErrorDomain, 0, eDict);
                }
                return(false);
            }

            // Convert to a string
            string aString = NSString.FromData(data, NSStringEncoding.UTF8).ToString();

            // Break the string into lines
            MyDocument.filenames = aString.Split(new char[] { '\n' });
            Console.WriteLine(MyDocument.filenames);

            // In case of revert
//			tableView.ReloadData();

            return(true);
        }
Beispiel #19
0
        public override void StartLoading()
        {
            // parse callback function name.
            // EX: callback=jXHR.cb0&data=%7B%22hello%22%3A%22world%22%7D&_=0.3452287893742323
            var parameters = Request.Url.Query.Split('&');

            if (parameters.Length > 2)
            {
                var callbackToks = parameters[0].Split('=');
                var dataToks     = parameters[1].Split('=');
                if (callbackToks.Length > 1 && dataToks.Length > 1)
                {
                    // Determine what to do here based on the url
                    var appUrl = new AppUrl()
                    {
                        Module   = Request.Url.Host,
                        Method   = Request.Url.RelativePath.Substring(1),
                        JsonData = System.Web.HttpUtility.UrlDecode(dataToks[1])
                    };

                    // this is a request from mt.js so handle it.
                    switch (appUrl.Module.ToLower())
                    {
                    case "app":
                        if (string.Equals(appUrl.Method, "fireEvent", StringComparison.InvariantCultureIgnoreCase))
                        {
                            // fire this event.
                            var feData = appUrl.DeserializeFireEvent();
                            // find event listeners for this event and trigger it.
                            JsBridge.JsEventFired(feData);
                        }

                        break;

                    case "api":
                        if (string.Equals(appUrl.Method, "log", StringComparison.InvariantCultureIgnoreCase))
                        {
                            // log output.
                            var lData = appUrl.DeserializeLog();
#if DEBUG
                            Console.WriteLine("BROWSER:[" + lData.Level + "]: " + lData.Message);
#endif
                        }

                        break;
                    }

                    // indicate success.
                    var data = NSData.FromString(callbackToks[1] + "({'success' : '1'});");
                    using (var response = new NSUrlResponse(Request.Url, "text/javascript", Convert.ToInt32(data.Length), "utf-8")) {
                        Client.ReceivedResponse(this, response, NSUrlCacheStoragePolicy.NotAllowed);
                        Client.DataLoaded(this, data);
                        Client.FinishedLoading(this);
                    }

                    return;
                }
            }

            Client.FailedWithError(this, NSError.FromDomain(new NSString("AppProtocolHandler"), Convert.ToInt32(NSUrlError.ResourceUnavailable)));
            Client.FinishedLoading(this);
        }
Beispiel #20
0
 public static NSError ToNSError(this IOReturn value)
 {
     return(NSError.FromDomain(NSError.MachErrorDomain, (int)value));
 }