コード例 #1
0
 public ActionResult Edit([Bind(Include = "IsmDeviceId,DeviceId,LocationId,SoftwareId,HardwareId")] IsmDevice ismDevice)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ismDevice).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.HardwareId = new SelectList(db.Hardware, "HardwareId", "Board", ismDevice.HardwareId);
     ViewBag.LocationId = new SelectList(db.Locations, "LocationId", "Country", ismDevice.LocationId);
     ViewBag.SoftwareId = new SelectList(db.Software, "SoftwareId", "SoftwareVersion", ismDevice.SoftwareId);
     return(View(ismDevice));
 }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "ContactId,FirstName,LastName,EmailAddress,PhoneNumber")] Contact contact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contact).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(contact));
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "HardwareId,Board,Camera")] Hardware hardware)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hardware).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hardware));
 }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "CommandId,Cmd,Timestamp,CommandStatus,IsmDeviceId")] Command command)
 {
     if (ModelState.IsValid)
     {
         db.Entry(command).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IsmDeviceId = new SelectList(db.IsmDevices, "IsmDeviceId", "DeviceId", command.IsmDeviceId);
     return(View(command));
 }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "LocationId,Country,City,PostalCode,Street,StreetNumber,ContactId")] Location location)
 {
     if (ModelState.IsValid)
     {
         db.Entry(location).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ContactId = new SelectList(db.Contacts, "ContactId", "FirstName", location.ContactId);
     return(View(location));
 }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "FilamentDataId,Time,FC,FL,H1,H2,H3,H4,H5,H6,H7,H8,H9,H10,IsmDeviceId,DeviceId,BlobUriImg,BlobUriColoredImg")] FilamentData filamentData)
 {
     if (ModelState.IsValid)
     {
         db.Entry(filamentData).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IsmDeviceId = new SelectList(db.IsmDevices, "IsmDeviceId", "DeviceId", filamentData.IsmDeviceId);
     return(View(filamentData));
 }
コード例 #7
0
        public ActionResult Edit(int?id, [Bind(Include = "IsmDeviceId,DeviceId,LocationId,SoftwareId,HardwareId")] IsmDevice ismDevice)
        {
            // Check Device ID against a whitelist of values to prevent XSS
            if (!IsmIoTSettings.RegexHelper.Text.IsMatch(ismDevice.DeviceId))
            {
                return(HttpNotFound());
            }
            // Check that POST device ID is the same as ID parameter
            if (id == null || id != ismDevice.IsmDeviceId)
            {
                return(HttpNotFound());
            }
            //// Return error if device doesn't exist
            if (!db.IsmDevices.Any(d => d.IsmDeviceId == ismDevice.IsmDeviceId))
            {
                //if (db.IsmDevices.Find(ismDevice.IsmDeviceId) == null)
                return(HttpNotFound());
            }
            // Check that unchangeable data (that is, current software and device ID) has not been tampered with.
            if (!db.IsmDevices.Any(d =>
                                   d.IsmDeviceId == ismDevice.IsmDeviceId &&
                                   d.DeviceId.Equals(ismDevice.DeviceId) &&
                                   d.SoftwareId == ismDevice.SoftwareId))
            {
                ;
            }
            return(HttpNotFound());

            if (ModelState.IsValid)
            {
                db.Entry(ismDevice).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.HardwareId = new SelectList(db.Hardware, "HardwareId", "Board", ismDevice.HardwareId);
            ViewBag.LocationId = new SelectList(db.Locations, "LocationId", "Country", ismDevice.LocationId);
            ViewBag.SoftwareId = new SelectList(db.Releases, "SoftwareId", "SoftwareVersion", ismDevice.SoftwareId);
            return(View(ismDevice));
        }
コード例 #8
0
ファイル: WorkerRole.cs プロジェクト: leononame/ismcloud
        private static async Task ProcessCmdMessage(FeedbackRecord record)
        {
            using (var db = new IsmIoTPortalContext())
            {
                // Achtung .Substring(4), weil die ersten 3 Zeichen das Präfix "CMD" sind
                int CommandId = Convert.ToInt32(record.OriginalMessageId.Substring(4));   // Beim Senden des Commands wurde der Schlüssel des DB Eintrages als MessageId angegeben
                var entry     = db.Commands.Where(c => c.CommandId == CommandId).First(); // Es gibt natürlich nur ein DB Eintrag mit dem Schlüssel CommandId

                if (record.StatusCode == FeedbackStatusCode.Success)
                {
                    db.Entry(entry).Entity.CommandStatus = CommandStatus.SUCCESS;
                }
                else // Rejected,...
                {
                    db.Entry(entry).Entity.CommandStatus = CommandStatus.FAILURE;
                }

                db.Entry(entry).State = EntityState.Modified;
                db.SaveChanges();

                await signalRHelper.IsmDevicesIndexChangedTask();
            }
        }
コード例 #9
0
ファイル: WorkerRole.cs プロジェクト: leononame/ismcloud
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            // 1. Check if this is after restart and "MCR is installed" already
            //
            bool   mcrAlreadyInstalled = false;
            string line = "";

            try
            {
                using (IsmIoTPortalContext db = new IsmIoTPortalContext())
                {
                    ImagingProcessorWorkerInstance entry = null;
                    var queryResults = db.ImagingProcessorWorkerInstances.Where(e => e.RoleInstanceId == RoleEnvironment.CurrentRoleInstance.Id);
                    if (queryResults.Count() > 0)
                    {
                        entry = queryResults.First(); // Es gibt natürlich nur ein DB Eintrag mit dem Schlüssel RoleInstanceId
                    }
                    if (entry == null)                // First start of this Instance -> Create and add new DB entry
                    {
                        //
                        entry = new ImagingProcessorWorkerInstance();
                        entry.RoleInstanceId = RoleEnvironment.CurrentRoleInstance.Id;
                        entry.McrInstalled   = false;
                        entry.Timestamp      = DateTime.UtcNow;
                        db.ImagingProcessorWorkerInstances.Add(entry);
                        db.SaveChanges();
                        // mcrAlreadyInstalled is still false
                    }
                    else
                    {
                        if (entry.McrInstalled == true)
                        {
                            mcrAlreadyInstalled = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logfile.Get(logfile).fTextout(Logging.Fontcolors.RED, "{0} > Failed to use McrInstalled flag. <br>", DateTime.Now.ToString());
                Logfile.Get(logfile).fTextout(Logging.Fontcolors.RED, "{0} > Exception: {1} <br>", DateTime.Now.ToString(), ex.Message);
                Logfile.Get(logfile).Update();
                mcrAlreadyInstalled = false;
            }

            // *************DEBUG*****************
            mcrAlreadyInstalled = true; // DEBUG


            // 2. Poll the MCR Installation Log if mcrAlreadyInstalled == false
            //
            Stopwatch stopWatch = new Stopwatch();
            bool      timeout   = false;

            stopWatch.Start();
            while (!mcrAlreadyInstalled && true)
            {
                try
                {
                    // Timeout
                    if (stopWatch.Elapsed > TimeSpan.FromMinutes(30))
                    {
                        timeout = true;
                        break;
                    }

                    // Sleep
                    await Task.Delay(TimeSpan.FromMinutes(5));

                    if (!File.Exists(mcrlog))
                    {
                        continue;
                    }

                    line = File.ReadLines(mcrlog).Last();
                    if (!line.Contains("End - Successful"))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    // Probably file reading errors because the MCR installer uses the file
                    continue;
                }
            }


            //
            // MCR is installed now -->Set the flag in DB and Reboot
            if (!mcrAlreadyInstalled && timeout == false)
            {
                try
                {
                    using (IsmIoTPortalContext db = new IsmIoTPortalContext())
                    {
                        // Update DB entry and set the McrInstalled Flag to true
                        var entry = db.ImagingProcessorWorkerInstances.Where(e => e.RoleInstanceId == RoleEnvironment.CurrentRoleInstance.Id).First(); // // Es gibt natürlich nur ein DB Eintrag mit dem Schlüssel RoleInstanceId
                        db.Entry(entry).Entity.McrInstalled = true;
                        db.Entry(entry).Entity.Timestamp    = DateTime.UtcNow;
                        db.Entry(entry).State = EntityState.Modified;
                        db.SaveChanges();

                        // Restart Worker Role
                        // Update: Der User nach dem Startup Task darf wohl kein shuttdown ausführen --> benutze schtasks
                        //string stat = ExecuteCommandSync("shutdown /R /F");

                        // Mit schtasks
                        DateTime executionTime = DateTime.Now.Add(new TimeSpan(0, 1, 0));
                        string   date          = string.Format("{0}/{1}/{2}", executionTime.Month.ToString("d2"), executionTime.Day.ToString("d2"), executionTime.Year);
                        string   time          = string.Format("{0}:{1}", executionTime.Hour.ToString("d2"), executionTime.Minute.ToString("d2"));
                        string   cmd           = string.Format("schtasks /CREATE /TN RebootRoleInstance /SC ONCE /SD {0} /ST {1} /RL HIGHEST /RU scheduser /RP Qwer123 /TR \"shutdown /R /F\" /F", date, time);
                        string   stat          = ExecuteCommandSync(cmd);
                        Logfile.Get(logfile).fTextout(Logging.Fontcolors.RED, "{0} > {1} <br>", DateTime.Now.ToString(), stat);
                        Logfile.Get(logfile).Update();
                    }
                }
                catch (Exception ex)
                {
                    Logfile.Get(logfile).fTextout(Logging.Fontcolors.RED, "{0} > Failed writing to update McrInstalled flag and reboot. <br>", DateTime.Now.ToString());
                    Logfile.Get(logfile).fTextout(Logging.Fontcolors.RED, "{0} > Exception: {1} <br>", DateTime.Now.ToString(), ex.Message);
                    Logfile.Get(logfile).Update();
                }
            }
            // Timeout --> Write to log and do Not start Event Processor
            if (!mcrAlreadyInstalled && timeout == true)
            {
                Logfile.Get(logfile).fTextout(Logging.Fontcolors.RED, "{0} > Timeout occured during MCR Installation Polling. <br>", DateTime.Now.ToString());
                Logfile.Get(logfile).Update();
            }
            // Reboot and MCR is already installed --> Start Event Processor
            if (mcrAlreadyInstalled)
            {
                //
                // Create EventProcessorHost

                /*the iotHubD2cEndpoint in the example is the name of the device-to - cloud endpoint on your IoT hub.
                 * Technically, and IoT hub could have multiple endpoints that are compatible with Event Hubs.
                 * At this time the only Event Hubs - compatible endpoint is called "messages/events", so it is a fixed string. */
                string iotHubD2cEndpoint = "messages/events";
                string eventHubName      = CloudConfigurationManager.GetSetting("iotHubName"); //"IsmIoTHub";
                string consumerGroupName = EventHubConsumerGroup.DefaultGroupName;
                // Alternativ geht auch CurrentRoleInstance.Id (ist auch unique)
                //string eventProcessorHostName = Guid.NewGuid().ToString();

                string eventProcessorHostName = RoleEnvironment.CurrentRoleInstance.Id;
                // leaseContainerName-Parameter wie im scaled out event processing beispiel:
                // here it's using eventhub as lease name. but it can be specified as any you want.
                // if the host is having same lease name, it will be shared between hosts.
                // by default it is using eventhub name as lease name.
                eventProcessorHost = new EventProcessorHost(eventProcessorHostName,
                                                            iotHubD2cEndpoint,                                     // eigentlich steht hier der EventHub Name aber siehe Kommentar, bei IoTHubs ist hier der fixe string "messages/events" notwendig
                                                            consumerGroupName,
                                                                                                                   //iotHubConnectionString,
                                                            CloudConfigurationManager.GetSetting("ismiothub"),     //System.Configuration.ConfigurationSettings.AppSettings.Get("ismiothub"),
                                                                                                                   //EventProcessor.StorageConnectionString,
                                                            CloudConfigurationManager.GetSetting("ismiotstorage"), //System.Configuration.ConfigurationSettings.AppSettings.Get("ismiotstorage"),
                                                            eventHubName.ToLowerInvariant());

                factory = new EventProcessorFactory(logfile);
                await eventProcessorHost.RegisterEventProcessorFactoryAsync(factory);

                // Register EventProcessorHost
                Logfile.Get(logfile).fTextout("{0} > Registering EventProcessor... <br>", DateTime.Now.ToString());
                Logfile.Get(logfile).Update();

                // Ansatz ohne Factory. Hatte jedoch den Nachteil, dass man keine Referenz auf das EventProcessor Objekt
                // hat und somit z.B. keine Eventhandler registrieren konnte. Parameter an Konstruktor gigen ja auch nicht,
                // weil dieser niemals sichtbar aufgerufen wird bei dem Ansatz
                //eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>().Wait();
            }

            while (!cancellationToken.IsCancellationRequested)
            {
                await Task.Delay(TimeSpan.FromHours(1), cancellationToken);
            }
        }