当前位置: 首页>>代码示例>>C#>>正文


C# Runtime.GetResource方法代码示例

本文整理汇总了C#中Runtime.GetResource方法的典型用法代码示例。如果您正苦于以下问题:C# Runtime.GetResource方法的具体用法?C# Runtime.GetResource怎么用?C# Runtime.GetResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Runtime的用法示例。


在下文中一共展示了Runtime.GetResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

            MoSync.SystemPropertyManager.RegisterSystemPropertyProvider("mosync.path.local",
                delegate(String key)
                {
                    // The isolated storage becomes the "root"
                    return "/";
                }
            );

            ioctls.maFileOpen = delegate(int _path, int _mode)
            {
                String path = core.GetDataMemory().ReadStringAtAddress(_path);
                path = ConvertPath(path);

                File file = null;
                FileAccess access = 0;

                if (_mode == MoSync.Constants.MA_ACCESS_READ)
                {
                    access = FileAccess.Read;
                }
                else if (_mode == MoSync.Constants.MA_ACCESS_READ_WRITE)
                {
                    access = FileAccess.ReadWrite;
                }
                else
                {
                    throw new Exception("Invalid file access mode");
                }

                file = new File(path, access);

                if (file.IsDirectory)
                {
                    if (isolatedStorage.FileExists(path))
                        return MoSync.Constants.MA_FERR_WRONG_TYPE;
                }
                else
                {
                    if (isolatedStorage.DirectoryExists(path))
                        return MoSync.Constants.MA_FERR_WRONG_TYPE;
                    try
                    {
                        file.TryOpen();
                    }
                    catch (IsolatedStorageException e)
                    {
                        MoSync.Util.Log(e);
                        return MoSync.Constants.MA_FERR_GENERIC;
                    }
                }

                mFileHandles.Add(mNextFileHandle, file);
                return mNextFileHandle++;
            };

            ioctls.maFileClose = delegate(int _file)
            {
                File file = mFileHandles[_file];
                file.Close();
                mFileHandles.Remove(_file);
                return 0;
            };

            ioctls.maFileRead = delegate(int _file, int _dst, int _len)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
                    return MoSync.Constants.MA_FERR_WRONG_TYPE;
                IsolatedStorageFileStream fileStream = file.FileStream;
                if (fileStream == null)
                    return MoSync.Constants.MA_FERR_GENERIC;
                core.GetDataMemory().WriteFromStream(_dst, fileStream, _len);
                return 0;
            };

            ioctls.maFileReadToData = delegate(int _file, int _data, int _offset, int _len)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
                    return MoSync.Constants.MA_FERR_WRONG_TYPE;
                IsolatedStorageFileStream fileStream = file.FileStream;
                if (fileStream == null)
                    return MoSync.Constants.MA_FERR_GENERIC;
                Resource dataRes = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                //Memory data = (Memory)dataRes.GetInternalObject();
                Stream data = (Stream)dataRes.GetInternalObject();
                MoSync.Util.CopySeekableStreams(fileStream, (int)fileStream.Position,
                    data, _offset, _len);
                //data.WriteFromStream(_offset, fileStream, _len);
                return 0;
            };

            ioctls.maFileWriteFromData = delegate(int _file, int _data, int _offset, int _len)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
//.........这里部分代码省略.........
开发者ID:patrickbroman,项目名称:MoSync,代码行数:101,代码来源:MoSyncFileModule.cs

示例2: Init


//.........这里部分代码省略.........
            syscalls.maFillTriangleStrip = delegate(int points, int count)
            {

                int[] xcoords = new int[count];
                int[] ycoords = new int[count];

                for (int i = 0; i < count; i++)
                {
                    xcoords[i] = core.GetDataMemory().ReadInt32(points + i * 8);
                    ycoords[i] = core.GetDataMemory().ReadInt32(points + i * 8 + 4);
                }

                for (int i = 2; i < count; i++)
                {
                    mCurrentDrawTarget.FillTriangle(
                        xcoords[i - 2], ycoords[i - 2],
                        xcoords[i - 1], ycoords[i - 1],
                        xcoords[i - 0], ycoords[i - 0],
                        (int)mCurrentColor);
                }
            };

            syscalls.maSetDrawTarget = delegate(int drawTarget)
            {
                int oldDrawTarget = mCurrentDrawTargetIndex;
                if (drawTarget == mCurrentDrawTargetIndex) return oldDrawTarget;
                if (drawTarget == MoSync.Constants.HANDLE_SCREEN)
                {
                    mCurrentDrawTarget = mBackBuffer;
                    mCurrentDrawTargetIndex = drawTarget;
                    return oldDrawTarget;
                }

                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, drawTarget);
                mCurrentDrawTarget = (WriteableBitmap)res.GetInternalObject();
                mCurrentDrawTargetIndex = drawTarget;
                return oldDrawTarget;
            };

            syscalls.maGetScrSize = delegate()
            {
                return MoSync.Util.CreateExtent(mBackBuffer.PixelWidth, mBackBuffer.PixelHeight);
            };

            syscalls.maGetImageSize = delegate(int handle)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, handle);
                BitmapSource src = (BitmapSource)res.GetInternalObject();
                int w = 0, h = 0;

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    w = src.PixelWidth;
                    h = src.PixelHeight;
                });

                return MoSync.Util.CreateExtent(w, h);
            };

            syscalls.maDrawImage = delegate(int image, int left, int top)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, image);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();
                Rect srcRect = new Rect(0, 0, src.PixelWidth, src.PixelHeight);
                Rect dstRect = new Rect(left, top, src.PixelWidth, src.PixelHeight);
                mCurrentDrawTarget.Blit(dstRect, src, srcRect, WriteableBitmapExtensions.BlendMode.Alpha);
开发者ID:asamuelsson,项目名称:MoSync,代码行数:67,代码来源:MoSyncGraphicsModule.cs

示例3: Init

        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            runtime.RegisterCleaner(delegate()
            {
                foreach (KeyValuePair<int, Connection> p in mConnections)
                {
                    p.Value.close();
                }
                mConnections.Clear();
            });

            mResultHandler = delegate(int handle, int connOp, int result)
            {
                Memory evt = new Memory(4 * 4);
                evt.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_CONN);
                evt.WriteInt32(MoSync.Struct.MAEvent.conn.handle, handle);
                evt.WriteInt32(MoSync.Struct.MAEvent.conn.opType, connOp);
                evt.WriteInt32(MoSync.Struct.MAEvent.conn.result, result);
                runtime.PostEvent(new Event(evt));
            };

            syscalls.maConnect = delegate(int _url)
            {
                String url = core.GetDataMemory().ReadStringAtAddress(_url);
                //Util.Log("maConnect(" + url + ")\n");
                if (url.StartsWith("btspp"))
                    return MoSync.Constants.CONNERR_UNAVAILABLE;
                Uri uri = new Uri(url);
                Connection c;
                if (uri.Scheme.Equals("socket"))
                {
                    c = new SocketConnection(uri, mNextConnHandle);
                }
                else if (uri.Scheme.Equals("http") || uri.Scheme.Equals("https"))
                {
                    c = new WebRequestConnection(uri, mNextConnHandle, MoSync.Constants.HTTP_GET);
                }
                else
                {
                    return MoSync.Constants.CONNERR_GENERIC;
                }

                c.connect(mResultHandler);
                mConnections.Add(mNextConnHandle, c);
                return mNextConnHandle++;
            };

            syscalls.maConnClose = delegate(int _conn)
            {
                Connection c = mConnections[_conn];
                c.close();
                mConnections.Remove(_conn);
            };

            syscalls.maConnGetAddr = delegate(int _conn, int _addr)
            {
                if (_conn == MoSync.Constants.HANDLE_LOCAL) // unavailable
                    return -1;
                Connection c = mConnections[_conn];
                return c.getAddr(core.GetDataMemory(), _addr);
            };

            syscalls.maConnRead = delegate(int _conn, int _dst, int _size)
            {
                Connection c = mConnections[_conn];
                c.recv(core.GetDataMemory().GetData(), _dst, _size, mResultHandler);
            };

            DataDelegate dataDelegate = delegate(int _conn, int _data,
                    CommDelegate cd)
            {
                Connection c = mConnections[_conn];
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                Stream s = (Stream)res.GetInternalObject();
                runtime.SetResourceRaw(_data, Resource.Flux);
                MemoryStream mem = null;
                if (s.GetType() == typeof(MemoryStream))
                {
                    mem = (MemoryStream)s;
                }
                else
                {
                    MoSync.Util.CriticalError("Only binaries (non-ubins) are allowed for maConn(Read/Write)(To/From)Data");
                }

                cd(c, mem.GetBuffer(),
                        delegate(int handle, int connOp, int result)
                        {
                            runtime.SetResourceRaw(_data, res);
                            mResultHandler(handle, connOp, result);
                        });
            };

            syscalls.maConnReadToData = delegate(int _conn, int _data, int _offset, int _size)
            {
                dataDelegate(_conn, _data,
                        delegate(Connection c, byte[] buf, ResultHandler rh)
                        {
                            c.recv(buf, _offset, _size, rh);
                        });
//.........这里部分代码省略.........
开发者ID:ronald132,项目名称:MoSync,代码行数:101,代码来源:MoSyncCommunicationsModule.cs

示例4: Init

        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            // maybe use some pretty reflection mechanism to find all syscall implementations here..
            syscalls.maCheckInterfaceVersion = delegate(int hash)
            {
                if (MoSync.Constants.MoSyncHash != (uint)hash)
                    MoSync.Util.CriticalError("Invalid hash!");
                return hash;
            };

            syscalls.maPanic = delegate(int code, int str)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(str);
                MoSync.Util.CriticalError(message + "\ncode: " + code);
            };

            syscalls.maExit = delegate(int res)
            {
                MoSync.Util.Exit(res);
            };

            DateTime startDate = System.DateTime.Now;
            syscalls.maGetMilliSecondCount = delegate()
            {
                System.TimeSpan offset = (System.DateTime.Now - startDate);

                return offset.Milliseconds + (offset.Seconds + (offset.Minutes + (offset.Hours + offset.Days * 24) * 60) * 60) * 1000;
            };

            syscalls.maTime = delegate()
            {
                return (int)Util.ToUnixTimeUtc(System.DateTime.Now);
            };

            syscalls.maLocalTime = delegate()
            {
                return (int)Util.ToUnixTime(System.DateTime.Now);
            };

            syscalls.maCreatePlaceholder = delegate()
            {
                Resource res = new Resource(null, MoSync.Constants.RT_PLACEHOLDER, true);
                return runtime.AddResource(res);
            };

            syscalls.maDestroyPlaceholder = delegate(int res)
            {
                if (!runtime.GetResource(0, res).IsDynamicPlaceholder())
                    MoSync.Util.CriticalError("maDestroyPlaceholder can only be used on handles created by maCreatePlaceholder.");
                runtime.RemoveResource(res);
            };

            syscalls.maFindLabel = delegate(int _name)
            {
                String name = core.GetDataMemory().ReadStringAtAddress(_name);
                int res;
                if (runtime.mLabels.TryGetValue(name, out res))
                    return res;
                else
                    return -1;
            };

            syscalls.maResetBacklight = delegate()
            {
            };

            syscalls.maVibrate = delegate(int _ms)
            {
                if (mVibrateController == null)
                    mVibrateController = Microsoft.Devices.VibrateController.Default;

                if (_ms < 0)
                    return _ms;
                else if (_ms == 0)
                    mVibrateController.Stop();
                else
                    mVibrateController.Start(TimeSpan.FromMilliseconds(_ms));

                return 0;
            };

            syscalls.maLoadProgram = delegate(int _data, int _reload)
            {
            #if REBUILD
                throw new Exception("maLoadProgram not available in rebuild mode");
            #else
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                //Memory mem = (Memory)res.GetInternalObject();
                Stream mem = (Stream)res.GetInternalObject();
                MoSync.Machine.SetLoadProgram(mem, _reload != 0);
                throw new Util.ExitException(0);
            #endif
            };
        }
开发者ID:sanyaade-embedded-systems,项目名称:MoSync,代码行数:94,代码来源:MoSyncMiscModule.cs

示例5: Init


//.........这里部分代码省略.........
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    canvas.Background = mVideoBrush;
                });

                return 0;
            };

            ioctls.maCameraSelect = delegate(int _cameraNumber)
            {
                CameraType cameraType = CameraType.Primary;
                if(_cameraNumber == MoSync.Constants.MA_CAMERA_CONST_BACK_CAMERA)
                {
                    cameraType = CameraType.Primary;
                }
                else if(_cameraNumber == MoSync.Constants.MA_CAMERA_CONST_FRONT_CAMERA)
                {
                    cameraType = CameraType.FrontFacing;
                }

                if(mCamera==null || mCamera.CameraType != cameraType)
                {
                    mCamera = new PhotoCamera(cameraType);
                    if(mVideoBrush == null)
                        mVideoBrush = new VideoBrush();
                    mVideoBrush.SetSource(mCamera);
                }

                return 0;
            };

            ioctls.maCameraNumber = delegate()
            {
                // front facing and back facing is the standard I believe.
                return 2;
            };

            ioctls.maCameraSnapshot = delegate(int _formatIndex, int _placeHolder)
            {
                AutoResetEvent are = new AutoResetEvent(false);

                System.Windows.Size dim;
                if (GetCameraFormat(_formatIndex, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                mCamera.Resolution = dim;

                if (mCameraSnapshotDelegate != null)
                    mCamera.CaptureImageAvailable -= mCameraSnapshotDelegate;
                mCameraSnapshotDelegate = delegate(object o, ContentReadyEventArgs args)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, _placeHolder);
                        Stream data = args.ImageStream;
                        Memory dataMem = new Memory((int)data.Length);
                        dataMem.WriteFromStream(0, data, (int)data.Length);
                        res.SetInternalObject(dataMem);
                    });
                    are.Set();
                };

                mCamera.CaptureImageAvailable += mCameraSnapshotDelegate;

                mCamera.CaptureImage();

                are.WaitOne();
                return 0;
            };

            ioctls.maCameraSetProperty = delegate(int _property, int _value)
            {
                return 0;
            };

            ioctls.maCameraSelect = delegate(int _camera)
            {
                return 0;
            };

            ioctls.maCameraGetProperty = delegate(int _property, int _value, int _bufSize)
            {
                String property = core.GetDataMemory().ReadStringAtAddress(_property);

                if (property.Equals(MoSync.Constants.MA_CAMERA_MAX_ZOOM))
                {
                    core.GetDataMemory().WriteStringAtAddress(
                        _value,
                        "0",
                        _bufSize);
                }

                return 0;
            };

            ioctls.maCameraRecord = delegate(int _stopStartFlag)
            {
                return 0;
            };
        }
开发者ID:patrickbroman,项目名称:MoSync,代码行数:101,代码来源:MoSyncCameraModule.cs

示例6: Init

        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            // maybe use some pretty reflection mechanism to find all syscall implementations here..
            syscalls.maCheckInterfaceVersion = delegate(int hash)
            {
                if (MoSync.Constants.MoSyncHash != (uint)hash)
                    MoSync.Util.CriticalError("Invalid hash!");
                return hash;
            };

            syscalls.maPanic = delegate(int code, int str)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(str);
                MoSync.Util.CriticalError(message + "\ncode: " + code);
            };

            syscalls.maExit = delegate(int res)
            {
                mCore.Stop();
            };

            DateTime startDate = System.DateTime.Now;
            syscalls.maGetMilliSecondCount = delegate()
            {
                System.TimeSpan offset = (System.DateTime.Now - startDate);

                return offset.Milliseconds + (offset.Seconds + (offset.Minutes + (offset.Hours + offset.Days * 24) * 60) * 60) * 1000;
            };

            syscalls.maTime = delegate()
            {
                return (int)Util.ToUnixTimeUtc(System.DateTime.Now);
            };

            syscalls.maLocalTime = delegate()
            {
                return (int)Util.ToUnixTime(System.DateTime.Now);
            };

            syscalls.maCreatePlaceholder = delegate()
            {
                Resource res = new Resource(null, MoSync.Constants.RT_PLACEHOLDER, true);
                return runtime.AddResource(res);
            };

            syscalls.maDestroyPlaceholder = delegate(int res)
            {
                if (!runtime.GetResource(0, res).IsDynamicPlaceholder())
                    MoSync.Util.CriticalError("maDestroyPlaceholder can only be used on handles created by maCreatePlaceholder.");
                runtime.RemoveResource(res);
            };

            syscalls.maFindLabel = delegate(int _name)
            {
                String name = core.GetDataMemory().ReadStringAtAddress(_name);
                int res;
                if (runtime.mLabels.TryGetValue(name, out res))
                    return res;
                else
                    return -1;
            };

            /*
             * PhoneApplicationService.Current.UserIdleDetectionMode
             * Disabling this will stop the screen from timing out and locking.
             * Discussion: this needs to be re-enabled for the backlight to work
             *             so an maStartBacklight should be needed for WP7;
             *             what about maToggleBacklight(bool)?
             *
             * We have maWakeLock instead on Windows Phone, Android, iOS.
             */
            syscalls.maResetBacklight = delegate()
            {
            };

            syscalls.maVibrate = delegate(int _ms)
            {
                if (mVibrateController == null)
                    mVibrateController = Microsoft.Devices.VibrateController.Default;

                // more than 5 seconds aren't allowed..
                if (_ms > 5000)
                    _ms = 5000;

                if (_ms < 0)
                    return _ms;
                else if (_ms == 0)
                    mVibrateController.Stop();
                else
                    mVibrateController.Start(TimeSpan.FromMilliseconds(_ms));

                return 1;
            };

            syscalls.maLoadProgram = delegate(int _data, int _reload)
            {
            #if REBUILD
                throw new Exception("maLoadProgram not available in rebuild mode");
            #elif !LIB
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
//.........这里部分代码省略.........
开发者ID:nagyist,项目名称:MoSync-MoSync,代码行数:101,代码来源:MoSyncMiscModule.cs

示例7: Init

        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            SystemPropertyManager.mSystemPropertyProviders.Clear();

            // maybe use some pretty reflection mechanism to find all syscall implementations here..
            syscalls.maCheckInterfaceVersion = delegate(int hash)
            {
                if (MoSync.Constants.MoSyncHash != (uint)hash)
                    MoSync.Util.CriticalError("Invalid hash!");
                return hash;
            };

            syscalls.maPanic = delegate(int code, int str)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(str);
                MoSync.Util.CriticalError(message + "\ncode: " + code);
            };

            syscalls.maExit = delegate(int res)
            {
                MoSync.Util.Exit(res);
            };

            DateTime startDate = System.DateTime.Now;
            syscalls.maGetMilliSecondCount = delegate()
            {
                System.TimeSpan offset = (System.DateTime.Now - startDate);

                return offset.Milliseconds + (offset.Seconds + (offset.Minutes + (offset.Hours + offset.Days * 24) * 60) * 60) * 1000;
            };

            syscalls.maTime = delegate()
            {
                return (int)Util.ToUnixTimeUtc(System.DateTime.Now);
            };

            syscalls.maLocalTime = delegate()
            {
                return (int)Util.ToUnixTime(System.DateTime.Now);
            };

            syscalls.maCreatePlaceholder = delegate()
            {
                return runtime.AddResource(new Resource(null, MoSync.Constants.RT_PLACEHOLDER));
            };

            syscalls.maFindLabel = delegate(int _name)
            {
                String name = core.GetDataMemory().ReadStringAtAddress(_name);
                int res;
                if (runtime.mLabels.TryGetValue(name, out res))
                    return res;
                else
                    return -1;
            };

            syscalls.maResetBacklight = delegate()
            {
            };

            syscalls.maSoundPlay = delegate(int _sound_res, int _offset, int _size)
            {
                // not implemented, but I don't wanna throw exceptions.
                return -1;
            };

            syscalls.maLoadProgram = delegate(int _data, int _reload)
            {
            #if REBUILD
                throw new Exception("maLoadProgram not available in rebuild mode");
            #else
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                Memory mem = (Memory)res.GetInternalObject();
                MoSync.Machine.SetLoadProgram(mem.GetStream(), _reload != 0);
                throw new Util.ExitException(0);
            #endif
            };
        }
开发者ID:asamuelsson,项目名称:MoSync,代码行数:78,代码来源:MoSyncMiscModule.cs

示例8: Init

        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            mRuntime = runtime;

            ioctls.maOpenGLInitFullscreen = delegate(int _glApi)
            {
                if (_glApi != MoSync.Constants.MA_GL_API_GL1)
                    return MoSync.Constants.MA_GL_INIT_RES_ERROR;

                Syscalls syscalls = runtime.GetSyscalls();
                mOldUpdateScreenImplementation = syscalls.maUpdateScreen;

                syscalls.maUpdateScreen = delegate()
                {
                    if (maUpdateScreenAction != null)
                        maUpdateScreenAction();
                };

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    // GamePage must always exist for fullscreen apps to work.
                    if (((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri("/GamePage.xaml", UriKind.Relative)))
                    {
                    }
                });

                return MoSync.Constants.MA_GL_INIT_RES_OK;
            };

            ioctls.maOpenGLCloseFullscreen = delegate()
            {

                return MoSync.Constants.MA_GL_INIT_RES_OK;
            };

            ioctls.maOpenGLTexImage2D = delegate(int _res)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, _res);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();
                byte[] pixels = src.ToByteArray();
                mGL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, src.PixelWidth, src.PixelHeight, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixels, 0);
                return MoSync.Constants.MA_GL_TEX_IMAGE_2D_OK;
            };

            ioctls.maOpenGLTexSubImage2D = delegate(int _res)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, _res);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();
                byte[] pixels = src.ToByteArray();
                mGL.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, src.PixelWidth, src.PixelHeight, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixels, 0);
                return MoSync.Constants.MA_GL_TEX_IMAGE_2D_OK;
            };

            ioctls.glViewport = delegate(int _x, int _y, int _w, int _h)
            {
                mGL.glViewport(_x, _y, _w, _h);
                return 0;
            };

            ioctls.glGetError = delegate()
            {
                int err = mGL.glGetError();
                if (err != GL.GL_NO_ERROR)
                {
                    int a = 2;
                    //err = GL.GL_NO_ERROR;
                }
                return err;
            };

            ioctls.glGetStringHandle = delegate(int _name)
            {

                String str = mGL.glGetString(_name);
                char[] data = str.ToCharArray();
                byte[] bytes = new byte[data.Length + 1];
                bytes[data.Length] = 0;
                for (int i = 0; i < data.Length; i++)
                {
                    bytes[i] = (byte)data[i];
                }

                return runtime.AddResource(new Resource(new System.IO.MemoryStream(bytes), MoSync.Constants.RT_BINARY, true));
            };

            ioctls.glMatrixMode = delegate(int mode)
            {
                mGL.glMatrixMode(mode);  return 0;
            };

            ioctls.glPushMatrix = delegate()
            {
                mGL.glPushMatrix(); return 0;
            };

            ioctls.glPopMatrix = delegate()
            {
                mGL.glPopMatrix(); return 0;
            };

//.........这里部分代码省略.........
开发者ID:ronald132,项目名称:MoSync,代码行数:101,代码来源:MoSyncOpenGLESModule.cs

示例9: Init


//.........这里部分代码省略.........
             * Returns the number of available Camera on the device.
             */
            ioctls.maCameraNumber = delegate()
            {
                if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) && PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                    return 2;
                else if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) || PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                    return 1;
                return 0;
            };

            /**
             * Captures an image and stores it as a new data object in the
             * supplied placeholder.
             * @param _formatIndex int the required format.
             * @param _placeHolder int the placeholder used for storing the image.
             */
            ioctls.maCameraSnapshot = delegate(int _formatIndex, int _placeHolder)
            {
                AutoResetEvent are = new AutoResetEvent(false);

                System.Windows.Size dim;
                if (GetCameraFormat(_formatIndex, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                mCamera.Resolution = dim;

                if (mCameraSnapshotDelegate != null)
                    mCamera.CaptureImageAvailable -= mCameraSnapshotDelegate;
                mCameraSnapshotDelegate = delegate(object o, ContentReadyEventArgs args)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, _placeHolder);
                        Stream data = args.ImageStream;
                        MemoryStream dataMem = new MemoryStream((int)data.Length);
                        MoSync.Util.CopySeekableStreams(data, 0, dataMem, 0, (int)data.Length);
                        res.SetInternalObject(dataMem);
                    });
                    are.Set();
                };

                mCamera.CaptureImageAvailable += mCameraSnapshotDelegate;

                mCamera.CaptureImage();

                are.WaitOne();
                return 0;
            };

            /**
             * Sets the property represented by the string situated at the
             * _property address with the value situated at the _value address.
             * @param _property int the property name address
             * @param _value int the value address
             *
             * Note: the fallowing properties are not available on windows phone
             *      MA_CAMERA_FOCUS_MODE, MA_CAMERA_IMAGE_FORMAT, MA_CAMERA_ZOOM,
             *      MA_CAMERA_MAX_ZOOM.
             */
            ioctls.maCameraSetProperty = delegate(int _property, int _value)
            {
                // if the camera is not initialized, we cannot access any of its properties
                if (!isCameraInitialized)
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
开发者ID:NiklasNummelin,项目名称:MoSync,代码行数:67,代码来源:MoSyncCameraModule.cs

示例10: Init


//.........这里部分代码省略.........
            syscalls.maFillTriangleStrip = delegate(int points, int count)
            {

                int[] xcoords = new int[count];
                int[] ycoords = new int[count];

                for (int i = 0; i < count; i++)
                {
                    xcoords[i] = core.GetDataMemory().ReadInt32(points + i * 8 + MoSync.Struct.MAPoint2d.x);
                    ycoords[i] = core.GetDataMemory().ReadInt32(points + i * 8 + MoSync.Struct.MAPoint2d.y);
                }

                for (int i = 2; i < count; i++)
                {
                    mCurrentDrawTarget.FillTriangle(
                        xcoords[i - 2], ycoords[i - 2],
                        xcoords[i - 1], ycoords[i - 1],
                        xcoords[i - 0], ycoords[i - 0],
                        (int)mCurrentColor);
                }
            };

            syscalls.maSetDrawTarget = delegate(int drawTarget)
            {
                int oldDrawTarget = mCurrentDrawTargetIndex;
                if (drawTarget == mCurrentDrawTargetIndex) return oldDrawTarget;
                if (drawTarget == MoSync.Constants.HANDLE_SCREEN)
                {
                    mCurrentDrawTarget = mBackBuffer;
                    mCurrentDrawTargetIndex = drawTarget;
                    return oldDrawTarget;
                }

                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, drawTarget);
                mCurrentDrawTarget = (WriteableBitmap)res.GetInternalObject();
                mCurrentDrawTargetIndex = drawTarget;
                return oldDrawTarget;
            };

            syscalls.maGetScrSize = delegate()
            {
                return MoSync.Util.CreateExtent(mBackBuffer.PixelWidth, mBackBuffer.PixelHeight);
            };

            syscalls.maGetImageSize = delegate(int handle)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, handle);
                BitmapSource src = (BitmapSource)res.GetInternalObject();
                if (src == null)
                    MoSync.Util.CriticalError("maGetImageSize used with an invalid image resource.");
                int w = 0, h = 0;

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    w = src.PixelWidth;
                    h = src.PixelHeight;
                });

                return MoSync.Util.CreateExtent(w, h);
            };

            syscalls.maDrawImage = delegate(int image, int left, int top)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, image);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();
                Rect srcRect = new Rect(0, 0, src.PixelWidth, src.PixelHeight);
开发者ID:ronald132,项目名称:MoSync,代码行数:67,代码来源:MoSyncGraphicsModule.cs

示例11: Init


//.........这里部分代码省略.........
             * Returns the number of available Camera on the device.
             */
            ioctls.maCameraNumber = delegate()
            {
                if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) && PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                    return 2;
                else if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) || PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                    return 1;
                return 0;
            };

            /**
             * Captures an image and stores it as a new data object in the
             * supplied placeholder.
             * @param _formatIndex int the required format.
             * @param _placeHolder int the placeholder used for storing the image.
             */
            ioctls.maCameraSnapshot = delegate(int _formatIndex, int _placeHolder)
            {
                AutoResetEvent are = new AutoResetEvent(false);

                System.Windows.Size dim;
                if (GetCameraFormat(_formatIndex, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                mCamera.Resolution = dim;

                if (mCameraSnapshotDelegate != null)
                    mCamera.CaptureImageAvailable -= mCameraSnapshotDelegate;
                mCameraSnapshotDelegate = delegate(object o, ContentReadyEventArgs args)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, _placeHolder);

                        Stream data = null;
                        try
                        {
                            // as the camera always takes a snapshot in landscape left orientation,
                            // we need to rotate the resulting image 90 degrees for a current PortraitUp orientation
                            // and 180 degrees for a current LandscapeRight orientation
                            int rotateAngle = 0;
                            if (currentPage.Orientation == PageOrientation.PortraitUp)
                            {
                                rotateAngle = 90;

                            }
                            else if (currentPage.Orientation == PageOrientation.LandscapeRight)
                            {
                                rotateAngle = 180;
                            }
                            // if the current page is in a LandscapeLeft orientation, the orientation angle will be 0
                            data = RotateImage(args.ImageStream, rotateAngle);
                        }
                        catch
                        {
                            // the orientation angle was not a multiple of 90 - we keep the original image
                            data = args.ImageStream;
                        }
                        MemoryStream dataMem = new MemoryStream((int)data.Length);
                        MoSync.Util.CopySeekableStreams(data, 0, dataMem, 0, (int)data.Length);
                        res.SetInternalObject(dataMem);
                    });
                    are.Set();
                };
开发者ID:milesm,项目名称:MoSync,代码行数:66,代码来源:MoSyncCameraModule.cs

示例12: Init

        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            syscalls.memset = delegate(int dst, int val, int num)
            {
                core.GetDataMemory().FillRange(dst, (byte)val, num);
                return dst;
            };

            syscalls.memcpy = delegate(int dst, int src, int num)
            {
                core.GetDataMemory().WriteMemoryAtAddress(dst, core.GetDataMemory(), src, num);
                return dst;
            };

            syscalls.strcpy = delegate(int dst, int src)
            {
                byte[] mem = core.GetDataMemory().GetData();
                int origDst = dst;
                src--;
                do
                {
                    src++;
                    mem[dst] = mem[src];
                    dst++;
                } while (mem[src] != 0);
                return origDst;
            };

            syscalls.strcmp = delegate(int str1, int str2)
            {
                byte[] mem = core.GetDataMemory().GetData();
                while (mem[str1] != 0 && mem[str1] == mem[str2])
                {
                    str1++;
                    str2++;
                }
                return (mem[str1] - mem[str2]);
            };

            syscalls.maCreateData = delegate(int placeholder, int size)
            {
                //Memory mem = null;
                MemoryStream mem = null;
                try
                {
                    //mem = new Memory(size);
                    mem = new MemoryStream(size);
                }
                catch (OutOfMemoryException e)
                {
                    MoSync.Util.Log(e);
                    return MoSync.Constants.RES_OUT_OF_MEMORY;
                }

                Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, placeholder);
                res.SetInternalObject(mem);
                res.SetResourceType(MoSync.Constants.RT_BINARY);
                return MoSync.Constants.RES_OK;
            };

            syscalls.maWriteData = delegate(int data, int src, int offset, int size)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, data);
                Stream mem = (Stream)res.GetInternalObject();
                mem.Seek(offset, SeekOrigin.Begin);
                mem.Write(core.GetDataMemory().GetData(), src, size);
                //mem.WriteMemoryAtAddress(offset, core.GetDataMemory(), src, size);
            };

            syscalls.maReadData = delegate(int data, int dst, int offset, int size)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, data);
                //Memory mem = (Memory)res.GetInternalObject();
                Stream mem = (Stream)res.GetInternalObject();
                mem.Seek(offset, SeekOrigin.Begin);
                mem.Read(core.GetDataMemory().GetData(), dst, size);
                //core.GetDataMemory().WriteMemoryAtAddress(dst, mem, offset, size);
            };

            syscalls.maGetDataSize = delegate(int data)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, data);
                //Memory mem = (Memory)res.GetInternalObject();
                Stream mem = (Stream)res.GetInternalObject();
                //return mem.GetSizeInBytes();
                return (int)mem.Length;
            };

            syscalls.maCopyData = delegate(int _params)
            {
                throw new Exception("maCopyData not implemented");
            };
        }
开发者ID:patrickbroman,项目名称:MoSync,代码行数:93,代码来源:MoSyncMemoryModule.cs

示例13: Init

        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            runtime.RegisterCleaner(delegate()
            {
                foreach(KeyValuePair<int, Connection> p in mConnections) {
                    p.Value.close();
                }
                mConnections.Clear();
            });

            mResultHandler = delegate(int handle, int connOp, int result)
            {
                Memory evt = new Memory(4 * 4);
                evt.WriteInt32(MAEvent_type, MoSync.Constants.EVENT_TYPE_CONN);
                evt.WriteInt32(MAConnEventData_handle, handle);
                evt.WriteInt32(MAConnEventData_opType, connOp);
                evt.WriteInt32(MAConnEventData_result, result);
                runtime.PostEvent(new Event(evt));
            };

            syscalls.maConnect = delegate(int _url)
            {
                String url = core.GetDataMemory().ReadStringAtAddress(_url);
                Uri uri = new Uri(url);
                Connection c;
                if (uri.Scheme.Equals("socket"))
                {
                    c = new SocketConnection(uri, mNextConnHandle);
                }
                else if (uri.Scheme.Equals("http") || uri.Scheme.Equals("https"))
                {
                    c = new WebRequestConnection(uri, mNextConnHandle, MoSync.Constants.HTTP_GET);
                }
                else
                {
                    return MoSync.Constants.CONNERR_GENERIC;
                }

                c.connect(mResultHandler);
                mConnections.Add(mNextConnHandle, c);
                return mNextConnHandle++;
            };

            syscalls.maConnClose = delegate(int _conn)
            {
                Connection c = mConnections[_conn];
                c.close();
                mConnections.Remove(_conn);
            };

            syscalls.maConnGetAddr = delegate(int _conn, int _addr)
            {
                Connection c = mConnections[_conn];
                return c.getAddr(_addr);
            };

            syscalls.maConnRead = delegate(int _conn, int _dst, int _size)
            {
                Connection c = mConnections[_conn];
                c.recv(core.GetDataMemory().GetData(), _dst, _size, mResultHandler);
            };

            DataDelegate dataDelegate = delegate(int _conn, int _data,
                CommDelegate cd)
            {
                Connection c = mConnections[_conn];
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                Memory mem = (Memory)res.GetInternalObject();
                runtime.SetResourceRaw(_data, Resource.Flux);
                cd(c, mem.GetData(),
                    delegate(int handle, int connOp, int result)
                    {
                        runtime.SetResourceRaw(_data, res);
                        mResultHandler(handle, connOp, result);
                    });
            };

            syscalls.maConnReadToData = delegate(int _conn, int _data, int _offset, int _size)
            {
                dataDelegate(_conn, _data,
                    delegate(Connection c, byte[] buf, ResultHandler rh)
                    {
                        c.recv(buf, _offset, _size, rh);
                    });
            };

            syscalls.maConnWrite = delegate(int _conn, int _src, int _size)
            {
                Connection c = mConnections[_conn];
                c.write(core.GetDataMemory().GetData(), _src, _size, mResultHandler);
            };

            syscalls.maConnWriteFromData = delegate(int _conn, int _data, int _offset, int _size)
            {
                dataDelegate(_conn, _data,
                    delegate(Connection c, byte[] buf, ResultHandler rh)
                    {
                        c.write(buf, _offset, _size, rh);
                    });
            };
//.........这里部分代码省略.........
开发者ID:asamuelsson,项目名称:MoSync,代码行数:101,代码来源:MoSyncCommunicationsModule.cs

示例14: OnAlertMessageBoxClosed


//.........这里部分代码省略.........
                            MessageBox.Show(message, title, MessageBoxButton.OK);

                            // Since the only way to exit the messageBox is by pressing OK there is no
                            // need for a result object.

                            Memory eventData = new Memory(8);
                            const int MAWidgetEventData_eventType = 0;
                            const int MAWidgetEventData_eventArgumentValue = 4;

                            //write 1 down since the buttone clicked is the first one
                            eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.EVENT_TYPE_ALERT);
                            eventData.WriteInt32(MAWidgetEventData_eventArgumentValue, 1);
                            //Posting a CustomEvent
                            mRuntime.PostEvent(new Event(eventData));
                        }
                    );
                }

                return 0;
            };

            ioctls.maGetSystemProperty = delegate(int _key, int _buf, int _size)
            {
                String key = core.GetDataMemory().ReadStringAtAddress(_key);
                String value = MoSync.SystemPropertyManager.GetSystemProperty(key);
                if (value == null)
                    return -2;
                if (value.Length + 1 <= _size)
                {
                    if(key.Equals("mosync.network.type"))
                    {
                        /**
                         * This code converts the result return by the GetSystemProperty
                         * for the "mosync.network.type" key to be supported by the current
                         * MoSync SDK 3.0
                         */
                        if (value.ToLower().Contains("wireless"))
                        {
                            value = "wifi";
                        }
                        else if(value.ToLower().Contains("ethernet"))
                        {
                            value = "ethernet";
                        }
                        else if(value.ToLower().Contains("mobilebroadbandgsm"))
                        {
                            value = "2g";
                        }
                        else if (value.ToLower().Contains("mobilebroadbandcdma"))
                        {
                            value = "3g";
                        }
                    }
                    core.GetDataMemory().WriteStringAtAddress(_buf, value, _size);
                }
                return value.Length + 1;
            };

            ioctls.maWakeLock = delegate(int flag)
            {
                if (MoSync.Constants.MA_WAKE_LOCK_ON == flag)
                {
                    Microsoft.Phone.Shell.PhoneApplicationService.Current.
                        UserIdleDetectionMode =
                            Microsoft.Phone.Shell.IdleDetectionMode.Enabled;
                }
                else
                {
                    Microsoft.Phone.Shell.PhoneApplicationService.Current.
                        UserIdleDetectionMode =
                            Microsoft.Phone.Shell.IdleDetectionMode.Disabled;
                }
                return 1;
            };

            // validates image input data and dispaches a delegate to save the image to camera roll
            ioctls.maSaveImageToDeviceGallery = delegate(int imageHandle, int imageNameAddr)
            {
                int returnCode = MoSync.Constants.MA_MEDIA_RES_IMAGE_EXPORT_FAILED;

                //Get the resource with the specified handle
                Resource res = mRuntime.GetResource(MoSync.Constants.RT_IMAGE, imageHandle);
                String imageName = mCore.GetDataMemory().ReadStringAtAddress(imageNameAddr);

                if ( (null != res) && !String.IsNullOrEmpty(imageName))
                {
                    object[] myArray = new object[3];
                    myArray[0] = imageHandle;
                    myArray[1] = imageName;
                    myArray[2] = res;

                    Deployment.Current.Dispatcher.BeginInvoke(
                        new Delegate_SaveImageToCameraRoll(SaveImageToCameraRoll),myArray);

                    returnCode = MoSync.Constants.MA_MEDIA_RES_OK;
                }

                return returnCode;
            };
        }
开发者ID:nagyist,项目名称:MoSync-MoSync,代码行数:101,代码来源:MoSyncMiscModule.cs

示例15: Init

        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            #if false
            mAudioInstanceUpdater = new AudioInstanceUpdater(mAudioInstances);
            Thread thread = new Thread(new ThreadStart(mAudioInstanceUpdater.Loop));
            thread.Start();
            #endif
            ioctls.maAudioDataCreateFromURL = delegate(int _mime, int _url, int _flags)
            {
                int ret = MoSync.Constants.MA_AUDIO_ERR_GENERIC;

                try
                {
                    String url = core.GetDataMemory().ReadStringAtAddress(_url);
                    IAudioData ad = Audio.FromUrlOrFilePath(url, (_flags & MoSync.Constants.MA_AUDIO_DATA_STREAM) != 0);
                    lock (mAudioData)
                    {
                        mAudioData.Add(ad);
                        ret = mAudioData.Count - 1;
                    }
                }
                catch (MoSync.Util.ReturnValueException rve)
                {
                    return rve.result;
                }
                catch (Exception)
                {
                    return MoSync.Constants.MA_AUDIO_ERR_GENERIC;
                }

                return ret;
            };

            ioctls.maAudioDataCreateFromResource = delegate(int _mime, int _data, int _offset, int _length, int _flags)
            {
                int ret = MoSync.Constants.MA_AUDIO_ERR_GENERIC;
                try
                {
                    Resource audiores = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                    BoundedStream s = new BoundedStream((Stream)audiores.GetInternalObject(), _offset, _length);
                    IAudioData ad = Audio.FromStream(s, (_flags & MoSync.Constants.MA_AUDIO_DATA_STREAM) != 0);
                    lock (mAudioData)
                    {
                        mAudioData.Add(ad);
                        ret = mAudioData.Count - 1;
                    }
                }
                catch (MoSync.Util.ReturnValueException rve)
                {
                    return rve.result;
                }
                catch (Exception)
                {
                    return MoSync.Constants.MA_AUDIO_ERR_GENERIC;
                }

                return ret;
            };

            ioctls.maAudioDataDestroy = delegate(int _audioData)
            {
                try
                {
                    lock (mAudioData)
                    {
                        IAudioData ad = mAudioData[_audioData];
                        ad.Dispose();
                        mAudioData[_audioData] = null;
                    }
                }
                catch (MoSync.Util.ReturnValueException rve)
                {
                    return rve.result;
                }
                catch (Exception)
                {
                    return MoSync.Constants.MA_AUDIO_ERR_GENERIC;
                }

                return MoSync.Constants.MA_AUDIO_ERR_OK;
            };

            ioctls.maAudioPrepare = delegate(int _audioInstance, int async)
            {
                try
                {
                    lock (mAudioInstances)
                    {

                        IAudioInstance ad = mAudioInstances[_audioInstance];
                        if (async == 0)
                        {
                            ad.Prepare(null);
                        }
                        else
                        {
                            ad.Prepare(() =>
                                {
                                    // Send initialized event.
                                    MoSync.Memory eventData = new MoSync.Memory(8);
//.........这里部分代码省略.........
开发者ID:ronald132,项目名称:MoSync,代码行数:101,代码来源:MoSyncAudioModule.cs


注:本文中的Runtime.GetResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。