Exemple #1
0
 static void OnAllocateUnixBuffer(IntPtr memoryBuffer, uint length, out Unix buffer)
 {
     var memory = _pool.Rent();
     unsafe
     {
         buffer = new Unix((IntPtr)memory.UnsafePointer, (uint)memory.Length);
     }
 }
 internal static int NonWindowsGetProcessParentPid(int pid)
 {
     return(IsMacOS ? Unix.NativeMethods.GetPPid(pid) : Unix.GetProcFSParentPid(pid));
 }
Exemple #3
0
 static void OnAllocateUnixBuffer(IntPtr memoryBuffer, uint length, out Unix buffer)
 {
     var memory = Marshal.AllocHGlobal((int)length);
     buffer = new Unix(memory, length);
 }
        // Platform methods prefixed NonWindows are:
        // - non-windows by the definition of the IsWindows method above
        // - here, because porting to Linux and other operating systems
        //   should not move the original Windows code out of the module
        //   it belongs to, so this way the windows code can remain in it's
        //   original source file and only the non-windows code has been moved
        //   out here
        // - only to be used with the IsWindows feature query, and only if
        //   no other more specific feature query makes sense

        internal static bool NonWindowsIsHardLink(ref IntPtr handle)
        {
            return(Unix.IsHardLink(ref handle));
        }
 internal static bool NonWindowsIsHardLink(FileSystemInfo fileInfo)
 {
     return(Unix.IsHardLink(fileInfo));
 }
Exemple #6
0
 public override ValueType ConvertToTotalValue(uint basis)
 {
     return(Unix.ToDateTime(basis));
 }
Exemple #7
0
 void OnMenuHelp(object sender, EventArgs args)
 {
     Unix.ShowUri(null, "ghelp:gbrainy",
                  Gdk.EventHelper.GetTime(new Gdk.Event(IntPtr.Zero)));
 }
Exemple #8
0
        static void OnAllocateUnixBuffer(IntPtr memoryBuffer, uint length, out Unix buffer)
        {
            var memory = Marshal.AllocHGlobal((int)length);

            buffer = new Unix(memory, length);
        }
Exemple #9
0
        public static void Copy(File modbusDevice, DeviceBase canDevice)
        {
            Record rec;
            UInt16 index;
            UInt32 var32;

            if (canDevice.DeviceType != DeviceType.KIP_BATTERY_POWER_v1)
            {
                throw new InvalidCastException("Требуется устройство CAN типа КИП-9811");
            }
            if (modbusDevice.Records[KIP9811Address.VisitingCard.DeviceType].Value !=
                (UInt16)DeviceType.KIP_BATTERY_POWER_v1)
            {
                throw new InvalidCastException("Требуется устройство modbus типа КИП-9811");
            }

            // Адреса, которые обрабатываются по особому
            UInt16[] exclusions = new ushort[] { 0x000A, 0x000B, 0x000C, 0x000E, 0x0014,
                                                 0x0019, 0x0020, 0x0024, 0x0025, 0x0026, 0x0036, 0x0037 };
            // Адреса, которые исключаются из обработки
            UInt16[] nothandled = new ushort[] { 0x0000, 0x0006, 0x0007, 0x0008, 0x0009,
                                                 0x000D, 0x000E };
            // Копируем данные
            foreach (UInt16 modbusAddress in _TableAddress.Keys)
            {
                // Исключаем из обработки адреса
                if (Exist(nothandled, modbusAddress))
                {
                    continue;
                }

                // Адреса для обработки особым способом,
                // так же пропускаем, их обработаем ниже
                if (Exist(exclusions, modbusAddress))
                {
                    continue;
                }

                // Получаем индекс объекта CAN-устройства
                index = _TableAddress[modbusAddress];
                // Копируем значение объекта в запись modbus
                modbusDevice.Records[modbusAddress].Value =
                    (UInt16)canDevice.ObjectDictionary[index].Value;
            }

            // Теперь обрабатываем сложные параметры
            // 0x0007
            //modbusDevice.Records[0x0007].Value = 0; //TODO Код производителя, всега неопределён
            // 0x000A
            modbusDevice.Records[0x000A].Value = Convert.ToUInt16(canDevice.NodeId);
            // 0x000B
            if (canDevice.Status == DeviceStatus.CommunicationError)
            {
                modbusDevice.Records[0x000B].Value = 0;
            }
            else
            {
                modbusDevice.Records[0x000B].Value = 1;
            }
            // 0x000C
            //modbusDevice.Records[0x000C].Value = 0; //TODO
            // 0x000E
            switch (canDevice.Status)
            {
            case DeviceStatus.CommunicationError:
            case DeviceStatus.ConfigurationError:
            case DeviceStatus.Stopped:
            {
                modbusDevice.Records[0x000E].Value =
                    (UInt16)DeviceStatus.Stopped;         // Stopped
                break;
            }

            case DeviceStatus.Operational:
            {
                modbusDevice.Records[0x000E].Value =
                    (UInt16)DeviceStatus.Operational;
                break;
            }

            case DeviceStatus.Preoperational:
            {
                modbusDevice.Records[0x000E].Value =
                    (UInt16)DeviceStatus.Preoperational;
                break;
            }

            default: { throw new NotSupportedException(); }
            }
            //0x0014 TODO
            //0x0019 TODO
            //0x0020 TODO
            //0x0024
            modbusDevice.Records[0x0024].Value = canDevice.ElectrodeArea;
            //0x0025, 0x0026
            var32 = (UInt32)canDevice.GetObject(_TableAddress[0x0025]);
            modbusDevice.Records[0x0025].Value = (UInt16)(var32 >> 16);
            var32 = (UInt32)canDevice.GetObject(_TableAddress[0x0026]);
            modbusDevice.Records[0x0026].Value = (UInt16)var32;
            //0x0036, 0x0037
            var32 = Unix.ToUnixTime((DateTime)canDevice.GetObject(_TableAddress[0x0036]));
            modbusDevice.Records[0x0036].Value = (UInt16)(var32 >> 16);
            var32 = Unix.ToUnixTime((DateTime)canDevice.GetObject(_TableAddress[0x0037]));
            unchecked
            {
                modbusDevice.Records[0x0037].Value = (UInt16)var32;
            }
            return;
        }
Exemple #10
0
 public static IntPtr error(bool useCLibrary = false)
 {
     return(useCLibrary ? BSD.dlerror() : Unix.dlerror());
 }
Exemple #11
0
 public static int close(IntPtr handle, bool useCLibrary = false)
 {
     return(useCLibrary ? BSD.dlclose(handle) : Unix.dlclose(handle));
 }
Exemple #12
0
 public static IntPtr sym(IntPtr handle, [NotNull] string name, bool useCLibrary = false)
 {
     return(useCLibrary ? BSD.dlsym(handle, name) : Unix.dlsym(handle, name));
 }
Exemple #13
0
 public static IntPtr open([CanBeNull] string fileName, SymbolFlag flags = SymbolFlag.RTLD_DEFAULT, bool useCLibrary = false)
 {
     return(useCLibrary ? BSD.dlopen(fileName, flags) : Unix.dlopen(fileName, flags));
 }
        public ActionResult Index(UploadModel uploadModel)
        {
            if (!ModelState.IsValid)
            {
                /*
                 * var errors = ModelState
                 *  .Where(x => x.Value.Errors.Count > 0)
                 *  .Select(x => new { x.Key, x.Value.Errors })
                 *  .ToArray();
                 */
                foreach (var _error in GetModelStateErrorsAsList(this.ModelState))
                {
                    ModelState.AddModelError("", _error.ErrorMessage);
                }
                return(View(uploadModel));
            }

            Torrent t;

            try
            {
                t = Torrent.Load(uploadModel.TorrentFile.InputStream);
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Invalid .torrent file.");
                return(View(uploadModel));
            }
            if (!t.IsPrivate)
            {
                ModelState.AddModelError("", "The torrent file needs to be marked as \"Private\" when you create the torrent.");
                return(View(uploadModel));
            }

            var TORRENT_DIR = TrackerSettings.TORRENT_DIRECTORY;
            var NFO_DIR     = TrackerSettings.NFO_DIRECTORY;

            using (var db = new OpenTrackerDbContext())
            {
                //
                var _torrentFilename = uploadModel.TorrentFile.FileName;
                if (!string.IsNullOrEmpty(uploadModel.TorrentName))
                {
                    _torrentFilename = uploadModel.TorrentName;
                }

                var cleanTorentFilename  = Regex.Replace(_torrentFilename, "[^A-Za-z0-9]", string.Empty);
                var finalTorrentFilename = string.Format("TEMP-{0}-{1}", DateTime.Now.Ticks, cleanTorentFilename);

                var _torrentPath = Path.Combine(TORRENT_DIR, string.Format("{0}.torrent", finalTorrentFilename));
                var _nfoPath     = Path.Combine(NFO_DIR, string.Format("{0}.nfo", finalTorrentFilename));
                uploadModel.NFO.SaveAs(_nfoPath);
                uploadModel.TorrentFile.SaveAs(_torrentPath);

                var infoHash    = t.InfoHash.ToString().Replace("-", string.Empty);
                var torrentSize = t.Files.Sum(file => file.Length);
                var numfiles    = t.Files.Count();
                var client      = t.CreatedBy;

                var torrent = new torrents
                {
                    categoryid        = uploadModel.CategoryId,
                    info_hash         = infoHash,
                    torrentname       = _torrentFilename.Replace(".torrent", string.Empty),
                    description       = uploadModel.Description,
                    description_small = uploadModel.SmallDescription,
                    added             = (int)Unix.ConvertToUnixTimestamp(DateTime.UtcNow),
                    numfiles          = numfiles,
                    size = torrentSize,
                    client_created_by = client,
                    owner             = new Core.Account.AccountInformation().UserId
                };
                db.AddTotorrents(torrent);
                db.SaveChanges();

                var _torrent = (from tor in db.torrents
                                where tor.info_hash == infoHash
                                select tor)
                               .Select(tor => new { tor.info_hash, tor.id })
                               .Take(1)
                               .FirstOrDefault();
                if (_torrent == null)
                {
                    // TODO: error logging etc. here
                }
                else
                {
                    System.IO.File.Move(_torrentPath, Path.Combine(TORRENT_DIR, string.Format("{0}.torrent", _torrent.id)));
                    System.IO.File.Move(_nfoPath, Path.Combine(NFO_DIR, string.Format("{0}.nfo", _torrent.id)));

                    var files = t.Files;
                    foreach (var tFile in files.Select(torrentFile => new torrents_files
                    {
                        torrentid = torrent.id,
                        filename = torrentFile.FullPath,
                        filesize = torrentFile.Length
                    }).OrderBy(torrentFile => torrentFile.filename))
                    {
                        db.AddTotorrents_files(tFile);
                    }
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Browse"));
            }
        }