示例#1
0
 public static void EnsureLoaded(this sw.FrameworkElement control)
 {
     ApplicationHandler.InvokeIfNecessary(() =>
     {
         if (!control.IsLoaded)
         {
             control.Dispatcher.Invoke(new Action(() => { }), sw.Threading.DispatcherPriority.ApplicationIdle, null);
         }
     });
 }
示例#2
0
        /// <summary>
        /// Construct a new LUIS subscription manager based on a Subscription Key.
        /// </summary>
        /// <param name="subscriptionKey">The subscription key of the LUIS account.</param>
        /// <param name="domain">String to represent the domain of the endpoint.</param>
        /// <param name="baseUri">Root URI for the service endpoint.</param>
        public LuisManager(string subscriptionKey, string domain = DEFAULT_DOMAIN, string baseUri = DEFAULT_BASE_URI)
        {
            if (string.IsNullOrEmpty(subscriptionKey))
            {
                throw new ArgumentNullException(nameof(subscriptionKey));
            }

            BASE_API_URL = string.Format(baseUri, domain);

            Apps = new ApplicationHandler(subscriptionKey, BASE_API_URL);
        }
示例#3
0
        public MyAppNode(NodeInfo identity, MyAppNodeConfiguration config) :
            base(identity, config)
        {
            var factory = new MyAppDataFactory(config.LoggerDelegate);

            _appRepo    = new MyAppDataRepo(factory.CreateMyAppData);
            _appHandler = new ApplicationHandler(this);

            MessageBus.Subscribe(_appHandler);
            MessageBus.Subscribe(_appRepo);
        }
        public ActionResult applicationInfo(ApplicationManager app)

        {
            if (ModelState.IsValid)
            {
                ApplicationHandler application = new ApplicationHandler();
                application.AddApp(app);
                return(RedirectToAction("successPage"));
            }
            return(View(app));
        }
示例#5
0
 public void Unlock(BitmapData bitmapData)
 {
     ApplicationHandler.InvokeIfNecessary(() => {
         var wb = Control as swm.Imaging.WriteableBitmap;
         if (wb != null)
         {
             wb.AddDirtyRect(new sw.Int32Rect(0, 0, Size.Width, Size.Height));
             wb.Unlock();
         }
     });
 }
示例#6
0
        public void TaskFinished(SnTaskResult taskResult)
        {
            SnTrace.TaskManagement.Write("AgentHub TaskFinished called. Agent: {0} / {1}, taskId: {2}, code: {3}, error: {4}",
                                         taskResult.MachineName, taskResult.AgentName, taskResult.Task.Id, taskResult.ResultCode,
                                         taskResult.Error == null ? "" : taskResult.Error.Message);
            try
            {
                if (string.IsNullOrEmpty(taskResult.Task.AppId))
                {
                    SnLog.WriteWarning($"AppId is empty for task #{taskResult.Task.Id}.",
                                       EventId.TaskManagement.Lifecycle);
                    return;
                }

                var doesApplicationNeedNotification = !string.IsNullOrWhiteSpace(taskResult.Task.GetFinalizeUrl());
                // first we make sure that the app is accessible by sending a ping request
                if (doesApplicationNeedNotification && !ApplicationHandler.SendPingRequest(taskResult.Task.AppId))
                {
                    var app = ApplicationHandler.GetApplication(taskResult.Task.AppId);

                    SnLog.WriteError(string.Format("Ping request to application {0} ({1}) failed when finalizing task #{2}. Task success: {3}, error: {4}",
                                                   taskResult.Task.AppId,
                                                   app == null ? "unknown app" : app.ApplicationUrl,
                                                   taskResult.Task.Id,
                                                   taskResult.Successful,
                                                   taskResult.Error == null ? "-" : taskResult.Error.ToString()),
                                     EventId.TaskManagement.Communication);

                    doesApplicationNeedNotification = false;
                }

                // remove the task from the database first
                TaskDataHandler.FinalizeTask(taskResult);

                SnTrace.TaskManagement.Write("AgentHub TaskFinished: task {0} has been deleted.", taskResult.Task.Id);

                if (doesApplicationNeedNotification)
                {
                    // This method does not need to be awaited, because we do not want to do anything
                    // with the result, only notify the app that the task has been finished.
                    ApplicationHandler.SendFinalizeNotificationAsync(taskResult);
                }

                // notify monitors
                TaskMonitorHub.OnTaskEvent(taskResult.Successful
                    ? SnTaskEvent.CreateDoneEvent(taskResult.Task.Id, taskResult.Task.Title, taskResult.ResultData, taskResult.Task.AppId, taskResult.Task.Tag, taskResult.MachineName, taskResult.AgentName)
                    : SnTaskEvent.CreateFailedEvent(taskResult.Task.Id, taskResult.Task.Title, taskResult.ResultData, taskResult.Task.AppId, taskResult.Task.Tag, taskResult.MachineName, taskResult.AgentName));
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex, "AgentHub TaskFinished failed.", EventId.TaskManagement.General);
            }
        }
示例#7
0
 public BitmapData Lock()
 {
     return(ApplicationHandler.InvokeIfNecessary(() =>
     {
         var wb = Control as swmi.WriteableBitmap;
         if (wb == null)
         {
             wb = new swmi.WriteableBitmap(Control);
             SetBitmap(wb);
         }
         wb.Lock();
         return new BitmapDataHandler(Widget, wb.BackBuffer, Stride, Control.Format.BitsPerPixel, wb);
     }));
 }
示例#8
0
        public static void EnsureLoaded(this sw.FrameworkElement control)
        {
            ApplicationHandler.InvokeIfNecessary(() =>
            {
#if TODO_XAML
                if (!control.IsLoaded)
                {
                    control.Dispatcher.Invoke(new Action(() => { }), sw.Threading.DispatcherPriority.ContextIdle, null);
                }
#else
                throw new NotImplementedException();
#endif
            });
        }
示例#9
0
        public BitmapData Lock()
        {
            if (isLocked)
            {
                throw new InvalidOperationException();
            }
            BitmapDataHandler bd = null;

            ApplicationHandler.InvokeIfNecessary(() => {
                Control.Lock();
                bd = new BitmapDataHandler(Widget, Control.BackBuffer, Size.Width, Control.Format.BitsPerPixel, Control);
            });
            isLocked = true;
            return(bd);
        }
示例#10
0
        public void RegisterApplication(RegisterApplicationRequest appRequest)
        {
            try
            {
                var app = TaskDataHandler.RegisterApplication(appRequest);
            }
            catch (Exception ex)
            {
                // the client app needs to be notified
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            // invalidate app cache
            ApplicationHandler.Reset();
        }
        public ActionResult DeleteApp(FormCollection form)
        {
            int num = Convert.ToInt32(form["applicationId"].ToString());

            if (ModelState.IsValid)
            {
                ApplicationHandler application        = new ApplicationHandler();
                ICollection <ApplicationManager> data = application.GetAllApps();
                ApplicationManager appManager         = new ApplicationManager();
                appManager = data.Single(x => x.applicationId == num);
                data.Remove(appManager);
                return(RedirectToAction("successPage"));
            }
            return(RedirectToAction("ErrorLogin"));
        }
示例#12
0
        public void Create(int width, int height, int bitsPerPixel)
        {
            Size = new Size(width, height);
            var format = swm.PixelFormats.Indexed8;

            numColors = (int)Math.Pow(2, bitsPerPixel);
            var colors = new List <swm.Color> (numColors);

            while (colors.Count < numColors)
            {
                colors.Add(swm.Colors.Black);
            }
            ApplicationHandler.InvokeIfNecessary(() => {
                Control = new swmi.WriteableBitmap(width, height, 96, 96, format, new swmi.BitmapPalette(colors));
            });
        }
示例#13
0
 public void Unlock(BitmapData bitmapData)
 {
     if (!isLocked)
     {
         throw new InvalidOperationException();
     }
     ApplicationHandler.InvokeIfNecessary(() => {
         Control.AddDirtyRect(new sw.Int32Rect(0, 0, Size.Width, Size.Height));
         Control.Unlock();
         if (paletteSetInLocked)
         {
             SetPalette();
             paletteSetInLocked = false;
         }
     });
     isLocked = false;
 }
示例#14
0
        public void Create(Image image, int width, int height, ImageInterpolation interpolation)
        {
            ApplicationHandler.InvokeIfNecessary(() => {
                var source = image.ToWpf();
                // use drawing group to allow for better quality scaling
                var group = new swm.DrawingGroup();
                swm.RenderOptions.SetBitmapScalingMode(group, interpolation.ToWpf());
                group.Children.Add(new swm.ImageDrawing(source, new sw.Rect(0, 0, width, height)));

                var drawingVisual = new swm.DrawingVisual();
                using (var drawingContext = drawingVisual.RenderOpen())
                    drawingContext.DrawDrawing(group);

                var resizedImage = new swm.Imaging.RenderTargetBitmap(width, height, source.DpiX, source.DpiY, swm.PixelFormats.Default);
                resizedImage.Render(drawingVisual);
                Control = resizedImage;
            });
        }
示例#15
0
        static void Main(string[] args)
        {
            string          jsonFilePath;
            ApplicationJson appJson = new ApplicationJson();

            Console.WriteLine();

#if DEBUG
            jsonFilePath = "appsettings.json";
#else
            jsonFilePath = args[0];
#endif
            try
            {
                Console.WriteLine("Reading settings from appsettings.json . . .");
                Console.WriteLine(jsonFilePath);

                appJson = JsonConvert.DeserializeObject <ApplicationJson>(File.ReadAllText(jsonFilePath));

                if (appJson.Application == null || appJson.Server == null)
                {
                    throw new ArgumentNullException("appsettings data is NULL");
                }

                Console.WriteLine("Reading complete");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Reading Error:");
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
                Environment.Exit(0);
            }

            Console.WriteLine();
            Console.WriteLine("Autobackup starting by " + Environment.UserName + " . . .");
            Console.WriteLine();
            ApplicationHandler appHandler = new ApplicationHandler(appJson.Application, appJson.Server);

            Console.WriteLine();
            Console.WriteLine("AutoBackuping Finished");
        }
示例#16
0
        public Bitmap Clone(Rectangle?rectangle = null)
        {
            var clone = ApplicationHandler.InvokeIfNecessary(() =>
            {
                if (rectangle != null)
                {
                    var rect = rectangle.Value;
                    var data = new byte[Stride * Control.PixelHeight];
                    Control.CopyPixels(data, Stride, 0);
                    var target = new swmi.WriteableBitmap(rect.Width, rect.Height, Control.DpiX, Control.DpiY, Control.Format, Control.Palette);
                    target.WritePixels(rect.ToWpfInt32(), data, Stride, destinationX: 0, destinationY: 0);
                    return(target);
                }
                else
                {
                    return(Control.Clone());
                }
            });

            return(new Bitmap(new BitmapHandler(clone)));
        }
示例#17
0
        public BitmapData Lock()
        {
            BitmapDataHandler handler = null;

            ApplicationHandler.InvokeIfNecessary(() => {
                var wb = Control as swm.Imaging.WriteableBitmap;
                if (wb != null)
                {
                    wb.Lock();
                    handler = new BitmapDataHandler(Widget, wb.BackBuffer, (int)stride, Control.Format.BitsPerPixel, Control);
                }
                else
                {
                    wb = new swm.Imaging.WriteableBitmap(Control);
                    wb.Lock();
                    Control = wb;
                    handler = new BitmapDataHandler(Widget, wb.BackBuffer, (int)stride, Control.Format.BitsPerPixel, wb);
                }
            });
            return(handler);
        }
示例#18
0
        public Bitmap Clone(Rectangle?rectangle = null)
        {
            swmi.BitmapSource clone = null;
            ApplicationHandler.InvokeIfNecessary(() => {
                if (rectangle != null)
                {
                    var rect    = rectangle.Value;
                    int stride  = Control.PixelWidth * (Control.Format.BitsPerPixel / 8);
                    byte[] data = new byte[stride * Control.PixelHeight];
                    Control.CopyPixels(data, stride, 0);
                    var target = new swmi.WriteableBitmap(rect.Width, rect.Height, Control.DpiX, Control.DpiY, Control.Format, null);
                    target.WritePixels(rect.ToWpfInt32(), data, stride, destinationX: 0, destinationY: 0);
                    clone = target;
                }
                else
                {
                    clone = Control.Clone();
                }
            });

            return(new Bitmap(Generator, new BitmapHandler(clone)));
        }
示例#19
0
        public static void DisconnectAll()
        {
            List <Socket> list = new List <Socket>();

            lock (ConnectionManager.thisManagerLock)
            {
                if (ConnectionManager.allConnections.Count > 0)
                {
                    foreach (KeyValuePair <Socket, ConnectionContext> current in ConnectionManager.allConnections)
                    {
                        Socket key = current.Key;
                        list.Add(key);
                        key.Close();
                    }
                }
                ConnectionManager.allConnections.Clear();
            }
            foreach (Socket current2 in list)
            {
                ApplicationHandler.DelegateOnLinkDown(current2, "");
            }
        }
示例#20
0
        public List <SocketAsyncEventArgs> IncommingHandler(SocketAsyncEventArgs receiveEventArg)
        {
            int i = 0;
            List <SocketAsyncEventArgs> list = new List <SocketAsyncEventArgs>();

            while (i < receiveEventArg.BytesTransferred)
            {
                int num = 1600 - this.nRemainingBytes;
                if (num == 0)
                {
                    return(null);
                }
                if (receiveEventArg.BytesTransferred - i < num)
                {
                    num = receiveEventArg.BytesTransferred - i;
                }
                Buffer.BlockCopy(receiveEventArg.Buffer, receiveEventArg.Offset + i, this.receiveBuffer, this.nRemainingBytes, num);
                this.nRemainingBytes += num;
                i += num;
                while (this.nRemainingBytes > 0)
                {
                    bool flag = false;
                    int  j;
                    for (j = 0; j < this.nRemainingBytes; j++)
                    {
                        if (this.receiveBuffer[j] == 13 || this.receiveBuffer[j] == 10)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        break;
                    }
                    int num2 = j;
                    while (num2 < this.nRemainingBytes && (this.receiveBuffer[num2] == 13 || this.receiveBuffer[num2] == 10))
                    {
                        num2++;
                    }
                    if (j > 0)
                    {
                        byte[] array = ApplicationHandler.ProtocolParser(receiveEventArg.AcceptSocket, this.status.nAuthorized, this.receiveBuffer, 0, j);
                        if (array != null)
                        {
                            SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs();
                            if (socketAsyncEventArgs != null)
                            {
                                socketAsyncEventArgs.AcceptSocket = receiveEventArg.AcceptSocket;
                                socketAsyncEventArgs.SetBuffer(array, 0, array.Length);
                                socketAsyncEventArgs.UserToken = null;
                                list.Add(socketAsyncEventArgs);
                            }
                        }
                    }
                    this.nRemainingBytes -= num2;
                    if (this.nRemainingBytes > 0)
                    {
                        Buffer.BlockCopy(this.receiveBuffer, num2, this.receiveBuffer, 0, this.nRemainingBytes);
                    }
                }
            }
            return(list);
        }
示例#21
0
 public DNP3Handler()
 {
     DNP3ApplicationHandler = new ApplicationHandler();
     DNP3DataLinkHandler    = new DataLinkHandler();
 }
示例#22
0
 public void Create(System.IO.Stream stream)
 {
     ApplicationHandler.InvokeIfNecessary(() => {
         Control = swmi.BitmapFrame.Create(stream, swmi.BitmapCreateOptions.None, swmi.BitmapCacheOption.OnLoad);
     });
 }
示例#23
0
 public void Create(string fileName)
 {
     ApplicationHandler.InvokeIfNecessary(() => {
         Control = swmi.BitmapFrame.Create(new Uri(fileName), swmi.BitmapCreateOptions.None, swmi.BitmapCacheOption.OnLoad);
     });
 }
示例#24
0
        public static void LocalToShareEx(Dictionary <string, Gateway> gts, bool bRemoveOffline)
        {
            if (!SharedData.IsProducer())
            {
                return;
            }
            if (SharedData.semaphoreInSnergy == null)
            {
                return;
            }
            if (gts.Count <= 0)
            {
                lock (SharedData.thisSharedLock)
                {
                    if (SharedData.semaphoreInSnergy != null)
                    {
                        SharedData.semaphoreInSnergy.WaitOne();
                        SharedData.WriteShareLong(32L, 0L);
                        SharedData.WriteShareLong(48L, 0L);
                        SharedData.semaphoreInSnergy.Release();
                    }
                }
                return;
            }
            byte[] array = new byte[SharedData.MAX_SHARE_DATA_SIZE + 1024L];
            Array.Clear(array, 0, array.Length);
            long num  = 0L;
            long num2 = 0L;
            long num3 = 0L;
            long num4 = 0L;
            long num5 = 0L;

            foreach (KeyValuePair <string, Gateway> current in gts)
            {
                byte[]   bytes  = Encoding.ASCII.GetBytes(current.Key);
                string[] array2 = current.Value.status.gatewayIP.Split(new char[]
                {
                    ':'
                });
                DateTime tUptime = current.Value.status.tUptime;
                if (ApplicationHandler.IsTopologyNotEmpty(current.Key) && (!bRemoveOffline || current.Value.status.gatewayIP.IndexOf(":0") < 0))
                {
                    num5 += 1L;
                    if (num2 >= SharedData.MAX_SHARE_DATA_SIZE || num3 > 0L)
                    {
                        num3 = 1L;
                    }
                    else
                    {
                        Buffer.BlockCopy(bytes, 0, array, (int)num2, 20);
                        num2 += 20L;
                        byte[] array3 = new byte[6];
                        Array.Clear(array3, 0, array3.Length);
                        if (array2.Length == 2)
                        {
                            string[] array4 = array2[0].Split(new char[]
                            {
                                '.'
                            });
                            if (array4.Length == 4)
                            {
                                array3[0] = Convert.ToByte(array4[0]);
                                array3[1] = Convert.ToByte(array4[1]);
                                array3[2] = Convert.ToByte(array4[2]);
                                array3[3] = Convert.ToByte(array4[3]);
                                array3[4] = (byte)(Convert.ToInt32(array2[1]) & 255);
                                array3[5] = (byte)(Convert.ToInt32(array2[1]) >> 8);
                            }
                        }
                        Buffer.BlockCopy(array3, 0, array, (int)num2, 6);
                        num2 += 6L;
                        long   value  = ((long)tUptime.Year << 40) + ((long)tUptime.Month << 32) + ((long)tUptime.Day << 24) + (long)((long)tUptime.Hour << 16) + (long)((long)tUptime.Minute << 8) + (long)tUptime.Second;
                        byte[] bytes2 = BitConverter.GetBytes(value);
                        Buffer.BlockCopy(bytes2, 0, array, (int)num2, 8);
                        num2 += 8L;
                        Array.Clear(array3, 0, array3.Length);
                        array3[0] = Convert.ToByte(current.Value.listDevice.Count);
                        Buffer.BlockCopy(array3, 0, array, (int)num2, 1);
                        num2 += 1L;
                        foreach (KeyValuePair <string, Device> current2 in current.Value.listDevice)
                        {
                            if (num2 >= SharedData.MAX_SHARE_DATA_SIZE)
                            {
                                num3 = 1L;
                                InSnergyService.PostLog("OutOfMem #2");
                                break;
                            }
                            byte[] bytes3 = Encoding.ASCII.GetBytes(current2.Value.sDID);
                            Buffer.BlockCopy(bytes3, 0, array, (int)num2, 20);
                            num2 += 20L;
                            long num6 = num2;
                            Array.Clear(array3, 0, array3.Length);
                            array3[0] = Convert.ToByte(current2.Value.listChannel.Count);
                            Buffer.BlockCopy(array3, 0, array, (int)num2, 1);
                            num2 += 1L;
                            long num7 = 0L;
                            foreach (KeyValuePair <string, Channel> current3 in current2.Value.listChannel)
                            {
                                if (num2 >= SharedData.MAX_SHARE_DATA_SIZE)
                                {
                                    num3 = 1L;
                                    InSnergyService.PostLog("OutOfMem #3");
                                    break;
                                }
                                int num8 = Convert.ToInt32(current3.Value.sCID);
                                if (num8 >= 1 && num8 <= 12)
                                {
                                    int num9 = current2.Value.mapChannel[num8 - 1];
                                    if (num9 != 0)
                                    {
                                        string text = num8.ToString();
                                        while (text.Length < 2)
                                        {
                                            text = "0" + text;
                                        }
                                        for (int i = 0; i < 3; i++)
                                        {
                                            string str   = "0" + (i + 1).ToString();
                                            string text2 = (num9 >> 8 * (2 - i) & 255).ToString();
                                            while (text2.Length < 2)
                                            {
                                                text2 = "0" + text2;
                                            }
                                            if (!(text2 == "00"))
                                            {
                                                byte[] bytes4 = Encoding.ASCII.GetBytes(text + str + text2);
                                                Buffer.BlockCopy(bytes4, 0, array, (int)num2, 6);
                                                num2 += 6L;
                                                long num10 = num2;
                                                Array.Clear(array3, 0, array3.Length);
                                                array3[0] = Convert.ToByte(current3.Value.measurePair.Count);
                                                Buffer.BlockCopy(array3, 0, array, (int)num2, 1);
                                                num2 += 1L;
                                                long num11 = 0L;
                                                foreach (KeyValuePair <string, Param> current4 in current3.Value.measurePair)
                                                {
                                                    int num12 = Convert.ToInt32(current4.Value.aID);
                                                    if ((SharedData.listParamEnabled == null || SharedData.listParamEnabled.Contains(num12)) && num12 > 1000 && num12 / 1000 == i + 1)
                                                    {
                                                        if (num2 >= SharedData.MAX_SHARE_DATA_SIZE)
                                                        {
                                                            num3 = 1L;
                                                            InSnergyService.PostLog("OutOfMem #4");
                                                            break;
                                                        }
                                                        byte[] bytes5 = BitConverter.GetBytes(num12);
                                                        Buffer.BlockCopy(bytes5, 0, array, (int)num2, 4);
                                                        num2 += 4L;
                                                        byte[] bytes6 = BitConverter.GetBytes(current4.Value.dvalue);
                                                        Buffer.BlockCopy(bytes6, 0, array, (int)num2, 8);
                                                        num2  += 8L;
                                                        value  = ((long)current4.Value.time.Year << 40) + ((long)current4.Value.time.Month << 32) + ((long)current4.Value.time.Day << 24) + (long)((long)current4.Value.time.Hour << 16) + (long)((long)current4.Value.time.Minute << 8) + (long)current4.Value.time.Second;
                                                        bytes2 = BitConverter.GetBytes(value);
                                                        Buffer.BlockCopy(bytes2, 0, array, (int)num2, 8);
                                                        num2  += 8L;
                                                        num11 += 1L;
                                                    }
                                                }
                                                if (num3 > 0L)
                                                {
                                                    break;
                                                }
                                                Array.Clear(array3, 0, array3.Length);
                                                array3[0] = Convert.ToByte(num11);
                                                Buffer.BlockCopy(array3, 0, array, (int)num10, 1);
                                                num7 += 1L;
                                            }
                                        }
                                    }
                                }
                            }
                            if (num3 > 0L)
                            {
                                break;
                            }
                            Array.Clear(array3, 0, array3.Length);
                            array3[0] = Convert.ToByte(num7);
                            Buffer.BlockCopy(array3, 0, array, (int)num6, 1);
                        }
                        if (num3 <= 0L)
                        {
                            num += 1L;
                            num4 = num2;
                        }
                    }
                }
            }
            Array.Resize <byte>(ref array, (int)num4);
            lock (SharedData.thisSharedLock)
            {
                if (SharedData.semaphoreInSnergy != null)
                {
                    num += num5 << 32;
                    SharedData.semaphoreInSnergy.WaitOne();
                    SharedData.WriteShareLong(32L, num);
                    SharedData.WriteShareLong(48L, num4);
                    SharedData.WriteShareArray(8280L, array);
                    long num13 = SharedData.ReadShareLong(56L);
                    num13 |= 8L;
                    SharedData.WriteShareLong(56L, num13);
                    SharedData.semaphoreInSnergy.Release();
                }
            }
            if (num3 > 0L)
            {
                if (num3 != SharedData.nLastShareMemoryErrorCode)
                {
                    InSnergyService.PostLog("Out of share-memory, data truncated");
                }
                SharedData.WriteStatus(2L, true);
            }
            else
            {
                SharedData.WriteStatus(2L, false);
            }
            SharedData.nLastShareMemoryErrorCode = num3;
        }
        public List <UserLevelObject> PackUp(byte[] data)
        {
            BitArray header     = new BitArray(new byte[] { data[0] });
            BitArray tempHeader = new BitArray(header);

            tempHeader[7] = false;
            tempHeader[6] = false;

            byte[] tempSeq = new byte[1];
            tempHeader.CopyTo(tempSeq, 0);

            byte newSeq = tempSeq[0];

            if (header[6] == true)
            {
                Fir      = true;
                sequence = newSeq;
                appSegments.Clear();
            }
            else if (!Fir)
            {
                return(null);
            }
            else if (newSeq != sequence + 1)
            {
                return(null);
            }

            sequence++;

            Fin = header[7];

            int length = data.Count() - 1;

            byte[] appData = new byte[length];

            for (int i = 0; i < length; i++)
            {
                appData[i] = data[i + 1];
            }

            appSegments.Add(appData);

            if (Fin)
            {
                Fir = false;
                Fin = false;

                int totalLength = 0;
                foreach (byte[] segment in appSegments)
                {
                    totalLength += segment.Count();
                }

                byte[] finalAppData = new byte[totalLength];

                int index = 0;
                foreach (byte[] segment in appSegments)
                {
                    segment.CopyTo(finalAppData, index);
                    index += segment.Count();
                }

                appSegments.Clear();

                DNP3ApplicationHandler = new ApplicationHandler();
                return(DNP3ApplicationHandler.PackUp(finalAppData));
            }
            else
            {
                return(null);
            }
        }
示例#26
0
 public AgentHub(IHubContext <TaskMonitorHub> monitorHub, ApplicationHandler appHandler, TaskDataHandler dataHandler)
 {
     _monitorHub         = monitorHub;
     _applicationHandler = appHandler;
     _dataHandler        = dataHandler;
 }
示例#27
0
 public static void MapWindowSoftInputModeAdjust(ApplicationHandler handler, Application application)
 {
     Platform.ApplicationExtensions.UpdateWindowSoftInputModeAdjust(handler.PlatformView, application);
 }
示例#28
0
        public RegisterTaskResult RegisterTask(RegisterTaskRequest taskRequest)
        {
            Application app = null;

            try
            {
                // load the corresponding application to make sure the appid is valid
                app = ApplicationHandler.GetApplication(taskRequest.AppId);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex, "Error loading app for id " + taskRequest.AppId, EventId.TaskManagement.General);
            }

            // If we do not know the appid, we must not register the task. Client applications
            // must observe this response and try to re-register the application, before
            // trying to register the task again (this can happen if the TaskManagement Web
            // was unreachable when the client application tried to register the appid before).
            if (app == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, RegisterTaskRequest.ERROR_UNKNOWN_APPID));
            }

            RegisterTaskResult result = null;

            try
            {
                // calculate hash with the default algrithm if not given
                var hash = taskRequest.Hash == 0
                    ? ComputeTaskHash(taskRequest.Type + taskRequest.AppId + taskRequest.Tag + taskRequest.TaskData)
                    : taskRequest.Hash;

                result = TaskDataHandler.RegisterTask(
                    taskRequest.Type,
                    taskRequest.Title,
                    taskRequest.Priority,
                    taskRequest.AppId,
                    taskRequest.Tag,
                    taskRequest.FinalizeUrl,
                    hash,
                    taskRequest.TaskData,
                    taskRequest.MachineName);
            }
            catch (Exception ex)
            {
                // the client app needs to be notified
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            try
            {
                // notify agents
                AgentHub.BroadcastMessage(result.Task);

                // notify monitor clients
                TaskMonitorHub.OnTaskEvent(SnTaskEvent.CreateRegisteredEvent(
                                               result.Task.Id, result.Task.Title, string.Empty, result.Task.AppId,
                                               result.Task.Tag, null, result.Task.Type, result.Task.Order,
                                               result.Task.Hash, result.Task.TaskData));
            }
            catch (Exception ex)
            {
                // The task has been created successfully, this error is only about
                // notification, so client applications should not be notified.
                SnLog.WriteException(ex, "Error during agent or monitor notification after a task was registered.", EventId.TaskManagement.Communication);
            }

            return(result);
        }
示例#29
0
 public static void LinkDownNotify(Socket sock)
 {
     ApplicationHandler.DelegateOnLinkDown(sock, "link down");
 }