Пример #1
0
        /// <summary>
        /// Allows POS to query for currently assigned tables to servers. Without the optional variables a complete list of
        /// currently assigned servers along with their tables will be returned.If serverName is supplied, only the
        /// tables assigned to that server will be returned. If tableNumber is supplied, only the server and other tables
        /// assigned to that server will be returned.If both optional variables are supplied the server name will take
        /// precedent.
        /// </summary>
        /// <param name="tableNumber">table number to query server for</param>
        /// <returns>ServerAssignmentResponse</returns>
        public ServerAssignmentResponse GetServerAssignments(int tableNumber)
        {
            var content = new MultipartForm()
                          .Set("tableNumber", tableNumber);

            return(SendRequest <ServerAssignmentResponse>("pos/getServerAssignment", content));
        }
Пример #2
0
        public virtual void PopulateForm(MultipartForm form)
        {
            foreach (var propInfo in GetType().GetRuntimeProperties())
            {
                var fieldName = string.Format("{0}{1}", Prefix, propInfo.Name);

                var value = propInfo.GetValue(this);
                if (value == null)
                {
                    form.Set(fieldName, DefaultForType(propInfo));
                }
                else
                {
                    if (value is Enum)
                    {
                        var description = value.GetType().GetRuntimeField(value.ToString()).GetCustomAttribute <DescriptionAttribute>();
                        form.Set(fieldName, description?.Description);
                    }
                    else
                    {
                        form.Set(fieldName, value.ToString());
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Allows POS to query for currently assigned tables to servers. Without the optional variables a complete list of
        /// currently assigned servers along with their tables will be returned.If serverName is supplied, only the
        /// tables assigned to that server will be returned. If tableNumber is supplied, only the server and other tables
        /// assigned to that server will be returned.If both optional variables are supplied the server name will take
        /// precedent.
        /// </summary>
        /// <param name="serverName">server name to query</param>
        /// <returns>ServerAssignmentResponse</returns>
        public ServerAssignmentResponse GetServerAssignments(string serverName)
        {
            var content = new MultipartForm()
                          .Set("serverName", serverName);

            return(SendRequest <ServerAssignmentResponse>("pos/getServerAssignment", content));
        }
Пример #4
0
        /// <summary>
        /// Allows POS to query table/check status by table number. Occupied and enabled/disabled statuses are
        /// returned, along with the checkID and bumpStatusID if a check is currently assigned.
        /// </summary>
        /// <param name="checkId">check id to query</param>
        /// <returns>Ticket</returns>
        public Ticket QueryCheckStatus(int checkId)
        {
            var content = new MultipartForm()
                          .Set("checkID", checkId);

            return(SendRequest <Ticket>("pos/checkStatus", content));
        }
Пример #5
0
        internal static void NewRevision(string host, string apiKey, string teamspace, string modelId, string filePath)
        {
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            fs.Close();

            Dictionary <string, object> postParameters = new Dictionary <string, object>();

            postParameters.Add("file", new MultipartForm.FileParameter(data, filePath, "application/octet-stream"));


            string uri = host + "/" + teamspace + "/" + modelId + "/upload?key=" + apiKey;

            Logger.Instance.Log("Posting a new revision at : " + uri);
            // Create request and receive response
            HttpWebResponse webResponse = MultipartForm.MultipartFormDataPost(uri, null, postParameters);

            // Process response
            StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
            string       fullResponse   = responseReader.ReadToEnd();

            webResponse.Close();
            if (fullResponse.Contains("The remote server returned an error"))
            {
                Logger.Instance.Log("Errored: " + fullResponse);
                throw new Exception(fullResponse);
            }
        }
Пример #6
0
        /// <summary>
        /// Allows POS to update/clear the party from the table inside Freshtxt.
        /// </summary>
        /// <param name="clearTime">optional: Time the table was cleared</param>
        /// <returns>TableServiceResponse</returns>
        public TableServiceResponse ClearTable(DateTime?clearTime = null)
        {
            var content = new MultipartForm()
                          .Set("checkID", CheckId)
                          .Set("clearTime", clearTime ?? DateTime.Now);

            return(SendRequest <TableServiceResponse>("pos/clearTable", content));
        }
Пример #7
0
        /// <summary>
        /// Allows POS to assign and update shift data within Freshtxt. With this single call, new section/station
        /// assignments can be made as well as server assignments to those sections.
        /// </summary>
        /// <param name="shiftData">Shift assignments object</param>
        /// <returns>ServerAssignmentResponse</returns>
        public ServerAssignmentResponse AssignShift(ShiftAssignments shiftData)
        {
            var content = new MultipartForm()
                          .Set("shiftData", shiftData.ToString());

            SendRequest <TableServiceResponse>("pos/assignShift", content);
            return(GetServerAssignments());
        }
Пример #8
0
 private void PopulateForm <T>(MultipartForm form, T element) where T : FormElement
 {
     if (element == null)
     {
         element = Activator.CreateInstance <T>();
     }
     element.PopulateForm(form);
 }
Пример #9
0
        /// <summary>
        /// This would be used to notifiy Freshxt of the order placement time.
        /// </summary>
        /// <param name="openTime">optional: The order placement time</param>
        /// <returns>TableServiceResponse</returns>
        public TableServiceResponse OpenOrder(DateTime?openTime = null)
        {
            var content = new MultipartForm()
                          .Set("checkID", CheckId)
                          .Set("openTime", openTime ?? DateTime.Now);

            return(SendRequest <TableServiceResponse>("pos/openOrder", content));
        }
Пример #10
0
        /// <summary>
        /// Allows POS to update the server name list inside Freshtxt. The complete list will be replaced with this method.
        /// </summary>
        /// <param name="serverList">Enumerable list of server names</param>
        /// <returns>ServerListResponse</returns>
        public ServerListResponse UpdateServerList(IEnumerable <string> serverList)
        {
            var _serverList = string.Join(",", serverList);

            var content = new MultipartForm()
                          .Set("serverList", _serverList);

            SendRequest <TableServiceResponse>("pos/updateServerList", content);
            return(GetServerList());
        }
Пример #11
0
        /// <summary>
        /// Allows POS to query table/check status by table number. Occupied and enabled/disabled statuses are
        /// returned, along with the checkID and bumpStatusID if a check is currently assigned.
        /// </summary>
        /// <param name="tableNumber">table number to query</param>
        /// <returns>Ticket</returns>
        public Ticket QueryTableStatus(int tableNumber)
        {
            var content = new MultipartForm()
                          .Set("tableNumber", tableNumber);

            var response = SendRequest <Ticket>("pos/tableStatus", content);

            response.TableNumber = tableNumber;
            return(response);
        }
Пример #12
0
        /// <summary>
        /// Allows POS to alter the partyName, partyNum (covers), section, and bumpStatusID for a table.
        /// </summary>
        /// <returns>TableServiceResponse</returns>
        public TableServiceResponse Update()
        {
            var content = new MultipartForm()
                          .Set("checkID", CheckId)
                          .Set("partyName", PartyName)
                          .Set("partNum", PartyNumber)
                          .Set("section", Section)
                          .Set("bumpStatusID", BumpStatusId);

            return(SendRequest <TableServiceResponse>("pos/editTable", content));
        }
Пример #13
0
        /// <summary>
        /// This will assign a seated party with the specificied tabled number with a checkID from your POS. Practical uses
        /// for this is when a server opens a check, your POS sends the tableNumber and checkID and Freshtxt returns
        /// the party waitTime and checkInTime.This must be set to use any other POS API calls.
        /// </summary>
        /// <param name="tableNumber">table number to assign to the check</param>
        /// <param name="checkId">ID of the check in the system</param>
        /// <param name="startTime">optional: time the ticket was assigned.</param>
        /// <returns>Ticket</returns>
        public Ticket AssignCheck(int tableNumber, int checkId, DateTime?startTime = null)
        {
            var content = new MultipartForm()
                          .Set("tableNumber", tableNumber)
                          .Set("checkID", checkId)
                          .Set("startTime", startTime ?? DateTime.Now);

            var response = SendRequest <Ticket>("pos/assignCheck", content);

            response.TableNumber = tableNumber;
            return(response);
        }
Пример #14
0
        /// <summary>
        /// This generally would be used to notifiy Freshxt of the kitchen bump time. This will allow the host to see a color
        /// status change on a table.The bumpStatusID is the status ID inside freshtxt that you want to set the bump to
        /// be.This can be configured inside the freshtxt application and is returned with every login in the
        /// tableStatus variable.The first item in that list is ID= 1, next id ID= 2 and so on.Setting ID = 0 will clear the
        /// tableStatus back to none.
        /// </summary>
        /// <param name="bumpStatusId">The ID of the bump status</param>
        /// <param name="bumpTime">optional: the time of the status change</param>
        /// <returns>TableServiceResponse</returns>
        public TableServiceResponse BumpStatus(int bumpStatusId, DateTime?bumpTime = null)
        {
            var content = new MultipartForm()
                          .Set("checkID", CheckId)
                          .Set("bumpStatusID", bumpStatusId)
                          .Set("bumpTime", bumpTime ?? DateTime.Now);

            var response = SendRequest <TableServiceResponse>("pos/bumpStatus", content);

            BumpStatusId = bumpStatusId;
            return(response);
        }
Пример #15
0
        protected T SendRequest <T>(string endpoint, MultipartForm formData) where T : TableServiceResponse
        {
            var connector = ServicesContainer.Instance.GetTableServiceClient(_configName);

            if (!connector.Configured && !endpoint.Equals("user/login"))
            {
                throw new ConfigurationException("Reservation service has not been configured properly. Please ensure you have logged in first.");
            }

            var response = connector.Call(endpoint, formData);

            return(Activator.CreateInstance(typeof(T), response, _configName) as T);
        }
Пример #16
0
        /// <summary>
        /// Allows POS to transfer a party from a table to another table number newTableNumber . This will preserve
        /// all data associated with that party.
        /// </summary>
        /// <param name="newTableNumber">The new table number to assign to the existing table</param>
        /// <returns>TableServiceResponse</returns>
        public TableServiceResponse Transfer(int newTableNumber)
        {
            var content = new MultipartForm()
                          .Set("checkID", CheckId)
                          .Set("newTableNumber", newTableNumber);

            var response = SendRequest <TableServiceResponse>("pos/settleCheck", content);

            if (response.ResponseCode == "00")
            {
                TableNumber = newTableNumber;
            }
            return(response);
        }
Пример #17
0
        /// <summary>
        /// Allow POS to settle the check within Freshtxt and optionally change the tableStatus. This will allow the host to
        /// see a color status change on a table.The bumpStatusID is the status ID inside freshtxt that you want to set the
        /// bump to be. This can be configured inside the freshtxt application and is returned with every login in the
        /// tableStatus variable.The first item in that list is ID= 1, next id ID= 2 and so on.Setting ID = 0 will clear the
        /// tableStatus back to none.
        /// </summary>
        /// <returns>TableServiceResponse</returns>
        public TableServiceResponse SettleCheck(int?bumpStatusId = null, DateTime?settleTime = null)
        {
            var content = new MultipartForm()
                          .Set("checkID", CheckId)
                          .Set("bumpStatusID", bumpStatusId)
                          .Set("settleTime", settleTime ?? DateTime.Now);

            var response = SendRequest <TableServiceResponse>("pos/settleCheck", content);

            if (bumpStatusId.HasValue)
            {
                BumpStatusId = bumpStatusId.Value;
            }
            return(response);
        }
Пример #18
0
        /// <summary>
        /// Used to log into the table service API and configure the connector for subsequent calls.
        /// </summary>
        /// <param name="username">Username of the user.</param>
        /// <param name="password">Password of the user.</param>
        /// <returns></returns>
        public LoginResponse Login(string username, string password)
        {
            var content = new MultipartForm()
                          .Set("username", username)
                          .Set("password", password);

            var response = SendRequest <LoginResponse>("user/login", content);

            // configure the connector
            var connector = ServicesContainer.Instance.GetTableServiceClient(_configName);

            connector.LocationId           = response.LocationId;
            connector.SecurityToken        = response.Token;
            connector.SessionId            = response.SessionId;
            connector.BumpStatusCollection = new BumpStatusCollection(response.TableStatus);

            return(response);
        }
Пример #19
0
        public String uploadFile(String url, String path)
        {
            String result = "";

            try
            {
                String        fileName = Path.GetFileName(url);
                MultipartForm form     = new MultipartForm(url);
                form.SendFile(@path);
                result  = ">>>Cinci: File Uploaded Successfully\r\n";
                result += ">>>" + path;
            }
            catch (Exception ex)
            {
                result  = ">>>Cinci: File Upload ERROR!\r\n";
                result += ">>>" + ex.Message;
            }
            return(result);
        }
Пример #20
0
        public string Call(string endpoint, MultipartForm content)
        {
            content.Set("locID", LocationId);
            content.Set("token", SecurityToken);
            content.Set("sessionID", SessionId);

            try {
                var response = SendRequest(endpoint, content.Content);
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    //TODO: add some error handling here
                }
                return(response.RawResponse);
            }
            catch (GatewayException) {
                throw;
            }
            catch (Exception exc) {
                throw new GatewayException(exc.Message, exc);
            }
        }
        ///<summary>
        ///
        ///</summary>
        private void UploadMapTile(IScene scene)
        {
            m_log.DebugFormat("[SIMIAN MAPTILE]: upload maptile for {0}", scene.RegionInfo.RegionName);

            // Create a PNG map tile and upload it to the AddMapTile API
            byte[]             pngData       = Utils.EmptyBytes;
            IMapImageGenerator tileGenerator = scene.RequestModuleInterface <IMapImageGenerator>();

            if (tileGenerator == null)
            {
                m_log.Warn("[SIMIAN MAPTILE]: Cannot upload PNG map tile without an ImageGenerator");
                return;
            }

            using (Image mapTile = tileGenerator.CreateMapTile())
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    mapTile.Save(stream, ImageFormat.Png);
                    pngData = stream.ToArray();
                }
            }

            List <MultipartForm.Element> postParameters = new List <MultipartForm.Element>()
            {
                new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
                new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
                new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
            };

            string errorMessage = null;
            int    tickstart    = Util.EnvironmentTickCount();

            // Make the remote storage request
            try
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);
                request.Timeout          = 20000;
                request.ReadWriteTimeout = 5000;

                using (HttpWebResponse response = MultipartForm.Post(request, postParameters))
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        string responseStr = responseStream.GetStreamString();
                        OSD    responseOSD = OSDParser.Deserialize(responseStr);
                        if (responseOSD.Type == OSDType.Map)
                        {
                            OSDMap responseMap = (OSDMap)responseOSD;
                            if (responseMap["Success"].AsBoolean())
                            {
                                return;
                            }

                            errorMessage = "Upload failed: " + responseMap["Message"].AsString();
                        }
                        else
                        {
                            errorMessage = "Response format was invalid:\n" + responseStr;
                        }
                    }
                }
            }
            catch (WebException we)
            {
                errorMessage = we.Message;
                if (we.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpWebResponse webResponse = (HttpWebResponse)we.Response;
                    errorMessage = String.Format("[{0}] {1}",
                                                 webResponse.StatusCode, webResponse.StatusDescription);
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
            finally
            {
                // This just dumps a warning for any operation that takes more than 100 ms
                int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
                m_log.DebugFormat("[SIMIAN MAPTILE]: map tile uploaded in {0}ms", tickdiff);
            }

            m_log.WarnFormat("[SIMIAN MAPTILE]: Failed to store {0} byte tile for {1}: {2}",
                             pngData.Length, scene.RegionInfo.RegionName, errorMessage);
        }
Пример #22
0
        /// <summary>
        ///   Creates a new asset
        /// </summary>
        /// Returns a random ID if none is passed into it
        /// <param name = "asset"></param>
        /// <returns></returns>
        public UUID Store(AssetBase asset)
        {
            if (String.IsNullOrEmpty(m_serverUrl))
            {
                MainConsole.Instance.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured");
                throw new InvalidOperationException();
            }

            bool   storedInCache = false;
            string errorMessage  = null;

            // AssetID handling
            if (asset.ID == UUID.Zero)
            {
                asset.ID = UUID.Random();
            }

            // Cache handling
            if (m_cache != null)
            {
                m_cache.Cache(asset);
                storedInCache = true;
            }

            // Local asset handling
            if ((asset.Flags & AssetFlags.Local) == AssetFlags.Local)
            {
                if (!storedInCache)
                {
                    MainConsole.Instance.Error("Cannot store local " + asset.TypeString + " asset without an asset cache");
                    asset.ID = UUID.Zero;
                }

                return(asset.ID);
            }

            // Distinguish public and private assets
            bool isPublic = true;

            switch ((AssetType)asset.Type)
            {
            case AssetType.CallingCard:
            case AssetType.Gesture:
            case AssetType.LSLBytecode:
            case AssetType.LSLText:
                isPublic = false;
                break;
            }

            // Make sure ContentType is set
            if (String.IsNullOrEmpty(asset.TypeString))
            {
                asset.TypeString = SLUtil.SLAssetTypeToContentType(asset.Type);
            }

            // Build the remote storage request
            List <MultipartForm.Element> postParameters = new List <MultipartForm.Element>
            {
                new MultipartForm.Parameter("AssetID",
                                            asset.ID.ToString()),
                new MultipartForm.Parameter("CreatorID",
                                            asset.CreatorID.ToString()),
                new MultipartForm.Parameter("Temporary",
                                            ((asset.Flags &
                                              AssetFlags.Temperary) ==
                                             AssetFlags.Temperary)
                                                                                                 ? "1"
                                                                                                 : "0"),
                new MultipartForm.Parameter("Public",
                                            isPublic ? "1" : "0"),
                new MultipartForm.File("Asset", asset.Name,
                                       asset.TypeString, asset.Data)
            };

            // Make the remote storage request
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_serverUrl);

                HttpWebResponse response = MultipartForm.Post(request, postParameters);
                using (Stream responseStream = response.GetResponseStream())
                {
                    string responseStr = null;

                    try
                    {
                        responseStr = responseStream.GetStreamString();
                        OSD responseOSD = OSDParser.Deserialize(responseStr);
                        if (responseOSD.Type == OSDType.Map)
                        {
                            OSDMap responseMap = (OSDMap)responseOSD;
                            if (responseMap["Success"].AsBoolean())
                            {
                                return(asset.ID);
                            }
                            else
                            {
                                errorMessage = "Upload failed: " + responseMap["Message"].AsString();
                            }
                        }
                        else
                        {
                            errorMessage = "Response format was invalid:\n" + responseStr;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!String.IsNullOrEmpty(responseStr))
                        {
                            errorMessage = "Failed to parse the response:\n" + responseStr;
                        }
                        else
                        {
                            errorMessage = "Failed to retrieve the response: " + ex.Message;
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                errorMessage = ex.Message;
            }

            MainConsole.Instance.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}",
                                            asset.Name, asset.ID, asset.TypeString, errorMessage);
            return(UUID.Zero);
        }
Пример #23
0
        private void DoCreateAsset(object o)
        {
            try
            {
                object[] array = (object[])o;

                string assetID     = (string)array[0];
                bool   isPublic    = (bool)array[1];
                string assetName   = (string)array[2];
                string contentType = (string)array[3];
                byte[] assetData   = (byte[])array[4];

                string errorMessage = null;

                // Build the remote storage request
                List <MultipartForm.Element> postParameters = new List <MultipartForm.Element>()
                {
                    new MultipartForm.Parameter("AssetID", assetID),
                    new MultipartForm.Parameter("Public", isPublic ? "1" : "0"),
                    new MultipartForm.File("Asset", assetName, contentType, assetData)
                };

                // Make the remote storage request
                try
                {
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_assetUrl);

                    HttpWebResponse response = MultipartForm.Post(request, postParameters);
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        string responseStr = null;

                        try
                        {
                            responseStr = responseStream.GetStreamString();
                            OSD responseOSD = OSDParser.Deserialize(responseStr);
                            if (responseOSD.Type == OSDType.Map)
                            {
                                OSDMap responseMap = (OSDMap)responseOSD;
                                if (responseMap["Success"].AsBoolean())
                                {
                                    return;
                                }
                                else
                                {
                                    errorMessage = "Upload failed: " + responseMap["Message"].AsString();
                                }
                            }
                            else
                            {
                                errorMessage = "Response format was invalid:\n" + responseStr;
                            }
                        }
                        catch (Exception ex)
                        {
                            if (!String.IsNullOrEmpty(responseStr))
                            {
                                errorMessage = "Failed to parse the response:\n" + responseStr;
                            }
                            else
                            {
                                errorMessage = "Failed to retrieve the response: " + ex.Message;
                            }
                        }
                    }
                }
                catch (WebException ex)
                {
                    errorMessage = ex.Message;
                }

                Console.WriteLine("Failed to store asset \"{0}\" ({1}, {2}): {3}", assetName, assetID, contentType, errorMessage);
            }
            finally
            {
                m_semaphore.Release();
            }
        }
Пример #24
0
        private void UploadMapTile(IScene scene)
        {
            string errorMessage = null;

            // Create a PNG map tile and upload it to the AddMapTile API
            byte[]             pngData       = Utils.EmptyBytes;
            IMapImageGenerator tileGenerator = scene.RequestModuleInterface <IMapImageGenerator>();

            if (tileGenerator == null)
            {
                m_log.Warn("[SIMIAN GRID CONNECTOR]: Cannot upload PNG map tile without an IMapImageGenerator");
                return;
            }

            using (Image mapTile = tileGenerator.CreateMapTile("defaultstripe.png"))
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    mapTile.Save(stream, ImageFormat.Png);
                    pngData = stream.ToArray();
                }
            }

            List <MultipartForm.Element> postParameters = new List <MultipartForm.Element>()
            {
                new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
                new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
                new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
            };

            // Make the remote storage request
            try
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);

                HttpWebResponse response = MultipartForm.Post(request, postParameters);
                using (Stream responseStream = response.GetResponseStream())
                {
                    string responseStr = null;

                    try
                    {
                        responseStr = responseStream.GetStreamString();
                        OSD responseOSD = OSDParser.Deserialize(responseStr);
                        if (responseOSD.Type == OSDType.Map)
                        {
                            OSDMap responseMap = (OSDMap)responseOSD;
                            if (responseMap["Success"].AsBoolean())
                            {
                                m_log.Info("[SIMIAN GRID CONNECTOR]: Uploaded " + pngData.Length + " byte PNG map tile to AddMapTile");
                            }
                            else
                            {
                                errorMessage = "Upload failed: " + responseMap["Message"].AsString();
                            }
                        }
                        else
                        {
                            errorMessage = "Response format was invalid:\n" + responseStr;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!String.IsNullOrEmpty(responseStr))
                        {
                            errorMessage = "Failed to parse the response:\n" + responseStr;
                        }
                        else
                        {
                            errorMessage = "Failed to retrieve the response: " + ex.Message;
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                errorMessage = ex.Message;
            }

            if (!String.IsNullOrEmpty(errorMessage))
            {
                m_log.WarnFormat("[SIMIAN GRID CONNECTOR]: Failed to store {0} byte PNG map tile for {1}: {2}",
                                 pngData.Length, scene.RegionInfo.RegionName, errorMessage.Replace('\n', ' '));
            }
        }
Пример #25
0
        /// <summary>
        /// Creates a new asset
        /// </summary>
        /// Returns a random ID if none is passed into it
        /// <param name="asset"></param>
        /// <returns></returns>
        public string Store(AssetBase asset)
        {
            if (String.IsNullOrEmpty(m_serverUrl))
            {
                m_log.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured");
                throw new InvalidOperationException();
            }

            bool   storedInCache = false;
            string errorMessage  = null;

            // AssetID handling
            if (String.IsNullOrEmpty(asset.ID) || asset.ID == ZeroID)
            {
                asset.FullID = UUID.Random();
                asset.ID     = asset.FullID.ToString();
            }

            // Cache handling
            if (m_cache != null)
            {
                m_cache.Cache(asset);
                storedInCache = true;
            }

            // Local asset handling
            if (asset.Local)
            {
                if (!storedInCache)
                {
                    m_log.Error("Cannot store local " + asset.Metadata.ContentType + " asset without an asset cache");
                    asset.ID     = null;
                    asset.FullID = UUID.Zero;
                }

                return(asset.ID);
            }

            // Distinguish public and private assets
            bool isPublic = true;

            switch ((AssetType)asset.Type)
            {
            case AssetType.CallingCard:
            case AssetType.Gesture:
            case AssetType.LSLBytecode:
            case AssetType.LSLText:
                isPublic = false;
                break;
            }

            // Make sure ContentType is set
            if (String.IsNullOrEmpty(asset.Metadata.ContentType))
            {
                asset.Metadata.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type);
            }

            // Build the remote storage request
            List <MultipartForm.Element> postParameters = new List <MultipartForm.Element>()
            {
                new MultipartForm.Parameter("AssetID", asset.FullID.ToString()),
                new MultipartForm.Parameter("CreatorID", asset.Metadata.CreatorID),
                new MultipartForm.Parameter("Temporary", asset.Temporary ? "1" : "0"),
                new MultipartForm.Parameter("Public", isPublic ? "1" : "0"),
                new MultipartForm.File("Asset", asset.Name, asset.Metadata.ContentType, asset.Data)
            };

            // Make the remote storage request
            try
            {
                // Simian does not require the asset ID to be in the URL because it's in the post data.
                // By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString());

                HttpWebResponse response = MultipartForm.Post(request, postParameters);
                using (Stream responseStream = response.GetResponseStream())
                {
                    string responseStr = null;

                    try
                    {
                        responseStr = responseStream.GetStreamString();
                        OSD responseOSD = OSDParser.Deserialize(responseStr);
                        if (responseOSD.Type == OSDType.Map)
                        {
                            OSDMap responseMap = (OSDMap)responseOSD;
                            if (responseMap["Success"].AsBoolean())
                            {
                                return(asset.ID);
                            }
                            else
                            {
                                errorMessage = "Upload failed: " + responseMap["Message"].AsString();
                            }
                        }
                        else
                        {
                            errorMessage = "Response format was invalid:\n" + responseStr;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!String.IsNullOrEmpty(responseStr))
                        {
                            errorMessage = "Failed to parse the response:\n" + responseStr;
                        }
                        else
                        {
                            errorMessage = "Failed to retrieve the response: " + ex.Message;
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                errorMessage = ex.Message;
            }

            m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}",
                             asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage);
            return(null);
        }
Пример #26
0
    private void uploadToSiteButton_Click(object sender, EventArgs e)
    {
        this.lifeTimer.Enabled = false;
        //declare the form.
        MultipartForm form;

        //define the inputbox as readonly, output only.
        InputBox i = new InputBox("Your URL", "Your URL is also copied to the clipboard automatically", false, true);

        uploadToSiteButton.Enabled = false;
        uploadToFtpButton.Enabled  = false;
        applyEffectButton.Enabled  = false;
        string returnValue;

        //see what option they chose.
        switch (hostingChoicesComboBox.SelectedItem.ToString().ToLower())
        {
        case "kalleload.net":
            form = new MultipartForm("http://www.kalleload.net/");
            form.FileContentType = "image/jpeg";
            form.InputBoxName    = "selector";
            form.setField("progress", "1");
            form.setField("markurl", String.Empty);
            form.setField("MAX_UPLOAD_SIZE", "16777216");
            form.sendFile(_FileNameToHandle);
            returnValue = utilities.parsePOSTData("kalleload", form.ResponseText.ToString());
            Clipboard.SetText(returnValue, TextDataFormat.Text);
            i.SetTextbox(returnValue);
            i.Show();
            break;

        //case "imgpurse.com":
        //    form = new MultipartForm("http://www.imgpurse.com/");
        //    form.FileContentType = "image/jpeg";
        //    form.InputBoxName = "file";
        //    form.setField("upload", "1");
        //    form.sendFile(_FileNameToHandle);
        //    returnValue = utilities.parsePOSTData("imgpurse", form.ResponseText.ToString());
        //    Clipboard.SetText(returnValue, TextDataFormat.Text);
        //    i.SetTextbox(returnValue);
        //    i.Show();
        //    break;
        case "tinypic.com":
            form = new MultipartForm("http://s4.tinypic.com/upload.php");
            form.FileContentType = "image/jpeg";
            form.InputBoxName    = "the_file";
            form.setField("UPLOAD_IDENTIFIER", "1154009790_1225587842");
            form.setField("upk", "e8bd19dfda564c710e602341ed9ffdec");
            form.setField("action", "upload");
            form.sendFile(_FileNameToHandle);
            returnValue = utilities.parsePOSTData("tinypic", form.ResponseText.ToString());
            Clipboard.SetText(returnValue, TextDataFormat.Text);
            i.SetTextbox(returnValue);
            i.Show();
            break;

        case "imageshack.us":
            form = new MultipartForm("http://www.imageshack.us");
            form.FileContentType = "image/jpeg";
            form.InputBoxName    = "fileupload";
            form.setField("swfbutan", "1");
            form.sendFile(_FileNameToHandle);
            returnValue = utilities.parsePOSTData("imageshack", form.ResponseText.ToString());
            Clipboard.SetText(returnValue, TextDataFormat.Text);
            i.SetTextbox(returnValue);
            i.Show();
            break;

        case "imgcow.com":
            form = new MultipartForm("http://www.imgcow.com/index.php");
            form.FileContentType = "image/jpeg";
            form.InputBoxName    = "file_1";
            form.sendFile(_FileNameToHandle);
            returnValue = utilities.parsePOSTData("imgcow", form.ResponseText.ToString());
            Clipboard.SetText(returnValue, TextDataFormat.Text);
            i.SetTextbox(returnValue);
            i.Show();
            break;

        default:
            break;
        }
        this.lifeTimer.Enabled          = true;
        this.applyEffectButton.Enabled  = true;
        this.uploadToSiteButton.Enabled = true;
        this.uploadToFtpButton.Enabled  = true;
        //get rid of the form.
        form = null;
    }
Пример #27
0
        internal MultipartForm BuildForm()
        {
            var form = new MultipartForm(false);

            PopulateForm(form, MerchantInfo);
            if (LegalInfoSameAsMerchant)
            {
                LegalInfo = new LegalInfo {
                    CorporateName         = MerchantInfo?.MerchantDbaName,
                    CorporateStreet       = MerchantInfo?.MerchantStreet,
                    CorporateCity         = MerchantInfo?.MerchantCity,
                    CorporateStatesSelect = MerchantInfo?.MerchantStatesSelect,
                    CorporateZip          = MerchantInfo?.MerchantZip
                };
            }
            PopulateForm(form, LegalInfo);
            PopulateForm(form, BusinessInfo);

            // OPTIONALS
            Headquarters?.PopulateForm(form);
            SalesMethods?.PopulateForm(form);
            ProcessingMethod?.PopulateForm(form);
            FutureDeliveryInfo?.PopulateForm(form);
            GolfIndustry?.PopulateForm(form);
            SalonIndustry?.PopulateForm(form);
            LodgingResortInfo?.PopulateForm(form);
            TransactionInfo?.PopulateForm(form);
            EquipmentInfo?.PopulateForm(form);
            ShippingOptions?.PopulateForm(form);
            DepositOptions?.PopulateForm(form);
            StatementOptions?.PopulateForm(form);
            DisputeOptions?.PopulateForm(form);

            // owners/officers
            for (int i = 0; i < 10; i++)
            {
                OwnerOfficer owner = new OwnerOfficer();
                if (i < OwnerOfficers.Count)
                {
                    owner = OwnerOfficers[i];
                }

                owner.Prefix = string.Format("OwnerOfficer{0}_", i + 1);
                PopulateForm(form, owner);

                // signers
                form.Set(string.Format("Signer{0}Email", i + 1), owner.EmailAddress ?? " ");
                form.Set(string.Format("Signer{0}FullName", i + 1), owner.FullName ?? " ");
            }

            // banking info
            PopulateForm(form, BankingInfo);
            if (BankingInfo != null)
            {
                foreach (var account in BankingInfo.BankAccounts)
                {
                    account.Prefix = string.Format("MerchantAccount{0}_", BankingInfo.BankAccounts.IndexOf(account) + 1);
                    account.PopulateForm(form);
                }
            }

            return(form);
        }
Пример #28
0
 /// <summary>
 /// Post请求
 /// </summary>
 /// <param name="address">地址</param>
 /// <param name="form">表单</param>
 /// <returns></returns>
 public byte[] HttpPost(string address, MultipartForm form)
 {
     this.Headers.Add(HttpRequestHeader.ContentType, "multipart/form-data; boundary=----" + form.Boundary);
     return(this.UploadData(address, "POST", form.ToArray()));
 }
Пример #29
0
        /// <summary>
        /// Post请求
        /// </summary>
        /// <param name="address">地址</param>
        /// <param name="form">表单</param>
        /// <param name="encoding">解码</param>
        /// <returns></returns>
        public async Task <string> HttpPost(string address, MultipartForm form, Encoding encoding)
        {
            var bytes = await this.HttpPost(address, form);

            return(encoding.GetString(bytes));
        }
Пример #30
0
        /// <summary>
        /// Post请求
        /// </summary>
        /// <param name="address">地址</param>
        /// <param name="form">表单</param>
        /// <param name="encoding">解码</param>
        /// <returns></returns>
        public string HttpPost(string address, MultipartForm form, Encoding encoding)
        {
            var bytes = this.HttpPost(address, form);

            return(encoding.GetString(bytes));
        }
Пример #31
0
    private void uploadToSiteButton_Click(object sender, EventArgs e)
    {
        this.lifeTimer.Enabled = false;
        //declare the form.
        MultipartForm form;

        //define the inputbox as readonly, output only.
        InputBox i = new InputBox("Your URL", "Your URL is also copied to the clipboard automatically", false, true);
        uploadToSiteButton.Enabled = false;
        uploadToFtpButton.Enabled = false;
        applyEffectButton.Enabled = false;
        string returnValue;
        //see what option they chose.
        switch(hostingChoicesComboBox.SelectedItem.ToString().ToLower())
        {
            case "kalleload.net":
                form = new MultipartForm("http://www.kalleload.net/");
                form.FileContentType = "image/jpeg";
                form.InputBoxName = "selector";
                form.setField("progress", "1");
                form.setField("markurl", String.Empty);
                form.setField("MAX_UPLOAD_SIZE", "16777216");
                form.sendFile(_FileNameToHandle);
                returnValue = utilities.parsePOSTData("kalleload", form.ResponseText.ToString());
                Clipboard.SetText(returnValue, TextDataFormat.Text);
                i.SetTextbox(returnValue);
                i.Show();
                break;

            //case "imgpurse.com":
            //    form = new MultipartForm("http://www.imgpurse.com/");
            //    form.FileContentType = "image/jpeg";
            //    form.InputBoxName = "file";
            //    form.setField("upload", "1");
            //    form.sendFile(_FileNameToHandle);
            //    returnValue = utilities.parsePOSTData("imgpurse", form.ResponseText.ToString());
            //    Clipboard.SetText(returnValue, TextDataFormat.Text);
            //    i.SetTextbox(returnValue);
            //    i.Show();
            //    break;
            case "tinypic.com":
                form = new MultipartForm("http://s4.tinypic.com/upload.php");
                form.FileContentType = "image/jpeg";
                form.InputBoxName = "the_file";
                form.setField("UPLOAD_IDENTIFIER", "1154009790_1225587842");
                form.setField("upk", "e8bd19dfda564c710e602341ed9ffdec");
                form.setField("action", "upload");
                form.sendFile(_FileNameToHandle);
                returnValue = utilities.parsePOSTData("tinypic", form.ResponseText.ToString());
                Clipboard.SetText(returnValue, TextDataFormat.Text);
                i.SetTextbox(returnValue);
                i.Show();
                break;
            case "imageshack.us":
                form = new MultipartForm("http://www.imageshack.us");
                form.FileContentType = "image/jpeg";
                form.InputBoxName = "fileupload";
                form.setField("swfbutan", "1");
                form.sendFile(_FileNameToHandle);
                returnValue = utilities.parsePOSTData("imageshack", form.ResponseText.ToString());
                Clipboard.SetText(returnValue, TextDataFormat.Text);
                i.SetTextbox(returnValue);
                i.Show();
                break;
            case "imgcow.com":
                form = new MultipartForm("http://www.imgcow.com/index.php");
                form.FileContentType = "image/jpeg";
                form.InputBoxName = "file_1";
                form.sendFile(_FileNameToHandle);
                returnValue = utilities.parsePOSTData("imgcow", form.ResponseText.ToString());
                Clipboard.SetText(returnValue, TextDataFormat.Text);
                i.SetTextbox(returnValue);
                i.Show();
                break;
            default:
                break;
        }
        this.lifeTimer.Enabled = true;
        this.applyEffectButton.Enabled = true;
        this.uploadToSiteButton.Enabled = true;
        this.uploadToFtpButton.Enabled = true;
        //get rid of the form.
        form = null;
    }