Пример #1
0
 public virtual void Receive(Message incoming)
 {
     switch(incoming.OperationType)
       {
     case MessageOperationType.Pass:
       OnPass(incoming);
       break;
     case MessageOperationType.Execute:
       OnExecute(incoming);
       break;
     case MessageOperationType.Return:
       OnReturn(incoming);
       break;
     case MessageOperationType.System:
       OnSystemCall(incoming);
       break;
     case MessageOperationType.Init:
       OnInit(incoming);
       break;
     case MessageOperationType.Failure:
       throw new ArgumentException(string.Format("Error: {0}", incoming.Value));
     default:
       DispatchTo(incoming.Sender, ObjectID, MessageOperationType.Failure, "Invalid Action Given");
       break;
       }
 }
Пример #2
0
 //TODO: Introduce code that just returns an encoded string
 //Since all that will be returned is the string itself and the
 //width and height; and an error code (potentially) why not just set it up as
 //such. I bet that the encoding of the hashtable isn't that efficient.
 public override Message Invoke(Message input)
 {
     Hashtable table = (Hashtable)input.Value;
       TranslateData(table);
       return new Message(Guid.NewGuid(), ObjectID, input.Sender,
       MessageOperationType.Return,
       Transform(table));
 }
 public override Message Invoke(Message input)
 {
     return new Message(Guid.NewGuid(),
       ObjectID,
       input.Sender,
       MessageOperationType.Return,
       Process((Hashtable)input.Value));
 }
 private void ApplyToImageBaseOperation(object sender, EventArgs e, Guid target)
 {
     if (srcImage != null)
     {
         Hashtable resultant = new Hashtable();
         if(dynamicFilterForms.ContainsKey(target))
         {
             dynamicFilterForms[target].ShowDialog();
             if(!dynamicFilterForms[target].ShouldApply)
                 return; //get out of here if they hit cancel
             resultant = dynamicFilterForms[target].StorageCells;
         }
         msg.Message m = new msg.Message(Guid.NewGuid(), id, target,
                 msg.MessageOperationType.Execute, resultant);
         int[][] elements = new int[srcImage.Width][];
         resultant["image"] = elements;
         Func<int,int,int> getPixelBase = (x,y) => srcImage.GetPixel(x,y).ToArgb();
         for(int i =0 ; i < srcImage.Width; i++)
         {
             Func<int,int> getPixel = (x) => getPixelBase(i,x);
             int[] line = new int[srcImage.Height];
             for(int j = 0; j < srcImage.Height; j++)
             {
                 line[j] = getPixel(j);
             }
             elements[i] = line;
         }
         try
         {
             var result = filterContainer.Invoke(m);
             var array = (int[][])result.Value;
             int width = array.Length;
             int height = array[0].Length;
             resultImage = new Bitmap(width, height);
             Action<int,int,int> setColorBase = (x,y,c) => resultImage.SetPixel(x,y,Color.FromArgb(c));
             for(int i = 0; i < width; i++)
             {
                 int[] aX = array[i];
                 Action<int,int> setColor = (y,c) => setColorBase(i,y,c);
                 for(int j=0; j < height; j++)
                 {
                     setColor(j, aX[j]);
                 }
             }
         }
         catch (Exception exception)
         {
             Console.WriteLine(exception.StackTrace);
             MessageBox.Show("An error occured during filter execution.\n See console for stack dump");
         }
     }
     else
     {
         OpenImage(this, new EventArgs());
     }
 }
 public override Message Invoke(Message input)
 {
     var result = TransformImage(TranslateData((Hashtable)input.Value));
     return new Message(Guid.NewGuid(), ObjectID, input.Sender, MessageOperationType.Return,
             result);
 }
Пример #6
0
 public Message Invoke(Message input)
 {
     return this[input.Receiver].Invoke(input);
 }
Пример #7
0
 public virtual void OnReturn(Message incoming)
 {
     //do nothing
 }
Пример #8
0
 public virtual void OnSystemCall(Message incoming)
 {
     //do nothing
 }
Пример #9
0
 public virtual void OnInit(Message incoming)
 {
     //do nothing
 }
Пример #10
0
 public virtual void OnPass(Message incoming)
 {
     //do nothing
 }
Пример #11
0
 public abstract void DispatchTo(Message mess);
Пример #12
0
 public virtual void OnExecute(Message incoming)
 {
     //do nothing
 }
Пример #13
0
 public Message Invoke(Message input)
 {
     long startingPosition = (long)input.Value;
     communications.Position = startingPosition;
     Hashtable ht = interpreter.CreateData();
     Message m2 = new Message(input.Sender, input.Receiver, input.OperationType,
             ht);
     Message oMSG = FilterLoader.Invoke(translationLayer[input.Receiver], m2);
     Hashtable table = (Hashtable)oMSG.Value;
     if(table.ContainsKey("terminate"))
     {
         communications.Position = 0L;
         TransmissionEncoder.PutIntoHashtable("terminate", table["terminate"].ToString(),
                 communications);
         TransmissionEncoder.WriteCode((byte)255, communications);
         communications.Position = 0L;
         return new Message(Guid.NewGuid(), oMSG.ObjectID, oMSG.Sender,
                 MessageOperationType.Return,
                 false);
     }
     else
     {
         communications.Position = 0L;
         TransmissionEncoder.PutIntoHashtable("width", (int)table["width"], communications);
         TransmissionEncoder.PutIntoHashtable("height", (int)table["height"], communications);
         TransmissionEncoder.PutIntoHashtable("result", table["result"].ToString(), communications);
         TransmissionEncoder.WriteCode((byte)255, communications);
         communications.Position = 0L;
         return new Message(Guid.NewGuid(), oMSG.ObjectID, oMSG.Sender,
                 MessageOperationType.Return,
                 true);
     }
 }
 private void ApplyToFileFormatOperation(object sender, EventArgs e, Guid target, string action, string path)
 {
     if(CanPerformOperation(target, action))
     {
         Hashtable resultant = new Hashtable();
         if(dynamicFileFormatForms.ContainsKey(target))
         {
             dynamicFileFormatForms[target].ShowDialog();
             if(!dynamicFileFormatForms[target].ShouldApply)
             {
                 return;
             }
             resultant = dynamicFileFormatForms[target].StorageCells;
         }
         resultant["action"] = action;
         resultant["path"] = path;
         try
         {
             if(action.Equals("save"))
             {
                 int[][] elements = new int[srcImage.Width][];
                 resultant["image"] = elements;
                 Func<int,int,Color> getPixelBase = (x,y) => srcImage.GetPixel(x,y);
                 for(int i =0 ; i < srcImage.Width; i++)
                 {
                     Func<int,Color> getPixel = (x) => getPixelBase(i,x);
                     int[] line = new int[srcImage.Height];
                     for(int j = 0; j < srcImage.Height; j++)
                     {
                         line[j] = getPixel(j).ToArgb();
                     }
                     elements[i] = line;
                 }
             }
             msg.Message m = new msg.Message(Guid.NewGuid(), id, target,
                     msg.MessageOperationType.Execute, resultant);
             var result = fileFormatContainer.Invoke(m);
             if(action.Equals("load"))
             {
                 var array = (int[][])result.Value;
                 //we could always just return the RGBA value across the boundaries
                 int width = array.Length;
                 int height = array[0].Length;
                 srcImage = new Bitmap(width, height);
                 Action<int,int,int> setColorBase = (x,y,c) => srcImage.SetPixel(x,y,Color.FromArgb(c));
                 for(int i = 0; i < width; i++)
                 {
                     int[] line = array[i];
                     Action<int,int> setColor = (y,c) => setColorBase(i,y,c);
                     for(int j = 0; j < height; j++)
                     {
                         setColor(j,line[j]);
                     }
                 }
             }
         }
         catch(Exception ex)
         {
             Console.WriteLine(ex.StackTrace);
             MessageBox.Show(string.Format("An error occured during a {0}-file operation.\nMessage: {1}", action, ex.Message));
         }
     }
     else
     {
         MessageBox.Show(string.Format("Operation {0} is not supported", action));
     }
 }
 private msg.Message QueryInfo(Guid target, string action)
 {
     Hashtable ht = new Hashtable();
     ht["action"] = action;
     msg.Message m = new msg.Message(Guid.NewGuid(), id, target,
             msg.MessageOperationType.Execute, ht);
     return fileFormatContainer.Invoke(m);
 }
 public abstract Message Invoke(Message input);
 public static Message Invoke(Guid targetPluginGroup, Message input)
 {
     return pluginEnvironments[targetPluginGroup].Invoke(input);
 }